merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / update / check / updatecheckconfig.hxx
blobbc1fd0987b18f06221838f24d15b7da928d3f4d9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include <cppuhelper/implbase3.hxx>
29 #include <com/sun/star/beans/NamedValue.hpp>
30 #include <com/sun/star/container/XNameContainer.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <com/sun/star/util/XChangesBatch.hpp>
34 #include <rtl/ref.hxx>
36 #include "updatecheckconfiglistener.hxx"
37 #include "updateinfo.hxx"
39 /* Interface to acess configuration data read-only */
40 struct IByNameAccess
42 virtual ::com::sun::star::uno::Any getValue(const sal_Char * pName) = 0;
45 /* This helper class provides by name access to a sequence of named values */
46 class NamedValueByNameAccess : public IByNameAccess
48 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& m_rValues;
50 public:
51 NamedValueByNameAccess(
52 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rValues) :
53 m_rValues(rValues) {} ;
55 virtual ~NamedValueByNameAccess();
57 virtual ::com::sun::star::uno::Any getValue(const sal_Char * pName);
61 /* This class encapsulates the configuration item actually used for storing the state
62 * the update check is actually in.
64 class UpdateCheckROModel
66 public:
67 UpdateCheckROModel(IByNameAccess& aNameAccess) : m_aNameAccess(aNameAccess) {};
69 bool isAutoCheckEnabled() const;
70 bool isDownloadPaused() const;
71 rtl::OUString getLocalFileName() const;
72 sal_Int64 getDownloadSize() const;
74 rtl::OUString getUpdateEntryVersion() const;
75 void getUpdateEntry(UpdateInfo& rInfo) const;
77 private:
79 rtl::OUString getStringValue(const sal_Char *) const;
81 IByNameAccess& m_aNameAccess;
86 /* This class implements the non published UNO service com.sun.star.setup.UpdateCheckConfig,
87 * which primary use is to be able to track changes done in the Toos -> Options page of this
88 * component, as this is not supported by the OOo configuration for extendable groups.
91 class UpdateCheckConfig : public ::cppu::WeakImplHelper3<
92 ::com::sun::star::container::XNameReplace,
93 ::com::sun::star::util::XChangesBatch,
94 ::com::sun::star::lang::XServiceInfo >
96 UpdateCheckConfig(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xContainer,
97 const ::rtl::Reference< UpdateCheckConfigListener >& rListener );
99 virtual ~UpdateCheckConfig();
101 public:
103 static ::com::sun::star::uno::Sequence< rtl::OUString > getServiceNames();
104 static rtl::OUString getImplName();
106 static ::rtl::Reference< UpdateCheckConfig > get(
107 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
108 const ::rtl::Reference< UpdateCheckConfigListener >& rListener = ::rtl::Reference< UpdateCheckConfigListener >());
110 // Should really implement ROModel ..
111 bool isAutoCheckEnabled() const;
112 bool isAutoDownloadEnabled() const;
113 rtl::OUString getUpdateEntryVersion() const;
115 /* Updates the timestamp of last check, but does not commit the change
116 * as either clearUpdateFound() or setUpdateFound() are expected to get
117 * called next.
119 void updateLastChecked();
121 /* Returns the date of the last successful check in seconds since 1970 */
122 sal_Int64 getLastChecked() const;
124 /* Returns configured check interval in seconds */
125 sal_Int64 getCheckInterval() const;
127 /* Reset values of previously remembered update
129 void clearUpdateFound();
131 /* Stores the specified data of an available update
133 void storeUpdateFound(const UpdateInfo& rInfo, const rtl::OUString& aCurrentBuild);
135 // Returns the local file name of a started download
136 rtl::OUString getLocalFileName() const;
138 // Returns the local file name of a started download
139 rtl::OUString getDownloadDestination() const;
141 // stores the local file name of a just started download
142 void storeLocalFileName(const rtl::OUString& rFileName, sal_Int64 nFileSize);
144 // Removes the local file name of a download
145 void clearLocalFileName();
147 // Stores the bool value for manually paused downloads
148 void storeDownloadPaused(bool paused);
150 // Returns the directory that acts as the user's desktop
151 static rtl::OUString getDesktopDirectory();
153 // Returns a directory accessible for all users
154 static rtl::OUString getAllUsersDirectory();
156 // store and retrieve information about extensions
157 void storeExtensionVersion( const rtl::OUString& rExtensionName,
158 const rtl::OUString& rVersion );
159 bool checkExtensionVersion( const rtl::OUString& rExtensionName,
160 const rtl::OUString& rVersion );
162 // XElementAccess
163 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( )
164 throw (::com::sun::star::uno::RuntimeException);
165 virtual sal_Bool SAL_CALL hasElements( )
166 throw (::com::sun::star::uno::RuntimeException);
168 // XNameAccess
169 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
170 throw (::com::sun::star::container::NoSuchElementException,
171 ::com::sun::star::lang::WrappedTargetException,
172 ::com::sun::star::uno::RuntimeException);
173 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( )
174 throw (::com::sun::star::uno::RuntimeException);
175 virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
176 throw (::com::sun::star::uno::RuntimeException);
178 // XNameReplace
179 virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
180 throw (::com::sun::star::lang::IllegalArgumentException,
181 ::com::sun::star::container::NoSuchElementException,
182 ::com::sun::star::lang::WrappedTargetException,
183 ::com::sun::star::uno::RuntimeException);
185 // XChangesBatch
186 virtual void SAL_CALL commitChanges( )
187 throw (::com::sun::star::lang::WrappedTargetException,
188 ::com::sun::star::uno::RuntimeException);
189 virtual ::sal_Bool SAL_CALL hasPendingChanges( )
190 throw (::com::sun::star::uno::RuntimeException);
191 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::ElementChange > SAL_CALL getPendingChanges( )
192 throw (::com::sun::star::uno::RuntimeException);
194 // XServiceInfo
195 virtual rtl::OUString SAL_CALL getImplementationName()
196 throw (::com::sun::star::uno::RuntimeException);
197 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName)
198 throw (::com::sun::star::uno::RuntimeException);
199 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames()
200 throw (::com::sun::star::uno::RuntimeException);
202 private:
204 static rtl::OUString getSubVersion( const rtl::OUString& rVersion, sal_Int32 *nIndex );
205 static bool isVersionGreater( const rtl::OUString& rVersion1, const rtl::OUString& rVersion2 );
207 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xContainer;
208 const ::rtl::Reference< UpdateCheckConfigListener > m_rListener;
211 //------------------------------------------------------------------------------
214 template <typename T>
215 T getValue( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rNamedValues, const sal_Char * pszName )
216 throw (::com::sun::star::uno::RuntimeException)
218 for( sal_Int32 n=0; n < rNamedValues.getLength(); n++ )
220 // Unfortunatly gcc-3.3 does not like Any.get<T>();
221 if( rNamedValues[n].Name.equalsAscii( pszName ) )
223 T value = T();
224 if( ! (rNamedValues[n].Value >>= value) )
225 throw ::com::sun::star::uno::RuntimeException(
226 ::rtl::OUString(
227 cppu_Any_extraction_failure_msg(
228 &rNamedValues[n].Value,
229 ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
230 SAL_NO_ACQUIRE ),
231 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
233 return value;
237 return T();