RZLWidget::RZLWidget(QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_TranslucentBackground); icon_unklar = new QIcon("/usr/share/raumzeitlabor-status-widget/unklar.png"); icon_auf = new QIcon("/usr/share/raumzeitlabor-status-widget/auf.png"); icon_zu = new QIcon("/usr/share/raumzeitlabor-status-widget/zu.png"); icon = icon_unklar; lastUpdated = "?"; hdl = curl_easy_init(); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Pragma: no-cache"); headers = curl_slist_append(headers, "Cache-Control: no-cache"); curl_easy_setopt(hdl, CURLOPT_URL, "http://status.raumzeitlabor.de/api/simple"); curl_easy_setopt(hdl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(hdl, CURLOPT_WRITEFUNCTION, recv_status); curl_easy_setopt(hdl, CURLOPT_WRITEDATA, this); curl_easy_setopt(hdl, CURLOPT_ERRORBUFFER, errbuf); /* set a timeout of 30 seconds */ curl_easy_setopt(hdl, CURLOPT_TIMEOUT, 30); /* Timer will be triggered in setConnection() as soon as the connection * status is known */ timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(trigger_update())); periodic_bearer = new QTimer(this); periodic_bearer->start(60 * 1000); connect(periodic_bearer, SIGNAL(timeout()), this, SLOT(trigger_periodic())); /* Setup stuff for the conic library */ DBusConnection *conn; DBusError err; dbus_error_init(&err); conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); if (!conn) return; dbus_connection_setup_with_g_main(conn, NULL); /* We want to get called on connection events */ connection = con_ic_connection_new(); g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(connection_change), this); g_object_set(G_OBJECT(connection), "automatic-connection-events", TRUE, NULL); /* ConIcConnection object named "connection" has already been created */ g_signal_connect(G_OBJECT(connection), "statistics", G_CALLBACK(connection_statistics), this); con_ic_connection_statistics(connection, NULL); }
Network::Network() : networkState(NetworkStateUnknown), networkStateChangeAction(new Model::Action()), connection(NULL) { connection=con_ic_connection_new(); if (connection!=NULL) { g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(ConnectionHandler), this); g_object_set(G_OBJECT(connection), "automatic-connection-events", true, NULL); con_ic_connection_connect(connection,CON_IC_CONNECT_FLAG_AUTOMATICALLY_TRIGGERED); } else { std::cerr << "Could not create ConIcConnection instance!" << std::endl; } }