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