[krb5-auth-dialog: 2/15] applet: Use GNotification instead of libnotify
- From: Guido Günther <guidog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [krb5-auth-dialog: 2/15] applet: Use GNotification instead of libnotify
- Date: Sat, 6 Feb 2021 19:16:58 +0000 (UTC)
commit 3227aa7cb458fc9f716e964c45b34b8cc6650050
Author: Guido Günther <agx sigxcpu org>
Date: Fri Feb 5 21:05:19 2021 +0100
applet: Use GNotification instead of libnotify
Fewer dependencies and simpler to use
.gitlab-ci.yml | 1 -
configure.ac | 3 -
etpo/Makefile.am | 2 -
src/Makefile.am | 2 -
src/ka-applet.c | 176 ++++++++++++++++++-------------------------------------
5 files changed, 58 insertions(+), 126 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 08dda0f..6f56c9c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -12,7 +12,6 @@ variables:
libgtk-3-dev
libkrb5-dev
libnm-dev
- libnotify-dev
libpam0g-dev
pkg-config
yelp-tools
diff --git a/configure.ac b/configure.ac
index 2f39541..50f4696 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,12 +29,10 @@ YELP_HELP_INIT
GTK_REQUIRED=3.14
GLIB_REQUIRED=2.28
-LIBNOTIFY_REQUIRED=0.7.0
PKG_CHECK_MODULES(GTK, [gtk+-3.0 >= $GTK_REQUIRED, glib-2.0 >= $GLIB_REQUIRED])
PKG_CHECK_MODULES(GIO, [gio-2.0, gio-unix-2.0])
PKG_CHECK_MODULES(GMODULE, gmodule-2.0)
-PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED)
dnl check for deprecated symbols:
dnl GNOME_MAINTAINER_MODE_DEFINES
@@ -249,7 +247,6 @@ AC_MSG_NOTICE([])
AC_MSG_NOTICE([ Kerberos: $KRB5_CFLAGS $KRB5_LIBS])
AC_MSG_NOTICE([ GTK: $GTK_CFLAGS $GTK_LIBS])
AC_MSG_NOTICE([ gio-unix: $GIO_UNIX_CFLAGS $GIO_UNIX_LIBS $GIO_CFLAGS $GIO_LIBS])
-AC_MSG_NOTICE([ libnotify: $LIBNOTIFY_CFLAGS $LIBNOTIFY_LIBS])
if test "$enable_network_manager" = "yes" ; then
AC_MSG_NOTICE([ Network Manager: $NETWORK_MANAGER_CFLAGS $NETWORK_MANAGER_LIBS])
else
diff --git a/etpo/Makefile.am b/etpo/Makefile.am
index 584657f..c496c91 100644
--- a/etpo/Makefile.am
+++ b/etpo/Makefile.am
@@ -6,12 +6,10 @@ AM_CFLAGS=\
@GTK_CFLAGS@ \
@KRB5_CFLAGS@ \
@NETWORK_MANAGER_CFLAGS@ \
- @LIBNOTIFY_CFLAGS@ \
@CFLAGS@
AM_LDFLAGS=\
@NETWORK_MANAGER_LIBS@ \
@KRB5_LIBS@ \
- @LIBNOTIFY_LIBS@ \
@GTK_LIBS@
DISTCLEANFILES=lexer.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 2ed9d60..ba6f403 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,7 +74,6 @@ krb5_auth_dialog_CFLAGS = \
$(GTK_CFLAGS) \
$(KRB5_CFLAGS) \
$(NETWORK_MANAGER_CFLAGS) \
- $(LIBNOTIFY_CFLAGS) \
$(WARN_CFLAGS) \
$(AM_CFLAGS) \
$(NULL)
@@ -84,7 +83,6 @@ krb5_auth_dialog_LDADD = \
$(NETWORK_MANAGER_LIBS) \
$(LIBCAP) \
$(KRB5_LIBS) \
- $(LIBNOTIFY_LIBS) \
$(GIO_LIBS) \
$(GMODULE_LIBS) \
$(GTK_LIBS) \
diff --git a/src/ka-applet.c b/src/ka-applet.c
index 4048da4..3d8d631 100644
--- a/src/ka-applet.c
+++ b/src/ka-applet.c
@@ -30,7 +30,6 @@
#include "ka-plugin-loader.h"
#include "ka-preferences.h"
#include "ka-closures.h"
-#include <libnotify/notify.h>
#include <signal.h>
@@ -94,7 +93,6 @@ struct _KaAppletPrivate {
gboolean auto_run; /* only start with valid ccache */
gint debug_flags; /* Debug options from environment */
- NotifyNotification *notification; /* notification messages */
char *krb_msg; /* Additional banner delivered by Kerberos */
/* GSettings options */
@@ -113,7 +111,6 @@ struct _KaAppletPrivate {
G_DEFINE_TYPE_WITH_PRIVATE (KaApplet, ka_applet, GTK_TYPE_APPLICATION);
-static void ka_close_notification (KaApplet *self);
static gboolean is_initialized;
static void
@@ -300,11 +297,47 @@ ka_applet_handle_debug(KaApplet *self)
}
+static void
+ka_list_tickets_action (GSimpleAction *action G_GNUC_UNUSED,
+ GVariant *parameter G_GNUC_UNUSED,
+ gpointer userdata)
+{
+ KaApplet *self = KA_APPLET (userdata);
+ KA_DEBUG ("Showing main window");
+ ka_main_window_show (self);
+}
+
+
+static void
+ka_remove_ccache_action (GSimpleAction *action G_GNUC_UNUSED,
+ GVariant *parameter G_GNUC_UNUSED,
+ gpointer userdata)
+{
+ KaApplet *self = KA_APPLET (userdata);
+ KA_DEBUG ("Removing ccache");
+ ka_destroy_ccache (self);
+}
+
+
+static void
+ka_acquire_tgt_action (GSimpleAction *action G_GNUC_UNUSED,
+ GVariant *parameter G_GNUC_UNUSED,
+ gpointer userdata)
+{
+ KaApplet *self = KA_APPLET (userdata);
+ KA_DEBUG ("Getting new tgt");
+ ka_grab_credentials (self);
+}
+
+
static GActionEntry app_entries[] = {
{ "preferences", action_preferences, NULL, NULL, NULL, {0} },
{ "about", action_about, NULL, NULL, NULL, {0} },
{ "help", action_help, NULL, NULL, NULL, {0} },
{ "quit", action_quit, NULL, NULL, NULL, {0} },
+ { "list-tickets", ka_list_tickets_action, NULL, NULL, NULL, {0} },
+ { "acquire-ticket", ka_acquire_tgt_action , NULL, NULL, NULL, {0} },
+ { "remove-ccache", ka_remove_ccache_action , NULL, NULL, NULL, {0} },
};
@@ -466,8 +499,6 @@ ka_applet_dispose (GObject *object)
KaApplet *applet = KA_APPLET (object);
GObjectClass *parent_class = G_OBJECT_CLASS (ka_applet_parent_class);
- ka_close_notification (applet);
-
if (applet->priv->pwdialog) {
gtk_widget_destroy (GTK_WIDGET(applet->priv->pwdialog));
applet->priv->pwdialog = NULL;
@@ -655,132 +686,41 @@ ka_applet_select_icon (KaApplet *applet, int remaining)
}
-static void
-ka_show_notification (KaApplet *applet)
-{
- GError *error = NULL;
- gboolean ret;
-
- ret = notify_notification_show (applet->priv->notification, &error);
- if (!ret) {
- g_assert (error);
- g_assert (error->message);
- g_warning ("Failed to show notification: %s", error->message);
- g_clear_error (&error);
- }
-}
-
-
-/* Callback to handle ticket related actions */
-static void
-ka_notify_ticket_action_cb (NotifyNotification *notification G_GNUC_UNUSED,
- gchar *action,
- gpointer user_data)
-{
- KaApplet *self = KA_APPLET (user_data);
-
- g_return_if_fail (self != NULL);
-
- if (strcmp (action, "ka-acquire-tgt") == 0) {
- KA_DEBUG ("Getting new tgt");
- ka_grab_credentials (self);
- } else if (strcmp (action, "ka-remove-ccache") == 0) {
- KA_DEBUG ("Removing ccache");
- ka_destroy_ccache (self);
- } else if (strcmp (action, "ka-list-tickets") == 0) {
- KA_DEBUG ("Showing main window");
- ka_main_window_show (self);
- } else {
- g_warning ("unkonwn action for callback");
- }
-}
-
-
-static void
-ka_close_notification (KaApplet *self)
-{
- GError *error = NULL;
-
- if (self->priv->notification != NULL) {
- if (!notify_notification_close (self->priv->notification, &error)) {
- if (error)
- g_warning ("Cannot close notification %s", error->message);
- else
- g_warning ("Cannot close notification");
- }
- g_object_unref (self->priv->notification);
- g_clear_error (&error);
- self->priv->notification = NULL;
- }
-}
-
static void
ka_send_event_notification (KaApplet *self,
const char *summary,
const char *message,
- const char *icon,
+ const char *iconname,
gboolean get_ticket_action)
{
- NotifyNotification *notification;
- const char *hint;
- gint timeout;
+ g_autoptr (GNotification) notification = NULL;
+ /* TODO: ka_appliet_select_icon ? */
+ g_autoptr (GIcon) icon = g_icon_new_for_string (iconname, NULL);
g_return_if_fail (self != NULL);
g_return_if_fail (summary != NULL);
g_return_if_fail (message != NULL);
- if (!notify_is_initted ())
- notify_init (KA_NAME);
+ notification = g_notification_new (summary);
+ g_notification_set_body (notification, message);
+ g_notification_set_icon (notification, icon);
- if (self->priv->notification) {
- notification = self->priv->notification;
- notify_notification_update (notification, summary, message, icon);
- } else {
- notification = self->priv->notification =
- notify_notification_new (summary, message, icon);
- notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
- }
+ g_notification_add_button (notification,
+ _("List Tickets"),
+ "app.list-tickets");
- notify_notification_set_hint (notification,
- "desktop-entry",
- g_variant_new_string (PACKAGE));
- hint = "resident";
- timeout = NOTIFY_EXPIRES_NEVER;
-
- notify_notification_set_timeout (notification, timeout);
- notify_notification_clear_hints (notification);
- notify_notification_set_hint (notification,
- hint,
- g_variant_new_boolean (TRUE));
-
- notify_notification_clear_actions(notification);
-
- notify_notification_add_action (notification,
- "ka-list-tickets",
- _("List Tickets"),
- (NotifyActionCallback)
- ka_notify_ticket_action_cb,
- self,
- NULL);
-
- if (get_ticket_action) {
- notify_notification_add_action (notification,
- "ka-acquire-tgt",
- _("Get Ticket"),
- (NotifyActionCallback)
- ka_notify_ticket_action_cb,
- self,
- NULL);
- } else {
- notify_notification_add_action (notification,
- "ka-remove-ccache",
- _("Remove Credentials Cache"),
- (NotifyActionCallback)
- ka_notify_ticket_action_cb,
- self,
- NULL);
- }
- ka_show_notification (self);
+ if (get_ticket_action)
+ g_notification_add_button (notification,
+ _("Get Ticket"),
+ "app.acquire-ticket");
+ else
+ g_notification_add_button (notification,
+ _("Remove Credentials Cache"),
+ "app.acquire-remove-ccache");
+
+ g_application_send_notification (G_APPLICATION (self),
+ PACKAGE,
+ notification);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]