/src/libreoffice/svtools/source/uno/fpicker.cxx
Line | Count | Source |
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 | | |
24 | | #include <svl/pickerhistoryaccess.hxx> |
25 | | #include <officecfg/Office/Common.hxx> |
26 | | |
27 | | #include <vcl/DesktopType.hxx> |
28 | | #include <vcl/svapp.hxx> |
29 | | |
30 | | #include "fpicker.hxx" |
31 | | |
32 | | using css::uno::Reference; |
33 | | using css::uno::Sequence; |
34 | | |
35 | | /* |
36 | | * FilePicker implementation. |
37 | | */ |
38 | | static OUString FilePicker_getSystemPickerServiceName() |
39 | 0 | { |
40 | 0 | #ifdef UNX |
41 | 0 | if (Application::GetDesktopEnvironment() == DesktopType::macOS) |
42 | 0 | return u"com.sun.star.ui.dialogs.AquaFilePicker"_ustr; |
43 | 0 | else |
44 | 0 | return u"com.sun.star.ui.dialogs.SystemFilePicker"_ustr; |
45 | 0 | #endif |
46 | | #ifdef _WIN32 |
47 | | return "com.sun.star.ui.dialogs.Win32FilePicker"; |
48 | | #endif |
49 | 0 | } |
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 |
53 | | static bool UseSystemFileDialog() |
54 | 0 | { |
55 | 0 | return !Application::IsHeadlessModeEnabled() && officecfg::Office::Common::Misc::UseSystemFileDialog::get(); |
56 | 0 | } |
57 | | |
58 | | Reference< css::uno::XInterface > FilePicker_CreateInstance ( |
59 | | Reference< css::uno::XComponentContext > const & context) |
60 | 0 | { |
61 | 0 | Reference< css::uno::XInterface > xResult; |
62 | |
|
63 | 0 | if (!context.is()) |
64 | 0 | return xResult; |
65 | | |
66 | 0 | Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager()); |
67 | 0 | if (xFactory.is() && UseSystemFileDialog()) |
68 | 0 | { |
69 | 0 | xResult.set( Application::createFilePicker( context ) ); |
70 | |
|
71 | 0 | if (!xResult.is()) |
72 | 0 | { |
73 | 0 | try |
74 | 0 | { |
75 | 0 | xResult = xFactory->createInstanceWithContext ( |
76 | 0 | FilePicker_getSystemPickerServiceName(), |
77 | 0 | context); |
78 | 0 | } |
79 | 0 | catch (css::uno::Exception const &) |
80 | 0 | { |
81 | | // Handled below (see @ fallback). |
82 | 0 | } |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | |
|
87 | 0 | if (!xResult.is() && xFactory.is()) |
88 | 0 | { |
89 | | // Always fall back to OfficeFilePicker. |
90 | 0 | xResult = xFactory->createInstanceWithContext ( |
91 | 0 | u"com.sun.star.ui.dialogs.OfficeFilePicker"_ustr, |
92 | 0 | context); |
93 | 0 | } |
94 | 0 | if (xResult.is()) |
95 | 0 | { |
96 | | // Add to FilePicker history. |
97 | 0 | svt::addFilePicker (xResult); |
98 | 0 | } |
99 | 0 | return xResult; |
100 | 0 | } |
101 | | |
102 | | OUString FilePicker_getImplementationName() |
103 | 0 | { |
104 | 0 | return u"com.sun.star.comp.svt.FilePicker"_ustr; |
105 | 0 | } |
106 | | |
107 | | Sequence< OUString > FilePicker_getSupportedServiceNames() |
108 | 0 | { |
109 | 0 | Sequence< OUString > aServiceNames { u"com.sun.star.ui.dialogs.FilePicker"_ustr }; |
110 | 0 | return aServiceNames; |
111 | 0 | } |
112 | | |
113 | | /* |
114 | | * FolderPicker implementation. |
115 | | */ |
116 | | static OUString FolderPicker_getSystemPickerServiceName() |
117 | 0 | { |
118 | 0 | #ifdef UNX |
119 | 0 | if (Application::GetDesktopEnvironment() == DesktopType::macOS) |
120 | 0 | return u"com.sun.star.ui.dialogs.AquaFolderPicker"_ustr; |
121 | 0 | #endif |
122 | 0 | return u"com.sun.star.ui.dialogs.SystemFolderPicker"_ustr; |
123 | 0 | } |
124 | | |
125 | | Reference< css::uno::XInterface > FolderPicker_CreateInstance ( |
126 | | Reference< css::uno::XComponentContext > const & context) |
127 | 0 | { |
128 | 0 | Reference< css::uno::XInterface > xResult; |
129 | |
|
130 | 0 | if (!context.is()) |
131 | 0 | return xResult; |
132 | | |
133 | 0 | Reference< css::lang::XMultiComponentFactory > xFactory (context->getServiceManager()); |
134 | 0 | if (xFactory.is() && UseSystemFileDialog()) |
135 | 0 | { |
136 | 0 | xResult.set( Application::createFolderPicker( context ) ); |
137 | 0 | if (!xResult.is()) |
138 | 0 | { |
139 | 0 | try |
140 | 0 | { |
141 | 0 | xResult = xFactory->createInstanceWithContext ( |
142 | 0 | FolderPicker_getSystemPickerServiceName(), |
143 | 0 | context); |
144 | 0 | } |
145 | 0 | catch (css::uno::Exception const &) |
146 | 0 | { |
147 | | // Handled below (see @ fallback). |
148 | 0 | } |
149 | 0 | } |
150 | 0 | } |
151 | 0 | if (!xResult.is() && xFactory.is() ) |
152 | 0 | { |
153 | | // Always fall back to OfficeFolderPicker. |
154 | 0 | xResult = xFactory->createInstanceWithContext ( |
155 | 0 | u"com.sun.star.ui.dialogs.OfficeFolderPicker"_ustr, |
156 | 0 | context); |
157 | 0 | } |
158 | 0 | if (xResult.is()) |
159 | 0 | { |
160 | | // Add to FolderPicker history. |
161 | 0 | svt::addFolderPicker (xResult); |
162 | 0 | } |
163 | 0 | return xResult; |
164 | 0 | } |
165 | | |
166 | | OUString FolderPicker_getImplementationName() |
167 | 0 | { |
168 | 0 | return u"com.sun.star.comp.svt.FolderPicker"_ustr; |
169 | 0 | } |
170 | | |
171 | | Sequence< OUString > FolderPicker_getSupportedServiceNames() |
172 | 0 | { |
173 | 0 | Sequence< OUString > aServiceNames { u"com.sun.star.ui.dialogs.FolderPicker"_ustr }; |
174 | 0 | return aServiceNames; |
175 | 0 | } |
176 | | |
177 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |