[krb5-auth-dialog: 1/15] applet: Drop tray icon related code




commit 8eb42cb89d145d93af1396fc4b6cdaae6730f625
Author: Guido Günther <agx sigxcpu org>
Date:   Fri Feb 5 19:43:24 2021 +0100

    applet: Drop tray icon related code
    
    It doesn't exist anymore in GTK4

 po/POTFILES.in                     |   1 -
 src/Makefile.am                    |   1 -
 src/ka-applet.c                    | 278 +++----------------------------------
 src/krb5-auth-dialog.gresource.xml |   1 -
 src/resources/ui/tray-icon-menu.ui |  30 ----
 5 files changed, 20 insertions(+), 291 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ce90dc9..044f0ae 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,5 +1,4 @@
 [type: gettext/glade]src/resources/ui/app-menu.ui
-[type: gettext/glade]src/resources/ui/tray-icon-menu.ui
 [type: gettext/glade]src/resources/ui/ka-main-window.ui
 [type: gettext/glade]src/resources/ui/ka-preferences.ui
 [type: gettext/glade]src/resources/ui/ka-pwdialog.ui
diff --git a/src/Makefile.am b/src/Makefile.am
index 0487fe8..2ed9d60 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -108,7 +108,6 @@ EXTRA_DIST = \
        resources/ui/ka-main-window.ui \
        resources/ui/ka-preferences.ui \
        resources/ui/ka-pwdialog.ui \
-       resources/ui/tray-icon-menu.ui \
        $(NULL)
 
 CLEANFILES = $(schema_DATA) \
diff --git a/src/ka-applet.c b/src/ka-applet.c
index 921ff9a..4048da4 100644
--- a/src/ka-applet.c
+++ b/src/ka-applet.c
@@ -1,6 +1,6 @@
 /* Krb5 Auth Applet -- Acquire and release Kerberos tickets
  *
- * (C) 2008,2009,2010,2013 Guido Guenther <agx sigxcpu org>
+ * (C) 2008,2009,2010,2013,2021 Guido Guenther <agx sigxcpu org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -58,7 +58,6 @@ enum {
 enum {
     KA_DEBUG_NO_APP_MENU    = 1,  /* Disable gtk-shell-shows-app-menu gtk setting */
     KA_DEBUG_NO_HEADER_BAR  = 2,  /* Disable header-bar setting */
-    KA_DEBUG_NO_PERSISTENCE = 4,  /* notification system does not support persistence */
 };
 
 
@@ -83,10 +82,7 @@ struct _KaAppletClass {
 };
 
 struct _KaAppletPrivate {
-    GtkStatusIcon *tray_icon;   /* the tray icon */
-    GtkWidget *context_menu;    /* the tray icon's context menu */
     const char *icons[3];       /* for invalid, expiring and valid tickts */
-    gboolean ns_persistence;    /* does the notification server support persistence */
 
     KaPwDialog *pwdialog;       /* the password dialog */
     KaPreferences *prefs;       /* the prefs dialog */
@@ -207,26 +203,6 @@ GtkWindow *ka_applet_last_focused_window (KaApplet *self)
 }
 
 
-static void
-action_remove_credentials_cache (GSimpleAction *action G_GNUC_UNUSED,
-                                 GVariant *parameter G_GNUC_UNUSED,
-                                 gpointer userdata)
-{
-    KaApplet *self = userdata;
-    ka_destroy_ccache (self);
-}
-
-
-static void
-action_list_tickets (GSimpleAction *action G_GNUC_UNUSED,
-                     GVariant *parameter G_GNUC_UNUSED,
-                     gpointer userdata)
-{
-    KaApplet *self = userdata;
-    ka_main_window_show (self);
-}
-
-
 static void
 action_preferences (GSimpleAction *action G_GNUC_UNUSED,
                    GVariant *parameter G_GNUC_UNUSED,
@@ -315,8 +291,6 @@ ka_applet_handle_debug(KaApplet *self)
                           "gtk-dialogs-use-header", FALSE,
                           NULL);
             self->priv->debug_flags |= KA_DEBUG_NO_HEADER_BAR;
