diff options
author | Guido Günther <agx@sigxcpu.org> | 2008-10-18 18:17:23 +0200 |
---|---|---|
committer | Guido Guenther <agx@sigxcpu.org> | 2008-10-18 18:17:23 +0200 |
commit | f1bf81e507d3319a6b31f4f679165fb72d58086a (patch) | |
tree | 8f6ac6188a950d210f8c3e8fedbf29bc343aa4d5 /src/krb5-auth-applet.c | |
parent | document changes and release 0.7.hit7cc1d84-1 (diff) | |
parent | Imported Upstream version 0.7.jit26357da (diff) | |
download | krb5-auth-dialog-f1bf81e507d3319a6b31f4f679165fb72d58086a.tar.gz krb5-auth-dialog-f1bf81e507d3319a6b31f4f679165fb72d58086a.tar.bz2 krb5-auth-dialog-f1bf81e507d3319a6b31f4f679165fb72d58086a.zip |
Merge commit 'upstream/0.7.jit26357da'
Diffstat (limited to 'src/krb5-auth-applet.c')
-rw-r--r-- | src/krb5-auth-applet.c | 94 |
1 files changed, 64 insertions, 30 deletions
diff --git a/src/krb5-auth-applet.c b/src/krb5-auth-applet.c index 4a11d09..c915240 100644 --- a/src/krb5-auth-applet.c +++ b/src/krb5-auth-applet.c @@ -24,65 +24,97 @@ #include "krb5-auth-applet.h" #include "krb5-auth-dialog.h" -#ifdef HAVE_LIBNOTIFY #include "krb5-auth-notify.h" -#endif #define NOTIFY_SECONDS 300 -/* update the tray icon's tooltip and icon */ -int -ka_update_status(Krb5AuthApplet* applet, krb5_timestamp expiry) +enum ka_icon { + inv_icon = 0, + exp_icon, + val_icon, +}; + + +/* determine the new tooltip text */ +static char* +ka_tooltip_text(Krb5AuthApplet* applet, int remaining) { - gchar* expiry_text; - int now = time(0); - int remaining = expiry - now; - static int last_warn = 0; - static gboolean expiry_notified = FALSE; + int hours, minutes; + gchar* tooltip_text; if (remaining > 0) { - int hours, minutes; if (remaining >= 3600) { hours = remaining / 3600; minutes = (remaining % 3600) / 60; - expiry_text = g_strdup_printf (_("Your credentials expire in %.2d:%.2dh"), hours, minutes); + tooltip_text = g_strdup_printf (_("Your credentials expire in %.2d:%.2dh"), hours, minutes); } else { minutes = remaining / 60; - expiry_text = g_strdup_printf (ngettext( + tooltip_text = g_strdup_printf (ngettext( "Your credentials expire in %d minute", "Your credentials expire in %d minutes", minutes), minutes); } - gtk_status_icon_set_from_icon_name (applet->tray_icon, applet->icons[1]); -#ifdef HAVE_LIBNOTIFY + } else + tooltip_text = g_strdup (_("Your credentials have expired")); + return tooltip_text; +} + + +/* determine the current icon */ +static const char* +ka_select_icon(Krb5AuthApplet* applet, int remaining) +{ + enum ka_icon tray_icon = inv_icon; + + if (remaining > 0) { + if (remaining < applet->pw_prompt_secs && + !applet->renewable) + tray_icon = exp_icon; + else + tray_icon = val_icon; + } + + return applet->icons[tray_icon]; +} + + +/* update the tray icon's tooltip and icon */ +int +ka_update_status(Krb5AuthApplet* applet, krb5_timestamp expiry) +{ + int now = time(0); + int remaining = expiry - now; + static int last_warn = 0; + static gboolean expiry_notified = FALSE; + const char* tray_icon = ka_select_icon (applet, remaining); + char* tooltip_text = ka_tooltip_text (applet, remaining); + + if (remaining > 0) { if (expiry_notified) { - ka_send_event_notification (applet, NOTIFY_URGENCY_NORMAL, + ka_send_event_notification (applet, _("Network credentials valid"), _("Your Kerberos credentials have been refreshed."), NULL); expiry_notified = FALSE; - } else if (remaining < applet->pw_prompt_secs && (now - last_warn) > NOTIFY_SECONDS) { - ka_send_event_notification (applet, NOTIFY_URGENCY_NORMAL, + } else if (remaining < applet->pw_prompt_secs && (now - last_warn) > NOTIFY_SECONDS && + !applet->renewable) { + ka_send_event_notification (applet, _("Network credentials expiring"), - expiry_text, NULL); + tooltip_text, NULL); last_warn = now; } -#endif } else { - expiry_text = g_strdup (_("Your credentials have expired")); - gtk_status_icon_set_from_icon_name (applet->tray_icon, applet->icons[0]); -#ifdef HAVE_LIBNOTIFY if (!expiry_notified) { - ka_send_event_notification (applet, NOTIFY_URGENCY_NORMAL, + ka_send_event_notification (applet, _("Network credentials expired"), _("Your Kerberos credentails have expired."), NULL); expiry_notified = TRUE; last_warn = 0; } -#endif } - gtk_status_icon_set_tooltip (applet->tray_icon, expiry_text); - g_free (expiry_text); + gtk_status_icon_set_from_icon_name (applet->tray_icon, tray_icon); + gtk_status_icon_set_tooltip (applet->tray_icon, tooltip_text); + g_free(tooltip_text); return 0; } @@ -213,7 +245,7 @@ ka_create_tray_icon (Krb5AuthApplet* applet) g_signal_connect (G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(ka_tray_icon_on_menu), applet); - gtk_status_icon_set_from_icon_name (tray_icon, applet->icons[0]); + gtk_status_icon_set_from_icon_name (tray_icon, applet->icons[exp_icon]); gtk_status_icon_set_tooltip (tray_icon, PACKAGE); return tray_icon; } @@ -222,8 +254,9 @@ ka_create_tray_icon (Krb5AuthApplet* applet) int ka_setup_icons (Krb5AuthApplet* applet) { - applet->icons[0] = "krb-no-valid-ticket"; - applet->icons[1] = "krb-valid-ticket"; + applet->icons[val_icon] = "krb-valid-ticket"; + applet->icons[exp_icon] = "krb-expiring-ticket"; + applet->icons[inv_icon] = "krb-no-valid-ticket"; return TRUE; } @@ -240,6 +273,7 @@ ka_create_applet() g_error ("Failure to create tray icon"); if (!(applet->context_menu = ka_create_context_menu (applet))) g_error ("Failure to create context menu"); + gtk_window_set_default_icon_name (applet->icons[val_icon]); ka_show_tray_icon (applet); return applet; |