LCOV - code coverage report
Current view: top level - libreoffice/cui/source/options - optupdt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 192 0.5 %
Date: 2012-12-27 Functions: 2 17 11.8 %
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 <sfx2/filedlghelper.hxx>
      22             : #include <svl/zforlist.hxx>
      23             : #include "optupdt.hxx"
      24             : #include "optupdt.hrc"
      25             : #include <dialmgr.hxx>
      26             : #include <cuires.hrc>
      27             : #include <comphelper/componentcontext.hxx>
      28             : #include <comphelper/processfactory.hxx>
      29             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      30             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      31             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      32             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      33             : #include <com/sun/star/frame/Desktop.hpp>
      34             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      35             : #include <com/sun/star/util/XChangesBatch.hpp>
      36             : #include <com/sun/star/util/URLTransformer.hpp>
      37             : #include <com/sun/star/util/XURLTransformer.hpp>
      38             : #include <osl/file.hxx>
      39             : #include <osl/security.hxx>
      40             : 
      41             : namespace beans = ::com::sun::star::beans;
      42             : namespace container = ::com::sun::star::container;
      43             : namespace dialogs = ::com::sun::star::ui::dialogs;
      44             : namespace frame = ::com::sun::star::frame;
      45             : namespace lang = ::com::sun::star::lang;
      46             : namespace uno = ::com::sun::star::uno;
      47             : namespace util = ::com::sun::star::util;
      48             : 
      49             : // class SvxOnlineUpdateTabPage --------------------------------------------------
      50             : 
      51           0 : SvxOnlineUpdateTabPage::SvxOnlineUpdateTabPage( Window* pParent, const SfxItemSet& rSet ) :
      52             : 
      53           0 :     SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_ONLINEUPDATE ), rSet ),
      54           0 :         m_aOptionsLine( this, CUI_RES( FL_OPTIONS ) ),
      55           0 :         m_aAutoCheckCheckBox( this, CUI_RES( CB_AUTOCHECK ) ),
      56           0 :         m_aEveryDayButton( this, CUI_RES( RB_EVERYDAY ) ),
      57           0 :         m_aEveryWeekButton( this, CUI_RES( RB_EVERYWEEK ) ),
      58           0 :         m_aEveryMonthButton( this, CUI_RES( RB_EVERYMONTH ) ),
      59           0 :         m_aCheckNowButton( this, CUI_RES( PB_CHECKNOW ) ),
      60           0 :         m_aAutoDownloadCheckBox( this, CUI_RES( CB_AUTODOWNLOAD ) ),
      61           0 :         m_aDestPathLabel( this, CUI_RES( FT_DESTPATHLABEL ) ),
      62           0 :         m_aDestPath( this, CUI_RES( FT_DESTPATH ) ),
      63           0 :         m_aChangePathButton( this, CUI_RES( PB_CHANGEPATH ) ),
      64           0 :         m_aLastChecked( this, CUI_RES( FT_LASTCHECKED ) )
      65             : {
      66           0 :     m_aNeverChecked = String( CUI_RES( STR_NEVERCHECKED ) );
      67           0 :     FreeResource();
      68             : 
      69           0 :     m_aAutoCheckCheckBox.SetClickHdl( LINK( this, SvxOnlineUpdateTabPage, AutoCheckHdl_Impl ) );
      70           0 :     m_aCheckNowButton.SetClickHdl( LINK( this, SvxOnlineUpdateTabPage, CheckNowHdl_Impl ) );
      71           0 :     m_aChangePathButton.SetClickHdl( LINK( this, SvxOnlineUpdateTabPage, FileDialogHdl_Impl ) );
      72             : 
      73           0 :     uno::Reference < lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
      74             : 
      75             :     m_xUpdateAccess = uno::Reference < container::XNameReplace >(
      76           0 :         xFactory->createInstance( "com.sun.star.setup.UpdateCheckConfig" ),
      77           0 :         uno::UNO_QUERY_THROW );
      78             : 
      79           0 :     sal_Bool bDownloadSupported = sal_False;
      80           0 :     m_xUpdateAccess->getByName( "DownloadSupported" ) >>= bDownloadSupported;
      81             : 
      82           0 :     WinBits nStyle = m_aDestPath.GetStyle();
      83           0 :     nStyle |= WB_PATHELLIPSIS;
      84           0 :     m_aDestPath.SetStyle(nStyle);
      85             : 
      86           0 :     m_aAutoDownloadCheckBox.Show(bDownloadSupported);
      87           0 :     m_aDestPathLabel.Show(bDownloadSupported);
      88           0 :     m_aDestPath.Show(bDownloadSupported);
      89           0 :     m_aChangePathButton.Show(bDownloadSupported);
      90             : 
      91             :     // dynamical length of the PushButtons
      92           0 :     CalcButtonWidth();
      93             : 
      94           0 :     m_aLastCheckedTemplate = m_aLastChecked.GetText();
      95             : 
      96           0 :     UpdateLastCheckedText();
      97           0 : }
      98             : 
      99             : // -----------------------------------------------------------------------
     100             : 
     101           0 : SvxOnlineUpdateTabPage::~SvxOnlineUpdateTabPage()
     102             : {
     103           0 : }
     104             : 
     105             : // -----------------------------------------------------------------------
     106           0 : void SvxOnlineUpdateTabPage::UpdateLastCheckedText()
     107             : {
     108           0 :     rtl::OUString aDateStr;
     109           0 :     rtl::OUString aTimeStr;
     110           0 :     rtl::OUString aText;
     111           0 :     sal_Int64 lastChecked = 0;
     112             : 
     113           0 :     m_xUpdateAccess->getByName("LastCheck") >>= lastChecked;
     114             : 
     115           0 :     if( lastChecked == 0 ) // never checked
     116             :     {
     117           0 :         aText = m_aNeverChecked;
     118             :     }
     119             :     else
     120             :     {
     121             :         TimeValue   lastCheckedTV;
     122             :         oslDateTime lastCheckedDT;
     123             : 
     124           0 :         Date  aDate( Date::EMPTY );
     125           0 :         Time  aTime( Time::EMPTY );
     126             : 
     127           0 :         lastCheckedTV.Seconds = (sal_uInt32) lastChecked;
     128           0 :         osl_getLocalTimeFromSystemTime( &lastCheckedTV, &lastCheckedTV );
     129             : 
     130           0 :         if ( osl_getDateTimeFromTimeValue(  &lastCheckedTV, &lastCheckedDT ) )
     131             :         {
     132           0 :             aDate = Date( lastCheckedDT.Day, lastCheckedDT.Month, lastCheckedDT.Year );
     133           0 :             aTime = Time( lastCheckedDT.Hours, lastCheckedDT.Minutes );
     134             :         }
     135             : 
     136           0 :         LanguageType eUILang = Application::GetSettings().GetUILanguageTag().getLanguageType();
     137           0 :         SvNumberFormatter *pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), eUILang );
     138           0 :         String      aTmpStr;
     139           0 :         Color*      pColor = NULL;
     140           0 :         Date*       pNullDate = pNumberFormatter->GetNullDate();
     141           0 :         sal_uInt32  nFormat = pNumberFormatter->GetStandardFormat( NUMBERFORMAT_DATE, eUILang );
     142             : 
     143           0 :         pNumberFormatter->GetOutputString( aDate - *pNullDate, nFormat, aTmpStr, &pColor );
     144           0 :         aDateStr = aTmpStr;
     145             : 
     146           0 :         nFormat = pNumberFormatter->GetStandardFormat( NUMBERFORMAT_TIME, eUILang );
     147           0 :         pNumberFormatter->GetOutputString( aTime.GetTimeInDays(), nFormat, aTmpStr, &pColor );
     148           0 :         aTimeStr = aTmpStr;
     149             : 
     150           0 :         delete pColor;
     151           0 :         delete pNumberFormatter;
     152             : 
     153           0 :         aText = m_aLastCheckedTemplate;
     154           0 :         sal_Int32 nIndex = aText.indexOf( "%DATE%" );
     155           0 :         if ( nIndex != -1 )
     156           0 :             aText = aText.replaceAt( nIndex, 6, aDateStr );
     157             : 
     158           0 :         nIndex = aText.indexOf( "%TIME%" );
     159           0 :         if ( nIndex != -1 )
     160           0 :             aText = aText.replaceAt( nIndex, 6, aTimeStr );
     161             :     }
     162             : 
     163           0 :     m_aLastChecked.SetText( aText );
     164           0 : }
     165             : 
     166             : // -----------------------------------------------------------------------
     167             : 
     168             : SfxTabPage*
     169           0 : SvxOnlineUpdateTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
     170             : {
     171           0 :     return new SvxOnlineUpdateTabPage( pParent, rAttrSet );
     172             : }
     173             : 
     174             : // -----------------------------------------------------------------------
     175             : 
     176             : 
     177           0 : sal_Bool SvxOnlineUpdateTabPage::FillItemSet( SfxItemSet& )
     178             : {
     179           0 :     sal_Bool bModified = sal_False;
     180             : 
     181             :     sal_Bool bValue;
     182             :     sal_Int64 nValue;
     183             : 
     184           0 :     if( m_aAutoCheckCheckBox.GetSavedValue() != m_aAutoCheckCheckBox.IsChecked() )
     185             :     {
     186           0 :         bValue = (sal_True == m_aAutoCheckCheckBox.IsChecked());
     187           0 :         m_xUpdateAccess->replaceByName( "AutoCheckEnabled", uno::makeAny( bValue ) );
     188           0 :         bModified = sal_True;
     189             :     }
     190             : 
     191           0 :     nValue = 0;
     192           0 :     if( sal_True == m_aEveryDayButton.IsChecked() )
     193             :     {
     194           0 :         if( sal_False == m_aEveryDayButton.GetSavedValue() )
     195           0 :             nValue = 86400;
     196             :     }
     197           0 :     else if( sal_True == m_aEveryWeekButton.IsChecked() )
     198             :     {
     199           0 :         if( sal_False == m_aEveryWeekButton.GetSavedValue() )
     200           0 :             nValue = 604800;
     201             :     }
     202           0 :     else if( sal_True == m_aEveryMonthButton.IsChecked() )
     203             :     {
     204           0 :         if( sal_False == m_aEveryMonthButton.GetSavedValue() )
     205           0 :             nValue = 2592000;
     206             :     }
     207             : 
     208           0 :     if( nValue > 0 )
     209             :     {
     210           0 :         m_xUpdateAccess->replaceByName( "CheckInterval", uno::makeAny( nValue ) );
     211           0 :         bModified = sal_True;
     212             :     }
     213             : 
     214           0 :     if( m_aAutoDownloadCheckBox.GetSavedValue() != m_aAutoDownloadCheckBox.IsChecked() )
     215             :     {
     216           0 :         bValue = (sal_True == m_aAutoDownloadCheckBox.IsChecked());
     217           0 :         m_xUpdateAccess->replaceByName( "AutoDownloadEnabled", uno::makeAny( bValue ) );
     218           0 :         bModified = sal_True;
     219             :     }
     220             : 
     221           0 :     rtl::OUString sValue, aURL;
     222           0 :     m_xUpdateAccess->getByName( "DownloadDestination" ) >>= sValue;
     223             : 
     224           0 :     if( ( osl::FileBase::E_None == osl::FileBase::getFileURLFromSystemPath(m_aDestPath.GetText(), aURL) ) &&
     225           0 :         ( ! aURL.equals( sValue ) ) )
     226             :     {
     227           0 :         m_xUpdateAccess->replaceByName( "DownloadDestination", uno::makeAny( aURL ) );
     228           0 :         bModified = sal_True;
     229             :     }
     230             : 
     231           0 :     uno::Reference< util::XChangesBatch > xChangesBatch(m_xUpdateAccess, uno::UNO_QUERY);
     232           0 :     if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
     233           0 :         xChangesBatch->commitChanges();
     234             : 
     235           0 :     return bModified;
     236             : }
     237             : 
     238             : // -----------------------------------------------------------------------
     239             : 
     240           0 : void SvxOnlineUpdateTabPage::Reset( const SfxItemSet& )
     241             : {
     242           0 :     sal_Bool bValue = sal_Bool();
     243           0 :     m_xUpdateAccess->getByName( "AutoCheckEnabled" ) >>= bValue;
     244             : 
     245           0 :     m_aAutoCheckCheckBox.Check(bValue);
     246           0 :     m_aEveryDayButton.Enable(bValue);
     247           0 :     m_aEveryWeekButton.Enable(bValue);
     248           0 :     m_aEveryMonthButton.Enable(bValue);
     249             : 
     250           0 :     sal_Int64 nValue = 0;
     251           0 :     m_xUpdateAccess->getByName( "CheckInterval" ) >>= nValue;
     252             : 
     253           0 :     if( nValue == 86400 )
     254           0 :         m_aEveryDayButton.Check();
     255           0 :     else if( nValue == 604800 )
     256           0 :         m_aEveryWeekButton.Check();
     257             :     else
     258           0 :         m_aEveryMonthButton.Check();
     259             : 
     260           0 :     m_aAutoCheckCheckBox.SaveValue();
     261           0 :     m_aEveryDayButton.SaveValue();
     262           0 :     m_aEveryWeekButton.SaveValue();
     263           0 :     m_aEveryMonthButton.SaveValue();
     264             : 
     265           0 :     m_xUpdateAccess->getByName( "AutoDownloadEnabled" ) >>= bValue;
     266           0 :     m_aAutoDownloadCheckBox.Check(bValue);
     267           0 :     m_aDestPathLabel.Enable(sal_True);
     268           0 :     m_aDestPath.Enable(sal_True);
     269           0 :     m_aChangePathButton.Enable(sal_True);
     270             : 
     271           0 :     rtl::OUString sValue, aPath;
     272           0 :     m_xUpdateAccess->getByName( "DownloadDestination" ) >>= sValue;
     273             : 
     274           0 :     if( osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(sValue, aPath) )
     275           0 :         m_aDestPath.SetText(aPath);
     276             : 
     277           0 :     m_aAutoDownloadCheckBox.SaveValue();
     278           0 : }
     279             : 
     280             : // -----------------------------------------------------------------------
     281             : 
     282           0 : void SvxOnlineUpdateTabPage::FillUserData()
     283             : {
     284           0 : }
     285             : 
     286             : // -----------------------------------------------------------------------
     287             : 
     288           0 : IMPL_LINK( SvxOnlineUpdateTabPage, AutoCheckHdl_Impl, CheckBox *, pBox )
     289             : {
     290           0 :     sal_Bool bEnabled = pBox->IsChecked();
     291             : 
     292           0 :     m_aEveryDayButton.Enable(bEnabled);
     293           0 :     m_aEveryWeekButton.Enable(bEnabled);
     294           0 :     m_aEveryMonthButton.Enable(bEnabled);
     295             : 
     296           0 :     return 0;
     297             : }
     298             : 
     299             : // -----------------------------------------------------------------------
     300             : 
     301           0 : IMPL_LINK_NOARG(SvxOnlineUpdateTabPage, FileDialogHdl_Impl)
     302             : {
     303           0 :     uno::Reference < uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     304           0 :     uno::Reference < dialogs::XFolderPicker2 >  xFolderPicker = dialogs::FolderPicker::create(xContext);
     305             : 
     306           0 :     rtl::OUString aURL;
     307           0 :     if( osl::FileBase::E_None != osl::FileBase::getFileURLFromSystemPath(m_aDestPath.GetText(), aURL) )
     308           0 :         osl::Security().getHomeDir(aURL);
     309             : 
     310           0 :     xFolderPicker->setDisplayDirectory( aURL );
     311           0 :     sal_Int16 nRet = xFolderPicker->execute();
     312             : 
     313           0 :     if ( dialogs::ExecutableDialogResults::OK == nRet )
     314             :     {
     315           0 :         rtl::OUString aFolder;
     316           0 :         if( osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(xFolderPicker->getDirectory(), aFolder))
     317           0 :             m_aDestPath.SetText( aFolder );
     318             :     }
     319             : 
     320           0 :     return 0;
     321             : }
     322             : 
     323             : // -----------------------------------------------------------------------
     324             : 
     325           0 : IMPL_LINK_NOARG(SvxOnlineUpdateTabPage, CheckNowHdl_Impl)
     326             : {
     327           0 :     uno::Reference < uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     328             : 
     329             :     try
     330             :     {
     331             :         uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
     332           0 :             com::sun::star::configuration::theDefaultProvider::get( xContext ) );
     333             : 
     334           0 :         beans::NamedValue aProperty;
     335           0 :         aProperty.Name  = "nodepath";
     336           0 :         aProperty.Value = uno::makeAny( OUString("org.openoffice.Office.Addons/AddonUI/OfficeHelp/UpdateCheckJob") );
     337             : 
     338           0 :         uno::Sequence< uno::Any > aArgumentList( 1 );
     339           0 :         aArgumentList[0] = uno::makeAny( aProperty );
     340             : 
     341             :         uno::Reference< container::XNameAccess > xNameAccess(
     342           0 :             xConfigProvider->createInstanceWithArguments(
     343           0 :                 "com.sun.star.configuration.ConfigurationAccess", aArgumentList ),
     344           0 :             uno::UNO_QUERY_THROW );
     345             : 
     346           0 :         util::URL aURL;
     347           0 :         xNameAccess->getByName("URL") >>= aURL.Complete;
     348             : 
     349           0 :         uno::Reference < util::XURLTransformer > xTransformer( util::URLTransformer::create( xContext ) );
     350             : 
     351           0 :         xTransformer->parseStrict(aURL);
     352             : 
     353           0 :         uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create( xContext );
     354             : 
     355             :         uno::Reference< frame::XDispatchProvider > xDispatchProvider(
     356           0 :             xDesktop->getCurrentFrame(), uno::UNO_QUERY );
     357             : 
     358           0 :         uno::Reference< frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch(aURL, rtl::OUString(), 0);
     359             : 
     360           0 :         if( xDispatch.is() )
     361             :         {
     362           0 :             xDispatch->dispatch(aURL, uno::Sequence< beans::PropertyValue > ());
     363           0 :             UpdateLastCheckedText();
     364           0 :         }
     365             :     }
     366           0 :     catch( const uno::Exception& e )
     367             :     {
     368             :          OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
     369             :             rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
     370             :     }
     371             : 
     372           0 :     return 0;
     373             : }
     374             : 
     375           0 : void SvxOnlineUpdateTabPage::CalcButtonWidth()
     376             : {
     377             :     // detect the longest button text
     378           0 :     long nTxtWidth = ::std::max( m_aCheckNowButton.GetCtrlTextWidth( m_aCheckNowButton.GetText() ),
     379           0 :                                  m_aCheckNowButton.GetCtrlTextWidth( m_aChangePathButton.GetText() ) );
     380             :     // add a little offset
     381           0 :     nTxtWidth = nTxtWidth + 12;
     382             :     // compare with the button width
     383           0 :     Size aSize = m_aCheckNowButton.GetSizePixel();
     384             :     // and change it if it's necessary
     385           0 :     if ( nTxtWidth > aSize.Width() )
     386             :     {
     387           0 :         aSize.Width() = nTxtWidth;
     388           0 :         m_aCheckNowButton.SetSizePixel( aSize );
     389           0 :         m_aChangePathButton.SetSizePixel( aSize );
     390             :     }
     391           3 : }
     392             : 
     393             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10