1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: newerverwarn.cxx,v $
10 * $Revision: 1.1.2.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "newerverwarn.hxx"
32 #include "newerverwarn.hrc"
35 #include <com/sun/star/frame/XDesktop.hpp>
36 #include <com/sun/star/frame/XDispatchProvider.hpp>
37 #include <com/sun/star/system/XSystemShellExecute.hpp>
38 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
39 #include <com/sun/star/util/XURLTransformer.hpp>
40 #include <com/sun/star/container/XNameReplace.hpp>
42 #include <comphelper/processfactory.hxx>
43 #include <comphelper/configurationhelper.hxx>
44 #include <comphelper/componentcontext.hxx>
45 #include <rtl/bootstrap.hxx>
46 #include <tools/diagnose_ex.h>
47 #include <vcl/msgbox.hxx>
48 #include <osl/process.h>
50 namespace beans
= ::com::sun::star::beans
;
51 namespace frame
= ::com::sun::star::frame
;
52 namespace lang
= ::com::sun::star::lang
;
53 namespace uno
= ::com::sun::star::uno
;
54 namespace util
= ::com::sun::star::util
;
55 namespace container
= ::com::sun::star::container
;
57 using namespace com::sun::star::system
;
59 #define DEFINE_CONST_UNICODE( CONSTASCII ) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONSTASCII ) )
64 NewerVersionWarningDialog::NewerVersionWarningDialog(
65 Window
* pParent
, const ::rtl::OUString
& rVersion
, ResMgr
& rResMgr
) :
67 ModalDialog( pParent
, ResId( RID_DLG_NEWER_VERSION_WARNING
, rResMgr
) ),
69 m_aImage ( this, ResId( FI_IMAGE
, rResMgr
) ),
70 m_aInfoText ( this, ResId( FT_INFO
, rResMgr
) ),
71 m_aButtonLine ( this, ResId( FL_BUTTON
, rResMgr
) ),
72 m_aUpdateBtn ( this, ResId( PB_UPDATE
, rResMgr
) ),
73 m_aLaterBtn ( this, ResId( PB_LATER
, rResMgr
) ),
74 m_sVersion ( rVersion
)
78 m_aUpdateBtn
.SetClickHdl( LINK( this, NewerVersionWarningDialog
, UpdateHdl
) );
79 m_aLaterBtn
.SetClickHdl( LINK( this, NewerVersionWarningDialog
, LaterHdl
) );
84 NewerVersionWarningDialog::~NewerVersionWarningDialog()
88 IMPL_LINK( NewerVersionWarningDialog
, UpdateHdl
, PushButton
*, EMPTYARG
)
90 // detect execute path
91 ::rtl::OUString sProgramPath
;
92 osl_getExecutableFile( &sProgramPath
.pData
);
93 sal_uInt32 nLastIndex
= sProgramPath
.lastIndexOf( '/' );
95 sProgramPath
= sProgramPath
.copy( 0, nLastIndex
+ 1 );
97 // read keys from soffice.ini (sofficerc)
98 ::rtl::OUString sIniFileName
= sProgramPath
;
99 sIniFileName
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SAL_CONFIGFILE( "version" ) ) );
100 ::rtl::Bootstrap
aIniFile( sIniFileName
);
101 ::rtl::OUString sNotifyURL
;
102 aIniFile
.getFrom( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ODFNotifyURL" ) ), sNotifyURL
);
106 if ( ( sNotifyURL
.getLength() > 0 ) && ( m_sVersion
.getLength() > 0 ) )
108 uno::Reference
< lang::XMultiServiceFactory
> xSMGR
=
109 ::comphelper::getProcessServiceFactory();
110 uno::Reference
< XSystemShellExecute
> xSystemShell(
111 xSMGR
->createInstance( ::rtl::OUString(
112 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
113 uno::UNO_QUERY_THROW
);
114 sNotifyURL
+= m_sVersion
;
115 if ( xSystemShell
.is() && sNotifyURL
.getLength() )
117 xSystemShell
->execute(
118 sNotifyURL
, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS
);
123 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
125 uno::Reference
< container::XNameReplace
> xUpdateConfig(
126 aContext
.createComponent( "com.sun.star.setup.UpdateCheckConfig" ), uno::UNO_QUERY_THROW
);
128 sal_Bool bUpdateCheckEnabled
= sal_False
;
129 OSL_VERIFY( xUpdateConfig
->getByName( DEFINE_CONST_UNICODE( "AutoCheckEnabled" ) ) >>= bUpdateCheckEnabled
);
131 // TODO: do we need to respect the bUpdateCheckEnabled flag? Finally, its meaning is "are automatic
132 // updates enabled", but this here is not an automatic update, but one triggered explicitly by the user.
134 uno::Any aVal
= ::comphelper::ConfigurationHelper::readDirectKey(
135 aContext
.getLegacyServiceFactory(),
136 DEFINE_CONST_UNICODE("org.openoffice.Office.Addons/"),
137 DEFINE_CONST_UNICODE("AddonUI/OfficeHelp/UpdateCheckJob"),
138 DEFINE_CONST_UNICODE("URL"),
139 ::comphelper::ConfigurationHelper::E_READONLY
);
141 if ( aVal
>>= aURL
.Complete
)
143 uno::Reference
< util::XURLTransformer
> xTransformer(
144 aContext
.createComponent( "com.sun.star.util.URLTransformer" ), uno::UNO_QUERY_THROW
);
145 xTransformer
->parseStrict( aURL
);
147 uno::Reference
< frame::XDesktop
> xDesktop(
148 aContext
.createComponent( "com.sun.star.frame.Desktop" ), uno::UNO_QUERY_THROW
);
150 uno::Reference
< frame::XDispatchProvider
> xDispatchProvider(
151 xDesktop
->getCurrentFrame(), uno::UNO_QUERY
);
152 if ( !xDispatchProvider
.is() )
153 xDispatchProvider
= uno::Reference
< frame::XDispatchProvider
> ( xDesktop
, uno::UNO_QUERY
);
155 uno::Reference
< frame::XDispatch
> xDispatch
=
156 xDispatchProvider
->queryDispatch( aURL
, rtl::OUString(), 0 );
157 if ( xDispatch
.is() )
158 xDispatch
->dispatch( aURL
, uno::Sequence
< beans::PropertyValue
>() );
162 catch( const uno::Exception
& )
164 DBG_UNHANDLED_EXCEPTION();
171 IMPL_LINK( NewerVersionWarningDialog
, LaterHdl
, CancelButton
*, EMPTYARG
)
173 EndDialog( RET_ASK_LATER
);
177 void NewerVersionWarningDialog::InitButtonWidth()
179 // one button too small for its text?
180 long nBtnTextWidth
= m_aUpdateBtn
.GetCtrlTextWidth( m_aUpdateBtn
.GetText() );
181 long nTemp
= m_aLaterBtn
.GetCtrlTextWidth( m_aLaterBtn
.GetText() );
182 if ( nTemp
> nBtnTextWidth
)
183 nBtnTextWidth
= nTemp
;
184 nBtnTextWidth
= nBtnTextWidth
* 115 / 100; // a little offset
185 long nMaxBtnWidth
= LogicToPixel( Size( MAX_BUTTON_WIDTH
, 0 ), MAP_APPFONT
).Width();
186 nBtnTextWidth
= std::min( nBtnTextWidth
, nMaxBtnWidth
);
187 long nButtonWidth
= m_aUpdateBtn
.GetSizePixel().Width();
189 if ( nBtnTextWidth
> nButtonWidth
)
191 long nDelta
= nBtnTextWidth
- nButtonWidth
;
192 Point aNewPos
= m_aUpdateBtn
.GetPosPixel();
193 aNewPos
.X() -= 2*nDelta
;
194 Size aNewSize
= m_aUpdateBtn
.GetSizePixel();
195 aNewSize
.Width() += nDelta
;
196 m_aUpdateBtn
.SetPosSizePixel( aNewPos
, aNewSize
);
197 aNewPos
= m_aLaterBtn
.GetPosPixel();
198 aNewPos
.X() -= nDelta
;
199 m_aLaterBtn
.SetPosSizePixel( aNewPos
, aNewSize
);
203 } // end of namespace uui