From fee2f8fdbe5a851643bed55decb14e1cff84cb8a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Feb 2016 18:07:18 -0600 Subject: in LiveSettings, add gschema support for notification app blacklisting --- src/settings-live.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 8 deletions(-) (limited to 'src/settings-live.cpp') 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 +extern "C" +{ + #include +} + 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>& 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& 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> 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(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(gself)->update_key(key); + static_cast(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(); -- cgit v1.2.3