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