Kaydet (Commit) 91d36160 authored tarafından Caolán McNamara's avatar Caolán McNamara

use SyncDbusSessionHelper for font install requests

don't need to have two implementations here and
can reduce ifdef forest

Change-Id: I972159ece9cce417aefd5ec4acf5ba5d1d08317b
Reviewed-on: https://gerrit.libreoffice.org/46968Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 12e788f1
...@@ -192,14 +192,10 @@ class VCL_PLUGIN_PUBLIC PrintFontManager ...@@ -192,14 +192,10 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
static void addFontconfigDir(const OString& rDirectory); static void addFontconfigDir(const OString& rDirectory);
std::set<OString> m_aPreviousLangSupportRequests; std::set<OString> m_aPreviousLangSupportRequests;
#if ENABLE_GIO std::vector<OUString> m_aCurrentRequests;
std::vector<OString> m_aCurrentRequests;
#endif
Timer m_aFontInstallerTimer; Timer m_aFontInstallerTimer;
#if ENABLE_GIO
DECL_LINK( autoInstallFontLangSupport, Timer*, void ); DECL_LINK( autoInstallFontLangSupport, Timer*, void );
#endif
PrintFontManager(); PrintFontManager();
public: public:
~PrintFontManager(); ~PrintFontManager();
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <memory> #include <memory>
#include <unx/fontmanager.hxx> #include <unx/fontmanager.hxx>
#include <impfont.hxx> #include <impfont.hxx>
#include <comphelper/sequence.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/sysdata.hxx> #include <vcl/sysdata.hxx>
#include <vcl/vclenum.hxx> #include <vcl/vclenum.hxx>
...@@ -31,8 +32,8 @@ ...@@ -31,8 +32,8 @@
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <unicode/uchar.h> #include <unicode/uchar.h>
#include <unicode/uscript.h> #include <unicode/uscript.h>
#include <config_gio.h>
#include <officecfg/Office/Common.hxx> #include <officecfg/Office/Common.hxx>
#include <org/freedesktop/PackageKit/SyncDbusSessionHelper.hpp>
using namespace psp; using namespace psp;
...@@ -40,10 +41,6 @@ using namespace psp; ...@@ -40,10 +41,6 @@ using namespace psp;
#include <ft2build.h> #include <ft2build.h>
#include <fontconfig/fcfreetype.h> #include <fontconfig/fcfreetype.h>
#if ENABLE_GIO
#include <gio/gio.h>
#endif
#include <cstdio> #include <cstdio>
#include <cstdarg> #include <cstdarg>
...@@ -863,97 +860,36 @@ namespace ...@@ -863,97 +860,36 @@ namespace
return OStringToOUString(aBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8); return OStringToOUString(aBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
} }
#if ENABLE_GIO sal_uInt32 get_xid_for_dbus()
guint get_xid_for_dbus()
{ {
if (Application::IsHeadlessModeEnabled())
return 0;
const vcl::Window *pTopWindow = Application::GetActiveTopWindow(); const vcl::Window *pTopWindow = Application::GetActiveTopWindow();
if (!pTopWindow) if (!pTopWindow)
pTopWindow = Application::GetFirstTopLevelWindow(); pTopWindow = Application::GetFirstTopLevelWindow();
const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : nullptr; const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : nullptr;
return pEnvData ? GetDbusId(*pEnvData) : 0; return pEnvData ? GetDbusId(*pEnvData) : 0;
} }
#endif
} }
#if ENABLE_GIO
IMPL_LINK_NOARG(PrintFontManager, autoInstallFontLangSupport, Timer *, void) IMPL_LINK_NOARG(PrintFontManager, autoInstallFontLangSupport, Timer *, void)
{ {
if (!officecfg::Office::Common::PackageKit::EnableFontInstallation::get()) try
return;
guint xid = get_xid_for_dbus();
if (!xid)
{
SAL_WARN("vcl", "Could not retrieve X Window ID for DBUS");
return;
}
GError *error = nullptr;
/* get the DBUS session connection */
GDBusConnection *session_connection = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error);
if (error != nullptr)
{ {
g_debug ("DBUS cannot connect : %s", error->message); using namespace org::freedesktop::PackageKit;
g_error_free (error); css::uno::Reference<XSyncDbusSessionHelper> xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext()));
return; xSyncDbusSessionHelper->InstallFontconfigResources(get_xid_for_dbus(), comphelper::containerToSequence(m_aCurrentRequests), "hide-finished");
}
/* get the proxy with gnome-session-manager */
GDBusProxy *proxy = g_dbus_proxy_new_sync(session_connection,
G_DBUS_PROXY_FLAGS_NONE,
nullptr, // GDBusInterfaceInfo
"org.freedesktop.PackageKit",
"/org/freedesktop/PackageKit",
"org.freedesktop.PackageKit.Modify",
nullptr, // GCancellable
&error);
if (proxy == nullptr && error != nullptr)
{
g_debug("Could not get DBUS proxy: org.freedesktop.PackageKit: %s", error->message);
g_error_free(error);
return;
} }
catch (const css::uno::Exception& e)
GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE("as")); // 'as'=array of strings
for (std::vector<OString>::const_iterator aI = m_aCurrentRequests.begin(); aI != m_aCurrentRequests.end(); ++aI)
g_variant_builder_add (builder, "s", aI->getStr());
GVariant *res = g_dbus_proxy_call_sync(proxy,
"InstallFontconfigResources",
// Create a new variant with the following types:
// 'u'=guint32 (xid); 'as'=array of strings (builder); 's'=string ("hide-finished")
// See also https://people.gnome.org/~ryanl/glib-docs/gvariant-format-strings.html
g_variant_new("(uass)", xid, builder, "hide-finished"),
G_DBUS_CALL_FLAGS_NONE,
-1, // Timeout
nullptr, // GCancellable
&error);
if (res == nullptr && error != nullptr)
{ {
SAL_INFO("vcl", "InstallFontconfigResources problem, caught " << e);
// Disable this method from now on. It's simply not available on some systems // Disable this method from now on. It's simply not available on some systems
// and leads to an error dialog being shown each time this is called tdf#104883 // and leads to an error dialog being shown each time this is called tdf#104883
std::shared_ptr<comphelper::ConfigurationChanges> batch( comphelper::ConfigurationChanges::create() ); std::shared_ptr<comphelper::ConfigurationChanges> batch( comphelper::ConfigurationChanges::create() );
officecfg::Office::Common::PackageKit::EnableFontInstallation::set(false, batch); officecfg::Office::Common::PackageKit::EnableFontInstallation::set(false, batch);
batch->commit(); batch->commit();
g_debug("InstallFontconfigResources problem : %s", error->message);
g_error_free(error);
} }
else
{
g_variant_unref(res);
}
g_variant_builder_unref(builder);
g_object_unref(G_OBJECT (proxy));
m_aCurrentRequests.clear(); m_aCurrentRequests.clear();
} }
#endif
void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissingCodes ) void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissingCodes )
{ {
...@@ -1109,8 +1045,7 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi ...@@ -1109,8 +1045,7 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi
} }
} }
OUString sStillMissing(pRemainingCodes.get(), nRemainingLen); OUString sStillMissing(pRemainingCodes.get(), nRemainingLen);
#if ENABLE_GIO if (!Application::IsHeadlessModeEnabled() && officecfg::Office::Common::PackageKit::EnableFontInstallation::get())
if (get_xid_for_dbus())
{ {
if (sStillMissing == rMissingCodes) //replaced nothing if (sStillMissing == rMissingCodes) //replaced nothing
{ {
...@@ -1129,7 +1064,7 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi ...@@ -1129,7 +1064,7 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi
if (!sTag.isEmpty() && m_aPreviousLangSupportRequests.find(sTag) == m_aPreviousLangSupportRequests.end()) if (!sTag.isEmpty() && m_aPreviousLangSupportRequests.find(sTag) == m_aPreviousLangSupportRequests.end())
{ {
OString sReq = OString(":lang=") + sTag; OString sReq = OString(":lang=") + sTag;
m_aCurrentRequests.push_back(sReq); m_aCurrentRequests.push_back(OUString::fromUtf8(sReq));
m_aPreviousLangSupportRequests.insert(sTag); m_aPreviousLangSupportRequests.insert(sTag);
} }
} }
...@@ -1140,7 +1075,6 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi ...@@ -1140,7 +1075,6 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi
m_aFontInstallerTimer.Start(); m_aFontInstallerTimer.Start();
} }
} }
#endif
rMissingCodes = sStillMissing; rMissingCodes = sStillMissing;
} }
} }
......
...@@ -146,10 +146,8 @@ PrintFontManager::PrintFontManager() ...@@ -146,10 +146,8 @@ PrintFontManager::PrintFontManager()
: m_nNextFontID( 1 ) : m_nNextFontID( 1 )
, m_nNextDirAtom( 1 ) , m_nNextDirAtom( 1 )
{ {
#if ENABLE_GIO
m_aFontInstallerTimer.SetInvokeHandler(LINK(this, PrintFontManager, autoInstallFontLangSupport)); m_aFontInstallerTimer.SetInvokeHandler(LINK(this, PrintFontManager, autoInstallFontLangSupport));
m_aFontInstallerTimer.SetTimeout(5000); m_aFontInstallerTimer.SetTimeout(5000);
#endif
} }
PrintFontManager::~PrintFontManager() PrintFontManager::~PrintFontManager()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment