Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / unx / gtk / fpicker / SalGtkFolderPicker.cxx
blobbf90682c93f9efe000dc9366f5946c0129f8f051
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifdef AIX
21 #define _LINUX_SOURCE_COMPAT
22 #include <sys/timer.h>
23 #undef _LINUX_SOURCE_COMPAT
24 #endif
26 #include <config_vclplug.h>
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"
42 #include <string.h>
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;
49 // constructor
51 SalGtkFolderPicker::SalGtkFolderPicker( const uno::Reference< uno::XComponentContext >& xContext ) :
52 SalGtkPicker( xContext )
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 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, (char *)NULL );
59 gtk_dialog_set_default_response( GTK_DIALOG (m_pDialog), GTK_RESPONSE_ACCEPT );
60 #if ENABLE_GNOME_VFS || ENABLE_GIO
61 gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( m_pDialog ), false );
62 #endif
63 gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( m_pDialog ), false );
66 void SAL_CALL SalGtkFolderPicker::setDisplayDirectory( const OUString& aDirectory )
67 throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
69 SolarMutexGuard g;
71 OSL_ASSERT( m_pDialog != NULL );
73 OString aTxt = unicodetouri( aDirectory );
74 if( aTxt.isEmpty() ){
75 aTxt = unicodetouri(OUString("file:///."));
78 if( aTxt.endsWith("/") )
79 aTxt = aTxt.copy( 0, aTxt.getLength() - 1 );
81 OSL_TRACE( "setting path to %s", aTxt.getStr() );
83 gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ),
84 aTxt.getStr() );
87 OUString SAL_CALL SalGtkFolderPicker::getDisplayDirectory() throw( uno::RuntimeException, std::exception )
89 SolarMutexGuard g;
91 OSL_ASSERT( m_pDialog != NULL );
93 gchar* pCurrentFolder =
94 gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) );
95 OUString aCurrentFolderName = uritounicode(pCurrentFolder);
96 g_free( pCurrentFolder );
98 return aCurrentFolderName;
101 OUString SAL_CALL SalGtkFolderPicker::getDirectory() throw( uno::RuntimeException, std::exception )
103 SolarMutexGuard g;
105 OSL_ASSERT( m_pDialog != NULL );
107 gchar* pSelectedFolder =
108 gtk_file_chooser_get_uri( GTK_FILE_CHOOSER( m_pDialog ) );
109 OUString aSelectedFolderName = uritounicode(pSelectedFolder);
110 g_free( pSelectedFolder );
112 return aSelectedFolderName;
115 void SAL_CALL SalGtkFolderPicker::setDescription( const OUString& /*rDescription*/ )
116 throw( uno::RuntimeException, std::exception )
120 // XExecutableDialog functions
122 void SAL_CALL SalGtkFolderPicker::setTitle( const OUString& aTitle ) throw( uno::RuntimeException, std::exception )
124 SolarMutexGuard g;
126 OSL_ASSERT( m_pDialog != NULL );
128 OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 );
130 gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() );
133 sal_Int16 SAL_CALL SalGtkFolderPicker::execute() throw( uno::RuntimeException, std::exception )
135 SolarMutexGuard g;
137 OSL_TRACE( "1: HERE WE ARE");
138 OSL_ASSERT( m_pDialog != NULL );
140 sal_Int16 retVal = 0;
142 uno::Reference< awt::XExtendedToolkit > xToolkit(
143 awt::Toolkit::create(m_xContext),
144 uno::UNO_QUERY);
146 uno::Reference< frame::XDesktop > xDesktop( frame::Desktop::create(m_xContext), uno::UNO_QUERY);
148 GtkWindow *pParent = RunDialog::GetTransientFor();
149 if (pParent)
150 gtk_window_set_transient_for(GTK_WINDOW(m_pDialog), pParent);
151 RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit, xDesktop);
152 uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog);
153 gint nStatus = pRunDialog->run();
154 switch( nStatus )
156 case GTK_RESPONSE_ACCEPT:
157 retVal = ExecutableDialogResults::OK;
158 break;
159 case GTK_RESPONSE_CANCEL:
160 retVal = ExecutableDialogResults::CANCEL;
161 break;
162 default:
163 retVal = 0;
164 break;
167 return retVal;
170 // XCancellable
172 void SAL_CALL SalGtkFolderPicker::cancel() throw( uno::RuntimeException, std::exception )
174 SolarMutexGuard g;
176 OSL_ASSERT( m_pDialog != NULL );
178 // TODO m_pImpl->cancel();
181 uno::Reference< ui::dialogs::XFolderPicker2 >
182 GtkInstance::createFolderPicker( const uno::Reference< uno::XComponentContext > &xMSF )
184 return uno::Reference< ui::dialogs::XFolderPicker2 >(
185 new SalGtkFolderPicker( xMSF ) );
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */