/*
* dhcpcd-gtk
- * Copyright 2009 Roy Marples <roy@marples.name>
+ * Copyright 2009-2014 Roy Marples <roy@marples.name>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#ifdef NOTIFY
# include <libnotify/notify.h>
+#ifndef NOTIFY_CHECK_VERSION
+# define NOTIFY_CHECK_VERSION(a,b,c) 0
+#endif
static NotifyNotification *nn;
#endif
+#include "config.h"
#include "dhcpcd-gtk.h"
static GtkStatusIcon *status_icon;
-static int ani_timer;
+static guint ani_timer;
static int ani_counter;
static bool online;
static bool carrier;
struct watch {
struct pollfd pollfd;
- int eventid;
+ guint eventid;
GIOChannel *gio;
struct watch *next;
};
animate_carrier(_unused gpointer data)
{
const char *icon;
-
+
if (ani_timer == 0)
return false;
animate_online(_unused gpointer data)
{
const char *icon;
-
+
if (ani_timer == 0)
return false;
msgs = NULL;
ifs = dhcpcd_interfaces(con);
for (i = ifs; i; i = i->next) {
- if (showif)
- g_message("%s: %s", i->ifname, i->reason);
- if (strcmp(i->reason, "RELEASE") == 0 ||
- strcmp(i->reason, "STOP") == 0)
- continue;
- if (dhcpcd_if_up(i))
+ if (i->up)
ison = iscarrier = true;
if (!iscarrier && g_strcmp0(i->reason, "CARRIER") == 0)
iscarrier = true;
msg = dhcpcd_if_message(i);
- if (msgs) {
- tmp = g_strconcat(msgs, "\n", msg, NULL);
- g_free(msgs);
- g_free(msg);
- msgs = tmp;
- } else
- msgs = msg;
+ if (msg) {
+ if (showif)
+ g_message("%s", msg);
+ if (msgs) {
+ tmp = g_strconcat(msgs, "\n", msg, NULL);
+ g_free(msgs);
+ g_free(msg);
+ msgs = tmp;
+ } else
+ msgs = msg;
+ } else if (showif)
+ g_message("%s: %s", i->ifname, i->reason);
}
if (online != ison || carrier != iscarrier) {
"network-offline");
}
}
- gtk_status_icon_set_tooltip(status_icon, msgs);
+ gtk_status_icon_set_tooltip_text(status_icon, msgs);
g_free(msgs);
}
#endif
}
+#ifdef NOTIFY
+static char *notify_last_msg;
+
static void
notify_closed(void)
{
-#ifdef NOTIFY
nn = NULL;
-#endif
}
-#ifdef NOTIFY
static void
notify(const char *title, const char *msg, const char *icon)
{
char **msgs, **m;
+ if (msg == NULL)
+ return;
+ /* Don't spam the same message */
+ if (notify_last_msg) {
+ if (notify_last_msg && strcmp(msg, notify_last_msg) == 0)
+ return;
+ g_free(notify_last_msg);
+ }
+ notify_last_msg = g_strdup(msg);
+
msgs = g_strsplit(msg, "\n", 0);
for (m = msgs; *m; m++)
g_message("%s", *m);
g_strfreev(msgs);
+
if (nn != NULL)
notify_notification_close(nn, NULL);
+
+#if NOTIFY_CHECK_VERSION(0,7,0)
+ nn = notify_notification_new(title, msg, icon);
+ notify_notification_set_hint(nn, "transient",
+ g_variant_new_boolean(TRUE));
+#else
if (gtk_status_icon_get_visible(status_icon))
nn = notify_notification_new_with_status_icon(title,
msg, icon, status_icon);
else
nn = notify_notification_new(title, msg, icon, NULL);
+#endif
+
notify_notification_set_timeout(nn, 5000);
g_signal_connect(nn, "closed", G_CALLBACK(notify_closed), NULL);
notify_notification_show(nn, NULL);
char *msg;
const char *icon;
- g_message("%s: %s", i->ifname, i->reason);
+ g_message("interface event: %s: %s", i->ifname, i->reason);
update_online(con, false);
-
+
/* We should ignore renew and stop so we don't annoy the user */
if (g_strcmp0(i->reason, "RENEW") == 0 ||
g_strcmp0(i->reason, "STOP") == 0)
return;
msg = dhcpcd_if_message(i);
- if (dhcpcd_if_up(i))
- icon = "network-transmit-receive";
- else
- icon = "network-transmit";
- if (dhcpcd_if_down(i))
- icon = "network-offline";
- notify(_("Network event"), msg, icon);
- g_free(msg);
+ if (msg) {
+ g_message("%s", msg);
+ if (i->up)
+ icon = "network-transmit-receive";
+ //else
+ // icon = "network-transmit";
+ if (!i->up)
+ icon = "network-offline";
+ notify(_("Network event"), msg, icon);
+ g_free(msg);
+ }
}
static void
if (g_strcmp0(status, "down") == 0) {
msg = N_(last ?
"Connection to dhcpcd lost" : "dhcpcd not running");
- gtk_status_icon_set_tooltip(status_icon, msg);
+ if (ani_timer != 0) {
+ g_source_remove(ani_timer);
+ ani_timer = 0;
+ ani_counter = 0;
+ }
+ gtk_status_icon_set_from_icon_name(status_icon,
+ "network-offline");
+ gtk_status_icon_set_tooltip_text(status_icon, msg);
notify(_("No network"), msg, "network-offline");
dhcpcd_prefs_abort();
while (wi_scans) {
w = wi_scans->next;
- dhcpcd_wi_scans_free(w->scans);
- free(wi_scans);
+ dhcpcd_wi_scans_free(wi_scans->scans);
+ g_free(wi_scans);
wi_scans = w;
}
} else {
g_message(_("%s: Received scan results"), i->ifname);
scans = dhcpcd_wi_scans(con, i);
+ if (scans == NULL && dhcpcd_error(con) != NULL) {
+ g_warning("%s: %s", i->ifname, dhcpcd_error(con));
+ dhcpcd_error_clear(con);
+ }
for (w = wi_scans; w; w = w->next)
if (w->connection == con && w->interface == i)
break;
notify(msg, txt, "network-wireless");
g_free(txt);
}
- g_free(w->scans);
+ dhcpcd_wi_scans_free(w->scans);
}
w->scans = scans;
}
{
struct watch *w;
GIOChannel *gio;
- int flags, eventid;
+ GIOCondition flags;
+ guint eventid;
/* Remove any existing watch */
delete_watch_cb(con, fd, data);
-
+
gio = g_io_channel_unix_new(fd->fd);
if (gio == NULL) {
- g_error(_("Error creating new GIO Channel\n"));
+ g_warning(_("Error creating new GIO Channel\n"));
return;
}
flags = 0;
flags |= G_IO_HUP;
if ((eventid = g_io_add_watch(gio, flags, gio_callback, con)) == 0) {
g_io_channel_unref(gio);
- g_error(_("Error creating watch\n"));
+ g_warning(_("Error creating watch\n"));
return;
}
w = g_malloc(sizeof(*w));
char *error = NULL;
char *version = NULL;
DHCPCD_CONNECTION *con;
-
+
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, NULL);
bind_textdomain_codeset(PACKAGE, "UTF-8");
- textdomain(PACKAGE);
+ textdomain(PACKAGE);
gtk_init(&argc, &argv);
g_set_application_name("Network Configurator");
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
ICONDIR);
status_icon = gtk_status_icon_new_from_icon_name("network-offline");
-
- gtk_status_icon_set_tooltip(status_icon,
+
+ gtk_status_icon_set_tooltip_text(status_icon,
_("Connecting to dhcpcd ..."));
gtk_status_icon_set_visible(status_icon, true);
+#ifdef NOTIFY
notify_init(PACKAGE);
+#endif
g_message(_("Connecting ..."));
con = dhcpcd_open(&error);
- if (con == NULL)
+ if (con == NULL) {
g_critical("libdhcpcd: %s", error);
+ exit(EXIT_FAILURE);
+ }
- gtk_status_icon_set_tooltip(status_icon, _("Triggering dhcpcd ..."));
+ gtk_status_icon_set_tooltip_text(status_icon,
+ _("Triggering dhcpcd ..."));
online = false;
if (!dhcpcd_command(con, "GetVersion", NULL, &version)) {
dhcpcd_set_watch_functions(con, add_watch_cb, delete_watch_cb, NULL);
dhcpcd_set_signal_functions(con, event_cb, status_cb, scan_cb, NULL);
- if (dhcpcd_error(con))
- g_error("libdhcpcd: %s", dhcpcd_error(con));
+ if (dhcpcd_error(con)) {
+ g_critical("libdhcpcd: %s", dhcpcd_error(con));
+ exit(EXIT_FAILURE);
+ }
menu_init(status_icon, con);