annotate pkui-icon.c @ 59:e3ac37407eb1

Added tag version-3 for changeset 017b0a4b6ec5
author Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
date Mon, 02 Jul 2018 13:26:44 +0200
parents b2f6b6b25703
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
1 /*
53
7de92a24e86c Update email address
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 48
diff changeset
2 * (C) 2011 Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
3 *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
4 * Licensed under the GNU General Public License Version 2
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
5 *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
9 * (at your option) any later version.
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
10 *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
14 * GNU General Public License for more details.
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
15 *
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
19 */
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
20
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
21 #include <glib/gi18n.h>
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
22 #include <libnotify/notify.h>
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
23 #include "pkui-backend.h"
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
24 #include "pkui-icon.h"
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
25
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
26 G_DEFINE_TYPE(PkuiIcon, pkui_icon, G_TYPE_OBJECT)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
27
46
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
28 #ifndef UPDATE_VIEWER_COMMAND
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
29 #define UPDATE_VIEWER_COMMAND ""
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
30 #endif /* UPDATE_VIEWER_COMMAND */
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
31
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
32 #define PKUI_ICON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
33 PKUI_TYPE_ICON, PkuiIconPrivate))
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
34
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
35 struct _PkuiIconPrivate
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
36 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
37 PkuiBackend *backend;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
38
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
39 GtkStatusIcon *status_icon;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
40 GtkWidget *status_icon_popup_menu;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
41 NotifyNotification *notification;
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
42 gchar **update_viewer_argv;
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
43 };
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
44
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
45 static GtkWidget* icon_popup_menu_create(PkuiIcon *self);
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
46 static void icon_popup_menu_popup(GtkStatusIcon *status_icon, guint button,
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
47 guint activate_time, gpointer user_data);
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
48 static void icon_activated(GtkStatusIcon *status_icon, gpointer user_data);
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
49 static void hide_notification(PkuiIcon *self);
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
50 static void backend_state_changed(PkuiBackend *backend, gpointer user_data);
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
51 static void update_viewer_exited(GPid pid, gint status, gpointer user_data);
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
52
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
53 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
54 pkui_icon_finalize(GObject *gobject)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
55 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
56 PkuiIcon *self = PKUI_ICON(gobject);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
57
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
58 gtk_widget_destroy(self->priv->status_icon_popup_menu);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
59 g_object_unref(self->priv->status_icon_popup_menu);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
60 g_object_unref(self->priv->status_icon);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
61 if (self->priv->notification != NULL) {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
62 notify_notification_close(self->priv->notification, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
63 g_object_unref(self->priv->notification);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
64 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
65 g_object_unref(self->priv->backend);
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
66 g_strfreev(self->priv->update_viewer_argv);
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
67
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
68 G_OBJECT_CLASS(pkui_icon_parent_class)->finalize(gobject);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
69 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
70
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
71 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
72 pkui_icon_class_init(PkuiIconClass *klass)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
73 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
74 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
75
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
76 gobject_class->finalize = pkui_icon_finalize;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
77
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
78 g_type_class_add_private(klass, sizeof (PkuiIconPrivate));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
79 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
80
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
81 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
82 pkui_icon_init(PkuiIcon *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
83 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
84 self->priv = PKUI_ICON_GET_PRIVATE(self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
85
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
86 gtk_window_set_default_icon_name("system-software-update");
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
87
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
88 self->priv->status_icon_popup_menu = icon_popup_menu_create(self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
89 g_object_ref(self->priv->status_icon_popup_menu);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
90 g_object_ref_sink(GTK_OBJECT(self->priv->status_icon_popup_menu));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
91
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
92 self->priv->status_icon = gtk_status_icon_new();
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
93 gtk_status_icon_set_title(self->priv->status_icon,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
94 _("Software Updates"));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
95 gtk_status_icon_set_visible(self->priv->status_icon, FALSE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
96 g_signal_connect(G_OBJECT(self->priv->status_icon), "activate",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
97 G_CALLBACK(icon_activated), self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
98 g_signal_connect(G_OBJECT(self->priv->status_icon), "popup-menu",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
99 G_CALLBACK(icon_popup_menu_popup), self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
100
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
101 self->priv->notification = NULL;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
102 self->priv->backend = NULL;
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
103 self->priv->update_viewer_argv = NULL;
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
104 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
105
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
106 static void
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
107 exec_update_viewer(PkuiIcon *self)
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
108 {
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
109 GError *error = NULL;
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
110 GPid pid;
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
111
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
112 g_return_if_fail(PKUI_IS_BACKEND(self->priv->backend));
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
113 g_return_if_fail(self->priv->update_viewer_argv != NULL);
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
114
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
115 g_debug("executing update viewer command");
46
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
116
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
117 if (!g_spawn_async(NULL, self->priv->update_viewer_argv, NULL,
46
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
118 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid,
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
119 &error)) {
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
120 g_warning("Could not execute command: %s", error->message);
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
121 g_error_free(error);
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
122 return;
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
123 }
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
124 g_child_watch_add(pid, (GChildWatchFunc)update_viewer_exited, self);
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
125
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
126 pkui_backend_set_inhibit_check(self->priv->backend, TRUE);
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
127 hide_notification(self);
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
128 }
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
129
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
130 static void
18
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
131 about_dialog_show(GtkMenuItem *item, gpointer user_data)
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
132 {
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
133 static const gchar *copyright = "Copyright \xc2\xa9 2011 Guido "
18
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
134 "Berhoerster\nCopyright \xc2\xa9 2011 Pavol Rusnak\n";
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
135 static const gchar *authors[3] = {
53
7de92a24e86c Update email address
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 48
diff changeset
136 "Guido Berhoerster <guido+pk-update-icon@berhoerster.name>",
18
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
137 "Pavol Rusnak <stick@gk2.sk>",
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
138 NULL
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
139 };
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
140 static const gchar *documenters[2] = {
53
7de92a24e86c Update email address
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 48
diff changeset
141 "Guido Berhoerster <guido+pk-update-icon@berhoerster.name>",
18
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
142 NULL
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
143 };
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
144 static const gchar *license =
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
145 "Licensed under the GNU General Public License Version 2\n\n"
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
146 "This program is free software; you can redistribute it and/or "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
147 "modify it under the terms of the GNU General Public License as "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
148 "published by the Free Software Foundation; either version 2 of "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
149 "the License, or (at your option) any later version.\n\n"
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
150 "This program is distributed in the hope that it will be useful, "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
151 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
152 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
153 "General Public License for more details.\n\n"
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
154 "You should have received a copy of the GNU General Public License "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
155 "along with this program; if not, write to the Free Software "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
156 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, "
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
157 "MA 02110-1301 USA.";
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
158 const gchar *translators = _("translators");
18
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
159
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
160 if (strcmp(translators, "translators") == 0)
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
161 translators = NULL;
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
162
25
bae8a7e20382 use the VERSION macro in the about dialog
Guido Berhoerster <gber@opensuse.org>
parents: 19
diff changeset
163 gtk_show_about_dialog (NULL, "version", VERSION, "copyright", copyright,
18
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
164 "authors", authors, "documenters", documenters,
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
165 "translator-credits", translators, "license", license,
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
166 "wrap-license", TRUE, NULL);
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
167 }
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
168
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
169 static void
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
170 backend_check_now(GtkMenuItem *menu_item, gpointer user_data)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
171 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
172 PkuiIcon *self = PKUI_ICON(user_data);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
173
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
174 g_return_if_fail(PKUI_IS_BACKEND(self->priv->backend));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
175
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
176 pkui_backend_check_now(self->priv->backend);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
177 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
178
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
179 static GtkWidget*
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
180 icon_popup_menu_create(PkuiIcon *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
181 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
182 GtkWidget *popup_menu = gtk_menu_new();
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
183 GtkWidget *item;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
184 GtkWidget *image;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
185
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
186 item = gtk_image_menu_item_new_with_mnemonic(_("_Check for Updates"));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
187 image = gtk_image_new_from_icon_name(GTK_STOCK_REFRESH,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
188 GTK_ICON_SIZE_MENU);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
189 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
190 gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), item);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
191 g_signal_connect(G_OBJECT(item), "activate",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
192 G_CALLBACK(backend_check_now), self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
193
18
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
194 item = gtk_image_menu_item_new_with_mnemonic(_("_About"));
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
195 image = gtk_image_new_from_icon_name(GTK_STOCK_ABOUT,
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
196 GTK_ICON_SIZE_MENU);
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
197 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
198 gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), item);
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
199 g_signal_connect(G_OBJECT(item), "activate",
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
200 G_CALLBACK(about_dialog_show), self);
9537882d759f add an about dialog
Guido Berhoerster <guido@berhoerster.name>
parents: 14
diff changeset
201
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
202 gtk_widget_show_all(GTK_WIDGET(popup_menu));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
203
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
204 return (popup_menu);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
205 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
206
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
207 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
208 icon_popup_menu_popup(GtkStatusIcon *status_icon, guint button,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
209 guint activate_time, gpointer user_data)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
210 {
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
211 PkuiIcon *self = PKUI_ICON(user_data);
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
212
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
213 gtk_menu_popup(GTK_MENU(self->priv->status_icon_popup_menu), NULL, NULL,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
214 NULL, NULL, button, activate_time);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
215 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
216
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
217 static void
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
218 notification_handle_action(NotifyNotification *notification, gchar *action,
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
219 gpointer user_data)
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
220 {
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
221 PkuiIcon *self = PKUI_ICON(user_data);
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
222
46
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
223 if (strcmp(action, "install-updates") == 0) {
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
224 exec_update_viewer(self);
46
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
225 }
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
226 }
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
227
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
228 static void
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
229 update_notification(PkuiIcon *self, guint updates_normal,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
230 guint updates_important)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
231 {
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
232 gchar *message;
48
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
233 gchar *message_a;
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
234 gchar *message_b;
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
235 gchar *title = updates_important ?
48
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
236 /* TRANSLATORS: This is a message without number mentioned */
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
237 ngettext("Important Software Update", "Important Software Updates",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
238 updates_important + updates_normal) :
48
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
239 /* TRANSLATORS: This is a message without number mentioned */
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
240 ngettext("Software Update", "Software Updates", updates_important +
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
241 updates_normal);
39
f6edbee6441f Stylistic fixes
Guido Berhoerster <gber@opensuse.org>
parents: 25
diff changeset
242 gchar *icon = updates_important ? "software-update-urgent" :
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
243 "software-update-available";
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
244 gchar *program = NULL;
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
245
48
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
246 if (updates_important > 0) {
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
247 if (updates_normal > 0) {
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
248 message_a = g_strdup_printf(
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
249 /*
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
250 * TRANSLATORS: This sentence contains two plurals.
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
251 * Texts related to these plurals are mixed. That is
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
252 * why it is split in three parts. Fill first two parts
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
253 * as you need, and use them as %s in the last one to
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
254 * construct a sentence. Note that if the first form of
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
255 * plural relates only to singular form, it is never
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
256 * used, and dedicated shorter sentences are used. */
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
257 ngettext("There is %d software update available,",
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
258 "There are %d software updates available,",
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
259 updates_normal + updates_important),
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
260 updates_normal + updates_important);
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
261 /*
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
262 * TRANSLATORS: This is the sentence part in the
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
263 * middle, form of which is related to the first
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
264 * number. If your language does not need it, simply
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
265 * use it as space or so. */
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
266 message_b = ngettext("of it", "of them",
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
267 updates_normal + updates_important);
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
268 message = g_strdup_printf(
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
269 /*
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
270 * TRANSLATORS: This forms the sentence. If you need to
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
271 * swap parts, use %3$s and %1$s etc. Plurals are
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
272 * related to second number. */
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
273 ngettext("%s %d %s is important.",
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
274 "%s %d %s are important.", updates_important),
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
275 message_a, updates_important, message_b);
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
276 g_free(message_a);
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
277 } else {
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
278 message = g_strdup_printf(ngettext("There is %d "
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
279 "important software update available.",
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
280 "There are %d important software updates "
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
281 "available.", updates_important),
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
282 updates_important);
48
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
283 }
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
284 } else {
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
285 message = g_strdup_printf(ngettext("There is %d software "
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
286 "update available.",
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
287 "There are %d software updates available.",
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
288 updates_normal), updates_normal);
48
1eb92ab03287 Avoid passing more arguments to g_strdup_printf() than specified in the format
Stanislav Brabec <sbrabec@suse.com>
parents: 46
diff changeset
289 }
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
290
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
291 gtk_status_icon_set_tooltip(self->priv->status_icon, message);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
292 gtk_status_icon_set_from_icon_name(self->priv->status_icon, icon);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
293 gtk_status_icon_set_visible(self->priv->status_icon, TRUE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
294
19
38b37e4a4d63 added a button for installing updates to the notification
Guido Berhoerster <guido@berhoerster.name>
parents: 18
diff changeset
295 if (self->priv->notification == NULL) {
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
296 self->priv->notification = notify_notification_new(title,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
297 message, icon
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
298 #if (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
299 , NULL
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
300 #endif
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
301 );
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
302 } else {
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
303 notify_notification_update(self->priv->notification, title,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
304 message, icon);
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
305 }
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
306
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
307 notify_notification_clear_actions(self->priv->notification);
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
308 program = (self->priv->update_viewer_argv != NULL) ?
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
309 g_find_program_in_path(self->priv->update_viewer_argv[0]) : NULL;
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
310 if (program != NULL) {
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
311 notify_notification_add_action(self->priv->notification,
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
312 "install-updates", ngettext("Install Update",
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
313 "Install Updates", updates_normal + updates_important),
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
314 notification_handle_action, self, NULL);
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
315 }
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
316
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
317 notify_notification_set_timeout(self->priv->notification,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
318 NOTIFY_EXPIRES_NEVER);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
319 notify_notification_set_urgency(self->priv->notification,
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
320 updates_important ? NOTIFY_URGENCY_CRITICAL :
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
321 NOTIFY_URGENCY_NORMAL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
322 notify_notification_show(self->priv->notification, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
323
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
324 g_free(program);
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
325 g_free(message);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
326 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
327
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
328 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
329 hide_notification(PkuiIcon *self)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
330 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
331 gtk_status_icon_set_visible(self->priv->status_icon, FALSE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
332 notify_notification_close(self->priv->notification, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
333 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
334
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
335
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
336 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
337 backend_state_changed(PkuiBackend *backend, gpointer user_data)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
338 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
339 PkuiIcon *self = PKUI_ICON(user_data);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
340 guint updates_normal;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
341 guint updates_important;
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
342
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
343 g_return_if_fail(PKUI_IS_BACKEND(backend));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
344
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
345 updates_normal = pkui_backend_get_updates_normal(backend);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
346 updates_important = pkui_backend_get_updates_important(backend);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
347 if (updates_normal > 0 || updates_important > 0)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
348 update_notification(self, updates_normal, updates_important);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
349 else if (updates_normal + updates_important == 0)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
350 hide_notification(self);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
351 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
352
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
353 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
354 update_viewer_exited(GPid pid, gint status, gpointer user_data)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
355 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
356 PkuiIcon *self = PKUI_ICON(user_data);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
357
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
358 g_return_if_fail(PKUI_IS_BACKEND(self->priv->backend));
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
359
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
360 g_spawn_close_pid(pid);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
361
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
362 pkui_backend_check_now(self->priv->backend);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
363 pkui_backend_set_inhibit_check(self->priv->backend, FALSE);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
364 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
365
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
366 static void
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
367 icon_activated(GtkStatusIcon *status_icon, gpointer user_data)
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
368 {
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
369 PkuiIcon *self = PKUI_ICON(user_data);
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
370 gchar *program = NULL;
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
371
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
372 program = (self->priv->update_viewer_argv != NULL) ?
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
373 g_find_program_in_path(self->priv->update_viewer_argv[0]) :
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
374 NULL;
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
375 if (program != NULL) {
46
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
376 exec_update_viewer(self);
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
377 }
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
378
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
379 g_free(program);
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
380 }
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
381
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
382 PkuiIcon *
46
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
383 pkui_icon_new(guint startup_delay, guint check_interval,
aa5d3752091d Make the update viewer command configurable
Guido Berhoerster <gber@opensuse.org>
parents: 39
diff changeset
384 const gchar *update_viewer_command)
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
385 {
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
386 GError *error = NULL;
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
387 PkuiIcon *icon = g_object_new(PKUI_TYPE_ICON, NULL);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
388
55
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
389 if (update_viewer_command == NULL) {
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
390 update_viewer_command = UPDATE_VIEWER_COMMAND;
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
391 }
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
392
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
393 if (!g_shell_parse_argv(update_viewer_command, NULL,
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
394 &icon->priv->update_viewer_argv, &error)) {
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
395 g_warning("Could not parse command: %s", error->message);
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
396 g_error_free(error);
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
397 }
b2f6b6b25703 Only show notification action if the update viewer executable exists
Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
parents: 53
diff changeset
398
14
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
399 icon->priv->backend = pkui_backend_new(startup_delay, check_interval);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
400 g_signal_connect(icon->priv->backend, "state-changed",
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
401 G_CALLBACK(backend_state_changed), icon);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
402
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
403 return (icon);
64f05992d8ec GObject-based rewrite
Guido Berhoerster <guido@berhoerster.name>
parents:
diff changeset
404 }