Esempio n. 1
0
static void
dhcpcd_if_cb(DHCPCD_IF *i, _unused void *data)
{
	DHCPCD_CONNECTION *con;
	char *msg;
	const char *icon;
	bool new_msg;

	/* We should ignore renew and stop so we don't annoy the user */
	if (g_strcmp0(i->reason, "RENEW") &&
	    g_strcmp0(i->reason, "STOP") &&
	    g_strcmp0(i->reason, "STOPPED"))
	{
		msg = dhcpcd_if_message(i, &new_msg);
		if (msg) {
			g_message("%s", msg);
			if (new_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);
		}
	}

	/* Update the tooltip with connection information */
	con = dhcpcd_if_connection(i);
	update_online(con, false);
}
Esempio n. 2
0
static void
update_online(DHCPCD_CONNECTION *con, bool showif)
{
	bool ison, iscarrier;
	char *msg, *msgs, *tmp;
	DHCPCD_IF *ifs, *i;

	ison = iscarrier = false;
	msgs = NULL;
	ifs = dhcpcd_interfaces(con);
	for (i = ifs; i; i = i->next) {
		if (g_strcmp0(i->type, "link") == 0) {
			if (i->up)
				iscarrier = true;
		} else {
			if (i->up)
				ison = true;
		}
		msg = dhcpcd_if_message(i, NULL);
		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) {
		online = ison;
		carrier = iscarrier;
		if (ani_timer != 0) {
			g_source_remove(ani_timer);
			ani_timer = 0;
			ani_counter = 0;
		}
		if (ison) {
			animate_online(NULL);
			ani_timer = g_timeout_add(300, animate_online, NULL);
		} else if (iscarrier) {
			animate_carrier(NULL);
			ani_timer = g_timeout_add(500, animate_carrier, NULL);
		} else {
			gtk_status_icon_set_from_icon_name(status_icon,
			    "network-offline");
		}
	}
	gtk_status_icon_set_tooltip_text(status_icon, msgs);
	g_free(msgs);
}
void DhcpcdQt::updateOnline(bool showIf)
{
	bool isOn, isCarrier;
	char *msg;
	DHCPCD_IF *ifs, *i;
	QString msgs;

	isOn = isCarrier = false;
	ifs = dhcpcd_interfaces(con);
	for (i = ifs; i; i = i->next) {
		if (strcmp(i->type, "link") == 0) {
			if (i->up)
				isCarrier = true;
		} else {
			if (i->up)
				isOn = true;
		}
		msg = dhcpcd_if_message(i, NULL);
		if (msg) {
			if (showIf)
				qDebug() << msg;
			if (msgs.isEmpty())
				msgs = QString::fromAscii(msg);
			else
				msgs += '\n' + QString::fromAscii(msg);
			free(msg);
		} else if (showIf)
			qDebug() << i->ifname << i->reason;
	}

	if (onLine != isOn || carrier != isCarrier) {
		onLine = isOn;
		carrier = isCarrier;
		aniTimer->stop();
		aniCounter = 0;
		if (isOn) {
			animate();
			aniTimer->start(300);
		} else if (isCarrier) {
			animate();
			aniTimer->start(500);
		} else
			setIcon("status", "network-offline");
	}

	trayIcon->setToolTip(msgs);
}
void DhcpcdQt::ifCallback(DHCPCD_IF *i)
{
	char *msg;
	bool new_msg;

	if (strcmp(i->reason, "RENEW") &&
	    strcmp(i->reason, "STOP") &&
	    strcmp(i->reason, "STOPPED"))
	{
		msg = dhcpcd_if_message(i, &new_msg);
		if (msg) {
			qDebug("%s", msg);
			if (new_msg) {
				QSystemTrayIcon::MessageIcon icon =
				    i->up ? QSystemTrayIcon::Information :
				    QSystemTrayIcon::Warning;
				QString t = tr("Network Event");
				QString m = msg;
				notify(t, m, icon);
			}
			free(msg);
		}
	}

	updateOnline(false);

	if (i->wireless) {
		for (auto &wi : *wis) {
			DHCPCD_WPA *wpa = wi->getWpa();
			if (dhcpcd_wpa_if(wpa) == i) {
				DHCPCD_WI_SCAN *scans;

				scans = dhcpcd_wi_scans(i);
				processScans(wi, scans);
			}
		}
	}
}