1*b557fc96SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b557fc96SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b557fc96SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b557fc96SAndrew Rist * distributed with this work for additional information 6*b557fc96SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b557fc96SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b557fc96SAndrew Rist * "License"); you may not use this file except in compliance 9*b557fc96SAndrew Rist * with the License. You may obtain a copy of the License at 10*b557fc96SAndrew Rist * 11*b557fc96SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*b557fc96SAndrew Rist * 13*b557fc96SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b557fc96SAndrew Rist * software distributed under the License is distributed on an 15*b557fc96SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b557fc96SAndrew Rist * KIND, either express or implied. See the License for the 17*b557fc96SAndrew Rist * specific language governing permissions and limitations 18*b557fc96SAndrew Rist * under the License. 19*b557fc96SAndrew Rist * 20*b557fc96SAndrew Rist *************************************************************/ 21*b557fc96SAndrew Rist 22*b557fc96SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_fpicker.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //------------------------------------------------------------------------ 28cdf0e10cSrcweir // includes 29cdf0e10cSrcweir //------------------------------------------------------------------------ 30cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 31cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 33cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 34cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 35cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 36cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h> 37cdf0e10cSrcweir #include <osl/diagnose.h> 38cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 39cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 40cdf0e10cSrcweir #include <FPServiceInfo.hxx> 41cdf0e10cSrcweir #include <vos/mutex.hxx> 42cdf0e10cSrcweir #include <vcl/svapp.hxx> 43cdf0e10cSrcweir #include "SalGtkFolderPicker.hxx" 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <tools/urlobj.hxx> 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <iostream> 48cdf0e10cSrcweir #include "resourceprovider.hxx" 49cdf0e10cSrcweir #ifndef _SV_RC_H 50cdf0e10cSrcweir #include <tools/rc.hxx> 51cdf0e10cSrcweir #endif 52cdf0e10cSrcweir 53cdf0e10cSrcweir //------------------------------------------------------------------------ 54cdf0e10cSrcweir // namespace directives 55cdf0e10cSrcweir //------------------------------------------------------------------------ 56cdf0e10cSrcweir 57cdf0e10cSrcweir using namespace ::rtl; 58cdf0e10cSrcweir using namespace ::com::sun::star; 59cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 60cdf0e10cSrcweir using namespace ::com::sun::star::lang; 61cdf0e10cSrcweir using namespace ::com::sun::star::uno; 62cdf0e10cSrcweir 63cdf0e10cSrcweir //------------------------------------------------------------------------ 64cdf0e10cSrcweir // helper functions 65cdf0e10cSrcweir //------------------------------------------------------------------------ 66cdf0e10cSrcweir 67cdf0e10cSrcweir namespace 68cdf0e10cSrcweir { 69cdf0e10cSrcweir // controling event notifications 70cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL FolderPicker_getSupportedServiceNames() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir uno::Sequence<rtl::OUString> aRet(2); 73cdf0e10cSrcweir aRet[0] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.SystemFolderPicker" ); 74cdf0e10cSrcweir aRet[1] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.GtkFolderPicker" ); 75cdf0e10cSrcweir return aRet; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 80cdf0e10cSrcweir // constructor 81cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 82cdf0e10cSrcweir SalGtkFolderPicker::SalGtkFolderPicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) : 83cdf0e10cSrcweir SalGtkPicker(xServiceMgr), 84cdf0e10cSrcweir m_xServiceMgr(xServiceMgr) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir CResourceProvider aResProvider; 87cdf0e10cSrcweir 88cdf0e10cSrcweir GdkThreadLock aLock; 89cdf0e10cSrcweir 90cdf0e10cSrcweir m_pDialog = gtk_file_chooser_dialog_new( 91cdf0e10cSrcweir OUStringToOString( aResProvider.getResString( FOLDERPICKER_TITLE ), RTL_TEXTENCODING_UTF8 ).getStr(), 92cdf0e10cSrcweir NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 93cdf0e10cSrcweir GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, (char *)NULL ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir gtk_dialog_set_default_response( GTK_DIALOG (m_pDialog), GTK_RESPONSE_ACCEPT ); 96cdf0e10cSrcweir gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( m_pDialog ), sal_False ); 97cdf0e10cSrcweir gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( m_pDialog ), sal_False ); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir // ------------------------------------------------- 101cdf0e10cSrcweir // XEventListener 102cdf0e10cSrcweir // ------------------------------------------------- 103cdf0e10cSrcweir 104cdf0e10cSrcweir void SAL_CALL SalGtkFolderPicker::disposing( const lang::EventObject& ) 105cdf0e10cSrcweir throw( uno::RuntimeException ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir void SAL_CALL SalGtkFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory ) 110cdf0e10cSrcweir throw( lang::IllegalArgumentException, uno::RuntimeException ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir OSL_ASSERT( m_pDialog != NULL ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir OString aTxt = unicodetouri( aDirectory ); 115cdf0e10cSrcweir 116cdf0e10cSrcweir if( aTxt.lastIndexOf('/') == aTxt.getLength() - 1 ) 117cdf0e10cSrcweir aTxt = aTxt.copy( 0, aTxt.getLength() - 1 ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir OSL_TRACE( "setting path to %s\n", aTxt.getStr() ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir GdkThreadLock aLock; 122cdf0e10cSrcweir 123cdf0e10cSrcweir gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ), 124cdf0e10cSrcweir aTxt.getStr() ); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir rtl::OUString SAL_CALL SalGtkFolderPicker::getDisplayDirectory() throw( uno::RuntimeException ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir OSL_ASSERT( m_pDialog != NULL ); 130cdf0e10cSrcweir 131cdf0e10cSrcweir GdkThreadLock aLock; 132cdf0e10cSrcweir 133cdf0e10cSrcweir gchar* pCurrentFolder = 134cdf0e10cSrcweir gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) ); 135cdf0e10cSrcweir ::rtl::OUString aCurrentFolderName = uritounicode(pCurrentFolder); 136cdf0e10cSrcweir g_free( pCurrentFolder ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir return aCurrentFolderName; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir rtl::OUString SAL_CALL SalGtkFolderPicker::getDirectory() throw( uno::RuntimeException ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir return getDisplayDirectory(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir void SAL_CALL SalGtkFolderPicker::setDescription( const rtl::OUString& rDescription ) 147cdf0e10cSrcweir throw( uno::RuntimeException ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir ::rtl::OString aDescription = OUStringToOString( rDescription, RTL_TEXTENCODING_UTF8 ); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir 153cdf0e10cSrcweir 154cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 155cdf0e10cSrcweir // XExecutableDialog functions 156cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 157cdf0e10cSrcweir 158cdf0e10cSrcweir void SAL_CALL SalGtkFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir OSL_ASSERT( m_pDialog != NULL ); 161cdf0e10cSrcweir 162cdf0e10cSrcweir ::rtl::OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 ); 163cdf0e10cSrcweir 164cdf0e10cSrcweir GdkThreadLock aLock; 165cdf0e10cSrcweir gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() ); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir sal_Int16 SAL_CALL SalGtkFolderPicker::execute() throw( uno::RuntimeException ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir OSL_TRACE( "1: HERE WE ARE\n"); 171cdf0e10cSrcweir OSL_ASSERT( m_pDialog != NULL ); 172cdf0e10cSrcweir 173cdf0e10cSrcweir sal_Int16 retVal = 0; 174cdf0e10cSrcweir 175cdf0e10cSrcweir uno::Reference< awt::XExtendedToolkit > xToolkit( 176cdf0e10cSrcweir m_xServiceMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.awt.Toolkit") ), uno::UNO_QUERY); 177cdf0e10cSrcweir 178cdf0e10cSrcweir RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit); 179cdf0e10cSrcweir uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog); 180cdf0e10cSrcweir gint nStatus = pRunDialog->run(); 181cdf0e10cSrcweir switch( nStatus ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir case GTK_RESPONSE_ACCEPT: 184cdf0e10cSrcweir retVal = ExecutableDialogResults::OK; 185cdf0e10cSrcweir break; 186cdf0e10cSrcweir case GTK_RESPONSE_CANCEL: 187cdf0e10cSrcweir retVal = ExecutableDialogResults::CANCEL; 188cdf0e10cSrcweir break; 189cdf0e10cSrcweir default: 190cdf0e10cSrcweir retVal = 0; 191cdf0e10cSrcweir break; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir return retVal; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir //------------------------------------------------------------------------------------ 198cdf0e10cSrcweir // XCancellable 199cdf0e10cSrcweir //------------------------------------------------------------------------------------ 200cdf0e10cSrcweir 201cdf0e10cSrcweir void SAL_CALL SalGtkFolderPicker::cancel() throw( uno::RuntimeException ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir OSL_ASSERT( m_pDialog != NULL ); 204cdf0e10cSrcweir 205cdf0e10cSrcweir // TODO m_pImpl->cancel(); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir // ------------------------------------------------- 209cdf0e10cSrcweir // XServiceInfo 210cdf0e10cSrcweir // ------------------------------------------------- 211cdf0e10cSrcweir 212cdf0e10cSrcweir rtl::OUString SAL_CALL SalGtkFolderPicker::getImplementationName() 213cdf0e10cSrcweir throw( uno::RuntimeException ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir return rtl::OUString::createFromAscii( FOLDER_PICKER_IMPL_NAME ); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir // ------------------------------------------------- 219cdf0e10cSrcweir // XServiceInfo 220cdf0e10cSrcweir // ------------------------------------------------- 221cdf0e10cSrcweir 222cdf0e10cSrcweir sal_Bool SAL_CALL SalGtkFolderPicker::supportsService( const rtl::OUString& ServiceName ) 223cdf0e10cSrcweir throw( uno::RuntimeException ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir uno::Sequence <rtl::OUString> SupportedServicesNames = FolderPicker_getSupportedServiceNames(); 226cdf0e10cSrcweir 227cdf0e10cSrcweir for( sal_Int32 n = SupportedServicesNames.getLength(); n--; ) 228cdf0e10cSrcweir if( SupportedServicesNames[n].compareTo( ServiceName ) == 0) 229cdf0e10cSrcweir return sal_True; 230cdf0e10cSrcweir 231cdf0e10cSrcweir return sal_False; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir // ------------------------------------------------- 235cdf0e10cSrcweir // XServiceInfo 236cdf0e10cSrcweir // ------------------------------------------------- 237cdf0e10cSrcweir 238cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL SalGtkFolderPicker::getSupportedServiceNames() 239cdf0e10cSrcweir throw( uno::RuntimeException ) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir return FolderPicker_getSupportedServiceNames(); 242cdf0e10cSrcweir } 243