Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index



 Hello,

 could somebody please review the attached patch? While digging for something 
else I noticed that --version doesn't work without $DISPLAY, recalled seeing 
a bugreport about that somewhere [*] and thought how hard that could be (oh, 
silly me). I swear this is the simplest and safest patch I've managed to come 
up with :-/, but since it still moves around initialization of some stuff, 
I'd like somebody else to check. Thanks.

[*] Speaking of the bugreport, does it ring a bell to somebody? I can't find 
it now.

-- 
 Lubos Lunak
 l.lunak@suse.cz
diff --git a/desktop/inc/app.hxx b/desktop/inc/app.hxx
index ee30123..14aff69 100644
--- a/desktop/inc/app.hxx
+++ b/desktop/inc/app.hxx
@@ -137,6 +137,10 @@ class Desktop : public Application
         void                    SetSplashScreenText( const ::rtl::OUString& rText );
         void                    SetSplashScreenProgress( sal_Int32 );
 
+#ifdef UNX
+        void EarlyCommandLineArgsPrepare();
+#endif
+
     private:
         // Bootstrap methods
         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > 
CreateApplicationServiceManager();
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 89c8e2a..d41df1c 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -671,14 +671,17 @@ void Desktop::Init()
     }
     
     // create service factory...
-    Reference < XMultiServiceFactory > rSMgr = CreateApplicationServiceManager();
-    if( rSMgr.is() )
+    if( !::comphelper::getProcessServiceFactory().is()) // may be set from 
Desktop::EarlyCommandLineArgsPrepare()
     {
-        ::comphelper::setProcessServiceFactory( rSMgr );
-    }
-    else
-    {
-        SetBootstrapError( BE_UNO_SERVICEMANAGER );
+        Reference < XMultiServiceFactory > rSMgr = CreateApplicationServiceManager();
+        if( rSMgr.is() )
+        {
+            ::comphelper::setProcessServiceFactory( rSMgr );
+        }
+        else
+        {
+            SetBootstrapError( BE_UNO_SERVICEMANAGER );
+        }
     }
 
     if ( GetBootstrapError() == BE_OK )
@@ -696,18 +699,6 @@ void Desktop::Init()
     if ( GetBootstrapError() == BE_OK )
     {
         CommandLineArgs* pCmdLineArgs = GetCommandLineArgs();
-#ifdef UNX
-    //  check whether we need to print cmdline help
-    if ( pCmdLineArgs->IsHelp() ) {
-        displayCmdlineHelp();
-        SetBootstrapStatus(BS_TERMINATE);
-    }
-    else if ( pCmdLineArgs->IsVersion() )
-    {
-        displayVersion();
-        SetBootstrapStatus(BS_TERMINATE);
-    }
-#endif
         // start ipc thread only for non-remote offices
         RTL_LOGFILE_CONTEXT( aLog2, "desktop (cd100003) ::OfficeIPCThread::EnableOfficeIPCThread" 
);
         OfficeIPCThread::Status aStatus = OfficeIPCThread::EnableOfficeIPCThread();
@@ -736,6 +727,19 @@ void Desktop::InitFinished()
     CloseSplashScreen();
 }
 
+#ifdef UNX
+// GetCommandLineArgs() requires this code to work, otherwise it will abort, and
+// on Unix command line args needs to be checked before Desktop::Init()
+void Desktop::EarlyCommandLineArgsPrepare()
+{
+    Reference < XMultiServiceFactory > rSMgr = CreateApplicationServiceManager();
+    if( rSMgr.is() )
+    {
+        ::comphelper::setProcessServiceFactory( rSMgr );
+    }
+}
+#endif
+
 void Desktop::DeInit()
 {
     RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::Desktop::DeInit" );
diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx
index 3d4a803..a975337 100644
--- a/desktop/source/app/sofficemain.cxx
+++ b/desktop/source/app/sofficemain.cxx
@@ -30,6 +30,8 @@
 #include "precompiled_desktop.hxx"
 
 #include "app.hxx"
+#include "cmdlineargs.hxx"
+#include "cmdlinehelp.hxx"
 
 #include <rtl/logfile.hxx>
 #include <tools/extendapplicationenvironment.hxx>
@@ -47,6 +49,21 @@ extern "C" int soffice_main()
     desktop::Desktop aDesktop;
     // This string is used during initialization of the Gtk+ VCL module
     aDesktop.SetAppName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("soffice")) );
+#ifdef UNX
+    // handle --version and --help already here, otherwise they would be handled
+    // after VCL initialization that might fail if $DISPLAY is not set
+    aDesktop.EarlyCommandLineArgsPrepare();
+    desktop::CommandLineArgs* pCmdLineArgs = aDesktop.GetCommandLineArgs();
+    if ( pCmdLineArgs->IsHelp() ) {
+        desktop::displayCmdlineHelp();
+        return EXIT_SUCCESS;
+    }
+    else if ( pCmdLineArgs->IsVersion() )
+    {
+        desktop::displayVersion();
+        return EXIT_SUCCESS;
+    }
+#endif
     return SVMain();
 }
 

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.