1*2722ceddSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2722ceddSAndrew Rist * distributed with this work for additional information 6*2722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2722ceddSAndrew Rist * "License"); you may not use this file except in compliance 9*2722ceddSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2722ceddSAndrew Rist * software distributed under the License is distributed on an 15*2722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2722ceddSAndrew Rist * KIND, either express or implied. See the License for the 17*2722ceddSAndrew Rist * specific language governing permissions and limitations 18*2722ceddSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2722ceddSAndrew Rist *************************************************************/ 21*2722ceddSAndrew Rist 22*2722ceddSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_desktop.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "dp_gui_shared.hxx" 28cdf0e10cSrcweir #include "dp_gui.h" 29cdf0e10cSrcweir #include "dp_gui_theextmgr.hxx" 30cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx" 31cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx" 32cdf0e10cSrcweir #include "unotools/configmgr.hxx" 33cdf0e10cSrcweir #include "comphelper/servicedecl.hxx" 34cdf0e10cSrcweir #include "comphelper/unwrapargs.hxx" 35cdf0e10cSrcweir #include <i18npool/mslangid.hxx> 36cdf0e10cSrcweir #include "vcl/svapp.hxx" 37cdf0e10cSrcweir #include "vcl/msgbox.hxx" 38cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp" 39cdf0e10cSrcweir #include "com/sun/star/task/XJobExecutor.hpp" 40cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include "boost/bind.hpp" 43cdf0e10cSrcweir #include "license_dialog.hxx" 44cdf0e10cSrcweir #include "dp_gui_dialog2.hxx" 45cdf0e10cSrcweir #include "dp_gui_extensioncmdqueue.hxx" 46cdf0e10cSrcweir 47cdf0e10cSrcweir using namespace ::dp_misc; 48cdf0e10cSrcweir using namespace ::com::sun::star; 49cdf0e10cSrcweir using namespace ::com::sun::star::uno; 50cdf0e10cSrcweir 51cdf0e10cSrcweir using ::rtl::OUString; 52cdf0e10cSrcweir 53cdf0e10cSrcweir namespace css = ::com::sun::star; 54cdf0e10cSrcweir namespace dp_gui { 55cdf0e10cSrcweir 56cdf0e10cSrcweir //============================================================================== 57cdf0e10cSrcweir class MyApp : public Application, private boost::noncopyable 58cdf0e10cSrcweir { 59cdf0e10cSrcweir public: 60cdf0e10cSrcweir MyApp(); 61cdf0e10cSrcweir virtual ~MyApp(); 62cdf0e10cSrcweir 63cdf0e10cSrcweir // Application 64cdf0e10cSrcweir virtual void Main(); 65cdf0e10cSrcweir }; 66cdf0e10cSrcweir 67cdf0e10cSrcweir //______________________________________________________________________________ 68cdf0e10cSrcweir MyApp::~MyApp() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir //______________________________________________________________________________ 73cdf0e10cSrcweir MyApp::MyApp() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir //______________________________________________________________________________ 78cdf0e10cSrcweir void MyApp::Main() 79cdf0e10cSrcweir { 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir //############################################################################## 83cdf0e10cSrcweir 84cdf0e10cSrcweir namespace 85cdf0e10cSrcweir { 86cdf0e10cSrcweir struct ProductName 87cdf0e10cSrcweir : public rtl::Static< String, ProductName > {}; 88cdf0e10cSrcweir struct Version 89cdf0e10cSrcweir : public rtl::Static< String, Version > {}; 90cdf0e10cSrcweir struct AboutBoxVersion 91cdf0e10cSrcweir : public rtl::Static< String, AboutBoxVersion > {}; 92cdf0e10cSrcweir struct OOOVendor 93cdf0e10cSrcweir : public rtl::Static< String, OOOVendor > {}; 94cdf0e10cSrcweir struct Extension 95cdf0e10cSrcweir : public rtl::Static< String, Extension > {}; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir void ReplaceProductNameHookProc( String& rStr ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir static int nAll = 0, nPro = 0; 101cdf0e10cSrcweir 102cdf0e10cSrcweir nAll++; 103cdf0e10cSrcweir if ( rStr.SearchAscii( "%PRODUCT" ) != STRING_NOTFOUND ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir String &rProductName = ProductName::get(); 106cdf0e10cSrcweir String &rVersion = Version::get(); 107cdf0e10cSrcweir String &rAboutBoxVersion = AboutBoxVersion::get(); 108cdf0e10cSrcweir String &rExtension = Extension::get(); 109cdf0e10cSrcweir String &rOOOVendor = OOOVendor::get(); 110cdf0e10cSrcweir 111cdf0e10cSrcweir if ( !rProductName.Len() ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir rtl::OUString aTmp; 114cdf0e10cSrcweir Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ); 115cdf0e10cSrcweir aRet >>= aTmp; 116cdf0e10cSrcweir rProductName = aTmp; 117cdf0e10cSrcweir 118cdf0e10cSrcweir aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTVERSION ); 119cdf0e10cSrcweir aRet >>= aTmp; 120cdf0e10cSrcweir rVersion = aTmp; 121cdf0e10cSrcweir 122cdf0e10cSrcweir aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::ABOUTBOXPRODUCTVERSION ); 123cdf0e10cSrcweir aRet >>= aTmp; 124cdf0e10cSrcweir rAboutBoxVersion = aTmp; 125cdf0e10cSrcweir 126cdf0e10cSrcweir aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::OOOVENDOR ); 127cdf0e10cSrcweir aRet >>= aTmp; 128cdf0e10cSrcweir rOOOVendor = aTmp; 129cdf0e10cSrcweir 130cdf0e10cSrcweir if ( !rExtension.Len() ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTEXTENSION ); 133cdf0e10cSrcweir aRet >>= aTmp; 134cdf0e10cSrcweir rExtension = aTmp; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir nPro++; 139cdf0e10cSrcweir rStr.SearchAndReplaceAllAscii( "%PRODUCTNAME", rProductName ); 140cdf0e10cSrcweir rStr.SearchAndReplaceAllAscii( "%PRODUCTVERSION", rVersion ); 141cdf0e10cSrcweir rStr.SearchAndReplaceAllAscii( "%ABOUTBOXPRODUCTVERSION", rAboutBoxVersion ); 142cdf0e10cSrcweir rStr.SearchAndReplaceAllAscii( "%OOOVENDOR", rOOOVendor ); 143cdf0e10cSrcweir rStr.SearchAndReplaceAllAscii( "%PRODUCTEXTENSION", rExtension ); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir //============================================================================== 148cdf0e10cSrcweir class ServiceImpl 149cdf0e10cSrcweir : public ::cppu::WeakImplHelper2<ui::dialogs::XAsynchronousExecutableDialog, 150cdf0e10cSrcweir task::XJobExecutor> 151cdf0e10cSrcweir { 152cdf0e10cSrcweir Reference<XComponentContext> const m_xComponentContext; 153cdf0e10cSrcweir boost::optional< Reference<awt::XWindow> > /* const */ m_parent; 154cdf0e10cSrcweir boost::optional<OUString> /* const */ m_view; 155cdf0e10cSrcweir /* if true then this service is running in an unopkg process and not in an office process */ 156cdf0e10cSrcweir boost::optional<sal_Bool> /* const */ m_unopkg; 157cdf0e10cSrcweir boost::optional<OUString> m_extensionURL; 158cdf0e10cSrcweir OUString m_initialTitle; 159cdf0e10cSrcweir bool m_bShowUpdateOnly; 160cdf0e10cSrcweir 161cdf0e10cSrcweir public: 162cdf0e10cSrcweir ServiceImpl( Sequence<Any> const & args, 163cdf0e10cSrcweir Reference<XComponentContext> const & xComponentContext ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir // XAsynchronousExecutableDialog 166cdf0e10cSrcweir virtual void SAL_CALL setDialogTitle( OUString const & aTitle ) 167cdf0e10cSrcweir throw (RuntimeException); 168cdf0e10cSrcweir virtual void SAL_CALL startExecuteModal( 169cdf0e10cSrcweir Reference< ui::dialogs::XDialogClosedListener > const & xListener ) 170cdf0e10cSrcweir throw (RuntimeException); 171cdf0e10cSrcweir 172cdf0e10cSrcweir // XJobExecutor 173cdf0e10cSrcweir virtual void SAL_CALL trigger( OUString const & event ) 174cdf0e10cSrcweir throw (RuntimeException); 175cdf0e10cSrcweir }; 176cdf0e10cSrcweir 177cdf0e10cSrcweir //______________________________________________________________________________ 178cdf0e10cSrcweir ServiceImpl::ServiceImpl( Sequence<Any> const& args, 179cdf0e10cSrcweir Reference<XComponentContext> const& xComponentContext) 180cdf0e10cSrcweir : m_xComponentContext(xComponentContext), 181cdf0e10cSrcweir m_bShowUpdateOnly( false ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir try { 184cdf0e10cSrcweir comphelper::unwrapArgs( args, m_parent, m_view, m_unopkg ); 185cdf0e10cSrcweir return; 186cdf0e10cSrcweir } catch (css::lang::IllegalArgumentException & ) { 187cdf0e10cSrcweir } 188cdf0e10cSrcweir try { 189cdf0e10cSrcweir comphelper::unwrapArgs( args, m_extensionURL); 190cdf0e10cSrcweir } catch (css::lang::IllegalArgumentException & ) { 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir ResHookProc pProc = ResMgr::GetReadStringHook(); 194cdf0e10cSrcweir if ( !pProc ) 195cdf0e10cSrcweir ResMgr::SetReadStringHook( ReplaceProductNameHookProc ); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir // XAsynchronousExecutableDialog 199cdf0e10cSrcweir //______________________________________________________________________________ 200cdf0e10cSrcweir void ServiceImpl::setDialogTitle( OUString const & title ) 201cdf0e10cSrcweir throw (RuntimeException) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir if ( dp_gui::TheExtensionManager::s_ExtMgr.is() ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir const ::vos::OGuard guard( Application::GetSolarMutex() ); 206cdf0e10cSrcweir ::rtl::Reference< ::dp_gui::TheExtensionManager > dialog( 207cdf0e10cSrcweir ::dp_gui::TheExtensionManager::get( m_xComponentContext, 208cdf0e10cSrcweir m_parent ? *m_parent : Reference<awt::XWindow>(), 209cdf0e10cSrcweir m_extensionURL ? *m_extensionURL : OUString() ) ); 210cdf0e10cSrcweir dialog->SetText( title ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir else 213cdf0e10cSrcweir m_initialTitle = title; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir //______________________________________________________________________________ 217cdf0e10cSrcweir void ServiceImpl::startExecuteModal( 218cdf0e10cSrcweir Reference< ui::dialogs::XDialogClosedListener > const & xListener ) 219cdf0e10cSrcweir throw (RuntimeException) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir bool bCloseDialog = true; // only used if m_bShowUpdateOnly is true 222cdf0e10cSrcweir ::std::auto_ptr<Application> app; 223cdf0e10cSrcweir //ToDo: synchronize access to s_dialog !!! 224cdf0e10cSrcweir if (! dp_gui::TheExtensionManager::s_ExtMgr.is()) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir const bool bAppUp = (GetpApp() != 0); 227cdf0e10cSrcweir bool bOfficePipePresent; 228cdf0e10cSrcweir try { 229cdf0e10cSrcweir bOfficePipePresent = dp_misc::office_is_running(); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir catch (Exception & exc) { 232cdf0e10cSrcweir if (bAppUp) { 233cdf0e10cSrcweir const vos::OGuard guard( Application::GetSolarMutex() ); 234cdf0e10cSrcweir std::auto_ptr<ErrorBox> box( 235cdf0e10cSrcweir new ErrorBox( Application::GetActiveTopWindow(), 236cdf0e10cSrcweir WB_OK, exc.Message ) ); 237cdf0e10cSrcweir box->Execute(); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir throw; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir if (! bOfficePipePresent) { 243cdf0e10cSrcweir OSL_ASSERT( ! bAppUp ); 244cdf0e10cSrcweir app.reset( new MyApp ); 245cdf0e10cSrcweir if (! InitVCL( Reference<lang::XMultiServiceFactory>( 246cdf0e10cSrcweir m_xComponentContext->getServiceManager(), 247cdf0e10cSrcweir UNO_QUERY_THROW ) )) 248cdf0e10cSrcweir throw RuntimeException( OUSTR("Cannot initialize VCL!"), 249cdf0e10cSrcweir static_cast<OWeakObject *>(this) ); 250cdf0e10cSrcweir AllSettings as = app->GetSettings(); 251cdf0e10cSrcweir OUString slang; 252cdf0e10cSrcweir if (! (::utl::ConfigManager::GetDirectConfigProperty( 253cdf0e10cSrcweir ::utl::ConfigManager::LOCALE ) >>= slang)) 254cdf0e10cSrcweir throw RuntimeException( OUSTR("Cannot determine language!"), 255cdf0e10cSrcweir static_cast<OWeakObject *>(this) ); 256cdf0e10cSrcweir as.SetUILanguage( MsLangId::convertIsoStringToLanguage( slang ) ); 257cdf0e10cSrcweir app->SetSettings( as ); 258cdf0e10cSrcweir String sTitle = ::utl::ConfigManager::GetDirectConfigProperty( 259cdf0e10cSrcweir ::utl::ConfigManager::PRODUCTNAME).get<OUString>() 260cdf0e10cSrcweir + String(static_cast<sal_Unicode>(' ')) 261cdf0e10cSrcweir + ::utl::ConfigManager::GetDirectConfigProperty( 262cdf0e10cSrcweir ::utl::ConfigManager::PRODUCTVERSION).get<OUString>(); 263cdf0e10cSrcweir app->SetDisplayName(sTitle); 264cdf0e10cSrcweir ExtensionCmdQueue::syncRepositories( m_xComponentContext ); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir } 267cdf0e10cSrcweir else 268cdf0e10cSrcweir { 269cdf0e10cSrcweir // When m_bShowUpdateOnly is set, we are inside the office and the user clicked 270cdf0e10cSrcweir // the update notification icon in the menu bar. We must not close the extensions 271cdf0e10cSrcweir // dialog after displaying the update dialog when it has been visible before 272cdf0e10cSrcweir if ( m_bShowUpdateOnly ) 273cdf0e10cSrcweir bCloseDialog = ! dp_gui::TheExtensionManager::s_ExtMgr->isVisible(); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir { 277cdf0e10cSrcweir const ::vos::OGuard guard( Application::GetSolarMutex() ); 278cdf0e10cSrcweir ::rtl::Reference< ::dp_gui::TheExtensionManager > myExtMgr( 279cdf0e10cSrcweir ::dp_gui::TheExtensionManager::get( 280cdf0e10cSrcweir m_xComponentContext, 281cdf0e10cSrcweir m_parent ? *m_parent : Reference<awt::XWindow>(), 282cdf0e10cSrcweir m_extensionURL ? *m_extensionURL : OUString() ) ); 283cdf0e10cSrcweir myExtMgr->createDialog( false ); 284cdf0e10cSrcweir if (m_initialTitle.getLength() > 0) { 285cdf0e10cSrcweir myExtMgr->SetText( m_initialTitle ); 286cdf0e10cSrcweir m_initialTitle = OUString(); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir if ( m_bShowUpdateOnly ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir myExtMgr->checkUpdates( true, !bCloseDialog ); 291cdf0e10cSrcweir if ( bCloseDialog ) 292cdf0e10cSrcweir myExtMgr->Close(); 293cdf0e10cSrcweir else 294cdf0e10cSrcweir myExtMgr->ToTop( TOTOP_RESTOREWHENMIN ); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir else 297cdf0e10cSrcweir { 298cdf0e10cSrcweir myExtMgr->Show(); 299cdf0e10cSrcweir myExtMgr->ToTop( TOTOP_RESTOREWHENMIN ); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir if (app.get() != 0) { 304cdf0e10cSrcweir Application::Execute(); 305cdf0e10cSrcweir DeInitVCL(); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir if (xListener.is()) 309cdf0e10cSrcweir xListener->dialogClosed( 310cdf0e10cSrcweir ui::dialogs::DialogClosedEvent( 311cdf0e10cSrcweir static_cast< ::cppu::OWeakObject * >(this), 312cdf0e10cSrcweir sal_Int16(0)) ); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir // XJobExecutor 316cdf0e10cSrcweir //______________________________________________________________________________ 317cdf0e10cSrcweir void ServiceImpl::trigger( OUString const &rEvent ) throw (RuntimeException) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir if ( rEvent == OUSTR("SHOW_UPDATE_DIALOG") ) 320cdf0e10cSrcweir m_bShowUpdateOnly = true; 321cdf0e10cSrcweir else 322cdf0e10cSrcweir m_bShowUpdateOnly = false; 323cdf0e10cSrcweir 324cdf0e10cSrcweir startExecuteModal( Reference< ui::dialogs::XDialogClosedListener >() ); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir namespace sdecl = comphelper::service_decl; 328cdf0e10cSrcweir sdecl::class_<ServiceImpl, sdecl::with_args<true> > serviceSI; 329cdf0e10cSrcweir sdecl::ServiceDecl const serviceDecl( 330cdf0e10cSrcweir serviceSI, 331cdf0e10cSrcweir "com.sun.star.comp.deployment.ui.PackageManagerDialog", 332cdf0e10cSrcweir "com.sun.star.deployment.ui.PackageManagerDialog" ); 333cdf0e10cSrcweir 334cdf0e10cSrcweir sdecl::class_<LicenseDialog, sdecl::with_args<true> > licenseSI; 335cdf0e10cSrcweir sdecl::ServiceDecl const licenseDecl( 336cdf0e10cSrcweir licenseSI, 337cdf0e10cSrcweir "com.sun.star.comp.deployment.ui.LicenseDialog", 338cdf0e10cSrcweir "com.sun.star.deployment.ui.LicenseDialog" ); 339cdf0e10cSrcweir 340cdf0e10cSrcweir sdecl::class_<UpdateRequiredDialogService, sdecl::with_args<true> > updateSI; 341cdf0e10cSrcweir sdecl::ServiceDecl const updateDecl( 342cdf0e10cSrcweir updateSI, 343cdf0e10cSrcweir "com.sun.star.comp.deployment.ui.UpdateRequiredDialog", 344cdf0e10cSrcweir "com.sun.star.deployment.ui.UpdateRequiredDialog" ); 345cdf0e10cSrcweir } // namespace dp_gui 346cdf0e10cSrcweir 347cdf0e10cSrcweir extern "C" { 348cdf0e10cSrcweir 349cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( 350cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** ) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir void * SAL_CALL component_getFactory( 356cdf0e10cSrcweir sal_Char const * pImplName, 357cdf0e10cSrcweir lang::XMultiServiceFactory * pServiceManager, 358cdf0e10cSrcweir registry::XRegistryKey * pRegistryKey ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir return component_getFactoryHelper( 361cdf0e10cSrcweir pImplName, pServiceManager, pRegistryKey, dp_gui::serviceDecl, dp_gui::licenseDecl, dp_gui::updateDecl ); 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir } // extern "C" 365