Update ooo320-m1
[ooovba.git] / fpicker / source / unx / gnome / SalGtkFolderPicker.cxx
bloba19f1cc29dffe5d10baddea70fb7470915a89367
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SalGtkFolderPicker.cxx,v $
10 * $Revision: 1.11.42.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
34 //------------------------------------------------------------------------
35 // includes
36 //------------------------------------------------------------------------
37 #include <com/sun/star/lang/DisposedException.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
40 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
41 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
42 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
43 #include <cppuhelper/interfacecontainer.h>
44 #include <osl/diagnose.h>
45 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
46 #include <com/sun/star/uno/Any.hxx>
47 #include <FPServiceInfo.hxx>
48 #include <vos/mutex.hxx>
49 #include <vcl/svapp.hxx>
50 #include "SalGtkFolderPicker.hxx"
52 #include <tools/urlobj.hxx>
54 #include <iostream>
55 #include "resourceprovider.hxx"
56 #ifndef _SV_RC_H
57 #include <tools/rc.hxx>
58 #endif
60 //------------------------------------------------------------------------
61 // namespace directives
62 //------------------------------------------------------------------------
64 using namespace ::rtl;
65 using namespace ::com::sun::star;
66 using namespace ::com::sun::star::ui::dialogs;
67 using namespace ::com::sun::star::lang;
68 using namespace ::com::sun::star::uno;
70 //------------------------------------------------------------------------
71 // helper functions
72 //------------------------------------------------------------------------
74 namespace
76 // controling event notifications
77 uno::Sequence<rtl::OUString> SAL_CALL FolderPicker_getSupportedServiceNames()
79 uno::Sequence<rtl::OUString> aRet(2);
80 aRet[0] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.SystemFolderPicker" );
81 aRet[1] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.GtkFolderPicker" );
82 return aRet;
86 //-----------------------------------------------------------------------------------------
87 // constructor
88 //-----------------------------------------------------------------------------------------
89 SalGtkFolderPicker::SalGtkFolderPicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) :
90 m_xServiceMgr( xServiceMgr )
92 CResourceProvider aResProvider;
93 m_pDialog = gtk_file_chooser_dialog_new(
94 OUStringToOString( aResProvider.getResString( FOLDERPICKER_TITLE ), RTL_TEXTENCODING_UTF8 ).getStr(),
95 NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
96 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, (char *)NULL );
98 gtk_dialog_set_default_response( GTK_DIALOG (m_pDialog), GTK_RESPONSE_ACCEPT );
99 gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( m_pDialog ), FALSE );
100 gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( m_pDialog ), FALSE );
103 // -------------------------------------------------
104 // XEventListener
105 // -------------------------------------------------
107 void SAL_CALL SalGtkFolderPicker::disposing( const lang::EventObject& )
108 throw( uno::RuntimeException )
112 void SAL_CALL SalGtkFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory )
113 throw( lang::IllegalArgumentException, uno::RuntimeException )
115 OSL_ASSERT( m_pDialog != NULL );
116 ::vos::OGuard aGuard( Application::GetSolarMutex() );
118 OString aTxt = unicodetouri( aDirectory );
120 if( aTxt.lastIndexOf('/') == aTxt.getLength() - 1 )
121 aTxt = aTxt.copy( 0, aTxt.getLength() - 1 );
123 OSL_TRACE( "setting path to %s\n", aTxt.getStr() );
125 gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ),
126 aTxt.getStr() );
129 rtl::OUString SAL_CALL SalGtkFolderPicker::getDisplayDirectory() throw( uno::RuntimeException )
131 OSL_ASSERT( m_pDialog != NULL );
132 ::vos::OGuard aGuard( Application::GetSolarMutex() );
134 gchar* pCurrentFolder =
135 gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) );
136 ::rtl::OUString aCurrentFolderName = uritounicode(pCurrentFolder);
137 g_free( pCurrentFolder );
139 return aCurrentFolderName;
142 rtl::OUString SAL_CALL SalGtkFolderPicker::getDirectory() throw( uno::RuntimeException )
144 return getDisplayDirectory();
147 void SAL_CALL SalGtkFolderPicker::setDescription( const rtl::OUString& rDescription )
148 throw( uno::RuntimeException )
150 ::rtl::OString aDescription = OUStringToOString( rDescription, RTL_TEXTENCODING_UTF8 );
155 //-----------------------------------------------------------------------------------------
156 // XExecutableDialog functions
157 //-----------------------------------------------------------------------------------------
159 void SAL_CALL SalGtkFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
161 OSL_ASSERT( m_pDialog != NULL );
162 ::vos::OGuard aGuard( Application::GetSolarMutex() );
164 ::rtl::OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 );
165 gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() );
168 sal_Int16 SAL_CALL SalGtkFolderPicker::execute() throw( uno::RuntimeException )
170 OSL_TRACE( "1: HERE WE ARE\n");
171 OSL_ASSERT( m_pDialog != NULL );
172 ::vos::OGuard aGuard( Application::GetSolarMutex() );
174 sal_Int16 retVal = 0;
176 uno::Reference< awt::XExtendedToolkit > xToolkit(
177 m_xServiceMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.awt.Toolkit") ), uno::UNO_QUERY);
179 RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit);
180 uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog);
181 gint nStatus = pRunDialog->run();
182 switch( nStatus )
184 case GTK_RESPONSE_ACCEPT:
185 retVal = ExecutableDialogResults::OK;
186 break;
187 case GTK_RESPONSE_CANCEL:
188 retVal = ExecutableDialogResults::CANCEL;
189 break;
190 default:
191 retVal = 0;
192 break;
195 return retVal;
198 //------------------------------------------------------------------------------------
199 // XCancellable
200 //------------------------------------------------------------------------------------
202 void SAL_CALL SalGtkFolderPicker::cancel() throw( uno::RuntimeException )
204 OSL_ASSERT( m_pDialog != NULL );
205 ::vos::OGuard aGuard( Application::GetSolarMutex() );
207 // TODO m_pImpl->cancel();
210 // -------------------------------------------------
211 // XServiceInfo
212 // -------------------------------------------------
214 rtl::OUString SAL_CALL SalGtkFolderPicker::getImplementationName()
215 throw( uno::RuntimeException )
217 return rtl::OUString::createFromAscii( FOLDER_PICKER_IMPL_NAME );
220 // -------------------------------------------------
221 // XServiceInfo
222 // -------------------------------------------------
224 sal_Bool SAL_CALL SalGtkFolderPicker::supportsService( const rtl::OUString& ServiceName )
225 throw( uno::RuntimeException )
227 uno::Sequence <rtl::OUString> SupportedServicesNames = FolderPicker_getSupportedServiceNames();
229 for( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
230 if( SupportedServicesNames[n].compareTo( ServiceName ) == 0)
231 return sal_True;
233 return sal_False;
236 // -------------------------------------------------
237 // XServiceInfo
238 // -------------------------------------------------
240 uno::Sequence<rtl::OUString> SAL_CALL SalGtkFolderPicker::getSupportedServiceNames()
241 throw( uno::RuntimeException )
243 return FolderPicker_getSupportedServiceNames();