update emoji autocorrect entries from po-files
[LibreOffice.git] / fpicker / source / aqua / SalAquaFolderPicker.mm
bloba597913641fe69254cd32bbebf576c870eb20b08
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 ::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;
58 // helper functions
61 namespace
63     // controlling event notifications
64     uno::Sequence<rtl::OUString> SAL_CALL FolderPicker_getSupportedServiceNames()
65     {
66         uno::Sequence<rtl::OUString> aRet(2);
67         aRet[0] = "com.sun.star.ui.dialogs.SystemFolderPicker";
68         aRet[1] = "com.sun.star.ui.dialogs.AquaFolderPicker";
69         return aRet;
70     }
74 // constructor
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__);
87 // XExecutableDialog functions
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;
96     implsetTitle(aTitle);
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();
111     switch( nResult )
112     {
113 #if MACOSX_SDK_VERSION >= 101000
114     case NSModalResponseOK:
115 #else
116     case NSOKButton:
117 #endif
118         OSL_TRACE("Dialog returned with OK");
119         retVal = ExecutableDialogResults::OK;
120         break;
122 #if MACOSX_SDK_VERSION >= 101000
123     case NSModalResponseCancel:
124 #else
125     case NSCancelButton:
126 #endif
127         OSL_TRACE("Dialog was cancelled!");
128         retVal = ExecutableDialogResults::CANCEL;
129         break;
131     default:
132         throw uno::RuntimeException("The dialog returned with an unknown result!", static_cast< cppu::OWeakObject * >( this ));
133         break;
134     }
136     DBG_PRINT_EXIT(CLASS_NAME, __func__);
137     return retVal;
141 // XFolderPicker functions
144 void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const rtl::OUString& aDirectory )
145     throw( lang::IllegalArgumentException, uno::RuntimeException )
147     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "directory", aDirectory);
149     SolarMutexGuard aGuard;
151     implsetDisplayDirectory(aDirectory);
153     DBG_PRINT_EXIT(CLASS_NAME, __func__);
156 rtl::OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory() throw( uno::RuntimeException )
158     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
160     SolarMutexGuard aGuard;
162     OUString aDirectory = implgetDisplayDirectory();
164     DBG_PRINT_EXIT(CLASS_NAME, __func__, aDirectory);
166     return aDirectory;
169 rtl::OUString SAL_CALL SalAquaFolderPicker::getDirectory() throw( uno::RuntimeException )
171     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
173     SolarMutexGuard aGuard;
175     NSArray *files = nil;
176     if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) {
177         files = [(NSOpenPanel*)m_pDialog URLs];
178     }
180     long nFiles = [files count];
181     SAL_INFO("fpicker.aqua", "# of items: " << nFiles);
183     if (nFiles < 1) {
184         throw uno::RuntimeException("no directory selected", static_cast< cppu::OWeakObject * >( this ));
185     }
187     rtl::OUString aDirectory;
189     NSURL *url = [files objectAtIndex:0];
190     OSL_TRACE("handling %s", [[url description] UTF8String]);
192     aDirectory = [url OUStringForInfo:FULLPATH];
194     implsetDisplayDirectory(aDirectory);
196     OSL_TRACE("dir url: %s", OUStringToOString(aDirectory, RTL_TEXTENCODING_UTF8).getStr());
198     DBG_PRINT_EXIT(CLASS_NAME, __func__);
199     return aDirectory;
202 void SAL_CALL SalAquaFolderPicker::setDescription( const rtl::OUString& rDescription )
203     throw( uno::RuntimeException )
205     DBG_PRINT_ENTRY(CLASS_NAME, __func__, "description", rDescription);
207     [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
209     DBG_PRINT_EXIT(CLASS_NAME, __func__);
213 // XServiceInfo
216 rtl::OUString SAL_CALL SalAquaFolderPicker::getImplementationName()
217     throw( uno::RuntimeException )
219     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
221     rtl::OUString retVal( FOLDER_PICKER_IMPL_NAME );
223     DBG_PRINT_EXIT(CLASS_NAME, __func__, retVal);
225     return retVal;
228 sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const rtl::OUString& sServiceName )
229     throw( uno::RuntimeException )
231     return cppu::supportsService(this, sServiceName);
234 uno::Sequence<rtl::OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
235     throw( uno::RuntimeException )
237     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
238     DBG_PRINT_EXIT(CLASS_NAME, __func__);
240     return FolderPicker_getSupportedServiceNames();
244 // XCancellable
247 void SAL_CALL SalAquaFolderPicker::cancel() throw( uno::RuntimeException )
249     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
251     SolarMutexGuard aGuard;
253     [m_pDialog cancel:nil];
255     DBG_PRINT_EXIT(CLASS_NAME, __func__);
259 // XEventListener
262 void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
263     throw( uno::RuntimeException )
265     DBG_PRINT_ENTRY(CLASS_NAME, __func__);
266     DBG_PRINT_EXIT(CLASS_NAME, __func__);
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */