LCOV - code coverage report
Current view: top level - desktop/source/deployment/gui - dp_gui_service.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 112 0.0 %
Date: 2012-08-25 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      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.
      15                 :            :  *
      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).
      21                 :            :  *
      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.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "dp_gui_shared.hxx"
      31                 :            : #include "dp_gui.h"
      32                 :            : #include "dp_gui_theextmgr.hxx"
      33                 :            : #include "cppuhelper/implbase2.hxx"
      34                 :            : #include "cppuhelper/implementationentry.hxx"
      35                 :            : #include "unotools/configmgr.hxx"
      36                 :            : #include "comphelper/servicedecl.hxx"
      37                 :            : #include "comphelper/unwrapargs.hxx"
      38                 :            : #include <i18npool/mslangid.hxx>
      39                 :            : #include "vcl/svapp.hxx"
      40                 :            : #include "vcl/msgbox.hxx"
      41                 :            : #include "com/sun/star/lang/XServiceInfo.hpp"
      42                 :            : #include "com/sun/star/task/XJobExecutor.hpp"
      43                 :            : #include "com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp"
      44                 :            : 
      45                 :            : #include <boost/optional.hpp>
      46                 :            : #include <boost/utility.hpp>
      47                 :            : #include "license_dialog.hxx"
      48                 :            : #include "dp_gui_dialog2.hxx"
      49                 :            : #include "dp_gui_extensioncmdqueue.hxx"
      50                 :            : 
      51                 :            : using namespace ::dp_misc;
      52                 :            : using namespace ::com::sun::star;
      53                 :            : using namespace ::com::sun::star::uno;
      54                 :            : 
      55                 :            : using ::rtl::OUString;
      56                 :            : 
      57                 :            : namespace css = ::com::sun::star;
      58                 :            : namespace dp_gui {
      59                 :            : 
      60                 :            : //==============================================================================
      61                 :            : class MyApp : public Application, private boost::noncopyable
      62                 :            : {
      63                 :            : public:
      64                 :            :     MyApp();
      65                 :            :     virtual ~MyApp();
      66                 :            : 
      67                 :            :     // Application
      68                 :            :     virtual int Main();
      69                 :            : };
      70                 :            : 
      71                 :            : //______________________________________________________________________________
      72                 :          0 : MyApp::~MyApp()
      73                 :            : {
      74                 :          0 : }
      75                 :            : 
      76                 :            : //______________________________________________________________________________
      77                 :          0 : MyApp::MyApp()
      78                 :            : {
      79                 :          0 : }
      80                 :            : 
      81                 :            : //______________________________________________________________________________
      82                 :          0 : int MyApp::Main()
      83                 :            : {
      84                 :          0 :     return EXIT_SUCCESS;
      85                 :            : }
      86                 :            : 
      87                 :            : 
      88                 :            : namespace
      89                 :            : {
      90                 :            :     struct ProductName
      91                 :            :         : public rtl::Static< String, ProductName > {};
      92                 :            :     struct Version
      93                 :            :         : public rtl::Static< String, Version > {};
      94                 :            :     struct AboutBoxVersion
      95                 :            :         : public rtl::Static< String, AboutBoxVersion > {};
      96                 :            :     struct AboutBoxVersionSuffix
      97                 :            :         : public rtl::Static< String, AboutBoxVersionSuffix > {};
      98                 :            :     struct OOOVendor
      99                 :            :         : public rtl::Static< String, OOOVendor > {};
     100                 :            :     struct Extension
     101                 :            :         : public rtl::Static< String, Extension > {};
     102                 :            : }
     103                 :            : 
     104                 :          0 : rtl::OUString ReplaceProductNameHookProc( const rtl::OUString& rStr )
     105                 :            : {
     106                 :          0 :     if (rStr.indexOf( "%PRODUCT" ) == -1)
     107                 :          0 :         return rStr;
     108                 :            : 
     109                 :          0 :     rtl::OUString sProductName = ProductName::get();
     110                 :          0 :     rtl::OUString sVersion = Version::get();
     111                 :          0 :     rtl::OUString sAboutBoxVersion = AboutBoxVersion::get();
     112                 :          0 :     rtl::OUString sAboutBoxVersionSuffix = AboutBoxVersionSuffix::get();
     113                 :          0 :     rtl::OUString sExtension = Extension::get();
     114                 :          0 :     rtl::OUString sOOOVendor = OOOVendor::get();
     115                 :            : 
     116                 :          0 :     if ( sProductName.isEmpty() )
     117                 :            :     {
     118                 :          0 :         sProductName = utl::ConfigManager::getProductName();
     119                 :          0 :         sVersion = utl::ConfigManager::getProductVersion();
     120                 :          0 :         sAboutBoxVersion = utl::ConfigManager::getAboutBoxProductVersion();
     121                 :          0 :         sAboutBoxVersionSuffix = utl::ConfigManager::getAboutBoxProductVersionSuffix();
     122                 :          0 :         sOOOVendor = utl::ConfigManager::getVendor();
     123                 :          0 :         if ( sExtension.isEmpty() )
     124                 :            :         {
     125                 :          0 :             sExtension = utl::ConfigManager::getProductExtension();
     126                 :            :         }
     127                 :            :     }
     128                 :            : 
     129                 :          0 :     rtl::OUString sRet = rStr.replaceAll( "%PRODUCTNAME", sProductName );
     130                 :          0 :     sRet = sRet.replaceAll( "%PRODUCTVERSION", sVersion );
     131                 :          0 :     sRet = sRet.replaceAll( "%ABOUTBOXPRODUCTVERSIONSUFFIX", sAboutBoxVersionSuffix );
     132                 :          0 :     sRet = sRet.replaceAll( "%ABOUTBOXPRODUCTVERSION", sAboutBoxVersion );
     133                 :          0 :     sRet = sRet.replaceAll( "%OOOVENDOR", sOOOVendor );
     134                 :          0 :     sRet = sRet.replaceAll( "%PRODUCTEXTENSION", sExtension );
     135                 :          0 :     return sRet;
     136                 :            : }
     137                 :            : 
     138                 :            : //==============================================================================
     139                 :          0 : class ServiceImpl
     140                 :            :     : public ::cppu::WeakImplHelper2<ui::dialogs::XAsynchronousExecutableDialog,
     141                 :            :                                      task::XJobExecutor>
     142                 :            : {
     143                 :            :     Reference<XComponentContext> const m_xComponentContext;
     144                 :            :     boost::optional< Reference<awt::XWindow> > /* const */ m_parent;
     145                 :            :     boost::optional<OUString> /* const */ m_view;
     146                 :            :     /* if true then this service is running in an unopkg process and not in an office process */
     147                 :            :     boost::optional<sal_Bool> /* const */ m_unopkg;
     148                 :            :     boost::optional<OUString> m_extensionURL;
     149                 :            :     OUString m_initialTitle;
     150                 :            :     bool m_bShowUpdateOnly;
     151                 :            : 
     152                 :            : public:
     153                 :            :     ServiceImpl( Sequence<Any> const & args,
     154                 :            :                  Reference<XComponentContext> const & xComponentContext );
     155                 :            : 
     156                 :            :     // XAsynchronousExecutableDialog
     157                 :            :     virtual void SAL_CALL setDialogTitle( OUString const & aTitle )
     158                 :            :         throw (RuntimeException);
     159                 :            :     virtual void SAL_CALL startExecuteModal(
     160                 :            :         Reference< ui::dialogs::XDialogClosedListener > const & xListener )
     161                 :            :         throw (RuntimeException);
     162                 :            : 
     163                 :            :     // XJobExecutor
     164                 :            :     virtual void SAL_CALL trigger( OUString const & event )
     165                 :            :         throw (RuntimeException);
     166                 :            : };
     167                 :            : 
     168                 :            : //______________________________________________________________________________
     169                 :          0 : ServiceImpl::ServiceImpl( Sequence<Any> const& args,
     170                 :            :                           Reference<XComponentContext> const& xComponentContext)
     171                 :            :     : m_xComponentContext(xComponentContext),
     172                 :          0 :       m_bShowUpdateOnly( false )
     173                 :            : {
     174                 :            :     try {
     175                 :          0 :         comphelper::unwrapArgs( args, m_parent, m_view, m_unopkg );
     176                 :          0 :         return;
     177                 :          0 :     } catch ( const css::lang::IllegalArgumentException & ) {
     178                 :            :     }
     179                 :            :     try {
     180                 :          0 :         comphelper::unwrapArgs( args, m_extensionURL);
     181                 :          0 :     } catch ( const css::lang::IllegalArgumentException & ) {
     182                 :            :     }
     183                 :            : 
     184                 :          0 :     ResHookProc pProc = ResMgr::GetReadStringHook();
     185                 :          0 :     if ( !pProc )
     186                 :          0 :         ResMgr::SetReadStringHook( ReplaceProductNameHookProc );
     187                 :            : }
     188                 :            : 
     189                 :            : // XAsynchronousExecutableDialog
     190                 :            : //______________________________________________________________________________
     191                 :          0 : void ServiceImpl::setDialogTitle( OUString const & title )
     192                 :            :     throw (RuntimeException)
     193                 :            : {
     194                 :          0 :     if ( dp_gui::TheExtensionManager::s_ExtMgr.is() )
     195                 :            :     {
     196                 :          0 :         const SolarMutexGuard guard;
     197                 :            :         ::rtl::Reference< ::dp_gui::TheExtensionManager > dialog(
     198                 :            :             ::dp_gui::TheExtensionManager::get( m_xComponentContext,
     199                 :          0 :                                                 m_parent ? *m_parent : Reference<awt::XWindow>(),
     200                 :          0 :                                                 m_extensionURL ? *m_extensionURL : OUString() ) );
     201                 :          0 :         dialog->SetText( title );
     202                 :            :     }
     203                 :            :     else
     204                 :          0 :         m_initialTitle = title;
     205                 :          0 : }
     206                 :            : 
     207                 :            : //______________________________________________________________________________
     208                 :          0 : void ServiceImpl::startExecuteModal(
     209                 :            :     Reference< ui::dialogs::XDialogClosedListener > const & xListener )
     210                 :            :     throw (RuntimeException)
     211                 :            : {
     212                 :          0 :     bool bCloseDialog = true;  // only used if m_bShowUpdateOnly is true
     213                 :          0 :     ::std::auto_ptr<Application> app;
     214                 :            :     //ToDo: synchronize access to s_dialog !!!
     215                 :          0 :     if (! dp_gui::TheExtensionManager::s_ExtMgr.is())
     216                 :            :     {
     217                 :          0 :         const bool bAppUp = (GetpApp() != 0);
     218                 :            :         bool bOfficePipePresent;
     219                 :            :         try {
     220                 :          0 :             bOfficePipePresent = dp_misc::office_is_running();
     221                 :            :         }
     222                 :          0 :         catch (const Exception & exc) {
     223                 :          0 :             if (bAppUp) {
     224                 :          0 :                 const SolarMutexGuard guard;
     225                 :            :                 std::auto_ptr<ErrorBox> box(
     226                 :            :                     new ErrorBox( Application::GetActiveTopWindow(),
     227                 :          0 :                                   WB_OK, exc.Message ) );
     228                 :          0 :                 box->Execute();
     229                 :            :             }
     230                 :          0 :             throw;
     231                 :            :         }
     232                 :            : 
     233                 :          0 :         if (! bOfficePipePresent) {
     234                 :            :             OSL_ASSERT( ! bAppUp );
     235                 :          0 :             app.reset( new MyApp );
     236                 :          0 :             if (! InitVCL( Reference<lang::XMultiServiceFactory>(
     237                 :          0 :                                m_xComponentContext->getServiceManager(),
     238                 :          0 :                                UNO_QUERY_THROW ) ))
     239                 :            :                 throw RuntimeException( OUSTR("Cannot initialize VCL!"),
     240                 :          0 :                                         static_cast<OWeakObject *>(this) );
     241                 :          0 :             AllSettings as = app->GetSettings();
     242                 :            :             as.SetUILanguage(
     243                 :            :                 MsLangId::convertIsoStringToLanguage(
     244                 :          0 :                     utl::ConfigManager::getLocale() ) );
     245                 :          0 :             app->SetSettings( as );
     246                 :          0 :             app->SetDisplayName(
     247                 :            :                 utl::ConfigManager::getProductName() +
     248                 :            :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")) +
     249                 :          0 :                 utl::ConfigManager::getProductVersion());
     250                 :          0 :             ExtensionCmdQueue::syncRepositories( m_xComponentContext );
     251                 :            :         }
     252                 :            :     }
     253                 :            :     else
     254                 :            :     {
     255                 :            :         // When m_bShowUpdateOnly is set, we are inside the office and the user clicked
     256                 :            :         // the update notification icon in the menu bar. We must not close the extensions
     257                 :            :         // dialog after displaying the update dialog when it has been visible before
     258                 :          0 :         if ( m_bShowUpdateOnly )
     259                 :          0 :             bCloseDialog = ! dp_gui::TheExtensionManager::s_ExtMgr->isVisible();
     260                 :            :     }
     261                 :            : 
     262                 :            :     {
     263                 :          0 :         const SolarMutexGuard guard;
     264                 :            :         ::rtl::Reference< ::dp_gui::TheExtensionManager > myExtMgr(
     265                 :            :             ::dp_gui::TheExtensionManager::get(
     266                 :            :                 m_xComponentContext,
     267                 :          0 :                 m_parent ? *m_parent : Reference<awt::XWindow>(),
     268                 :          0 :                 m_extensionURL ? *m_extensionURL : OUString() ) );
     269                 :          0 :         myExtMgr->createDialog( false );
     270                 :          0 :         if (!m_initialTitle.isEmpty()) {
     271                 :          0 :             myExtMgr->SetText( m_initialTitle );
     272                 :          0 :             m_initialTitle = OUString();
     273                 :            :         }
     274                 :          0 :         if ( m_bShowUpdateOnly )
     275                 :            :         {
     276                 :          0 :             myExtMgr->checkUpdates( true, !bCloseDialog );
     277                 :          0 :             if ( bCloseDialog )
     278                 :          0 :                 myExtMgr->Close();
     279                 :            :             else
     280                 :          0 :                 myExtMgr->ToTop( TOTOP_RESTOREWHENMIN );
     281                 :            :         }
     282                 :            :         else
     283                 :            :         {
     284                 :          0 :             myExtMgr->Show();
     285                 :          0 :             myExtMgr->ToTop( TOTOP_RESTOREWHENMIN );
     286                 :          0 :         }
     287                 :            :     }
     288                 :            : 
     289                 :          0 :     if (app.get() != 0) {
     290                 :          0 :         Application::Execute();
     291                 :          0 :         DeInitVCL();
     292                 :            :     }
     293                 :            : 
     294                 :          0 :     if (xListener.is())
     295                 :          0 :         xListener->dialogClosed(
     296                 :            :             ui::dialogs::DialogClosedEvent(
     297                 :            :                 static_cast< ::cppu::OWeakObject * >(this),
     298                 :          0 :                 sal_Int16(0)) );
     299                 :          0 : }
     300                 :            : 
     301                 :            : // XJobExecutor
     302                 :            : //______________________________________________________________________________
     303                 :          0 : void ServiceImpl::trigger( OUString const &rEvent ) throw (RuntimeException)
     304                 :            : {
     305                 :          0 :     if ( rEvent == OUSTR("SHOW_UPDATE_DIALOG") )
     306                 :          0 :         m_bShowUpdateOnly = true;
     307                 :            :     else
     308                 :          0 :         m_bShowUpdateOnly = false;
     309                 :            : 
     310                 :          0 :     startExecuteModal( Reference< ui::dialogs::XDialogClosedListener >() );
     311                 :          0 : }
     312                 :            : 
     313                 :            : namespace sdecl = comphelper::service_decl;
     314                 :          0 : sdecl::class_<ServiceImpl, sdecl::with_args<true> > serviceSI;
     315                 :          0 : sdecl::ServiceDecl const serviceDecl(
     316                 :            :     serviceSI,
     317                 :            :     "com.sun.star.comp.deployment.ui.PackageManagerDialog",
     318                 :            :     "com.sun.star.deployment.ui.PackageManagerDialog" );
     319                 :            : 
     320                 :          0 : sdecl::class_<LicenseDialog, sdecl::with_args<true> > licenseSI;
     321                 :          0 : sdecl::ServiceDecl const licenseDecl(
     322                 :            :     licenseSI,
     323                 :            :     "com.sun.star.comp.deployment.ui.LicenseDialog",
     324                 :            :     "com.sun.star.deployment.ui.LicenseDialog" );
     325                 :            : 
     326                 :          0 : sdecl::class_<UpdateRequiredDialogService, sdecl::with_args<true> > updateSI;
     327                 :          0 : sdecl::ServiceDecl const updateDecl(
     328                 :            :     updateSI,
     329                 :            :     "com.sun.star.comp.deployment.ui.UpdateRequiredDialog",
     330                 :            :     "com.sun.star.deployment.ui.UpdateRequiredDialog" );
     331                 :            : } // namespace dp_gui
     332                 :            : 
     333                 :            : extern "C" {
     334                 :            : 
     335                 :          0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL deploymentgui_component_getFactory(
     336                 :            :     sal_Char const * pImplName,
     337                 :            :     lang::XMultiServiceFactory * pServiceManager,
     338                 :            :     registry::XRegistryKey * pRegistryKey )
     339                 :            : {
     340                 :            :     return component_getFactoryHelper(
     341                 :          0 :         pImplName, pServiceManager, pRegistryKey, dp_gui::serviceDecl, dp_gui::licenseDecl, dp_gui::updateDecl );
     342                 :            : }
     343                 :            : 
     344                 :          0 : } // extern "C"
     345                 :            : 
     346                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10