Skip to content
Permalink
Browse files

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.
  • Loading branch information...
braikar authored and lukefromdc committed Oct 2, 2018
1 parent 10b9c30 commit d68268a7200b0f9ecf93566f1da9beca58ca4c1d
@@ -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)
@@ -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 <vuntz@gnome.org>",
"Alberts Muktupāvels",
"Colomban Wendling <cwendling@hypra.fr>",
"Fabien Broquard <braikar@gmail.com>",
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);
}

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/mate/panel/applet/na">
<file compressed="true">notification-area-preferences-dialog.ui</file>
<file compressed="true">notification-area-menu.xml</file>
</gresource>
</gresources>
@@ -1,3 +1,4 @@
<menuitem name="Notification Area Preferences Item" action="SystemTrayPreferences" />
<menuitem name="Notification Area Help Item" action="SystemTrayHelp" />
<menuitem name="Notification Area About Item" action="SystemTrayAbout" />

@@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1
mate-panel - panel-properties-dialog
Copyright (C) Mate Developer
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Author: Wolfgang Ulbrich
-->
<interface>
<requires lib="gtk+" version="3.14"/>
<!-- interface-license-type gplv2 -->
<!-- interface-name mate-panel -->
<!-- interface-description panel-properties-dialog -->
<!-- interface-copyright Mate Developer -->
<!-- interface-authors Wolfgang Ulbrich -->
<object class="GtkAdjustment" id="adjustment1">
<property name="lower">7</property>
<property name="upper">100</property>
<property name="value">26</property>
<property name="step_increment">1</property>
<property name="page_increment">1</property>
</object>
<object class="GtkDialog" id="notification_area_preferences_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Notification Area Preferences</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="closebutton">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkNotebook" id="notebook">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">5</property>
<property name="show_tabs">False</property>
<property name="show_border">False</property>
<child>
<object class="GtkGrid" id="general_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel" id="min_icon_size_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">_Minimum Icon Size:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">min_icon_size_spin</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="min_icon_size_spin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="text" translatable="yes">26</property>
<property name="adjustment">adjustment1</property>
<property name="climb_rate">1</property>
<property name="numeric">True</property>
<property name="value">26</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="min_icon_size_label_pixels">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">pixels</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
<child type="tab">
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child type="tab">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-7">closebutton</action-widget>
</action-widgets>
</object>
</interface>
@@ -14,6 +14,7 @@ applets/fish/fish.c
[type: gettext/gsettings]applets/fish/org.mate.panel.applet.fish.gschema.xml.in
[type: gettext/ini]applets/fish/org.mate.panel.FishApplet.mate-panel-applet.in.in
applets/notification_area/main.c
[type: gettext/glade]applets/notification_area/notification-area-preferences-dialog.ui
[type: gettext/gsettings]applets/notification_area/org.mate.panel.applet.notification-area.gschema.xml.in
[type: gettext/ini]applets/notification_area/org.mate.panel.NotificationAreaApplet.mate-panel-applet.in.in
[type: gettext/gsettings]applets/wncklet/org.mate.panel.applet.window-list.gschema.xml.in

0 comments on commit d68268a

Please sign in to comment.
You can’t perform that action at this time.