1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/types.h>
21 #include <rtl/ustring.hxx>
23 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
25 #include <svtools/miscopt.hxx>
26 #include <svl/pickerhistoryaccess.hxx>
28 #include <vcl/svapp.hxx>
30 #include "fpicker.hxx"
32 using css::uno::Reference
;
33 using css::uno::Sequence
;
36 * FilePicker implementation.
38 static OUString
FilePicker_getSystemPickerServiceName()
41 OUString
aDesktopEnvironment (Application::GetDesktopEnvironment());
42 if (aDesktopEnvironment
.equalsIgnoreAsciiCase("tde"))
43 return OUString ("com.sun.star.ui.dialogs.TDEFilePicker");
44 else if (aDesktopEnvironment
.equalsIgnoreAsciiCase("kde"))
45 return OUString ("com.sun.star.ui.dialogs.KDEFilePicker");
46 else if (aDesktopEnvironment
.equalsIgnoreAsciiCase("kde4"))
47 return OUString ("com.sun.star.ui.dialogs.KDE4FilePicker");
48 else if (aDesktopEnvironment
.equalsIgnoreAsciiCase("macosx"))
49 return OUString ("com.sun.star.ui.dialogs.AquaFilePicker");
51 return OUString ("com.sun.star.ui.dialogs.SystemFilePicker");
54 return OUString ("com.sun.star.ui.dialogs.Win32FilePicker");
58 Reference
< css::uno::XInterface
> FilePicker_CreateInstance (
59 Reference
< css::uno::XComponentContext
> const & context
)
61 Reference
< css::uno::XInterface
> xResult
;
66 Reference
< css::lang::XMultiComponentFactory
> xFactory (context
->getServiceManager());
67 if (xFactory
.is() && SvtMiscOptions().UseSystemFileDialog())
69 xResult
= Reference
< css::uno::XInterface
>( Application::createFilePicker( context
) );
75 xResult
= xFactory
->createInstanceWithContext (
76 FilePicker_getSystemPickerServiceName(),
79 catch (css::uno::Exception
const &)
81 // Handled below (see @ fallback).
87 if (!xResult
.is() && xFactory
.is())
89 // Always fall back to OfficeFilePicker.
90 xResult
= xFactory
->createInstanceWithContext (
91 OUString( "com.sun.star.ui.dialogs.OfficeFilePicker"),
96 // Add to FilePicker history.
97 svt::addFilePicker (xResult
);
102 OUString SAL_CALL
FilePicker_getImplementationName()
104 return OUString("com.sun.star.comp.svt.FilePicker");
107 Sequence
< OUString
> FilePicker_getSupportedServiceNames()
109 Sequence
< OUString
> aServiceNames(1);
110 aServiceNames
.getArray()[0] = "com.sun.star.ui.dialogs.FilePicker";
111 return aServiceNames
;
115 * FolderPicker implementation.
117 static OUString
FolderPicker_getSystemPickerServiceName()
119 OUString
aDesktopEnvironment (Application::GetDesktopEnvironment());
121 if (aDesktopEnvironment
.equalsIgnoreAsciiCase("tde"))
122 return OUString("com.sun.star.ui.dialogs.TDEFolderPicker");
123 else if (aDesktopEnvironment
.equalsIgnoreAsciiCase("kde"))
124 return OUString("com.sun.star.ui.dialogs.KDEFolderPicker");
125 else if (aDesktopEnvironment
.equalsIgnoreAsciiCase("macosx"))
126 return OUString("com.sun.star.ui.dialogs.AquaFolderPicker");
128 return OUString("com.sun.star.ui.dialogs.SystemFolderPicker");
131 Reference
< css::uno::XInterface
> FolderPicker_CreateInstance (
132 Reference
< css::uno::XComponentContext
> const & context
)
134 Reference
< css::uno::XInterface
> xResult
;
139 Reference
< css::lang::XMultiComponentFactory
> xFactory (context
->getServiceManager());
140 if (xFactory
.is() && SvtMiscOptions().UseSystemFileDialog())
142 xResult
= Reference
< css::uno::XInterface
>( Application::createFolderPicker( context
) );
147 xResult
= xFactory
->createInstanceWithContext (
148 FolderPicker_getSystemPickerServiceName(),
151 catch (css::uno::Exception
const &)
153 // Handled below (see @ fallback).
157 if (!xResult
.is() && xFactory
.is() )
159 // Always fall back to OfficeFolderPicker.
160 xResult
= xFactory
->createInstanceWithContext (
161 OUString( "com.sun.star.ui.dialogs.OfficeFolderPicker"),
166 // Add to FolderPicker history.
167 svt::addFolderPicker (xResult
);
172 OUString SAL_CALL
FolderPicker_getImplementationName()
174 return OUString("com.sun.star.comp.svt.FolderPicker");
177 Sequence
< OUString
> FolderPicker_getSupportedServiceNames()
179 Sequence
< OUString
> aServiceNames(1);
180 aServiceNames
.getArray()[0] = "com.sun.star.ui.dialogs.FolderPicker";
181 return aServiceNames
;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */