1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
24 #include <com/sun/star/frame/XDesktop.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/util/URLTransformer.hpp>
29 #include <com/sun/star/util/XURLTransformer.hpp>
30 #include <com/sun/star/container/XNameReplace.hpp>
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>
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
;
47 using namespace com::sun::star::system
;
49 #define DEFINE_CONST_UNICODE( CONSTASCII ) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONSTASCII ) )
54 NewerVersionWarningDialog::NewerVersionWarningDialog(
55 Window
* pParent
, const ::rtl::OUString
& rVersion
, ResMgr
& rResMgr
) :
57 ModalDialog( pParent
, ResId( RID_DLG_NEWER_VERSION_WARNING
, rResMgr
) ),
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 m_sVersion ( rVersion
)
68 m_aUpdateBtn
.SetClickHdl( LINK( this, NewerVersionWarningDialog
, UpdateHdl
) );
69 m_aLaterBtn
.SetClickHdl( LINK( this, NewerVersionWarningDialog
, LaterHdl
) );
74 NewerVersionWarningDialog::~NewerVersionWarningDialog()
78 IMPL_LINK_NOARG(NewerVersionWarningDialog
, UpdateHdl
)
80 // detect execute path
81 ::rtl::OUString sProgramPath
;
82 osl_getExecutableFile( &sProgramPath
.pData
);
83 sal_uInt32 nLastIndex
= sProgramPath
.lastIndexOf( '/' );
85 sProgramPath
= sProgramPath
.copy( 0, nLastIndex
+ 1 );
87 // read keys from soffice.ini (sofficerc)
88 ::rtl::OUString sIniFileName
= sProgramPath
;
89 sIniFileName
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SAL_CONFIGFILE( "version" ) ) );
90 ::rtl::Bootstrap
aIniFile( sIniFileName
);
91 ::rtl::OUString sNotifyURL
;
92 aIniFile
.getFrom( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ODFNotifyURL" ) ), sNotifyURL
);
96 if ( !sNotifyURL
.isEmpty() && !m_sVersion
.isEmpty() )
98 uno::Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
99 uno::Reference
< XSystemShellExecute
> xSystemShell( SystemShellExecute::create(xContext
) );
100 sNotifyURL
+= m_sVersion
;
101 if ( !sNotifyURL
.isEmpty() )
103 xSystemShell
->execute(
104 sNotifyURL
, ::rtl::OUString(), SystemShellExecuteFlags::URIS_ONLY
);
109 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
111 uno::Reference
< container::XNameReplace
> xUpdateConfig(
112 aContext
.createComponent( "com.sun.star.setup.UpdateCheckConfig" ), uno::UNO_QUERY_THROW
);
114 sal_Bool bUpdateCheckEnabled
= sal_False
;
115 OSL_VERIFY( xUpdateConfig
->getByName( DEFINE_CONST_UNICODE( "AutoCheckEnabled" ) ) >>= bUpdateCheckEnabled
);
117 // TODO: do we need to respect the bUpdateCheckEnabled flag? Finally, its meaning is "are automatic
118 // updates enabled", but this here is not an automatic update, but one triggered explicitly by the user.
120 uno::Any aVal
= ::comphelper::ConfigurationHelper::readDirectKey(
121 aContext
.getUNOContext(),
122 DEFINE_CONST_UNICODE("org.openoffice.Office.Addons/"),
123 DEFINE_CONST_UNICODE("AddonUI/OfficeHelp/UpdateCheckJob"),
124 DEFINE_CONST_UNICODE("URL"),
125 ::comphelper::ConfigurationHelper::E_READONLY
);
127 if ( aVal
>>= aURL
.Complete
)
129 uno::Reference
< util::XURLTransformer
> xTransformer( util::URLTransformer::create(aContext
.getUNOContext()) );
130 xTransformer
->parseStrict( aURL
);
132 uno::Reference
< frame::XDesktop
> xDesktop(
133 aContext
.createComponent( "com.sun.star.frame.Desktop" ), uno::UNO_QUERY_THROW
);
135 uno::Reference
< frame::XDispatchProvider
> xDispatchProvider(
136 xDesktop
->getCurrentFrame(), uno::UNO_QUERY
);
137 if ( !xDispatchProvider
.is() )
138 xDispatchProvider
= uno::Reference
< frame::XDispatchProvider
> ( xDesktop
, uno::UNO_QUERY
);
140 uno::Reference
< frame::XDispatch
> xDispatch
=
141 xDispatchProvider
->queryDispatch( aURL
, rtl::OUString(), 0 );
142 if ( xDispatch
.is() )
143 xDispatch
->dispatch( aURL
, uno::Sequence
< beans::PropertyValue
>() );
147 catch( const uno::Exception
& )
149 DBG_UNHANDLED_EXCEPTION();
156 IMPL_LINK_NOARG(NewerVersionWarningDialog
, LaterHdl
)
158 EndDialog( RET_ASK_LATER
);
162 void NewerVersionWarningDialog::InitButtonWidth()
164 // one button too small for its text?
165 long nBtnTextWidth
= m_aUpdateBtn
.GetCtrlTextWidth( m_aUpdateBtn
.GetText() );
166 long nTemp
= m_aLaterBtn
.GetCtrlTextWidth( m_aLaterBtn
.GetText() );
167 if ( nTemp
> nBtnTextWidth
)
168 nBtnTextWidth
= nTemp
;
169 nBtnTextWidth
= nBtnTextWidth
* 115 / 100; // a little offset
170 long nMaxBtnWidth
= LogicToPixel( Size( MAX_BUTTON_WIDTH
, 0 ), MAP_APPFONT
).Width();
171 nBtnTextWidth
= std::min( nBtnTextWidth
, nMaxBtnWidth
);
172 long nButtonWidth
= m_aUpdateBtn
.GetSizePixel().Width();
174 if ( nBtnTextWidth
> nButtonWidth
)
176 long nDelta
= nBtnTextWidth
- nButtonWidth
;
177 Point aNewPos
= m_aUpdateBtn
.GetPosPixel();
178 aNewPos
.X() -= 2*nDelta
;
179 Size aNewSize
= m_aUpdateBtn
.GetSizePixel();
180 aNewSize
.Width() += nDelta
;
181 m_aUpdateBtn
.SetPosSizePixel( aNewPos
, aNewSize
);
182 aNewPos
= m_aLaterBtn
.GetPosPixel();
183 aNewPos
.X() -= nDelta
;
184 m_aLaterBtn
.SetPosSizePixel( aNewPos
, aNewSize
);
188 } // end of namespace uui
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */