1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include <cppuhelper/implbase3.hxx>
25 #include <com/sun/star/beans/NamedValue.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <com/sun/star/util/XChangesBatch.hpp>
30 #include <rtl/ref.hxx>
31
32 #include "updatecheckconfiglistener.hxx"
33 #include "updateinfo.hxx"
34
35 /* Interface to access configuration data read-only */
36 struct IByNameAccess
37 {
38 virtual ::com::sun::star::uno::Any getValue(const sal_Char * pName) = 0;
39 };
40
41 /* This helper class provides by name access to a sequence of named values */
42 class NamedValueByNameAccess : public IByNameAccess
43 {
44 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& m_rValues;
45
46 public:
NamedValueByNameAccess(const::com::sun::star::uno::Sequence<::com::sun::star::beans::NamedValue> & rValues)47 NamedValueByNameAccess(
48 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rValues) :
49 m_rValues(rValues) {} ;
50
51 virtual ~NamedValueByNameAccess();
52
53 virtual ::com::sun::star::uno::Any getValue(const sal_Char * pName);
54 };
55
56
57 /* This class encapsulates the configuration item actually used for storing the state
58 * the update check is actually in.
59 */
60 class UpdateCheckROModel
61 {
62 public:
UpdateCheckROModel(IByNameAccess & aNameAccess)63 UpdateCheckROModel(IByNameAccess& aNameAccess) : m_aNameAccess(aNameAccess) {};
64
65 bool isAutoCheckEnabled() const;
66 bool isDownloadPaused() const;
67 rtl::OUString getLocalFileName() const;
68 sal_Int64 getDownloadSize() const;
69
70 rtl::OUString getUpdateEntryVersion() const;
71 void getUpdateEntry(UpdateInfo& rInfo) const;
72
73 private:
74
75 rtl::OUString getStringValue(const sal_Char *) const;
76
77 IByNameAccess& m_aNameAccess;
78 };
79
80
81
82 /* This class implements the non published UNO service com.sun.star.setup.UpdateCheckConfig,
83 * which primary use is to be able to track changes done in the Tools -> Options page of this
84 * component, as this is not supported by the AOO configuration for extendable groups.
85 */
86
87 class UpdateCheckConfig : public ::cppu::WeakImplHelper3<
88 ::com::sun::star::container::XNameReplace,
89 ::com::sun::star::util::XChangesBatch,
90 ::com::sun::star::lang::XServiceInfo >
91 {
92 UpdateCheckConfig( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xContainer,
93 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xAvailableUpdates,
94 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xIgnoredUpdates,
95 const ::rtl::Reference< UpdateCheckConfigListener >& rListener );
96
97 virtual ~UpdateCheckConfig();
98
99 public:
100
101 static ::com::sun::star::uno::Sequence< rtl::OUString > getServiceNames();
102 static rtl::OUString getImplName();
103
104 static ::rtl::Reference< UpdateCheckConfig > get(
105 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
106 const ::rtl::Reference< UpdateCheckConfigListener >& rListener = ::rtl::Reference< UpdateCheckConfigListener >());
107
108 // Should really implement ROModel ..
109 bool isAutoCheckEnabled() const;
110 bool isAutoDownloadEnabled() const;
111 rtl::OUString getUpdateEntryVersion() const;
112
113 /* Updates the timestamp of last check, but does not commit the change
114 * as either clearUpdateFound() or setUpdateFound() are expected to get
115 * called next.
116 */
117 void updateLastChecked();
118
119 /* Returns the date of the last successful check in seconds since 1970 */
120 sal_Int64 getLastChecked() const;
121
122 /* Returns configured check interval in seconds */
123 sal_Int64 getCheckInterval() const;
124
125 /* Reset values of previously remembered update
126 */
127 void clearUpdateFound();
128
129 /* Stores the specified data of an available update
130 */
131 void storeUpdateFound(const UpdateInfo& rInfo, const rtl::OUString& aCurrentBuild);
132
133 // Returns the local file name of a started download
134 rtl::OUString getLocalFileName() const;
135
136 // Returns the local file name of a started download
137 rtl::OUString getDownloadDestination() const;
138
139 // stores the local file name of a just started download
140 void storeLocalFileName(const rtl::OUString& rFileName, sal_Int64 nFileSize);
141
142 // Removes the local file name of a download
143 void clearLocalFileName();
144
145 // Stores the bool value for manually paused downloads
146 void storeDownloadPaused(bool paused);
147
148 // Returns the directory that acts as the user's desktop
149 static rtl::OUString getDesktopDirectory();
150
151 // Returns a directory accessible for all users
152 static rtl::OUString getAllUsersDirectory();
153
154 // store and retrieve information about extensions
155 bool storeExtensionVersion( const rtl::OUString& rExtensionName,
156 const rtl::OUString& rVersion );
157 bool checkExtensionVersion( const rtl::OUString& rExtensionName,
158 const rtl::OUString& rVersion );
159
160 // XElementAccess
161 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( );
162 virtual sal_Bool SAL_CALL hasElements( );
163
164 // XNameAccess
165 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName );
166 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( );
167 virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName );
168
169 // XNameReplace
170 virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement );
171
172 // XChangesBatch
173 virtual void SAL_CALL commitChanges( );
174 virtual ::sal_Bool SAL_CALL hasPendingChanges( );
175 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::ElementChange > SAL_CALL getPendingChanges( );
176
177 // XServiceInfo
178 virtual rtl::OUString SAL_CALL getImplementationName();
179 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName);
180 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames();
181
182 private:
183
184 static rtl::OUString getSubVersion( const rtl::OUString& rVersion, sal_Int32 *nIndex );
185 static bool isVersionGreater( const rtl::OUString& rVersion1, const rtl::OUString& rVersion2 );
186
187 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xContainer;
188 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xAvailableUpdates;
189 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xIgnoredUpdates;
190 const ::rtl::Reference< UpdateCheckConfigListener > m_rListener;
191 };
192
193 //------------------------------------------------------------------------------
194
195
196 template <typename T>
getValue(const::com::sun::star::uno::Sequence<::com::sun::star::beans::NamedValue> & rNamedValues,const sal_Char * pszName)197 T getValue( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rNamedValues, const sal_Char * pszName )
198 {
199 for( sal_Int32 n=0; n < rNamedValues.getLength(); n++ )
200 {
201 // Unfortunately gcc-3.3 does not like Any.get<T>();
202 if( rNamedValues[n].Name.equalsAscii( pszName ) )
203 {
204 T value = T();
205 if( ! (rNamedValues[n].Value >>= value) )
206 throw ::com::sun::star::uno::RuntimeException(
207 ::rtl::OUString(
208 cppu_Any_extraction_failure_msg(
209 &rNamedValues[n].Value,
210 ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
211 SAL_NO_ACQUIRE ),
212 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
213
214 return value;
215 }
216 }
217
218 return T();
219 }
220