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: fpicker.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
33 #include "sal/types.h"
34 #include "rtl/ustring.hxx"
36 #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
37 #include "cppuhelper/implementationentry.hxx"
39 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
42 #include <tools/prewin.h>
43 #include <tools/postwin.h>
44 #include <odma_lib.hxx>
47 #include "svtools/miscopt.hxx"
48 #include "svtools/pickerhistoryaccess.hxx"
51 #include "vcl/svapp.hxx"
54 namespace css
= com::sun::star
;
56 using css::uno::Reference
;
57 using css::uno::Sequence
;
61 * FilePicker implementation.
63 static OUString
FilePicker_getSystemPickerServiceName()
66 OUString
aDesktopEnvironment (Application::GetDesktopEnvironment());
67 if (aDesktopEnvironment
.equalsIgnoreAsciiCaseAscii ("gnome"))
68 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.GtkFilePicker"));
69 else if (aDesktopEnvironment
.equalsIgnoreAsciiCaseAscii ("kde"))
70 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDEFilePicker"));
71 else if (aDesktopEnvironment
.equalsIgnoreAsciiCaseAscii ("kde4"))
72 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDE4FilePicker"));
73 else if (aDesktopEnvironment
.equalsIgnoreAsciiCaseAscii ("macosx"))
74 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.AquaFilePicker"));
77 if (SvtMiscOptions().TryODMADialog() && ::odma::DMSsAvailable()) {
78 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.ODMAFilePicker"));
80 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.Win32FilePicker"));
82 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.SystemFilePicker"));
85 static Reference
< css::uno::XInterface
> FilePicker_createInstance (
86 Reference
< css::uno::XComponentContext
> const & rxContext
)
88 Reference
< css::uno::XInterface
> xResult
;
91 Reference
< css::lang::XMultiComponentFactory
> xFactory (rxContext
->getServiceManager());
94 if (SvtMiscOptions().UseSystemFileDialog())
98 xResult
= xFactory
->createInstanceWithContext (
99 FilePicker_getSystemPickerServiceName(),
102 catch (css::uno::Exception
const &)
104 // Handled below (see @ fallback).
109 // Always fall back to OfficeFilePicker.
110 xResult
= xFactory
->createInstanceWithContext (
111 OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFilePicker")),
116 // Add to FilePicker history.
117 svt::addFilePicker (xResult
);
124 static OUString
FilePicker_getImplementationName()
126 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.comp.fpicker.FilePicker"));
129 static Sequence
< OUString
> FilePicker_getSupportedServiceNames()
131 Sequence
< OUString
> aServiceNames(1);
132 aServiceNames
.getArray()[0] =
133 OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker"));
134 return aServiceNames
;
138 * FolderPicker implementation.
140 static OUString
FolderPicker_getSystemPickerServiceName()
142 OUString
aDesktopEnvironment (Application::GetDesktopEnvironment());
144 if (aDesktopEnvironment
.equalsIgnoreAsciiCaseAscii ("gnome"))
145 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.GtkFolderPicker"));
146 else if (aDesktopEnvironment
.equalsIgnoreAsciiCaseAscii ("kde"))
147 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDEFolderPicker"));
148 else if (aDesktopEnvironment
.equalsIgnoreAsciiCaseAscii ("macosx"))
149 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.AquaFolderPicker"));
152 if (SvtMiscOptions().TryODMADialog() && ::odma::DMSsAvailable()) {
153 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.ODMAFolderPicker"));
156 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.SystemFolderPicker"));
159 static Reference
< css::uno::XInterface
> FolderPicker_createInstance (
160 Reference
< css::uno::XComponentContext
> const & rxContext
)
162 Reference
< css::uno::XInterface
> xResult
;
165 Reference
< css::lang::XMultiComponentFactory
> xFactory (rxContext
->getServiceManager());
168 if (SvtMiscOptions().UseSystemFileDialog())
172 xResult
= xFactory
->createInstanceWithContext (
173 FolderPicker_getSystemPickerServiceName(),
176 catch (css::uno::Exception
const &)
178 // Handled below (see @ fallback).
183 // Always fall back to OfficeFolderPicker.
184 xResult
= xFactory
->createInstanceWithContext (
185 OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFolderPicker")),
190 // Add to FolderPicker history.
191 svt::addFolderPicker (xResult
);
198 static OUString
FolderPicker_getImplementationName()
200 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.comp.fpicker.FolderPicker"));
203 static Sequence
< OUString
> FolderPicker_getSupportedServiceNames()
205 Sequence
< OUString
> aServiceNames(1);
206 aServiceNames
.getArray()[0] =
207 OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker"));
208 return aServiceNames
;
212 * Implementation entries.
214 static cppu::ImplementationEntry g_entries
[] =
217 FilePicker_createInstance
,
218 FilePicker_getImplementationName
,
219 FilePicker_getSupportedServiceNames
,
220 cppu::createSingleComponentFactory
, 0, 0
223 FolderPicker_createInstance
,
224 FolderPicker_getImplementationName
,
225 FolderPicker_getSupportedServiceNames
,
226 cppu::createSingleComponentFactory
, 0, 0
232 * Public (exported) interface.
236 SAL_DLLPUBLIC_EXPORT
void SAL_CALL
component_getImplementationEnvironment (
237 const sal_Char
** ppEnvTypeName
, uno_Environment
** /* ppEnv */)
239 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
242 SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
component_writeInfo (
243 void * pServiceManager
, void * pRegistryKey
)
245 return cppu::component_writeInfoHelper (
246 pServiceManager
, pRegistryKey
, g_entries
);
249 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
component_getFactory (
250 const sal_Char
* pImplementationName
, void * pServiceManager
, void * pRegistryKey
)
252 return cppu::component_getFactoryHelper (
253 pImplementationName
, pServiceManager
, pRegistryKey
, g_entries
);