-        } else if (!g_strcmp0(*opt, "no-persistence")) {
-            self->priv->debug_flags |= KA_DEBUG_NO_PERSISTENCE;
         } else {
             g_warning ("Unhandled debug options %s", *opt);
         }
@@ -494,10 +468,6 @@ ka_applet_dispose (GObject *object)
 
     ka_close_notification (applet);
 
-    if (applet->priv->tray_icon) {
-        g_object_unref (applet->priv->tray_icon);
-        applet->priv->tray_icon = NULL;
-    }
     if (applet->priv->pwdialog) {
         gtk_widget_destroy (GTK_WIDGET(applet->priv->pwdialog));
         applet->priv->pwdialog = NULL;
@@ -685,63 +655,19 @@ ka_applet_select_icon (KaApplet *applet, int remaining)
 }
 
 
-static gboolean
-ka_tray_icon_is_embedded (KaApplet *self)
-{
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-    if (self->priv->tray_icon
-        && gtk_status_icon_is_embedded (self->priv->tray_icon))
-        return TRUE;
-    else
-        return FALSE;
-G_GNUC_END_IGNORE_DEPRECATIONS
-}
-
-
-static gboolean
-ka_show_notification (KaApplet *applet)
-{
-    /* wait for the panel to be settled before showing a bubble */
-    if (applet->priv->ns_persistence
-        || ka_tray_icon_is_embedded (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);
-        }
-    } else {
-        g_timeout_add_seconds (5, (GSourceFunc) ka_show_notification, applet);
-    }
-    return FALSE;
-}
-
-
-/* Callback to handle disabling of notification */
 static void
-ka_notify_disable_action_cb (NotifyNotification *notification G_GNUC_UNUSED,
-                              gchar *action,
-                              gpointer user_data)
+ka_show_notification (KaApplet *applet)
 {
-    KaApplet *self = KA_APPLET (user_data);
-    GSettings *ns = g_settings_get_child (self->priv->settings,
-                                              KA_SETTING_CHILD_NOTIFY);
+    GError *error = NULL;
+    gboolean ret;
 
-    if (strcmp (action, "dont-show-again") == 0) {
-        KA_DEBUG ("turning of notification %s", self->priv->notify_key);
-        if (!g_settings_set_boolean (ns,
-                                     self->priv->notify_key, FALSE)) {
-            g_warning("Failed to set %s", self->priv->notify_key);
-        }
-        self->priv->notify_key = NULL;
-    } else {
-        g_warning ("unkonwn action for callback");
+    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);
     }
-    g_object_unref (ns);
 }
 
 
@@ -818,28 +744,24 @@ ka_send_event_notification (KaApplet *self,
     notify_notification_set_hint (notification,
                                   "desktop-entry",
                                   g_variant_new_string (PACKAGE));
-    if (self->priv->ns_persistence) {
-        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));
-    }
+    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);
 
