1859212d1SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3859212d1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4859212d1SAndrew Rist * or more contributor license agreements. See the NOTICE file 5859212d1SAndrew Rist * distributed with this work for additional information 6859212d1SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7859212d1SAndrew Rist * to you under the Apache License, Version 2.0 (the 8859212d1SAndrew Rist * "License"); you may not use this file except in compliance 9859212d1SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11859212d1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13859212d1SAndrew Rist * Unless required by applicable law or agreed to in writing, 14859212d1SAndrew Rist * software distributed under the License is distributed on an 15859212d1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16859212d1SAndrew Rist * KIND, either express or implied. See the License for the 17859212d1SAndrew Rist * specific language governing permissions and limitations 18859212d1SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20859212d1SAndrew Rist *************************************************************/ 21859212d1SAndrew Rist 22859212d1SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "newerverwarn.hxx" 25cdf0e10cSrcweir #include "newerverwarn.hrc" 26cdf0e10cSrcweir #include "ids.hrc" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 29cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 30*9807c9deSAriel Constenla-Haile #include <com/sun/star/system/SystemShellExecute.hpp> 31cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 32cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 33cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 36cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 37cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 38cdf0e10cSrcweir #include <rtl/bootstrap.hxx> 39cdf0e10cSrcweir #include <tools/diagnose_ex.h> 40cdf0e10cSrcweir #include <vcl/msgbox.hxx> 41cdf0e10cSrcweir #include <osl/process.h> 42cdf0e10cSrcweir 43cdf0e10cSrcweir namespace beans = ::com::sun::star::beans; 44cdf0e10cSrcweir namespace frame = ::com::sun::star::frame; 45cdf0e10cSrcweir namespace lang = ::com::sun::star::lang; 46cdf0e10cSrcweir namespace uno = ::com::sun::star::uno; 47cdf0e10cSrcweir namespace util = ::com::sun::star::util; 48cdf0e10cSrcweir namespace container = ::com::sun::star::container; 49cdf0e10cSrcweir 50cdf0e10cSrcweir using namespace com::sun::star::system; 51cdf0e10cSrcweir 52cdf0e10cSrcweir #define DEFINE_CONST_UNICODE( CONSTASCII ) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONSTASCII ) ) 53cdf0e10cSrcweir 54cdf0e10cSrcweir namespace uui 55cdf0e10cSrcweir { 56cdf0e10cSrcweir 57cdf0e10cSrcweir NewerVersionWarningDialog::NewerVersionWarningDialog( 58cdf0e10cSrcweir Window* pParent, const ::rtl::OUString& rVersion, ResMgr& rResMgr ) : 59cdf0e10cSrcweir 60cdf0e10cSrcweir ModalDialog( pParent, ResId( RID_DLG_NEWER_VERSION_WARNING, rResMgr ) ), 61cdf0e10cSrcweir 62cdf0e10cSrcweir m_aImage ( this, ResId( FI_IMAGE, rResMgr ) ), 63cdf0e10cSrcweir m_aInfoText ( this, ResId( FT_INFO, rResMgr ) ), 64cdf0e10cSrcweir m_aButtonLine ( this, ResId( FL_BUTTON, rResMgr ) ), 65cdf0e10cSrcweir m_aUpdateBtn ( this, ResId( PB_UPDATE, rResMgr ) ), 66cdf0e10cSrcweir m_aLaterBtn ( this, ResId( PB_LATER, rResMgr ) ), 67cdf0e10cSrcweir m_sVersion ( rVersion ) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir FreeResource(); 70cdf0e10cSrcweir 71cdf0e10cSrcweir m_aUpdateBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, UpdateHdl ) ); 72cdf0e10cSrcweir m_aLaterBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, LaterHdl ) ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir InitButtonWidth(); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir NewerVersionWarningDialog::~NewerVersionWarningDialog() 78cdf0e10cSrcweir { 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir IMPL_LINK( NewerVersionWarningDialog, UpdateHdl, PushButton*, EMPTYARG ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir // detect execute path 84cdf0e10cSrcweir ::rtl::OUString sProgramPath; 85cdf0e10cSrcweir osl_getExecutableFile( &sProgramPath.pData ); 86cdf0e10cSrcweir sal_uInt32 nLastIndex = sProgramPath.lastIndexOf( '/' ); 87cdf0e10cSrcweir if ( nLastIndex > 0 ) 88cdf0e10cSrcweir sProgramPath = sProgramPath.copy( 0, nLastIndex + 1 ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir // read keys from soffice.ini (sofficerc) 91cdf0e10cSrcweir ::rtl::OUString sIniFileName = sProgramPath; 92cdf0e10cSrcweir sIniFileName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SAL_CONFIGFILE( "version" ) ) ); 93cdf0e10cSrcweir ::rtl::Bootstrap aIniFile( sIniFileName ); 94cdf0e10cSrcweir ::rtl::OUString sNotifyURL; 95cdf0e10cSrcweir aIniFile.getFrom( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ODFNotifyURL" ) ), sNotifyURL ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir try 98cdf0e10cSrcweir { 99cdf0e10cSrcweir if ( ( sNotifyURL.getLength() > 0 ) && ( m_sVersion.getLength() > 0 ) ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir uno::Reference< XSystemShellExecute > xSystemShell( 102*9807c9deSAriel Constenla-Haile com::sun::star::system::SystemShellExecute::create( 103*9807c9deSAriel Constenla-Haile ::comphelper::getProcessComponentContext() ) ); 104cdf0e10cSrcweir sNotifyURL += m_sVersion; 105cdf0e10cSrcweir if ( xSystemShell.is() && sNotifyURL.getLength() ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir xSystemShell->execute( 108cdf0e10cSrcweir sNotifyURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS ); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111cdf0e10cSrcweir else 112cdf0e10cSrcweir { 113cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 114cdf0e10cSrcweir 115cdf0e10cSrcweir uno::Reference < container::XNameReplace > xUpdateConfig( 116cdf0e10cSrcweir aContext.createComponent( "com.sun.star.setup.UpdateCheckConfig" ), uno::UNO_QUERY_THROW ); 117cdf0e10cSrcweir 118cdf0e10cSrcweir sal_Bool bUpdateCheckEnabled = sal_False; 119cdf0e10cSrcweir OSL_VERIFY( xUpdateConfig->getByName( DEFINE_CONST_UNICODE( "AutoCheckEnabled" ) ) >>= bUpdateCheckEnabled ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir // TODO: do we need to respect the bUpdateCheckEnabled flag? Finally, its meaning is "are automatic 122cdf0e10cSrcweir // updates enabled", but this here is not an automatic update, but one triggered explicitly by the user. 123cdf0e10cSrcweir 124cdf0e10cSrcweir uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey( 125cdf0e10cSrcweir aContext.getLegacyServiceFactory(), 126cdf0e10cSrcweir DEFINE_CONST_UNICODE("org.openoffice.Office.Addons/"), 127cdf0e10cSrcweir DEFINE_CONST_UNICODE("AddonUI/OfficeHelp/UpdateCheckJob"), 128cdf0e10cSrcweir DEFINE_CONST_UNICODE("URL"), 129cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_READONLY ); 130cdf0e10cSrcweir util::URL aURL; 131cdf0e10cSrcweir if ( aVal >>= aURL.Complete ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir uno::Reference< util::XURLTransformer > xTransformer( 134cdf0e10cSrcweir aContext.createComponent( "com.sun.star.util.URLTransformer" ), uno::UNO_QUERY_THROW ); 135cdf0e10cSrcweir xTransformer->parseStrict( aURL ); 136cdf0e10cSrcweir 137cdf0e10cSrcweir uno::Reference < frame::XDesktop > xDesktop( 138cdf0e10cSrcweir aContext.createComponent( "com.sun.star.frame.Desktop" ), uno::UNO_QUERY_THROW ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > xDispatchProvider( 141cdf0e10cSrcweir xDesktop->getCurrentFrame(), uno::UNO_QUERY ); 142cdf0e10cSrcweir if ( !xDispatchProvider.is() ) 143cdf0e10cSrcweir xDispatchProvider = uno::Reference < frame::XDispatchProvider > ( xDesktop, uno::UNO_QUERY ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir uno::Reference< frame::XDispatch > xDispatch = 146cdf0e10cSrcweir xDispatchProvider->queryDispatch( aURL, rtl::OUString(), 0 ); 147cdf0e10cSrcweir if ( xDispatch.is() ) 148cdf0e10cSrcweir xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() ); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir } 151cdf0e10cSrcweir } 152cdf0e10cSrcweir catch( const uno::Exception& ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir EndDialog( RET_OK ); 158cdf0e10cSrcweir return 0; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir IMPL_LINK( NewerVersionWarningDialog, LaterHdl, CancelButton*, EMPTYARG ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir EndDialog( RET_ASK_LATER ); 164cdf0e10cSrcweir return 0; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir void NewerVersionWarningDialog::InitButtonWidth() 168cdf0e10cSrcweir { 169cdf0e10cSrcweir // one button too small for its text? 170cdf0e10cSrcweir long nBtnTextWidth = m_aUpdateBtn.GetCtrlTextWidth( m_aUpdateBtn.GetText() ); 171cdf0e10cSrcweir long nTemp = m_aLaterBtn.GetCtrlTextWidth( m_aLaterBtn.GetText() ); 172cdf0e10cSrcweir if ( nTemp > nBtnTextWidth ) 173cdf0e10cSrcweir nBtnTextWidth = nTemp; 174cdf0e10cSrcweir nBtnTextWidth = nBtnTextWidth * 115 / 100; // a little offset 175cdf0e10cSrcweir long nMaxBtnWidth = LogicToPixel( Size( MAX_BUTTON_WIDTH, 0 ), MAP_APPFONT ).Width(); 176cdf0e10cSrcweir nBtnTextWidth = std::min( nBtnTextWidth, nMaxBtnWidth ); 177cdf0e10cSrcweir long nButtonWidth = m_aUpdateBtn .GetSizePixel().Width(); 178cdf0e10cSrcweir 179cdf0e10cSrcweir if ( nBtnTextWidth > nButtonWidth ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir long nDelta = nBtnTextWidth - nButtonWidth; 182cdf0e10cSrcweir Point aNewPos = m_aUpdateBtn.GetPosPixel(); 183cdf0e10cSrcweir aNewPos.X() -= 2*nDelta; 184cdf0e10cSrcweir Size aNewSize = m_aUpdateBtn.GetSizePixel(); 185cdf0e10cSrcweir aNewSize.Width() += nDelta; 186cdf0e10cSrcweir m_aUpdateBtn.SetPosSizePixel( aNewPos, aNewSize ); 187cdf0e10cSrcweir aNewPos = m_aLaterBtn.GetPosPixel(); 188cdf0e10cSrcweir aNewPos.X() -= nDelta; 189cdf0e10cSrcweir m_aLaterBtn.SetPosSizePixel( aNewPos, aNewSize ); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir } // end of namespace uui 194cdf0e10cSrcweir 195