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