update dev300-m58
[ooovba.git] / fpicker / source / generic / fpicker.cxx
blobd7da75aed887ae3abc4a2fed87afd85635367ae8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fpicker.cxx,v $
10 * $Revision: 1.6 $
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"
38 #endif
39 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
41 #ifdef WNT
42 #include <tools/prewin.h>
43 #include <tools/postwin.h>
44 #include <odma_lib.hxx>
45 #endif
47 #include "svtools/miscopt.hxx"
48 #include "svtools/pickerhistoryaccess.hxx"
50 #ifndef _SV_APP_HXX
51 #include "vcl/svapp.hxx"
52 #endif
54 namespace css = com::sun::star;
56 using css::uno::Reference;
57 using css::uno::Sequence;
58 using rtl::OUString;
61 * FilePicker implementation.
63 static OUString FilePicker_getSystemPickerServiceName()
65 #ifdef UNX
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"));
75 #endif
76 #ifdef WNT
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"));
81 #endif
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;
89 if (rxContext.is())
91 Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager());
92 if (xFactory.is())
94 if (SvtMiscOptions().UseSystemFileDialog())
96 try
98 xResult = xFactory->createInstanceWithContext (
99 FilePicker_getSystemPickerServiceName(),
100 rxContext);
102 catch (css::uno::Exception const &)
104 // Handled below (see @ fallback).
107 if (!xResult.is())
109 // Always fall back to OfficeFilePicker.
110 xResult = xFactory->createInstanceWithContext (
111 OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFilePicker")),
112 rxContext);
114 if (xResult.is())
116 // Add to FilePicker history.
117 svt::addFilePicker (xResult);
121 return 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());
143 #ifdef UNX
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"));
150 #endif
151 #ifdef WNT
152 if (SvtMiscOptions().TryODMADialog() && ::odma::DMSsAvailable()) {
153 return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.ODMAFolderPicker"));
155 #endif
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;
163 if (rxContext.is())
165 Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager());
166 if (xFactory.is())
168 if (SvtMiscOptions().UseSystemFileDialog())
172 xResult = xFactory->createInstanceWithContext (
173 FolderPicker_getSystemPickerServiceName(),
174 rxContext);
176 catch (css::uno::Exception const &)
178 // Handled below (see @ fallback).
181 if (!xResult.is())
183 // Always fall back to OfficeFolderPicker.
184 xResult = xFactory->createInstanceWithContext (
185 OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFolderPicker")),
186 rxContext);
188 if (xResult.is())
190 // Add to FolderPicker history.
191 svt::addFolderPicker (xResult);
195 return 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
228 { 0, 0, 0, 0, 0, 0 }
232 * Public (exported) interface.
234 extern "C"
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);
256 } // extern "C"