shell/source/backends/kde5be/kde5backend.cxx |   56 ++++++++++++++++++++-------
 1 file changed, 42 insertions(+), 14 deletions(-)

New commits:
commit 5a64bc2b1214e6ad8424f57576aa5752a09815d4
Author:     Katarina Behrens <katarina.behr...@cib.de>
AuthorDate: Tue Apr 16 09:47:31 2019 +0200
Commit:     Thorsten Behrens <thorsten.behr...@cib.de>
CommitDate: Wed Apr 17 17:37:52 2019 +0200

    Stop qt event loop after KDE settings have been read
    
    Two use-cases here in kde5backend
    1) kde or qt vclplug has already started qt event loop => just use this
    loop to read KDE settings
    2) no qt event loop runs (we're most likely in gtk3_kde5 vclplug) =>
    start a new event loop, read the settings and stop it
    
    In case 2) letting qt event loop run means subsequently all UI ops
    need to happen in main thread. This is problematic to enforce in
    non-qt-based vclplugs
    
    In both cases, cache those settings for future use - the assumption is,
    most of them are static during a session anyway.
    
    Change-Id: Ifa203f4cdb9a753db808f945762fb131ee83393c
    Reviewed-on: https://gerrit.libreoffice.org/70808
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de>

diff --git a/shell/source/backends/kde5be/kde5backend.cxx 
b/shell/source/backends/kde5be/kde5backend.cxx
index e2f6e25c0764..101a21387a4c 100644
--- a/shell/source/backends/kde5be/kde5backend.cxx
+++ b/shell/source/backends/kde5be/kde5backend.cxx
@@ -120,7 +120,7 @@ private:
     {
     }
 
-    bool enabled_;
+    std::map<OUString, css::beans::Optional<css::uno::Any>> m_KDESettings;
 };
 
 OString getDisplayArg()
@@ -148,10 +148,28 @@ OString getExecutable()
     return OUStringToOString(aBin, osl_getThreadTextEncoding());
 }
 
+void readKDESettings(std::map<OUString, css::beans::Optional<css::uno::Any>>& 
rSettings)
+{
+    const std::vector<OUString> aKeys
+        = { "EnableATToolSupport",  "ExternalMailer",       
"SourceViewFontHeight",
+            "SourceViewFontName",   "WorkPathVariable",     
"ooInetFTPProxyName",
+            "ooInetFTPProxyPort",   "ooInetHTTPProxyName",  
"ooInetHTTPProxyPort",
+            "ooInetHTTPSProxyName", "ooInetHTTPSProxyPort", "ooInetNoProxy",
+            "ooInetProxyType" };
+
+    for (const OUString& aKey : aKeys)
+    {
+        css::beans::Optional<css::uno::Any> aValue = 
kde5access::getValue(aKey);
+        std::pair<OUString, css::beans::Optional<css::uno::Any>> elem
+            = std::make_pair(aKey, aValue);
+        rSettings.insert(elem);
+    }
+}
+
 // init the QApplication when we load the kde5backend into a non-Qt vclplug 
(e.g. Gtk3KDE5)
 // TODO: use a helper process to read these values without linking to Qt 
directly?
 // TODO: share this code somehow with Qt5Instance.cxx?
-void initQApp()
+void initQApp(std::map<OUString, css::beans::Optional<css::uno::Any>>& 
rSettings)
 {
     const auto aDisplay = getDisplayArg();
     int nFakeArgc = aDisplay.isEmpty() ? 2 : 3;
@@ -169,36 +187,42 @@ void initQApp()
         unsetenv("SESSION_MANAGER");
     }
 
-    auto app = new QApplication(nFakeArgc, pFakeArgv);
-    QObject::connect(app, &QObject::destroyed, app, [nFakeArgc, pFakeArgv]() {
+    std::unique_ptr<QApplication> app(new QApplication(nFakeArgc, pFakeArgv));
+    QObject::connect(app.get(), &QObject::destroyed, app.get(), [nFakeArgc, 
pFakeArgv]() {
         for (int i = 0; i < nFakeArgc; ++i)
             delete pFakeArgv[i];
         delete[] pFakeArgv;
     });
 
+    readKDESettings(rSettings);
+
     if (session_manager != nullptr)
     {
         // coverity[tainted_string] - trusted source for setenv
         setenv("SESSION_MANAGER", session_manager, 1);
         free(session_manager);
     }
-
-    QApplication::setQuitOnLastWindowClosed(false);
 }
 
 Service::Service()
-    : enabled_(false)
 {
     css::uno::Reference<css::uno::XCurrentContext> 
context(css::uno::getCurrentContext());
     if (context.is())
     {
-        if (!qApp)
-        {
-            initQApp();
-        }
         OUString desktop;
         context->getValueByName("system.desktop-environment") >>= desktop;
-        enabled_ = desktop == "KDE5" && qApp != nullptr;
+
+        if (desktop == "KDE5")
+        {
+            if (!qApp) // no qt event loop yet
+            {
+                // so we start one and read KDE settings
+                initQApp(m_KDESettings);
+            }
+            else // someone else (most likely kde/qt vclplug) has started qt 
event loop
+                // all that is left to do is to read KDE settings
+                readKDESettings(m_KDESettings);
+        }
     }
 }
 
@@ -218,8 +242,12 @@ css::uno::Any Service::getPropertyValue(OUString const& 
PropertyName)
         || PropertyName == "ooInetHTTPSProxyPort" || PropertyName == 
"ooInetNoProxy"
         || PropertyName == "ooInetProxyType")
     {
-        return css::uno::makeAny(enabled_ ? kde5access::getValue(PropertyName)
-                                          : 
css::beans::Optional<css::uno::Any>());
+        std::map<OUString, css::beans::Optional<css::uno::Any>>::iterator it
+            = m_KDESettings.find(PropertyName);
+        if (it != m_KDESettings.end())
+            return css::uno::makeAny(it->second);
+        else
+            return css::uno::makeAny(css::beans::Optional<css::uno::Any>());
     }
     else if (PropertyName == "givenname" || PropertyName == "sn"
              || PropertyName == "TemplatePathVariable")
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to