LibreOffice Module extensions (master) 1
updatecheckconfig.hxx
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#pragma once
21
23#include <com/sun/star/beans/NamedValue.hpp>
24#include <com/sun/star/container/XNameContainer.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
26#include <com/sun/star/uno/XComponentContext.hpp>
27#include <com/sun/star/util/XChangesBatch.hpp>
28#include <rtl/ref.hxx>
29
31#include "updateinfo.hxx"
32
33/* This helper class provides by name access to a sequence of named values */
35{
36 const css::uno::Sequence< css::beans::NamedValue >& m_rValues;
37
38public:
40 const css::uno::Sequence< css::beans::NamedValue >& rValues) :
41 m_rValues(rValues) {} ;
42
43 css::uno::Any getValue(const char * pName);
44};
45
46
47/* This class encapsulates the configuration item actually used for storing the state
48 * the update check is actually in.
49 */
51{
52public:
53 explicit UpdateCheckROModel(NamedValueByNameAccess& aNameAccess) : m_aNameAccess(aNameAccess) {};
54
55 bool isAutoCheckEnabled() const;
56 bool isDownloadPaused() const;
57 OUString getLocalFileName() const;
58 sal_Int64 getDownloadSize() const;
59
60 OUString getUpdateEntryVersion() const;
61 void getUpdateEntry(UpdateInfo& rInfo) const;
62
63private:
64
65 OUString getStringValue(const char *) const;
66
68};
69
70
71/* This class implements the non published UNO service com.sun.star.setup.UpdateCheckConfig,
72 * which primary use is to be able to track changes done in the Tools -> Options page of this
73 * component, as this is not supported by the OOo configuration for extendable groups.
74 */
75
76class UpdateCheckConfig : public ::cppu::WeakImplHelper<
77 css::container::XNameReplace,
78 css::util::XChangesBatch,
79 css::lang::XServiceInfo >
80{
81 UpdateCheckConfig( const css::uno::Reference< css::container::XNameContainer >& xContainer,
82 const css::uno::Reference< css::container::XNameContainer >& xAvailableUpdates,
83 const css::uno::Reference< css::container::XNameContainer >& xIgnoredUpdates,
84 const ::rtl::Reference< UpdateCheckConfigListener >& rListener );
85
86 virtual ~UpdateCheckConfig() override;
87
88public:
89
90 static ::rtl::Reference< UpdateCheckConfig > get(
91 const css::uno::Reference< css::uno::XComponentContext >& xContext,
92 const ::rtl::Reference< UpdateCheckConfigListener >& rListener = ::rtl::Reference< UpdateCheckConfigListener >());
93
94 // Should really implement ROModel...
95 bool isAutoCheckEnabled() const;
96 bool isAutoDownloadEnabled() const;
97 OUString getUpdateEntryVersion() const;
98
99 /* Updates the timestamp of last check, but does not commit the change
100 * as either clearUpdateFound() or setUpdateFound() are expected to get
101 * called next.
102 */
103 void updateLastChecked();
104
105 /* Returns the date of the last successful check in seconds since 1970 */
106 sal_Int64 getLastChecked() const;
107
108 /* Returns configured check interval in seconds */
109 sal_Int64 getCheckInterval() const;
110
111 /* Reset values of previously remembered update
112 */
113 void clearUpdateFound();
114
115 /* Stores the specified data of an available update
116 */
117 void storeUpdateFound(const UpdateInfo& rInfo, const OUString& aCurrentBuild);
118
119 // Returns the local file name of a started download
120 OUString getLocalFileName() const;
121
122 // Returns the local file name of a started download
123 OUString getDownloadDestination() const;
124
125 // stores the local file name of a just started download
126 void storeLocalFileName(const OUString& rFileName, sal_Int64 nFileSize);
127
128 // Removes the local file name of a download
129 void clearLocalFileName();
130
131 // Stores the bool value for manually paused downloads
132 void storeDownloadPaused(bool paused);
133
134 // Returns the directory for downloaded files
135 static OUString getDownloadsDirectory();
136
137 // Returns a directory accessible for all users
138 static OUString getAllUsersDirectory();
139
140 // store and retrieve information about extensions
141 bool storeExtensionVersion( const OUString& rExtensionName,
142 const OUString& rVersion );
143 bool checkExtensionVersion( const OUString& rExtensionName,
144 const OUString& rVersion );
145
146 // XElementAccess
147 virtual css::uno::Type SAL_CALL getElementType( ) override;
148 virtual sal_Bool SAL_CALL hasElements( ) override;
149
150 // XNameAccess
151 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
152 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
153 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
154
155 // XNameReplace
156 virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
157
158 // XChangesBatch
159 virtual void SAL_CALL commitChanges( ) override;
160 virtual sal_Bool SAL_CALL hasPendingChanges( ) override;
161 virtual css::uno::Sequence< css::util::ElementChange > SAL_CALL getPendingChanges( ) override;
162
163 // XServiceInfo
164 virtual OUString SAL_CALL getImplementationName() override;
165 virtual sal_Bool SAL_CALL supportsService(OUString const & serviceName) override;
166 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
167
168private:
169
170 static OUString getSubVersion( const OUString& rVersion, sal_Int32 *nIndex );
171 static bool isVersionGreater( const OUString& rVersion1, const OUString& rVersion2 );
172
173 const css::uno::Reference< css::container::XNameContainer > m_xContainer;
174 const css::uno::Reference< css::container::XNameContainer > m_xAvailableUpdates;
175 const css::uno::Reference< css::container::XNameContainer > m_xIgnoredUpdates;
176 const ::rtl::Reference< UpdateCheckConfigListener > m_rListener;
177};
178
180template <typename T>
181T getValue( const css::uno::Sequence< css::beans::NamedValue >& rNamedValues, const char * pszName )
182{
183 for( css::beans::NamedValue const & nv : rNamedValues )
184 {
185 // Unfortunately gcc-3.3 does not like Any.get<T>();
186 if( nv.Name.equalsAscii( pszName ) )
187 {
188 T value = T();
189 if( ! (nv.Value >>= value) )
190 throw css::uno::RuntimeException(
191 OUString(
193 &nv.Value,
194 ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
195 SAL_NO_ACQUIRE ),
196 css::uno::Reference< css::uno::XInterface >() );
197
198 return value;
199 }
200 }
201
202 return T();
203}
204
205/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool paused
const css::uno::Sequence< css::beans::NamedValue > & m_rValues
NamedValueByNameAccess(const css::uno::Sequence< css::beans::NamedValue > &rValues)
css::uno::Any getValue(const char *pName)
const css::uno::Reference< css::container::XNameContainer > m_xIgnoredUpdates
virtual ~UpdateCheckConfig() override
void storeDownloadPaused(bool paused)
sal_Int64 getLastChecked() const
void storeLocalFileName(const OUString &rFileName, sal_Int64 nFileSize)
sal_Int64 getCheckInterval() const
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
static OUString getSubVersion(const OUString &rVersion, sal_Int32 *nIndex)
virtual sal_Bool SAL_CALL hasElements() override
static OUString getAllUsersDirectory()
static OUString getDownloadsDirectory()
bool storeExtensionVersion(const OUString &rExtensionName, const OUString &rVersion)
static bool isVersionGreater(const OUString &rVersion1, const OUString &rVersion2)
checks if the second version string is greater than the first one
OUString getUpdateEntryVersion() const
static ::rtl::Reference< UpdateCheckConfig > get(const css::uno::Reference< css::uno::XComponentContext > &xContext, const ::rtl::Reference< UpdateCheckConfigListener > &rListener=::rtl::Reference< UpdateCheckConfigListener >())
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual css::uno::Sequence< css::util::ElementChange > SAL_CALL getPendingChanges() override
UpdateCheckConfig(const css::uno::Reference< css::container::XNameContainer > &xContainer, const css::uno::Reference< css::container::XNameContainer > &xAvailableUpdates, const css::uno::Reference< css::container::XNameContainer > &xIgnoredUpdates, const ::rtl::Reference< UpdateCheckConfigListener > &rListener)
virtual sal_Bool SAL_CALL supportsService(OUString const &serviceName) override
bool isAutoCheckEnabled() const
OUString getLocalFileName() const
OUString getDownloadDestination() const
virtual OUString SAL_CALL getImplementationName() override
const ::rtl::Reference< UpdateCheckConfigListener > m_rListener
virtual sal_Bool SAL_CALL hasPendingChanges() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool isAutoDownloadEnabled() const
virtual void SAL_CALL commitChanges() override
bool checkExtensionVersion(const OUString &rExtensionName, const OUString &rVersion)
void storeUpdateFound(const UpdateInfo &rInfo, const OUString &aCurrentBuild)
const css::uno::Reference< css::container::XNameContainer > m_xContainer
const css::uno::Reference< css::container::XNameContainer > m_xAvailableUpdates
virtual css::uno::Type SAL_CALL getElementType() override
OUString getStringValue(const char *) const
void getUpdateEntry(UpdateInfo &rInfo) const
OUString getUpdateEntryVersion() const
sal_Int64 getDownloadSize() const
OUString getLocalFileName() const
UpdateCheckROModel(NamedValueByNameAccess &aNameAccess)
bool isDownloadPaused() const
bool isAutoCheckEnabled() const
NamedValueByNameAccess & m_aNameAccess
IJScriptValueObject VARIANT value
Definition: comifaces.hxx:28
rtl_uString *SAL_CALL cppu_Any_extraction_failure_msg(uno_Any const *pAny, typelib_TypeDescriptionReference *pType) SAL_THROW_EXTERN_C()
sal_Int32 nIndex
OUString aName
unsigned char sal_Bool
T getValue(const css::uno::Sequence< css::beans::NamedValue > &rNamedValues, const char *pszName)