merged tag ooo/DEV300_m102
[LibreOffice.git] / uui / source / newerverwarn.cxx
blobf5d735b38d5b259768b140905e5ca382ec1cf376
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #include "newerverwarn.hxx"
29 #include "newerverwarn.hrc"
30 #include "ids.hrc"
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>
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>
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;
54 using namespace com::sun::star::system;
56 #define DEFINE_CONST_UNICODE( CONSTASCII ) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONSTASCII ) )
58 namespace uui
61 NewerVersionWarningDialog::NewerVersionWarningDialog(
62 Window* pParent, const ::rtl::OUString& rVersion, ResMgr& rResMgr ) :
64 ModalDialog( pParent, ResId( RID_DLG_NEWER_VERSION_WARNING, rResMgr ) ),
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 )
73 FreeResource();
75 m_aUpdateBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, UpdateHdl ) );
76 m_aLaterBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, LaterHdl ) );
78 InitButtonWidth();
81 NewerVersionWarningDialog::~NewerVersionWarningDialog()
85 IMPL_LINK( NewerVersionWarningDialog, UpdateHdl, PushButton*, EMPTYARG )
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 );
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 );
103 if ( ( sNotifyURL.getLength() > 0 ) && ( m_sVersion.getLength() > 0 ) )
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() )
114 xSystemShell->execute(
115 sNotifyURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
118 else
120 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
122 uno::Reference < container::XNameReplace > xUpdateConfig(
123 aContext.createComponent( "com.sun.star.setup.UpdateCheckConfig" ), uno::UNO_QUERY_THROW );
125 sal_Bool bUpdateCheckEnabled = sal_False;
126 OSL_VERIFY( xUpdateConfig->getByName( DEFINE_CONST_UNICODE( "AutoCheckEnabled" ) ) >>= bUpdateCheckEnabled );
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.
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 )
140 uno::Reference< util::XURLTransformer > xTransformer(
141 aContext.createComponent( "com.sun.star.util.URLTransformer" ), uno::UNO_QUERY_THROW );
142 xTransformer->parseStrict( aURL );
144 uno::Reference < frame::XDesktop > xDesktop(
145 aContext.createComponent( "com.sun.star.frame.Desktop" ), uno::UNO_QUERY_THROW );
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 );
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 >() );
159 catch( const uno::Exception& )
161 DBG_UNHANDLED_EXCEPTION();
164 EndDialog( RET_OK );
165 return 0;
168 IMPL_LINK( NewerVersionWarningDialog, LaterHdl, CancelButton*, EMPTYARG )
170 EndDialog( RET_ASK_LATER );
171 return 0;
174 void NewerVersionWarningDialog::InitButtonWidth()
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();
186 if ( nBtnTextWidth > nButtonWidth )
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 );
200 } // end of namespace uui