summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-09-03 16:59:48 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-09-03 17:01:39 +0100
commita4196e56eb3560a2ec2199b87e5d7ff12d55a097 (patch)
treed94e77f1e9128ea95f20a23ef890b88ca5aab085 /vcl
parentfeddd3d87077abb2d5435804a9a4859286f6d86f (diff)
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
Diffstat (limited to 'vcl')
-rw-r--r--vcl/generic/fontmanager/fontconfig.cxx116
-rw-r--r--vcl/generic/fontmanager/fontmanager.cxx4
-rw-r--r--vcl/inc/vcl/fontmanager.hxx5
3 files changed, 71 insertions, 54 deletions
diff --git a/vcl/generic/fontmanager/fontconfig.cxx b/vcl/generic/fontmanager/fontconfig.cxx
index a98e52949e15..f5f214514d3a 100644
--- a/vcl/generic/fontmanager/fontconfig.cxx
+++ b/vcl/generic/fontmanager/fontconfig.cxx
@@ -846,64 +846,71 @@ namespace
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;
- /* 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;
- }
+ const Window *pTopWindow = Application::IsHeadlessModeEnabled() ? NULL : Application::GetActiveTopWindow();
+ const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : NULL;
+ return pEnvData ? pEnvData->aWindow : 0;
+ }
+#endif
+}
- /* 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;
- }
+IMPL_LINK_NOARG(PrintFontManager, autoInstallFontLangSupport)
+{
+ guint xid = get_xid_for_dbus();
- gchar **fonts = (gchar**)g_malloc((rNewReqs.size() + 1) * sizeof(gchar*));
- gchar **font = fonts;
- 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);
- }
+ if (!xid)
+ return -1;
- g_free(fonts);
- g_object_unref(G_OBJECT (proxy));
+#ifdef ENABLE_DBUS
+ 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();
- const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : NULL;
- return pEnvData ? pEnvData->aWindow : 0;
+ g_warning("InstallFontconfigResources problem : %s", error->message);
+ g_error_free(error);
}
+
+ g_free(fonts);
+ g_object_unref(G_OBJECT (proxy));
+ m_aCurrentRequests.clear();
#endif
+ return 0;
}
bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& rMissingCodes )
@@ -1050,10 +1057,8 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& r
}
OUString sStillMissing(pRemainingCodes, nRemainingLen);
#ifdef ENABLE_DBUS
- guint xid = get_xid_for_dbus();
- if (xid)
+ if (get_xid_for_dbus())
{
- std::vector<OString> aNewRequests;
if (sStillMissing == rMissingCodes) //replaced nothing
{
//It'd be better if we could ask packagekit using the
@@ -1071,13 +1076,16 @@ bool PrintFontManager::Substitute( FontSelectPattern &rPattern, rtl::OUString& r
if (!sTag.isEmpty() && m_aPreviousLangSupportRequests.find(sTag) == m_aPreviousLangSupportRequests.end())
{
OString sReq = OString(":lang=") + sTag;
- aNewRequests.push_back(sReq);
+ m_aCurrentRequests.push_back(sReq);
m_aPreviousLangSupportRequests.insert(sTag);
}
}
}
- if (!aNewRequests.empty())
- autoInstallFontLangSupport(aNewRequests, xid);
+ if (!m_aCurrentRequests.empty())
+ {
+ m_aFontInstallerTimer.Stop();
+ m_aFontInstallerTimer.Start();
+ }
}
#endif
rMissingCodes = sStillMissing;
diff --git a/vcl/generic/fontmanager/fontmanager.cxx b/vcl/generic/fontmanager/fontmanager.cxx
index 8199fc332d69..2a3d29ae8293 100644
--- a/vcl/generic/fontmanager/fontmanager.cxx
+++ b/vcl/generic/fontmanager/fontmanager.cxx
@@ -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_aFontInstallerTimer.SetTimeoutHdl(LINK(this, PrintFontManager, autoInstallFontLangSupport));
+ m_aFontInstallerTimer.SetTimeout(5000);
}
// -------------------------------------------------------------------------
PrintFontManager::~PrintFontManager()
{
+ m_aFontInstallerTimer.Stop();
deinitFontconfig();
for( ::boost::unordered_map< fontID, PrintFont* >::const_iterator it = m_aFonts.begin(); it != m_aFonts.end(); ++it )
delete (*it).second;
diff --git a/vcl/inc/vcl/fontmanager.hxx b/vcl/inc/vcl/fontmanager.hxx
index 4bd7a4d42264..6666f0ffda0d 100644
--- a/vcl/inc/vcl/fontmanager.hxx
+++ b/vcl/inc/vcl/fontmanager.hxx
@@ -36,6 +36,7 @@
#include "vcl/dllapi.h"
#include "vcl/helper.hxx"
+#include "vcl/timer.hxx"
#include "vcl/vclenum.hxx"
#include "com/sun/star/lang/Locale.hpp"
@@ -354,6 +355,10 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
bool readOverrideMetrics();
std::set<OString> m_aPreviousLangSupportRequests;
+ std::vector<OString> m_aCurrentRequests;
+ Timer m_aFontInstallerTimer;
+
+ DECL_LINK( autoInstallFontLangSupport, void* );
PrintFontManager();
~PrintFontManager();