annotate xia-icon.c @ 15:3457a401e685

Add NEWS file
author Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
date Fri, 23 Jan 2015 10:58:04 +0100
parents 14f31e92372f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
1 /*
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
2 * Copyright (C) 2013 Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
3 *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
4 * Permission is hereby granted, free of charge, to any person obtaining
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
5 * a copy of this software and associated documentation files (the
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
6 * "Software"), to deal in the Software without restriction, including
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
7 * without limitation the rights to use, copy, modify, merge, publish,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
8 * distribute, sublicense, and/or sell copies of the Software, and to
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
9 * permit persons to whom the Software is furnished to do so, subject to
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
10 * the following conditions:
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
11 *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
12 * The above copyright notice and this permission notice shall be included
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
13 * in all copies or substantial portions of the Software.
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
14 *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
22 */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
23
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
24 #include <glib/gi18n.h>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
25 #include "xia-debug.h"
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
26 #include "xia-inhibitor.h"
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
27 #include "xia-icon.h"
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
28
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
29 G_DEFINE_TYPE(XiaIcon, xia_icon, G_TYPE_OBJECT)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
30
13
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 0
diff changeset
31 #define XIA_ICON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),\
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 0
diff changeset
32 XIA_TYPE_ICON, XiaIconPrivate))
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
33
13
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 0
diff changeset
34 struct _XiaIconPrivate {
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
35 XiaInhibitor *inhibitor;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
36
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
37 GtkStatusIcon *status_icon;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
38 GtkWidget *status_icon_popup_menu;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
39 GtkWidget *check_menu_item_inhibited;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
40 };
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
41
13
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 0
diff changeset
42 static void icon_update(XiaIcon *self);
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 0
diff changeset
43 static GtkWidget * icon_popup_menu_create(XiaIcon *self);
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 0
diff changeset
44 static void icon_popup_menu_popup(GtkStatusIcon *status_icon, guint button,
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
45 guint activate_time, gpointer user_data);
13
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 0
diff changeset
46 static void icon_activate(GtkStatusIcon *status_icon, gpointer user_data);
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
47
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
48 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
49 xia_icon_finalize(GObject *gobject)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
50 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
51 XiaIcon *self = XIA_ICON(gobject);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
52
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
53 gtk_widget_destroy(self->priv->status_icon_popup_menu);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
54 g_object_unref(self->priv->status_icon_popup_menu);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
55 g_object_unref(self->priv->status_icon);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
56 g_object_unref(self->priv->inhibitor);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
57
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
58 G_OBJECT_CLASS(xia_icon_parent_class)->finalize(gobject);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
59 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
60
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
61 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
62 xia_icon_class_init(XiaIconClass *klass)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
63 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
64 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
65
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
66 gobject_class->finalize = xia_icon_finalize;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
67
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
68 g_type_class_add_private(klass, sizeof (XiaIconPrivate));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
69 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
70
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
71 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
72 xia_icon_init(XiaIcon *self)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
73 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
74 self->priv = XIA_ICON_GET_PRIVATE(self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
75
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
76 self->priv->inhibitor = xia_inhibitor_new();
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
77
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
78 self->priv->status_icon = gtk_status_icon_new();
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
79 gtk_status_icon_set_title(self->priv->status_icon,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
80 _("Inhibit automatic power management"));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
81
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
82 self->priv->status_icon_popup_menu = icon_popup_menu_create(self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
83 g_object_ref(self->priv->status_icon_popup_menu);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
84 g_object_ref_sink(GTK_OBJECT(self->priv->status_icon_popup_menu));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
85
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
86 g_signal_connect(G_OBJECT(self->priv->status_icon), "activate",
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
87 G_CALLBACK(icon_activate), self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
88 g_signal_connect(G_OBJECT(self->priv->status_icon), "popup-menu",
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
89 G_CALLBACK(icon_popup_menu_popup), self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
90
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
91 icon_update(self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
92 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
93
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
94 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
95 about_dialog_show(GtkMenuItem *item, gpointer user_data)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
96 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
97 const gchar *copyright = "Copyright \302\251 2013 Guido Berhoerster\n";
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
98 const gchar *comments = _("Allows users to inhibit automatic power "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
99 "management\n\nTo Ai\n");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
100 const gchar *logo_icon_name = "xinhibit-applet";
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
101 const gchar *authors[2] = {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
102 "Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>",
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
103 NULL
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
104 };
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
105 const gchar *license =
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
106 "Copyright \302\251 2013 Guido Berhoerster\n\n"
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
107 "Permission is hereby granted, free of charge, to any person "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
108 "obtaining a copy of this software and associated documentation "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
109 "files (the \"Software\"), to deal in the Software without "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
110 "restriction, including without limitation the rights to use, "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
111 "copy, modify, merge, publish, distribute, sublicense, and/or sell "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
112 "copies of the Software, and to permit persons to whom the "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
113 "Software is furnished to do so, subject to the following "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
114 "conditions:\n\n"
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
115 "The above copyright notice and this permission notice shall be "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
116 "included in all copies or substantial portions of the Software."
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
117 "\n\n"
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
118 "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
119 "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
120 "OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
121 "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
122 "HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
123 "WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
124 "FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
125 "OTHER DEALINGS IN THE SOFTWARE.";
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
126 const gchar *translators = _("translators");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
127
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
128 if (strcmp(translators, "translators") == 0) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
129 translators = NULL;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
130 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
131
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
132 gtk_show_about_dialog(NULL, "version", VERSION, "copyright", copyright,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
133 "logo-icon-name", logo_icon_name, "comments", comments, "authors",
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
134 authors, "translator-credits", translators, "license", license,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
135 "wrap-license", TRUE, NULL);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
136 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
137
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
138 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
139 icon_update(XiaIcon *self)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
140 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
141 gboolean inhibited;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
142
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
143 inhibited = xia_inhibitor_get_inhibited(self->priv->inhibitor);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
144
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
145 g_debug("Updating icon, inhibit: %s", (inhibited) ? "on" : "off");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
146
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
147 gtk_status_icon_set_tooltip_text(self->priv->status_icon, (inhibited) ?
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
148 _("Enable Automatic Power Management") :
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
149 _("Inhibit Automatic Power Management"));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
150 gtk_status_icon_set_from_icon_name(self->priv->status_icon,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
151 (inhibited) ? "xinhibit-applet-inhibited" :
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
152 "xinhibit-applet-uninhibited");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
153 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
154 self->priv->check_menu_item_inhibited), inhibited);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
155 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
156
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
157 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
158 icon_activate(GtkStatusIcon *status_icon, gpointer user_data)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
159 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
160 XiaIcon *self = XIA_ICON(user_data);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
161 gboolean inhibited = xia_inhibitor_get_inhibited(self->priv->inhibitor);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
162
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
163 g_debug("Icon activated, inhibit: %s", (!inhibited) ? "on" : "off");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
164
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
165 xia_inhibitor_set_inhibited(self->priv->inhibitor, !inhibited);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
166 icon_update(self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
167 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
168
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
169 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
170 check_menu_item_inhibit_activate(GtkCheckMenuItem *menu_item,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
171 gpointer user_data)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
172 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
173 XiaIcon *self = XIA_ICON(user_data);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
174 gboolean inhibited = gtk_check_menu_item_get_active(menu_item);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
175
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
176 g_debug("Inhibit menu item activated, inhibit: %s", (inhibited) ? "on" :
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
177 "off");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
178
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
179 if (xia_inhibitor_get_inhibited(self->priv->inhibitor) != inhibited) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
180 xia_inhibitor_set_inhibited(self->priv->inhibitor, inhibited);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
181 icon_update(self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
182 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
183 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
184
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
185 static GtkWidget*
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
186 icon_popup_menu_create(XiaIcon *self)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
187 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
188 GtkWidget *popup_menu = gtk_menu_new();
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
189 GtkWidget *item;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
190 GtkWidget *image;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
191
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
192 self->priv->check_menu_item_inhibited = \
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
193 gtk_check_menu_item_new_with_mnemonic(_("_Inhibit Automatic Power "
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
194 "Management"));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
195 gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu),
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
196 self->priv->check_menu_item_inhibited);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
197 g_signal_connect(G_OBJECT(self->priv->check_menu_item_inhibited),
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
198 "activate", G_CALLBACK(check_menu_item_inhibit_activate), self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
199
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
200 item = gtk_image_menu_item_new_with_mnemonic(_("_About"));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
201 image = gtk_image_new_from_icon_name(GTK_STOCK_ABOUT,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
202 GTK_ICON_SIZE_MENU);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
203 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
204 gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), item);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
205 g_signal_connect(G_OBJECT(item), "activate",
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
206 G_CALLBACK(about_dialog_show), self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
207
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
208 gtk_widget_show_all(GTK_WIDGET(popup_menu));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
209
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
210 return (popup_menu);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
211 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
212
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
213 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
214 icon_popup_menu_popup(GtkStatusIcon *status_icon, guint button,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
215 guint activate_time, gpointer user_data)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
216 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
217 XiaIcon *self = XIA_ICON(user_data);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
218
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
219 gtk_menu_popup(GTK_MENU(self->priv->status_icon_popup_menu), NULL, NULL,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
220 NULL, NULL, button, activate_time);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
221 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
222
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
223 XiaIcon *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
224 xia_icon_new(void)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
225 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
226 return (g_object_new(XIA_TYPE_ICON, NULL));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
227 }