LibreOffice Module cui (master) 1
optupdt.cxx
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#include <vcl/svapp.hxx>
21#include <vcl/settings.hxx>
22#include <svl/numformat.hxx>
23#include <svl/zforlist.hxx>
24#include "optupdt.hxx"
26#include <com/sun/star/configuration/theDefaultProvider.hpp>
27#include <com/sun/star/lang/XMultiServiceFactory.hpp>
28#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
29#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
30#include <com/sun/star/deployment/UpdateInformationProvider.hpp>
31#include <com/sun/star/ucb/XWebDAVCommandEnvironment.hpp>
32#include <com/sun/star/frame/Desktop.hpp>
33#include <com/sun/star/frame/XDispatchProvider.hpp>
34#include <com/sun/star/util/XChangesBatch.hpp>
35#include <com/sun/star/util/URLTransformer.hpp>
36#include <com/sun/star/util/XURLTransformer.hpp>
37#include <com/sun/star/setup/UpdateCheckConfig.hpp>
38#include <com/sun/star/configuration/ReadWriteAccess.hpp>
39#include <com/sun/star/beans/PropertyAttribute.hpp>
40#include <com/sun/star/beans/NamedValue.hpp>
42#include <officecfg/Office/Common.hxx>
43#include <osl/file.hxx>
44#include <osl/security.hxx>
45#include <tools/diagnose_ex.h>
47
48using namespace ::css;
49
51 : SfxTabPage(pPage, pController, "cui/ui/optonlineupdatepage.ui", "OptOnlineUpdatePage", &rSet)
52 , m_xNeverChecked(m_xBuilder->weld_label("neverchecked"))
53 , m_xAutoCheckCheckBox(m_xBuilder->weld_check_button("autocheck"))
54 , m_xEveryDayButton(m_xBuilder->weld_radio_button("everyday"))
55 , m_xEveryWeekButton(m_xBuilder->weld_radio_button("everyweek"))
56 , m_xEveryMonthButton(m_xBuilder->weld_radio_button("everymonth"))
57 , m_xCheckNowButton(m_xBuilder->weld_button("checknow"))
58 , m_xAutoDownloadCheckBox(m_xBuilder->weld_check_button("autodownload"))
59 , m_xDestPathLabel(m_xBuilder->weld_label("destpathlabel"))
60 , m_xDestPath(m_xBuilder->weld_label("destpath"))
61 , m_xChangePathButton(m_xBuilder->weld_button("changepath"))
62 , m_xLastChecked(m_xBuilder->weld_label("lastchecked"))
63 , m_xExtrasCheckBox(m_xBuilder->weld_check_button("extrabits"))
64 , m_xUserAgentLabel(m_xBuilder->weld_label("useragent"))
65 , m_xPrivacyPolicyButton(m_xBuilder->weld_link_button("btnPrivacyPolicy"))
66{
67 m_aNeverChecked = m_xNeverChecked->get_label();
68
69 m_xAutoCheckCheckBox->connect_toggled( LINK( this, SvxOnlineUpdateTabPage, AutoCheckHdl_Impl ) );
70 m_xExtrasCheckBox->connect_toggled( LINK( this, SvxOnlineUpdateTabPage, ExtrasCheckHdl_Impl ) );
71 m_xCheckNowButton->connect_clicked( LINK( this, SvxOnlineUpdateTabPage, CheckNowHdl_Impl ) );
72 m_xChangePathButton->connect_clicked( LINK( this, SvxOnlineUpdateTabPage, FileDialogHdl_Impl ) );
74 officecfg::Office::Common::Menus::PrivacyPolicyURL::get()
75 + "?type=updatecheck&LOvers=" + utl::ConfigManager::getProductVersion()
76 + "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getBcp47());
77
78
79 uno::Reference < uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
80
81 m_xUpdateAccess = setup::UpdateCheckConfig::create( xContext );
82 m_xReadWriteAccess = css::configuration::ReadWriteAccess::create(xContext, "*");
83
84 bool bDownloadSupported = false;
85 m_xUpdateAccess->getByName( "DownloadSupported" ) >>= bDownloadSupported;
86
87 m_xAutoDownloadCheckBox->set_visible(bDownloadSupported);
88 m_xDestPathLabel->set_visible(bDownloadSupported);
89 m_xDestPath->set_visible(bDownloadSupported);
90 m_xChangePathButton->set_visible(bDownloadSupported);
91
93
96}
97
99{
100}
101
103{
104 OUString aText;
105 sal_Int64 lastChecked = 0;
106
107 m_xUpdateAccess->getByName("LastCheck") >>= lastChecked;
108
109 if( lastChecked == 0 ) // never checked
110 {
111 aText = m_aNeverChecked;
112 }
113 else
114 {
115 TimeValue lastCheckedTV;
116 oslDateTime lastCheckedDT;
117
118 Date aDate( Date::EMPTY );
120
121 lastCheckedTV.Seconds = static_cast<sal_uInt32>(lastChecked);
122 osl_getLocalTimeFromSystemTime( &lastCheckedTV, &lastCheckedTV );
123
124 if ( osl_getDateTimeFromTimeValue( &lastCheckedTV, &lastCheckedDT ) )
125 {
126 aDate = Date( lastCheckedDT.Day, lastCheckedDT.Month, lastCheckedDT.Year );
127 aTime = ::tools::Time( lastCheckedDT.Hours, lastCheckedDT.Minutes );
128 }
129
131 std::optional<SvNumberFormatter> pNumberFormatter( std::in_place, ::comphelper::getProcessComponentContext(), eUILang );
132 const Color* pColor = nullptr;
133 const Date& rNullDate = pNumberFormatter->GetNullDate();
134 sal_uInt32 nFormat = pNumberFormatter->GetStandardFormat( SvNumFormatType::DATE, eUILang );
135
136 OUString aDateStr;
137 pNumberFormatter->GetOutputString( aDate - rNullDate, nFormat, aDateStr, &pColor );
138
139 nFormat = pNumberFormatter->GetStandardFormat( SvNumFormatType::TIME, eUILang );
140 OUString aTimeStr;
141 pNumberFormatter->GetOutputString( aTime.GetTimeInDays(), nFormat, aTimeStr, &pColor );
142
143 pNumberFormatter.reset();
144
146 sal_Int32 nIndex = aText.indexOf( "%DATE%" );
147 if ( nIndex != -1 )
148 aText = aText.replaceAt( nIndex, 6, aDateStr );
149
150 nIndex = aText.indexOf( "%TIME%" );
151 if ( nIndex != -1 )
152 aText = aText.replaceAt( nIndex, 6, aTimeStr );
153 }
154
155 m_xLastChecked->set_label(aText);
156}
157
159{
160 try {
162 css::deployment::UpdateInformationProvider::create(
163 ::comphelper::getProcessComponentContext() ),
164 css::uno::UNO_QUERY_THROW );
165
166 OUString aPseudoURL = "useragent:normal";
167 if( m_xExtrasCheckBox->get_active() )
168 aPseudoURL = "useragent:extended";
170 = xDav->getUserRequestHeaders( aPseudoURL, ucb::WebDAVHTTPMethod(0) );
171
172 for (const css::beans::StringPair & aHeader : aHeaders)
173 {
174 if ( aHeader.First == "User-Agent" )
175 {
176 OUString aText = aHeader.Second;
177 aText = aText.replaceAll(";", ";\n");
178 aText = aText.replaceAll("(", "\n(");
179 m_xUserAgentLabel->set_label(aText);
180 break;
181 }
182 }
183 } catch (const uno::Exception &) {
184 TOOLS_WARN_EXCEPTION( "cui.options", "Unexpected exception fetching User Agent" );
185 }
186}
187
188std::unique_ptr<SfxTabPage> SvxOnlineUpdateTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
189{
190 return std::make_unique<SvxOnlineUpdateTabPage>( pPage, pController, *rAttrSet );
191}
192
194{
195 bool bModified = false;
196
197 bool bValue;
198 sal_Int64 nValue;
199
200 if( m_xAutoCheckCheckBox->get_state_changed_from_saved() )
201 {
202 bValue = m_xAutoCheckCheckBox->get_active();
203 m_xUpdateAccess->replaceByName( "AutoCheckEnabled", uno::Any( bValue ) );
204 bModified = true;
205 }
206
207 nValue = 0;
208 if( m_xEveryDayButton->get_active() )
209 {
210 if( !m_xEveryDayButton->get_saved_state() )
211 nValue = 86400;
212 }
213 else if( m_xEveryWeekButton->get_active() )
214 {
215 if( !m_xEveryWeekButton->get_saved_state() )
216 nValue = 604800;
217 }
218 else if( m_xEveryMonthButton->get_active() )
219 {
220 if( !m_xEveryMonthButton->get_saved_state() )
221 nValue = 2592000;
222 }
223
224 if( nValue > 0 )
225 {
226 m_xUpdateAccess->replaceByName( "CheckInterval", uno::Any( nValue ) );
227 bModified = true;
228 }
229
230 if( m_xAutoDownloadCheckBox->get_state_changed_from_saved() )
231 {
232 bValue = m_xAutoDownloadCheckBox->get_active();
233 m_xUpdateAccess->replaceByName( "AutoDownloadEnabled", uno::Any( bValue ) );
234 bModified = true;
235 }
236
237 OUString sValue, aURL;
238 m_xUpdateAccess->getByName( "DownloadDestination" ) >>= sValue;
239
240 if( ( osl::FileBase::E_None == osl::FileBase::getFileURLFromSystemPath(m_xDestPath->get_label(), aURL) ) &&
241 ( aURL != sValue ) )
242 {
243 m_xUpdateAccess->replaceByName( "DownloadDestination", uno::Any( aURL ) );
244 bModified = true;
245 }
246
247 if( m_xExtrasCheckBox->get_state_changed_from_saved() )
248 {
249 bValue = m_xExtrasCheckBox->get_active();
250 m_xUpdateAccess->replaceByName( "ExtendedUserAgent", uno::Any( bValue ) );
251 bModified = true;
252 }
253
254 uno::Reference< util::XChangesBatch > xChangesBatch(m_xUpdateAccess, uno::UNO_QUERY);
255 if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
256 xChangesBatch->commitChanges();
257
258 return bModified;
259}
260
262{
263 bool bValue = false;
264 m_xUpdateAccess->getByName( "AutoCheckEnabled" ) >>= bValue;
265 beans::Property aProperty = m_xReadWriteAccess->getPropertyByHierarchicalName("/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job['UpdateCheck']/Arguments/AutoCheckEnabled");
266 bool bReadOnly = (aProperty.Attributes & beans::PropertyAttribute::READONLY) != 0;
267
268 m_xAutoCheckCheckBox->set_active(bValue);
269 m_xAutoCheckCheckBox->set_sensitive(!bReadOnly);
270
271 sal_Int64 nValue = 0;
272 m_xUpdateAccess->getByName( "CheckInterval" ) >>= nValue;
273 aProperty = m_xReadWriteAccess->getPropertyByHierarchicalName("/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job['UpdateCheck']/Arguments/CheckInterval");
274 bool bReadOnly2 = (aProperty.Attributes & beans::PropertyAttribute::READONLY) != 0;
275 m_xEveryDayButton->set_sensitive(bValue && !(bReadOnly || bReadOnly2));
276 m_xEveryWeekButton->set_sensitive(bValue && !(bReadOnly || bReadOnly2));
277 m_xEveryMonthButton->set_sensitive(bValue && !(bReadOnly || bReadOnly2));
278
279 if( nValue == 86400 )
280 m_xEveryDayButton->set_active(true);
281 else if( nValue == 604800 )
282 m_xEveryWeekButton->set_active(true);
283 else
284 m_xEveryMonthButton->set_active(true);
285
286 m_xAutoCheckCheckBox->save_state();
287 m_xEveryDayButton->save_state();
288 m_xEveryWeekButton->save_state();
289 m_xEveryMonthButton->save_state();
290
291 m_xUpdateAccess->getByName( "AutoDownloadEnabled" ) >>= bValue;
292 aProperty = m_xReadWriteAccess->getPropertyByHierarchicalName("/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job['UpdateCheck']/Arguments/AutoDownloadEnabled");
293 bReadOnly = (aProperty.Attributes & beans::PropertyAttribute::READONLY) != 0;
294 m_xAutoDownloadCheckBox->set_active(bValue);
295 m_xAutoDownloadCheckBox->set_sensitive(!bReadOnly);
296 m_xDestPathLabel->set_sensitive(true);
297 m_xDestPath->set_sensitive(true);
298
299 OUString sValue, aPath;
300 m_xUpdateAccess->getByName( "DownloadDestination" ) >>= sValue;
301 aProperty = m_xReadWriteAccess->getPropertyByHierarchicalName("/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job['UpdateCheck']/Arguments/DownloadDestination");
302 bReadOnly = (aProperty.Attributes & beans::PropertyAttribute::READONLY) != 0;
303 m_xChangePathButton->set_sensitive(!bReadOnly);
304
305 if( osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(sValue, aPath) )
306 m_xDestPath->set_label(aPath);
307
308 m_xUpdateAccess->getByName( "ExtendedUserAgent" ) >>= bValue;
309 aProperty = m_xReadWriteAccess->getPropertyByHierarchicalName("/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job['UpdateCheck']/Arguments/ExtendedUserAgent");
310 bReadOnly = (aProperty.Attributes & beans::PropertyAttribute::READONLY) != 0;
311 m_xExtrasCheckBox->set_active(bValue);
312 m_xExtrasCheckBox->set_sensitive(!bReadOnly);
313 m_xExtrasCheckBox->save_state();
315
316 m_xAutoDownloadCheckBox->save_state();
317}
318
320{
321}
322
323IMPL_LINK(SvxOnlineUpdateTabPage, AutoCheckHdl_Impl, weld::Toggleable&, rBox, void)
324{
325 bool bEnabled = rBox.get_active();
326 beans::Property aProperty = m_xReadWriteAccess->getPropertyByHierarchicalName("/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job['UpdateCheck']/Arguments/CheckInterval");
327 bool bReadOnly = (aProperty.Attributes & beans::PropertyAttribute::READONLY) != 0;
328 m_xEveryDayButton->set_sensitive(bEnabled && !bReadOnly);
329 m_xEveryWeekButton->set_sensitive(bEnabled && !bReadOnly);
330 m_xEveryMonthButton->set_sensitive(bEnabled && !bReadOnly);
331}
332
334{
335 UpdateUserAgent();
336}
337
339{
340 uno::Reference < uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
342
343 OUString aURL;
344 if( osl::FileBase::E_None != osl::FileBase::getFileURLFromSystemPath(m_xDestPath->get_label(), aURL) )
345 osl::Security().getHomeDir(aURL);
346
347 xFolderPicker->setDisplayDirectory( aURL );
348 sal_Int16 nRet = xFolderPicker->execute();
349
350 if ( ui::dialogs::ExecutableDialogResults::OK == nRet )
351 {
352 OUString aFolder;
353 if( osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(xFolderPicker->getDirectory(), aFolder))
354 m_xDestPath->set_label(aFolder);
355 }
356}
357
359{
360 uno::Reference < uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
361
362 try
363 {
365 css::configuration::theDefaultProvider::get( xContext ) );
366
367 beans::NamedValue aProperty;
368 aProperty.Name = "nodepath";
369 aProperty.Value <<= OUString("org.openoffice.Office.Addons/AddonUI/OfficeHelp/UpdateCheckJob");
370
371 uno::Sequence< uno::Any > aArgumentList{ uno::Any(aProperty) };
372
374 xConfigProvider->createInstanceWithArguments(
375 "com.sun.star.configuration.ConfigurationAccess", aArgumentList ),
376 uno::UNO_QUERY_THROW );
377
378 util::URL aURL;
379 xNameAccess->getByName("URL") >>= aURL.Complete;
380
381 uno::Reference < util::XURLTransformer > xTransformer( util::URLTransformer::create( xContext ) );
382
383 xTransformer->parseStrict(aURL);
384
385 uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create( xContext );
386
388 xDesktop->getCurrentFrame(), uno::UNO_QUERY );
389
391 if( xDispatchProvider.is() )
392 xDispatch = xDispatchProvider->queryDispatch(aURL, OUString(), 0);
393
394 if( xDispatch.is() )
396
397 UpdateLastCheckedText();
398 }
399 catch( const uno::Exception& )
400 {
401 TOOLS_WARN_EXCEPTION("cui.options", "Caught exception, thread terminated");
402 }
403}
404
405/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LanguageTag & GetUILanguageTag() const
static const AllSettings & GetSettings()
LanguageType getLanguageType(bool bResolveSystem=true) const
std::unique_ptr< weld::CheckButton > m_xAutoCheckCheckBox
Definition: optupdt.hxx:38
std::unique_ptr< weld::Label > m_xUserAgentLabel
Definition: optupdt.hxx:49
SvxOnlineUpdateTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optupdt.cxx:50
virtual void Reset(const SfxItemSet *rSet) override
Definition: optupdt.cxx:261
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: optupdt.cxx:188
OUString m_aNeverChecked
Definition: optupdt.hxx:31
std::unique_ptr< weld::LinkButton > m_xPrivacyPolicyButton
Definition: optupdt.hxx:50
virtual ~SvxOnlineUpdateTabPage() override
Definition: optupdt.cxx:98
OUString m_aLastCheckedTemplate
Definition: optupdt.hxx:32
std::unique_ptr< weld::CheckButton > m_xAutoDownloadCheckBox
Definition: optupdt.hxx:43
std::unique_ptr< weld::CheckButton > m_xExtrasCheckBox
Definition: optupdt.hxx:48
std::unique_ptr< weld::Label > m_xNeverChecked
Definition: optupdt.hxx:37
std::unique_ptr< weld::Button > m_xCheckNowButton
Definition: optupdt.hxx:42
void UpdateLastCheckedText()
Definition: optupdt.cxx:102
virtual void FillUserData() override
Definition: optupdt.cxx:319
css::uno::Reference< css::container::XNameReplace > m_xUpdateAccess
Definition: optupdt.hxx:34
std::unique_ptr< weld::Label > m_xDestPath
Definition: optupdt.hxx:45
std::unique_ptr< weld::Button > m_xChangePathButton
Definition: optupdt.hxx:46
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optupdt.cxx:193
std::unique_ptr< weld::RadioButton > m_xEveryMonthButton
Definition: optupdt.hxx:41
std::unique_ptr< weld::RadioButton > m_xEveryDayButton
Definition: optupdt.hxx:39
css::uno::Reference< css::configuration::XReadWriteAccess > m_xReadWriteAccess
Definition: optupdt.hxx:35
std::unique_ptr< weld::RadioButton > m_xEveryWeekButton
Definition: optupdt.hxx:40
std::unique_ptr< weld::Label > m_xLastChecked
Definition: optupdt.hxx:47
std::unique_ptr< weld::Label > m_xDestPathLabel
Definition: optupdt.hxx:44
double GetTimeInDays() const
static OUString getProductVersion()
static OUString getUILocale()
#define TOOLS_WARN_EXCEPTION(area, stream)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Reference< XDispatch > xDispatch
URL aURL
sal_Int16 nValue
bool bReadOnly
sal_Int32 nIndex
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
IMPL_LINK_NOARG(SvxOnlineUpdateTabPage, ExtrasCheckHdl_Impl, weld::Toggleable &, void)
Definition: optupdt.cxx:333
IMPL_LINK(SvxOnlineUpdateTabPage, AutoCheckHdl_Impl, weld::Toggleable &, rBox, void)
Definition: optupdt.cxx:323
static SfxItemSet & rSet