Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / desktop / source / deployment / registry / inc / dp_backend.h
blob319c0904541c6436b96ff4789a961d47eff84eda
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 #ifndef INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_REGISTRY_INC_DP_BACKEND_H
21 #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_REGISTRY_INC_DP_BACKEND_H
23 #include <dp_misc.h>
24 #include <dp_resource.h>
25 #include <dp_shared.hxx>
26 #include <dp_interact.h>
27 #include <rtl/ref.hxx>
28 #include <cppuhelper/weakref.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <cppuhelper/compbase.hxx>
31 #include <com/sun/star/lang/XEventListener.hpp>
32 #include <com/sun/star/deployment/XPackageRegistry.hpp>
33 #include <com/sun/star/deployment/XPackageManager.hpp>
34 #include <com/sun/star/deployment/InvalidRemovedParameterException.hpp>
35 #include <unordered_map>
36 #include <strings.hrc>
38 namespace dp_registry
40 namespace backend
43 class PackageRegistryBackend;
45 #define BACKEND_SERVICE_NAME "com.sun.star.deployment.PackageRegistryBackend"
47 typedef ::cppu::WeakComponentImplHelper<
48 css::deployment::XPackage > t_PackageBase;
51 class Package : protected ::dp_misc::MutexHolder, public t_PackageBase
53 PackageRegistryBackend * getMyBackend() const;
54 void processPackage_impl(
55 bool registerPackage,
56 bool startup,
57 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
58 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
60 protected:
61 ::rtl::Reference<PackageRegistryBackend> m_myBackend;
62 const OUString m_url;
63 OUString m_name;
64 OUString m_displayName;
65 const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType;
66 const bool m_bRemoved;
67 //Only set if m_bRemoved = true;
68 const OUString m_identifier;
70 void check() const;
71 void fireModified();
72 virtual void SAL_CALL disposing() override;
74 void checkAborted(
75 ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel );
77 // @@@ to be implemented by specific backend:
78 virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
79 isRegistered_(
80 ::osl::ResettableMutexGuard & guard,
81 ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
82 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
83 = 0;
84 virtual void processPackage_(
85 ::osl::ResettableMutexGuard & guard,
86 bool registerPackage,
87 bool startup,
88 ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
89 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
90 = 0;
92 virtual ~Package() override;
93 Package( ::rtl::Reference<PackageRegistryBackend> const & myBackend,
94 OUString const & url,
95 OUString const & name,
96 OUString const & displayName,
97 css::uno::Reference<css::deployment::XPackageTypeInfo> const &
98 xPackageType,
99 bool bRemoved,
100 OUString const & identifier);
102 public:
104 class TypeInfo :
105 public ::cppu::WeakImplHelper<css::deployment::XPackageTypeInfo>
107 const OUString m_mediaType;
108 const OUString m_fileFilter;
109 const OUString m_shortDescr;
110 public:
111 virtual ~TypeInfo() override;
112 TypeInfo( OUString const & mediaType,
113 OUString const & fileFilter,
114 OUString const & shortDescr )
115 : m_mediaType(mediaType), m_fileFilter(fileFilter),
116 m_shortDescr(shortDescr)
118 // XPackageTypeInfo
119 virtual OUString SAL_CALL getMediaType() override;
120 virtual OUString SAL_CALL getDescription() override;
121 virtual OUString SAL_CALL getShortDescription() override;
122 virtual OUString SAL_CALL getFileFilter() override;
123 virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast,
124 sal_Bool smallIcon ) override;
127 // XComponent
128 virtual void SAL_CALL dispose() override;
129 virtual void SAL_CALL addEventListener(
130 css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
131 virtual void SAL_CALL removeEventListener(
132 css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
134 // XModifyBroadcaster
135 virtual void SAL_CALL addModifyListener(
136 css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
137 virtual void SAL_CALL removeModifyListener(
138 css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
140 // XPackage
141 virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
142 createAbortChannel() override;
143 virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
144 SAL_CALL isRegistered(
145 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
146 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
148 virtual ::sal_Int32 SAL_CALL checkPrerequisites(
149 const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel,
150 const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv,
151 sal_Bool noLicenseChecking) override;
153 virtual ::sal_Bool SAL_CALL checkDependencies(
154 const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv ) override;
156 virtual void SAL_CALL registerPackage(
157 sal_Bool startup,
158 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
159 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
160 virtual void SAL_CALL revokePackage(
161 sal_Bool startup,
162 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
163 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
164 virtual sal_Bool SAL_CALL isBundle() override;
165 virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
166 SAL_CALL getBundle(
167 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
168 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
169 virtual OUString SAL_CALL getName() override;
170 virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override;
171 virtual OUString SAL_CALL getVersion() override;
172 virtual OUString SAL_CALL getURL() override;
173 virtual OUString SAL_CALL getDisplayName() override;
174 virtual OUString SAL_CALL getDescription() override;
175 virtual OUString SAL_CALL getLicenseText() override;
176 virtual css::uno::Sequence< OUString > SAL_CALL
177 getUpdateInformationURLs() override;
178 virtual css::beans::StringPair SAL_CALL getPublisherInfo() override;
179 virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL
180 getIcon( sal_Bool bHighContrast ) override;
181 virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL
182 getPackageType() override;
183 virtual void SAL_CALL exportTo(
184 OUString const & destFolderURL,
185 OUString const & newTitle,
186 sal_Int32 nameClashAction,
187 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
188 virtual OUString SAL_CALL getRepositoryName() override;
189 virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override;
190 virtual sal_Bool SAL_CALL isRemoved() override;
194 typedef ::cppu::WeakComponentImplHelper<
195 css::lang::XEventListener,
196 css::deployment::XPackageRegistry > t_BackendBase;
199 class PackageRegistryBackend
200 : protected ::dp_misc::MutexHolder, public t_BackendBase
202 //The map held originally WeakReferences. The map entries are removed in the disposing
203 //function, which is called when the XPackages are destructed or they are
204 //explicitly disposed. The latter happens, for example, when an extension is
205 //removed (see dp_manager.cxx). However, because of how the help systems work, now
206 // XPackageManager::getDeployedPackages is called often. This results in a lot
207 //of bindPackage calls which are costly. Therefore we keep hard references in
208 //the map now.
209 typedef std::unordered_map<
210 OUString, css::uno::Reference<css::deployment::XPackage> > t_string2ref;
211 t_string2ref m_bound;
213 protected:
214 OUString m_cachePath;
215 css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
217 OUString m_context;
218 // currently only for library containers:
219 enum class Context {
220 Unknown, User, Shared, Bundled, Tmp, Document
221 } m_eContext;
223 static OUString StrCannotDetectMediaType() { return DpResId(RID_STR_CANNOT_DETECT_MEDIA_TYPE); }
224 static OUString StrUnsupportedMediaType() { return DpResId(RID_STR_UNSUPPORTED_MEDIA_TYPE); }
226 // @@@ to be implemented by specific backend:
227 virtual css::uno::Reference<css::deployment::XPackage> bindPackage_(
228 OUString const & url, OUString const & mediaType,
229 bool bRemoved, OUString const & identifier,
230 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
231 = 0;
233 void check();
234 virtual void SAL_CALL disposing() override;
236 virtual ~PackageRegistryBackend() override;
237 PackageRegistryBackend(
238 css::uno::Sequence<css::uno::Any> const & args,
239 css::uno::Reference<css::uno::XComponentContext> const & xContext );
241 /* creates a folder with a unique name.
242 If url is empty then it is created in the backend folder, otherwise
243 at a location relative to that folder specified by url.
245 OUString createFolder(
246 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
247 /* deletes folders and files.
249 All folder all files which end with ".tmp" or ".tmp_" and which are
250 not used are deleted.
252 void deleteUnusedFolders(
253 std::vector< OUString> const & usedFolders);
254 /* deletes one folder with a "temporary" name and the corresponding
255 tmp file, which was used to derive the folder name.
257 static void deleteTempFolder(
258 OUString const & folderUrl);
260 public:
261 static OUString StrRegisteringPackage() { return DpResId(RID_STR_REGISTERING_PACKAGE); }
262 static OUString StrRevokingPackage() { return DpResId(RID_STR_REVOKING_PACKAGE); }
264 css::uno::Reference<css::uno::XComponentContext> const &
265 getComponentContext() const { return m_xComponentContext; }
267 OUString const & getCachePath() const { return m_cachePath; }
268 bool transientMode() const { return m_cachePath.isEmpty(); }
270 const OUString& getContext() const {return m_context; }
272 // XEventListener
273 virtual void SAL_CALL disposing( css::lang::EventObject const & evt ) override;
275 // XPackageRegistry
276 virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage(
277 OUString const & url, OUString const & mediaType,
278 sal_Bool bRemoved, OUString const & identifier,
279 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
281 // virtual void SAL_CALL packageRemoved(
282 // OUString const & url, OUString const & mediaType)
283 // throw (css::deployment::DeploymentException,
284 // css::uno::RuntimeException);
291 #endif
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */