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 //------------------------------------------------------------------------ 29*cdf0e10cSrcweir // includes 30*cdf0e10cSrcweir //------------------------------------------------------------------------ 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 38*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h> 39*cdf0e10cSrcweir #include <osl/diagnose.h> 40*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 42*cdf0e10cSrcweir #include <FPServiceInfo.hxx> 43*cdf0e10cSrcweir #include <vos/mutex.hxx> 44*cdf0e10cSrcweir #include <vcl/svapp.hxx> 45*cdf0e10cSrcweir #include "SalAquaFolderPicker.hxx" 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <tools/urlobj.hxx> 48*cdf0e10cSrcweir #include <iostream> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include "resourceprovider.hxx" 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #ifndef _SV_RC_H 53*cdf0e10cSrcweir #include <tools/rc.hxx> 54*cdf0e10cSrcweir #endif 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include <osl/file.hxx> 57*cdf0e10cSrcweir #include "CFStringUtilities.hxx" 58*cdf0e10cSrcweir #include "NSString_OOoAdditions.hxx" 59*cdf0e10cSrcweir #include "NSURL_OOoAdditions.hxx" 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir #pragma mark DEFINES 62*cdf0e10cSrcweir #define CLASS_NAME "SalAquaFolderPicker" 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //------------------------------------------------------------------------ 65*cdf0e10cSrcweir // namespace directives 66*cdf0e10cSrcweir //------------------------------------------------------------------------ 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir using namespace ::rtl; 69*cdf0e10cSrcweir using namespace ::com::sun::star; 70*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 71*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 72*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir //------------------------------------------------------------------------ 75*cdf0e10cSrcweir // helper functions 76*cdf0e10cSrcweir //------------------------------------------------------------------------ 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir namespace 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir // controling event notifications 81*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL FolderPicker_getSupportedServiceNames() 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir uno::Sequence<rtl::OUString> aRet(2); 84*cdf0e10cSrcweir aRet[0] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.SystemFolderPicker" ); 85*cdf0e10cSrcweir aRet[1] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.AquaFolderPicker" ); 86*cdf0e10cSrcweir return aRet; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 91*cdf0e10cSrcweir // constructor 92*cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 93*cdf0e10cSrcweir SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) : 94*cdf0e10cSrcweir m_xServiceMgr( xServiceMgr ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir m_nDialogType = NAVIGATIONSERVICES_DIRECTORY; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 104*cdf0e10cSrcweir // XExecutableDialog functions 105*cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void SAL_CALL SalAquaFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir implsetTitle(aTitle); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir sal_Int16 SAL_CALL SalAquaFolderPicker::execute() throw( uno::RuntimeException ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir sal_Int16 retVal = 0; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir int nResult = runandwaitforresult(); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir switch( nResult ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir case NSOKButton: 131*cdf0e10cSrcweir OSL_TRACE("Dialog returned with OK"); 132*cdf0e10cSrcweir retVal = ExecutableDialogResults::OK; 133*cdf0e10cSrcweir break; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir case NSCancelButton: 136*cdf0e10cSrcweir OSL_TRACE("Dialog was cancelled!"); 137*cdf0e10cSrcweir retVal = ExecutableDialogResults::CANCEL; 138*cdf0e10cSrcweir break; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir default: 141*cdf0e10cSrcweir throw uno::RuntimeException(rtl::OUString::createFromAscii("The dialog returned with an unknown result!"), static_cast< XFolderPicker* >( this )); 142*cdf0e10cSrcweir break; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 146*cdf0e10cSrcweir return retVal; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 150*cdf0e10cSrcweir // XFolderPicker functions 151*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory ) 154*cdf0e10cSrcweir throw( lang::IllegalArgumentException, uno::RuntimeException ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", aDirectory); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir implsetDisplayDirectory(aDirectory); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir rtl::OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory() throw( uno::RuntimeException ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir OUString aDirectory = implgetDisplayDirectory(); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__, aDirectory); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir return aDirectory; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir rtl::OUString SAL_CALL SalAquaFolderPicker::getDirectory() throw( uno::RuntimeException ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir NSArray *files = nil; 185*cdf0e10cSrcweir if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) { 186*cdf0e10cSrcweir files = [(NSOpenPanel*)m_pDialog URLs]; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir long nFiles = [files count]; 190*cdf0e10cSrcweir OSL_TRACE("# of items: %d", nFiles); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if (nFiles < 1) { 193*cdf0e10cSrcweir throw uno::RuntimeException(rtl::OUString::createFromAscii("no directory selected"), static_cast< XFolderPicker* >( this )); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir rtl::OUString aDirectory; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir NSURL *url = [files objectAtIndex:0]; 199*cdf0e10cSrcweir OSL_TRACE("handling %s", [[url description] UTF8String]); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir aDirectory = [url OUStringForInfo:FULLPATH]; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir implsetDisplayDirectory(aDirectory); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir OSL_TRACE("dir url: %s", OUStringToOString(aDirectory, RTL_TEXTENCODING_UTF8).getStr()); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 208*cdf0e10cSrcweir return aDirectory; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir void SAL_CALL SalAquaFolderPicker::setDescription( const rtl::OUString& rDescription ) 212*cdf0e10cSrcweir throw( uno::RuntimeException ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__, "description", rDescription); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir [m_pDialog setMessage:[NSString stringWithOUString:rDescription]]; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // ------------------------------------------------- 222*cdf0e10cSrcweir // XServiceInfo 223*cdf0e10cSrcweir // ------------------------------------------------- 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir rtl::OUString SAL_CALL SalAquaFolderPicker::getImplementationName() 226*cdf0e10cSrcweir throw( uno::RuntimeException ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir rtl::OUString retVal = rtl::OUString::createFromAscii( FOLDER_PICKER_IMPL_NAME ); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir return retVal; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const rtl::OUString& sServiceName ) 238*cdf0e10cSrcweir throw( uno::RuntimeException ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__, "serviceName", sServiceName); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir sal_Bool retVal = sal_False; 243*cdf0e10cSrcweir uno::Sequence <rtl::OUString> supportedServicesNames = FolderPicker_getSupportedServiceNames(); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir for( sal_Int32 n = supportedServicesNames.getLength(); n--; ) { 246*cdf0e10cSrcweir if( supportedServicesNames[n].compareTo( sServiceName ) == 0) { 247*cdf0e10cSrcweir retVal = sal_True; 248*cdf0e10cSrcweir break; 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal); 253*cdf0e10cSrcweir return retVal; 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames() 257*cdf0e10cSrcweir throw( uno::RuntimeException ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__); 260*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir return FolderPicker_getSupportedServiceNames(); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 266*cdf0e10cSrcweir // XCancellable 267*cdf0e10cSrcweir //------------------------------------------------------------------------------------ 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir void SAL_CALL SalAquaFolderPicker::cancel() throw( uno::RuntimeException ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir [m_pDialog cancel:nil]; 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir // ------------------------------------------------- 281*cdf0e10cSrcweir // XEventListener 282*cdf0e10cSrcweir // ------------------------------------------------- 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& ) 285*cdf0e10cSrcweir throw( uno::RuntimeException ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir DBG_PRINT_ENTRY(CLASS_NAME, __func__); 288*cdf0e10cSrcweir DBG_PRINT_EXIT(CLASS_NAME, __func__); 289*cdf0e10cSrcweir } 290