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 <rtl/ustring.hxx>
22 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
24 #include <svl/pickerhistoryaccess.hxx>
25 #include <officecfg/Office/Common.hxx>
27 #include <vcl/svapp.hxx>
29 #include "fpicker.hxx"
31 using css::uno::Reference
;
32 using css::uno::Sequence
;
35 * FilePicker implementation.
37 static OUString
FilePicker_getSystemPickerServiceName()
40 OUString
aDesktopEnvironment (Application::GetDesktopEnvironment());
41 if (aDesktopEnvironment
.equalsIgnoreAsciiCase("macosx"))
42 return u
"com.sun.star.ui.dialogs.AquaFilePicker"_ustr
;
44 return u
"com.sun.star.ui.dialogs.SystemFilePicker"_ustr
;
47 return "com.sun.star.ui.dialogs.Win32FilePicker";
51 // Ensure that we use not the system file dialogs as headless mode relies on
52 // Application::EnableHeadlessMode() which only works for VCL dialogs
53 static bool UseSystemFileDialog()
55 return !Application::IsHeadlessModeEnabled() && officecfg::Office::Common::Misc::UseSystemFileDialog::get();
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() && UseSystemFileDialog())
69 xResult
.set( 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 u
"com.sun.star.ui.dialogs.OfficeFilePicker"_ustr
,
96 // Add to FilePicker history.
97 svt::addFilePicker (xResult
);
102 OUString
FilePicker_getImplementationName()
104 return u
"com.sun.star.comp.svt.FilePicker"_ustr
;
107 Sequence
< OUString
> FilePicker_getSupportedServiceNames()
109 Sequence
< OUString
> aServiceNames
{ u
"com.sun.star.ui.dialogs.FilePicker"_ustr
};
110 return aServiceNames
;
114 * FolderPicker implementation.
116 static OUString
FolderPicker_getSystemPickerServiceName()
119 OUString
aDesktopEnvironment (Application::GetDesktopEnvironment());
120 if (aDesktopEnvironment
.equalsIgnoreAsciiCase("macosx"))
121 return u
"com.sun.star.ui.dialogs.AquaFolderPicker"_ustr
;
123 return u
"com.sun.star.ui.dialogs.SystemFolderPicker"_ustr
;
126 Reference
< css::uno::XInterface
> FolderPicker_CreateInstance (
127 Reference
< css::uno::XComponentContext
> const & context
)
129 Reference
< css::uno::XInterface
> xResult
;
134 Reference
< css::lang::XMultiComponentFactory
> xFactory (context
->getServiceManager());
135 if (xFactory
.is() && UseSystemFileDialog())
137 xResult
.set( Application::createFolderPicker( context
) );
142 xResult
= xFactory
->createInstanceWithContext (
143 FolderPicker_getSystemPickerServiceName(),
146 catch (css::uno::Exception
const &)
148 // Handled below (see @ fallback).
152 if (!xResult
.is() && xFactory
.is() )
154 // Always fall back to OfficeFolderPicker.
155 xResult
= xFactory
->createInstanceWithContext (
156 u
"com.sun.star.ui.dialogs.OfficeFolderPicker"_ustr
,
161 // Add to FolderPicker history.
162 svt::addFolderPicker (xResult
);
167 OUString
FolderPicker_getImplementationName()
169 return u
"com.sun.star.comp.svt.FolderPicker"_ustr
;
172 Sequence
< OUString
> FolderPicker_getSupportedServiceNames()
174 Sequence
< OUString
> aServiceNames
{ u
"com.sun.star.ui.dialogs.FolderPicker"_ustr
};
175 return aServiceNames
;
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */