Loading

Paste #ppwvkz1sz

  1. From b20aee817589cce55288296d30eb0484e66d4347 Mon Sep 17 00:00:00 2001
  2. From: Jan Grulich <jgrulich@redhat.com>
  3. Date: Tue, 4 Dec 2018 14:08:52 +0100
  4. Subject: test
  5.  
  6.  
  7. diff --git a/qgnomeplatform.pro b/qgnomeplatform.pro
  8. index 9d6f52e..a67ec65 100644
  9. --- a/qgnomeplatform.pro
  10. +++ b/qgnomeplatform.pro
  11. @@ -7,6 +7,7 @@ CONFIG += plugin \
  12.            link_pkgconfig
  13.  
  14.  QT += core-private \
  15. +      dbus \
  16.        gui-private \
  17.        widgets
  18.  
  19. diff --git a/src/gnomehintssettings.cpp b/src/gnomehintssettings.cpp
  20. index 4e11fb7..6edc734 100644
  21. --- a/src/gnomehintssettings.cpp
  22. +++ b/src/gnomehintssettings.cpp
  23. @@ -32,8 +32,35 @@
  24.  #include <QSettings>
  25.  #include <QStandardPaths>
  26.  
  27. +#include <QDBusArgument>
  28. +#include <QDBusConnection>
  29. +#include <QDBusMessage>
  30. +
  31.  Q_LOGGING_CATEGORY(QGnomePlatform, "qt.qpa.qgnomeplatform")
  32.  
  33. +const QDBusArgument &operator>>(const QDBusArgument &argument, QMap<QString, QVariantMap> &map)
  34. +{
  35. +    argument.beginMap();
  36. +    map.clear();
  37. +
  38. +    while (!argument.atEnd()) {
  39. +        QString key;
  40. +        QVariantMap value;
  41. +        argument.beginMapEntry();
  42. +        argument >> key >> value;
  43. +        argument.endMapEntry();
  44. +        map.insert(key, value);
  45. +    }
  46. +
  47. +    argument.endMap();
  48. +    return argument;
  49. +}
  50. +
  51. +static inline bool checkUsePortalSupport()
  52. +{
  53. +    return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QStringLiteral("flatpak-info")).isEmpty() || qEnvironmentVariableIsSet("SNAP");
  54. +}
  55. +
  56.  void gtkMessageHandler(const gchar *log_domain,
  57.                         GLogLevelFlags log_level,
  58.                         const gchar *message,
  59. @@ -50,6 +77,7 @@ void gtkMessageHandler(const gchar *log_domain,
  60.  
  61.  GnomeHintsSettings::GnomeHintsSettings()
  62.      : QObject(0)
  63. +    , m_usePortal(checkUsePortalSupport())
  64.      , m_settings(g_settings_new("org.gnome.desktop.interface"))
  65.  {
  66.      gtk_init(nullptr, nullptr);
  67. @@ -62,6 +90,11 @@ GnomeHintsSettings::GnomeHintsSettings()
  68.          m_cinnamonSettings = g_settings_new("org.cinnamon.desktop.interface");
  69.      }
  70.  
  71. +    qWarning() << "Using qgnomeplatform";
  72. +    if (m_usePortal) {
  73. +        updatePortalSetting();
  74. +    }
  75. +
  76.      // Get current theme and variant
  77.      loadTheme();
  78.  
  79. @@ -85,6 +118,11 @@ GnomeHintsSettings::GnomeHintsSettings()
  80.          }
  81.      }
  82.  
  83. +    if (m_usePortal) {
  84. +        QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/org/freedesktop/portal/desktop"), QStringLiteral("org.freedesktop.portal.Settings"),
  85. +                                              QStringLiteral("SettingChanged"), this, SLOT(portalSettingChanged(QString,QString,QDBusVariant)));
  86. +    }
  87. +
  88.      // g_signal_connect(gtk_settings_get_default(), "notify::gtk-theme-name", G_CALLBACK(gtkThemeChanged), this);
  89.  
  90.                                          /* Other theme hints */
  91. @@ -352,6 +390,10 @@ void GnomeHintsSettings::loadStaticHints() {
  92.      m_hints[QPlatformTheme::IconThemeSearchPaths] = xdgIconThemePaths();
  93.  }
  94.  
  95. +void GnomeHintsSettings::portalSettingChanged(const QString &group, const QString &key, const QDBusVariant &value)
  96. +{
  97. +}
  98. +
  99.  QStringList GnomeHintsSettings::xdgIconThemePaths() const
  100.  {
  101.      QStringList paths;
  102. @@ -421,3 +463,21 @@ void GnomeHintsSettings::configureKvantum(const QString &theme) const
  103.          config.setValue("theme", theme);
  104.      }
  105.  }
  106. +
  107. +void GnomeHintsSettings::updatePortalSetting()
  108. +{
  109. +    qWarning() << "Update portal";
  110. +    m_portalSettings.clear();
  111. +    QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.portal.Desktop"),
  112. +                                                          QStringLiteral("/org/freedesktop/portal/desktop"),
  113. +                                                          QStringLiteral("org.freedesktop.portal.Settings"),
  114. +                                                          QStringLiteral("ReadAll"));
  115. +    message << QStringList{QStringLiteral("org.gnome.desktop.interface.*")};
  116. +
  117. +    // FIXME: async?
  118. +    QDBusMessage resultMessage = QDBusConnection::sessionBus().call(message);
  119. +    if (resultMessage.type() == QDBusMessage::ReplyMessage) {
  120. +        QDBusArgument dbusArgument = resultMessage.arguments().at(0).value<QDBusArgument>();
  121. +        dbusArgument >> m_portalSettings;
  122. +    }
  123. +}
  124. diff --git a/src/gnomehintssettings.h b/src/gnomehintssettings.h
  125. index 5de911c..65fad38 100644
  126. --- a/src/gnomehintssettings.h
  127. +++ b/src/gnomehintssettings.h
  128. @@ -20,6 +20,7 @@
  129.  #ifndef GNOME_HINTS_SETTINGS_H
  130.  #define GNOME_HINTS_SETTINGS_H
  131.  
  132. +#include <QDBusVariant>
  133.  #include <QFont>
  134.  #include <QObject>
  135.  #include <QVariant>
  136. @@ -86,6 +87,7 @@ private Q_SLOTS:
  137.      void loadFonts();
  138.      void loadPalette();
  139.      void loadStaticHints();
  140. +    void portalSettingChanged(const QString &group, const QString &key, const QDBusVariant &value);
  141.  
  142.  protected:
  143.      static void gsettingPropertyChanged(GSettings *settings, gchar *key, GnomeHintsSettings *gnomeHintsSettings);
  144. @@ -116,14 +118,17 @@ private:
  145.      QStringList xdgIconThemePaths() const;
  146.      QString kvantumThemeForGtkTheme() const;
  147.      void configureKvantum(const QString &theme) const;
  148. +    void updatePortalSetting();
  149.  
  150.      bool m_gtkThemeDarkVariant = false;
  151. +    bool m_usePortal = false;
  152.      QString m_gtkTheme = nullptr;
  153.      QPalette *m_palette = nullptr;
  154.      GSettings *m_cinnamonSettings = nullptr;
  155.      GSettings *m_settings = nullptr;
  156.      QHash<QPlatformTheme::Font, QFont*> m_fonts;
  157.      QHash<QPlatformTheme::ThemeHint, QVariant> m_hints;
  158. +    QMap<QString, QVariantMap> m_portalSettings;
  159.  };
  160.  
  161.  template <> inline int GnomeHintsSettings::getSettingsProperty(GSettings *settings, const QString &property, bool *ok) {

Comments