diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2016-02-01 18:07:18 -0600 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2021-08-29 14:27:02 +0200 |
commit | fee2f8fdbe5a851643bed55decb14e1cff84cb8a (patch) | |
tree | 1f44368c759989c0f22643b16a086259bfe3e176 /src | |
parent | dfa174a82854b214b7eeaa62ad8b7567c4c1a949 (diff) | |
download | ayatana-indicator-datetime-fee2f8fdbe5a851643bed55decb14e1cff84cb8a.tar.gz ayatana-indicator-datetime-fee2f8fdbe5a851643bed55decb14e1cff84cb8a.tar.bz2 ayatana-indicator-datetime-fee2f8fdbe5a851643bed55decb14e1cff84cb8a.zip |
in LiveSettings, add gschema support for notification app blacklisting
Diffstat (limited to 'src')
-rw-r--r-- | src/settings-live.cpp | 80 |
1 files changed, 72 insertions, 8 deletions
diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 5c2addb..e63bcbe 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -19,6 +19,11 @@ #include <datetime/settings-live.h> +extern "C" +{ + #include <ayatana/common/utils.h> +} + namespace ayatana { namespace indicator { namespace datetime { @@ -29,13 +34,19 @@ namespace datetime { LiveSettings::~LiveSettings() { + g_clear_object(&m_settings_cunh); g_clear_object(&m_settings); } -LiveSettings::LiveSettings(): - m_settings(g_settings_new(SETTINGS_INTERFACE)) +LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) { - g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed), this); + g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); + + if (ayatana_common_utils_is_lomiri()) + { + m_settings_cunh = g_settings_new(SETTINGS_CUNH_SCHEMA_ID); + g_signal_connect (m_settings_cunh, "changed", G_CALLBACK(on_changed_cunh), this); + } // init the Properties from the GSettings backend update_custom_time_format(); @@ -57,6 +68,7 @@ LiveSettings::LiveSettings(): update_alarm_duration(); update_alarm_haptic(); update_snooze_duration(); + update_muted_apps(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -64,6 +76,20 @@ LiveSettings::LiveSettings(): g_settings_set_string(m_settings, SETTINGS_CUSTOM_TIME_FORMAT_S, value.c_str()); }); + if (ayatana_common_utils_is_lomiri()) + { + muted_apps.changed().connect([this](const std::set<std::pair<std::string,std::string>>& value){ + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)")); + for(const auto& app : value){ + const auto& pkgname {app.first}; + const auto& appname {app.second}; + g_variant_builder_add(&builder, "(ss)", pkgname.c_str(), appname.c_str()); + } + g_settings_set_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S, g_variant_builder_end(&builder)); + }); + } + locations.changed().connect([this](const std::vector<std::string>& value){ const int n = value.size(); gchar** strv = g_new0(gchar*, n+1); @@ -163,6 +189,27 @@ void LiveSettings::update_locations() locations.set(l); } +void LiveSettings::update_muted_apps() +{ + if (ayatana_common_utils_is_lomiri()) + { + std::set<std::pair<std::string,std::string>> apps; + + auto blacklist = g_settings_get_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S); + GVariantIter* iter {nullptr}; + g_variant_get (blacklist, "a(ss)", &iter); + gchar* pkgname; + gchar* appname; + while (g_variant_iter_loop (iter, "(ss)", &pkgname, &appname)) { + apps.insert(std::make_pair(pkgname,appname)); + } + g_variant_iter_free (iter); + g_clear_pointer(&blacklist, g_variant_unref); + + muted_apps.set(apps); + } +} + void LiveSettings::update_show_calendar() { const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_CALENDAR_S); @@ -265,14 +312,31 @@ void LiveSettings::update_snooze_duration() **** ***/ -void LiveSettings::on_changed(GSettings* /*settings*/, - gchar* key, - gpointer gself) +void LiveSettings::on_changed_cunh(GSettings* /*settings*/, + gchar* key, + gpointer gself) +{ + static_cast<LiveSettings*>(gself)->update_key_cunh(key); +} + +void LiveSettings::update_key_cunh(const std::string& key) +{ + if (key == SETTINGS_CUNH_BLACKLIST_S) + update_muted_apps(); +} + +/*** +**** +***/ + +void LiveSettings::on_changed_ccid(GSettings* /*settings*/, + gchar* key, + gpointer gself) { - static_cast<LiveSettings*>(gself)->update_key(key); + static_cast<LiveSettings*>(gself)->update_key_ccid(key); } -void LiveSettings::update_key(const std::string& key) +void LiveSettings::update_key_ccid(const std::string& key) { if (key == SETTINGS_LOCATIONS_S) update_locations(); |