bump product version to 4.2.0.1
[LibreOffice.git] / uui / source / newerverwarn.cxx
blob5f96cdb2d94ff6ab0c2da3714ce0cf758e7d5162
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 <config_features.h>
21 #include <config_folders.h>
23 #include "newerverwarn.hxx"
24 #include "newerverwarn.hrc"
25 #include "ids.hrc"
27 #include <com/sun/star/frame/Desktop.hpp>
28 #include <com/sun/star/frame/XDispatchProvider.hpp>
29 #include <com/sun/star/system/SystemShellExecute.hpp>
30 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
31 #include <com/sun/star/setup/UpdateCheckConfig.hpp>
32 #include <com/sun/star/util/URLTransformer.hpp>
33 #include <com/sun/star/util/XURLTransformer.hpp>
34 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
35 #include <com/sun/star/container/XNameReplace.hpp>
37 #include <comphelper/processfactory.hxx>
38 #include <rtl/bootstrap.hxx>
39 #include <tools/diagnose_ex.h>
40 #include <vcl/msgbox.hxx>
41 #include <osl/process.h>
42 #include <officecfg/Office/Addons.hxx>
44 using namespace com::sun::star;
46 namespace uui
49 NewerVersionWarningDialog::NewerVersionWarningDialog(
50 Window* pParent, const OUString& rVersion, ResMgr& rResMgr ) :
52 ModalDialog( pParent, ResId( RID_DLG_NEWER_VERSION_WARNING, rResMgr ) ),
54 m_aImage ( this, ResId( FI_IMAGE, rResMgr ) ),
55 m_aInfoText ( this, ResId( FT_INFO, rResMgr ) ),
56 m_aButtonLine ( this, ResId( FL_BUTTON, rResMgr ) ),
57 m_aUpdateBtn ( this, ResId( PB_UPDATE, rResMgr ) ),
58 m_aLaterBtn ( this, ResId( PB_LATER, rResMgr ) ),
59 m_sVersion ( rVersion )
61 FreeResource();
63 m_aUpdateBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, UpdateHdl ) );
64 m_aLaterBtn.SetClickHdl( LINK( this, NewerVersionWarningDialog, LaterHdl ) );
66 InitButtonWidth();
69 NewerVersionWarningDialog::~NewerVersionWarningDialog()
73 IMPL_LINK_NOARG(NewerVersionWarningDialog, UpdateHdl)
75 // detect execute path
76 OUString sProgramPath;
77 osl_getExecutableFile( &sProgramPath.pData );
78 sal_uInt32 nLastIndex = sProgramPath.lastIndexOf( '/' );
79 if ( nLastIndex > 0 )
80 sProgramPath = sProgramPath.copy( 0, nLastIndex + 1 );
82 // read keys from soffice.ini (sofficerc)
83 OUString sIniFileName = sProgramPath;
84 #if HAVE_FEATURE_MACOSX_MACLIKE_APP_STRUCTURE
85 sIniFileName += "../" LIBO_ETC_FOLDER "/";
86 #endif
87 sIniFileName += SAL_CONFIGFILE( "version" );
88 ::rtl::Bootstrap aIniFile( sIniFileName );
89 OUString sNotifyURL;
90 aIniFile.getFrom( OUString( "ODFNotifyURL" ), sNotifyURL );
92 try
94 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
95 if ( !sNotifyURL.isEmpty() && !m_sVersion.isEmpty() )
97 uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShell( com::sun::star::system::SystemShellExecute::create(xContext) );
98 sNotifyURL += m_sVersion;
99 if ( !sNotifyURL.isEmpty() )
101 xSystemShell->execute(
102 sNotifyURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
105 else
107 uno::Reference < container::XNameReplace > xUpdateConfig =
108 setup::UpdateCheckConfig::create(xContext);
110 sal_Bool bUpdateCheckEnabled = sal_False;
111 OSL_VERIFY( xUpdateConfig->getByName("AutoCheckEnabled") >>= bUpdateCheckEnabled );
113 // TODO: do we need to respect the bUpdateCheckEnabled flag? Finally, its meaning is "are automatic
114 // updates enabled", but this here is not an automatic update, but one triggered explicitly by the user.
115 css::uno::Reference< css::container::XHierarchicalNameAccess > xOfficeHelp(officecfg::Office::Addons::AddonUI::OfficeHelp::get(xContext), css::uno::UNO_QUERY_THROW);
117 util::URL aURL;
118 if ( xOfficeHelp->getByHierarchicalName("['UpdateCheckJob']/URL") >>= aURL.Complete )
120 uno::Reference< util::XURLTransformer > xTransformer( util::URLTransformer::create(xContext) );
121 xTransformer->parseStrict( aURL );
123 uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create(xContext);
125 uno::Reference< frame::XDispatchProvider > xDispatchProvider(
126 xDesktop->getCurrentFrame(), uno::UNO_QUERY );
127 if ( !xDispatchProvider.is() )
128 xDispatchProvider = uno::Reference < frame::XDispatchProvider > ( xDesktop, uno::UNO_QUERY );
130 uno::Reference< frame::XDispatch > xDispatch =
131 xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
132 if ( xDispatch.is() )
133 xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() );
137 catch( const uno::Exception& )
139 DBG_UNHANDLED_EXCEPTION();
142 EndDialog( RET_OK );
143 return 0;
146 IMPL_LINK_NOARG(NewerVersionWarningDialog, LaterHdl)
148 EndDialog( RET_ASK_LATER );
149 return 0;
152 void NewerVersionWarningDialog::InitButtonWidth()
154 // one button too small for its text?
155 long nBtnTextWidth = m_aUpdateBtn.GetCtrlTextWidth( m_aUpdateBtn.GetText() );
156 long nTemp = m_aLaterBtn.GetCtrlTextWidth( m_aLaterBtn.GetText() );
157 if ( nTemp > nBtnTextWidth )
158 nBtnTextWidth = nTemp;
159 nBtnTextWidth = nBtnTextWidth * 115 / 100; // a little offset
160 long nMaxBtnWidth = LogicToPixel( Size( MAX_BUTTON_WIDTH, 0 ), MAP_APPFONT ).Width();
161 nBtnTextWidth = std::min( nBtnTextWidth, nMaxBtnWidth );
162 long nButtonWidth = m_aUpdateBtn .GetSizePixel().Width();
164 if ( nBtnTextWidth > nButtonWidth )
166 long nDelta = nBtnTextWidth - nButtonWidth;
167 Point aNewPos = m_aUpdateBtn.GetPosPixel();
168 aNewPos.X() -= 2*nDelta;
169 Size aNewSize = m_aUpdateBtn.GetSizePixel();
170 aNewSize.Width() += nDelta;
171 m_aUpdateBtn.SetPosSizePixel( aNewPos, aNewSize );
172 aNewPos = m_aLaterBtn.GetPosPixel();
173 aNewPos.X() -= nDelta;
174 m_aLaterBtn.SetPosSizePixel( aNewPos, aNewSize );
178 } // end of namespace uui
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */