/*
* dhcpcd-gtk
- * Copyright 2009-2012 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
#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;
static void
update_online(DHCPCD_CONNECTION *con, bool showif)
{
- bool ison, iscarrier, isstop;
+ bool ison, iscarrier;
char *msg, *msgs, *tmp;
- DHCPCD_IF *ifs, *i, *j;
+ DHCPCD_IF *ifs, *i;
ison = iscarrier = 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 (strcmp(i->type, "ipv4") != 0) {
- isstop = false;
- for (j = ifs; j; j = j->next)
- if (strcmp(j->ifname, i->ifname) == 0 &&
- strcmp(j->type, "ipv4") == 0)
- {
- if (strcmp(j->reason, "STOP") == 0)
- isstop = true;
- break;
- }
- if (isstop)
- continue;
- }
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) {
{
char **msgs, **m;
+ if (msg == NULL)
+ return;
/* Don't spam the same message */
if (notify_last_msg) {
- if (strcmp(msg, notify_last_msg) == 0)
+ if (notify_last_msg && strcmp(msg, notify_last_msg) == 0)
return;
g_free(notify_last_msg);
}
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 (i->up)
- icon = "network-transmit-receive";
- //else
- // icon = "network-transmit";
- if (!i->up)
- 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
{
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_warning(_("Error creating new GIO Channel\n"));
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");