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 // controlling event notifications
FolderPicker_getSupportedServiceNames()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 //-----------------------------------------------------------------------------------------
SalGtkFolderPicker(const uno::Reference<lang::XMultiServiceFactory> & xServiceMgr)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
disposing(const lang::EventObject &)104 void SAL_CALL SalGtkFolderPicker::disposing( const lang::EventObject& )
105 {
106 }
107
setDisplayDirectory(const rtl::OUString & aDirectory)108 void SAL_CALL SalGtkFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory )
109 {
110 OSL_ASSERT( m_pDialog != NULL );
111
112 OString aTxt = unicodetouri( aDirectory );
113
114 if( aTxt.lastIndexOf('/') == aTxt.getLength() - 1 )
115 aTxt = aTxt.copy( 0, aTxt.getLength() - 1 );
116
117 OSL_TRACE( "setting path to %s\n", aTxt.getStr() );
118
119 GdkThreadLock aLock;
120
121 gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ),
122 aTxt.getStr() );
123 }
124
getDisplayDirectory()125 rtl::OUString SAL_CALL SalGtkFolderPicker::getDisplayDirectory()
126 {
127 OSL_ASSERT( m_pDialog != NULL );
128
129 GdkThreadLock aLock;
130
131 gchar* pCurrentFolder =
132 gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) );
133 ::rtl::OUString aCurrentFolderName = uritounicode(pCurrentFolder);
134 g_free( pCurrentFolder );
135
136 return aCurrentFolderName;
137 }
138
getDirectory()139 rtl::OUString SAL_CALL SalGtkFolderPicker::getDirectory()
140 {
141 return getDisplayDirectory();
142 }
143
setDescription(const rtl::OUString & rDescription)144 void SAL_CALL SalGtkFolderPicker::setDescription( const rtl::OUString& rDescription )
145 {
146 ::rtl::OString aDescription = OUStringToOString( rDescription, RTL_TEXTENCODING_UTF8 );
147 }
148
149
150
151 //-----------------------------------------------------------------------------------------
152 // XExecutableDialog functions
153 //-----------------------------------------------------------------------------------------
154
setTitle(const rtl::OUString & aTitle)155 void SAL_CALL SalGtkFolderPicker::setTitle( const rtl::OUString& aTitle )
156 {
157 OSL_ASSERT( m_pDialog != NULL );
158
159 ::rtl::OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 );
160
161 GdkThreadLock aLock;
162 gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() );
163 }
164
execute()165 sal_Int16 SAL_CALL SalGtkFolderPicker::execute()
166 {
167 OSL_TRACE( "1: HERE WE ARE\n");
168 OSL_ASSERT( m_pDialog != NULL );
169
170 sal_Int16 retVal = 0;
171
172 uno::Reference< awt::XExtendedToolkit > xToolkit(
173 m_xServiceMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.awt.Toolkit") ), uno::UNO_QUERY);
174
175 RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit);
176 uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog);
177 gint nStatus = pRunDialog->run();
178 switch( nStatus )
179 {
180 case GTK_RESPONSE_ACCEPT:
181 retVal = ExecutableDialogResults::OK;
182 break;
183 case GTK_RESPONSE_CANCEL:
184 retVal = ExecutableDialogResults::CANCEL;
185 break;
186 default:
187 retVal = 0;
188 break;
189 }
190
191 return retVal;
192 }
193
194 //------------------------------------------------------------------------------------
195 // XCancellable
196 //------------------------------------------------------------------------------------
197
cancel()198 void SAL_CALL SalGtkFolderPicker::cancel()
199 {
200 OSL_ASSERT( m_pDialog != NULL );
201
202 // TODO m_pImpl->cancel();
203 }
204
205 // -------------------------------------------------
206 // XServiceInfo
207 // -------------------------------------------------
208
getImplementationName()209 rtl::OUString SAL_CALL SalGtkFolderPicker::getImplementationName()
210 {
211 return rtl::OUString::createFromAscii( FOLDER_PICKER_IMPL_NAME );
212 }
213
214 // -------------------------------------------------
215 // XServiceInfo
216 // -------------------------------------------------
217
supportsService(const rtl::OUString & ServiceName)218 sal_Bool SAL_CALL SalGtkFolderPicker::supportsService( const rtl::OUString& ServiceName )
219 {
220 uno::Sequence <rtl::OUString> SupportedServicesNames = FolderPicker_getSupportedServiceNames();
221
222 for( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
223 if( SupportedServicesNames[n].compareTo( ServiceName ) == 0)
224 return sal_True;
225
226 return sal_False;
227 }
228
229 // -------------------------------------------------
230 // XServiceInfo
231 // -------------------------------------------------
232
getSupportedServiceNames()233 uno::Sequence<rtl::OUString> SAL_CALL SalGtkFolderPicker::getSupportedServiceNames()
234 {
235 return FolderPicker_getSupportedServiceNames();
236 }
237