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: dp_gui_service.cxx,v $
10 * $Revision: 1.23.86.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_desktop.hxx"
34 #include "dp_gui_shared.hxx"
36 #include "dp_gui_theextmgr.hxx"
37 #include "cppuhelper/implbase2.hxx"
38 #include "cppuhelper/implementationentry.hxx"
39 #include "unotools/configmgr.hxx"
40 #include "comphelper/servicedecl.hxx"
41 #include "comphelper/unwrapargs.hxx"
42 #include <i18npool/mslangid.hxx>
43 #include "vcl/svapp.hxx"
44 #include "vcl/msgbox.hxx"
45 #include "com/sun/star/lang/XServiceInfo.hpp"
46 #include "com/sun/star/task/XJobExecutor.hpp"
47 #include "com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp"
49 #include "boost/bind.hpp"
50 #include "license_dialog.hxx"
51 #include "dp_gui_dialog2.hxx"
53 using namespace ::dp_misc
;
54 using namespace ::com::sun::star
;
55 using namespace ::com::sun::star::uno
;
57 using ::rtl::OUString
;
59 namespace css
= ::com::sun::star
;
62 //==============================================================================
63 class MyApp
: public Application
, private boost::noncopyable
73 //______________________________________________________________________________
78 //______________________________________________________________________________
83 //______________________________________________________________________________
88 //##############################################################################
93 : public rtl::Static
< String
, ProductName
> {};
95 : public rtl::Static
< String
, Version
> {};
96 struct AboutBoxVersion
97 : public rtl::Static
< String
, AboutBoxVersion
> {};
99 : public rtl::Static
< String
, Extension
> {};
102 void ReplaceProductNameHookProc( String
& rStr
)
104 static int nAll
= 0, nPro
= 0;
107 if ( rStr
.SearchAscii( "%PRODUCT" ) != STRING_NOTFOUND
)
109 String
&rProductName
= ProductName::get();
110 String
&rVersion
= Version::get();
111 String
&rAboutBoxVersion
= AboutBoxVersion::get();
112 String
&rExtension
= Extension::get();
114 if ( !rProductName
.Len() )
117 Any aRet
= ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME
);
121 aRet
= ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTVERSION
);
125 aRet
= ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::ABOUTBOXPRODUCTVERSION
);
127 rAboutBoxVersion
= aTmp
;
129 if ( !rExtension
.Len() )
131 aRet
= ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTEXTENSION
);
138 rStr
.SearchAndReplaceAllAscii( "%PRODUCTNAME", rProductName
);
139 rStr
.SearchAndReplaceAllAscii( "%PRODUCTVERSION", rVersion
);
140 rStr
.SearchAndReplaceAllAscii( "%ABOUTBOXPRODUCTVERSION", rAboutBoxVersion
);
141 rStr
.SearchAndReplaceAllAscii( "%PRODUCTEXTENSION", rExtension
);
145 //==============================================================================
147 : public ::cppu::WeakImplHelper2
<ui::dialogs::XAsynchronousExecutableDialog
,
150 Reference
<XComponentContext
> const m_xComponentContext
;
151 boost::optional
< Reference
<awt::XWindow
> > /* const */ m_parent
;
152 boost::optional
<OUString
> /* const */ m_view
;
153 /* if true then this service is running in an unopkg process and not in an office process */
154 boost::optional
<sal_Bool
> /* const */ m_unopkg
;
155 boost::optional
<OUString
> m_extensionURL
;
156 OUString m_initialTitle
;
157 bool m_bShowUpdateOnly
;
160 ServiceImpl( Sequence
<Any
> const & args
,
161 Reference
<XComponentContext
> const & xComponentContext
);
163 // XAsynchronousExecutableDialog
164 virtual void SAL_CALL
setDialogTitle( OUString
const & aTitle
)
165 throw (RuntimeException
);
166 virtual void SAL_CALL
startExecuteModal(
167 Reference
< ui::dialogs::XDialogClosedListener
> const & xListener
)
168 throw (RuntimeException
);
171 virtual void SAL_CALL
trigger( OUString
const & event
)
172 throw (RuntimeException
);
175 //______________________________________________________________________________
176 ServiceImpl::ServiceImpl( Sequence
<Any
> const& args
,
177 Reference
<XComponentContext
> const& xComponentContext
)
178 : m_xComponentContext(xComponentContext
),
179 m_bShowUpdateOnly( false )
182 comphelper::unwrapArgs( args
, m_parent
, m_view
, m_unopkg
);
184 } catch (css::lang::IllegalArgumentException
& ) {
187 comphelper::unwrapArgs( args
, m_extensionURL
);
188 } catch (css::lang::IllegalArgumentException
& ) {
191 ResHookProc pProc
= ResMgr::GetReadStringHook();
193 ResMgr::SetReadStringHook( ReplaceProductNameHookProc
);
196 // XAsynchronousExecutableDialog
197 //______________________________________________________________________________
198 void ServiceImpl::setDialogTitle( OUString
const & title
)
199 throw (RuntimeException
)
201 if ( dp_gui::TheExtensionManager::s_ExtMgr
.is() )
203 const ::vos::OGuard
guard( Application::GetSolarMutex() );
204 ::rtl::Reference
< ::dp_gui::TheExtensionManager
> dialog(
205 ::dp_gui::TheExtensionManager::get( m_xComponentContext
,
206 m_parent
? *m_parent
: Reference
<awt::XWindow
>(),
207 m_extensionURL
? *m_extensionURL
: OUString() ) );
208 dialog
->SetText( title
);
211 m_initialTitle
= title
;
214 //______________________________________________________________________________
215 void ServiceImpl::startExecuteModal(
216 Reference
< ui::dialogs::XDialogClosedListener
> const & xListener
)
217 throw (RuntimeException
)
219 bool bCloseDialog
= true; // only used if m_bShowUpdateOnly is true
220 ::std::auto_ptr
<Application
> app
;
221 //ToDo: synchronize access to s_dialog !!!
222 if (! dp_gui::TheExtensionManager::s_ExtMgr
.is())
224 const bool bAppUp
= (GetpApp() != 0);
225 bool bOfficePipePresent
;
227 bOfficePipePresent
= dp_misc::office_is_running();
229 catch (Exception
& exc
) {
231 const vos::OGuard
guard( Application::GetSolarMutex() );
232 std::auto_ptr
<ErrorBox
> box(
233 new ErrorBox( Application::GetActiveTopWindow(),
234 WB_OK
, exc
.Message
) );
240 if (! bOfficePipePresent
) {
241 OSL_ASSERT( ! bAppUp
);
242 app
.reset( new MyApp
);
243 if (! InitVCL( Reference
<lang::XMultiServiceFactory
>(
244 m_xComponentContext
->getServiceManager(),
246 throw RuntimeException( OUSTR("Cannot initialize VCL!"),
247 static_cast<OWeakObject
*>(this) );
248 AllSettings as
= app
->GetSettings();
250 if (! (::utl::ConfigManager::GetDirectConfigProperty(
251 ::utl::ConfigManager::LOCALE
) >>= slang
))
252 throw RuntimeException( OUSTR("Cannot determine language!"),
253 static_cast<OWeakObject
*>(this) );
254 as
.SetUILanguage( MsLangId::convertIsoStringToLanguage( slang
) );
255 app
->SetSettings( as
);
256 String sTitle
= ::utl::ConfigManager::GetDirectConfigProperty(
257 ::utl::ConfigManager::PRODUCTNAME
).get
<OUString
>()
258 + String(static_cast<sal_Unicode
>(' '))
259 + ::utl::ConfigManager::GetDirectConfigProperty(
260 ::utl::ConfigManager::PRODUCTVERSION
).get
<OUString
>();
261 app
->SetDisplayName(sTitle
);
266 // When m_bShowUpdateOnly is set, we are inside the office and the user clicked
267 // the update notification icon in the menu bar. We must not close the extensions
268 // dialog after displaying the update dialog when it has been visible before
269 if ( m_bShowUpdateOnly
)
270 bCloseDialog
= ! dp_gui::TheExtensionManager::s_ExtMgr
->isVisible();
274 const ::vos::OGuard
guard( Application::GetSolarMutex() );
275 ::rtl::Reference
< ::dp_gui::TheExtensionManager
> myExtMgr(
276 ::dp_gui::TheExtensionManager::get(
278 m_parent
? *m_parent
: Reference
<awt::XWindow
>(),
279 m_extensionURL
? *m_extensionURL
: OUString() ) );
280 myExtMgr
->createDialog( false );
281 if (m_initialTitle
.getLength() > 0) {
282 myExtMgr
->SetText( m_initialTitle
);
283 m_initialTitle
= OUString();
285 if ( m_bShowUpdateOnly
)
287 myExtMgr
->checkUpdates( true, !bCloseDialog
);
291 myExtMgr
->ToTop( TOTOP_RESTOREWHENMIN
);
296 myExtMgr
->ToTop( TOTOP_RESTOREWHENMIN
);
300 if (app
.get() != 0) {
301 Application::Execute();
306 xListener
->dialogClosed(
307 ui::dialogs::DialogClosedEvent(
308 static_cast< ::cppu::OWeakObject
* >(this),
313 //______________________________________________________________________________
314 void ServiceImpl::trigger( OUString
const &rEvent
) throw (RuntimeException
)
316 if ( rEvent
== OUSTR("SHOW_UPDATE_DIALOG") )
317 m_bShowUpdateOnly
= true;
319 m_bShowUpdateOnly
= false;
321 startExecuteModal( Reference
< ui::dialogs::XDialogClosedListener
>() );
324 namespace sdecl
= comphelper::service_decl
;
325 sdecl::class_
<ServiceImpl
, sdecl::with_args
<true> > serviceSI
;
326 sdecl::ServiceDecl
const serviceDecl(
328 "com.sun.star.comp.deployment.ui.PackageManagerDialog",
329 "com.sun.star.deployment.ui.PackageManagerDialog" );
331 sdecl::class_
<LicenseDialog
, sdecl::with_args
<true> > licenseSI
;
332 sdecl::ServiceDecl
const licenseDecl(
334 "com.sun.star.comp.deployment.ui.LicenseDialog",
335 "com.sun.star.deployment.ui.LicenseDialog" );
337 sdecl::class_
<UpdateRequiredDialogService
, sdecl::with_args
<true> > updateSI
;
338 sdecl::ServiceDecl
const updateDecl(
340 "com.sun.star.comp.deployment.ui.UpdateRequiredDialog",
341 "com.sun.star.deployment.ui.UpdateRequiredDialog" );
342 } // namespace dp_gui
346 void SAL_CALL
component_getImplementationEnvironment(
347 const sal_Char
** ppEnvTypeName
, uno_Environment
** )
349 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
352 sal_Bool SAL_CALL
component_writeInfo(
353 lang::XMultiServiceFactory
* pServiceManager
,
354 registry::XRegistryKey
* pRegistryKey
)
356 return component_writeInfoHelper(
357 pServiceManager
, pRegistryKey
, dp_gui::serviceDecl
, dp_gui::licenseDecl
, dp_gui::updateDecl
);
360 void * SAL_CALL
component_getFactory(
361 sal_Char
const * pImplName
,
362 lang::XMultiServiceFactory
* pServiceManager
,
363 registry::XRegistryKey
* pRegistryKey
)
365 return component_getFactoryHelper(
366 pImplName
, pServiceManager
, pRegistryKey
, dp_gui::serviceDecl
, dp_gui::licenseDecl
, dp_gui::updateDecl
);