tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / desktop / source / deployment / registry / inc / dp_backend.h
bloba68420d6b01988a8ec86fcf0a0e719cb9f7f6816
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <dp_shared.hxx>
23 #include <dp_interact.h>
24 #include <rtl/ref.hxx>
25 #include <cppuhelper/basemutex.hxx>
26 #include <cppuhelper/implbase.hxx>
27 #include <cppuhelper/compbase.hxx>
28 #include <com/sun/star/lang/XEventListener.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/deployment/XPackageRegistry.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <unordered_map>
33 #include <strings.hrc>
34 #include <utility>
36 namespace dp_registry::backend
39 class PackageRegistryBackend;
41 inline constexpr OUString BACKEND_SERVICE_NAME = u"com.sun.star.deployment.PackageRegistryBackend"_ustr;
43 typedef ::cppu::WeakComponentImplHelper<
44 css::deployment::XPackage > t_PackageBase;
47 class Package : protected cppu::BaseMutex, public t_PackageBase
49 PackageRegistryBackend * getMyBackend() const;
50 void processPackage_impl(
51 bool registerPackage,
52 bool startup,
53 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
54 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
56 protected:
57 ::rtl::Reference<PackageRegistryBackend> m_myBackend;
58 const OUString m_url;
59 OUString m_name;
60 OUString m_displayName;
61 const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType;
62 const bool m_bRemoved;
63 //Only set if m_bRemoved = true;
64 const OUString m_identifier;
66 void check() const;
67 void fireModified();
68 virtual void SAL_CALL disposing() override;
70 void checkAborted(
71 ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel );
73 // @@@ to be implemented by specific backend:
74 virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
75 isRegistered_(
76 ::osl::ResettableMutexGuard & guard,
77 ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
78 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
79 = 0;
80 virtual void processPackage_(
81 ::osl::ResettableMutexGuard & guard,
82 bool registerPackage,
83 bool startup,
84 ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
85 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
86 = 0;
88 virtual ~Package() override;
89 Package( ::rtl::Reference<PackageRegistryBackend> myBackend,
90 OUString url,
91 OUString name,
92 OUString displayName,
93 css::uno::Reference<css::deployment::XPackageTypeInfo> const & xPackageType,
94 bool bRemoved,
95 OUString identifier);
97 public:
99 class TypeInfo :
100 public ::cppu::WeakImplHelper<css::deployment::XPackageTypeInfo>
102 const OUString m_mediaType;
103 const OUString m_fileFilter;
104 const OUString m_shortDescr;
105 public:
106 virtual ~TypeInfo() override;
107 TypeInfo( OUString mediaType,
108 OUString fileFilter,
109 OUString shortDescr )
110 : m_mediaType(std::move(mediaType)), m_fileFilter(std::move(fileFilter)),
111 m_shortDescr(std::move(shortDescr))
113 // XPackageTypeInfo
114 virtual OUString SAL_CALL getMediaType() override;
115 virtual OUString SAL_CALL getDescription() override;
116 virtual OUString SAL_CALL getShortDescription() override;
117 virtual OUString SAL_CALL getFileFilter() override;
118 virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast,
119 sal_Bool smallIcon ) override;
122 // XComponent
123 virtual void SAL_CALL dispose() override;
124 virtual void SAL_CALL addEventListener(
125 css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
126 virtual void SAL_CALL removeEventListener(
127 css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
129 // XModifyBroadcaster
130 virtual void SAL_CALL addModifyListener(
131 css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
132 virtual void SAL_CALL removeModifyListener(
133 css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
135 // XPackage
136 virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
137 createAbortChannel() override;
138 virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
139 SAL_CALL isRegistered(
140 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
141 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
143 virtual ::sal_Int32 SAL_CALL checkPrerequisites(
144 const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel,
145 const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv,
146 sal_Bool noLicenseChecking) override;
148 virtual ::sal_Bool SAL_CALL checkDependencies(
149 const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv ) override;
151 virtual void SAL_CALL registerPackage(
152 sal_Bool startup,
153 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
154 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
155 virtual void SAL_CALL revokePackage(
156 sal_Bool startup,
157 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
158 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
159 virtual sal_Bool SAL_CALL isBundle() override;
160 virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
161 SAL_CALL getBundle(
162 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
163 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
164 virtual OUString SAL_CALL getName() override;
165 virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override;
166 virtual OUString SAL_CALL getVersion() override;
167 virtual OUString SAL_CALL getURL() override;
168 virtual OUString SAL_CALL getDisplayName() override;
169 virtual OUString SAL_CALL getDescription() override;
170 virtual OUString SAL_CALL getLicenseText() override;
171 virtual css::uno::Sequence< OUString > SAL_CALL
172 getUpdateInformationURLs() override;
173 virtual css::beans::StringPair SAL_CALL getPublisherInfo() override;
174 virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL
175 getIcon( sal_Bool bHighContrast ) override;
176 virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL
177 getPackageType() override;
178 virtual void SAL_CALL exportTo(
179 OUString const & destFolderURL,
180 OUString const & newTitle,
181 sal_Int32 nameClashAction,
182 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
183 virtual OUString SAL_CALL getRepositoryName() override;
184 virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override;
185 virtual sal_Bool SAL_CALL isRemoved() override;
189 typedef ::cppu::WeakComponentImplHelper<
190 css::lang::XEventListener,
191 css::deployment::XPackageRegistry,
192 css::lang::XServiceInfo > t_BackendBase;
195 class PackageRegistryBackend
196 : protected cppu::BaseMutex, public t_BackendBase
198 //The map held originally WeakReferences. The map entries are removed in the disposing
199 //function, which is called when the XPackages are destructed or they are
200 //explicitly disposed. The latter happens, for example, when an extension is
201 //removed (see dp_manager.cxx). However, because of how the help systems work, now
202 // XPackageManager::getDeployedPackages is called often. This results in a lot
203 //of bindPackage calls which are costly. Therefore we keep hard references in
204 //the map now.
205 typedef std::unordered_map<
206 OUString, css::uno::Reference<css::deployment::XPackage> > t_string2ref;
207 t_string2ref m_bound;
209 protected:
210 OUString m_cachePath;
211 css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
213 OUString m_context;
214 // currently only for library containers:
215 enum class Context {
216 Unknown, User, Shared, Bundled, Tmp, Document
217 } m_eContext;
219 static OUString StrCannotDetectMediaType() { return DpResId(RID_STR_CANNOT_DETECT_MEDIA_TYPE); }
220 static OUString StrUnsupportedMediaType() { return DpResId(RID_STR_UNSUPPORTED_MEDIA_TYPE); }
222 // @@@ to be implemented by specific backend:
223 virtual css::uno::Reference<css::deployment::XPackage> bindPackage_(
224 OUString const & url, OUString const & mediaType,
225 bool bRemoved, OUString const & identifier,
226 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
227 = 0;
229 void check();
230 virtual void SAL_CALL disposing() override;
232 virtual ~PackageRegistryBackend() override;
233 PackageRegistryBackend(
234 css::uno::Sequence<css::uno::Any> const & args,
235 css::uno::Reference<css::uno::XComponentContext> const & xContext );
237 /* creates a folder with a unique name.
238 If url is empty then it is created in the backend folder, otherwise
239 at a location relative to that folder specified by url.
241 OUString createFolder(
242 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
243 /* deletes folders and files.
245 All folder all files which end with ".tmp" or ".tmp_" and which are
246 not used are deleted.
248 void deleteUnusedFolders(
249 std::vector< OUString> const & usedFolders);
250 /* deletes one folder with a "temporary" name and the corresponding
251 tmp file, which was used to derive the folder name.
253 static void deleteTempFolder(
254 OUString const & folderUrl);
256 public:
257 static OUString StrRegisteringPackage() { return DpResId(RID_STR_REGISTERING_PACKAGE); }
258 static OUString StrRevokingPackage() { return DpResId(RID_STR_REVOKING_PACKAGE); }
260 css::uno::Reference<css::uno::XComponentContext> const &
261 getComponentContext() const { return m_xComponentContext; }
263 OUString const & getCachePath() const { return m_cachePath; }
264 bool transientMode() const { return m_cachePath.isEmpty(); }
266 const OUString& getContext() const {return m_context; }
268 // XEventListener
269 virtual void SAL_CALL disposing( css::lang::EventObject const & evt ) override;
271 // XPackageRegistry
272 virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage(
273 OUString const & url, OUString const & mediaType,
274 sal_Bool bRemoved, OUString const & identifier,
275 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
277 // virtual void SAL_CALL packageRemoved(
278 // OUString const & url, OUString const & mediaType)
279 // throw (css::deployment::DeploymentException,
280 // css::uno::RuntimeException);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */