Update ooo320-m1
[ooovba.git] / svx / source / cui / multifil.cxx
blob4ea8d0d7f919e4aeb8a81ad5646acd45f9007941
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: multifil.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
39 #include <tools/shl.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <sfx2/filedlghelper.hxx>
43 #include <tools/urlobj.hxx>
45 #include "multipat.hxx"
46 #include "multifil.hxx"
47 #include <svx/dialmgr.hxx>
49 #include "multipat.hrc"
50 #include <svx/dialogs.hrc>
52 // #97807# -------------
53 #include <com/sun/star/ucb/XContentProvider.hpp>
54 #include <ucbhelper/contentbroker.hxx>
56 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
58 using namespace com::sun::star::ucb;
59 using namespace com::sun::star::uno;
61 // class SvxMultiFileDialog ----------------------------------------------
63 IMPL_LINK( SvxMultiFileDialog, AddHdl_Impl, PushButton *, pBtn )
65 sfx2::FileDialogHelper aDlg(
66 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
68 if ( IsClassPathMode() )
70 aDlg.SetTitle( SVX_RES( RID_SVXSTR_ARCHIVE_TITLE ) );
71 aDlg.AddFilter( SVX_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), String::CreateFromAscii("*.jar;*.zip") );
74 if ( aDlg.Execute() == ERRCODE_NONE )
76 // #97807# URL content comparison of entries -----------
77 INetURLObject aFile( aDlg.GetPath() );
78 String sInsFile = aFile.getFSysPath( INetURLObject::FSYS_DETECT );
79 ::ucbhelper::Content aContent( aFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() );
80 Reference< XContent > xContent = aContent.get();
81 OSL_ENSURE( xContent.is(), "AddHdl_Impl: invalid content interface!" );
82 Reference< XContentIdentifier > xID = xContent->getIdentifier();
83 OSL_ENSURE( xID.is(), "AddHdl_Impl: invalid ID interface!" );
84 // ensure the content of files are valid
86 USHORT nCount = aPathLB.GetEntryCount();
87 BOOL bDuplicated = FALSE;
88 try
90 if( nCount > 0 ) // start comparison
92 USHORT i;
93 ::ucbhelper::Content & VContent = aContent; // temporary Content reference
94 Reference< XContent > xVContent;
95 Reference< XContentIdentifier > xVID;
96 for( i = 0; i < nCount; i++ )
98 String sVFile = aPathLB.GetEntry( i );
99 std::map< String, ::ucbhelper::Content >::iterator aCur = aFileContentMap.find( sVFile );
100 if( aCur == aFileContentMap.end() ) // look for File Content in aFileContentMap, but not find it.
102 INetURLObject aVFile( sVFile, INetURLObject::FSYS_DETECT );
103 aFileContentMap[sVFile] = ::ucbhelper::Content( aVFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() );
104 VContent = aFileContentMap.find( sVFile )->second;
106 else
107 VContent = aCur->second;
108 xVContent = VContent.get();
109 OSL_ENSURE( xVContent.is(), "AddHdl_Impl: invalid content interface!" );
110 xVID = xVContent->getIdentifier();
111 OSL_ENSURE( xVID.is(), "AddHdl_Impl: invalid ID interface!" );
112 if ( xID.is() && xVID.is() )
114 // get a generic content provider
115 ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
116 Reference< XContentProvider > xProvider;
117 if ( pBroker )
118 xProvider = pBroker->getContentProviderInterface();
119 if ( xProvider.is() )
121 if ( 0 == xProvider->compareContentIds( xID, xVID ) )
123 bDuplicated = TRUE;
124 break;
129 } // end of if the entries are more than zero.
130 } // end of try(}
131 catch( const Exception& ) // catch every exception of comparison
133 OSL_ENSURE( sal_False, "AddHdl_Impl: caught an unexpected exception!" );
136 if ( bDuplicated ) // #97807# --------------------
138 String sMsg( SVX_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
139 sMsg.SearchAndReplaceAscii( "%1", sInsFile );
140 InfoBox( pBtn, sMsg ).Execute();
142 else
144 USHORT nPos = aPathLB.InsertEntry( sInsFile, LISTBOX_APPEND );
145 aPathLB.SetEntryData( nPos, (void*) new String( sInsFile ) );
148 } // end of if ( aDlg.Execute() == ERRCODE_NONE )
149 return 0;
152 // -----------------------------------------------------------------------
154 IMPL_LINK( SvxMultiFileDialog, DelHdl_Impl, PushButton *, EMPTYARG )
156 USHORT nPos = aPathLB.GetSelectEntryPos();
157 aPathLB.RemoveEntry( nPos );
158 USHORT nCnt = aPathLB.GetEntryCount();
160 if ( nCnt )
162 nCnt--;
164 if ( nPos > nCnt )
165 nPos = nCnt;
166 aPathLB.SelectEntryPos( nPos );
168 return 0;
171 // -----------------------------------------------------------------------
173 SvxMultiFileDialog::SvxMultiFileDialog( Window* pParent, BOOL bEmptyAllowed ) :
175 SvxMultiPathDialog( pParent, bEmptyAllowed )
178 aAddBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, AddHdl_Impl ) );
179 aDelBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, DelHdl_Impl ) );
180 SetText( SVX_RES( RID_SVXSTR_FILE_TITLE ) );
181 aPathFL.SetText( SVX_RES( RID_SVXSTR_FILE_HEADLINE ) );
182 aDelBtn.Enable();
185 // -----------------------------------------------------------------------
187 SvxMultiFileDialog::~SvxMultiFileDialog()