/************************************************************************* * * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: SalAquaFolderPicker.cxx,v $ * * $Revision: 1.8 $ * * last change: $Author: kz $ $Date: 2006/07/06 10:32:15 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. * * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2005 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * ************************************************************************/ //------------------------------------------------------------------------ // includes //------------------------------------------------------------------------ #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ #include #endif #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ #include #endif #ifndef _COM_SUN_STAR_UI_DIALOGS_EXECUTABLEDIALOGRESULTS_HPP_ #include #endif #ifndef _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_ #include #endif #ifndef _COM_SUN_STAR_UI_DIALOGS_COMMONFILEPICKERELEMENTIDS_HPP_ #include #endif #ifndef _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_ #include #endif #ifndef _CPPUHELPER_INTERFACECONTAINER_H_ #include #endif #ifndef _OSL_DIAGNOSE_H_ #include #endif #ifndef _COM_SUN_STAR_UI_DIALOGS_TEMPLATEDESCRIPTION_HPP_ #include #endif #ifndef _COM_SUN_STAR_UNO_ANY_HXX_ #include #endif #ifndef _FPSERVICEINFO_HXX_ #include #endif #ifndef _VOS_MUTEX_HXX_ #include #endif #ifndef _SV_SVAPP_HXX #include #endif #ifndef _SALAQUAFOLDERPICKER_HXX_ #include "SalAquaFolderPicker.hxx" #endif #include #include #include "resourceprovider.hxx" #ifndef _SV_RC_H #include #endif #include // FIXME - for MAXPATHLEN... #include //------------------------------------------------------------------------ // namespace directives //------------------------------------------------------------------------ using namespace ::rtl; using namespace ::com::sun::star; using namespace ::com::sun::star::ui::dialogs; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; //------------------------------------------------------------------------ // helper functions //------------------------------------------------------------------------ namespace { // controling event notifications uno::Sequence SAL_CALL FolderPicker_getSupportedServiceNames() { uno::Sequence aRet(3); aRet[0] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FolderPicker" ); aRet[1] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.SystemFolderPicker" ); aRet[2] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.AquaFolderPicker" ); return aRet; } } //----------------------------------------------------------------------------------------- // constructor //----------------------------------------------------------------------------------------- SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference& xServiceMgr ) : m_xServiceMgr( xServiceMgr ) { fprintf(stderr, "PJ: constructor of SalAquaFolderPicker\n"); CResourceProvider aResProvider; m_pDialog = NULL; m_nDialogType = NAVIGATIONSERVICES_DIRECTORY; // gtk_file_chooser_dialog_new( // OUStringToOString( aResProvider.getResString( FOLDERPICKER_TITLE ), RTL_TEXTENCODING_UTF8 ).getStr(), // NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, // GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, (char *)NULL ); // gtk_dialog_set_default_response( GTK_DIALOG (m_pDialog), GTK_RESPONSE_ACCEPT ); // gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( m_pDialog ), FALSE ); // gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( m_pDialog ), FALSE ); fprintf(stderr, "PJ: leaving constructor of SalAquaFolderPicker\n"); } // ------------------------------------------------- // XEventListener // ------------------------------------------------- void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& ) throw( uno::RuntimeException ) { fprintf(stderr, "PJ: >>>> SalAquaFolderPicker::disposing\n"); fprintf(stderr, "PJ: <<<< SalAquaFolderPicker::disposing\n"); } void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory ) throw( lang::IllegalArgumentException, uno::RuntimeException ) { fprintf(stderr, "PJ: >>>> SalAquaFolderPicker::setDisplayDirectory (%s)\n", ::rtl::OUStringToOString (aDirectory, RTL_TEXTENCODING_UTF8).pData->buffer); ::vos::OGuard aGuard( Application::GetSolarMutex() ); m_sDisplayDirectory = aDirectory; fprintf(stderr, "PJ: <<<< SalAquaFolderPicker::setDisplayDirectory\n"); } rtl::OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory() throw( uno::RuntimeException ) { fprintf(stderr, "PJ: >>>> SalAquaFolderPicker::getDisplayDirectory\n"); ::vos::OGuard aGuard( Application::GetSolarMutex() ); ::rtl::OUString aDirectory; long count; AEDescList selection; FSRef folder; char path[MAXPATHLEN]; selection = m_pReplyRecord.selection; AECountItems(&selection, &count); // Choose folder dialog -> only one item should be returned! if ( count==1 ) { // Get the FSRef of selected directory AEGetNthPtr(&selection, 1, typeFSRef, NULL, NULL, &folder, sizeof(folder), NULL); // Convert it into C string FSRefMakePath( &folder, (UInt8 *)path, MAXPATHLEN ); fprintf(stderr, "PJ: User selected: %s\n", path); osl::FileBase::getFileURLFromSystemPath(::rtl::OStringToOUString(OString(path), RTL_TEXTENCODING_UTF8), aDirectory); fprintf(stderr, "PJ: aDirectory should be %s\n", ::rtl::OUStringToOString (aDirectory, RTL_TEXTENCODING_UTF8).pData->buffer); } fprintf(stderr, "PJ: <<<< SalAquaFolderPicker::getDisplayDirectory (returning %s)\n", ::rtl::OUStringToOString (aDirectory, RTL_TEXTENCODING_UTF8).pData->buffer); return aDirectory; } rtl::OUString SAL_CALL SalAquaFolderPicker::getDirectory() throw( uno::RuntimeException ) { fprintf(stderr, "PJ: >>>> SalAquaFolderPicker::getDirectory\n"); rtl::OUString aDirectory = getDisplayDirectory(); fprintf(stderr, "PJ: <<<< SalAquaFolderPicker::getDirectory (returning %s)\n", ::rtl::OUStringToOString (aDirectory, RTL_TEXTENCODING_UTF8).pData->buffer); // FIXME: is this OK? return aDirectory; } void SAL_CALL SalAquaFolderPicker::setDescription( const rtl::OUString& rDescription ) throw( uno::RuntimeException ) { ::rtl::OString aDescription = OUStringToOString( rDescription, RTL_TEXTENCODING_UTF8 ); } //----------------------------------------------------------------------------------------- // XExecutableDialog functions //----------------------------------------------------------------------------------------- void SAL_CALL SalAquaFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException ) { fprintf(stderr, "PJ: SalAquaFolderPicker::setTitle (%s)\n", ::rtl::OUStringToOString (aTitle, RTL_TEXTENCODING_UTF8).pData->buffer); implsetTitle(aTitle); } sal_Int16 SAL_CALL SalAquaFolderPicker::execute() throw( uno::RuntimeException ) { fprintf (stderr, "PJ: >>>> SalAquaFolderPicker::execute\n"); ::vos::OGuard aGuard( Application::GetSolarMutex() ); sal_Int16 retVal = 0; OSStatus nStatus = runandwaitforresult(); switch( nStatus ) { case noErr: fprintf(stderr, "PJ: OK!\n"); retVal = ExecutableDialogResults::OK; break; case userCanceledErr: fprintf(stderr, "PJ: user cancelled!\n"); retVal = ExecutableDialogResults::CANCEL; break; default: retVal = 0; break; } fprintf (stderr, "PJ: <<<< SalAquaFolderPicker::execute\n"); return retVal; } //------------------------------------------------------------------------------------ // XCancellable //------------------------------------------------------------------------------------ void SAL_CALL SalAquaFolderPicker::cancel() throw( uno::RuntimeException ) { fprintf (stderr, "PJ: >>>> SalAquaFolderPicker::cancel\n"); ::vos::OGuard aGuard( Application::GetSolarMutex() ); fprintf (stderr, "PJ: <<<< SalAquaFolderPicker::cancel\n"); } // ------------------------------------------------- // XServiceInfo // ------------------------------------------------- rtl::OUString SAL_CALL SalAquaFolderPicker::getImplementationName() throw( uno::RuntimeException ) { return rtl::OUString::createFromAscii( FOLDER_PICKER_IMPL_NAME ); } // ------------------------------------------------- // XServiceInfo // ------------------------------------------------- sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const rtl::OUString& ServiceName ) throw( uno::RuntimeException ) { uno::Sequence SupportedServicesNames = FolderPicker_getSupportedServiceNames(); for( sal_Int32 n = SupportedServicesNames.getLength(); n--; ) if( SupportedServicesNames[n].compareTo( ServiceName ) == 0) return sal_True; return sal_False; } // ------------------------------------------------- // XServiceInfo // ------------------------------------------------- uno::Sequence SAL_CALL SalAquaFolderPicker::getSupportedServiceNames() throw( uno::RuntimeException ) { return FolderPicker_getSupportedServiceNames(); }