1*2ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2ee96f1cSAndrew Rist * distributed with this work for additional information
6*2ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance
9*2ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*2ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*2ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2ee96f1cSAndrew Rist * software distributed under the License is distributed on an
15*2ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the
17*2ee96f1cSAndrew Rist * specific language governing permissions and limitations
18*2ee96f1cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*2ee96f1cSAndrew Rist *************************************************************/
21*2ee96f1cSAndrew Rist
22*2ee96f1cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cui.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir #include <tools/shl.hxx>
29cdf0e10cSrcweir #include <vcl/msgbox.hxx>
30cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <tools/urlobj.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "multipat.hxx"
35cdf0e10cSrcweir #include "multifil.hxx"
36cdf0e10cSrcweir #include <dialmgr.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include "multipat.hrc"
39cdf0e10cSrcweir #include <cuires.hrc>
40cdf0e10cSrcweir
41cdf0e10cSrcweir // #97807# -------------
42cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp>
43cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
46cdf0e10cSrcweir
47cdf0e10cSrcweir using namespace com::sun::star::ucb;
48cdf0e10cSrcweir using namespace com::sun::star::uno;
49cdf0e10cSrcweir
50cdf0e10cSrcweir // class SvxMultiFileDialog ----------------------------------------------
51cdf0e10cSrcweir
IMPL_LINK(SvxMultiFileDialog,AddHdl_Impl,PushButton *,pBtn)52cdf0e10cSrcweir IMPL_LINK( SvxMultiFileDialog, AddHdl_Impl, PushButton *, pBtn )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir sfx2::FileDialogHelper aDlg(
55cdf0e10cSrcweir com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
56cdf0e10cSrcweir
57cdf0e10cSrcweir if ( IsClassPathMode() )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir aDlg.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE ) );
60cdf0e10cSrcweir aDlg.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), String::CreateFromAscii("*.jar;*.zip") );
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
63cdf0e10cSrcweir if ( aDlg.Execute() == ERRCODE_NONE )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir // #97807# URL content comparison of entries -----------
66cdf0e10cSrcweir INetURLObject aFile( aDlg.GetPath() );
67cdf0e10cSrcweir String sInsFile = aFile.getFSysPath( INetURLObject::FSYS_DETECT );
68cdf0e10cSrcweir ::ucbhelper::Content aContent( aFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() );
69cdf0e10cSrcweir Reference< XContent > xContent = aContent.get();
70cdf0e10cSrcweir OSL_ENSURE( xContent.is(), "AddHdl_Impl: invalid content interface!" );
71cdf0e10cSrcweir Reference< XContentIdentifier > xID = xContent->getIdentifier();
72cdf0e10cSrcweir OSL_ENSURE( xID.is(), "AddHdl_Impl: invalid ID interface!" );
73cdf0e10cSrcweir // ensure the content of files are valid
74cdf0e10cSrcweir
75cdf0e10cSrcweir sal_uInt16 nCount = aPathLB.GetEntryCount();
76cdf0e10cSrcweir sal_Bool bDuplicated = sal_False;
77cdf0e10cSrcweir try
78cdf0e10cSrcweir {
79cdf0e10cSrcweir if( nCount > 0 ) // start comparison
80cdf0e10cSrcweir {
81cdf0e10cSrcweir sal_uInt16 i;
82cdf0e10cSrcweir ::ucbhelper::Content & VContent = aContent; // temporary Content reference
83cdf0e10cSrcweir Reference< XContent > xVContent;
84cdf0e10cSrcweir Reference< XContentIdentifier > xVID;
85cdf0e10cSrcweir for( i = 0; i < nCount; i++ )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir String sVFile = aPathLB.GetEntry( i );
88cdf0e10cSrcweir std::map< String, ::ucbhelper::Content >::iterator aCur = aFileContentMap.find( sVFile );
89cdf0e10cSrcweir if( aCur == aFileContentMap.end() ) // look for File Content in aFileContentMap, but not find it.
90cdf0e10cSrcweir {
91cdf0e10cSrcweir INetURLObject aVFile( sVFile, INetURLObject::FSYS_DETECT );
92cdf0e10cSrcweir aFileContentMap[sVFile] = ::ucbhelper::Content( aVFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() );
93cdf0e10cSrcweir VContent = aFileContentMap.find( sVFile )->second;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir else
96cdf0e10cSrcweir VContent = aCur->second;
97cdf0e10cSrcweir xVContent = VContent.get();
98cdf0e10cSrcweir OSL_ENSURE( xVContent.is(), "AddHdl_Impl: invalid content interface!" );
99cdf0e10cSrcweir xVID = xVContent->getIdentifier();
100cdf0e10cSrcweir OSL_ENSURE( xVID.is(), "AddHdl_Impl: invalid ID interface!" );
101cdf0e10cSrcweir if ( xID.is() && xVID.is() )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir // get a generic content provider
104cdf0e10cSrcweir ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
105cdf0e10cSrcweir Reference< XContentProvider > xProvider;
106cdf0e10cSrcweir if ( pBroker )
107cdf0e10cSrcweir xProvider = pBroker->getContentProviderInterface();
108cdf0e10cSrcweir if ( xProvider.is() )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir if ( 0 == xProvider->compareContentIds( xID, xVID ) )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir bDuplicated = sal_True;
113cdf0e10cSrcweir break;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir } // end of if the entries are more than zero.
119cdf0e10cSrcweir } // end of try(}
120cdf0e10cSrcweir catch( const Exception& ) // catch every exception of comparison
121cdf0e10cSrcweir {
122cdf0e10cSrcweir OSL_ENSURE( sal_False, "AddHdl_Impl: caught an unexpected exception!" );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
125cdf0e10cSrcweir if ( bDuplicated ) // #97807# --------------------
126cdf0e10cSrcweir {
127cdf0e10cSrcweir String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
128cdf0e10cSrcweir sMsg.SearchAndReplaceAscii( "%1", sInsFile );
129cdf0e10cSrcweir InfoBox( pBtn, sMsg ).Execute();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir else
132cdf0e10cSrcweir {
133cdf0e10cSrcweir sal_uInt16 nPos = aPathLB.InsertEntry( sInsFile, LISTBOX_APPEND );
134cdf0e10cSrcweir aPathLB.SetEntryData( nPos, (void*) new String( sInsFile ) );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir } // end of if ( aDlg.Execute() == ERRCODE_NONE )
138cdf0e10cSrcweir return 0;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir // -----------------------------------------------------------------------
142cdf0e10cSrcweir
IMPL_LINK(SvxMultiFileDialog,DelHdl_Impl,PushButton *,EMPTYARG)143cdf0e10cSrcweir IMPL_LINK( SvxMultiFileDialog, DelHdl_Impl, PushButton *, EMPTYARG )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir sal_uInt16 nPos = aPathLB.GetSelectEntryPos();
146cdf0e10cSrcweir aPathLB.RemoveEntry( nPos );
147cdf0e10cSrcweir sal_uInt16 nCnt = aPathLB.GetEntryCount();
148cdf0e10cSrcweir
149cdf0e10cSrcweir if ( nCnt )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir nCnt--;
152cdf0e10cSrcweir
153cdf0e10cSrcweir if ( nPos > nCnt )
154cdf0e10cSrcweir nPos = nCnt;
155cdf0e10cSrcweir aPathLB.SelectEntryPos( nPos );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir return 0;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir // -----------------------------------------------------------------------
161cdf0e10cSrcweir
SvxMultiFileDialog(Window * pParent,sal_Bool bEmptyAllowed)162cdf0e10cSrcweir SvxMultiFileDialog::SvxMultiFileDialog( Window* pParent, sal_Bool bEmptyAllowed ) :
163cdf0e10cSrcweir
164cdf0e10cSrcweir SvxMultiPathDialog( pParent, bEmptyAllowed )
165cdf0e10cSrcweir
166cdf0e10cSrcweir {
167cdf0e10cSrcweir aAddBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, AddHdl_Impl ) );
168cdf0e10cSrcweir aDelBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, DelHdl_Impl ) );
169cdf0e10cSrcweir SetText( CUI_RES( RID_SVXSTR_FILE_TITLE ) );
170cdf0e10cSrcweir aPathFL.SetText( CUI_RES( RID_SVXSTR_FILE_HEADLINE ) );
171cdf0e10cSrcweir aDelBtn.Enable();
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir // -----------------------------------------------------------------------
175cdf0e10cSrcweir
~SvxMultiFileDialog()176cdf0e10cSrcweir SvxMultiFileDialog::~SvxMultiFileDialog()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir
181