LibreOffice Module fpicker (master)  1
SalAquaFolderPicker.mm
Go to the documentation of this file.
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  */
19 
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>
27 #include <osl/diagnose.h>
28 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
29 #include <osl/mutex.hxx>
30 #include <sal/log.hxx>
31 #include <vcl/svapp.hxx>
32 #include "SalAquaFolderPicker.hxx"
33 
34 #include <iostream>
35 
36 #include "resourceprovider.hxx"
37 
38 #include <osl/file.hxx>
39 #include "CFStringUtilities.hxx"
41 #include "NSURL_OOoAdditions.hxx"
42 
43 #pragma mark DEFINES
44 
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::ui::dialogs;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::uno;
49 
51 {
53 }
54 
55 // XExecutableDialog
56 
57 void SAL_CALL SalAquaFolderPicker::setTitle( const OUString& aTitle )
58 {
59  SolarMutexGuard aGuard;
60 
61  implsetTitle(aTitle);
62 }
63 
64 sal_Int16 SAL_CALL SalAquaFolderPicker::execute()
65 {
66  SolarMutexGuard aGuard;
67 
68  sal_Int16 retVal = 0;
69 
70  int nResult = runandwaitforresult();
71 
72  switch( nResult )
73  {
74  case NSModalResponseOK:
75  retVal = ExecutableDialogResults::OK;
76  break;
77 
78  case NSModalResponseCancel:
79  retVal = ExecutableDialogResults::CANCEL;
80  break;
81 
82  default:
83  throw uno::RuntimeException("The dialog returned with an unknown result!", static_cast< cppu::OWeakObject * >( this ));
84  break;
85  }
86 
87  return retVal;
88 }
89 
90 // XFolderPicker
91 
92 void SAL_CALL SalAquaFolderPicker::setDisplayDirectory( const OUString& aDirectory )
93 {
94  SolarMutexGuard aGuard;
95 
96  implsetDisplayDirectory(aDirectory);
97 }
98 
100 {
101  SolarMutexGuard aGuard;
102 
103  OUString aDirectory = implgetDisplayDirectory();
104 
105  return aDirectory;
106 }
107 
109 {
110  SolarMutexGuard aGuard;
111 
112  NSArray *files = nil;
114  files = [static_cast<NSOpenPanel*>(m_pDialog) URLs];
115  }
116 
117  NSUInteger nFiles = [files count];
118  SAL_INFO("fpicker.aqua", "# of items: " << nFiles);
119 
120  if (nFiles < 1) {
121  throw uno::RuntimeException("no directory selected", static_cast< cppu::OWeakObject * >( this ));
122  }
123 
124  OUString aDirectory;
125 
126  NSURL *url = [files objectAtIndex:0];
127 
128  aDirectory = [url OUStringForInfo:FULLPATH];
129 
130  implsetDisplayDirectory(aDirectory);
131 
132  return aDirectory;
133 }
134 
135 void SAL_CALL SalAquaFolderPicker::setDescription( const OUString& rDescription )
136 {
137  [m_pDialog setMessage:[NSString stringWithOUString:rDescription]];
138 }
139 
140 // XServiceInfo
141 
143 {
144  return "com.sun.star.ui.dialogs.SalAquaFolderPicker";
145 }
146 
147 sal_Bool SAL_CALL SalAquaFolderPicker::supportsService( const OUString& sServiceName )
148 {
149  return cppu::supportsService(this, sServiceName);
150 }
151 
152 uno::Sequence<OUString> SAL_CALL SalAquaFolderPicker::getSupportedServiceNames()
153 {
154  return { "com.sun.star.ui.dialogs.SystemFolderPicker", "com.sun.star.ui.dialogs.AquaFolderPicker" };
155 }
156 
157 // XCancellable
158 
160 {
161  SolarMutexGuard aGuard;
162 
163  [m_pDialog cancel:nil];
164 }
165 
166 // XEventListener
167 
168 void SAL_CALL SalAquaFolderPicker::disposing( const lang::EventObject& )
169 {
170 }
171 
172 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
174  css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
175 {
176  return cppu::acquire(new SalAquaFolderPicker());
177 }
178 
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL setDisplayDirectory(const OUString &rDirectory) override
OUString const & implgetDisplayDirectory()
int runandwaitforresult()
virtual void SAL_CALL setTitle(const OUString &aTitle) override
void implsetDisplayDirectory(const OUString &rDirectory)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * fpicker_SalAquaFolderPicker_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void implsetTitle(const OUString &aTitle)
virtual void SAL_CALL setDescription(const OUString &rDescription) override
unsigned char sal_Bool
virtual void SAL_CALL cancel() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
NSSavePanel * m_pDialog
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
#define SAL_INFO(area, stream)
virtual OUString SAL_CALL getDisplayDirectory() override
virtual OUString SAL_CALL getDirectory() override
NavigationServices_DialogType m_nDialogType
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Int16 SAL_CALL execute() override