Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / fpicker / source / aqua / SalAquaFolderPicker.mm
blob31cd0e16e8e0421a36232e60b381b104b122b28d
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  */
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 <cppuhelper/supportsservice.hxx>
28 #include <osl/diagnose.h>
29 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <FPServiceInfo.hxx>
32 #include <osl/mutex.hxx>
33 #include <vcl/svapp.hxx>
34 #include "SalAquaFolderPicker.hxx"
36 #include <iostream>
38 #include "resourceprovider.hxx"
40 #include <osl/file.hxx>
41 #include "CFStringUtilities.hxx"
42 #include "NSString_OOoAdditions.hxx"
43 #include "NSURL_OOoAdditions.hxx"
45 #pragma mark DEFINES
46 #define CLASS_NAME "SalAquaFolderPicker"
49 // namespace directives
52 using namespace ::rtl;
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::ui::dialogs;
55 using namespace ::com::sun::star::lang;
56 using namespace ::com::sun::star::uno;
59 // helper functions
62 namespace
64     // controlling event notifications
65     uno::Sequence<rtl::OUString> SAL_CALL FolderPicker_getSupportedServiceNames()
66     {
67         uno::Sequence<rtl::OUString> aRet(2);
68         aRet[0] = "com.sun.star.ui.dialogs.SystemFolderPicker";
69         aRet[1] = "com.sun.star.ui.dialogs.AquaFolderPicker";
70         return aRet;
71     }
75 // constructor
77 SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) :
78     m_xServiceMgr( xServiceMgr )
80     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
82     m_nDialogType = NAVIGATIONSERVICES_DIRECTORY;
84     DBG_PRINT_EXIT(CLASS_NAME, __func__);
88 // XExecutableDialog functions
91 void SAL_CALL SalAquaFolderPicker::setTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
93     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "title", aTitle);
95     SolarMutexGuard aGuard;
97     implsetTitle(aTitle);
99     DBG_PRINT_EXIT(CLASS_NAME, __func__);
102 sal_Int16 SAL_CALL SalAquaFolderPicker::execute() throw( uno::RuntimeException )
104     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
106     SolarMutexGuard aGuard;
108     sal_Int16 retVal = 0;
110     int nResult = runandwaitforresult();
112     switch( nResult )
113     {
114     case NSOKButton:
115         OSL_TRACE("Dialog returned with OK");
116         retVal = ExecutableDialogResults::OK;
117         break;
119     case NSCancelButton:
120         OSL_TRACE("Dialog was cancelled!");
121         retVal = ExecutableDialogResults::CANCEL;
122         break;
124     default:
125         throw uno::RuntimeException(OUString("The dialog returned with an unknown result!"), static_cast< cppu::OWeakObject * >( this ));
126         break;
127     }
129     DBG_PRINT_EXIT(CLASS_NAME, __func__);
130     return retVal;
134 // XFolderPicker functions
137 void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory )
138     throw( lang::IllegalArgumentException, uno::RuntimeException )
140     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", aDirectory);
142     SolarMutexGuard aGuard;
144     implsetDisplayDirectory(aDirectory);
146     DBG_PRINT_EXIT(CLASS_NAME, __func__);
149 rtl::OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory() throw( uno::RuntimeException )
151     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
153     SolarMutexGuard aGuard;
155     OUString aDirectory = implgetDisplayDirectory();
157     DBG_PRINT_EXIT(CLASS_NAME, __func__, aDirectory);
159     return aDirectory;
162 rtl::OUString SAL_CALL SalAquaFolderPicker::getDirectory() throw( uno::RuntimeException )
164     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
166     SolarMutexGuard aGuard;
168     NSArray *files = nil;
169     if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) {
170         files = [(NSOpenPanel*)m_pDialog URLs];
171     }
173     long nFiles = [files count];
174     OSL_TRACE("# of items: %d", nFiles);
176     if (nFiles < 1) {
177         throw uno::RuntimeException(OUString("no directory selected"), static_cast< cppu::OWeakObject * >( this ));
178     }
180     rtl::OUString aDirectory;
182     NSURL *url = [files objectAtIndex:0];
183     OSL_TRACE("handling %s", [[url description] UTF8String]);
185     aDirectory = [url OUStringForInfo:FULLPATH];
187     implsetDisplayDirectory(aDirectory);
189     OSL_TRACE("dir url: %s", OUStringToOString(aDirectory, RTL_TEXTENCODING_UTF8).getStr());
191     DBG_PRINT_EXIT(CLASS_NAME, __func__);
192     return aDirectory;
195 void SAL_CALL SalAquaFolderPicker::setDescription( const rtl::OUString& rDescription )
196     throw( uno::RuntimeException )
198     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "description", rDescription);
200     [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
202     DBG_PRINT_EXIT(CLASS_NAME, __func__);
206 // XServiceInfo
209 rtl::OUString SAL_CALL SalAquaFolderPicker::getImplementationName()
210     throw( uno::RuntimeException )
212     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
214     rtl::OUString retVal( FOLDER_PICKER_IMPL_NAME );
216     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
218     return retVal;
221 sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const rtl::OUString& sServiceName )
222     throw( uno::RuntimeException )
224     return cppu::supportsService(this, sServiceName);
227 uno::Sequence<rtl::OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
228     throw( uno::RuntimeException )
230     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
231     DBG_PRINT_EXIT(CLASS_NAME, __func__);
233     return FolderPicker_getSupportedServiceNames();
237 // XCancellable
240 void SAL_CALL SalAquaFolderPicker::cancel() throw( uno::RuntimeException )
242     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
244     SolarMutexGuard aGuard;
246     [m_pDialog cancel:nil];
248     DBG_PRINT_EXIT(CLASS_NAME, __func__);
252 // XEventListener
255 void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
256     throw( uno::RuntimeException )
258     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
259     DBG_PRINT_EXIT(CLASS_NAME, __func__);
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */