1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: updatecheckconfig.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <cppuhelper/implbase3.hxx>
32 #include <com/sun/star/beans/NamedValue.hpp>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/util/XChangesBatch.hpp>
37 #include <rtl/ref.hxx>
39 #include "updatecheckconfiglistener.hxx"
40 #include "updateinfo.hxx"
42 /* Interface to acess configuration data read-only */
45 virtual ::com::sun::star::uno::Any
getValue(const sal_Char
* pName
) = 0;
48 /* This helper class provides by name access to a sequence of named values */
49 class NamedValueByNameAccess
: public IByNameAccess
51 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>& m_rValues
;
54 NamedValueByNameAccess(
55 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>& rValues
) :
56 m_rValues(rValues
) {} ;
58 virtual ~NamedValueByNameAccess();
60 virtual ::com::sun::star::uno::Any
getValue(const sal_Char
* pName
);
64 /* This class encapsulates the configuration item actually used for storing the state
65 * the update check is actually in.
67 class UpdateCheckROModel
70 UpdateCheckROModel(IByNameAccess
& aNameAccess
) : m_aNameAccess(aNameAccess
) {};
72 bool isAutoCheckEnabled() const;
73 bool isDownloadPaused() const;
74 rtl::OUString
getLocalFileName() const;
75 sal_Int64
getDownloadSize() const;
77 rtl::OUString
getUpdateEntryVersion() const;
78 void getUpdateEntry(UpdateInfo
& rInfo
) const;
82 rtl::OUString
getStringValue(const sal_Char
*) const;
84 IByNameAccess
& m_aNameAccess
;
89 /* This class implements the non published UNO service com.sun.star.setup.UpdateCheckConfig,
90 * which primary use is to be able to track changes done in the Toos -> Options page of this
91 * component, as this is not supported by the OOo configuration for extendable groups.
94 class UpdateCheckConfig
: public ::cppu::WeakImplHelper3
<
95 ::com::sun::star::container::XNameReplace
,
96 ::com::sun::star::util::XChangesBatch
,
97 ::com::sun::star::lang::XServiceInfo
>
99 UpdateCheckConfig(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>& xContainer
,
100 const ::rtl::Reference
< UpdateCheckConfigListener
>& rListener
);
102 virtual ~UpdateCheckConfig();
106 static ::com::sun::star::uno::Sequence
< rtl::OUString
> getServiceNames();
107 static rtl::OUString
getImplName();
109 static ::rtl::Reference
< UpdateCheckConfig
> get(
110 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xContext
,
111 const ::rtl::Reference
< UpdateCheckConfigListener
>& rListener
= ::rtl::Reference
< UpdateCheckConfigListener
>());
113 // Should really implement ROModel ..
114 bool isAutoCheckEnabled() const;
115 bool isAutoDownloadEnabled() const;
116 rtl::OUString
getUpdateEntryVersion() const;
118 /* Updates the timestamp of last check, but does not commit the change
119 * as either clearUpdateFound() or setUpdateFound() are expected to get
122 void updateLastChecked();
124 /* Returns the date of the last successful check in seconds since 1970 */
125 sal_Int64
getLastChecked() const;
127 /* Returns configured check interval in seconds */
128 sal_Int64
getCheckInterval() const;
130 /* Reset values of previously remembered update
132 void clearUpdateFound();
134 /* Stores the specified data of an available update
136 void storeUpdateFound(const UpdateInfo
& rInfo
, const rtl::OUString
& aCurrentBuild
);
138 // Returns the local file name of a started download
139 rtl::OUString
getLocalFileName() const;
141 // Returns the local file name of a started download
142 rtl::OUString
getDownloadDestination() const;
144 // stores the local file name of a just started download
145 void storeLocalFileName(const rtl::OUString
& rFileName
, sal_Int64 nFileSize
);
147 // Removes the local file name of a download
148 void clearLocalFileName();
150 // Stores the bool value for manually paused downloads
151 void storeDownloadPaused(bool paused
);
153 // Returns the directory that acts as the user's desktop
154 static rtl::OUString
getDesktopDirectory();
156 // Returns a directory accessible for all users
157 static rtl::OUString
getAllUsersDirectory();
159 // store and retrieve information about extensions
160 void storeExtensionVersion( const rtl::OUString
& rExtensionName
,
161 const rtl::OUString
& rVersion
);
162 bool checkExtensionVersion( const rtl::OUString
& rExtensionName
,
163 const rtl::OUString
& rVersion
);
166 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( )
167 throw (::com::sun::star::uno::RuntimeException
);
168 virtual sal_Bool SAL_CALL
hasElements( )
169 throw (::com::sun::star::uno::RuntimeException
);
172 virtual ::com::sun::star::uno::Any SAL_CALL
getByName( const ::rtl::OUString
& aName
)
173 throw (::com::sun::star::container::NoSuchElementException
,
174 ::com::sun::star::lang::WrappedTargetException
,
175 ::com::sun::star::uno::RuntimeException
);
176 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getElementNames( )
177 throw (::com::sun::star::uno::RuntimeException
);
178 virtual ::sal_Bool SAL_CALL
hasByName( const ::rtl::OUString
& aName
)
179 throw (::com::sun::star::uno::RuntimeException
);
182 virtual void SAL_CALL
replaceByName( const ::rtl::OUString
& aName
, const ::com::sun::star::uno::Any
& aElement
)
183 throw (::com::sun::star::lang::IllegalArgumentException
,
184 ::com::sun::star::container::NoSuchElementException
,
185 ::com::sun::star::lang::WrappedTargetException
,
186 ::com::sun::star::uno::RuntimeException
);
189 virtual void SAL_CALL
commitChanges( )
190 throw (::com::sun::star::lang::WrappedTargetException
,
191 ::com::sun::star::uno::RuntimeException
);
192 virtual ::sal_Bool SAL_CALL
hasPendingChanges( )
193 throw (::com::sun::star::uno::RuntimeException
);
194 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::util::ElementChange
> SAL_CALL
getPendingChanges( )
195 throw (::com::sun::star::uno::RuntimeException
);
198 virtual rtl::OUString SAL_CALL
getImplementationName()
199 throw (::com::sun::star::uno::RuntimeException
);
200 virtual sal_Bool SAL_CALL
supportsService(rtl::OUString
const & serviceName
)
201 throw (::com::sun::star::uno::RuntimeException
);
202 virtual ::com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames()
203 throw (::com::sun::star::uno::RuntimeException
);
207 static rtl::OUString
getSubVersion( const rtl::OUString
& rVersion
, sal_Int32
*nIndex
);
208 static bool isVersionGreater( const rtl::OUString
& rVersion1
, const rtl::OUString
& rVersion2
);
210 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> m_xContainer
;
211 const ::rtl::Reference
< UpdateCheckConfigListener
> m_rListener
;
214 //------------------------------------------------------------------------------
217 template <typename T
>
218 T
getValue( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>& rNamedValues
, const sal_Char
* pszName
)
219 throw (::com::sun::star::uno::RuntimeException
)
221 for( sal_Int32 n
=0; n
< rNamedValues
.getLength(); n
++ )
223 // Unfortunatly gcc-3.3 does not like Any.get<T>();
224 if( rNamedValues
[n
].Name
.equalsAscii( pszName
) )
227 if( ! (rNamedValues
[n
].Value
>>= value
) )
228 throw ::com::sun::star::uno::RuntimeException(
230 cppu_Any_extraction_failure_msg(
231 &rNamedValues
[n
].Value
,
232 ::cppu::getTypeFavourUnsigned(&value
).getTypeLibType() ),
234 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>() );