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