LCOV - code coverage report
Current view: top level - cui/source/options - optupdt.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 177 0.0 %
Date: 2014-11-03 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <sfx2/filedlghelper.hxx>
      23             : #include <svl/zforlist.hxx>
      24             : #include "optupdt.hxx"
      25             : #include <dialmgr.hxx>
      26             : #include <cuires.hrc>
      27             : #include <comphelper/processfactory.hxx>
      28             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      31             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.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 <osl/file.hxx>
      39             : #include <osl/security.hxx>
      40             : 
      41             : using namespace ::com::sun::star;
      42             : 
      43             : // class SvxOnlineUpdateTabPage --------------------------------------------------
      44             : 
      45           0 : SvxOnlineUpdateTabPage::SvxOnlineUpdateTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
      46           0 :     : SfxTabPage(pParent, "OptOnlineUpdatePage", "cui/ui/optonlineupdatepage.ui", &rSet)
      47             : {
      48           0 :     m_aNeverChecked = get<FixedText>("neverchecked")->GetText();
      49           0 :     get(m_pAutoCheckCheckBox, "autocheck");
      50           0 :     get(m_pEveryDayButton, "everyday");
      51           0 :     get(m_pEveryWeekButton, "everyweek");
      52           0 :     get(m_pEveryMonthButton, "everymonth");
      53           0 :     get(m_pCheckNowButton, "checknow");
      54           0 :     get(m_pAutoDownloadCheckBox, "autodownload");
      55           0 :     get(m_pDestPathLabel, "destpathlabel");
      56           0 :     get(m_pDestPath, "destpath");
      57           0 :     get(m_pChangePathButton, "changepath");
      58           0 :     get(m_pLastChecked, "lastchecked");
      59             : 
      60           0 :     m_pAutoCheckCheckBox->SetClickHdl( LINK( this, SvxOnlineUpdateTabPage, AutoCheckHdl_Impl ) );
      61           0 :     m_pCheckNowButton->SetClickHdl( LINK( this, SvxOnlineUpdateTabPage, CheckNowHdl_Impl ) );
      62           0 :     m_pChangePathButton->SetClickHdl( LINK( this, SvxOnlineUpdateTabPage, FileDialogHdl_Impl ) );
      63             : 
      64           0 :     uno::Reference < uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
      65             : 
      66           0 :     m_xUpdateAccess = setup::UpdateCheckConfig::create( xContext );
      67             : 
      68           0 :     bool bDownloadSupported = false;
      69           0 :     m_xUpdateAccess->getByName( "DownloadSupported" ) >>= bDownloadSupported;
      70             : 
      71           0 :     WinBits nStyle = m_pDestPath->GetStyle();
      72           0 :     nStyle |= WB_PATHELLIPSIS;
      73           0 :     m_pDestPath->SetStyle(nStyle);
      74             : 
      75           0 :     m_pAutoDownloadCheckBox->Show(bDownloadSupported);
      76           0 :     m_pDestPathLabel->Show(bDownloadSupported);
      77           0 :     m_pDestPath->Show(bDownloadSupported);
      78           0 :     m_pChangePathButton->Show(bDownloadSupported);
      79             : 
      80           0 :     m_aLastCheckedTemplate = m_pLastChecked->GetText();
      81             : 
      82           0 :     UpdateLastCheckedText();
      83           0 : }
      84             : 
      85             : 
      86             : 
      87           0 : SvxOnlineUpdateTabPage::~SvxOnlineUpdateTabPage()
      88             : {
      89           0 : }
      90             : 
      91             : 
      92           0 : void SvxOnlineUpdateTabPage::UpdateLastCheckedText()
      93             : {
      94           0 :     OUString aDateStr;
      95           0 :     OUString aTimeStr;
      96           0 :     OUString aText;
      97           0 :     sal_Int64 lastChecked = 0;
      98             : 
      99           0 :     m_xUpdateAccess->getByName("LastCheck") >>= lastChecked;
     100             : 
     101           0 :     if( lastChecked == 0 ) // never checked
     102             :     {
     103           0 :         aText = m_aNeverChecked;
     104             :     }
     105             :     else
     106             :     {
     107             :         TimeValue   lastCheckedTV;
     108             :         oslDateTime lastCheckedDT;
     109             : 
     110           0 :         Date  aDate( Date::EMPTY );
     111           0 :         tools::Time  aTime( tools::Time::EMPTY );
     112             : 
     113           0 :         lastCheckedTV.Seconds = (sal_uInt32) lastChecked;
     114           0 :         osl_getLocalTimeFromSystemTime( &lastCheckedTV, &lastCheckedTV );
     115             : 
     116           0 :         if ( osl_getDateTimeFromTimeValue(  &lastCheckedTV, &lastCheckedDT ) )
     117             :         {
     118           0 :             aDate = Date( lastCheckedDT.Day, lastCheckedDT.Month, lastCheckedDT.Year );
     119           0 :             aTime = ::tools::Time( lastCheckedDT.Hours, lastCheckedDT.Minutes );
     120             :         }
     121             : 
     122           0 :         LanguageType eUILang = Application::GetSettings().GetUILanguageTag().getLanguageType();
     123           0 :         SvNumberFormatter *pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessComponentContext(), eUILang );
     124           0 :         Color*      pColor = NULL;
     125           0 :         Date*       pNullDate = pNumberFormatter->GetNullDate();
     126           0 :         sal_uInt32  nFormat = pNumberFormatter->GetStandardFormat( NUMBERFORMAT_DATE, eUILang );
     127             : 
     128           0 :         pNumberFormatter->GetOutputString( aDate - *pNullDate, nFormat, aDateStr, &pColor );
     129             : 
     130           0 :         nFormat = pNumberFormatter->GetStandardFormat( NUMBERFORMAT_TIME, eUILang );
     131           0 :         pNumberFormatter->GetOutputString( aTime.GetTimeInDays(), nFormat, aTimeStr, &pColor );
     132             : 
     133           0 :         delete pColor;
     134           0 :         delete pNumberFormatter;
     135             : 
     136           0 :         aText = m_aLastCheckedTemplate;
     137           0 :         sal_Int32 nIndex = aText.indexOf( "%DATE%" );
     138           0 :         if ( nIndex != -1 )
     139           0 :             aText = aText.replaceAt( nIndex, 6, aDateStr );
     140             : 
     141           0 :         nIndex = aText.indexOf( "%TIME%" );
     142           0 :         if ( nIndex != -1 )
     143           0 :             aText = aText.replaceAt( nIndex, 6, aTimeStr );
     144             :     }
     145             : 
     146           0 :     m_pLastChecked->SetText( aText );
     147           0 : }
     148             : 
     149             : 
     150             : 
     151             : SfxTabPage*
     152           0 : SvxOnlineUpdateTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
     153             : {
     154           0 :     return new SvxOnlineUpdateTabPage( pParent, *rAttrSet );
     155             : }
     156             : 
     157             : 
     158             : 
     159             : 
     160           0 : bool SvxOnlineUpdateTabPage::FillItemSet( SfxItemSet* )
     161             : {
     162           0 :     bool bModified = false;
     163             : 
     164             :     bool bValue;
     165             :     sal_Int64 nValue;
     166             : 
     167           0 :     if( m_pAutoCheckCheckBox->IsValueChangedFromSaved() )
     168             :     {
     169           0 :         bValue = m_pAutoCheckCheckBox->IsChecked();
     170           0 :         m_xUpdateAccess->replaceByName( "AutoCheckEnabled", uno::makeAny( bValue ) );
     171           0 :         bModified = true;
     172             :     }
     173             : 
     174           0 :     nValue = 0;
     175           0 :     if( m_pEveryDayButton->IsChecked() )
     176             :     {
     177           0 :         if( !m_pEveryDayButton->GetSavedValue() )
     178           0 :             nValue = 86400;
     179             :     }
     180           0 :     else if( m_pEveryWeekButton->IsChecked() )
     181             :     {
     182           0 :         if( !m_pEveryWeekButton->GetSavedValue() )
     183           0 :             nValue = 604800;
     184             :     }
     185           0 :     else if( m_pEveryMonthButton->IsChecked() )
     186             :     {
     187           0 :         if( !m_pEveryMonthButton->GetSavedValue() )
     188           0 :             nValue = 2592000;
     189             :     }
     190             : 
     191           0 :     if( nValue > 0 )
     192             :     {
     193           0 :         m_xUpdateAccess->replaceByName( "CheckInterval", uno::makeAny( nValue ) );
     194           0 :         bModified = true;
     195             :     }
     196             : 
     197           0 :     if( m_pAutoDownloadCheckBox->IsValueChangedFromSaved() )
     198             :     {
     199           0 :         bValue = m_pAutoDownloadCheckBox->IsChecked();
     200           0 :         m_xUpdateAccess->replaceByName( "AutoDownloadEnabled", uno::makeAny( bValue ) );
     201           0 :         bModified = true;
     202             :     }
     203             : 
     204           0 :     OUString sValue, aURL;
     205           0 :     m_xUpdateAccess->getByName( "DownloadDestination" ) >>= sValue;
     206             : 
     207           0 :     if( ( osl::FileBase::E_None == osl::FileBase::getFileURLFromSystemPath(m_pDestPath->GetText(), aURL) ) &&
     208           0 :         ( ! aURL.equals( sValue ) ) )
     209             :     {
     210           0 :         m_xUpdateAccess->replaceByName( "DownloadDestination", uno::makeAny( aURL ) );
     211           0 :         bModified = true;
     212             :     }
     213             : 
     214           0 :     uno::Reference< util::XChangesBatch > xChangesBatch(m_xUpdateAccess, uno::UNO_QUERY);
     215           0 :     if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
     216           0 :         xChangesBatch->commitChanges();
     217             : 
     218           0 :     return bModified;
     219             : }
     220             : 
     221             : 
     222             : 
     223           0 : void SvxOnlineUpdateTabPage::Reset( const SfxItemSet* )
     224             : {
     225           0 :     bool bValue = false;
     226           0 :     m_xUpdateAccess->getByName( "AutoCheckEnabled" ) >>= bValue;
     227             : 
     228           0 :     m_pAutoCheckCheckBox->Check(bValue);
     229           0 :     m_pEveryDayButton->Enable(bValue);
     230           0 :     m_pEveryWeekButton->Enable(bValue);
     231           0 :     m_pEveryMonthButton->Enable(bValue);
     232             : 
     233           0 :     sal_Int64 nValue = 0;
     234           0 :     m_xUpdateAccess->getByName( "CheckInterval" ) >>= nValue;
     235             : 
     236           0 :     if( nValue == 86400 )
     237           0 :         m_pEveryDayButton->Check();
     238           0 :     else if( nValue == 604800 )
     239           0 :         m_pEveryWeekButton->Check();
     240             :     else
     241           0 :         m_pEveryMonthButton->Check();
     242             : 
     243           0 :     m_pAutoCheckCheckBox->SaveValue();
     244           0 :     m_pEveryDayButton->SaveValue();
     245           0 :     m_pEveryWeekButton->SaveValue();
     246           0 :     m_pEveryMonthButton->SaveValue();
     247             : 
     248           0 :     m_xUpdateAccess->getByName( "AutoDownloadEnabled" ) >>= bValue;
     249           0 :     m_pAutoDownloadCheckBox->Check(bValue);
     250           0 :     m_pDestPathLabel->Enable(true);
     251           0 :     m_pDestPath->Enable(true);
     252           0 :     m_pChangePathButton->Enable(true);
     253             : 
     254           0 :     OUString sValue, aPath;
     255           0 :     m_xUpdateAccess->getByName( "DownloadDestination" ) >>= sValue;
     256             : 
     257           0 :     if( osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(sValue, aPath) )
     258           0 :         m_pDestPath->SetText(aPath);
     259             : 
     260           0 :     m_pAutoDownloadCheckBox->SaveValue();
     261           0 : }
     262             : 
     263             : 
     264             : 
     265           0 : void SvxOnlineUpdateTabPage::FillUserData()
     266             : {
     267           0 : }
     268             : 
     269             : 
     270             : 
     271           0 : IMPL_LINK( SvxOnlineUpdateTabPage, AutoCheckHdl_Impl, CheckBox *, pBox )
     272             : {
     273           0 :     bool bEnabled = pBox->IsChecked();
     274             : 
     275           0 :     m_pEveryDayButton->Enable(bEnabled);
     276           0 :     m_pEveryWeekButton->Enable(bEnabled);
     277           0 :     m_pEveryMonthButton->Enable(bEnabled);
     278             : 
     279           0 :     return 0;
     280             : }
     281             : 
     282             : 
     283             : 
     284           0 : IMPL_LINK_NOARG(SvxOnlineUpdateTabPage, FileDialogHdl_Impl)
     285             : {
     286           0 :     uno::Reference < uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     287           0 :     uno::Reference < ui::dialogs::XFolderPicker2 >  xFolderPicker = ui::dialogs::FolderPicker::create(xContext);
     288             : 
     289           0 :     OUString aURL;
     290           0 :     if( osl::FileBase::E_None != osl::FileBase::getFileURLFromSystemPath(m_pDestPath->GetText(), aURL) )
     291           0 :         osl::Security().getHomeDir(aURL);
     292             : 
     293           0 :     xFolderPicker->setDisplayDirectory( aURL );
     294           0 :     sal_Int16 nRet = xFolderPicker->execute();
     295             : 
     296           0 :     if ( ui::dialogs::ExecutableDialogResults::OK == nRet )
     297             :     {
     298           0 :         OUString aFolder;
     299           0 :         if( osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(xFolderPicker->getDirectory(), aFolder))
     300           0 :             m_pDestPath->SetText( aFolder );
     301             :     }
     302             : 
     303           0 :     return 0;
     304             : }
     305             : 
     306             : 
     307             : 
     308           0 : IMPL_LINK_NOARG(SvxOnlineUpdateTabPage, CheckNowHdl_Impl)
     309             : {
     310           0 :     uno::Reference < uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     311             : 
     312             :     try
     313             :     {
     314             :         uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
     315           0 :             com::sun::star::configuration::theDefaultProvider::get( xContext ) );
     316             : 
     317           0 :         beans::NamedValue aProperty;
     318           0 :         aProperty.Name  = "nodepath";
     319           0 :         aProperty.Value = uno::makeAny( OUString("org.openoffice.Office.Addons/AddonUI/OfficeHelp/UpdateCheckJob") );
     320             : 
     321           0 :         uno::Sequence< uno::Any > aArgumentList( 1 );
     322           0 :         aArgumentList[0] = uno::makeAny( aProperty );
     323             : 
     324             :         uno::Reference< container::XNameAccess > xNameAccess(
     325           0 :             xConfigProvider->createInstanceWithArguments(
     326           0 :                 "com.sun.star.configuration.ConfigurationAccess", aArgumentList ),
     327           0 :             uno::UNO_QUERY_THROW );
     328             : 
     329           0 :         util::URL aURL;
     330           0 :         xNameAccess->getByName("URL") >>= aURL.Complete;
     331             : 
     332           0 :         uno::Reference < util::XURLTransformer > xTransformer( util::URLTransformer::create( xContext ) );
     333             : 
     334           0 :         xTransformer->parseStrict(aURL);
     335             : 
     336           0 :         uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create( xContext );
     337             : 
     338             :         uno::Reference< frame::XDispatchProvider > xDispatchProvider(
     339           0 :             xDesktop->getCurrentFrame(), uno::UNO_QUERY );
     340             : 
     341           0 :         uno::Reference< frame::XDispatch > xDispatch;
     342           0 :         if( xDispatchProvider.is() )
     343           0 :             xDispatch = xDispatchProvider->queryDispatch(aURL, OUString(), 0);
     344             : 
     345           0 :         if( xDispatch.is() )
     346           0 :             xDispatch->dispatch(aURL, uno::Sequence< beans::PropertyValue > ());
     347             : 
     348           0 :         UpdateLastCheckedText();
     349             :     }
     350           0 :     catch( const uno::Exception& e )
     351             :     {
     352             :          OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
     353             :             OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
     354             :     }
     355             : 
     356           0 :     return 0;
     357           0 : }
     358             : 
     359             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10