Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / fpicker / source / aqua / SalAquaFolderPicker.mm
blob3d2259cbcdbffc09dc3ae488a1c9f026b70a9c29
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 <cppuhelper/interfacecontainer.h>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <osl/diagnose.h>
28 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
29 #include "FPServiceInfo.hxx"
30 #include <osl/mutex.hxx>
31 #include <sal/log.hxx>
32 #include <vcl/svapp.hxx>
33 #include "SalAquaFolderPicker.hxx"
35 #include <iostream>
37 #include "resourceprovider.hxx"
39 #include <osl/file.hxx>
40 #include "CFStringUtilities.hxx"
41 #include "NSString_OOoAdditions.hxx"
42 #include "NSURL_OOoAdditions.hxx"
44 #pragma mark DEFINES
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::ui::dialogs;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::uno;
51 namespace
53     // controlling event notifications
54     uno::Sequence<OUString> FolderPicker_getSupportedServiceNames()
55     {
56         return { "com.sun.star.ui.dialogs.SystemFolderPicker", "com.sun.star.ui.dialogs.AquaFolderPicker" };
57     }
60 SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr ) :
61     m_xServiceMgr( xServiceMgr )
63     m_nDialogType = NAVIGATIONSERVICES_DIRECTORY;
66 // XExecutableDialog
68 void SAL_CALL SalAquaFolderPicker::setTitle( const OUString& aTitle )
70     SolarMutexGuard aGuard;
72     implsetTitle(aTitle);
75 sal_Int16 SAL_CALL SalAquaFolderPicker::execute()
77     SolarMutexGuard aGuard;
79     sal_Int16 retVal = 0;
81     int nResult = runandwaitforresult();
83     switch( nResult )
84     {
85     case NSModalResponseOK:
86         retVal = ExecutableDialogResults::OK;
87         break;
89     case NSModalResponseCancel:
90         retVal = ExecutableDialogResults::CANCEL;
91         break;
93     default:
94         throw uno::RuntimeException("The dialog returned with an unknown result!", static_cast< cppu::OWeakObject * >( this ));
95         break;
96     }
98     return retVal;
101 // XFolderPicker
103 void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const OUString& aDirectory )
105     SolarMutexGuard aGuard;
107     implsetDisplayDirectory(aDirectory);
110 OUString SAL_CALL SalAquaFolderPicker::getDisplayDirectory()
112     SolarMutexGuard aGuard;
114     OUString aDirectory = implgetDisplayDirectory();
116     return aDirectory;
119 OUString SAL_CALL SalAquaFolderPicker::getDirectory()
121     SolarMutexGuard aGuard;
123     NSArray *files = nil;
124     if (m_nDialogType == NAVIGATIONSERVICES_DIRECTORY) {
125         files = [static_cast<NSOpenPanel*>(m_pDialog) URLs];
126     }
128     long nFiles = [files count];
129     SAL_INFO("fpicker.aqua", "# of items: " << nFiles);
131     if (nFiles < 1) {
132         throw uno::RuntimeException("no directory selected", static_cast< cppu::OWeakObject * >( this ));
133     }
135     OUString aDirectory;
137     NSURL *url = [files objectAtIndex:0];
139     aDirectory = [url OUStringForInfo:FULLPATH];
141     implsetDisplayDirectory(aDirectory);
143     return aDirectory;
146 void SAL_CALL SalAquaFolderPicker::setDescription( const OUString& rDescription )
148     [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
151 // XServiceInfo
153 OUString SAL_CALL SalAquaFolderPicker::getImplementationName()
155     return FOLDER_PICKER_IMPL_NAME;
158 sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const OUString& sServiceName )
160     return cppu::supportsService(this, sServiceName);
163 uno::Sequence<OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
165     return FolderPicker_getSupportedServiceNames();
168 // XCancellable
170 void SAL_CALL SalAquaFolderPicker::cancel()
172     SolarMutexGuard aGuard;
174     [m_pDialog cancel:nil];
177 // XEventListener
179 void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */