void ConnectionChecker::stateSignal (const QDBusMessage& msg)
{
- unsigned int status = msg.arguments ().value (7).value<unsigned int>();
+ if (msg.arguments ().count () == 8) {
+ unsigned int status = msg.arguments ().value (7).value<unsigned int>();
- updateState (status == ICD_STATE_CONNECTED);
+ updateState (status == ICD_STATE_CONNECTED, msg.arguments ().value (3).toString ());
+ }
}
-void ConnectionChecker::updateState (bool new_state)
+void ConnectionChecker::updateState (bool new_state, const QString& net_type)
{
+ network_type_t new_net = Net_None;
+
if (new_state != _connected) {
_connected = new_state;
emit connected (_connected);
}
+
+ if (_connected) {
+ if (net_type.startsWith ("WLAN"))
+ 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);
+ }
+ }
}
{
Q_OBJECT
+public:
+ enum network_type_t {
+ Net_None,
+ Net_WLAN,
+ Net_GSM,
+ };
+
private:
bool _connected;
+ network_type_t _net_type;
+
QDBusConnection _bus;
QDBusInterface *_itf;
protected:
ConnectionChecker ();
- void updateState (bool new_state);
+ void updateState (bool new_state, const QString& net_type = QString ());
protected slots:
void stateSignal (const QDBusMessage& msg);
bool isConnected () const
{ return _connected; };
+ network_type_t network_type () const
+ { return _net_type; };
+
void requestState ();
signals:
void connected (bool active);
+ void type_changed (ConnectionChecker::network_type_t type);
};
#endif // __CONNECTION_H__
ConnectionChecker *cc = ConnectionChecker::instance ();
connect (cc, SIGNAL (connected (bool)), SLOT (connected (bool)));
+ connect (cc, SIGNAL (type_changed (ConnectionChecker::network_type_t)), SLOT (type_changed (ConnectionChecker::network_type_t)));
setText (cc->isConnected () ? "Connected" : "Not connected");
connect (this, SIGNAL (clicked ()), SLOT (checkConnection ()));
setText (ConnectionChecker::instance ()->isConnected () ? "Connected" : "Not connected");
}
+ void type_changed (ConnectionChecker::network_type_t type)
+ {
+ switch (type) {
+ case ConnectionChecker::Net_None:
+ printf ("Type: none\n");
+ break;
+ case ConnectionChecker::Net_WLAN:
+ printf ("Type: WLAN\n");
+ break;
+ case ConnectionChecker::Net_GSM:
+ printf ("Type: GSM\n");
+ break;
+ }
+ }
+
void checkConnection ()
{
ConnectionChecker::instance ()->requestState ();