1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "newerverwarn.hxx"
30 #include "newerverwarn.hrc"
33 #include <com/sun/star/frame/XDesktop.hpp>
34 #include <com/sun/star/frame/XDispatchProvider.hpp>
35 #include <com/sun/star/system/XSystemShellExecute.hpp>
36 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
37 #include <com/sun/star/util/XURLTransformer.hpp>
38 #include <com/sun/star/container/XNameReplace.hpp>
40 #include <comphelper/processfactory.hxx>
41 #include <comphelper/configurationhelper.hxx>
42 #include <comphelper/componentcontext.hxx>
43 #include <rtl/bootstrap.hxx>
44 #include <tools/diagnose_ex.h>
45 #include <vcl/msgbox.hxx>
46 #include <osl/process.h>
48 namespace beans
= ::com::sun::star::beans
;
49 namespace frame
= ::com::sun::star::frame
;
50 namespace lang
= ::com::sun::star::lang
;
51 namespace uno
= ::com::sun::star::uno
;
52 namespace util
= ::com::sun::star::util
;
53 namespace container
= ::com::sun::star::container
;
55 using namespace com::sun::star::system
;
57 #define DEFINE_CONST_UNICODE( CONSTASCII ) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONSTASCII ) )
62 NewerVersionWarningDialog::NewerVersionWarningDialog(
63 Window
* pParent
, const ::rtl::OUString
& rVersion
, ResMgr
& rResMgr
) :
65 ModalDialog( pParent
, ResId( RID_DLG_NEWER_VERSION_WARNING
, rResMgr
) ),
67 m_aImage ( this, ResId( FI_IMAGE
, rResMgr
) ),
68 m_aInfoText ( this, ResId( FT_INFO
, rResMgr
) ),
69 m_aButtonLine ( this, ResId( FL_BUTTON
, rResMgr
) ),
70 m_aUpdateBtn ( this, ResId( PB_UPDATE
, rResMgr
) ),
71 m_aLaterBtn ( this, ResId( PB_LATER
, rResMgr
) ),
72 m_sVersion ( rVersion
)
76 m_aUpdateBtn
.SetClickHdl( LINK( this, NewerVersionWarningDialog
, UpdateHdl
) );
77 m_aLaterBtn
.SetClickHdl( LINK( this, NewerVersionWarningDialog
, LaterHdl
) );
82 NewerVersionWarningDialog::~NewerVersionWarningDialog()
86 IMPL_LINK_NOARG(NewerVersionWarningDialog
, UpdateHdl
)
88 // detect execute path
89 ::rtl::OUString sProgramPath
;
90 osl_getExecutableFile( &sProgramPath
.pData
);
91 sal_uInt32 nLastIndex
= sProgramPath
.lastIndexOf( '/' );
93 sProgramPath
= sProgramPath
.copy( 0, nLastIndex
+ 1 );
95 // read keys from soffice.ini (sofficerc)
96 ::rtl::OUString sIniFileName
= sProgramPath
;
97 sIniFileName
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SAL_CONFIGFILE( "version" ) ) );
98 ::rtl::Bootstrap
aIniFile( sIniFileName
);
99 ::rtl::OUString sNotifyURL
;
100 aIniFile
.getFrom( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ODFNotifyURL" ) ), sNotifyURL
);
104 if ( !sNotifyURL
.isEmpty() && !m_sVersion
.isEmpty() )
106 uno::Reference
< lang::XMultiServiceFactory
> xSMGR
=
107 ::comphelper::getProcessServiceFactory();
108 uno::Reference
< XSystemShellExecute
> xSystemShell(
109 xSMGR
->createInstance( ::rtl::OUString(
110 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
111 uno::UNO_QUERY_THROW
);
112 sNotifyURL
+= m_sVersion
;
113 if ( xSystemShell
.is() && !sNotifyURL
.isEmpty() )
115 xSystemShell
->execute(
116 sNotifyURL
, ::rtl::OUString(), SystemShellExecuteFlags::URIS_ONLY
);
121 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
123 uno::Reference
< container::XNameReplace
> xUpdateConfig(
124 aContext
.createComponent( "com.sun.star.setup.UpdateCheckConfig" ), uno::UNO_QUERY_THROW
);
126 sal_Bool bUpdateCheckEnabled
= sal_False
;
127 OSL_VERIFY( xUpdateConfig
->getByName( DEFINE_CONST_UNICODE( "AutoCheckEnabled" ) ) >>= bUpdateCheckEnabled
);
129 // TODO: do we need to respect the bUpdateCheckEnabled flag? Finally, its meaning is "are automatic
130 // updates enabled", but this here is not an automatic update, but one triggered explicitly by the user.
132 uno::Any aVal
= ::comphelper::ConfigurationHelper::readDirectKey(
133 aContext
.getLegacyServiceFactory(),
134 DEFINE_CONST_UNICODE("org.openoffice.Office.Addons/"),
135 DEFINE_CONST_UNICODE("AddonUI/OfficeHelp/UpdateCheckJob"),
136 DEFINE_CONST_UNICODE("URL"),
137 ::comphelper::ConfigurationHelper::E_READONLY
);
139 if ( aVal
>>= aURL
.Complete
)
141 uno::Reference
< util::XURLTransformer
> xTransformer(
142 aContext
.createComponent( "com.sun.star.util.URLTransformer" ), uno::UNO_QUERY_THROW
);
143 xTransformer
->parseStrict( aURL
);
145 uno::Reference
< frame::XDesktop
> xDesktop(
146 aContext
.createComponent( "com.sun.star.frame.Desktop" ), uno::UNO_QUERY_THROW
);
148 uno::Reference
< frame::XDispatchProvider
> xDispatchProvider(
149 xDesktop
->getCurrentFrame(), uno::UNO_QUERY
);
150 if ( !xDispatchProvider
.is() )
151 xDispatchProvider
= uno::Reference
< frame::XDispatchProvider
> ( xDesktop
, uno::UNO_QUERY
);
153 uno::Reference
< frame::XDispatch
> xDispatch
=
154 xDispatchProvider
->queryDispatch( aURL
, rtl::OUString(), 0 );
155 if ( xDispatch
.is() )
156 xDispatch
->dispatch( aURL
, uno::Sequence
< beans::PropertyValue
>() );
160 catch( const uno::Exception
& )
162 DBG_UNHANDLED_EXCEPTION();
169 IMPL_LINK_NOARG(NewerVersionWarningDialog
, LaterHdl
)
171 EndDialog( RET_ASK_LATER
);
175 void NewerVersionWarningDialog::InitButtonWidth()
177 // one button too small for its text?
178 long nBtnTextWidth
= m_aUpdateBtn
.GetCtrlTextWidth( m_aUpdateBtn
.GetText() );
179 long nTemp
= m_aLaterBtn
.GetCtrlTextWidth( m_aLaterBtn
.GetText() );
180 if ( nTemp
> nBtnTextWidth
)
181 nBtnTextWidth
= nTemp
;
182 nBtnTextWidth
= nBtnTextWidth
* 115 / 100; // a little offset
183 long nMaxBtnWidth
= LogicToPixel( Size( MAX_BUTTON_WIDTH
, 0 ), MAP_APPFONT
).Width();
184 nBtnTextWidth
= std::min( nBtnTextWidth
, nMaxBtnWidth
);
185 long nButtonWidth
= m_aUpdateBtn
.GetSizePixel().Width();
187 if ( nBtnTextWidth
> nButtonWidth
)
189 long nDelta
= nBtnTextWidth
- nButtonWidth
;
190 Point aNewPos
= m_aUpdateBtn
.GetPosPixel();
191 aNewPos
.X() -= 2*nDelta
;
192 Size aNewSize
= m_aUpdateBtn
.GetSizePixel();
193 aNewSize
.Width() += nDelta
;
194 m_aUpdateBtn
.SetPosSizePixel( aNewPos
, aNewSize
);
195 aNewPos
= m_aLaterBtn
.GetPosPixel();
196 aNewPos
.X() -= nDelta
;
197 m_aLaterBtn
.SetPosSizePixel( aNewPos
, aNewSize
);
201 } // end of namespace uui
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */