bump product version to 4.1.6.2
[LibreOffice.git] / uui / source / newerverwarn.cxx
blobffa48d012a122f878482637372e8ee9138114d8c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "newerverwarn.hxx"
21 #include "newerverwarn.hrc"
22 #include "ids.hrc"
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/setup/UpdateCheckConfig.hpp>
29 #include <com/sun/star/util/URLTransformer.hpp>
30 #include <com/sun/star/util/XURLTransformer.hpp>
31 #include <com/sun/star/container/XNameReplace.hpp>
33 #include <comphelper/processfactory.hxx>
34 #include <comphelper/configurationhelper.hxx>
35 #include <comphelper/componentcontext.hxx>
36 #include <rtl/bootstrap.hxx>
37 #include <tools/diagnose_ex.h>
38 #include <vcl/msgbox.hxx>
39 #include <osl/process.h>
41 using namespace com::sun::star;
43 namespace uui
46 NewerVersionWarningDialog::NewerVersionWarningDialog(
47 Window* pParent, const OUString& rVersion, ResMgr& rResMgr ) :
49 ModalDialog( pParent, ResId( RID_DLG_NEWER_VERSION_WARNING, rResMgr ) ),
51 m_aImage ( this, ResId( FI_IMAGE, rResMgr ) ),
52 m_aInfoText ( this, ResId( FT_INFO, rResMgr ) ),
53 m_aButtonLine ( this, ResId( FL_BUTTON, rResMgr ) ),
54 m_aUpdateBtn ( this, ResId( PB_UPDATE, rResMgr ) ),
55 m_aLaterBtn ( this, ResId( PB_LATER, rResMgr ) ),
56 m_sVersion ( rVersion )
58 FreeResource();
60 m_aUpdateBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, UpdateHdl ) );
61 m_aLaterBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, LaterHdl ) );
63 InitButtonWidth();
66 NewerVersionWarningDialog::~NewerVersionWarningDialog()
70 IMPL_LINK_NOARG(NewerVersionWarningDialog, UpdateHdl)
72 // detect execute path
73 OUString sProgramPath;
74 osl_getExecutableFile( &sProgramPath.pData );
75 sal_uInt32 nLastIndex = sProgramPath.lastIndexOf( '/' );
76 if ( nLastIndex > 0 )
77 sProgramPath = sProgramPath.copy( 0, nLastIndex + 1 );
79 // read keys from soffice.ini (sofficerc)
80 OUString sIniFileName = sProgramPath;
81 sIniFileName += OUString( SAL_CONFIGFILE( "version" ) );
82 ::rtl::Bootstrap aIniFile( sIniFileName );
83 OUString sNotifyURL;
84 aIniFile.getFrom( OUString( "ODFNotifyURL" ), sNotifyURL );
86 try
88 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
89 if ( !sNotifyURL.isEmpty() && !m_sVersion.isEmpty() )
91 uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShell( com::sun::star::system::SystemShellExecute::create(xContext) );
92 sNotifyURL += m_sVersion;
93 if ( !sNotifyURL.isEmpty() )
95 xSystemShell->execute(
96 sNotifyURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
99 else
101 uno::Reference < container::XNameReplace > xUpdateConfig =
102 setup::UpdateCheckConfig::create(xContext);
104 sal_Bool bUpdateCheckEnabled = sal_False;
105 OSL_VERIFY( xUpdateConfig->getByName( OUString( "AutoCheckEnabled" ) ) >>= bUpdateCheckEnabled );
107 // TODO: do we need to respect the bUpdateCheckEnabled flag? Finally, its meaning is "are automatic
108 // updates enabled", but this here is not an automatic update, but one triggered explicitly by the user.
110 uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
111 xContext,
112 "org.openoffice.Office.Addons/",
113 "AddonUI/OfficeHelp/UpdateCheckJob",
114 "URL",
115 ::comphelper::ConfigurationHelper::E_READONLY );
116 util::URL aURL;
117 if ( aVal >>= aURL.Complete )
119 uno::Reference< util::XURLTransformer > xTransformer( util::URLTransformer::create(xContext) );
120 xTransformer->parseStrict( aURL );
122 uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create(xContext);
124 uno::Reference< frame::XDispatchProvider > xDispatchProvider(
125 xDesktop->getCurrentFrame(), uno::UNO_QUERY );
126 if ( !xDispatchProvider.is() )
127 xDispatchProvider = uno::Reference < frame::XDispatchProvider > ( xDesktop, uno::UNO_QUERY );
129 uno::Reference< frame::XDispatch > xDispatch =
130 xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
131 if ( xDispatch.is() )
132 xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
136 catch( const uno::Exception& )
138 DBG_UNHANDLED_EXCEPTION();
141 EndDialog( RET_OK );
142 return 0;
145 IMPL_LINK_NOARG(NewerVersionWarningDialog, LaterHdl)
147 EndDialog( RET_ASK_LATER );
148 return 0;
151 void NewerVersionWarningDialog::InitButtonWidth()
153 // one button too small for its text?
154 long nBtnTextWidth = m_aUpdateBtn.GetCtrlTextWidth( m_aUpdateBtn.GetText() );
155 long nTemp = m_aLaterBtn.GetCtrlTextWidth( m_aLaterBtn.GetText() );
156 if ( nTemp > nBtnTextWidth )
157 nBtnTextWidth = nTemp;
158 nBtnTextWidth = nBtnTextWidth * 115 / 100; // a little offset
159 long nMaxBtnWidth = LogicToPixel( Size( MAX_BUTTON_WIDTH, 0 ), MAP_APPFONT ).Width();
160 nBtnTextWidth = std::min( nBtnTextWidth, nMaxBtnWidth );
161 long nButtonWidth = m_aUpdateBtn .GetSizePixel().Width();
163 if ( nBtnTextWidth > nButtonWidth )
165 long nDelta = nBtnTextWidth - nButtonWidth;
166 Point aNewPos = m_aUpdateBtn.GetPosPixel();
167 aNewPos.X() -= 2*nDelta;
168 Size aNewSize = m_aUpdateBtn.GetSizePixel();
169 aNewSize.Width() += nDelta;
170 m_aUpdateBtn.SetPosSizePixel( aNewPos, aNewSize );
171 aNewPos = m_aLaterBtn.GetPosPixel();
172 aNewPos.X() -= nDelta;
173 m_aLaterBtn.SetPosSizePixel( aNewPos, aNewSize );
177 } // end of namespace uui
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */