From: Max Lapan Date: Tue, 16 Mar 2010 12:12:46 +0000 (+0300) Subject: Hanlde situation when user changes connection. X-Git-Tag: v0.1~27 X-Git-Url: https://vcs.maemo.org/git/?p=yandex-traffic;a=commitdiff_plain;h=39d019b3778ff4027f41e356fb6956e1a13bdca1 Hanlde situation when user changes connection. When this occurs, connected and disconnected events are mixed, so we may become confused. To handle this, we maintain connection counter. If it becomes 2, we don't emit disconnect signal, just decrement the counter. --- diff --git a/connection.cpp b/connection.cpp index a487364..9e990c3 100644 --- a/connection.cpp +++ b/connection.cpp @@ -26,6 +26,7 @@ ConnectionChecker::ConnectionChecker () _itf = new QDBusInterface (ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE, _bus); _bus.connect (ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE, ICD_DBUS_API_STATE_SIG, this, SLOT (stateSignal (const QDBusMessage&))); + _conn_counter = 0; requestState (); } @@ -43,11 +44,19 @@ void ConnectionChecker::requestState () void ConnectionChecker::stateSignal (const QDBusMessage& msg) { - if (msg.arguments ().count () == 8) { - unsigned int status = msg.arguments ().value (7).value(); + if (msg.arguments ().count () != 8) + return; - updateState (status == ICD_STATE_CONNECTED, msg.arguments ().value (3).toString ()); - } + unsigned int state = msg.arguments ().value (7).value(); + QString net = msg.arguments ().value (3).toString (); + + if (state == ICD_STATE_CONNECTED) + _conn_counter++; + if (state == ICD_STATE_DISCONNECTED) + _conn_counter--; + + if (state == ICD_STATE_CONNECTED || !_conn_counter) + updateState (state == ICD_STATE_CONNECTED, net); } @@ -65,9 +74,10 @@ void ConnectionChecker::updateState (bool new_state, const QString& net_type) new_net = Net_WLAN; else if (net_type.startsWith ("GPRS") || net_type.startsWith ("DUN_GSM")) new_net = Net_GSM; - if (new_net != _net_type) { - _net_type = new_net; - type_changed (_net_type); - } + } + + if (new_net != _net_type) { + _net_type = new_net; + type_changed (_net_type); } } diff --git a/connection.hpp b/connection.hpp index 3d6bd8c..e89b267 100644 --- a/connection.hpp +++ b/connection.hpp @@ -20,6 +20,7 @@ public: private: bool _connected; network_type_t _net_type; + int _conn_counter; QDBusConnection _bus; QDBusInterface *_itf;