1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "newerverwarn.hxx" 29 #include "newerverwarn.hrc" 30 #include "ids.hrc" 31 32 #include <com/sun/star/frame/XDesktop.hpp> 33 #include <com/sun/star/frame/XDispatchProvider.hpp> 34 #include <com/sun/star/system/XSystemShellExecute.hpp> 35 #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 36 #include <com/sun/star/util/XURLTransformer.hpp> 37 #include <com/sun/star/container/XNameReplace.hpp> 38 39 #include <comphelper/processfactory.hxx> 40 #include <comphelper/configurationhelper.hxx> 41 #include <comphelper/componentcontext.hxx> 42 #include <rtl/bootstrap.hxx> 43 #include <tools/diagnose_ex.h> 44 #include <vcl/msgbox.hxx> 45 #include <osl/process.h> 46 47 namespace beans = ::com::sun::star::beans; 48 namespace frame = ::com::sun::star::frame; 49 namespace lang = ::com::sun::star::lang; 50 namespace uno = ::com::sun::star::uno; 51 namespace util = ::com::sun::star::util; 52 namespace container = ::com::sun::star::container; 53 54 using namespace com::sun::star::system; 55 56 #define DEFINE_CONST_UNICODE( CONSTASCII ) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONSTASCII ) ) 57 58 namespace uui 59 { 60 61 NewerVersionWarningDialog::NewerVersionWarningDialog( 62 Window* pParent, const ::rtl::OUString& rVersion, ResMgr& rResMgr ) : 63 64 ModalDialog( pParent, ResId( RID_DLG_NEWER_VERSION_WARNING, rResMgr ) ), 65 66 m_aImage ( this, ResId( FI_IMAGE, rResMgr ) ), 67 m_aInfoText ( this, ResId( FT_INFO, rResMgr ) ), 68 m_aButtonLine ( this, ResId( FL_BUTTON, rResMgr ) ), 69 m_aUpdateBtn ( this, ResId( PB_UPDATE, rResMgr ) ), 70 m_aLaterBtn ( this, ResId( PB_LATER, rResMgr ) ), 71 m_sVersion ( rVersion ) 72 { 73 FreeResource(); 74 75 m_aUpdateBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, UpdateHdl ) ); 76 m_aLaterBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, LaterHdl ) ); 77 78 InitButtonWidth(); 79 } 80 81 NewerVersionWarningDialog::~NewerVersionWarningDialog() 82 { 83 } 84 85 IMPL_LINK( NewerVersionWarningDialog, UpdateHdl, PushButton*, EMPTYARG ) 86 { 87 // detect execute path 88 ::rtl::OUString sProgramPath; 89 osl_getExecutableFile( &sProgramPath.pData ); 90 sal_uInt32 nLastIndex = sProgramPath.lastIndexOf( '/' ); 91 if ( nLastIndex > 0 ) 92 sProgramPath = sProgramPath.copy( 0, nLastIndex + 1 ); 93 94 // read keys from soffice.ini (sofficerc) 95 ::rtl::OUString sIniFileName = sProgramPath; 96 sIniFileName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SAL_CONFIGFILE( "version" ) ) ); 97 ::rtl::Bootstrap aIniFile( sIniFileName ); 98 ::rtl::OUString sNotifyURL; 99 aIniFile.getFrom( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ODFNotifyURL" ) ), sNotifyURL ); 100 101 try 102 { 103 if ( ( sNotifyURL.getLength() > 0 ) && ( m_sVersion.getLength() > 0 ) ) 104 { 105 uno::Reference< lang::XMultiServiceFactory > xSMGR = 106 ::comphelper::getProcessServiceFactory(); 107 uno::Reference< XSystemShellExecute > xSystemShell( 108 xSMGR->createInstance( ::rtl::OUString( 109 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ), 110 uno::UNO_QUERY_THROW ); 111 sNotifyURL += m_sVersion; 112 if ( xSystemShell.is() && sNotifyURL.getLength() ) 113 { 114 xSystemShell->execute( 115 sNotifyURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS ); 116 } 117 } 118 else 119 { 120 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 121 122 uno::Reference < container::XNameReplace > xUpdateConfig( 123 aContext.createComponent( "com.sun.star.setup.UpdateCheckConfig" ), uno::UNO_QUERY_THROW ); 124 125 sal_Bool bUpdateCheckEnabled = sal_False; 126 OSL_VERIFY( xUpdateConfig->getByName( DEFINE_CONST_UNICODE( "AutoCheckEnabled" ) ) >>= bUpdateCheckEnabled ); 127 128 // TODO: do we need to respect the bUpdateCheckEnabled flag? Finally, its meaning is "are automatic 129 // updates enabled", but this here is not an automatic update, but one triggered explicitly by the user. 130 131 uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey( 132 aContext.getLegacyServiceFactory(), 133 DEFINE_CONST_UNICODE("org.openoffice.Office.Addons/"), 134 DEFINE_CONST_UNICODE("AddonUI/OfficeHelp/UpdateCheckJob"), 135 DEFINE_CONST_UNICODE("URL"), 136 ::comphelper::ConfigurationHelper::E_READONLY ); 137 util::URL aURL; 138 if ( aVal >>= aURL.Complete ) 139 { 140 uno::Reference< util::XURLTransformer > xTransformer( 141 aContext.createComponent( "com.sun.star.util.URLTransformer" ), uno::UNO_QUERY_THROW ); 142 xTransformer->parseStrict( aURL ); 143 144 uno::Reference < frame::XDesktop > xDesktop( 145 aContext.createComponent( "com.sun.star.frame.Desktop" ), uno::UNO_QUERY_THROW ); 146 147 uno::Reference< frame::XDispatchProvider > xDispatchProvider( 148 xDesktop->getCurrentFrame(), uno::UNO_QUERY ); 149 if ( !xDispatchProvider.is() ) 150 xDispatchProvider = uno::Reference < frame::XDispatchProvider > ( xDesktop, uno::UNO_QUERY ); 151 152 uno::Reference< frame::XDispatch > xDispatch = 153 xDispatchProvider->queryDispatch( aURL, rtl::OUString(), 0 ); 154 if ( xDispatch.is() ) 155 xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() ); 156 } 157 } 158 } 159 catch( const uno::Exception& ) 160 { 161 DBG_UNHANDLED_EXCEPTION(); 162 } 163 164 EndDialog( RET_OK ); 165 return 0; 166 } 167 168 IMPL_LINK( NewerVersionWarningDialog, LaterHdl, CancelButton*, EMPTYARG ) 169 { 170 EndDialog( RET_ASK_LATER ); 171 return 0; 172 } 173 174 void NewerVersionWarningDialog::InitButtonWidth() 175 { 176 // one button too small for its text? 177 long nBtnTextWidth = m_aUpdateBtn.GetCtrlTextWidth( m_aUpdateBtn.GetText() ); 178 long nTemp = m_aLaterBtn.GetCtrlTextWidth( m_aLaterBtn.GetText() ); 179 if ( nTemp > nBtnTextWidth ) 180 nBtnTextWidth = nTemp; 181 nBtnTextWidth = nBtnTextWidth * 115 / 100; // a little offset 182 long nMaxBtnWidth = LogicToPixel( Size( MAX_BUTTON_WIDTH, 0 ), MAP_APPFONT ).Width(); 183 nBtnTextWidth = std::min( nBtnTextWidth, nMaxBtnWidth ); 184 long nButtonWidth = m_aUpdateBtn .GetSizePixel().Width(); 185 186 if ( nBtnTextWidth > nButtonWidth ) 187 { 188 long nDelta = nBtnTextWidth - nButtonWidth; 189 Point aNewPos = m_aUpdateBtn.GetPosPixel(); 190 aNewPos.X() -= 2*nDelta; 191 Size aNewSize = m_aUpdateBtn.GetSizePixel(); 192 aNewSize.Width() += nDelta; 193 m_aUpdateBtn.SetPosSizePixel( aNewPos, aNewSize ); 194 aNewPos = m_aLaterBtn.GetPosPixel(); 195 aNewPos.X() -= nDelta; 196 m_aLaterBtn.SetPosSizePixel( aNewPos, aNewSize ); 197 } 198 } 199 200 } // end of namespace uui 201 202