1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <com/sun/star/lang/DisposedException.hpp>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
23 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
24 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
25 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
26 #include <cppuhelper/interfacecontainer.h>
27 #include <osl/diagnose.h>
28 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <FPServiceInfo.hxx>
31 #include <osl/mutex.hxx>
32 #include <vcl/svapp.hxx>
33 #include "SalAquaFolderPicker.hxx"
37 #include "resourceprovider.hxx"
39 #include <osl/file.hxx>
40 #include "CFStringUtilities.hxx"
41 #include "NSString_OOoAdditions.hxx"
42 #include "NSURL_OOoAdditions.hxx"
45 #define CLASS_NAME "SalAquaFolderPicker"
47 //------------------------------------------------------------------------
48 // namespace directives
49 //------------------------------------------------------------------------
51 using namespace ::rtl;
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::ui::dialogs;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::uno;
57 //------------------------------------------------------------------------
59 //------------------------------------------------------------------------
63 // controling event notifications
64 uno::Sequence<rtl::OUString> SAL_CALL FolderPicker_getSupportedServiceNames()
66 uno::Sequence<rtl::OUString> aRet(2);
67 aRet[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.SystemFolderPicker" ));
68 aRet[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.AquaFolderPicker" ));
73 //-----------------------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------------------
76 SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) :
77 m_xServiceMgr( xServiceMgr )
79 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
81 m_nDialogType = NAVIGATIONSERVICES_DIRECTORY;
83 DBG_PRINT_EXIT(CLASS_NAME, __func__);
86 //-----------------------------------------------------------------------------------------
87 // XExecutableDialog functions
88 //-----------------------------------------------------------------------------------------
90 void SAL_CALL SalAquaFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
92 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle);
94 SolarMutexGuard aGuard;
98 DBG_PRINT_EXIT(CLASS_NAME, __func__);
101 sal_Int16 SAL_CALL SalAquaFolderPicker::execute() throw( uno::RuntimeException )
103 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
105 SolarMutexGuard aGuard;
107 sal_Int16 retVal = 0;
109 int nResult = runandwaitforresult();
114 OSL_TRACE("Dialog returned with OK");
115 retVal = ExecutableDialogResults::OK;
119 OSL_TRACE("Dialog was cancelled!");
120 retVal = ExecutableDialogResults::CANCEL;
124 throw uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The dialog returned with an unknown result!")), static_cast< cppu::OWeakObject * >( this ));
128 DBG_PRINT_EXIT(CLASS_NAME, __func__);
132 //------------------------------------------------------------------------------------
133 // XFolderPicker functions
134 //------------------------------------------------------------------------------------
136 void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory )
137 throw( lang::IllegalArgumentException, uno::RuntimeException )
139 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", aDirectory);
141 SolarMutexGuard aGuard;
143 implsetDisplayDirectory(aDirectory);
145 DBG_PRINT_EXIT(CLASS_NAME, __func__);
148 rtl::OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory() throw( uno::RuntimeException )
150 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
152 SolarMutexGuard aGuard;
154 OUString aDirectory = implgetDisplayDirectory();
156 DBG_PRINT_EXIT(CLASS_NAME, __func__, aDirectory);
161 rtl::OUString SAL_CALL SalAquaFolderPicker::getDirectory() throw( uno::RuntimeException )
163 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
165 SolarMutexGuard aGuard;
167 NSArray *files = nil;
168 if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) {
169 files = [(NSOpenPanel*)m_pDialog URLs];
172 long nFiles = [files count];
173 OSL_TRACE("# of items: %d", nFiles);
176 throw uno::RuntimeException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("no directory selected")), static_cast< cppu::OWeakObject * >( this ));
179 rtl::OUString aDirectory;
181 NSURL *url = [files objectAtIndex:0];
182 OSL_TRACE("handling %s", [[url description] UTF8String]);
184 aDirectory = [url OUStringForInfo:FULLPATH];
186 implsetDisplayDirectory(aDirectory);
188 OSL_TRACE("dir url: %s", OUStringToOString(aDirectory, RTL_TEXTENCODING_UTF8).getStr());
190 DBG_PRINT_EXIT(CLASS_NAME, __func__);
194 void SAL_CALL SalAquaFolderPicker::setDescription( const rtl::OUString& rDescription )
195 throw( uno::RuntimeException )
197 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "description", rDescription);
199 [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
201 DBG_PRINT_EXIT(CLASS_NAME, __func__);
204 // -------------------------------------------------
206 // -------------------------------------------------
208 rtl::OUString SAL_CALL SalAquaFolderPicker::getImplementationName()
209 throw( uno::RuntimeException )
211 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
213 rtl::OUString retVal(RTL_CONSTASCII_USTRINGPARAM( FOLDER_PICKER_IMPL_NAME ));
215 DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
220 sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const rtl::OUString& sServiceName )
221 throw( uno::RuntimeException )
223 DBG_PRINT_ENTRY(CLASS_NAME, __func__, "serviceName", sServiceName);
225 sal_Bool retVal = sal_False;
226 uno::Sequence <rtl::OUString> supportedServicesNames = FolderPicker_getSupportedServiceNames();
228 for( sal_Int32 n = supportedServicesNames.getLength(); n--; ) {
229 if( supportedServicesNames[n] == sServiceName ) {
235 DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
239 uno::Sequence<rtl::OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
240 throw( uno::RuntimeException )
242 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
243 DBG_PRINT_EXIT(CLASS_NAME, __func__);
245 return FolderPicker_getSupportedServiceNames();
248 //------------------------------------------------------------------------------------
250 //------------------------------------------------------------------------------------
252 void SAL_CALL SalAquaFolderPicker::cancel() throw( uno::RuntimeException )
254 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
256 SolarMutexGuard aGuard;
258 [m_pDialog cancel:nil];
260 DBG_PRINT_EXIT(CLASS_NAME, __func__);
263 // -------------------------------------------------
265 // -------------------------------------------------
267 void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
268 throw( uno::RuntimeException )
270 DBG_PRINT_ENTRY(CLASS_NAME, __func__);
271 DBG_PRINT_EXIT(CLASS_NAME, __func__);
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */