aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Conti <jason.conti@gmail.com>2020-08-20 09:35:44 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2020-08-20 14:38:04 +0200
commit82ca9185e9894121cc1d13bb06e7dc0e09dfd01b (patch)
treec48498323f58b98f3acfbc2377cedce1667bb6d0
parent77fb1c1f8f3f2856f9c991198cb231f22d19b40e (diff)
downloadayatana-indicator-notifications-82ca9185e9894121cc1d13bb06e7dc0e09dfd01b.tar.gz
ayatana-indicator-notifications-82ca9185e9894121cc1d13bb06e7dc0e09dfd01b.tar.bz2
ayatana-indicator-notifications-82ca9185e9894121cc1d13bb06e7dc0e09dfd01b.zip
Add our own do-not-disturb setting.
* Remove the MATE specific code from indicator-notifications-settings. * When do-not-disturb is set the indicator will try to set do-not-disturb on all supported desktops (currently only MATE).
-rw-r--r--data/org.ayatana.indicator.notifications.gschema.xml.in.in5
-rw-r--r--src/indicator-notifications-settings.c67
-rw-r--r--src/indicator-notifications.c69
-rw-r--r--src/settings.h4
4 files changed, 87 insertions, 58 deletions
diff --git a/data/org.ayatana.indicator.notifications.gschema.xml.in.in b/data/org.ayatana.indicator.notifications.gschema.xml.in.in
index c7b6277..db9777a 100644
--- a/data/org.ayatana.indicator.notifications.gschema.xml.in.in
+++ b/data/org.ayatana.indicator.notifications.gschema.xml.in.in
@@ -15,6 +15,11 @@
<_summary>Clear notifications on middle click</_summary>
<_description>Normally when middle clicking the notification icon, the unread status will be toggled if the queue is not empty. With this option enabled, the notification queue will be cleared instead.</_description>
</key>
+ <key name="do-not-disturb" type="b">
+ <default>false</default>
+ <summary>Enable do-not-disturb mode</summary>
+ <description>On supported desktops enables do-not-disturb mode on the notification daemon.</description>
+ </key>
<key name="hide-indicator" type="b">
<default>false</default>
<_summary>Hide the indicator</_summary>
diff --git a/src/indicator-notifications-settings.c b/src/indicator-notifications-settings.c
index 4a36f52..3e9517c 100644
--- a/src/indicator-notifications-settings.c
+++ b/src/indicator-notifications-settings.c
@@ -13,9 +13,6 @@
#define SCHEMA_KEY "schema-key"
-#define MATE_SCHEMA "org.mate.NotificationDaemon"
-#define MATE_KEY_DND "do-not-disturb"
-
#define COLUMN_APPNAME 0
typedef struct
@@ -54,11 +51,6 @@ static gboolean foreach_check_duplicates(GtkTreeModel *model, GtkTreePath *path,
static gboolean foreach_build_array(GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer user_data);
-/* Mate Functions */
-static gboolean has_mate_dnd();
-static gboolean get_mate_dnd();
-static void mate_dnd_button_toggled_cb(GtkToggleButton *button, gpointer user_data);
-
/* Callbacks */
static void blacklist_add_clicked_cb(GtkButton *button, gpointer user_data);
static void blacklist_remove_clicked_cb(GtkButton *button, gpointer user_data);
@@ -155,47 +147,6 @@ foreach_build_array(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, g
return FALSE;
}
-static gboolean
-has_mate_dnd()
-{
- /* Check if we can access the mate do-not-disturb key */
- GSettingsSchemaSource *source = g_settings_schema_source_get_default();
- if (source == NULL) {
- return FALSE;
- }
-
- /* Lookup the schema */
- GSettingsSchema *schema = g_settings_schema_source_lookup(source, MATE_SCHEMA, FALSE);
-
- /* Couldn't find the schema */
- if (schema == NULL) {
- return FALSE;
- }
-
- /* Found the schema, make sure we have the do-not-disturb key */
- gboolean result = g_settings_schema_has_key(schema, MATE_KEY_DND);
- g_settings_schema_unref(schema);
-
- return result;
-}
-
-static gboolean
-get_mate_dnd()
-{
- GSettings *settings = g_settings_new(MATE_SCHEMA);
- gboolean result = g_settings_get_boolean(settings, MATE_KEY_DND);
- g_object_unref(settings);
- return result;
-}
-
-static void
-mate_dnd_button_toggled_cb(GtkToggleButton *button, gpointer user_data)
-{
- GSettings *settings = g_settings_new(MATE_SCHEMA);
- g_settings_set_boolean(settings, MATE_KEY_DND, gtk_toggle_button_get_active(button));
- g_object_unref(settings);
-}
-
static void
blacklist_add_clicked_cb(GtkButton *button, gpointer user_data)
{
@@ -279,7 +230,7 @@ indicator_notifications_settings_activate(GApplication *app)
GtkWidget *vbox;
GtkWidget *button_cmc;
GtkWidget *button_hide_ind;
- GtkWidget *button_mate_dnd;
+ GtkWidget *button_dnd;
GtkWidget *spin;
GtkWidget *spin_label;
GtkWidget *blacklist_label;
@@ -341,14 +292,14 @@ indicator_notifications_settings_activate(GApplication *app)
gtk_box_pack_start(GTK_BOX(vbox), button_hide_ind, FALSE, FALSE, 4);
gtk_widget_show(button_hide_ind);
- /* mate do-not-disturb */
- if (has_mate_dnd()) {
- button_mate_dnd = gtk_check_button_new_with_label(_("Mate Desktop Do Not Disturb"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_mate_dnd), get_mate_dnd());
- g_signal_connect(button_mate_dnd, "toggled", G_CALLBACK(mate_dnd_button_toggled_cb), NULL);
- gtk_box_pack_start(GTK_BOX(vbox), button_mate_dnd, FALSE, FALSE, 4);
- gtk_widget_show(button_mate_dnd);
- }
+ /* do-not-disturb */
+ button_dnd = gtk_check_button_new_with_label(_("Do not disturb"));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_dnd),
+ g_settings_get_boolean(self->settings, NOTIFICATIONS_KEY_DND));
+ g_object_set_data(G_OBJECT(button_dnd), SCHEMA_KEY, NOTIFICATIONS_KEY_DND);
+ g_signal_connect(button_dnd, "toggled", G_CALLBACK(button_toggled_cb), self->settings);
+ gtk_box_pack_start(GTK_BOX(vbox), button_dnd, FALSE, FALSE, 4);
+ gtk_widget_show(button_dnd);
/* max-items */
/* FIXME: indicator does not change max items until restart... */
diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c
index ab9e900..ef8aff4 100644
--- a/src/indicator-notifications.c
+++ b/src/indicator-notifications.c
@@ -61,6 +61,7 @@ struct _IndicatorNotificationsPrivate {
GList *hidden_items;
gboolean clear_on_middle_click;
+ gboolean do_not_disturb;
gboolean have_unread;
gboolean hide_indicator;
@@ -118,6 +119,8 @@ static void update_indicator_visibility(IndicatorNotifications *self);
static void load_blacklist_hints(IndicatorNotifications *self);
static void save_blacklist_hints(IndicatorNotifications *self);
static void update_blacklist_hints(IndicatorNotifications *self, Notification *notification);
+static void update_do_not_disturb(IndicatorNotifications *self);
+static void settings_try_set_boolean(const gchar *schema, const gchar *key, gboolean value);
/* Callbacks */
static void clear_item_activated_cb(GtkMenuItem *menuitem, gpointer user_data);
@@ -206,9 +209,11 @@ indicator_notifications_init(IndicatorNotifications *self)
/* Connect to GSettings */
self->priv->settings = g_settings_new(NOTIFICATIONS_SCHEMA);
self->priv->clear_on_middle_click = g_settings_get_boolean(self->priv->settings, NOTIFICATIONS_KEY_CLEAR_MC);
+ self->priv->do_not_disturb = g_settings_get_boolean(self->priv->settings, NOTIFICATIONS_KEY_DND);
self->priv->hide_indicator = g_settings_get_boolean(self->priv->settings, NOTIFICATIONS_KEY_HIDE_INDICATOR);
self->priv->max_items = g_settings_get_int(self->priv->settings, NOTIFICATIONS_KEY_MAX_ITEMS);
update_blacklist(self);
+ update_do_not_disturb(self);
g_signal_connect(self->priv->settings, "changed", G_CALLBACK(setting_changed_cb), self);
/* Set up blacklist hints */
@@ -599,6 +604,66 @@ update_blacklist_hints(IndicatorNotifications *self, Notification *notification)
}
/**
+ * update_do_not_disturb:
+ * @self: the indicator object
+ *
+ * Updates the icon with the do-not-disturb version and sets do-not-disturb options
+ * on external notification daemons that are supported.
+ **/
+static void
+update_do_not_disturb(IndicatorNotifications *self)
+{
+ g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self));
+
+ /* TODO: update icons here */
+
+ /* Mate do-not-disturb support */
+ settings_try_set_boolean(MATE_SCHEMA, MATE_KEY_DND, self->priv->do_not_disturb);
+}
+
+/**
+ * settings_try_set_boolean:
+ * @schema: the GSettings schema
+ * @key: the GSettings key
+ * @value: the boolean value
+ *
+ * Checks to see if the schema and key exist before setting the value.
+ */
+static void
+settings_try_set_boolean(const gchar *schema, const gchar *key, gboolean value)
+{
+ /* Check if we can access the schema */
+ GSettingsSchemaSource *source = g_settings_schema_source_get_default();
+ if (source == NULL) {
+ return;
+ }
+
+ /* Lookup the schema */
+ GSettingsSchema *source_schema = g_settings_schema_source_lookup(source, schema, FALSE);
+
+ /* Couldn't find the schema */
+ if (source_schema == NULL) {
+ return;
+ }
+
+ /* Found the schema, make sure we have the key */
+ if (g_settings_schema_has_key(source_schema, key)) {
+ /* Make sure the key is of boolean type */
+ GSettingsSchemaKey *source_key = g_settings_schema_get_key(source_schema, key);
+
+ if (g_variant_type_equal(g_settings_schema_key_get_value_type(source_key), G_VARIANT_TYPE_BOOLEAN)) {
+ /* Set the value */
+ GSettings *settings = g_settings_new(schema);
+ g_settings_set_boolean(settings, key, value);
+ g_object_unref(settings);
+ }
+
+ g_settings_schema_key_unref(source_key);
+ }
+ g_settings_schema_unref(source_schema);
+}
+
+/**
* clear_item_activated_cb:
* @menuitem: the clear menuitem
* @user_data: the indicator object
@@ -662,6 +727,10 @@ setting_changed_cb(GSettings *settings, gchar *key, gpointer user_data)
self->priv->hide_indicator = g_settings_get_boolean(settings, NOTIFICATIONS_KEY_HIDE_INDICATOR);
update_indicator_visibility(self);
}
+ else if(g_strcmp0(key, NOTIFICATIONS_KEY_DND) == 0) {
+ self->priv->do_not_disturb = g_settings_get_boolean(settings, NOTIFICATIONS_KEY_DND);
+ update_do_not_disturb(self);
+ }
else if(g_strcmp0(key, NOTIFICATIONS_KEY_CLEAR_MC) == 0) {
self->priv->clear_on_middle_click = g_settings_get_boolean(self->priv->settings, NOTIFICATIONS_KEY_CLEAR_MC);
}
diff --git a/src/settings.h b/src/settings.h
index 53b9780..90945e1 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -9,7 +9,11 @@
#define NOTIFICATIONS_KEY_BLACKLIST "blacklist"
#define NOTIFICATIONS_KEY_BLACKLIST_HINTS "blacklist-hints"
#define NOTIFICATIONS_KEY_CLEAR_MC "clear-on-middle-click"
+#define NOTIFICATIONS_KEY_DND "do-not-disturb"
#define NOTIFICATIONS_KEY_HIDE_INDICATOR "hide-indicator"
#define NOTIFICATIONS_KEY_MAX_ITEMS "max-items"
+#define MATE_SCHEMA "org.mate.NotificationDaemon"
+#define MATE_KEY_DND "do-not-disturb"
+
#endif