LibreOffice Module svtools (master) 1
fpicker.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <rtl/ustring.hxx>
21
22#include <com/sun/star/lang/XMultiComponentFactory.hpp>
23
25#include <officecfg/Office/Common.hxx>
26
27#include <vcl/svapp.hxx>
28
29#include "fpicker.hxx"
30
31using css::uno::Reference;
32using css::uno::Sequence;
33
34/*
35 * FilePicker implementation.
36 */
38{
39#ifdef UNX
40 OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
41 if (aDesktopEnvironment.equalsIgnoreAsciiCase("macosx"))
42 return "com.sun.star.ui.dialogs.AquaFilePicker";
43 else
44 return "com.sun.star.ui.dialogs.SystemFilePicker";
45#endif
46#ifdef _WIN32
47 return "com.sun.star.ui.dialogs.Win32FilePicker";
48#endif
49}
50
51// Ensure that we use not the system file dialogs as headless mode relies on
52// Application::EnableHeadlessMode() which only works for VCL dialogs
54{
55 return !Application::IsHeadlessModeEnabled() && officecfg::Office::Common::Misc::UseSystemFileDialog::get();
56}
57
58Reference< css::uno::XInterface > FilePicker_CreateInstance (
59 Reference< css::uno::XComponentContext > const & context)
60{
61 Reference< css::uno::XInterface > xResult;
62
63 if (!context.is())
64 return xResult;
65
66 Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager());
67 if (xFactory.is() && UseSystemFileDialog())
68 {
69 xResult.set( Application::createFilePicker( context ) );
70
71 if (!xResult.is())
72 {
73 try
74 {
75 xResult = xFactory->createInstanceWithContext (
77 context);
78 }
79 catch (css::uno::Exception const &)
80 {
81 // Handled below (see @ fallback).
82 }
83 }
84 }
85
86
87 if (!xResult.is() && xFactory.is())
88 {
89 // Always fall back to OfficeFilePicker.
90 xResult = xFactory->createInstanceWithContext (
91 "com.sun.star.ui.dialogs.OfficeFilePicker",
92 context);
93 }
94 if (xResult.is())
95 {
96 // Add to FilePicker history.
97 svt::addFilePicker (xResult);
98 }
99 return xResult;
100}
101
103{
104 return "com.sun.star.comp.svt.FilePicker";
105}
106
108{
109 Sequence< OUString > aServiceNames { "com.sun.star.ui.dialogs.FilePicker" };
110 return aServiceNames;
111}
112
113/*
114 * FolderPicker implementation.
115 */
117{
118#ifdef UNX
119 OUString aDesktopEnvironment (Application::GetDesktopEnvironment());
120 if (aDesktopEnvironment.equalsIgnoreAsciiCase("macosx"))
121 return "com.sun.star.ui.dialogs.AquaFolderPicker";
122#endif
123 return "com.sun.star.ui.dialogs.SystemFolderPicker";
124}
125
126Reference< css::uno::XInterface > FolderPicker_CreateInstance (
127 Reference< css::uno::XComponentContext > const & context)
128{
129 Reference< css::uno::XInterface > xResult;
130
131 if (!context.is())
132 return xResult;
133
134 Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager());
135 if (xFactory.is() && UseSystemFileDialog())
136 {
137 xResult.set( Application::createFolderPicker( context ) );
138 if (!xResult.is())
139 {
140 try
141 {
142 xResult = xFactory->createInstanceWithContext (
144 context);
145 }
146 catch (css::uno::Exception const &)
147 {
148 // Handled below (see @ fallback).
149 }
150 }
151 }
152 if (!xResult.is() && xFactory.is() )
153 {
154 // Always fall back to OfficeFolderPicker.
155 xResult = xFactory->createInstanceWithContext (
156 "com.sun.star.ui.dialogs.OfficeFolderPicker",
157 context);
158 }
159 if (xResult.is())
160 {
161 // Add to FolderPicker history.
162 svt::addFolderPicker (xResult);
163 }
164 return xResult;
165}
166
168{
169 return "com.sun.star.comp.svt.FolderPicker";
170}
171
173{
174 Sequence< OUString > aServiceNames { "com.sun.star.ui.dialogs.FolderPicker" };
175 return aServiceNames;
176}
177
178/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static css::uno::Reference< css::ui::dialogs::XFilePicker2 > createFilePicker(const css::uno::Reference< css::uno::XComponentContext > &rServiceManager)
static css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rServiceManager)
static const OUString & GetDesktopEnvironment()
static bool IsHeadlessModeEnabled()
Reference< XSingleServiceFactory > xFactory
Sequence< OUString > aServiceNames
Reference< css::uno::XInterface > FilePicker_CreateInstance(Reference< css::uno::XComponentContext > const &context)
Definition: fpicker.cxx:58
static OUString FilePicker_getSystemPickerServiceName()
Definition: fpicker.cxx:37
OUString FilePicker_getImplementationName()
Definition: fpicker.cxx:102
static bool UseSystemFileDialog()
Definition: fpicker.cxx:53
Sequence< OUString > FilePicker_getSupportedServiceNames()
Definition: fpicker.cxx:107
static OUString FolderPicker_getSystemPickerServiceName()
Definition: fpicker.cxx:116
Reference< css::uno::XInterface > FolderPicker_CreateInstance(Reference< css::uno::XComponentContext > const &context)
Definition: fpicker.cxx:126
OUString FolderPicker_getImplementationName()
Definition: fpicker.cxx:167
Sequence< OUString > FolderPicker_getSupportedServiceNames()
Definition: fpicker.cxx:172
void addFilePicker(const Reference< XInterface > &_rxPicker)
void addFolderPicker(const Reference< XInterface > &_rxPicker)