[Libreoffice-commits] core.git: sfx2/source

Olivier Hallot olivier.hallot at libreoffice.org
Tue Apr 17 09:59:14 UTC 2018


 sfx2/source/appl/sfxhelp.cxx |   99 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 92 insertions(+), 7 deletions(-)

New commits:
commit cdbb14cedb7d07aec0dda47fbb5ab65a02fb0cf6
Author: Olivier Hallot <olivier.hallot at libreoffice.org>
Date:   Tue Apr 10 22:50:31 2018 -0300

    Enable new Help to be installed as extension
    
    This patch enables the new help to be installed as an extension
    
    The extension must match the locale and LibreOffice version
    
    Extension id must be <locale>.help.libreoffice.org
    Version must match product version
    
    Help extension can be packed as Uno package from new help
    offline build (--with-help=html)
    
    To test the patch, use the en-US help in uno package format available in
    
    https://helponline.libreoffice.org/Help_en-US_6.1.oxt
    
    (To make it distinct from other help installations, the headings paragraphs
    are in red.)
    
    Change-Id: I2ff9eb94ef932c29ff7a93ce0241837213b25f2f
    Reviewed-on: https://gerrit.libreoffice.org/52700
    Reviewed-by: Olivier Hallot <olivier.hallot at libreoffice.org>
    Tested-by: Olivier Hallot <olivier.hallot at libreoffice.org>

diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
index 43606ae0183e..d0cc5248264b 100644
--- a/sfx2/source/appl/sfxhelp.cxx
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -39,6 +39,7 @@
 #include <com/sun/star/frame/ModuleManager.hpp>
 #include <com/sun/star/system/SystemShellExecute.hpp>
 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
+#include <com/sun/star/deployment/PackageInformationProvider.hpp>
 #include <unotools/configmgr.hxx>
 #include <unotools/configitem.hxx>
 #include <svtools/helpopt.hxx>
@@ -82,6 +83,10 @@ using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::util;
 using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::system;
+using ::com::sun::star::deployment::PackageInformationProvider;
+using ::com::sun::star::deployment::XPackageInformationProvider;
+
+namespace uno = css::uno ;
 
 class NoHelpErrorBox
 {
@@ -200,6 +205,78 @@ bool impl_hasHTMLHelpInstalled()
     return bOK;
 }
 
+// Root path of the HTML help extension
+OUString getExtensionHTMLHelpRootURL()
+{
+    static OUString s_instURL;
+    if (!s_instURL.isEmpty())
+        return s_instURL;
+
+    static OUString aLocaleStr;
+
+    if (aLocaleStr.isEmpty())
+    {
+        // detect installed locale
+        aLocaleStr = HelpLocaleString();
+    }
+
+    Reference< XComponentContext > m_xContext( comphelper::getProcessComponentContext() );
+    const Reference< XPackageInformationProvider > xPackageInfo = PackageInformationProvider::get(m_xContext);
+
+    s_instURL = xPackageInfo->getPackageLocation(aLocaleStr + ".help.libreoffice.org");
+
+    return s_instURL;
+}
+
+/// Check if HTML help extension is installed
+/// verify extension installed and correct version
+bool impl_hasHTMLHelpExtensionInstalled()
+{
+    if (comphelper::LibreOfficeKit::isActive())
+        return false;
+
+    static OUString aLocaleStr;
+    static OUString aRootURL;
+    static OUString aVersion;
+
+    if (aLocaleStr.isEmpty())
+    {
+        // detect installed locale
+        aLocaleStr = HelpLocaleString();
+    }
+
+    OUString aIdentifier(aLocaleStr + ".help.libreoffice.org");
+
+    if (aRootURL.isEmpty())
+    {
+        Reference< XComponentContext > m_xContext( comphelper::getProcessComponentContext() );
+        const Reference< XPackageInformationProvider > xPackageInfo = PackageInformationProvider::get(m_xContext);
+        aRootURL = xPackageInfo->getPackageLocation(aIdentifier);
+        if(aRootURL.isEmpty())
+        {
+            return false;
+        }
+        uno::Sequence< uno::Sequence< OUString > > aExtensionList (xPackageInfo->getExtensionList());
+
+        if(aExtensionList.hasElements())
+        {
+            for (long i = aExtensionList.getLength() - 1; i >= 0; i--)
+            {
+                SAL_INFO("sfx.appl", aExtensionList[i][0] + " - " + aExtensionList[i][1]) ;
+                if (aExtensionList[i][0] == aIdentifier)
+                {
+                    aVersion = aExtensionList[i][1];
+                    break;
+                }
+            }
+        }
+    }
+
+    bool bOK(!aRootURL.isEmpty() && (aVersion.startsWith(utl::ConfigManager::getProductVersion())));
+
+    return bOK;
+}
+
 } // namespace
 
 /// Return the locale we prefer for displaying help
@@ -690,12 +767,12 @@ static bool impl_showOnlineHelp( const OUString& rURL )
 #define SHTML3 "\"><script type=\"text/javascript\"> window.location.href = \""
 #define SHTML4 "\";</script><title>Help Page Redirection</title></head><body></body></html>"
 
-static bool impl_showOfflineHelp( const OUString& rURL )
+
+static bool impl_showOfflineHelp( const OUString& rURL, const OUString& rBaseInstallPath)
 {
-    OUString aBaseInstallPath = getHelpRootURL();
     OUString const aInternal( "vnd.sun.star.help://"  );
 
-    OUString aHelpLink( aBaseInstallPath + "/index.html?" );
+    OUString aHelpLink( rBaseInstallPath + "/index.html?" );
     aHelpLink += rURL.copy( aInternal.getLength() );
     aHelpLink = aHelpLink.replaceAll("%2F","/").replaceAll("%3A",":");
 
@@ -813,10 +890,14 @@ bool SfxHelp::Start_Impl(const OUString& rURL, const vcl::Window* pWindow, const
         impl_showOnlineHelp( aHelpURL );
         return true;
     }
-
+    if ( impl_hasHTMLHelpExtensionInstalled() )
+    {
+        impl_showOfflineHelp( aHelpURL, getExtensionHTMLHelpRootURL() );
+        return true;
+    }
     if ( impl_hasHTMLHelpInstalled() )
     {
-        impl_showOfflineHelp(aHelpURL);
+        impl_showOfflineHelp(aHelpURL, getHelpRootURL());
         return true;
     }
 
@@ -957,12 +1038,16 @@ bool SfxHelp::Start_Impl(const OUString& rURL, weld::Widget* pWidget, const OUSt
         return true;
     }
 
+    if ( impl_hasHTMLHelpExtensionInstalled() )
+    {
+        impl_showOfflineHelp( aHelpURL, getExtensionHTMLHelpRootURL() );
+        return true;
+    }
     if ( impl_hasHTMLHelpInstalled() )
     {
-        impl_showOfflineHelp(aHelpURL);
+        impl_showOfflineHelp(aHelpURL, getHelpRootURL());
         return true;
     }
-
     if ( !impl_hasHelpInstalled() )
     {
         std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pWidget, "sfx/ui/helpmanual.ui"));


More information about the Libreoffice-commits mailing list