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 <com/sun/star/awt/Toolkit.hpp>
27 : #include <com/sun/star/frame/Desktop.hpp>
28 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
29 : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
30 : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
31 : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
32 : #include <osl/diagnose.h>
33 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
34 : #include <com/sun/star/uno/Any.hxx>
35 : #include <osl/mutex.hxx>
36 : #include <vcl/svapp.hxx>
37 : #include "unx/gtk/gtkinst.hxx"
38 : #include "gtk/fpicker/SalGtkFolderPicker.hxx"
39 :
40 : #include <string.h>
41 :
42 : using namespace ::rtl;
43 : using namespace ::com::sun::star;
44 : using namespace ::com::sun::star::ui::dialogs;
45 : using namespace ::com::sun::star::lang;
46 : using namespace ::com::sun::star::uno;
47 :
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, (char *)NULL );
58 :
59 0 : gtk_dialog_set_default_response( GTK_DIALOG (m_pDialog), GTK_RESPONSE_ACCEPT );
60 0 : gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( m_pDialog ), sal_False );
61 0 : gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( m_pDialog ), sal_False );
62 0 : }
63 :
64 : // -------------------------------------------------
65 : // XEventListener
66 : // -------------------------------------------------
67 :
68 0 : void SAL_CALL SalGtkFolderPicker::disposing( const lang::EventObject& )
69 : throw( uno::RuntimeException )
70 : {
71 0 : }
72 :
73 0 : void SAL_CALL SalGtkFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory )
74 : throw( lang::IllegalArgumentException, uno::RuntimeException )
75 : {
76 0 : SolarMutexGuard g;
77 :
78 : OSL_ASSERT( m_pDialog != NULL );
79 :
80 0 : OString aTxt = unicodetouri( aDirectory );
81 :
82 0 : if( !aTxt.isEmpty() && aTxt.lastIndexOf('/') == aTxt.getLength() - 1 )
83 0 : aTxt = aTxt.copy( 0, aTxt.getLength() - 1 );
84 :
85 : OSL_TRACE( "setting path to %s", aTxt.getStr() );
86 :
87 0 : gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ),
88 0 : aTxt.getStr() );
89 0 : }
90 :
91 0 : rtl::OUString SAL_CALL SalGtkFolderPicker::getDisplayDirectory() throw( uno::RuntimeException )
92 : {
93 0 : SolarMutexGuard g;
94 :
95 : OSL_ASSERT( m_pDialog != NULL );
96 :
97 : gchar* pCurrentFolder =
98 0 : gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) );
99 0 : ::rtl::OUString aCurrentFolderName = uritounicode(pCurrentFolder);
100 0 : g_free( pCurrentFolder );
101 :
102 0 : return aCurrentFolderName;
103 : }
104 :
105 0 : rtl::OUString SAL_CALL SalGtkFolderPicker::getDirectory() throw( uno::RuntimeException )
106 : {
107 0 : return getDisplayDirectory();
108 : }
109 :
110 0 : void SAL_CALL SalGtkFolderPicker::setDescription( const rtl::OUString& rDescription )
111 : throw( uno::RuntimeException )
112 : {
113 0 : ::rtl::OString aDescription = OUStringToOString( rDescription, RTL_TEXTENCODING_UTF8 );
114 0 : }
115 :
116 : //-----------------------------------------------------------------------------------------
117 : // XExecutableDialog functions
118 : //-----------------------------------------------------------------------------------------
119 :
120 0 : void SAL_CALL SalGtkFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
121 : {
122 0 : SolarMutexGuard g;
123 :
124 : OSL_ASSERT( m_pDialog != NULL );
125 :
126 0 : ::rtl::OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 );
127 :
128 0 : gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() );
129 0 : }
130 :
131 0 : sal_Int16 SAL_CALL SalGtkFolderPicker::execute() throw( uno::RuntimeException )
132 : {
133 0 : SolarMutexGuard g;
134 :
135 : OSL_TRACE( "1: HERE WE ARE");
136 : OSL_ASSERT( m_pDialog != NULL );
137 :
138 0 : sal_Int16 retVal = 0;
139 :
140 : uno::Reference< awt::XExtendedToolkit > xToolkit(
141 : awt::Toolkit::create(m_xContext),
142 0 : uno::UNO_QUERY);
143 :
144 0 : uno::Reference< frame::XDesktop > xDesktop( frame::Desktop::create(m_xContext), uno::UNO_QUERY);
145 :
146 0 : RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit, xDesktop);
147 0 : uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog);
148 0 : gint nStatus = pRunDialog->run();
149 0 : switch( nStatus )
150 : {
151 : case GTK_RESPONSE_ACCEPT:
152 0 : retVal = ExecutableDialogResults::OK;
153 0 : break;
154 : case GTK_RESPONSE_CANCEL:
155 0 : retVal = ExecutableDialogResults::CANCEL;
156 0 : break;
157 : default:
158 0 : retVal = 0;
159 0 : break;
160 : }
161 :
162 0 : return retVal;
163 : }
164 :
165 : //------------------------------------------------------------------------------------
166 : // XCancellable
167 : //------------------------------------------------------------------------------------
168 :
169 0 : void SAL_CALL SalGtkFolderPicker::cancel() throw( uno::RuntimeException )
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 : }
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|