LCOV - code coverage report
Current view: top level - libreoffice/uui/source - newerverwarn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 71 0.0 %
Date: 2012-12-27 Functions: 0 8 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 "newerverwarn.hxx"
      21             : #include "newerverwarn.hrc"
      22             : #include "ids.hrc"
      23             : 
      24             : #include <com/sun/star/frame/Desktop.hpp>
      25             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      26             : #include <com/sun/star/system/SystemShellExecute.hpp>
      27             : #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
      28             : #include <com/sun/star/util/URLTransformer.hpp>
      29             : #include <com/sun/star/util/XURLTransformer.hpp>
      30             : #include <com/sun/star/container/XNameReplace.hpp>
      31             : 
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <comphelper/configurationhelper.hxx>
      34             : #include <comphelper/componentcontext.hxx>
      35             : #include <rtl/bootstrap.hxx>
      36             : #include <tools/diagnose_ex.h>
      37             : #include <vcl/msgbox.hxx>
      38             : #include <osl/process.h>
      39             : 
      40             : namespace beans     = ::com::sun::star::beans;
      41             : namespace frame     = ::com::sun::star::frame;
      42             : namespace lang      = ::com::sun::star::lang;
      43             : namespace uno       = ::com::sun::star::uno;
      44             : namespace util      = ::com::sun::star::util;
      45             : namespace container = ::com::sun::star::container;
      46             : 
      47             : using namespace com::sun::star::system;
      48             : 
      49             : namespace uui
      50             : {
      51             : 
      52           0 : NewerVersionWarningDialog::NewerVersionWarningDialog(
      53             :     Window* pParent, const ::rtl::OUString& rVersion, ResMgr& rResMgr ) :
      54             : 
      55             :     ModalDialog( pParent, ResId( RID_DLG_NEWER_VERSION_WARNING, rResMgr ) ),
      56             : 
      57             :     m_aImage        ( this, ResId( FI_IMAGE, rResMgr ) ),
      58             :     m_aInfoText     ( this, ResId( FT_INFO, rResMgr ) ),
      59             :     m_aButtonLine   ( this, ResId( FL_BUTTON, rResMgr ) ),
      60             :     m_aUpdateBtn    ( this, ResId( PB_UPDATE, rResMgr ) ),
      61             :     m_aLaterBtn     ( this, ResId( PB_LATER, rResMgr ) ),
      62           0 :     m_sVersion      ( rVersion )
      63             : {
      64           0 :     FreeResource();
      65             : 
      66           0 :     m_aUpdateBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, UpdateHdl ) );
      67           0 :     m_aLaterBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, LaterHdl ) );
      68             : 
      69           0 :     InitButtonWidth();
      70           0 : }
      71             : 
      72           0 : NewerVersionWarningDialog::~NewerVersionWarningDialog()
      73             : {
      74           0 : }
      75             : 
      76           0 : IMPL_LINK_NOARG(NewerVersionWarningDialog, UpdateHdl)
      77             : {
      78             :     // detect execute path
      79           0 :     OUString sProgramPath;
      80           0 :     osl_getExecutableFile( &sProgramPath.pData );
      81           0 :     sal_uInt32 nLastIndex = sProgramPath.lastIndexOf( '/' );
      82           0 :     if ( nLastIndex > 0 )
      83           0 :         sProgramPath = sProgramPath.copy( 0, nLastIndex + 1 );
      84             : 
      85             :     // read keys from soffice.ini (sofficerc)
      86           0 :     OUString sIniFileName = sProgramPath;
      87           0 :     sIniFileName += OUString( SAL_CONFIGFILE( "version" ) );
      88           0 :     ::rtl::Bootstrap aIniFile( sIniFileName );
      89           0 :     OUString sNotifyURL;
      90           0 :     aIniFile.getFrom( OUString(  "ODFNotifyURL" ), sNotifyURL );
      91             : 
      92             :     try
      93             :     {
      94           0 :         if (  !sNotifyURL.isEmpty()  &&  !m_sVersion.isEmpty() )
      95             :         {
      96           0 :             uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
      97           0 :             uno::Reference< XSystemShellExecute > xSystemShell( SystemShellExecute::create(xContext) );
      98           0 :             sNotifyURL += m_sVersion;
      99           0 :             if ( !sNotifyURL.isEmpty() )
     100             :             {
     101           0 :                 xSystemShell->execute(
     102           0 :                     sNotifyURL, ::rtl::OUString(), SystemShellExecuteFlags::URIS_ONLY );
     103           0 :             }
     104             :         }
     105             :         else
     106             :         {
     107           0 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
     108             : 
     109             :             uno::Reference < container::XNameReplace > xUpdateConfig(
     110           0 :                 aContext.createComponent( "com.sun.star.setup.UpdateCheckConfig" ), uno::UNO_QUERY_THROW );
     111             : 
     112           0 :             sal_Bool bUpdateCheckEnabled = sal_False;
     113           0 :             OSL_VERIFY( xUpdateConfig->getByName( OUString( "AutoCheckEnabled" ) ) >>= bUpdateCheckEnabled );
     114             : 
     115             :             // TODO: do we need to respect the bUpdateCheckEnabled flag? Finally, its meaning is "are automatic
     116             :             // updates enabled", but this here is not an automatic update, but one triggered explicitly by the user.
     117             : 
     118             :             uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
     119             :                                     aContext.getUNOContext(),
     120             :                                     "org.openoffice.Office.Addons/",
     121             :                                     "AddonUI/OfficeHelp/UpdateCheckJob",
     122             :                                     "URL",
     123           0 :                                     ::comphelper::ConfigurationHelper::E_READONLY );
     124           0 :             util::URL aURL;
     125           0 :             if ( aVal >>= aURL.Complete )
     126             :             {
     127           0 :                 uno::Reference< util::XURLTransformer > xTransformer( util::URLTransformer::create(aContext.getUNOContext()) );
     128           0 :                 xTransformer->parseStrict( aURL );
     129             : 
     130           0 :                 uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create(aContext.getUNOContext());
     131             : 
     132             :                 uno::Reference< frame::XDispatchProvider > xDispatchProvider(
     133           0 :                     xDesktop->getCurrentFrame(), uno::UNO_QUERY );
     134           0 :                 if ( !xDispatchProvider.is() )
     135           0 :                     xDispatchProvider = uno::Reference < frame::XDispatchProvider > ( xDesktop, uno::UNO_QUERY );
     136             : 
     137             :                 uno::Reference< frame::XDispatch > xDispatch =
     138           0 :                     xDispatchProvider->queryDispatch( aURL, rtl::OUString(), 0 );
     139           0 :                 if ( xDispatch.is() )
     140           0 :                     xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
     141           0 :             }
     142             :         }
     143             :     }
     144           0 :     catch( const uno::Exception& )
     145             :     {
     146             :         DBG_UNHANDLED_EXCEPTION();
     147             :     }
     148             : 
     149           0 :     EndDialog( RET_OK );
     150           0 :     return 0;
     151             : }
     152             : 
     153           0 : IMPL_LINK_NOARG(NewerVersionWarningDialog, LaterHdl)
     154             : {
     155           0 :     EndDialog( RET_ASK_LATER );
     156           0 :     return 0;
     157             : }
     158             : 
     159           0 : void NewerVersionWarningDialog::InitButtonWidth()
     160             : {
     161             :     // one button too small for its text?
     162           0 :     long nBtnTextWidth = m_aUpdateBtn.GetCtrlTextWidth( m_aUpdateBtn.GetText() );
     163           0 :     long nTemp = m_aLaterBtn.GetCtrlTextWidth( m_aLaterBtn.GetText() );
     164           0 :     if ( nTemp > nBtnTextWidth )
     165           0 :         nBtnTextWidth = nTemp;
     166           0 :     nBtnTextWidth = nBtnTextWidth * 115 / 100; // a little offset
     167           0 :     long nMaxBtnWidth = LogicToPixel( Size( MAX_BUTTON_WIDTH, 0 ), MAP_APPFONT ).Width();
     168           0 :     nBtnTextWidth = std::min( nBtnTextWidth, nMaxBtnWidth );
     169           0 :     long nButtonWidth = m_aUpdateBtn .GetSizePixel().Width();
     170             : 
     171           0 :     if ( nBtnTextWidth > nButtonWidth )
     172             :     {
     173           0 :         long nDelta = nBtnTextWidth - nButtonWidth;
     174           0 :         Point aNewPos = m_aUpdateBtn.GetPosPixel();
     175           0 :         aNewPos.X() -= 2*nDelta;
     176           0 :         Size aNewSize = m_aUpdateBtn.GetSizePixel();
     177           0 :         aNewSize.Width() += nDelta;
     178           0 :         m_aUpdateBtn.SetPosSizePixel( aNewPos, aNewSize );
     179           0 :         aNewPos = m_aLaterBtn.GetPosPixel();
     180           0 :         aNewPos.X() -= nDelta;
     181           0 :         m_aLaterBtn.SetPosSizePixel( aNewPos, aNewSize );
     182             :     }
     183           0 : }
     184             : 
     185             : } // end of namespace uui
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10