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

adjust auto font installation

to happen on a 5 second timer and collect up as much missing
stuff in one go as we can

Change-Id: I79f5e70634684a2ef83e3090790531149baf529b
üst feddd3d8
...@@ -846,64 +846,71 @@ namespace ...@@ -846,64 +846,71 @@ namespace
return LanguageTag(OStringToOUString(aBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8)); return LanguageTag(OStringToOUString(aBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8));
} }
int autoInstallFontLangSupport(const std::vector<OString> &rNewReqs, guint xid) guint get_xid_for_dbus()
{ {
GError *error = NULL; const Window *pTopWindow = Application::IsHeadlessModeEnabled() ? NULL : Application::GetActiveTopWindow();
/* get the DBUS session connection */ const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : NULL;
DBusGConnection *session_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); return pEnvData ? pEnvData->aWindow : 0;
if (error != NULL) }
{ #endif
g_warning ("DBUS cannot connect : %s", error->message); }
g_error_free (error);
return -1;
}
/* get the proxy with gnome-session-manager */ IMPL_LINK_NOARG(PrintFontManager, autoInstallFontLangSupport)
DBusGProxy *proxy = dbus_g_proxy_new_for_name(session_connection, {
"org.freedesktop.PackageKit", guint xid = get_xid_for_dbus();
"/org/freedesktop/PackageKit",
"org.freedesktop.PackageKit.Modify");
if (proxy == NULL)
{
g_warning("Could not get DBUS proxy: org.freedesktop.PackageKit");
return -1;
}
gchar **fonts = (gchar**)g_malloc((rNewReqs.size() + 1) * sizeof(gchar*)); if (!xid)
gchar **font = fonts; return -1;
for (std::vector<OString>::const_iterator aI = rNewReqs.begin(); aI != rNewReqs.end(); ++aI)
*font++ = (gchar*)aI->getStr();
*font = NULL;
gboolean res = dbus_g_proxy_call(proxy, "InstallFontconfigResources", &error,
G_TYPE_UINT, xid, /* xid */
G_TYPE_STRV, fonts, /* data */
G_TYPE_STRING, "hide-finished", /* interaction */
G_TYPE_INVALID,
G_TYPE_INVALID);
/* check the return value */
if (!res)
g_warning("InstallFontconfigResources method failed");
/* check the error value */
if (error != NULL)
{
g_warning("InstallFontconfigResources problem : %s", error->message);
g_error_free(error);
}
g_free(fonts); #ifdef ENABLE_DBUS
g_object_unref(G_OBJECT (proxy)); GError *error = NULL;
/* get the DBUS session connection */
DBusGConnection *session_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (error != NULL)
{
g_warning ("DBUS cannot connect : %s", error->message);
g_error_free (error);
return -1;
}
return 0; /* get the proxy with gnome-session-manager */
DBusGProxy *proxy = dbus_g_proxy_new_for_name(session_connection,
"org.freedesktop.PackageKit",
"/org/freedesktop/PackageKit",
"org.freedesktop.PackageKit.Modify");
if (proxy == NULL)
{
g_warning("Could not get DBUS proxy: org.freedesktop.PackageKit");
return -1;
} }
guint get_xid_for_dbus() gchar **fonts = (gchar**)g_malloc((m_aCurrentRequests.size() + 1) * sizeof(gchar*));
gchar **font = fonts;
for (std::vector<OString>::const_iterator aI = m_aCurrentRequests.begin(); aI != m_aCurrentRequests.end(); ++aI)
*font++ = (gchar*)aI->getStr();
*font = NULL;
gboolean res = dbus_g_proxy_call(proxy, "InstallFontconfigResources", &error,
G_TYPE_UINT, xid, /* xid */
G_TYPE_STRV, fonts, /* data */
G_TYPE_STRING, "hide-finished", /* interaction */
G_TYPE_INVALID,
G_TYPE_INVALID);
/* check the return value */
if (!res)
g_warning("InstallFontconfigResources method failed");
/* check the error value */
if (error != NULL)
{ {
const Window *pTopWindow = Application::IsHeadlessModeEnabled() ? NULL : Application::GetActiveTopWindow(); g_warning("InstallFontconfigResources problem : %s", error->message);
const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : NULL; g_error_free(error);
return pEnvData ? pEnvData->aWindow : 0;
} }
g_free(fonts);
g_object_unref(G_OBJECT (proxy));
m_aCurrentRequests.clear();
#endif #endif
return 0;
} }
bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& rMissingCodes ) bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& rMissingCodes )
...@@ -1050,10 +1057,8 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& r ...@@ -1050,10 +1057,8 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& r
} }
OUString sStillMissing(pRemainingCodes, nRemainingLen); OUString sStillMissing(pRemainingCodes, nRemainingLen);
#ifdef ENABLE_DBUS #ifdef ENABLE_DBUS
guint xid = get_xid_for_dbus(); if (get_xid_for_dbus())
if (xid)
{ {
std::vector<OString> aNewRequests;
if (sStillMissing == rMissingCodes) //replaced nothing if (sStillMissing == rMissingCodes) //replaced nothing
{ {
//It'd be better if we could ask packagekit using the //It'd be better if we could ask packagekit using the
...@@ -1071,13 +1076,16 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& r ...@@ -1071,13 +1076,16 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& r
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;
aNewRequests.push_back(sReq); m_aCurrentRequests.push_back(sReq);
m_aPreviousLangSupportRequests.insert(sTag); m_aPreviousLangSupportRequests.insert(sTag);
} }
} }
} }
if (!aNewRequests.empty()) if (!m_aCurrentRequests.empty())
autoInstallFontLangSupport(aNewRequests, xid); {
m_aFontInstallerTimer.Stop();
m_aFontInstallerTimer.Start();
}
} }
#endif #endif
rMissingCodes = sStillMissing; rMissingCodes = sStillMissing;
......
...@@ -1018,12 +1018,16 @@ PrintFontManager::PrintFontManager() ...@@ -1018,12 +1018,16 @@ PrintFontManager::PrintFontManager()
m_aAdobecodeToUnicode.insert( ::boost::unordered_multimap< sal_uInt8, sal_Unicode >::value_type( aAdobeCodes[i].aAdobeStandardCode, aAdobeCodes[i].aUnicode ) ); m_aAdobecodeToUnicode.insert( ::boost::unordered_multimap< sal_uInt8, sal_Unicode >::value_type( aAdobeCodes[i].aAdobeStandardCode, aAdobeCodes[i].aUnicode ) );
} }
} }
m_aFontInstallerTimer.SetTimeoutHdl(LINK(this, PrintFontManager, autoInstallFontLangSupport));
m_aFontInstallerTimer.SetTimeout(5000);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
PrintFontManager::~PrintFontManager() PrintFontManager::~PrintFontManager()
{ {
m_aFontInstallerTimer.Stop();
deinitFontconfig(); deinitFontconfig();
for( ::boost::unordered_map< fontID, PrintFont* >::const_iterator it = m_aFonts.begin(); it != m_aFonts.end(); ++it ) for( ::boost::unordered_map< fontID, PrintFont* >::const_iterator it = m_aFonts.begin(); it != m_aFonts.end(); ++it )
delete (*it).second; delete (*it).second;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "vcl/dllapi.h" #include "vcl/dllapi.h"
#include "vcl/helper.hxx" #include "vcl/helper.hxx"
#include "vcl/timer.hxx"
#include "vcl/vclenum.hxx" #include "vcl/vclenum.hxx"
#include "com/sun/star/lang/Locale.hpp" #include "com/sun/star/lang/Locale.hpp"
...@@ -354,6 +355,10 @@ class VCL_PLUGIN_PUBLIC PrintFontManager ...@@ -354,6 +355,10 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
bool readOverrideMetrics(); bool readOverrideMetrics();
std::set<OString> m_aPreviousLangSupportRequests; std::set<OString> m_aPreviousLangSupportRequests;
std::vector<OString> m_aCurrentRequests;
Timer m_aFontInstallerTimer;
DECL_LINK( autoInstallFontLangSupport, void* );
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