void DhcpcdQt::statusCallback(const char *status)
{

	qDebug("Status changed to %s", status);
	if (strcmp(status, "down") == 0) {
		aniTimer->stop();
		aniCounter = 0;
		onLine = carrier = false;
		setIcon("status", "network-offline");
		trayIcon->setToolTip(tr("Not connected to dhcpcd"));
		/* Close down everything */
		if (notifier) {
			notifier->setEnabled(false);
			notifier->deleteLater();
			notifier = NULL;
		}
		if (ssidMenu) {
			ssidMenu->deleteLater();
			ssidMenu = NULL;
		}
		preferencesAction->setEnabled(false);
		if (preferences) {
			preferences->deleteLater();
			preferences = NULL;
		}
	} else {
		bool refresh;

		if (lastStatus == NULL || strcmp(lastStatus, "down") == 0) {
			qDebug("Connected to dhcpcd-%s", dhcpcd_version(con));
			refresh = true;
		} else
			refresh = strcmp(lastStatus, "opened") ? false : true;
		updateOnline(refresh);
	}

	free(lastStatus);
	lastStatus = strdup(status);

	if (strcmp(status, "down") == 0) {
		if (retryOpenTimer == NULL) {
			retryOpenTimer = new QTimer(this);
			connect(retryOpenTimer, SIGNAL(timeout()),
			    this, SLOT(tryOpen()));
			retryOpenTimer->start(DHCPCD_RETRYOPEN);
		}
	}
}
Exemple #2
0
static void
dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status,
    _unused void *data)
{
	static char *last = NULL;
	const char *msg;
	bool refresh;
	WI_SCAN *w;

	g_message("Status changed to %s", status);
	if (g_strcmp0(status, "down") == 0) {
		msg = N_(last ?
		    "Connection to dhcpcd lost" : "dhcpcd not running");
		if (ani_timer != 0) {
			g_source_remove(ani_timer);
			ani_timer = 0;
			ani_counter = 0;
		}
		online = carrier = false;
		gtk_status_icon_set_from_icon_name(status_icon,
		    "network-offline");
		gtk_status_icon_set_tooltip_text(status_icon, msg);
		dhcpcd_prefs_abort();
		while (wi_scans) {
			w = wi_scans->next;
			dhcpcd_wi_scans_free(wi_scans->scans);
			g_free(wi_scans);
			wi_scans = w;
		}
		dhcpcd_unwatch(-1, con);
		g_timeout_add(DHCPCD_RETRYOPEN, dhcpcd_try_open, con);
	} else {
		if ((last == NULL || g_strcmp0(last, "down") == 0)) {
			g_message(_("Connected to %s-%s"), "dhcpcd",
			    dhcpcd_version(con));
			refresh = true;
		} else
			refresh = g_strcmp0(last, "opened") ? false : true;
		update_online(con, refresh);
	}

	g_free(last);
	last = g_strdup(status);
}