1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_cui.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // include --------------------------------------------------------------- 32*cdf0e10cSrcweir #include <tools/shl.hxx> 33*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 34*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <tools/urlobj.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include "multipat.hxx" 39*cdf0e10cSrcweir #include "multifil.hxx" 40*cdf0e10cSrcweir #include <dialmgr.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "multipat.hrc" 43*cdf0e10cSrcweir #include <cuires.hrc> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // #97807# ------------- 46*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp> 47*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp" 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir using namespace com::sun::star::ucb; 52*cdf0e10cSrcweir using namespace com::sun::star::uno; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // class SvxMultiFileDialog ---------------------------------------------- 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir IMPL_LINK( SvxMultiFileDialog, AddHdl_Impl, PushButton *, pBtn ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir sfx2::FileDialogHelper aDlg( 59*cdf0e10cSrcweir com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 ); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir if ( IsClassPathMode() ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir aDlg.SetTitle( CUI_RES( RID_SVXSTR_ARCHIVE_TITLE ) ); 64*cdf0e10cSrcweir aDlg.AddFilter( CUI_RES( RID_SVXSTR_ARCHIVE_HEADLINE ), String::CreateFromAscii("*.jar;*.zip") ); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir if ( aDlg.Execute() == ERRCODE_NONE ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir // #97807# URL content comparison of entries ----------- 70*cdf0e10cSrcweir INetURLObject aFile( aDlg.GetPath() ); 71*cdf0e10cSrcweir String sInsFile = aFile.getFSysPath( INetURLObject::FSYS_DETECT ); 72*cdf0e10cSrcweir ::ucbhelper::Content aContent( aFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() ); 73*cdf0e10cSrcweir Reference< XContent > xContent = aContent.get(); 74*cdf0e10cSrcweir OSL_ENSURE( xContent.is(), "AddHdl_Impl: invalid content interface!" ); 75*cdf0e10cSrcweir Reference< XContentIdentifier > xID = xContent->getIdentifier(); 76*cdf0e10cSrcweir OSL_ENSURE( xID.is(), "AddHdl_Impl: invalid ID interface!" ); 77*cdf0e10cSrcweir // ensure the content of files are valid 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir sal_uInt16 nCount = aPathLB.GetEntryCount(); 80*cdf0e10cSrcweir sal_Bool bDuplicated = sal_False; 81*cdf0e10cSrcweir try 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir if( nCount > 0 ) // start comparison 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir sal_uInt16 i; 86*cdf0e10cSrcweir ::ucbhelper::Content & VContent = aContent; // temporary Content reference 87*cdf0e10cSrcweir Reference< XContent > xVContent; 88*cdf0e10cSrcweir Reference< XContentIdentifier > xVID; 89*cdf0e10cSrcweir for( i = 0; i < nCount; i++ ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir String sVFile = aPathLB.GetEntry( i ); 92*cdf0e10cSrcweir std::map< String, ::ucbhelper::Content >::iterator aCur = aFileContentMap.find( sVFile ); 93*cdf0e10cSrcweir if( aCur == aFileContentMap.end() ) // look for File Content in aFileContentMap, but not find it. 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir INetURLObject aVFile( sVFile, INetURLObject::FSYS_DETECT ); 96*cdf0e10cSrcweir aFileContentMap[sVFile] = ::ucbhelper::Content( aVFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >() ); 97*cdf0e10cSrcweir VContent = aFileContentMap.find( sVFile )->second; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir else 100*cdf0e10cSrcweir VContent = aCur->second; 101*cdf0e10cSrcweir xVContent = VContent.get(); 102*cdf0e10cSrcweir OSL_ENSURE( xVContent.is(), "AddHdl_Impl: invalid content interface!" ); 103*cdf0e10cSrcweir xVID = xVContent->getIdentifier(); 104*cdf0e10cSrcweir OSL_ENSURE( xVID.is(), "AddHdl_Impl: invalid ID interface!" ); 105*cdf0e10cSrcweir if ( xID.is() && xVID.is() ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir // get a generic content provider 108*cdf0e10cSrcweir ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get(); 109*cdf0e10cSrcweir Reference< XContentProvider > xProvider; 110*cdf0e10cSrcweir if ( pBroker ) 111*cdf0e10cSrcweir xProvider = pBroker->getContentProviderInterface(); 112*cdf0e10cSrcweir if ( xProvider.is() ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir if ( 0 == xProvider->compareContentIds( xID, xVID ) ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir bDuplicated = sal_True; 117*cdf0e10cSrcweir break; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } // end of if the entries are more than zero. 123*cdf0e10cSrcweir } // end of try(} 124*cdf0e10cSrcweir catch( const Exception& ) // catch every exception of comparison 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir OSL_ENSURE( sal_False, "AddHdl_Impl: caught an unexpected exception!" ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir if ( bDuplicated ) // #97807# -------------------- 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir String sMsg( CUI_RES( RID_SVXSTR_MULTIFILE_DBL_ERR ) ); 132*cdf0e10cSrcweir sMsg.SearchAndReplaceAscii( "%1", sInsFile ); 133*cdf0e10cSrcweir InfoBox( pBtn, sMsg ).Execute(); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir else 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir sal_uInt16 nPos = aPathLB.InsertEntry( sInsFile, LISTBOX_APPEND ); 138*cdf0e10cSrcweir aPathLB.SetEntryData( nPos, (void*) new String( sInsFile ) ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir } // end of if ( aDlg.Execute() == ERRCODE_NONE ) 142*cdf0e10cSrcweir return 0; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // ----------------------------------------------------------------------- 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir IMPL_LINK( SvxMultiFileDialog, DelHdl_Impl, PushButton *, EMPTYARG ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir sal_uInt16 nPos = aPathLB.GetSelectEntryPos(); 150*cdf0e10cSrcweir aPathLB.RemoveEntry( nPos ); 151*cdf0e10cSrcweir sal_uInt16 nCnt = aPathLB.GetEntryCount(); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir if ( nCnt ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir nCnt--; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir if ( nPos > nCnt ) 158*cdf0e10cSrcweir nPos = nCnt; 159*cdf0e10cSrcweir aPathLB.SelectEntryPos( nPos ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir return 0; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir // ----------------------------------------------------------------------- 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir SvxMultiFileDialog::SvxMultiFileDialog( Window* pParent, sal_Bool bEmptyAllowed ) : 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir SvxMultiPathDialog( pParent, bEmptyAllowed ) 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir aAddBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, AddHdl_Impl ) ); 172*cdf0e10cSrcweir aDelBtn.SetClickHdl( LINK( this, SvxMultiFileDialog, DelHdl_Impl ) ); 173*cdf0e10cSrcweir SetText( CUI_RES( RID_SVXSTR_FILE_TITLE ) ); 174*cdf0e10cSrcweir aPathFL.SetText( CUI_RES( RID_SVXSTR_FILE_HEADLINE ) ); 175*cdf0e10cSrcweir aDelBtn.Enable(); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // ----------------------------------------------------------------------- 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir SvxMultiFileDialog::~SvxMultiFileDialog() 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir 185