aboutsummaryrefslogtreecommitdiff
path: root/src/settings-live.cpp
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2016-02-01 18:07:18 -0600
committerRobert Tari <robert@tari.in>2021-06-30 15:01:54 +0200
commit0b4ad877e1a5b083eda5c31227e476d969d00925 (patch)
tree0ac5b0d94a05eae12c1a54a283a2a7554b30ffe4 /src/settings-live.cpp
parentb4ff1a2458802e3238d952c69f9dd664f013137b (diff)
downloadayatana-indicator-datetime-0b4ad877e1a5b083eda5c31227e476d969d00925.tar.gz
ayatana-indicator-datetime-0b4ad877e1a5b083eda5c31227e476d969d00925.tar.bz2
ayatana-indicator-datetime-0b4ad877e1a5b083eda5c31227e476d969d00925.zip
in LiveSettings, add gschema support for notification app blacklisting
Diffstat (limited to 'src/settings-live.cpp')
-rw-r--r--src/settings-live.cpp80
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();