aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorguidog <guidog@517b70f8-ed25-0410-8bf6-f5db08f7b76e>2009-01-10 13:25:42 +0000
committerguidog <guidog@517b70f8-ed25-0410-8bf6-f5db08f7b76e>2009-01-10 13:25:42 +0000
commitf3856ed33296714b37691e4cbf18797bd205514f (patch)
treed0f155cc6b8a5ebb71d20bad784d138c7169e8d1 /src
parentb34cfa0d399f1478ffa11f27e99d796bb78bd699 (diff)
move HAVE_LIBNOTIFY check into krb5-auth-notify.c
and simplify ka_update_status git-svn-id: http://svn.gnome.org/svn/krb5-auth-dialog/trunk@110 517b70f8-ed25-0410-8bf6-f5db08f7b76e
Diffstat (limited to 'src')
-rw-r--r--src/krb5-auth-applet.c80
-rw-r--r--src/krb5-auth-notify.c19
-rw-r--r--src/krb5-auth-notify.h4
3 files changed, 66 insertions, 37 deletions
diff --git a/src/krb5-auth-applet.c b/src/krb5-auth-applet.c
index 4f2215d..c915240 100644
--- a/src/krb5-auth-applet.c
+++ b/src/krb5-auth-applet.c
@@ -24,73 +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
-enum ka_icons {
+enum ka_icon {
inv_icon = 0,
exp_icon,
val_icon,
};
-/* update the tray icon's tooltip and icon */
-int
-ka_update_status(Krb5AuthApplet* applet, krb5_timestamp expiry)
+
+/* 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);
- gtk_status_icon_set_from_icon_name (applet->tray_icon, applet->icons[val_icon]);
+ 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[exp_icon]);
}
-#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 &&
!applet->renewable) {
- ka_send_event_notification (applet, NOTIFY_URGENCY_NORMAL,
+ 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[inv_icon]);
-#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;
}
diff --git a/src/krb5-auth-notify.c b/src/krb5-auth-notify.c
index 3186a47..019662e 100644
--- a/src/krb5-auth-notify.c
+++ b/src/krb5-auth-notify.c
@@ -18,15 +18,14 @@
*/
#include "config.h"
-
-#ifdef HAVE_LIBNOTIFY
-
#include "krb5-auth-applet.h"
#include "krb5-auth-notify.h"
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notify.h>
+
void
ka_send_event_notification (Krb5AuthApplet *applet,
- NotifyUrgency urgency,
const char *summary,
const char *message,
const char *icon)
@@ -50,8 +49,18 @@ ka_send_event_notification (Krb5AuthApplet *applet,
applet->notification = \
notify_notification_new_with_status_icon(summary, message, notify_icon, applet->tray_icon);
- notify_notification_set_urgency (applet->notification, urgency);
+ notify_notification_set_urgency (applet->notification, NOTIFY_URGENCY_NORMAL);
notify_notification_show (applet->notification, NULL);
}
+#else /* HAVE_LIBNOTIFY */
+
+void
+ka_send_event_notification (Krb5AuthApplet *applet __attribute__((__unused__)),
+ const char *summary __attribute__((__unused__)),
+ const char *message __attribute__((__unused__)),
+ const char *icon __attribute__((__unused__)))
+{
+}
+
#endif /* HAVE_LIBNOTIFY */
diff --git a/src/krb5-auth-notify.h b/src/krb5-auth-notify.h
index 7d27b8a..9c0ce55 100644
--- a/src/krb5-auth-notify.h
+++ b/src/krb5-auth-notify.h
@@ -21,12 +21,8 @@
#ifndef KRB5_AUTH_NOTIFY_H
#define KRB5_AUTH_NOTIFY_H
-#include <libnotify/notify.h>
-
void ka_send_event_notification (Krb5AuthApplet *applet,
- NotifyUrgency urgency,
const char *summary,
const char *message,
const char *icon);
#endif
-