Skip to content

Commit d68268a

Browse files
braikarlukefromdc
authored andcommitted
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.
1 parent 10b9c30 commit d68268a

File tree

6 files changed

+263
-0
lines changed

6 files changed

+263
-0
lines changed

applets/notification_area/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ notification_area_gschemas_in = org.mate.panel.applet.notification-area.gschema.
9797
gsettings_SCHEMAS = $(notification_area_gschemas_in:.xml.in=.xml)
9898

9999
ui_FILES = \
100+
notification-area-preferences-dialog.ui \
100101
notification-area-menu.xml
101102

102103
na-resources.c: na.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/na.gresource.xml)

applets/notification_area/main.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@
4040

4141
#define NOTIFICATION_AREA_ICON "mate-panel-notification-area"
4242

43+
typedef struct
44+
{
45+
GtkWidget *preferences_dialog;
46+
GtkWidget *min_icon_size_spin;
47+
} NAPreferencesDialog;
48+
4349
struct _NaTrayAppletPrivate
4450
{
4551
GtkWidget *grid;
4652

53+
NAPreferencesDialog *dialog;
54+
GtkBuilder *builder;
55+
4756
GSettings *settings;
4857
gint min_icon_size;
4958

@@ -116,6 +125,10 @@ gsettings_changed_min_icon_size (GSettings *settings,
116125
{
117126
applet->priv->min_icon_size = g_settings_get_int (settings, key);
118127

128+
if (applet->priv->dialog)
129+
gtk_spin_button_set_value (GTK_SPIN_BUTTON (applet->priv->dialog->min_icon_size_spin),
130+
applet->priv->min_icon_size);
131+
119132
na_grid_set_min_icon_size (NA_GRID (applet->priv->grid), applet->priv->min_icon_size);
120133
}
121134

@@ -126,6 +139,78 @@ setup_gsettings (NaTrayApplet *applet)
126139
g_signal_connect (applet->priv->settings, "changed::" KEY_MIN_ICON_SIZE, G_CALLBACK (gsettings_changed_min_icon_size), applet);
127140
}
128141

142+
static void
143+
na_preferences_dialog_min_icon_size_changed (NaTrayApplet *applet,
144+
GtkSpinButton *spin_button)
145+
{
146+
applet->priv->min_icon_size = gtk_spin_button_get_value_as_int (spin_button);
147+
g_settings_set_int (applet->priv->settings, KEY_MIN_ICON_SIZE, applet->priv->min_icon_size);
148+
}
149+
150+
static gboolean
151+
na_preferences_dialog_hide_event (GtkWidget *widget,
152+
GdkEvent *event,
153+
NaTrayApplet *applet)
154+
{
155+
gtk_widget_hide (applet->priv->dialog->preferences_dialog);
156+
return TRUE;
157+
}
158+
159+
static void
160+
na_preferences_dialog_response (NaTrayApplet *applet,
161+
int response,
162+
GtkWidget *preferences_dialog)
163+
{
164+
switch (response)
165+
{
166+
case GTK_RESPONSE_CLOSE:
167+
gtk_widget_hide (preferences_dialog);
168+
break;
169+
default:
170+
break;
171+
}
172+
}
173+
174+
static void
175+
ensure_prefs_window_is_created (NaTrayApplet *applet)
176+
{
177+
if (applet->priv->dialog)
178+
return;
179+
180+
applet->priv->dialog = g_new0 (NAPreferencesDialog, 1);
181+
182+
applet->priv->dialog->preferences_dialog = GTK_WIDGET (gtk_builder_get_object (applet->priv->builder, "notification_area_preferences_dialog"));
183+
184+
gtk_window_set_icon_name (GTK_WINDOW (applet->priv->dialog->preferences_dialog), NOTIFICATION_AREA_ICON);
185+
186+
applet->priv->dialog->min_icon_size_spin = GTK_WIDGET (gtk_builder_get_object (applet->priv->builder, "min_icon_size_spin"));
187+
g_return_if_fail (applet->priv->dialog->min_icon_size_spin != NULL);
188+
189+
gtk_spin_button_set_range (GTK_SPIN_BUTTON (applet->priv->dialog->min_icon_size_spin), 7, 100);
190+
gtk_spin_button_set_value (GTK_SPIN_BUTTON (applet->priv->dialog->min_icon_size_spin), applet->priv->min_icon_size);
191+
192+
g_signal_connect_swapped (applet->priv->dialog->min_icon_size_spin, "value_changed",
193+
G_CALLBACK (na_preferences_dialog_min_icon_size_changed),
194+
applet);
195+
196+
g_signal_connect_swapped (applet->priv->dialog->preferences_dialog, "response",
197+
G_CALLBACK (na_preferences_dialog_response), applet);
198+
199+
g_signal_connect (G_OBJECT (applet->priv->dialog->preferences_dialog), "delete_event",
200+
G_CALLBACK (na_preferences_dialog_hide_event), applet);
201+
}
202+
203+
static void
204+
properties_dialog (GtkAction *action,
205+
NaTrayApplet *applet)
206+
{
207+
ensure_prefs_window_is_created (applet);
208+
209+
gtk_window_set_screen (GTK_WINDOW (applet->priv->dialog->preferences_dialog),
210+
gtk_widget_get_screen (GTK_WIDGET (applet)));
211+
gtk_window_present (GTK_WINDOW (applet->priv->dialog->preferences_dialog));
212+
}
213+
129214
static void help_cb(GtkAction* action, NaTrayApplet* applet)
130215
{
131216
GError* error = NULL;
@@ -173,6 +258,7 @@ static void about_cb(GtkAction* action, NaTrayApplet* applet)
173258
"Vincent Untz <vuntz@gnome.org>",
174259
"Alberts Muktupāvels",
175260
"Colomban Wendling <cwendling@hypra.fr>",
261+
"Fabien Broquard <braikar@gmail.com>",
176262
NULL
177263
};
178264

@@ -200,6 +286,9 @@ static void about_cb(GtkAction* action, NaTrayApplet* applet)
200286
}
201287

