aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--include/datetime/settings-live.h8
-rw-r--r--include/datetime/settings-shared.h3
-rw-r--r--src/settings-live.cpp80
3 files changed, 81 insertions, 10 deletions
diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h
index ccf7122..330b8e8 100644
--- a/include/datetime/settings-live.h
+++ b/include/datetime/settings-live.h
@@ -38,8 +38,10 @@ public:
virtual ~LiveSettings();
private:
- static void on_changed(GSettings*, gchar*, gpointer);
- void update_key(const std::string& key);
+ static void on_changed_ccid(GSettings*, gchar*, gpointer);
+ static void on_changed_cunh(GSettings*, gchar*, gpointer);
+ void update_key_ccid(const std::string& key);
+ void update_key_cunh(const std::string& key);
void update_custom_time_format();
void update_locations();
@@ -60,8 +62,10 @@ private:
void update_alarm_duration();
void update_alarm_haptic();
void update_snooze_duration();
+ void update_muted_apps();
GSettings* m_settings;
+ GSettings* m_settings_cunh;
// we've got a raw pointer here, so disable copying
LiveSettings(const LiveSettings&) =delete;
diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h
index bd84a2d..f385e7a 100644
--- a/include/datetime/settings-shared.h
+++ b/include/datetime/settings-shared.h
@@ -51,4 +51,7 @@ TimeFormatMode;
#define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback"
#define SETTINGS_SNOOZE_DURATION_S "snooze-duration-minutes"
+#define SETTINGS_CUNH_SCHEMA_ID "com.lomiri.notifications.hub"
+#define SETTINGS_CUNH_BLACKLIST_S "blacklist"
+
#endif // INDICATOR_DATETIME_SETTINGS_SHARED
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();