From 44686bc81055c7bee7f41f9e219c35115ce8119f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Wed, 20 Dec 2017 15:29:39 +0000 Subject: [PATCH] request installation of langpack via packagekit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if ui is set to track the locale automatically and the current locale has no match in installed resources but has a match in the list of languages that libreoffice was compiled to contain so e.g. de_AT locale shouldn't trigger the installation of anything if langpack-de is already installed and yue_HK shouldn't trigger install of anything cause that not supported (at time of writing) for libreoffice put Fedora/RHEL/Ubuntu naming schemes in here. I moved the lang code from svl to svtools so I could use the restart dialog to prompt to restart after the langpack is installed, but packagekit's blocking mode seems to be no longer blocking and control returns immediately which is a change since the last time I played with this stuff, so drop the restart thing for now. The lack of a blocking modal also makes the "run this on idle when there's a toplevel window up and running" a bit futile, but lets keep that for now anyway. also... set dbus id for existing DbusSessionHelper users Change-Id: I64329e21ae79b6607856de9781bee0274b9cb136 Reviewed-on: https://gerrit.libreoffice.org/46854 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara (cherry picked from commit 7cf4eeed81fd333c87dedffa792f5d547b7981f0) Change-Id: Ice731be539850338ccdd8af87839e0b4d83f01e7 --- config_host/config_langs.h.in | 10 ++ config_host/config_vendor.h.in | 10 ++ configure.ac | 4 + cui/source/options/optgdlg.cxx | 3 +- desktop/source/app/langselect.cxx | 3 +- include/svl/languageoptions.hxx | 3 - include/svtools/langhelp.hxx | 3 + offapi/org/freedesktop/PackageKit/XModify.idl | 22 ++-- .../registry/data/org/openoffice/Office/Common.xcu | 3 + .../schema/org/openoffice/Office/Common.xcs | 6 + sfx2/source/appl/appserv.cxx | 3 +- .../sessioninstall/SyncDbusSessionHelper.cxx | 57 +++++---- .../sessioninstall/SyncDbusSessionHelper.hxx | 20 ++-- svl/source/config/languageoptions.cxx | 33 ------ svtools/source/misc/langhelp.cxx | 130 ++++++++++++++++++++- sw/source/uibase/app/apphdl.cxx | 3 +- vcl/inc/unx/fontmanager.hxx | 6 +- vcl/unx/generic/fontmanager/fontconfig.cxx | 93 ++------------- vcl/unx/generic/fontmanager/fontmanager.cxx | 2 - 19 files changed, 235 insertions(+), 179 deletions(-) create mode 100644 config_host/config_langs.h.in create mode 100644 config_host/config_vendor.h.in diff --git a/config_host/config_langs.h.in b/config_host/config_langs.h.in new file mode 100644 index 0000000..d60a5c1 --- /dev/null +++ b/config_host/config_langs.h.in @@ -0,0 +1,10 @@ +/* Configuration of restriction on supported ui languages, by the + * --with-lang option. + */ + +#ifndef CONFIG_LANGS_H +#define CONFIG_LANGS_H + +#define WITH_LANG "" + +#endif diff --git a/config_host/config_vendor.h.in b/config_host/config_vendor.h.in new file mode 100644 index 0000000..3260221 --- /dev/null +++ b/config_host/config_vendor.h.in @@ -0,0 +1,10 @@ +/* Configuration of restriction on supported ui languages, by the + * --with-lang option. + */ + +#ifndef CONFIG_VENDOR_H +#define CONFIG_VENDOR_H + +#define OOO_VENDOR "" + +#endif diff --git a/configure.ac b/configure.ac index bbb47e6..55e2aa0 100644 --- a/configure.ac +++ b/configure.ac @@ -11777,6 +11777,7 @@ if test "$enable_release_build" = "" -o "$enable_release_build" = "no"; then ALL_LANGS=`echo $ALL_LANGS qtz` fi AC_SUBST(ALL_LANGS) +AC_DEFINE_UNQUOTED(WITH_LANG,"$WITH_LANG") AC_SUBST(WITH_LANG) AC_SUBST(WITH_LANG_LIST) AC_SUBST(GIT_NEEDED_SUBMODULES) @@ -11925,6 +11926,7 @@ else OOO_VENDOR="$with_vendor" AC_MSG_RESULT([$OOO_VENDOR]) fi +AC_DEFINE_UNQUOTED(OOO_VENDOR,"$OOO_VENDOR") AC_SUBST(OOO_VENDOR) if test "$_os" = "Android" ; then @@ -12538,6 +12540,7 @@ AC_CONFIG_HEADERS([config_host/config_gio.h]) AC_CONFIG_HEADERS([config_host/config_global.h]) AC_CONFIG_HEADERS([config_host/config_gpgme.h]) AC_CONFIG_HEADERS([config_host/config_java.h]) +AC_CONFIG_HEADERS([config_host/config_langs.h]) AC_CONFIG_HEADERS([config_host/config_lgpl.h]) AC_CONFIG_HEADERS([config_host/config_liblangtag.h]) AC_CONFIG_HEADERS([config_host/config_locales.h]) @@ -12549,6 +12552,7 @@ AC_CONFIG_HEADERS([config_host/config_options.h]) AC_CONFIG_HEADERS([config_host/config_options_calc.h]) AC_CONFIG_HEADERS([config_host/config_test.h]) AC_CONFIG_HEADERS([config_host/config_typesizes.h]) +AC_CONFIG_HEADERS([config_host/config_vendor.h]) AC_CONFIG_HEADERS([config_host/config_vcl.h]) AC_CONFIG_HEADERS([config_host/config_vclplug.h]) AC_CONFIG_HEADERS([config_host/config_version.h]) diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx index 1c90931..7965179 100644 --- a/cui/source/options/optgdlg.cxx +++ b/cui/source/options/optgdlg.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1122,7 +1123,7 @@ namespace LanguageTag GetInstalledLocaleForSystemUILanguage() { css::uno::Sequence inst(officecfg::Setup::Office::InstalledLocales::get()->getElementNames()); - return LanguageTag(getInstalledLocaleForSystemUILanguage(inst)).makeFallback(); + return LanguageTag(getInstalledLocaleForSystemUILanguage(inst, false)).makeFallback(); } } diff --git a/desktop/source/app/langselect.cxx b/desktop/source/app/langselect.cxx index 4ce877a..86ce743 100644 --- a/desktop/source/app/langselect.cxx +++ b/desktop/source/app/langselect.cxx @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -103,7 +104,7 @@ bool prepareLocale() { } } if (locale.isEmpty()) { - locale = getInstalledLocaleForSystemUILanguage(inst); + locale = getInstalledLocaleForSystemUILanguage(inst, true); } if (locale.isEmpty()) { return false; diff --git a/include/svl/languageoptions.hxx b/include/svl/languageoptions.hxx index f386cb6..6de8eb5 100644 --- a/include/svl/languageoptions.hxx +++ b/include/svl/languageoptions.hxx @@ -131,9 +131,6 @@ public: bool isCJKKeyboardLayoutInstalled() const; }; -OUString SVL_DLLPUBLIC getInstalledLocaleForLanguage(css::uno::Sequence const & installed, OUString const & locale); -OUString SVL_DLLPUBLIC getInstalledLocaleForSystemUILanguage(css::uno::Sequence const & installed); - #endif // INCLUDED_SVL_LANGUAGEOPTIONS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svtools/langhelp.hxx b/include/svtools/langhelp.hxx index a3a84df..db22bb3 100644 --- a/include/svtools/langhelp.hxx +++ b/include/svtools/langhelp.hxx @@ -22,6 +22,9 @@ */ SVT_DLLPUBLIC void localizeWebserviceURI( OUString& io_rURI ); +OUString SVT_DLLPUBLIC getInstalledLocaleForLanguage(css::uno::Sequence const & installed, OUString const & locale); +OUString SVT_DLLPUBLIC getInstalledLocaleForSystemUILanguage(css::uno::Sequence const & installed, bool bRequestInstallIfMissing); + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/offapi/org/freedesktop/PackageKit/XModify.idl b/offapi/org/freedesktop/PackageKit/XModify.idl index a712bb5..69544e9 100644 --- a/offapi/org/freedesktop/PackageKit/XModify.idl +++ b/offapi/org/freedesktop/PackageKit/XModify.idl @@ -22,7 +22,7 @@ module PackageKit * The interface used for modifying the package database. * * @sa - * https://git.gnome.org/browse/gnome-software/tree/src/org.freedesktop.PackageKit.xml + * https://git.gnome.org/browse/gnome-software/tree/src/org.freedesktop.PackageKit.Modify2.xml * for documentation of the corresponding D-Bus interface */ interface XModify : com::sun::star::uno::XInterface @@ -32,70 +32,70 @@ interface XModify : com::sun::star::uno::XInterface * @since LibreOffice 4.0 */ - void InstallPackageFiles( [in] unsigned long xid, [in] sequence< string > files, [in] string interaction); + void InstallPackageFiles([in] sequence< string > files, [in] string interaction); /** * Installs sequence< string > packages to provide sequence< string > files. * @since LibreOffice 4.0 */ - void InstallProvideFiles( [in] unsigned long xid, [in] sequence< string > files, [in] string interaction); + void InstallProvideFiles([in] sequence< string > files, [in] string interaction); /** * Installs sequence< string > packages to provide sequence< string > files. * @since LibreOffice 4.0 */ - void InstallCatalogs( [in] unsigned long xid, [in] sequence< string > files, [in] string interaction); + void InstallCatalogs([in] sequence< string > files, [in] string interaction); /** * Installs sequence< string > packages from a configured software source. * @since LibreOffice 4.0 */ - void InstallPackageNames( [in] unsigned long xid, [in] sequence< string > packages, [in] string interaction); + void InstallPackageNames([in] sequence< string > packages, [in] string interaction); /** * Installs mimetype handlers from a configured software source. * @since LibreOffice 4.0 */ - void InstallMimeTypes( [in] unsigned long xid, [in] sequence< string > mimeTypes, [in] string interaction); + void InstallMimeTypes([in] sequence< string > mimeTypes, [in] string interaction); /** * Installs fontconfig resources ( [in] usually fonts) from a configured software source. * @since LibreOffice 4.0 */ - void InstallFontconfigResources( [in] unsigned long xid, [in] sequence< string > resources, [in] string interaction); + void InstallFontconfigResources([in] sequence< string > resources, [in] string interaction); /** * Installs GStreamer resources ( [in] usually codecs) from a configured software source. * @since LibreOffice 4.0 */ - void InstallGStreamerResources( [in] unsigned long xid, [in] sequence< string > resources, [in] string interaction); + void InstallGStreamerResources([in] sequence< string > resources, [in] string interaction); /** * Installs resources of a given type from a configured software source. * @since LibreOffice 4.0 */ - void InstallResources( [in] unsigned long xid, [in] sequence< string > types, [in] sequence< string > resources, [in] string interaction); + void InstallResources([in] sequence< string > types, [in] sequence< string > resources, [in] string interaction); /** * Removes sequence< string > packages that provide the given local sequence< string > files. * @since LibreOffice 4.0 */ - void RemovePackageByFiles( [in] unsigned long xid, [in] sequence< string > files, [in] string interaction); + void RemovePackageByFiles([in] sequence< string > files, [in] string interaction); /** * Installs printer drivers from a configured software source. * @since LibreOffice 4.0 */ - void InstallPrinterDrivers( [in] unsigned long xid, [in] sequence< string > files, [in] string interaction); + void InstallPrinterDrivers([in] sequence< string > files, [in] string interaction); }; } ; // PackageKit diff --git a/officecfg/registry/data/org/openoffice/Office/Common.xcu b/officecfg/registry/data/org/openoffice/Office/Common.xcu index 6b94ff9..26d1ba0 100644 --- a/officecfg/registry/data/org/openoffice/Office/Common.xcu +++ b/officecfg/registry/data/org/openoffice/Office/Common.xcu @@ -535,6 +535,9 @@ true + + true + diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index f9816fc..2884179 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -6382,6 +6382,12 @@ true + + + Specifies if missing langpack installation should be triggered. + + true + diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 1e2a2ec..e48e5aa 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -196,7 +197,7 @@ namespace using namespace svtools; Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext())); Sequence< OUString > vPackages { "libreoffice-base" }; - xSyncDbusSessionHelper->InstallPackageNames(0, vPackages, OUString()); + xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString()); // Ill be back (hopefully)! SolarMutexGuard aGuard; executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_BIBLIOGRAPHY_INSTALL); diff --git a/shell/source/sessioninstall/SyncDbusSessionHelper.cxx b/shell/source/sessioninstall/SyncDbusSessionHelper.cxx index a1211f7..1938077 100644 --- a/shell/source/sessioninstall/SyncDbusSessionHelper.cxx +++ b/shell/source/sessioninstall/SyncDbusSessionHelper.cxx @@ -18,7 +18,7 @@ using namespace ::com::sun::star::uno; namespace { - struct GVariantDeleter { void operator()(GVariant* pV) { g_variant_unref(pV); } }; + struct GVariantDeleter { void operator()(GVariant* pV) { if (pV) g_variant_unref(pV); } }; struct GVariantBuilderDeleter { void operator()(GVariantBuilder* pVB) { g_variant_builder_unref(pVB); } }; template struct GObjectDeleter { void operator()(T* pO) { g_object_unref(pO); } }; class GErrorWrapper @@ -55,8 +55,15 @@ namespace return proxy; } + static GVariant* pk_make_platform_data() + { + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); + return g_variant_builder_end(&builder); + } + void request( - char const * method, sal_uInt32 xid, + char const * method, css::uno::Sequence const & resources, OUString const & interaction) { @@ -70,14 +77,14 @@ void request( } auto iactUtf8(OUStringToOString(interaction, RTL_TEXTENCODING_UTF8)); std::shared_ptr proxy( - lcl_GetPackageKitProxy("Modify"), GObjectDeleter()); + lcl_GetPackageKitProxy("Modify2"), GObjectDeleter()); GErrorWrapper error; - g_dbus_proxy_call_sync( + std::shared_ptr result(g_dbus_proxy_call_sync( proxy.get(), method, g_variant_new( - "(uass)", static_cast(xid), builder.get(), - iactUtf8.getStr()), - G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error.getRef()); + "(asss@a{sv})", builder.get(), iactUtf8.getStr(), + "libreoffice-startcenter.desktop", pk_make_platform_data()), + G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error.getRef()), GVariantDeleter()); } } @@ -92,66 +99,66 @@ namespace shell { namespace sessioninstall } void SyncDbusSessionHelper::InstallPackageFiles( - sal_uInt32 xid, css::uno::Sequence const & files, + css::uno::Sequence const & files, OUString const & interaction) { - request("InstallPackageFiles", xid, files, interaction); + request("InstallPackageFiles", files, interaction); } void SyncDbusSessionHelper::InstallProvideFiles( - sal_uInt32 xid, css::uno::Sequence const & files, + css::uno::Sequence const & files, OUString const & interaction) { - request("InstallProvideFiles", xid, files, interaction); + request("InstallProvideFiles", files, interaction); } void SyncDbusSessionHelper::InstallCatalogs( - sal_uInt32 xid, css::uno::Sequence const & files, + css::uno::Sequence const & files, OUString const & interaction) { - request("InstallCatalogs", xid, files, interaction); + request("InstallCatalogs", files, interaction); } void SyncDbusSessionHelper::InstallPackageNames( - sal_uInt32 xid, css::uno::Sequence const & packages, + css::uno::Sequence const & packages, OUString const & interaction) { - request("InstallPackageNames", xid, packages, interaction); + request("InstallPackageNames", packages, interaction); } void SyncDbusSessionHelper::InstallMimeTypes( - sal_uInt32 xid, css::uno::Sequence const & mimeTypes, + css::uno::Sequence const & mimeTypes, OUString const & interaction) { - request("InstallMimeTypes", xid, mimeTypes, interaction); + request("InstallMimeTypes", mimeTypes, interaction); } void SyncDbusSessionHelper::InstallFontconfigResources( - sal_uInt32 xid, css::uno::Sequence const & resources, + css::uno::Sequence const & resources, OUString const & interaction) { - request("InstallFontconfigResources", xid, resources, interaction); + request("InstallFontconfigResources", resources, interaction); } void SyncDbusSessionHelper::InstallGStreamerResources( - sal_uInt32 xid, css::uno::Sequence const & resources, + css::uno::Sequence const & resources, OUString const & interaction) { - request("InstallGStreamerResources", xid, resources, interaction); + request("InstallGStreamerResources", resources, interaction); } void SyncDbusSessionHelper::RemovePackageByFiles( - sal_uInt32 xid, css::uno::Sequence const & files, + css::uno::Sequence const & files, OUString const & interaction) { - request("RemovePackageByFiles", xid, files, interaction); + request("RemovePackageByFiles", files, interaction); } void SyncDbusSessionHelper::InstallPrinterDrivers( - sal_uInt32 xid, css::uno::Sequence const & files, + css::uno::Sequence const & files, OUString const & interaction) { - request("InstallPrinteDrivers", xid, files, interaction); + request("InstallPrinteDrivers", files, interaction); } void SAL_CALL SyncDbusSessionHelper::IsInstalled( const OUString& sPackagename, const OUString& sInteraction, sal_Bool& o_isInstalled ) diff --git a/shell/source/sessioninstall/SyncDbusSessionHelper.hxx b/shell/source/sessioninstall/SyncDbusSessionHelper.hxx index 731b649..72b17ba 100644 --- a/shell/source/sessioninstall/SyncDbusSessionHelper.hxx +++ b/shell/source/sessioninstall/SyncDbusSessionHelper.hxx @@ -23,26 +23,26 @@ namespace shell { namespace sessioninstall SyncDbusSessionHelper(css::uno::Reference< css::uno::XComponentContext> const&); // XModify Methods - virtual void SAL_CALL InstallPackageFiles( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; + virtual void SAL_CALL InstallPackageFiles( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; - virtual void SAL_CALL InstallProvideFiles( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; + virtual void SAL_CALL InstallProvideFiles( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; - virtual void SAL_CALL InstallCatalogs( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; + virtual void SAL_CALL InstallCatalogs( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; - virtual void SAL_CALL InstallPackageNames( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& packages, const OUString& interaction ) override; + virtual void SAL_CALL InstallPackageNames( const css::uno::Sequence< OUString >& packages, const OUString& interaction ) override; - virtual void SAL_CALL InstallMimeTypes( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& mimeTypes, const OUString& interaction ) override; + virtual void SAL_CALL InstallMimeTypes( const css::uno::Sequence< OUString >& mimeTypes, const OUString& interaction ) override; - virtual void SAL_CALL InstallFontconfigResources( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& resources, const OUString& interaction ) override; + virtual void SAL_CALL InstallFontconfigResources( const css::uno::Sequence< OUString >& resources, const OUString& interaction ) override; - virtual void SAL_CALL InstallGStreamerResources( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& resources, const OUString& interaction ) override; + virtual void SAL_CALL InstallGStreamerResources( const css::uno::Sequence< OUString >& resources, const OUString& interaction ) override; - virtual void SAL_CALL InstallResources( ::sal_uInt32 /* xid */, const css::uno::Sequence< OUString >& /* types */, const css::uno::Sequence< OUString >& /* resources */, const OUString& /* interaction */ ) override + virtual void SAL_CALL InstallResources( const css::uno::Sequence< OUString >& /* types */, const css::uno::Sequence< OUString >& /* resources */, const OUString& /* interaction */ ) override { throw css::uno::RuntimeException(); } // not implemented - virtual void SAL_CALL RemovePackageByFiles( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; + virtual void SAL_CALL RemovePackageByFiles( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; - virtual void SAL_CALL InstallPrinterDrivers( ::sal_uInt32 xid, const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; + virtual void SAL_CALL InstallPrinterDrivers( const css::uno::Sequence< OUString >& files, const OUString& interaction ) override; // XQuery Methods virtual void SAL_CALL IsInstalled( const OUString& /* package_name */, const OUString& /* interaction */, sal_Bool& /* installed */ ) override; diff --git a/svl/source/config/languageoptions.cxx b/svl/source/config/languageoptions.cxx index 9f9fe45..74af031 100644 --- a/svl/source/config/languageoptions.cxx +++ b/svl/source/config/languageoptions.cxx @@ -27,7 +27,6 @@ #include #include #include -#include #ifdef _WIN32 #if !defined WIN32_LEAN_AND_MEAN @@ -256,41 +255,9 @@ bool SvtSystemLanguageOptions::isKeyboardLayoutTypeInstalled(sal_Int16 scriptTyp return isInstalled; } - bool SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled() const { return isKeyboardLayoutTypeInstalled(css::i18n::ScriptType::ASIAN); } -OUString getInstalledLocaleForLanguage(css::uno::Sequence const & installed, OUString const & locale) -{ - if (locale.isEmpty()) - return OUString(); // do not attempt to resolve anything - - for (sal_Int32 i = 0; i != installed.getLength(); ++i) { - if (installed[i] == locale) { - return installed[i]; - } - } - std::vector fallbacks(LanguageTag(locale).getFallbackStrings(false)); - for (OUString & rf : fallbacks) { - for (sal_Int32 i = 0; i != installed.getLength(); ++i) { - if (installed[i] == rf) { - return installed[i]; - } - } - } - return OUString(); -} - -OUString getInstalledLocaleForSystemUILanguage(const css::uno::Sequence& rLocaleElementNames) -{ - OUString locale = getInstalledLocaleForLanguage(rLocaleElementNames, officecfg::System::L10N::UILocale::get()); - if (locale.isEmpty()) - locale = getInstalledLocaleForLanguage(rLocaleElementNames, "en-US"); - if (locale.isEmpty() && rLocaleElementNames.hasElements()) - locale = rLocaleElementNames[0]; - return locale; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/misc/langhelp.cxx b/svtools/source/misc/langhelp.cxx index 16a3a1d..1e4c5c5 100644 --- a/svtools/source/misc/langhelp.cxx +++ b/svtools/source/misc/langhelp.cxx @@ -7,12 +7,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - +#include +#include +#include +#include +#include +#include #include - +#include #include +#include #include -#include +#include +#include +#include void localizeWebserviceURI( OUString& rURI ) { @@ -33,4 +41,120 @@ void localizeWebserviceURI( OUString& rURI ) rURI += aLang; } +OUString getInstalledLocaleForLanguage(css::uno::Sequence const & installed, OUString const & locale) +{ + if (locale.isEmpty()) + return OUString(); // do not attempt to resolve anything + + for (sal_Int32 i = 0; i != installed.getLength(); ++i) { + if (installed[i] == locale) { + return installed[i]; + } + } + std::vector fallbacks(LanguageTag(locale).getFallbackStrings(false)); + for (OUString & rf : fallbacks) { + for (sal_Int32 i = 0; i != installed.getLength(); ++i) { + if (installed[i] == rf) { + return installed[i]; + } + } + } + return OUString(); +} + +static std::unique_ptr xLangpackInstaller; + +class InstallLangpack : public Idle +{ + std::vector m_aPackages; +public: + explicit InstallLangpack(const std::vector& rPackages) + : Idle("install langpack") + , m_aPackages(rPackages) + { + SetPriority(TaskPriority::LOWEST); + } + + virtual void Invoke() override + { + vcl::Window* pTopWindow = Application::GetActiveTopWindow(); + if (!pTopWindow) + pTopWindow = Application::GetFirstTopLevelWindow(); + if (!pTopWindow) + { + Start(); + return; + } + try + { + using namespace org::freedesktop::PackageKit; + css::uno::Reference xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext())); + xSyncDbusSessionHelper->InstallPackageNames(comphelper::containerToSequence(m_aPackages), OUString()); + } + catch (const css::uno::Exception& e) + { + SAL_INFO("svl", "trying to install a LibreOffice langpack, caught " << e); + } + xLangpackInstaller.reset(); + } +}; + +OUString getInstalledLocaleForSystemUILanguage(const css::uno::Sequence& rLocaleElementNames, bool bRequestInstallIfMissing) +{ + OUString wantedLocale = officecfg::System::L10N::UILocale::get(); + OUString locale = getInstalledLocaleForLanguage(rLocaleElementNames, wantedLocale); + if (bRequestInstallIfMissing && locale.isEmpty() && !wantedLocale.isEmpty() && !Application::IsHeadlessModeEnabled() && + officecfg::Office::Common::PackageKit::EnableLangpackInstallation::get()) + { + LanguageTag aWantedTag(wantedLocale); + if (aWantedTag.getLanguage() != "en") + { + // We try these bases + the exact locale + fallback locale. + // + // The theory is that we can request a bunch of packages + // and it's a success if one of them is available + std::vector aPackages; + OUString sAvailableLocales(WITH_LANG); + std::vector aAvailable; + sal_Int32 nIndex = 0; + do + { + aAvailable.emplace_back(sAvailableLocales.getToken(0, ' ', nIndex)); + } + while (nIndex >= 0); + OUString install = getInstalledLocaleForLanguage(comphelper::containerToSequence(aAvailable), wantedLocale); + if (!install.isEmpty() && install != "en-US") + { + if (strcmp(OOO_VENDOR, "Red Hat, Inc.") == 0 || strcmp(OOO_VENDOR, "The Fedora Project") == 0) + { + // langpack is the typical Fedora/RHEL naming convention + LanguageType eType = aWantedTag.getLanguageType(); + if (MsLangId::isSimplifiedChinese(eType)) + aPackages.emplace_back("libreoffice-langpack-zh-Hans"); + else if (MsLangId::isTraditionalChinese(eType)) + aPackages.emplace_back("libreoffice-langpack-zh-Hant"); + else + aPackages.emplace_back("libreoffice-langpack-" + install); + } + //Debian would be: "The Document Foundation/Debian" + else if (strcmp(OOO_VENDOR, "The Document Foundation, Debian and Ubuntu") == 0) + { + // l10n is the typical Debian/Ubuntu naming convention + aPackages.emplace_back("libreoffice-l10n-" + install); + } + } + if (!aPackages.empty()) + { + xLangpackInstaller.reset(new InstallLangpack(aPackages)); + xLangpackInstaller->Start(); + } + } + } + if (locale.isEmpty()) + locale = getInstalledLocaleForLanguage(rLocaleElementNames, "en-US"); + if (locale.isEmpty() && rLocaleElementNames.hasElements()) + locale = rLocaleElementNames[0]; + return locale; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx index 467112e..6986807 100644 --- a/sw/source/uibase/app/apphdl.cxx +++ b/sw/source/uibase/app/apphdl.cxx @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -420,7 +421,7 @@ void SwMailMergeWizardExecutor::ExecuteMailMergeWizard( const SfxItemSet * pArgs using namespace svtools; css::uno::Reference< XSyncDbusSessionHelper > xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext())); const css::uno::Sequence< OUString > vPackages{ "libreoffice-base" }; - xSyncDbusSessionHelper->InstallPackageNames(0, vPackages, OUString()); + xSyncDbusSessionHelper->InstallPackageNames(vPackages, OUString()); SolarMutexGuard aGuard; executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, RESTART_REASON_MAILMERGE_INSTALL); } diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx index 03d033e..14aebde 100644 --- a/vcl/inc/unx/fontmanager.hxx +++ b/vcl/inc/unx/fontmanager.hxx @@ -192,14 +192,10 @@ class VCL_PLUGIN_PUBLIC PrintFontManager static void addFontconfigDir(const OString& rDirectory); std::set m_aPreviousLangSupportRequests; -#if ENABLE_GIO - std::vector m_aCurrentRequests; -#endif + std::vector m_aCurrentRequests; Timer m_aFontInstallerTimer; -#if ENABLE_GIO DECL_LINK( autoInstallFontLangSupport, Timer*, void ); -#endif PrintFontManager(); public: ~PrintFontManager(); diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx index 2c16e04..59acfa5 100644 --- a/vcl/unx/generic/fontmanager/fontconfig.cxx +++ b/vcl/unx/generic/fontmanager/fontconfig.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -31,8 +32,8 @@ #include #include #include -#include #include +#include using namespace psp; @@ -40,10 +41,6 @@ using namespace psp; #include #include -#if ENABLE_GIO -#include -#endif - #include #include @@ -862,96 +859,28 @@ namespace aBuf.append('-').append(pScriptCode); return OStringToOUString(aBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8); } - -#if ENABLE_GIO - guint get_xid_for_dbus() - { - // FIXME: Application::GetActiveTopWindow only returns something sensible if LO currently has the focus - // (which is not the case when you are trying to debug this...). It should instead return the last active window. - const vcl::Window *pTopWindow = Application::IsHeadlessModeEnabled() ? nullptr : Application::GetActiveTopWindow(); - const SystemEnvData* pEnvData = pTopWindow ? pTopWindow->GetSystemData() : nullptr; - return pEnvData ? pEnvData->aWindow : 0; - } -#endif } -#if ENABLE_GIO IMPL_LINK_NOARG(PrintFontManager, autoInstallFontLangSupport, Timer *, void) { - if (!officecfg::Office::Common::PackageKit::EnableFontInstallation::get()) - return; - - guint xid = get_xid_for_dbus(); - - if (!xid) + try { - SAL_WARN("vcl", "Could not retrieve X Window ID for DBUS"); - return; + using namespace org::freedesktop::PackageKit; + css::uno::Reference xSyncDbusSessionHelper(SyncDbusSessionHelper::create(comphelper::getProcessComponentContext())); + xSyncDbusSessionHelper->InstallFontconfigResources(comphelper::containerToSequence(m_aCurrentRequests), "hide-finished"); } - - - 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); - g_error_free (error); - return; - } - - /* 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; - } - - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE("as")); // 'as'=array of strings - for (std::vector::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) + catch (const css::uno::Exception& e) { + SAL_INFO("vcl", "InstallFontconfigResources problem, caught " << e); // 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 std::shared_ptr batch( comphelper::ConfigurationChanges::create() ); officecfg::Office::Common::PackageKit::EnableFontInstallation::set(false, batch); 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(); } -#endif void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissingCodes ) { @@ -1107,8 +1036,7 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi } } OUString sStillMissing(pRemainingCodes.get(), nRemainingLen); -#if ENABLE_GIO - if (get_xid_for_dbus()) + if (!Application::IsHeadlessModeEnabled() && officecfg::Office::Common::PackageKit::EnableFontInstallation::get()) { if (sStillMissing == rMissingCodes) //replaced nothing { @@ -1127,7 +1055,7 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi if (!sTag.isEmpty() && m_aPreviousLangSupportRequests.find(sTag) == m_aPreviousLangSupportRequests.end()) { OString sReq = OString(":lang=") + sTag; - m_aCurrentRequests.push_back(sReq); + m_aCurrentRequests.push_back(OUString::fromUtf8(sReq)); m_aPreviousLangSupportRequests.insert(sTag); } } @@ -1138,7 +1066,6 @@ void PrintFontManager::Substitute( FontSelectPattern &rPattern, OUString& rMissi m_aFontInstallerTimer.Start(); } } -#endif rMissingCodes = sStillMissing; } } diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx index c956345..d1743dd 100644 --- a/vcl/unx/generic/fontmanager/fontmanager.cxx +++ b/vcl/unx/generic/fontmanager/fontmanager.cxx @@ -146,10 +146,8 @@ PrintFontManager::PrintFontManager() : m_nNextFontID( 1 ) , m_nNextDirAtom( 1 ) { -#if ENABLE_GIO m_aFontInstallerTimer.SetInvokeHandler(LINK(this, PrintFontManager, autoInstallFontLangSupport)); m_aFontInstallerTimer.SetTimeout(5000); -#endif } PrintFontManager::~PrintFontManager() -- 2.9.5