summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamarque V. Souza <lamarque@gmail.com>2011-09-26 19:30:52 (GMT)
committerLamarque V. Souza <lamarque@gmail.com>2011-09-26 19:39:07 (GMT)
commit987e18493c26ea52ca9ca216e4083a6fabb95092 (patch)
treec11f5a5804ca66dada5c0325c70babc5baed5806
parent81ea2edfa3a6350d7aff8b90d254f0c789fa46ef (diff)
Make kded's networkstatus module watch for backends' (un)registration
signals. Without this patch if the backend (currently NetworkManager and Wicd) stops running networkstatus will keep the last known state and will never update it anymore, even if the backend starts running in the future. That happens with NM's backend because the m_manager object requires NM running when it is initialized in NetworkManagerStatus constructor. Probably the same happens with Wicd backend but I have not tested it (the Wicd backend uses a different way to connect to Wicd service). (cherry picked from commit 34dcf57a1c972a34d54196f34e2ecd01380aef0f)
-rw-r--r--solid-networkstatus/kded/networkmanagerstatus.cpp11
-rw-r--r--solid-networkstatus/kded/networkmanagerstatus.h1
-rw-r--r--solid-networkstatus/kded/networkstatus.cpp73
-rw-r--r--solid-networkstatus/kded/networkstatus.h5
-rw-r--r--solid-networkstatus/kded/systemstatusinterface.h1
-rw-r--r--solid-networkstatus/kded/wicdstatus.cpp5
-rw-r--r--solid-networkstatus/kded/wicdstatus.h1
7 files changed, 83 insertions, 14 deletions
diff --git a/solid-networkstatus/kded/networkmanagerstatus.cpp b/solid-networkstatus/kded/networkmanagerstatus.cpp
index 0339ffc..127e465 100644
--- a/solid-networkstatus/kded/networkmanagerstatus.cpp
+++ b/solid-networkstatus/kded/networkmanagerstatus.cpp
@@ -35,9 +35,9 @@
NetworkManagerStatus::NetworkManagerStatus( QObject *parent )
: SystemStatusInterface( parent ),
- m_manager( "org.freedesktop.NetworkManager",
- "/org/freedesktop/NetworkManager",
- "org.freedesktop.NetworkManager",
+ m_manager( NM_DBUS_SERVICE,
+ NM_DBUS_PATH,
+ NM_DBUS_INTERFACE,
QDBusConnection::systemBus() )
{
connect( &m_manager, SIGNAL(StateChanged(uint)),
@@ -60,6 +60,11 @@ bool NetworkManagerStatus::isSupported() const
return m_manager.isValid();
}
+QString NetworkManagerStatus::serviceName() const
+{
+ return QString(NM_DBUS_SERVICE);
+}
+
void NetworkManagerStatus::nmStateChanged( uint nmState )
{
emit statusChanged( convertNmState( nmState ) );
diff --git a/solid-networkstatus/kded/networkmanagerstatus.h b/solid-networkstatus/kded/networkmanagerstatus.h
index 0f57692..78ef953 100644
--- a/solid-networkstatus/kded/networkmanagerstatus.h
+++ b/solid-networkstatus/kded/networkmanagerstatus.h
@@ -36,6 +36,7 @@ public:
/* reimp */ Solid::Networking::Status status() const;
/* reimp */ bool isSupported() const;
+ /* reimp */ QString serviceName() const;
private slots:
void nmStateChanged( uint nmState );
diff --git a/solid-networkstatus/kded/networkstatus.cpp b/solid-networkstatus/kded/networkstatus.cpp
index e692d2b..2daf6e1 100644
--- a/solid-networkstatus/kded/networkstatus.cpp
+++ b/solid-networkstatus/kded/networkstatus.cpp
@@ -56,7 +56,8 @@ typedef QMap< QString, Network * > NetworkMap;
class NetworkStatusModule::Private
{
public:
- Private() : status( Solid::Networking::Unknown ), backend( 0 ), serviceWatcher( 0 )
+ Private() : status( Solid::Networking::Unknown ), backend( 0 ), serviceWatcher( 0 ),
+ backendAppearedWatcher( 0 ), backendDisappearedWatcher ( 0 )
{
}
@@ -68,6 +69,8 @@ public:
Solid::Networking::Status status;
SystemStatusInterface *backend;
QDBusServiceWatcher *serviceWatcher;
+ QDBusServiceWatcher *backendAppearedWatcher;
+ QDBusServiceWatcher *backendDisappearedWatcher;
};
// CTORS/DTORS
@@ -196,26 +199,74 @@ void NetworkStatusModule::unregisterNetwork( const QString & networkName )
}
}
+void NetworkStatusModule::backendRegistered()
+{
+ // we need to reset backend objects to make them connect to the appearing service.
+ if (!backends.isEmpty()) {
+ qDeleteAll(backends);
+ backends.clear();
+
+ delete d->backendAppearedWatcher;
+ d->backendAppearedWatcher = 0;
+
+ delete d->backendDisappearedWatcher;
+ d->backendDisappearedWatcher = 0;
+ }
+ init();
+}
+
+void NetworkStatusModule::backendUnregistered()
+{
+ solidNetworkingStatusChanged(Solid::Networking::Unknown);
+}
+
void NetworkStatusModule::init()
{
- QList<SystemStatusInterface*> backends;
+ if (backends.isEmpty()) {
#ifdef NM_BACKEND_ENABLED
- backends << new NetworkManagerStatus( this );
+ backends << new NetworkManagerStatus( this );
#endif
- backends << new WicdStatus( this );
+ backends << new WicdStatus( this );
+ }
- while ( !backends.isEmpty() ) {
- d->backend = backends.takeFirst();
- if ( d->backend->isSupported() ) {
+ for ( int i = 0; i < backends.count(); i++ ) {
+ if ( backends.value(i)->isSupported() ) {
+ // select our backend...
+ d->backend = backends.takeAt(i);
+ // and delete the rest.
qDeleteAll(backends);
backends.clear();
- } else {
- delete d->backend;
- d->backend = 0;
+ break;
}
}
- if ( d->backend != 0 ) {
+ if (d->backendAppearedWatcher == 0) {
+ d->backendAppearedWatcher = new QDBusServiceWatcher(this);
+ d->backendAppearedWatcher->setConnection(QDBusConnection::systemBus());
+ d->backendAppearedWatcher->setWatchMode(QDBusServiceWatcher::WatchForRegistration);
+ }
+
+ if ( d->backend == 0 ) {
+ // if none found watch for all backends registration.
+ for ( int i = 0; i < backends.count(); i++ ) {
+ d->backendAppearedWatcher->addWatchedService(backends.value(i)->serviceName());
+ }
+ connect(d->backendAppearedWatcher, SIGNAL(serviceRegistered(const QString &)), SLOT(backendRegistered()));
+ return;
+ } else {
+ // watch for the selected backend re-registration only.
+ d->backendAppearedWatcher->addWatchedService(d->backend->serviceName());
+ connect(d->backendAppearedWatcher, SIGNAL(serviceRegistered(const QString &)), SLOT(backendRegistered()));
+
+ // watch for the selected bakend unregistration.
+ if (d->backendDisappearedWatcher == 0) {
+ d->backendDisappearedWatcher = new QDBusServiceWatcher(this);
+ d->backendDisappearedWatcher->setConnection(QDBusConnection::systemBus());
+ d->backendDisappearedWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
+ d->backendDisappearedWatcher->addWatchedService(d->backend->serviceName());
+ connect(d->backendDisappearedWatcher, SIGNAL(serviceUnregistered(const QString &)), SLOT(backendUnregistered()));
+ }
+
connect( d->backend, SIGNAL(statusChanged(Solid::Networking::Status)),
this, SLOT(solidNetworkingStatusChanged(Solid::Networking::Status)));
Solid::Networking::Status status = d->backend->status();
diff --git a/solid-networkstatus/kded/networkstatus.h b/solid-networkstatus/kded/networkstatus.h
index 3a159d3..875dbf7 100644
--- a/solid-networkstatus/kded/networkstatus.h
+++ b/solid-networkstatus/kded/networkstatus.h
@@ -27,6 +27,8 @@
#include "network.h"
+class SystemStatusInterface;
+
class NetworkStatusModule : public KDEDModule
{
Q_OBJECT
@@ -52,6 +54,8 @@ Q_SIGNALS:
protected Q_SLOTS:
void serviceUnregistered( const QString & name );
void solidNetworkingStatusChanged( Solid::Networking::Status status );
+ void backendRegistered();
+ void backendUnregistered();
protected:
// set up embedded backend
void init();
@@ -59,6 +63,7 @@ protected:
void updateStatus();
private:
+ QList<SystemStatusInterface*> backends;
class Private;
Private *d;
};
diff --git a/solid-networkstatus/kded/systemstatusinterface.h b/solid-networkstatus/kded/systemstatusinterface.h
index 1b9427f..4d85603 100644
--- a/solid-networkstatus/kded/systemstatusinterface.h
+++ b/solid-networkstatus/kded/systemstatusinterface.h
@@ -35,6 +35,7 @@ protected:
public:
virtual Solid::Networking::Status status() const = 0;
virtual bool isSupported() const = 0;
+ virtual QString serviceName() const = 0;
signals:
void statusChanged( Solid::Networking::Status status );
diff --git a/solid-networkstatus/kded/wicdstatus.cpp b/solid-networkstatus/kded/wicdstatus.cpp
index 056e913..b18e70d 100644
--- a/solid-networkstatus/kded/wicdstatus.cpp
+++ b/solid-networkstatus/kded/wicdstatus.cpp
@@ -55,6 +55,11 @@ bool WicdStatus::isSupported() const
return m_wicd.isValid();
}
+QString WicdStatus::serviceName() const
+{
+ return QString(WICD_DBUS_SERVICE);
+}
+
void WicdStatus::wicdStateChanged()
{
Solid::Networking::Status status = Solid::Networking::Unknown;
diff --git a/solid-networkstatus/kded/wicdstatus.h b/solid-networkstatus/kded/wicdstatus.h
index 0704795..5192599 100644
--- a/solid-networkstatus/kded/wicdstatus.h
+++ b/solid-networkstatus/kded/wicdstatus.h
@@ -34,6 +34,7 @@ public:
/* reimp */ Solid::Networking::Status status() const;
/* reimp */ bool isSupported() const;
+ /* reimp */ QString serviceName() const;
private slots:
void wicdStateChanged();