-    if (self->priv->ns_persistence) {
-        notify_notification_add_action (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,
@@ -850,38 +772,18 @@ ka_send_event_notification (KaApplet *self,
                                         self,
                                         NULL);
     } else {
-        if (!self->priv->ns_persistence) {
-            notify_notification_add_action (notification,
-                                            "dont-show-again",
-                                            _("Don't show me this again"),
-                                            (NotifyActionCallback)
-                                            ka_notify_disable_action_cb, self,
-                                            NULL);
-        } else {
-            notify_notification_add_action (notification,
+        notify_notification_add_action (notification,
                                         "ka-remove-ccache",
                                         _("Remove Credentials Cache"),
                                         (NotifyActionCallback)
                                         ka_notify_ticket_action_cb,
                                         self,
                                         NULL);
-        }
     }
     ka_show_notification (self);
 }
 
 
-static void
-ka_update_tray_icon (KaApplet *self, const char *icon, const char *tooltip)
-{
-    if (self->priv->tray_icon) {
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-        gtk_status_icon_set_from_icon_name (self->priv->tray_icon, icon);
-        gtk_status_icon_set_tooltip_text (self->priv->tray_icon, tooltip);
-G_GNUC_END_IGNORE_DEPRECATIONS
-    }
-}
-
 /* check whether a given notification is enabled */
 static gboolean
 get_notify_enabled (KaApplet *self, const char *key)
@@ -908,7 +810,6 @@ ka_applet_update_status (KaApplet *applet, krb5_timestamp expiry)
     static gboolean initial_notification = TRUE;
     static krb5_timestamp old_expiry = 0;
     gboolean notify = TRUE;
-    const char *status_icon = ka_applet_select_icon (applet, remaining);
     char *tooltip_text = ka_applet_tooltip_text (remaining);
 
     if (remaining > 0) {
@@ -975,106 +876,12 @@ ka_applet_update_status (KaApplet *applet, krb5_timestamp expiry)
     }
 
     old_expiry = expiry;
-    ka_update_tray_icon(applet, status_icon, tooltip_text);
     g_free (tooltip_text);
     initial_notification = FALSE;
     return 0;
 }
 
 
