1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SalAquaFolderPicker.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //------------------------------------------------------------------------
33 //------------------------------------------------------------------------
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
38 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
39 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
40 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
41 #include <cppuhelper/interfacecontainer.h>
42 #include <osl/diagnose.h>
43 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <FPServiceInfo.hxx>
46 #include <vos/mutex.hxx>
47 #include <vcl/svapp.hxx>
48 #include "SalAquaFolderPicker.hxx"
50 #include <tools/urlobj.hxx>
53 #include "resourceprovider.hxx"
56 #include <tools/rc.hxx>
59 #include <osl/file.hxx>
60 #include "CFStringUtilities.hxx"
61 #include "NSString_OOoAdditions.hxx"
62 #include "NSURL_OOoAdditions.hxx"
65 #define CLASS_NAME "SalAquaFolderPicker"
67 //------------------------------------------------------------------------
68 // namespace directives
69 //------------------------------------------------------------------------
71 using namespace ::rtl
;
72 using namespace ::com::sun::star
;
73 using namespace ::com::sun::star::ui::dialogs
;
74 using namespace ::com::sun::star::lang
;
75 using namespace ::com::sun::star::uno
;
77 //------------------------------------------------------------------------
79 //------------------------------------------------------------------------
83 // controling event notifications
84 uno::Sequence
<rtl::OUString
> SAL_CALL
FolderPicker_getSupportedServiceNames()
86 uno::Sequence
<rtl::OUString
> aRet(2);
87 aRet
[0] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.SystemFolderPicker" );
88 aRet
[1] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.AquaFolderPicker" );
93 //-----------------------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------------------
96 SalAquaFolderPicker::SalAquaFolderPicker( const uno::Reference
<lang::XMultiServiceFactory
>& xServiceMgr
) :
97 m_xServiceMgr( xServiceMgr
)
99 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
101 m_nDialogType
= NAVIGATIONSERVICES_DIRECTORY
;
103 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
106 //-----------------------------------------------------------------------------------------
107 // XExecutableDialog functions
108 //-----------------------------------------------------------------------------------------
110 void SAL_CALL
SalAquaFolderPicker::setTitle( const rtl::OUString
& aTitle
) throw( uno::RuntimeException
)
112 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "title", aTitle
);
114 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
116 implsetTitle(aTitle
);
118 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
121 sal_Int16 SAL_CALL
SalAquaFolderPicker::execute() throw( uno::RuntimeException
)
123 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
125 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
127 sal_Int16 retVal
= 0;
129 int nResult
= runandwaitforresult();
134 OSL_TRACE("Dialog returned with OK");
135 retVal
= ExecutableDialogResults::OK
;
139 OSL_TRACE("Dialog was cancelled!");
140 retVal
= ExecutableDialogResults::CANCEL
;
144 throw uno::RuntimeException(rtl::OUString::createFromAscii("The dialog returned with an unknown result!"), static_cast< XFolderPicker
* >( this ));
148 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
152 //------------------------------------------------------------------------------------
153 // XFolderPicker functions
154 //------------------------------------------------------------------------------------
156 void SAL_CALL
SalAquaFolderPicker::setDisplayDirectory( const rtl::OUString
& aDirectory
)
157 throw( lang::IllegalArgumentException
, uno::RuntimeException
)
159 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "directory", aDirectory
);
161 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
163 implsetDisplayDirectory(aDirectory
);
165 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
168 rtl::OUString SAL_CALL
SalAquaFolderPicker::getDisplayDirectory() throw( uno::RuntimeException
)
170 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
172 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
174 OUString aDirectory
= implgetDisplayDirectory();
176 DBG_PRINT_EXIT(CLASS_NAME
, __func__
, aDirectory
);
181 rtl::OUString SAL_CALL
SalAquaFolderPicker::getDirectory() throw( uno::RuntimeException
)
183 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
185 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
187 NSArray
*files
= nil
;
188 if (m_nDialogType
== NAVIGATIONSERVICES_DIRECTORY
) {
189 files
= [(NSOpenPanel
*)m_pDialog URLs
];
192 long nFiles
= [files count
];
193 OSL_TRACE("# of items: %d", nFiles
);
196 throw uno::RuntimeException(rtl::OUString::createFromAscii("no directory selected"), static_cast< XFolderPicker
* >( this ));
199 rtl::OUString aDirectory
;
201 NSURL
*url
= [files objectAtIndex
:0];
202 OSL_TRACE("handling %s", [[url description
] UTF8String
]);
204 aDirectory
= [url OUStringForInfo
:FULLPATH
];
206 implsetDisplayDirectory(aDirectory
);
208 OSL_TRACE("dir url: %s", OUStringToOString(aDirectory
, RTL_TEXTENCODING_UTF8
).getStr());
210 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
214 void SAL_CALL
SalAquaFolderPicker::setDescription( const rtl::OUString
& rDescription
)
215 throw( uno::RuntimeException
)
217 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "description", rDescription
);
219 [m_pDialog setMessage
:[NSString stringWithOUString
:rDescription
]];
221 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
224 // -------------------------------------------------
226 // -------------------------------------------------
228 rtl::OUString SAL_CALL
SalAquaFolderPicker::getImplementationName()
229 throw( uno::RuntimeException
)
231 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
233 rtl::OUString retVal
= rtl::OUString::createFromAscii( FOLDER_PICKER_IMPL_NAME
);
235 DBG_PRINT_EXIT(CLASS_NAME
, __func__
, retVal
);
240 sal_Bool SAL_CALL
SalAquaFolderPicker::supportsService( const rtl::OUString
& sServiceName
)
241 throw( uno::RuntimeException
)
243 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
, "serviceName", sServiceName
);
245 sal_Bool retVal
= sal_False
;
246 uno::Sequence
<rtl::OUString
> supportedServicesNames
= FolderPicker_getSupportedServiceNames();
248 for( sal_Int32 n
= supportedServicesNames
.getLength(); n
--; ) {
249 if( supportedServicesNames
[n
].compareTo( sServiceName
) == 0) {
255 DBG_PRINT_EXIT(CLASS_NAME
, __func__
, retVal
);
259 uno::Sequence
<rtl::OUString
> SAL_CALL
SalAquaFolderPicker::getSupportedServiceNames()
260 throw( uno::RuntimeException
)
262 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
263 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
265 return FolderPicker_getSupportedServiceNames();
268 //------------------------------------------------------------------------------------
270 //------------------------------------------------------------------------------------
272 void SAL_CALL
SalAquaFolderPicker::cancel() throw( uno::RuntimeException
)
274 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
276 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
278 [m_pDialog cancel
:nil
];
280 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);
283 // -------------------------------------------------
285 // -------------------------------------------------
287 void SAL_CALL
SalAquaFolderPicker::disposing( const lang::EventObject
& )
288 throw( uno::RuntimeException
)
290 DBG_PRINT_ENTRY(CLASS_NAME
, __func__
);
291 DBG_PRINT_EXIT(CLASS_NAME
, __func__
);