202288
static const GtkActionEntry menu_actions [] = {
289+
{ "SystemTrayPreferences", "document-properties", N_("_Preferences"),
290+
NULL, NULL,
291+
G_CALLBACK (properties_dialog) },
203292
{ "SystemTrayHelp", "help-browser", N_("_Help"),
204293
NULL, NULL,
205294
G_CALLBACK (help_cb) },
@@ -230,6 +319,10 @@ na_tray_applet_realize (GtkWidget *widget)
230319

231320
// load min icon size
232321
gsettings_changed_min_icon_size (applet->priv->settings, KEY_MIN_ICON_SIZE, applet);
322+
323+
applet->priv->builder = gtk_builder_new ();
324+
gtk_builder_set_translation_domain (applet->priv->builder, GETTEXT_PACKAGE);
325+
gtk_builder_add_from_resource (applet->priv->builder, NA_RESOURCE_PATH "notification-area-preferences-dialog.ui", NULL);
233326
}
234327

235328
static void
@@ -239,6 +332,8 @@ na_tray_applet_dispose (GObject *object)
239332
g_clear_object (&NA_TRAY_APPLET (object)->priv->sn_watcher);
240333
#endif
241334

335+
g_clear_object (&NA_TRAY_APPLET (object)->priv->builder);
336+
242337
G_OBJECT_CLASS (na_tray_applet_parent_class)->dispose (object);
243338
}
244339

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<gresources>
33
<gresource prefix="/org/mate/panel/applet/na">
4+
<file compressed="true">notification-area-preferences-dialog.ui</file>
45
<file compressed="true">notification-area-menu.xml</file>
56
</gresource>
67
</gresources>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<menuitem name="Notification Area Preferences Item" action="SystemTrayPreferences" />
12
<menuitem name="Notification Area Help Item" action="SystemTrayHelp" />
23
<menuitem name="Notification Area About Item" action="SystemTrayAbout" />
34

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Generated with glade 3.22.1
3+
4+
mate-panel - panel-properties-dialog
5+
Copyright (C) Mate Developer
6+
7+
This program is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU General Public License
9+
as published by the Free Software Foundation; either version 2
10+
of the License, or (at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
21+
Author: Wolfgang Ulbrich
22+
23+
-->
24+
<interface>
25+
<requires lib="gtk+" version="3.14"/>
26+
<!-- interface-license-type gplv2 -->
27+
<!-- interface-name mate-panel -->
28+
<!-- interface-description panel-properties-dialog -->
29+
<!-- interface-copyright Mate Developer -->
30+
<!-- interface-authors Wolfgang Ulbrich -->
31+
<object class="GtkAdjustment" id="adjustment1">
32+
<property name="lower">7</property>
33+
<property name="upper">100</property>
34+
<property name="value">26</property>
35+
<property name="step_increment">1</property>
36+
<property name="page_increment">1</property>
37+
</object>
38+
<object class="GtkDialog" id="notification_area_preferences_dialog">
39+
<property name="can_focus">False</property>
40+
<property name="border_width">5</property>
41+
<property name="title" translatable="yes">Notification Area Preferences</property>
42+
<property name="resizable">False</property>
43+
<property name="window_position">center</property>
44+
<property name="type_hint">dialog</property>
45+
<child>
46+
<placeholder/>
47+
</child>
48+
<child internal-child="vbox">
49+
<object class="GtkBox" id="dialog-vbox">
50+
<property name="visible">True</property>
51+
<property name="can_focus">False</property>
52+
<property name="orientation">vertical</property>
53+
<property name="spacing">2</property>
54+
<child internal-child="action_area">
55+
<object class="GtkButtonBox" id="dialog-action_area">
56+
<property name="visible">True</property>
57+
<property name="can_focus">False</property>
58+
<child>
59+
<object class="GtkButton" id="closebutton">
60+
<property name="label">gtk-close</property>
61+
<property name="visible">True</property>
62+
<property name="can_focus">True</property>
63+
<property name="has_focus">True</property>
64+
<property name="can_default">True</property>
65+
<property name="receives_default">False</property>
66+
<property name="use_stock">True</property>
67+
</object>
68+
<packing>
69+
<property name="expand">False</property>
70+
<property name="fill">False</property>
71+
<property name="position">1</property>
72+
</packing>
73+
</child>
74+
</object>
75+
<packing>
76+
<property name="expand">False</property>
77+
<property name="fill">False</property>
78+
<property name="pack_type">end</property>
79+
<property name="position">0</property>
80+
</packing>
81+
</child>
82+
<child>
83+
<object class="GtkNotebook" id="notebook">
84+
<property name="visible">True</property>
85+
<property name="can_focus">True</property>
86+
<property name="border_width">5</property>
87+
<property name="show_tabs">False</property>
88+
<property name="show_border">False</property>
89+
<child>
90+
<object class="GtkGrid" id="general_grid">
91+
<property name="visible">True</property>
92+
<property name="can_focus">False</property>
93+
<property name="margin_left">6</property>
94+
<property name="margin_right">6</property>
95+
<property name="margin_top">6</property>
96+
<property name="margin_bottom">6</property>
97+
<property name="row_spacing">6</property>
98+
<property name="column_spacing">12</property>
99+
<child>
100+
<object class="GtkLabel" id="min_icon_size_label">
101+
<property name="visible">True</property>
102+
<property name="can_focus">False</property>
103+
<property name="halign">start</property>
104+
<property name="label" translatable="yes">_Minimum Icon Size:</property>
105+
<property name="use_underline">True</property>
106+
<property name="mnemonic_widget">min_icon_size_spin</property>
107+
</object>
108+
<packing>
109+
<property name="left_attach">0</property>
110+
<property name="top_attach">0</property>
111+
</packing>
112+
</child>
113+
<child>
114+
<object class="GtkSpinButton" id="min_icon_size_spin">
115+
<property name="visible">True</property>
116+
<property name="can_focus">True</property>
117+
<property name="hexpand">True</property>
118+
<property name="text" translatable="yes">26</property>
119+
<property name="adjustment">adjustment1</property>
120+
<property name="climb_rate">1</property>
121+
<property name="numeric">True</property>
122+
<property name="value">26</property>
123+
</object>
124+
<packing>
125+
<property name="left_attach">1</property>
126+
<property name="top_attach">0</property>
127+
</packing>
128+
</child>
129+
<child>
130+
<object class="GtkLabel" id="min_icon_size_label_pixels">
131+
<property name="visible">True</property>
132+
<property name="can_focus">False</property>
133+
<property name="label" translatable="yes">pixels</property>
134+
</object>
135+
<packing>
136+
<property name="left_attach">2</property>
137+
<property name="top_attach">0</property>
138+
</packing>
139+
</child>
140+
</object>
141+
</child>
142+
<child type="tab">
143+
<placeholder/>
144+
</child>
145+
<child>
146+
<placeholder/>
147+
</child>
148+
<child type="tab">
149+
<placeholder/>
150+
</child>
151+
</object>
152+
<packing>
153+
<property name="expand">False</property>
154+
<property name="fill">True</property>
155+
<property name="position">1</property>
156+
</packing>
157+
</child>
158+
</object>
159+
</child>
160+
<action-widgets>
161+
<action-widget response="-7">closebutton</action-widget>
162+
</action-widgets>
163+
</object>
164+
</interface>

po/POTFILES.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ applets/fish/fish.c
1414
[type: gettext/gsettings]applets/fish/org.mate.panel.applet.fish.gschema.xml.in
1515
[type: gettext/ini]applets/fish/org.mate.panel.FishApplet.mate-panel-applet.in.in
1616
applets/notification_area/main.c
17+
[type: gettext/glade]applets/notification_area/notification-area-preferences-dialog.ui
1718
[type: gettext/gsettings]applets/notification_area/org.mate.panel.applet.notification-area.gschema.xml.in
1819
[type: gettext/ini]applets/notification_area/org.mate.panel.NotificationAreaApplet.mate-panel-applet.in.in
1920
[type: gettext/gsettings]applets/wncklet/org.mate.panel.applet.window-list.gschema.xml.in

0 commit comments

Comments
 (0)