xref: /trunk/main/fpicker/source/generic/fpicker.cxx (revision b557fc96)
1*b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b557fc96SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b557fc96SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b557fc96SAndrew Rist  * distributed with this work for additional information
6*b557fc96SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b557fc96SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b557fc96SAndrew Rist  * "License"); you may not use this file except in compliance
9*b557fc96SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b557fc96SAndrew Rist  *
11*b557fc96SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b557fc96SAndrew Rist  *
13*b557fc96SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b557fc96SAndrew Rist  * software distributed under the License is distributed on an
15*b557fc96SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b557fc96SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b557fc96SAndrew Rist  * specific language governing permissions and limitations
18*b557fc96SAndrew Rist  * under the License.
19*b557fc96SAndrew Rist  *
20*b557fc96SAndrew Rist  *************************************************************/
21*b557fc96SAndrew Rist 
22*b557fc96SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
26cdf0e10cSrcweir #include "sal/types.h"
27cdf0e10cSrcweir #include "rtl/ustring.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
30cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp"
33cdf0e10cSrcweir #include "svtools/miscopt.hxx"
34cdf0e10cSrcweir #include "svl/pickerhistoryaccess.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef _SV_APP_HXX
37cdf0e10cSrcweir #include "vcl/svapp.hxx"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace css = com::sun::star;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using css::uno::Reference;
43cdf0e10cSrcweir using css::uno::Sequence;
44cdf0e10cSrcweir using rtl::OUString;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir /*
47cdf0e10cSrcweir  * FilePicker implementation.
48cdf0e10cSrcweir  */
FilePicker_getSystemPickerServiceName()49cdf0e10cSrcweir static OUString FilePicker_getSystemPickerServiceName()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
52cdf0e10cSrcweir 	if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("gnome"))
53cdf0e10cSrcweir 		return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.GtkFilePicker"));
54cdf0e10cSrcweir 	else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("kde"))
55cdf0e10cSrcweir 		return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDEFilePicker"));
56cdf0e10cSrcweir 	else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("kde4"))
57cdf0e10cSrcweir 		return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDE4FilePicker"));
58cdf0e10cSrcweir     else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("macosx"))
59cdf0e10cSrcweir         return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.AquaFilePicker"));
60cdf0e10cSrcweir     else
61cdf0e10cSrcweir         return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.SystemFilePicker"));
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
FilePicker_createInstance(Reference<css::uno::XComponentContext> const & rxContext)64cdf0e10cSrcweir static Reference< css::uno::XInterface > FilePicker_createInstance (
65cdf0e10cSrcweir 	Reference< css::uno::XComponentContext > const & rxContext)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	Reference< css::uno::XInterface > xResult;
68cdf0e10cSrcweir 	if (rxContext.is())
69cdf0e10cSrcweir 	{
70cdf0e10cSrcweir 		Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager());
71cdf0e10cSrcweir 		if (xFactory.is())
72cdf0e10cSrcweir 		{
73cdf0e10cSrcweir 			if (SvtMiscOptions().UseSystemFileDialog())
74cdf0e10cSrcweir 			{
75cdf0e10cSrcweir 				try
76cdf0e10cSrcweir 				{
77cdf0e10cSrcweir 					xResult = xFactory->createInstanceWithContext (
78cdf0e10cSrcweir 						FilePicker_getSystemPickerServiceName(),
79cdf0e10cSrcweir 						rxContext);
80cdf0e10cSrcweir 				}
81cdf0e10cSrcweir 				catch (css::uno::Exception const &)
82cdf0e10cSrcweir 				{
83cdf0e10cSrcweir 					// Handled below (see @ fallback).
84cdf0e10cSrcweir 				}
85cdf0e10cSrcweir 			}
86cdf0e10cSrcweir 			if (!xResult.is())
87cdf0e10cSrcweir 			{
88cdf0e10cSrcweir 				// Always fall back to OfficeFilePicker.
89cdf0e10cSrcweir 				xResult = xFactory->createInstanceWithContext (
90cdf0e10cSrcweir 					OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFilePicker")),
91cdf0e10cSrcweir 					rxContext);
92cdf0e10cSrcweir 			}
93cdf0e10cSrcweir 			if (xResult.is())
94cdf0e10cSrcweir 			{
95cdf0e10cSrcweir 				// Add to FilePicker history.
96cdf0e10cSrcweir 				svt::addFilePicker (xResult);
97cdf0e10cSrcweir 			}
98cdf0e10cSrcweir 		}
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 	return xResult;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
FilePicker_getImplementationName()103cdf0e10cSrcweir static OUString FilePicker_getImplementationName()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.comp.fpicker.FilePicker"));
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
FilePicker_getSupportedServiceNames()108cdf0e10cSrcweir static Sequence< OUString > FilePicker_getSupportedServiceNames()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	Sequence< OUString > aServiceNames(1);
111cdf0e10cSrcweir 	aServiceNames.getArray()[0] =
112cdf0e10cSrcweir 		OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker"));
113cdf0e10cSrcweir 	return aServiceNames;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir /*
117cdf0e10cSrcweir  * FolderPicker implementation.
118cdf0e10cSrcweir  */
FolderPicker_getSystemPickerServiceName()119cdf0e10cSrcweir static OUString FolderPicker_getSystemPickerServiceName()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
122cdf0e10cSrcweir 	if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("gnome"))
123cdf0e10cSrcweir 		return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.GtkFolderPicker"));
124cdf0e10cSrcweir 	else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("kde"))
125cdf0e10cSrcweir 		return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.KDEFolderPicker"));
126cdf0e10cSrcweir     else if (aDesktopEnvironment.equalsIgnoreAsciiCaseAscii ("macosx"))
127cdf0e10cSrcweir         return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.AquaFolderPicker"));
128cdf0e10cSrcweir 	else
129cdf0e10cSrcweir 		return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.ui.dialogs.SystemFolderPicker"));
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
FolderPicker_createInstance(Reference<css::uno::XComponentContext> const & rxContext)132cdf0e10cSrcweir static Reference< css::uno::XInterface > FolderPicker_createInstance (
133cdf0e10cSrcweir 	Reference< css::uno::XComponentContext > const & rxContext)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir 	Reference< css::uno::XInterface > xResult;
136cdf0e10cSrcweir 	if (rxContext.is())
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir 		Reference< css::lang::XMultiComponentFactory > xFactory (rxContext->getServiceManager());
139cdf0e10cSrcweir 		if (xFactory.is())
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir 			if (SvtMiscOptions().UseSystemFileDialog())
142cdf0e10cSrcweir 			{
143cdf0e10cSrcweir 				try
144cdf0e10cSrcweir 				{
145cdf0e10cSrcweir 					xResult = xFactory->createInstanceWithContext (
146cdf0e10cSrcweir 						FolderPicker_getSystemPickerServiceName(),
147cdf0e10cSrcweir 						rxContext);
148cdf0e10cSrcweir 				}
149cdf0e10cSrcweir 				catch (css::uno::Exception const &)
150cdf0e10cSrcweir 				{
151cdf0e10cSrcweir 					// Handled below (see @ fallback).
152cdf0e10cSrcweir 				}
153cdf0e10cSrcweir 			}
154cdf0e10cSrcweir 			if (!xResult.is())
155cdf0e10cSrcweir 			{
156cdf0e10cSrcweir 				// Always fall back to OfficeFolderPicker.
157cdf0e10cSrcweir 				xResult = xFactory->createInstanceWithContext (
158cdf0e10cSrcweir 					OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFolderPicker")),
159cdf0e10cSrcweir 					rxContext);
160cdf0e10cSrcweir 			}
161cdf0e10cSrcweir 			if (xResult.is())
162cdf0e10cSrcweir 			{
163cdf0e10cSrcweir 				// Add to FolderPicker history.
164cdf0e10cSrcweir 				svt::addFolderPicker (xResult);
165cdf0e10cSrcweir 			}
166cdf0e10cSrcweir 		}
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 	return xResult;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
FolderPicker_getImplementationName()171cdf0e10cSrcweir static OUString FolderPicker_getImplementationName()
172cdf0e10cSrcweir {
173cdf0e10cSrcweir 	return OUString (RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.comp.fpicker.FolderPicker"));
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
FolderPicker_getSupportedServiceNames()176cdf0e10cSrcweir static Sequence< OUString > FolderPicker_getSupportedServiceNames()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	Sequence< OUString > aServiceNames(1);
179cdf0e10cSrcweir 	aServiceNames.getArray()[0] =
180cdf0e10cSrcweir 		OUString (RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker"));
181cdf0e10cSrcweir 	return aServiceNames;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir /*
185cdf0e10cSrcweir  * Implementation entries.
186cdf0e10cSrcweir  */
187cdf0e10cSrcweir static cppu::ImplementationEntry g_entries[] =
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	{
190cdf0e10cSrcweir 		FilePicker_createInstance,
191cdf0e10cSrcweir 		FilePicker_getImplementationName,
192cdf0e10cSrcweir 		FilePicker_getSupportedServiceNames,
193cdf0e10cSrcweir 		cppu::createSingleComponentFactory, 0, 0
194cdf0e10cSrcweir 	},
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir 		FolderPicker_createInstance,
197cdf0e10cSrcweir 		FolderPicker_getImplementationName,
198cdf0e10cSrcweir 		FolderPicker_getSupportedServiceNames,
199cdf0e10cSrcweir 		cppu::createSingleComponentFactory, 0, 0
200cdf0e10cSrcweir 	},
201cdf0e10cSrcweir 	{ 0, 0, 0, 0, 0, 0 }
202cdf0e10cSrcweir };
203cdf0e10cSrcweir 
204cdf0e10cSrcweir /*
205cdf0e10cSrcweir  * Public (exported) interface.
206cdf0e10cSrcweir  */
207cdf0e10cSrcweir extern "C"
208cdf0e10cSrcweir {
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)209cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment (
210cdf0e10cSrcweir 	const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */)
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void * pRegistryKey)215cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory (
216cdf0e10cSrcweir 	const sal_Char * pImplementationName, void * pServiceManager, void * pRegistryKey)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	return cppu::component_getFactoryHelper (
219cdf0e10cSrcweir 		pImplementationName, pServiceManager, pRegistryKey, g_entries);
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir } // extern "C"
223