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