-static GActionEntry trayicon_entries[] = {
-    { "remove_credentials_cache", action_remove_credentials_cache, NULL, NULL, NULL, {0} },
-    { "list_tickets", action_list_tickets, NULL, NULL, NULL, {0} },
-    { "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} },
-};
-
-/* The tray icon's context menu */
-static gboolean
-ka_applet_create_tray_icon_context_menu (KaApplet *self)
-{
-    GtkBuilder *builder;
-    GMenuModel *model;
-    GSimpleActionGroup *group;
-
-    builder = gtk_builder_new_from_resource (
-        "/org/gnome/krb5-auth-dialog/ui/tray-icon-menu.ui");
-    model = G_MENU_MODEL (
-        gtk_builder_get_object (builder, "tray-icon-context-menu"));
-
-    self->priv->context_menu = gtk_menu_new_from_model (model);
-    gtk_widget_show_all (self->priv->context_menu);
-
-    group = g_simple_action_group_new ();
-    g_action_map_add_action_entries (G_ACTION_MAP (group),
-                                     trayicon_entries, G_N_ELEMENTS (trayicon_entries),
-                                     self);
-
-    gtk_widget_insert_action_group (GTK_WIDGET(self->priv->context_menu),
-                                    "trayicon",
-                                    G_ACTION_GROUP(group));
-
-    g_object_unref (builder);
-    return TRUE;
-}
-
-
-static void
-ka_tray_icon_on_menu (GtkStatusIcon *status_icon G_GNUC_UNUSED,
-                      guint button,
-                      guint activate_time,
-                      gpointer user_data)
-{
-    KaApplet *applet = KA_APPLET (user_data);
-
-    KA_DEBUG ("Trayicon right clicked: %d", applet->priv->pw_prompt_secs);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-    gtk_menu_popup (GTK_MENU (applet->priv->context_menu), NULL, NULL,
-                    gtk_status_icon_position_menu, applet->priv->tray_icon,
-                    button, activate_time);
-G_GNUC_END_IGNORE_DEPRECATIONS
-}
-
-
-static gboolean
-ka_tray_icon_on_click (GtkStatusIcon *status_icon G_GNUC_UNUSED,
-                       gpointer data)
-{
-    KaApplet *applet = KA_APPLET (data);
-
-    KA_DEBUG ("Trayicon clicked: %d", applet->priv->pw_prompt_secs);
-    ka_grab_credentials (applet);
-    return TRUE;
-}
-
-
-static gboolean
-ka_applet_create_tray_icon (KaApplet *self)
-{
-    GtkStatusIcon *tray_icon;
-
-    if (self->priv->ns_persistence)
-        return FALSE;
-
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-    tray_icon = self->priv->tray_icon = gtk_status_icon_new ();
-    gtk_status_icon_set_from_icon_name (tray_icon,
-                                        self->priv->icons[exp_icon]);
-    gtk_status_icon_set_tooltip_text (tray_icon, PACKAGE);
-    gtk_status_icon_set_title (tray_icon, KA_NAME);
-G_GNUC_END_IGNORE_DEPRECATIONS
-
-    g_signal_connect (G_OBJECT (tray_icon), "activate",
-                      G_CALLBACK (ka_tray_icon_on_click), self);
-    g_signal_connect (G_OBJECT (tray_icon),
-                      "popup-menu",
-                      G_CALLBACK (ka_tray_icon_on_menu), self);
-    ka_applet_create_tray_icon_context_menu (self);
-    return TRUE;
-}
-
 static int
 ka_applet_setup_icons (KaApplet *applet)
 {
@@ -1141,42 +948,6 @@ ka_applet_signal_emit (KaApplet *this,
 }
 
 
-static void
-ka_ns_check_persistence (KaApplet *self)
-{
-    GList   *caps;
-    GList   *l;
-    gboolean is_autostart = g_getenv("DESKTOP_AUTOSTART_ID") ? TRUE : FALSE;
-    gint    seconds = 5;
-
-    self->priv->ns_persistence = FALSE;
-
-    if (self->priv->debug_flags & KA_DEBUG_NO_PERSISTENCE)
-        return;
-
-    do {
-        caps = notify_get_server_caps ();
-        if (caps == NULL)
-            g_warning ("Failed to read server caps");
-        else {
-            l = g_list_find_custom (caps, "persistence", (GCompareFunc)strcmp);
-            if (l != NULL) {
-                self->priv->ns_persistence = TRUE;
-                KA_DEBUG ("Notification server supports persistence.");
-            }
-            g_list_free_full (caps, (GDestroyNotify)g_free);
-        }
-        /* During session start we have to wait until the shell is fully up
-         * to reliably detect the persistence property (#642666) */
-        if (is_autostart && !self->priv->ns_persistence) {
-            sleep(1);
-            seconds--;
-        } else
-            break;
-    } while (seconds);
-}
-
-
 /* undo what was done on startup() */
 void
 ka_applet_destroy (KaApplet* self)
@@ -1194,16 +965,10 @@ ka_applet_destroy (KaApplet* self)
     gtk_widget_destroy (GTK_WIDGET(self->priv->prefs));
     self->priv->prefs = NULL;
 
-    if (self->priv->context_menu) {
-        gtk_widget_destroy (GTK_WIDGET(self->priv->context_menu));
-        self->priv->context_menu = NULL;
-    }
-
     ka_kerberos_destroy ();
 }
 
 
-/* create the tray icon applet */
 KaApplet *
 ka_applet_create ()
 {
@@ -1226,9 +991,6 @@ ka_applet_create ()
 
     g_return_val_if_fail (ka_dbus_connect (applet), NULL);
 
-    ka_ns_check_persistence(applet);
-    ka_applet_create_tray_icon (applet);
-
     return applet;
 }
 
diff --git a/src/krb5-auth-dialog.gresource.xml b/src/krb5-auth-dialog.gresource.xml
index c149d76..e941cb3 100644
--- a/src/krb5-auth-dialog.gresource.xml
+++ b/src/krb5-auth-dialog.gresource.xml
@@ -5,6 +5,5 @@
     <file preprocess="xml-stripblanks">ui/ka-pwdialog.ui</file>
     <file preprocess="xml-stripblanks">ui/ka-preferences.ui</file>
     <file preprocess="xml-stripblanks">ui/app-menu.ui</file>
-    <file preprocess="xml-stripblanks">ui/tray-icon-menu.ui</file>
   </gresource>
 </gresources>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]