From d68268a7200b0f9ecf93566f1da9beca58ca4c1d Mon Sep 17 00:00:00 2001 From: Fabien Broquard Date: Tue, 2 Oct 2018 20:35:14 +0200 Subject: na-tray: add preferences dialog and applet menu entry The only option in the preferences is a GtkSpinButton for the user to be able to set the icon sizes easily without having to use dconf-editor. --- applets/notification_area/Makefile.am | 1 + applets/notification_area/main.c | 95 ++++++++++++ applets/notification_area/na.gresource.xml | 1 + .../notification_area/notification-area-menu.xml | 1 + .../notification-area-preferences-dialog.ui | 164 +++++++++++++++++++++ 5 files changed, 262 insertions(+) create mode 100644 applets/notification_area/notification-area-preferences-dialog.ui (limited to 'applets') diff --git a/applets/notification_area/Makefile.am b/applets/notification_area/Makefile.am index 67d4f8c6..57ee0a3b 100644 --- a/applets/notification_area/Makefile.am +++ b/applets/notification_area/Makefile.am @@ -97,6 +97,7 @@ notification_area_gschemas_in = org.mate.panel.applet.notification-area.gschema. gsettings_SCHEMAS = $(notification_area_gschemas_in:.xml.in=.xml) ui_FILES = \ + notification-area-preferences-dialog.ui \ notification-area-menu.xml na-resources.c: na.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/na.gresource.xml) diff --git a/applets/notification_area/main.c b/applets/notification_area/main.c index 9fc63e04..8d97ee59 100644 --- a/applets/notification_area/main.c +++ b/applets/notification_area/main.c @@ -40,10 +40,19 @@ #define NOTIFICATION_AREA_ICON "mate-panel-notification-area" +typedef struct +{ + GtkWidget *preferences_dialog; + GtkWidget *min_icon_size_spin; +} NAPreferencesDialog; + struct _NaTrayAppletPrivate { GtkWidget *grid; + NAPreferencesDialog *dialog; + GtkBuilder *builder; + GSettings *settings; gint min_icon_size; @@ -116,6 +125,10 @@ gsettings_changed_min_icon_size (GSettings *settings, { applet->priv->min_icon_size = g_settings_get_int (settings, key); + if (applet->priv->dialog) + gtk_spin_button_set_value (GTK_SPIN_BUTTON (applet->priv->dialog->min_icon_size_spin), + applet->priv->min_icon_size); + na_grid_set_min_icon_size (NA_GRID (applet->priv->grid), applet->priv->min_icon_size); } @@ -126,6 +139,78 @@ setup_gsettings (NaTrayApplet *applet) g_signal_connect (applet->priv->settings, "changed::" KEY_MIN_ICON_SIZE, G_CALLBACK (gsettings_changed_min_icon_size), applet); } +static void +na_preferences_dialog_min_icon_size_changed (NaTrayApplet *applet, + GtkSpinButton *spin_button) +{ + applet->priv->min_icon_size = gtk_spin_button_get_value_as_int (spin_button); + g_settings_set_int (applet->priv->settings, KEY_MIN_ICON_SIZE, applet->priv->min_icon_size); +} + +static gboolean +na_preferences_dialog_hide_event (GtkWidget *widget, + GdkEvent *event, + NaTrayApplet *applet) +{ + gtk_widget_hide (applet->priv->dialog->preferences_dialog); + return TRUE; +} + +static void +na_preferences_dialog_response (NaTrayApplet *applet, + int response, + GtkWidget *preferences_dialog) +{ + switch (response) + { + case GTK_RESPONSE_CLOSE: + gtk_widget_hide (preferences_dialog); + break; + default: + break; + } +} + +static void +ensure_prefs_window_is_created (NaTrayApplet *applet) +{ + if (applet->priv->dialog) + return; + + applet->priv->dialog = g_new0 (NAPreferencesDialog, 1); + + applet->priv->dialog->preferences_dialog = GTK_WIDGET (gtk_builder_get_object (applet->priv->builder, "notification_area_preferences_dialog")); + + gtk_window_set_icon_name (GTK_WINDOW (applet->priv->dialog->preferences_dialog), NOTIFICATION_AREA_ICON); + + applet->priv->dialog->min_icon_size_spin = GTK_WIDGET (gtk_builder_get_object (applet->priv->builder, "min_icon_size_spin")); + g_return_if_fail (applet->priv->dialog->min_icon_size_spin != NULL); + + gtk_spin_button_set_range (GTK_SPIN_BUTTON (applet->priv->dialog->min_icon_size_spin), 7, 100); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (applet->priv->dialog->min_icon_size_spin), applet->priv->min_icon_size); + + g_signal_connect_swapped (applet->priv->dialog->min_icon_size_spin, "value_changed", + G_CALLBACK (na_preferences_dialog_min_icon_size_changed), + applet); + + g_signal_connect_swapped (applet->priv->dialog->preferences_dialog, "response", + G_CALLBACK (na_preferences_dialog_response), applet); + + g_signal_connect (G_OBJECT (applet->priv->dialog->preferences_dialog), "delete_event", + G_CALLBACK (na_preferences_dialog_hide_event), applet); +} + +static void +properties_dialog (GtkAction *action, + NaTrayApplet *applet) +{ + ensure_prefs_window_is_created (applet); + + gtk_window_set_screen (GTK_WINDOW (applet->priv->dialog->preferences_dialog), + gtk_widget_get_screen (GTK_WIDGET (applet))); + gtk_window_present (GTK_WINDOW (applet->priv->dialog->preferences_dialog)); +} + static void help_cb(GtkAction* action, NaTrayApplet* applet) { GError* error = NULL; @@ -173,6 +258,7 @@ static void about_cb(GtkAction* action, NaTrayApplet* applet) "Vincent Untz ", "Alberts Muktupāvels", "Colomban Wendling ", + "Fabien Broquard ", NULL }; @@ -200,6 +286,9 @@ static void about_cb(GtkAction* action, NaTrayApplet* applet) } static const GtkActionEntry menu_actions [] = { + { "SystemTrayPreferences", "document-properties", N_("_Preferences"), + NULL, NULL, + G_CALLBACK (properties_dialog) }, { "SystemTrayHelp", "help-browser", N_("_Help"), NULL, NULL, G_CALLBACK (help_cb) }, @@ -230,6 +319,10 @@ na_tray_applet_realize (GtkWidget *widget) // load min icon size gsettings_changed_min_icon_size (applet->priv->settings, KEY_MIN_ICON_SIZE, applet); + + applet->priv->builder = gtk_builder_new (); + gtk_builder_set_translation_domain (applet->priv->builder, GETTEXT_PACKAGE); + gtk_builder_add_from_resource (applet->priv->builder, NA_RESOURCE_PATH "notification-area-preferences-dialog.ui", NULL); } static void @@ -239,6 +332,8 @@ na_tray_applet_dispose (GObject *object) g_clear_object (&NA_TRAY_APPLET (object)->priv->sn_watcher); #endif + g_clear_object (&NA_TRAY_APPLET (object)->priv->builder); + G_OBJECT_CLASS (na_tray_applet_parent_class)->dispose (object); } diff --git a/applets/notification_area/na.gresource.xml b/applets/notification_area/na.gresource.xml index 1b20172a..e65ca5d0 100644 --- a/applets/notification_area/na.gresource.xml +++ b/applets/notification_area/na.gresource.xml @@ -1,6 +1,7 @@ + notification-area-preferences-dialog.ui notification-area-menu.xml diff --git a/applets/notification_area/notification-area-menu.xml b/applets/notification_area/notification-area-menu.xml index fdbcc83f..18b624ab 100644 --- a/applets/notification_area/notification-area-menu.xml +++ b/applets/notification_area/notification-area-menu.xml @@ -1,3 +1,4 @@ + diff --git a/applets/notification_area/notification-area-preferences-dialog.ui b/applets/notification_area/notification-area-preferences-dialog.ui new file mode 100644 index 00000000..d4be2a0c --- /dev/null +++ b/applets/notification_area/notification-area-preferences-dialog.ui @@ -0,0 +1,164 @@ + + + + + + + + + + + 7 + 100 + 26 + 1 + 1 + + + False + 5 + Notification Area Preferences + False + center + dialog + + + + + + True + False + vertical + 2 + + + True + False + + + gtk-close + True + True + True + True + False + True + + + False + False + 1 + + + + + False + False + end + 0 + + + + + True + True + 5 + False + False + + + True + False + 6 + 6 + 6 + 6 + 6 + 12 + + + True + False + start + _Minimum Icon Size: + True + min_icon_size_spin + + + 0 + 0 + + + + + True + True + True + 26 + adjustment1 + 1 + True + 26 + + + 1 + 0 + + + + + True + False + pixels + + + 2 + 0 + + + + + + + + + + + + + + + + False + True + 1 + + + + + + closebutton + + + -- cgit v1.2.1