From e4bf77f46267730d5c2e771b5dcef6a338eaf88e Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Thu, 20 Aug 2020 09:32:00 +0200 Subject: Add blacklist hints for recent application names. --- src/indicator-notifications-settings.c | 43 ++++++++++++++ src/indicator-notifications.c | 102 +++++++++++++++++++++++++++++++++ src/settings.h | 11 ++-- 3 files changed, 151 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/indicator-notifications-settings.c b/src/indicator-notifications-settings.c index 439413e..b01a709 100644 --- a/src/indicator-notifications-settings.c +++ b/src/indicator-notifications-settings.c @@ -44,6 +44,7 @@ static void indicator_notifications_settings_activate(GApplication *app); /* Utility Functions */ static void load_blacklist(IndicatorNotificationsSettings *self); +static void load_blacklist_hints(IndicatorNotificationsSettings *self); static void save_blacklist(IndicatorNotificationsSettings *self); static gboolean foreach_check_duplicates(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data); @@ -55,6 +56,7 @@ static void blacklist_add_clicked_cb(GtkButton *button, gpointer user_data); static void blacklist_remove_clicked_cb(GtkButton *button, gpointer user_data); static void button_toggled_cb(GtkToggleButton *button, gpointer user_data); static void max_items_changed_cb(GtkSpinButton *button, gpointer user_data); +static gboolean blacklist_entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data); static void load_blacklist(IndicatorNotificationsSettings *self) @@ -75,6 +77,26 @@ load_blacklist(IndicatorNotificationsSettings *self) g_strfreev(items); } +static void +load_blacklist_hints(IndicatorNotificationsSettings *self) +{ + GtkEntryCompletion *completion = gtk_entry_get_completion(GTK_ENTRY(self->blacklist_entry)); + GtkListStore *list = GTK_LIST_STORE(gtk_entry_completion_get_model(completion)); + GtkTreeIter iter; + gchar **items; + + gtk_list_store_clear(list); + + items = g_settings_get_strv(self->settings, NOTIFICATIONS_KEY_BLACKLIST_HINTS); + + for (int i = 0; items[i] != NULL; i++) { + gtk_list_store_append(list, &iter); + gtk_list_store_set(list, &iter, 0, items[i], -1); + } + + g_strfreev(items); +} + static void save_blacklist(IndicatorNotificationsSettings *self) { @@ -191,6 +213,15 @@ max_items_changed_cb(GtkSpinButton *button, gpointer user_data) g_settings_set_int(settings, NOTIFICATIONS_KEY_MAX_ITEMS, value); } +static gboolean +blacklist_entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + IndicatorNotificationsSettings *self = (IndicatorNotificationsSettings *) user_data; + load_blacklist_hints(self); + g_signal_emit_by_name(widget, "changed", NULL); + return FALSE; +} + static void indicator_notifications_settings_activate(GApplication *app) { @@ -209,6 +240,8 @@ indicator_notifications_settings_activate(GApplication *app) GtkWidget *hbox; GtkWidget *button_3; GtkWidget *button_4; + GtkEntryCompletion *entry_completion; + GtkListStore *entry_list; IndicatorNotificationsSettings *self = (IndicatorNotificationsSettings *) app; @@ -309,6 +342,16 @@ indicator_notifications_settings_activate(GApplication *app) self->blacklist_entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(hbox), self->blacklist_entry, TRUE, TRUE, 0); gtk_widget_show(self->blacklist_entry); + + entry_completion = gtk_entry_completion_new(); + entry_list = gtk_list_store_new(1, G_TYPE_STRING); + gtk_entry_completion_set_model(entry_completion, GTK_TREE_MODEL(entry_list)); + gtk_entry_completion_set_text_column(entry_completion, 0); + gtk_entry_completion_set_minimum_key_length(entry_completion, 0); + gtk_entry_set_completion(GTK_ENTRY(self->blacklist_entry), entry_completion); + /* When we focus the entry, emit the changed signal so we get the hints immediately */ + /* also update the blacklist hints from gsettings */ + g_signal_connect(self->blacklist_entry, "focus-in-event", G_CALLBACK(blacklist_entry_focus_in_cb), self); } static void diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c index 07ccd26..ab9e900 100644 --- a/src/indicator-notifications.c +++ b/src/indicator-notifications.c @@ -77,6 +77,8 @@ struct _IndicatorNotificationsPrivate { GHashTable *blacklist; + GList *blacklist_hints; + GSettings *settings; }; @@ -86,6 +88,8 @@ struct _IndicatorNotificationsPrivate { #define INDICATOR_ICON_READ "ayatana-indicator-notification-read" #define INDICATOR_ICON_UNREAD "ayatana-indicator-notification-unread" +#define HINT_MAX 10 + GType indicator_notifications_get_type(void); /* Indicator Class Functions */ @@ -111,6 +115,9 @@ static void set_unread(IndicatorNotifications *self, gboolean unread); static void update_blacklist(IndicatorNotifications *self); static void update_clear_item_markup(IndicatorNotifications *self); 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); /* Callbacks */ static void clear_item_activated_cb(GtkMenuItem *menuitem, gpointer user_data); @@ -203,6 +210,10 @@ indicator_notifications_init(IndicatorNotifications *self) self->priv->max_items = g_settings_get_int(self->priv->settings, NOTIFICATIONS_KEY_MAX_ITEMS); update_blacklist(self); g_signal_connect(self->priv->settings, "changed", G_CALLBACK(setting_changed_cb), self); + + /* Set up blacklist hints */ + self->priv->blacklist_hints = NULL; + load_blacklist_hints(self); } static void @@ -245,6 +256,11 @@ indicator_notifications_dispose(GObject *object) self->priv->blacklist = NULL; } + if(self->priv->blacklist_hints != NULL) { + g_list_free_full(self->priv->blacklist_hints, g_free); + self->priv->blacklist_hints = NULL; + } + G_OBJECT_CLASS (indicator_notifications_parent_class)->dispose (object); return; } @@ -500,6 +516,88 @@ update_indicator_visibility(IndicatorNotifications *self) } } +/** + * load_blacklist_hints: + * @self: the indicator object + * + * Loads the blacklist hints from gsettings + **/ +static void +load_blacklist_hints(IndicatorNotifications *self) +{ + g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); + g_return_if_fail(self->priv->blacklist_hints == NULL); + + gchar **items = g_settings_get_strv(self->priv->settings, NOTIFICATIONS_KEY_BLACKLIST_HINTS); + int i; + + for (i = 0; items[i] != NULL; i++) { + self->priv->blacklist_hints = g_list_prepend(self->priv->blacklist_hints, items[i]); + } + + g_free(items); +} + +/** + * save_blacklist_hints: + * @self: the indicator object + * + * Saves the blacklist hints to gsettings + **/ +static void +save_blacklist_hints(IndicatorNotifications *self) +{ + g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); + + gchar *hints[HINT_MAX + 1]; + int i = 0; + + GList *l; + for (l = self->priv->blacklist_hints; (l != NULL) && (i < HINT_MAX); l = l->next, i++) { + hints[i] = (gchar *) l->data; + } + + hints[i] = NULL; + + g_settings_set_strv(self->priv->settings, NOTIFICATIONS_KEY_BLACKLIST_HINTS, (const gchar **) hints); +} + +/** + * update_blacklist_hints: + * @self: the indicator object + * + * Adds an application name to the hints + **/ +static void +update_blacklist_hints(IndicatorNotifications *self, Notification *notification) +{ + g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); + g_return_if_fail(IS_NOTIFICATION(notification)); + + const gchar *appname = notification_get_app_name(notification); + + /* Avoid duplicates */ + GList *l; + for (l = self->priv->blacklist_hints; l != NULL; l = l->next) { + if (g_strcmp0(appname, (const gchar *) l->data) == 0) + return; + } + + /* Add the appname */ + self->priv->blacklist_hints = g_list_prepend(self->priv->blacklist_hints, g_strdup(appname)); + + /* Keep only a reasonable number */ + while (g_list_length(self->priv->blacklist_hints) > HINT_MAX) { + GList *last = g_list_last(self->priv->blacklist_hints); + g_free(last->data); + self->priv->blacklist_hints = g_list_delete_link(self->priv->blacklist_hints, last); + } + + /* Save the hints */ + /* FIXME: maybe don't do this every update */ + save_blacklist_hints(self); +} + /** * clear_item_activated_cb: * @menuitem: the clear menuitem @@ -625,6 +723,10 @@ message_received_cb(DBusSpy *spy, Notification *note, gpointer user_data) return; } + /* Save a hint for the appname */ + update_blacklist_hints(self, note); + + /* Create the menuitem */ GtkWidget *item = notification_menuitem_new(); notification_menuitem_set_from_notification(NOTIFICATION_MENUITEM(item), note); g_signal_connect(item, NOTIFICATION_MENUITEM_SIGNAL_CLICKED, G_CALLBACK(notification_clicked_cb), self); diff --git a/src/settings.h b/src/settings.h index 87e341f..53b9780 100644 --- a/src/settings.h +++ b/src/settings.h @@ -5,10 +5,11 @@ #ifndef __SETTINGS_H__ #define __SETTINGS_H__ -#define NOTIFICATIONS_SCHEMA "org.ayatana.indicator.notifications" -#define NOTIFICATIONS_KEY_BLACKLIST "blacklist" -#define NOTIFICATIONS_KEY_CLEAR_MC "clear-on-middle-click" -#define NOTIFICATIONS_KEY_HIDE_INDICATOR "hide-indicator" -#define NOTIFICATIONS_KEY_MAX_ITEMS "max-items" +#define NOTIFICATIONS_SCHEMA "org.ayatana.indicator.notifications" +#define NOTIFICATIONS_KEY_BLACKLIST "blacklist" +#define NOTIFICATIONS_KEY_BLACKLIST_HINTS "blacklist-hints" +#define NOTIFICATIONS_KEY_CLEAR_MC "clear-on-middle-click" +#define NOTIFICATIONS_KEY_HIDE_INDICATOR "hide-indicator" +#define NOTIFICATIONS_KEY_MAX_ITEMS "max-items" #endif -- cgit v1.2.3 From 77fb1c1f8f3f2856f9c991198cb231f22d19b40e Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Fri, 30 Aug 2019 23:23:53 -0400 Subject: Add mate do-not-disturb option if available. --- src/indicator-notifications-settings.c | 107 +++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/indicator-notifications-settings.c b/src/indicator-notifications-settings.c index b01a709..4a36f52 100644 --- a/src/indicator-notifications-settings.c +++ b/src/indicator-notifications-settings.c @@ -13,6 +13,9 @@ #define SCHEMA_KEY "schema-key" +#define MATE_SCHEMA "org.mate.NotificationDaemon" +#define MATE_KEY_DND "do-not-disturb" + #define COLUMN_APPNAME 0 typedef struct @@ -51,6 +54,11 @@ 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); @@ -147,6 +155,47 @@ 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) { @@ -228,8 +277,9 @@ indicator_notifications_settings_activate(GApplication *app) GtkWidget *window; GtkWidget *frame; GtkWidget *vbox; - GtkWidget *button_1; - GtkWidget *button_2; + GtkWidget *button_cmc; + GtkWidget *button_hide_ind; + GtkWidget *button_mate_dnd; GtkWidget *spin; GtkWidget *spin_label; GtkWidget *blacklist_label; @@ -238,8 +288,8 @@ indicator_notifications_settings_activate(GApplication *app) GtkTreeViewColumn *column; GtkCellRenderer *renderer; GtkWidget *hbox; - GtkWidget *button_3; - GtkWidget *button_4; + GtkWidget *button_blacklist_rem; + GtkWidget *button_blacklist_add; GtkEntryCompletion *entry_completion; GtkListStore *entry_list; @@ -274,22 +324,31 @@ indicator_notifications_settings_activate(GApplication *app) gtk_widget_show(vbox); /* clear-on-middle-click */ - button_1 = gtk_check_button_new_with_label(_("Clear notifications on middle click")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_1), + button_cmc = gtk_check_button_new_with_label(_("Clear notifications on middle click")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_cmc), g_settings_get_boolean(self->settings, NOTIFICATIONS_KEY_CLEAR_MC)); - g_object_set_data(G_OBJECT(button_1), SCHEMA_KEY, NOTIFICATIONS_KEY_CLEAR_MC); - g_signal_connect(button_1, "toggled", G_CALLBACK(button_toggled_cb), self->settings); - gtk_box_pack_start(GTK_BOX(vbox), button_1, FALSE, FALSE, 4); - gtk_widget_show(button_1); + g_object_set_data(G_OBJECT(button_cmc), SCHEMA_KEY, NOTIFICATIONS_KEY_CLEAR_MC); + g_signal_connect(button_cmc, "toggled", G_CALLBACK(button_toggled_cb), self->settings); + gtk_box_pack_start(GTK_BOX(vbox), button_cmc, FALSE, FALSE, 4); + gtk_widget_show(button_cmc); /* hide-indicator */ - button_2 = gtk_check_button_new_with_label(_("Hide indicator")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_2), + button_hide_ind = gtk_check_button_new_with_label(_("Hide indicator")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_hide_ind), g_settings_get_boolean(self->settings, NOTIFICATIONS_KEY_HIDE_INDICATOR)); - g_object_set_data(G_OBJECT(button_2), SCHEMA_KEY, NOTIFICATIONS_KEY_HIDE_INDICATOR); - g_signal_connect(button_2, "toggled", G_CALLBACK(button_toggled_cb), self->settings); - gtk_box_pack_start(GTK_BOX(vbox), button_2, FALSE, FALSE, 4); - gtk_widget_show(button_2); + g_object_set_data(G_OBJECT(button_hide_ind), SCHEMA_KEY, NOTIFICATIONS_KEY_HIDE_INDICATOR); + g_signal_connect(button_hide_ind, "toggled", G_CALLBACK(button_toggled_cb), self->settings); + 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); + } /* max-items */ /* FIXME: indicator does not change max items until restart... */ @@ -329,15 +388,15 @@ indicator_notifications_settings_activate(GApplication *app) gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_widget_show(hbox); - button_3 = gtk_button_new_with_label(_("Remove")); - g_signal_connect(button_3, "clicked", G_CALLBACK(blacklist_remove_clicked_cb), self); - gtk_box_pack_start(GTK_BOX(hbox), button_3, FALSE, FALSE, 2); - gtk_widget_show(button_3); + button_blacklist_rem = gtk_button_new_with_label(_("Remove")); + g_signal_connect(button_blacklist_rem, "clicked", G_CALLBACK(blacklist_remove_clicked_cb), self); + gtk_box_pack_start(GTK_BOX(hbox), button_blacklist_rem, FALSE, FALSE, 2); + gtk_widget_show(button_blacklist_rem); - button_4 = gtk_button_new_with_label(_("Add")); - g_signal_connect(button_4, "clicked", G_CALLBACK(blacklist_add_clicked_cb), self); - gtk_box_pack_start(GTK_BOX(hbox), button_4, FALSE, FALSE, 2); - gtk_widget_show(button_4); + button_blacklist_add = gtk_button_new_with_label(_("Add")); + g_signal_connect(button_blacklist_add, "clicked", G_CALLBACK(blacklist_add_clicked_cb), self); + gtk_box_pack_start(GTK_BOX(hbox), button_blacklist_add, FALSE, FALSE, 2); + gtk_widget_show(button_blacklist_add); self->blacklist_entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(hbox), self->blacklist_entry, TRUE, TRUE, 0); -- cgit v1.2.3 From 82ca9185e9894121cc1d13bb06e7dc0e09dfd01b Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Thu, 20 Aug 2020 09:35:44 +0200 Subject: 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). --- src/indicator-notifications-settings.c | 67 +++++---------------------------- src/indicator-notifications.c | 69 ++++++++++++++++++++++++++++++++++ src/settings.h | 4 ++ 3 files changed, 82 insertions(+), 58 deletions(-) (limited to 'src') 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 */ @@ -598,6 +603,66 @@ update_blacklist_hints(IndicatorNotifications *self, Notification *notification) save_blacklist_hints(self); } +/** + * 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 @@ -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 -- cgit v1.2.3 From 8f195248f8b7ca0cc6c87c02188c4ed360964143 Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Thu, 20 Aug 2020 09:38:41 +0200 Subject: Add do-not-disturb mode read/unread icons. --- src/indicator-notifications.c | 46 +++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c index ef8aff4..db53df7 100644 --- a/src/indicator-notifications.c +++ b/src/indicator-notifications.c @@ -86,8 +86,10 @@ struct _IndicatorNotificationsPrivate { #include "settings.h" #define INDICATOR_ICON_SIZE 22 -#define INDICATOR_ICON_READ "ayatana-indicator-notification-read" -#define INDICATOR_ICON_UNREAD "ayatana-indicator-notification-unread" +#define INDICATOR_ICON_READ "ayatana-indicator-notification-read" +#define INDICATOR_ICON_UNREAD "ayatana-indicator-notification-unread" +#define INDICATOR_ICON_READ_DND "ayatana-indicator-notification-read-dnd" +#define INDICATOR_ICON_UNREAD_DND "ayatana-indicator-notification-unread-dnd" #define HINT_MAX 10 @@ -113,6 +115,7 @@ static void clear_menuitems(IndicatorNotifications *self); static void insert_menuitem(IndicatorNotifications *self, GtkWidget *item); static void remove_menuitem(IndicatorNotifications *self, GtkWidget *item); static void set_unread(IndicatorNotifications *self, gboolean unread); +static void update_unread(IndicatorNotifications *self); static void update_blacklist(IndicatorNotifications *self); static void update_clear_item_markup(IndicatorNotifications *self); static void update_indicator_visibility(IndicatorNotifications *self); @@ -213,7 +216,6 @@ indicator_notifications_init(IndicatorNotifications *self) 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 */ @@ -284,7 +286,8 @@ get_image(IndicatorObject *io) if(self->priv->image == NULL) { self->priv->image = GTK_IMAGE(gtk_image_new()); - set_unread(self, FALSE); + /* We have to wait until the image is created to update do-not-disturb the first time */ + update_do_not_disturb(self); update_indicator_visibility(self); } @@ -438,14 +441,37 @@ set_unread(IndicatorNotifications *self, gboolean unread) { g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); - if(unread) { - gtk_image_set_from_icon_name(self->priv->image, INDICATOR_ICON_UNREAD, GTK_ICON_SIZE_MENU); + self->priv->have_unread = unread; + update_unread(self); +} + +/** + * update_unread: + * @self: the indicator object + * + * Updates the indicator icons. + **/ +static void +update_unread(IndicatorNotifications *self) +{ + g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); + + if(self->priv->have_unread) { + if (self->priv->do_not_disturb) { + gtk_image_set_from_icon_name(self->priv->image, INDICATOR_ICON_UNREAD_DND, GTK_ICON_SIZE_MENU); + } + else { + gtk_image_set_from_icon_name(self->priv->image, INDICATOR_ICON_UNREAD, GTK_ICON_SIZE_MENU); + } } else { - gtk_image_set_from_icon_name(self->priv->image, INDICATOR_ICON_READ, GTK_ICON_SIZE_MENU); + if (self->priv->do_not_disturb) { + gtk_image_set_from_icon_name(self->priv->image, INDICATOR_ICON_READ_DND, GTK_ICON_SIZE_MENU); + } + else { + gtk_image_set_from_icon_name(self->priv->image, INDICATOR_ICON_READ, GTK_ICON_SIZE_MENU); + } } - - self->priv->have_unread = unread; } /** @@ -615,7 +641,7 @@ update_do_not_disturb(IndicatorNotifications *self) { g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); - /* TODO: update icons here */ + update_unread(self); /* Mate do-not-disturb support */ settings_try_set_boolean(MATE_SCHEMA, MATE_KEY_DND, self->priv->do_not_disturb); -- cgit v1.2.3 From d1b76b9aa5330cc27a0f3ecefc57becfbe8ea02e Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Thu, 5 Sep 2019 09:23:54 -0400 Subject: Discard notifications when indicator is hidden. --- src/indicator-notifications.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c index db53df7..2ab4083 100644 --- a/src/indicator-notifications.c +++ b/src/indicator-notifications.c @@ -805,6 +805,12 @@ message_received_cb(DBusSpy *spy, Notification *note, gpointer user_data) g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(user_data)); IndicatorNotifications *self = INDICATOR_NOTIFICATIONS(user_data); + /* Discard notifications if we are hidden */ + if(self->priv->hide_indicator) { + g_object_unref(note); + return; + } + /* Discard useless notifications */ if(notification_is_private(note) || notification_is_empty(note)) { g_object_unref(note); -- cgit v1.2.3 From 3fbc05dc4cbf564644f2500508e642eb80f07264 Mon Sep 17 00:00:00 2001 From: Tasos Sahanidis Date: Thu, 20 Aug 2020 09:41:52 +0200 Subject: Add option to swap Settings and Clear. --- src/indicator-notifications-settings.c | 10 ++++++++++ src/indicator-notifications.c | 30 ++++++++++++++++++++++++++++++ src/settings.h | 15 ++++++++------- 3 files changed, 48 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/indicator-notifications-settings.c b/src/indicator-notifications-settings.c index 3e9517c..46fd37b 100644 --- a/src/indicator-notifications-settings.c +++ b/src/indicator-notifications-settings.c @@ -231,6 +231,7 @@ indicator_notifications_settings_activate(GApplication *app) GtkWidget *button_cmc; GtkWidget *button_hide_ind; GtkWidget *button_dnd; + GtkWidget *button_swap_clr_s; GtkWidget *spin; GtkWidget *spin_label; GtkWidget *blacklist_label; @@ -301,6 +302,15 @@ indicator_notifications_settings_activate(GApplication *app) gtk_box_pack_start(GTK_BOX(vbox), button_dnd, FALSE, FALSE, 4); gtk_widget_show(button_dnd); + /* swap-clear-settings */ + button_swap_clr_s = gtk_check_button_new_with_label(_("Swap \"Clear\" and \"Settings\" items")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_swap_clr_s), + g_settings_get_boolean(self->settings, NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS)); + g_object_set_data(G_OBJECT(button_swap_clr_s), SCHEMA_KEY, NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS); + g_signal_connect(button_swap_clr_s, "toggled", G_CALLBACK(button_toggled_cb), self->settings); + gtk_box_pack_start(GTK_BOX(vbox), button_swap_clr_s, FALSE, FALSE, 4); + gtk_widget_show(button_swap_clr_s); + /* max-items */ /* FIXME: indicator does not change max items until restart... */ spin_label = gtk_label_new(_("Maximum number of visible notifications")); diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c index 2ab4083..67dcb96 100644 --- a/src/indicator-notifications.c +++ b/src/indicator-notifications.c @@ -64,6 +64,7 @@ struct _IndicatorNotificationsPrivate { gboolean do_not_disturb; gboolean have_unread; gboolean hide_indicator; + gboolean swap_clear_settings; gint max_items; @@ -124,6 +125,7 @@ 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); +static void swap_clear_settings_items(IndicatorNotifications *self); /* Callbacks */ static void clear_item_activated_cb(GtkMenuItem *menuitem, gpointer user_data); @@ -216,6 +218,9 @@ indicator_notifications_init(IndicatorNotifications *self) 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); + self->priv->swap_clear_settings = g_settings_get_boolean(self->priv->settings, NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS); + if(self->priv->swap_clear_settings) + swap_clear_settings_items(self); g_signal_connect(self->priv->settings, "changed", G_CALLBACK(setting_changed_cb), self); /* Set up blacklist hints */ @@ -689,6 +694,27 @@ settings_try_set_boolean(const gchar *schema, const gchar *key, gboolean value) g_settings_schema_unref(source_schema); } +/** + * swap_clear_settings_items: + * @self: the indicator object + * + * Swaps the position of the clear and settings items. + **/ +static void +swap_clear_settings_items(IndicatorNotifications *self) +{ + g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); + + // Pick which widget to move + GtkWidget *widget = self->priv->settings_item; + if(self->priv->swap_clear_settings) + widget = self->priv->clear_item; + + gtk_container_remove(GTK_CONTAINER(self->priv->menu), g_object_ref(widget)); + gtk_menu_shell_append(GTK_MENU_SHELL(self->priv->menu), widget); + g_object_unref(widget); +} + /** * clear_item_activated_cb: * @menuitem: the clear menuitem @@ -763,6 +789,10 @@ setting_changed_cb(GSettings *settings, gchar *key, gpointer user_data) else if(g_strcmp0(key, NOTIFICATIONS_KEY_BLACKLIST) == 0) { update_blacklist(self); } + else if(g_strcmp0(key, NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS) == 0) { + self->priv->swap_clear_settings = g_settings_get_boolean(self->priv->settings, NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS); + swap_clear_settings_items(self); + } /* TODO: Trim or extend the notifications list based on "max-items" key * (Currently requires a restart) */ } diff --git a/src/settings.h b/src/settings.h index 90945e1..4eb0030 100644 --- a/src/settings.h +++ b/src/settings.h @@ -5,13 +5,14 @@ #ifndef __SETTINGS_H__ #define __SETTINGS_H__ -#define NOTIFICATIONS_SCHEMA "org.ayatana.indicator.notifications" -#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 NOTIFICATIONS_SCHEMA "org.ayatana.indicator.notifications" +#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 NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS "swap-clear-settings" #define MATE_SCHEMA "org.mate.NotificationDaemon" #define MATE_KEY_DND "do-not-disturb" -- cgit v1.2.3 From aca92b39f32f0d850f5a74b79591a587273c2168 Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Thu, 20 Aug 2020 09:45:37 +0200 Subject: Rename blacklist to filter-list. --- src/indicator-notifications-settings.c | 126 ++++++++++++++++----------------- src/indicator-notifications.c | 98 ++++++++++++------------- src/settings.h | 4 +- 3 files changed, 114 insertions(+), 114 deletions(-) (limited to 'src') diff --git a/src/indicator-notifications-settings.c b/src/indicator-notifications-settings.c index 46fd37b..510a0ec 100644 --- a/src/indicator-notifications-settings.c +++ b/src/indicator-notifications-settings.c @@ -21,8 +21,8 @@ typedef struct GSettings *settings; - GtkWidget *blacklist_treeview; - GtkWidget *blacklist_entry; + GtkWidget *filter_list_treeview; + GtkWidget *filter_list_entry; /* GtkTreeModel foreach variables */ gboolean result; @@ -43,31 +43,31 @@ static void indicator_notifications_settings_dispose(GObject *object); static void indicator_notifications_settings_activate(GApplication *app); /* Utility Functions */ -static void load_blacklist(IndicatorNotificationsSettings *self); -static void load_blacklist_hints(IndicatorNotificationsSettings *self); -static void save_blacklist(IndicatorNotificationsSettings *self); +static void load_filter_list(IndicatorNotificationsSettings *self); +static void load_filter_list_hints(IndicatorNotificationsSettings *self); +static void save_filter_list(IndicatorNotificationsSettings *self); static gboolean foreach_check_duplicates(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data); static gboolean foreach_build_array(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, 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); +static void filter_list_add_clicked_cb(GtkButton *button, gpointer user_data); +static void filter_list_remove_clicked_cb(GtkButton *button, gpointer user_data); static void button_toggled_cb(GtkToggleButton *button, gpointer user_data); static void max_items_changed_cb(GtkSpinButton *button, gpointer user_data); -static gboolean blacklist_entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data); +static gboolean filter_list_entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data); static void -load_blacklist(IndicatorNotificationsSettings *self) +load_filter_list(IndicatorNotificationsSettings *self) { - GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->blacklist_treeview))); + GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->filter_list_treeview))); GtkTreeIter iter; gchar **items; gtk_list_store_clear(list); - items = g_settings_get_strv(self->settings, NOTIFICATIONS_KEY_BLACKLIST); + items = g_settings_get_strv(self->settings, NOTIFICATIONS_KEY_FILTER_LIST); for (int i = 0; items[i] != NULL; i++) { gtk_list_store_append(list, &iter); @@ -78,16 +78,16 @@ load_blacklist(IndicatorNotificationsSettings *self) } static void -load_blacklist_hints(IndicatorNotificationsSettings *self) +load_filter_list_hints(IndicatorNotificationsSettings *self) { - GtkEntryCompletion *completion = gtk_entry_get_completion(GTK_ENTRY(self->blacklist_entry)); + GtkEntryCompletion *completion = gtk_entry_get_completion(GTK_ENTRY(self->filter_list_entry)); GtkListStore *list = GTK_LIST_STORE(gtk_entry_completion_get_model(completion)); GtkTreeIter iter; gchar **items; gtk_list_store_clear(list); - items = g_settings_get_strv(self->settings, NOTIFICATIONS_KEY_BLACKLIST_HINTS); + items = g_settings_get_strv(self->settings, NOTIFICATIONS_KEY_FILTER_LIST_HINTS); for (int i = 0; items[i] != NULL; i++) { gtk_list_store_append(list, &iter); @@ -98,19 +98,19 @@ load_blacklist_hints(IndicatorNotificationsSettings *self) } static void -save_blacklist(IndicatorNotificationsSettings *self) +save_filter_list(IndicatorNotificationsSettings *self) { - GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->blacklist_treeview))); + GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->filter_list_treeview))); gchar **items; - /* build an array of the blacklist items */ + /* build an array of the filter list items */ self->array = g_ptr_array_new(); gtk_tree_model_foreach(GTK_TREE_MODEL(list), foreach_build_array, self); g_ptr_array_add(self->array, NULL); items = (gchar **) g_ptr_array_free(self->array, FALSE); self->array = NULL; - g_settings_set_strv(self->settings, NOTIFICATIONS_KEY_BLACKLIST, (const gchar **) items); + g_settings_set_strv(self->settings, NOTIFICATIONS_KEY_FILTER_LIST, (const gchar **) items); g_strfreev(items); } @@ -148,14 +148,14 @@ foreach_build_array(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, g } static void -blacklist_add_clicked_cb(GtkButton *button, gpointer user_data) +filter_list_add_clicked_cb(GtkButton *button, gpointer user_data) { IndicatorNotificationsSettings *self = (IndicatorNotificationsSettings *) user_data; - GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->blacklist_treeview))); + GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->filter_list_treeview))); GtkTreeIter iter; /* strip off the leading and trailing whitespace in case of user error */ - self->text = g_strdup(gtk_entry_get_text(GTK_ENTRY(self->blacklist_entry))); + self->text = g_strdup(gtk_entry_get_text(GTK_ENTRY(self->filter_list_entry))); g_strstrip(self->text); if (strlen(self->text) > 0) { @@ -166,12 +166,12 @@ blacklist_add_clicked_cb(GtkButton *button, gpointer user_data) if (self->result == FALSE) { gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, COLUMN_APPNAME, self->text, -1); - save_blacklist(self); + save_filter_list(self); } } /* clear the entry */ - gtk_entry_set_text(GTK_ENTRY(self->blacklist_entry), ""); + gtk_entry_set_text(GTK_ENTRY(self->filter_list_entry), ""); /* cleanup text */ g_free(self->text); @@ -179,19 +179,19 @@ blacklist_add_clicked_cb(GtkButton *button, gpointer user_data) } static void -blacklist_remove_clicked_cb(GtkButton *button, gpointer user_data) +filter_list_remove_clicked_cb(GtkButton *button, gpointer user_data) { IndicatorNotificationsSettings *self = (IndicatorNotificationsSettings *) user_data; - GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->blacklist_treeview))); + GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(self->filter_list_treeview))); GtkTreeIter iter; GtkTreeSelection *selection; - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self->blacklist_treeview)); + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self->filter_list_treeview)); if (gtk_tree_selection_get_selected(selection, NULL, &iter) == TRUE) { gtk_list_store_remove(list, &iter); - save_blacklist(self); + save_filter_list(self); } } @@ -214,10 +214,10 @@ max_items_changed_cb(GtkSpinButton *button, gpointer user_data) } static gboolean -blacklist_entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) +filter_list_entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) { IndicatorNotificationsSettings *self = (IndicatorNotificationsSettings *) user_data; - load_blacklist_hints(self); + load_filter_list_hints(self); g_signal_emit_by_name(widget, "changed", NULL); return FALSE; } @@ -234,14 +234,14 @@ indicator_notifications_settings_activate(GApplication *app) GtkWidget *button_swap_clr_s; GtkWidget *spin; GtkWidget *spin_label; - GtkWidget *blacklist_label; - GtkListStore *blacklist_list; - GtkWidget *blacklist_scroll; + GtkWidget *filter_list_label; + GtkListStore *filter_list_list; + GtkWidget *filter_list_scroll; GtkTreeViewColumn *column; GtkCellRenderer *renderer; GtkWidget *hbox; - GtkWidget *button_blacklist_rem; - GtkWidget *button_blacklist_add; + GtkWidget *button_filter_list_rem; + GtkWidget *button_filter_list_add; GtkEntryCompletion *entry_completion; GtkListStore *entry_list; @@ -323,55 +323,55 @@ indicator_notifications_settings_activate(GApplication *app) gtk_box_pack_start(GTK_BOX(vbox), spin, FALSE, FALSE, 4); gtk_widget_show(spin); - /* blacklist */ - blacklist_label = gtk_label_new(_("Discard notifications by application name")); - gtk_box_pack_start(GTK_BOX(vbox), blacklist_label, FALSE, FALSE, 4); - gtk_widget_show(blacklist_label); + /* filter-list */ + filter_list_label = gtk_label_new(_("Discard notifications by application name")); + gtk_box_pack_start(GTK_BOX(vbox), filter_list_label, FALSE, FALSE, 4); + gtk_widget_show(filter_list_label); - blacklist_scroll = gtk_scrolled_window_new(NULL, NULL); - gtk_box_pack_start(GTK_BOX(vbox), blacklist_scroll, TRUE, TRUE, 4); - gtk_widget_show(blacklist_scroll); + filter_list_scroll = gtk_scrolled_window_new(NULL, NULL); + gtk_box_pack_start(GTK_BOX(vbox), filter_list_scroll, TRUE, TRUE, 4); + gtk_widget_show(filter_list_scroll); - blacklist_list = gtk_list_store_new(1, G_TYPE_STRING); + filter_list_list = gtk_list_store_new(1, G_TYPE_STRING); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("appname", renderer, "text", COLUMN_APPNAME, NULL); - self->blacklist_treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(blacklist_list)); - g_object_unref(blacklist_list); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self->blacklist_treeview), FALSE); - gtk_tree_view_append_column(GTK_TREE_VIEW(self->blacklist_treeview), column); - load_blacklist(self); - gtk_container_add(GTK_CONTAINER(blacklist_scroll), self->blacklist_treeview); - gtk_widget_show(self->blacklist_treeview); + self->filter_list_treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(filter_list_list)); + g_object_unref(filter_list_list); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self->filter_list_treeview), FALSE); + gtk_tree_view_append_column(GTK_TREE_VIEW(self->filter_list_treeview), column); + load_filter_list(self); + gtk_container_add(GTK_CONTAINER(filter_list_scroll), self->filter_list_treeview); + gtk_widget_show(self->filter_list_treeview); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_widget_show(hbox); - button_blacklist_rem = gtk_button_new_with_label(_("Remove")); - g_signal_connect(button_blacklist_rem, "clicked", G_CALLBACK(blacklist_remove_clicked_cb), self); - gtk_box_pack_start(GTK_BOX(hbox), button_blacklist_rem, FALSE, FALSE, 2); - gtk_widget_show(button_blacklist_rem); + button_filter_list_rem = gtk_button_new_with_label(_("Remove")); + g_signal_connect(button_filter_list_rem, "clicked", G_CALLBACK(filter_list_remove_clicked_cb), self); + gtk_box_pack_start(GTK_BOX(hbox), button_filter_list_rem, FALSE, FALSE, 2); + gtk_widget_show(button_filter_list_rem); - button_blacklist_add = gtk_button_new_with_label(_("Add")); - g_signal_connect(button_blacklist_add, "clicked", G_CALLBACK(blacklist_add_clicked_cb), self); - gtk_box_pack_start(GTK_BOX(hbox), button_blacklist_add, FALSE, FALSE, 2); - gtk_widget_show(button_blacklist_add); + button_filter_list_add = gtk_button_new_with_label(_("Add")); + g_signal_connect(button_filter_list_add, "clicked", G_CALLBACK(filter_list_add_clicked_cb), self); + gtk_box_pack_start(GTK_BOX(hbox), button_filter_list_add, FALSE, FALSE, 2); + gtk_widget_show(button_filter_list_add); - self->blacklist_entry = gtk_entry_new(); - gtk_box_pack_start(GTK_BOX(hbox), self->blacklist_entry, TRUE, TRUE, 0); - gtk_widget_show(self->blacklist_entry); + self->filter_list_entry = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox), self->filter_list_entry, TRUE, TRUE, 0); + gtk_widget_show(self->filter_list_entry); entry_completion = gtk_entry_completion_new(); entry_list = gtk_list_store_new(1, G_TYPE_STRING); gtk_entry_completion_set_model(entry_completion, GTK_TREE_MODEL(entry_list)); gtk_entry_completion_set_text_column(entry_completion, 0); gtk_entry_completion_set_minimum_key_length(entry_completion, 0); - gtk_entry_set_completion(GTK_ENTRY(self->blacklist_entry), entry_completion); + gtk_entry_set_completion(GTK_ENTRY(self->filter_list_entry), entry_completion); /* When we focus the entry, emit the changed signal so we get the hints immediately */ - /* also update the blacklist hints from gsettings */ - g_signal_connect(self->blacklist_entry, "focus-in-event", G_CALLBACK(blacklist_entry_focus_in_cb), self); + /* also update the filter list hints from gsettings */ + g_signal_connect(self->filter_list_entry, "focus-in-event", G_CALLBACK(filter_list_entry_focus_in_cb), self); } static void diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c index 67dcb96..e5f2951 100644 --- a/src/indicator-notifications.c +++ b/src/indicator-notifications.c @@ -77,9 +77,9 @@ struct _IndicatorNotificationsPrivate { DBusSpy *spy; - GHashTable *blacklist; + GHashTable *filter_list; - GList *blacklist_hints; + GList *filter_list_hints; GSettings *settings; }; @@ -117,12 +117,12 @@ static void insert_menuitem(IndicatorNotifications *self, GtkWidget *item); static void remove_menuitem(IndicatorNotifications *self, GtkWidget *item); static void set_unread(IndicatorNotifications *self, gboolean unread); static void update_unread(IndicatorNotifications *self); -static void update_blacklist(IndicatorNotifications *self); +static void update_filter_list(IndicatorNotifications *self); static void update_clear_item_markup(IndicatorNotifications *self); 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 load_filter_list_hints(IndicatorNotifications *self); +static void save_filter_list_hints(IndicatorNotifications *self); +static void update_filter_list_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); static void swap_clear_settings_items(IndicatorNotifications *self); @@ -208,8 +208,8 @@ indicator_notifications_init(IndicatorNotifications *self) self->priv->spy = dbus_spy_new(); g_signal_connect(self->priv->spy, DBUS_SPY_SIGNAL_MESSAGE_RECEIVED, G_CALLBACK(message_received_cb), self); - /* Initialize an empty blacklist */ - self->priv->blacklist = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + /* Initialize an empty filter list */ + self->priv->filter_list = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); /* Connect to GSettings */ self->priv->settings = g_settings_new(NOTIFICATIONS_SCHEMA); @@ -217,15 +217,15 @@ indicator_notifications_init(IndicatorNotifications *self) 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_filter_list(self); self->priv->swap_clear_settings = g_settings_get_boolean(self->priv->settings, NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS); if(self->priv->swap_clear_settings) swap_clear_settings_items(self); g_signal_connect(self->priv->settings, "changed", G_CALLBACK(setting_changed_cb), self); - /* Set up blacklist hints */ - self->priv->blacklist_hints = NULL; - load_blacklist_hints(self); + /* Set up filter-list hints */ + self->priv->filter_list_hints = NULL; + load_filter_list_hints(self); } static void @@ -263,14 +263,14 @@ indicator_notifications_dispose(GObject *object) self->priv->settings = NULL; } - if(self->priv->blacklist != NULL) { - g_hash_table_unref(self->priv->blacklist); - self->priv->blacklist = NULL; + if(self->priv->filter_list != NULL) { + g_hash_table_unref(self->priv->filter_list); + self->priv->filter_list = NULL; } - if(self->priv->blacklist_hints != NULL) { - g_list_free_full(self->priv->blacklist_hints, g_free); - self->priv->blacklist_hints = NULL; + if(self->priv->filter_list_hints != NULL) { + g_list_free_full(self->priv->filter_list_hints, g_free); + self->priv->filter_list_hints = NULL; } G_OBJECT_CLASS (indicator_notifications_parent_class)->dispose (object); @@ -480,24 +480,24 @@ update_unread(IndicatorNotifications *self) } /** - * update_blacklist: + * update_filter_list: * @self: the indicator object * - * Updates the blacklist from GSettings. This currently does not filter already + * Updates the filter list from GSettings. This currently does not filter already * allowed messages. It only applies to messages received in the future. **/ static void -update_blacklist(IndicatorNotifications *self) +update_filter_list(IndicatorNotifications *self) { g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); - g_return_if_fail(self->priv->blacklist != NULL); + g_return_if_fail(self->priv->filter_list != NULL); - g_hash_table_remove_all(self->priv->blacklist); - gchar **items = g_settings_get_strv(self->priv->settings, NOTIFICATIONS_KEY_BLACKLIST); + g_hash_table_remove_all(self->priv->filter_list); + gchar **items = g_settings_get_strv(self->priv->settings, NOTIFICATIONS_KEY_FILTER_LIST); int i; for(i = 0; items[i] != NULL; i++) { - g_hash_table_insert(self->priv->blacklist, g_strdup(items[i]), NULL); + g_hash_table_insert(self->priv->filter_list, g_strdup(items[i]), NULL); } g_strfreev(items); @@ -553,35 +553,35 @@ update_indicator_visibility(IndicatorNotifications *self) } /** - * load_blacklist_hints: + * load_filter_list_hints: * @self: the indicator object * - * Loads the blacklist hints from gsettings + * Loads the filter list hints from gsettings **/ static void -load_blacklist_hints(IndicatorNotifications *self) +load_filter_list_hints(IndicatorNotifications *self) { g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); - g_return_if_fail(self->priv->blacklist_hints == NULL); + g_return_if_fail(self->priv->filter_list_hints == NULL); - gchar **items = g_settings_get_strv(self->priv->settings, NOTIFICATIONS_KEY_BLACKLIST_HINTS); + gchar **items = g_settings_get_strv(self->priv->settings, NOTIFICATIONS_KEY_FILTER_LIST_HINTS); int i; for (i = 0; items[i] != NULL; i++) { - self->priv->blacklist_hints = g_list_prepend(self->priv->blacklist_hints, items[i]); + self->priv->filter_list_hints = g_list_prepend(self->priv->filter_list_hints, items[i]); } g_free(items); } /** - * save_blacklist_hints: + * save_filter_list_hints: * @self: the indicator object * - * Saves the blacklist hints to gsettings + * Saves the filter list hints to gsettings **/ static void -save_blacklist_hints(IndicatorNotifications *self) +save_filter_list_hints(IndicatorNotifications *self) { g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); @@ -589,23 +589,23 @@ save_blacklist_hints(IndicatorNotifications *self) int i = 0; GList *l; - for (l = self->priv->blacklist_hints; (l != NULL) && (i < HINT_MAX); l = l->next, i++) { + for (l = self->priv->filter_list_hints; (l != NULL) && (i < HINT_MAX); l = l->next, i++) { hints[i] = (gchar *) l->data; } hints[i] = NULL; - g_settings_set_strv(self->priv->settings, NOTIFICATIONS_KEY_BLACKLIST_HINTS, (const gchar **) hints); + g_settings_set_strv(self->priv->settings, NOTIFICATIONS_KEY_FILTER_LIST_HINTS, (const gchar **) hints); } /** - * update_blacklist_hints: + * update_filter_list_hints: * @self: the indicator object * * Adds an application name to the hints **/ static void -update_blacklist_hints(IndicatorNotifications *self, Notification *notification) +update_filter_list_hints(IndicatorNotifications *self, Notification *notification) { g_return_if_fail(IS_INDICATOR_NOTIFICATIONS(self)); g_return_if_fail(IS_NOTIFICATION(notification)); @@ -614,24 +614,24 @@ update_blacklist_hints(IndicatorNotifications *self, Notification *notification) /* Avoid duplicates */ GList *l; - for (l = self->priv->blacklist_hints; l != NULL; l = l->next) { + for (l = self->priv->filter_list_hints; l != NULL; l = l->next) { if (g_strcmp0(appname, (const gchar *) l->data) == 0) return; } /* Add the appname */ - self->priv->blacklist_hints = g_list_prepend(self->priv->blacklist_hints, g_strdup(appname)); + self->priv->filter_list_hints = g_list_prepend(self->priv->filter_list_hints, g_strdup(appname)); /* Keep only a reasonable number */ - while (g_list_length(self->priv->blacklist_hints) > HINT_MAX) { - GList *last = g_list_last(self->priv->blacklist_hints); + while (g_list_length(self->priv->filter_list_hints) > HINT_MAX) { + GList *last = g_list_last(self->priv->filter_list_hints); g_free(last->data); - self->priv->blacklist_hints = g_list_delete_link(self->priv->blacklist_hints, last); + self->priv->filter_list_hints = g_list_delete_link(self->priv->filter_list_hints, last); } /* Save the hints */ /* FIXME: maybe don't do this every update */ - save_blacklist_hints(self); + save_filter_list_hints(self); } /** @@ -786,8 +786,8 @@ setting_changed_cb(GSettings *settings, gchar *key, gpointer user_data) 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); } - else if(g_strcmp0(key, NOTIFICATIONS_KEY_BLACKLIST) == 0) { - update_blacklist(self); + else if(g_strcmp0(key, NOTIFICATIONS_KEY_FILTER_LIST) == 0) { + update_filter_list(self); } else if(g_strcmp0(key, NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS) == 0) { self->priv->swap_clear_settings = g_settings_get_boolean(self->priv->settings, NOTIFICATIONS_KEY_SWAP_CLEAR_SETTINGS); @@ -847,15 +847,15 @@ message_received_cb(DBusSpy *spy, Notification *note, gpointer user_data) return; } - /* Discard notifications on the blacklist */ - if(self->priv->blacklist != NULL && g_hash_table_contains(self->priv->blacklist, + /* Discard notifications on the filter list */ + if(self->priv->filter_list != NULL && g_hash_table_contains(self->priv->filter_list, notification_get_app_name(note))) { g_object_unref(note); return; } /* Save a hint for the appname */ - update_blacklist_hints(self, note); + update_filter_list_hints(self, note); /* Create the menuitem */ GtkWidget *item = notification_menuitem_new(); diff --git a/src/settings.h b/src/settings.h index 4eb0030..43f0383 100644 --- a/src/settings.h +++ b/src/settings.h @@ -6,8 +6,8 @@ #define __SETTINGS_H__ #define NOTIFICATIONS_SCHEMA "org.ayatana.indicator.notifications" -#define NOTIFICATIONS_KEY_BLACKLIST "blacklist" -#define NOTIFICATIONS_KEY_BLACKLIST_HINTS "blacklist-hints" +#define NOTIFICATIONS_KEY_BLACKLIST "filter-list" +#define NOTIFICATIONS_KEY_BLACKLIST_HINTS "filter-list-hints" #define NOTIFICATIONS_KEY_CLEAR_MC "clear-on-middle-click" #define NOTIFICATIONS_KEY_DND "do-not-disturb" #define NOTIFICATIONS_KEY_HIDE_INDICATOR "hide-indicator" -- cgit v1.2.3 From ab788386e4d79b0199741388e55d8a4032f6e9cc Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Fri, 21 Aug 2020 14:58:52 +0200 Subject: src/indicator-notifications: settings_try_set_boolean(): Enable the recursive schema lookup so we have a better chance of finding it. --- src/indicator-notifications.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c index e5f2951..56ddd7a 100644 --- a/src/indicator-notifications.c +++ b/src/indicator-notifications.c @@ -670,7 +670,7 @@ settings_try_set_boolean(const gchar *schema, const gchar *key, gboolean value) } /* Lookup the schema */ - GSettingsSchema *source_schema = g_settings_schema_source_lookup(source, schema, FALSE); + GSettingsSchema *source_schema = g_settings_schema_source_lookup(source, schema, TRUE); /* Couldn't find the schema */ if (source_schema == NULL) { -- cgit v1.2.3 From d50e5a3a331fcf14c9b06da7fdce443eacecd1de Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Thu, 20 Aug 2020 14:08:43 +0200 Subject: Update translation files (for blacklist/filter-list renaming and do-not-disturb feature). --- src/settings.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/settings.h b/src/settings.h index 43f0383..9663c8d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -6,8 +6,8 @@ #define __SETTINGS_H__ #define NOTIFICATIONS_SCHEMA "org.ayatana.indicator.notifications" -#define NOTIFICATIONS_KEY_BLACKLIST "filter-list" -#define NOTIFICATIONS_KEY_BLACKLIST_HINTS "filter-list-hints" +#define NOTIFICATIONS_KEY_FILTER_LIST "filter-list" +#define NOTIFICATIONS_KEY_FILTER_LIST_HINTS "filter-list-hints" #define NOTIFICATIONS_KEY_CLEAR_MC "clear-on-middle-click" #define NOTIFICATIONS_KEY_DND "do-not-disturb" #define NOTIFICATIONS_KEY_HIDE_INDICATOR "hide-indicator" -- cgit v1.2.3