1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <cppuhelper/implbase.hxx>
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>
30 #include "updatecheckconfiglistener.hxx"
31 #include "updateinfo.hxx"
33 /* This helper class provides by name access to a sequence of named values */
34 class NamedValueByNameAccess
36 const css::uno::Sequence
< css::beans::NamedValue
>& m_rValues
;
39 explicit NamedValueByNameAccess(
40 const css::uno::Sequence
< css::beans::NamedValue
>& rValues
) :
41 m_rValues(rValues
) {} ;
43 css::uno::Any
getValue(const char * pName
);
47 /* This class encapsulates the configuration item actually used for storing the state
48 * the update check is actually in.
50 class UpdateCheckROModel
53 explicit UpdateCheckROModel(NamedValueByNameAccess
& aNameAccess
) : m_aNameAccess(aNameAccess
) {};
55 bool isAutoCheckEnabled() const;
56 bool isDownloadPaused() const;
57 OUString
getLocalFileName() const;
58 sal_Int64
getDownloadSize() const;
60 OUString
getUpdateEntryVersion() const;
61 void getUpdateEntry(UpdateInfo
& rInfo
) const;
65 OUString
getStringValue(const char *) const;
67 NamedValueByNameAccess
& m_aNameAccess
;
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.
76 class UpdateCheckConfig
: public ::cppu::WeakImplHelper
<
77 css::container::XNameReplace
,
78 css::util::XChangesBatch
,
79 css::lang::XServiceInfo
>
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
);
86 virtual ~UpdateCheckConfig() override
;
90 static ::rtl::Reference
< UpdateCheckConfig
> get(
91 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
92 const ::rtl::Reference
< UpdateCheckConfigListener
>& rListener
= ::rtl::Reference
< UpdateCheckConfigListener
>());
94 // Should really implement ROModel...
95 bool isAutoCheckEnabled() const;
96 bool isAutoDownloadEnabled() const;
97 OUString
getUpdateEntryVersion() const;
99 /* Updates the timestamp of last check, but does not commit the change
100 * as either clearUpdateFound() or setUpdateFound() are expected to get
103 void updateLastChecked();
105 /* Returns the date of the last successful check in seconds since 1970 */
106 sal_Int64
getLastChecked() const;
108 /* Returns configured check interval in seconds */
109 sal_Int64
getCheckInterval() const;
111 /* Reset values of previously remembered update
113 void clearUpdateFound();
115 /* Stores the specified data of an available update
117 void storeUpdateFound(const UpdateInfo
& rInfo
, const OUString
& aCurrentBuild
);
119 // Returns the local file name of a started download
120 OUString
getLocalFileName() const;
122 // Returns the local file name of a started download
123 OUString
getDownloadDestination() const;
125 // stores the local file name of a just started download
126 void storeLocalFileName(const OUString
& rFileName
, sal_Int64 nFileSize
);
128 // Removes the local file name of a download
129 void clearLocalFileName();
131 // Stores the bool value for manually paused downloads
132 void storeDownloadPaused(bool paused
);
134 // Returns the directory for downloaded files
135 static OUString
getDownloadsDirectory();
137 // Returns a directory accessible for all users
138 static OUString
getAllUsersDirectory();
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
);
147 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
148 virtual sal_Bool SAL_CALL
hasElements( ) override
;
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
;
156 virtual void SAL_CALL
replaceByName( const OUString
& aName
, const css::uno::Any
& aElement
) override
;
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
;
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
;
170 static OUString
getSubVersion( const OUString
& rVersion
, sal_Int32
*nIndex
);
171 static bool isVersionGreater( const OUString
& rVersion1
, const OUString
& rVersion2
);
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
;
179 /// @throws css::uno::RuntimeException
180 template <typename T
>
181 T
getValue( const css::uno::Sequence
< css::beans::NamedValue
>& rNamedValues
, const char * pszName
)
183 for( css::beans::NamedValue
const & nv
: rNamedValues
)
185 // Unfortunately gcc-3.3 does not like Any.get<T>();
186 if( nv
.Name
.equalsAscii( pszName
) )
189 if( ! (nv
.Value
>>= value
) )
190 throw css::uno::RuntimeException(
192 cppu_Any_extraction_failure_msg(
194 ::cppu::getTypeFavourUnsigned(&value
).getTypeLibType() ),
196 css::uno::Reference
< css::uno::XInterface
>() );
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */