Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifdef AIX
21 : #define _LINUX_SOURCE_COMPAT
22 : #include <sys/timer.h>
23 : #undef _LINUX_SOURCE_COMPAT
24 : #endif
25 :
26 : #include <config_vclplug.h>
27 :
28 : #include <com/sun/star/awt/Toolkit.hpp>
29 : #include <com/sun/star/frame/Desktop.hpp>
30 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
31 : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
32 : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
33 : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
34 : #include <osl/diagnose.h>
35 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
36 : #include <com/sun/star/uno/Any.hxx>
37 : #include <osl/mutex.hxx>
38 : #include <vcl/svapp.hxx>
39 : #include "unx/gtk/gtkinst.hxx"
40 : #include "gtk/fpicker/SalGtkFolderPicker.hxx"
41 :
42 : #include <string.h>
43 :
44 : using namespace ::com::sun::star;
45 : using namespace ::com::sun::star::ui::dialogs;
46 : using namespace ::com::sun::star::lang;
47 : using namespace ::com::sun::star::uno;
48 :
49 : // constructor
50 :
51 0 : SalGtkFolderPicker::SalGtkFolderPicker( const uno::Reference< uno::XComponentContext >& xContext ) :
52 0 : SalGtkPicker( xContext )
53 : {
54 : m_pDialog = gtk_file_chooser_dialog_new(
55 : OUStringToOString( getResString( FOLDERPICKER_TITLE ), RTL_TEXTENCODING_UTF8 ).getStr(),
56 : NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
57 0 : GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, nullptr );
58 :
59 0 : gtk_dialog_set_default_response( GTK_DIALOG (m_pDialog), GTK_RESPONSE_ACCEPT );
60 : #if ENABLE_GNOME_VFS || ENABLE_GIO
61 0 : gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( m_pDialog ), false );
62 : #endif
63 0 : gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( m_pDialog ), false );
64 0 : }
65 :
66 0 : void SAL_CALL SalGtkFolderPicker::setDisplayDirectory( const OUString& aDirectory )
67 : throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
68 : {
69 0 : SolarMutexGuard g;
70 :
71 : OSL_ASSERT( m_pDialog != NULL );
72 :
73 0 : OString aTxt = unicodetouri( aDirectory );
74 0 : if( aTxt.isEmpty() ){
75 0 : aTxt = unicodetouri(OUString("file:///."));
76 : }
77 :
78 0 : if( aTxt.endsWith("/") )
79 0 : aTxt = aTxt.copy( 0, aTxt.getLength() - 1 );
80 :
81 : OSL_TRACE( "setting path to %s", aTxt.getStr() );
82 :
83 0 : gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ),
84 0 : aTxt.getStr() );
85 0 : }
86 :
87 0 : OUString SAL_CALL SalGtkFolderPicker::getDisplayDirectory() throw( uno::RuntimeException, std::exception )
88 : {
89 0 : SolarMutexGuard g;
90 :
91 : OSL_ASSERT( m_pDialog != NULL );
92 :
93 : gchar* pCurrentFolder =
94 0 : gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) );
95 0 : OUString aCurrentFolderName = uritounicode(pCurrentFolder);
96 0 : g_free( pCurrentFolder );
97 :
98 0 : return aCurrentFolderName;
99 : }
100 :
101 0 : OUString SAL_CALL SalGtkFolderPicker::getDirectory() throw( uno::RuntimeException, std::exception )
102 : {
103 0 : SolarMutexGuard g;
104 :
105 : OSL_ASSERT( m_pDialog != NULL );
106 :
107 : gchar* pSelectedFolder =
108 0 : gtk_file_chooser_get_uri( GTK_FILE_CHOOSER( m_pDialog ) );
109 0 : OUString aSelectedFolderName = uritounicode(pSelectedFolder);
110 0 : g_free( pSelectedFolder );
111 :
112 0 : return aSelectedFolderName;
113 : }
114 :
115 0 : void SAL_CALL SalGtkFolderPicker::setDescription( const OUString& /*rDescription*/ )
116 : throw( uno::RuntimeException, std::exception )
117 : {
118 0 : }
119 :
120 : // XExecutableDialog functions
121 :
122 0 : void SAL_CALL SalGtkFolderPicker::setTitle( const OUString& aTitle ) throw( uno::RuntimeException, std::exception )
123 : {
124 0 : SolarMutexGuard g;
125 :
126 : OSL_ASSERT( m_pDialog != NULL );
127 :
128 0 : OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 );
129 :
130 0 : gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() );
131 0 : }
132 :
133 0 : sal_Int16 SAL_CALL SalGtkFolderPicker::execute() throw( uno::RuntimeException, std::exception )
134 : {
135 0 : SolarMutexGuard g;
136 :
137 : OSL_TRACE( "1: HERE WE ARE");
138 : OSL_ASSERT( m_pDialog != NULL );
139 :
140 0 : sal_Int16 retVal = 0;
141 :
142 : uno::Reference< awt::XExtendedToolkit > xToolkit(
143 : awt::Toolkit::create(m_xContext),
144 0 : uno::UNO_QUERY);
145 :
146 0 : uno::Reference< frame::XDesktop > xDesktop( frame::Desktop::create(m_xContext), uno::UNO_QUERY);
147 :
148 0 : RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit, xDesktop);
149 0 : uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog);
150 0 : gint nStatus = pRunDialog->run();
151 0 : switch( nStatus )
152 : {
153 : case GTK_RESPONSE_ACCEPT:
154 0 : retVal = ExecutableDialogResults::OK;
155 0 : break;
156 : case GTK_RESPONSE_CANCEL:
157 0 : retVal = ExecutableDialogResults::CANCEL;
158 0 : break;
159 : default:
160 0 : retVal = 0;
161 0 : break;
162 : }
163 :
164 0 : return retVal;
165 : }
166 :
167 : // XCancellable
168 :
169 0 : void SAL_CALL SalGtkFolderPicker::cancel() throw( uno::RuntimeException, std::exception )
170 : {
171 0 : SolarMutexGuard g;
172 :
173 0 : OSL_ASSERT( m_pDialog != NULL );
174 :
175 : // TODO m_pImpl->cancel();
176 0 : }
177 :
178 : uno::Reference< ui::dialogs::XFolderPicker2 >
179 0 : GtkInstance::createFolderPicker( const uno::Reference< uno::XComponentContext > &xMSF )
180 : {
181 : return uno::Reference< ui::dialogs::XFolderPicker2 >(
182 0 : new SalGtkFolderPicker( xMSF ) );
183 9 : }
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|