Merge lp:~azzar1/update-notifier/livepatch-notification-button into lp:update-notifier/ubuntu

Proposed by Andrea Azzarone
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 951
Merged at revision: 953
Proposed branch: lp:~azzar1/update-notifier/livepatch-notification-button
Merge into: lp:update-notifier/ubuntu
Diff against target: 146 lines (+64/-8)
2 files modified
debian/changelog (+6/-0)
src/livepatch.c (+58/-8)
To merge this branch: bzr merge lp:~azzar1/update-notifier/livepatch-notification-button
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+362478@code.launchpad.net

Commit message

src/livepatch.c: Add a "Settings..." button to the notification.

To post a comment you must log in.
951. By Andrea Azzarone

src/livepatch.c: Add a "Settings..." button to the notification.

Revision history for this message
Sebastien Bacher (seb128) wrote :

Thank you for your work, that looks mostly fine, I'm unsure why you add the action twice though?

+ if (info) {
+ notify_notification_add_action (n, "settings", _("Show Settings…"),
+ notify_action_cb, NULL, NULL);
+ notify_notification_add_action (n, "default", _("Show Settings…"),
+ notify_action_cb, NULL, NULL);

Wouldn't one be enough?

review: Needs Information
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Thank you for your work, that looks mostly fine, I'm unsure why you add the
> action twice though?
>
> + if (info) {
> + notify_notification_add_action (n, "settings", _("Show Settings…"),
> + notify_action_cb, NULL, NULL);
> + notify_notification_add_action (n, "default", _("Show Settings…"),
> + notify_action_cb, NULL, NULL);
>
> Wouldn't one be enough?

One is to add a button, one is to open software properties if you click on the notification.

Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2019-01-07 16:32:46 +0000
+++ debian/changelog 2019-01-30 17:24:03 +0000
@@ -1,3 +1,9 @@
1update-notifier (3.192.12) UNRELEASED; urgency=medium
2
3 * src/livepatch.c: Add a "Settings..." button to the notification.
4
5 -- Andrea Azzarone <andrea.azzarone@canonical.com> Wed, 30 Jan 2019 17:20:42 +0000
6
1update-notifier (3.192.11) disco; urgency=medium7update-notifier (3.192.11) disco; urgency=medium
28
3 * src/update-notifier.c: Don't use G_SPAWN_DO_NOT_REAP_CHILD in order9 * src/update-notifier.c: Don't use G_SPAWN_DO_NOT_REAP_CHILD in order
410
=== modified file 'src/livepatch.c'
--- src/livepatch.c 2018-11-12 09:52:00 +0000
+++ src/livepatch.c 2019-01-30 17:24:03 +0000
@@ -3,6 +3,7 @@
3#endif3#endif
44
5#include <errno.h>5#include <errno.h>
6#include <gio/gdesktopappinfo.h>
6#include <glib.h>7#include <glib.h>
7#include <glib/gstdio.h>8#include <glib/gstdio.h>
8#include <libnotify/notify.h>9#include <libnotify/notify.h>
@@ -11,6 +12,7 @@
1112
12#include "update-notifier.h"13#include "update-notifier.h"
1314
15#define LIVEPATCH_DESKTOP_FILE "software-properties-livepatch.desktop"
14#define STATUS_PATH "/var/snap/canonical-livepatch/current/status"16#define STATUS_PATH "/var/snap/canonical-livepatch/current/status"
1517
16static void18static void
@@ -29,12 +31,55 @@
29}31}
3032
31static void33static void
34notify_action_cb (NotifyNotification *notification,
35 char *action,
36 gpointer user_data)
37{
38 g_autoptr(GDesktopAppInfo) info = NULL;
39 g_autoptr(GdkAppLaunchContext) context = NULL;
40 g_autoptr(GError) error = NULL;
41
42 info = g_desktop_app_info_new (LIVEPATCH_DESKTOP_FILE);
43 if (!info) {
44 g_warning ("Could not find application '%s'", LIVEPATCH_DESKTOP_FILE);
45 return;
46 }
47
48 context = gdk_display_get_app_launch_context (gdk_display_get_default ());
49 if (!g_app_info_launch (G_APP_INFO (info), NULL, G_APP_LAUNCH_CONTEXT (context), &error)) {
50 g_warning ("Could not launch application '%s'", LIVEPATCH_DESKTOP_FILE);
51 }
52}
53
54static gboolean
32show_notification (const char *summary, const char *body, const char *icon)55show_notification (const char *summary, const char *body, const char *icon)
33{56{
34 NotifyNotification *n = notify_notification_new (summary, body, icon);57 NotifyNotification *n;
58 g_autoptr(GDesktopAppInfo) info = NULL;
59 g_autoptr(GError) error = NULL;
60
61 n = notify_notification_new (summary, body, icon);
35 notify_notification_set_timeout (n, 60000);62 notify_notification_set_timeout (n, 60000);
36 notify_notification_show (n, NULL);63
37 g_object_unref (n);64 info = g_desktop_app_info_new (LIVEPATCH_DESKTOP_FILE);
65 if (info) {
66 notify_notification_add_action (n, "settings", _("Show Settings…"),
67 notify_action_cb, NULL, NULL);
68 notify_notification_add_action (n, "default", _("Show Settings…"),
69 notify_action_cb, NULL, NULL);
70 } else {
71 g_warning ("Could not find application '%s'. The notification will not "
72 "have a 'Show Settings…' button.", LIVEPATCH_DESKTOP_FILE);
73 }
74
75 g_signal_connect (n, "closed", G_CALLBACK (gtk_main_quit), NULL);
76
77 if (!notify_notification_show (n, &error)) {
78 g_warning ("Could not show notification: '%s", error->message);
79 return FALSE;
80 }
81
82 return TRUE;
38}83}
3984
40static void85static void
@@ -94,17 +139,17 @@
94 return difftime (status_stat.st_mtim.tv_sec, boot_timestamp) >= 0;139 return difftime (status_stat.st_mtim.tv_sec, boot_timestamp) >= 0;
95}140}
96141
97static void142static gboolean
98show_status_notification ()143show_status_notification ()
99{144{
100 g_autofree gchar *event = NULL;145 g_autofree gchar *event = NULL;
101 g_autofree gchar *description = NULL;146 g_autofree gchar *description = NULL;
102147
103 if (!g_file_test (STATUS_PATH, G_FILE_TEST_EXISTS))148 if (!g_file_test (STATUS_PATH, G_FILE_TEST_EXISTS))
104 return;149 return FALSE;
105150
106 if (!file_modified_after_boot (STATUS_PATH))151 if (!file_modified_after_boot (STATUS_PATH))
107 return;152 return FALSE;
108153
109 get_event_from_file (STATUS_PATH, &event, &description);154 get_event_from_file (STATUS_PATH, &event, &description);
110155
@@ -120,6 +165,7 @@
120165
121 if (is_overflow || conversion_failed) {166 if (is_overflow || conversion_failed) {
122 g_warning ("Failed to parse the status file");167 g_warning ("Failed to parse the status file");
168 return FALSE;
123 } else if (num_updates != 0) {169 } else if (num_updates != 0) {
124 body = g_strdup_printf (170 body = g_strdup_printf (
125 ngettext ("%" G_GUINT64_FORMAT " Livepatch update has been successfully applied.",171 ngettext ("%" G_GUINT64_FORMAT " Livepatch update has been successfully applied.",
@@ -127,18 +173,22 @@
127 num_updates),173 num_updates),
128 num_updates);174 num_updates);
129175
130 show_notification (_("Canonical Livepatch"), body, NULL);176 return show_notification (_("Canonical Livepatch"), body, NULL);
131 }177 }
132 }178 }
179
180 return FALSE;
133}181}
134182
135int183int
136main (int argc, char **argv)184main (int argc, char **argv)
137{185{
186 gtk_init (&argc, &argv);
138 init_notification ();187 init_notification ();
139 init_gettext ();188 init_gettext ();
140189
141 show_status_notification ();190 if (show_status_notification ())
191 gtk_main ();
142192
143 return EXIT_SUCCESS;193 return EXIT_SUCCESS;
144}194}

Subscribers

People subscribed via source and target branches

to all changes: