• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

SolidModules

networkstatus.cpp

Go to the documentation of this file.
00001 /*  This file is part of kdebase/workspace/solid
00002     Copyright (C) 2005,2007 Will Stephenson <wstephenson@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library.  If not, write to the Free Software
00015     Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018     As a special exception, permission is given to link this library
00019     with any edition of Qt, and distribute the resulting executable,
00020     without including the source code for Qt in the source distribution.
00021 */
00022 
00023 #include "networkstatus.h"
00024 
00025 #include <QMap>
00026 
00027 #include <KDebug>
00028 #include <solid/control/networkmanager.h>
00029 
00030 #include "network.h"
00031 #include "clientadaptor.h"
00032 #include "serviceadaptor.h"
00033 
00034 #include <kpluginfactory.h>
00035 
00036 K_PLUGIN_FACTORY(NetworkStatusFactory,
00037                  registerPlugin<NetworkStatusModule>();
00038     )
00039 K_EXPORT_PLUGIN(NetworkStatusFactory("networkstatus"))
00040 
00041 // INTERNALLY USED STRUCTS AND TYPEDEFS
00042 
00043 typedef QMap< QString, Network * > NetworkMap;
00044 
00045 class NetworkStatusModule::Private
00046 {
00047 public:
00048     Private() : status( Solid::Networking::Unknown )
00049     {
00050 
00051     }
00052     ~Private()
00053     {
00054 
00055     }
00056     NetworkMap networks;
00057     Solid::Networking::Status status;
00058     Solid::Control::NetworkManager::Notifier * notifier;
00059 };
00060 
00061 // CTORS/DTORS
00062 
00063 NetworkStatusModule::NetworkStatusModule(QObject* parent, const QList<QVariant>&)
00064     : KDEDModule(parent), d( new Private )
00065 {
00066     new ClientAdaptor( this );
00067     new ServiceAdaptor( this );
00068 
00069     QDBusConnection dbus = QDBusConnection::sessionBus();
00070     QDBusConnectionInterface * sessionBus = dbus.interface();
00071 
00072     connect( sessionBus, SIGNAL(serviceOwnerChanged(const QString&,const QString&,const QString&)), this, SLOT(serviceOwnerChanged(const QString&,const QString&,const QString&)) );
00073     init();
00074 }
00075 
00076 NetworkStatusModule::~NetworkStatusModule()
00077 {
00078     Q_FOREACH ( Network * net, d->networks ) {
00079         delete net;
00080     }
00081 
00082     delete d;
00083 }
00084 
00085 // CLIENT INTERFACE
00086 
00087 int NetworkStatusModule::status()
00088 {
00089     kDebug( 1222 ) << " status: " << (int)d->status;
00090     return (int)d->status;
00091 }
00092 
00093 //protected:
00094 
00095 void NetworkStatusModule::updateStatus()
00096 {
00097     Solid::Networking::Status bestStatus = Solid::Networking::Unknown;
00098     const Solid::Networking::Status oldStatus = d->status;
00099 
00100     Q_FOREACH ( Network * net, d->networks ) {
00101         if ( net->status() > bestStatus )
00102             bestStatus = net->status();
00103     }
00104     d->status = bestStatus;
00105 
00106     if ( oldStatus != d->status ) {
00107         emit statusChanged( (uint)d->status );
00108     }
00109 }
00110 
00111 void NetworkStatusModule::serviceOwnerChanged( const QString & name ,const QString & oldOwner, const QString & newOwner )
00112 {
00113   if ( !oldOwner.isEmpty() && newOwner.isEmpty( ) ) {
00114     // unregister and delete any networks owned by a service that has just unregistered
00115     QMutableMapIterator<QString,Network*> it( d->networks );
00116     while ( it.hasNext() ) {
00117       it.next();
00118       if ( it.value()->service() == name )
00119       {
00120         kDebug( 1222 ) << "Departing service " << name << " owned network " << it.value()->name() << ", removing it";
00121         Network * removedNet = it.value();
00122         it.remove();
00123         updateStatus();
00124         delete removedNet;
00125       }
00126     }
00127   }
00128 }
00129 
00130 // SERVICE INTERFACE //
00131 
00132 QStringList NetworkStatusModule::networks()
00133 {
00134     if ( d->networks.count() ) {
00135       kDebug() << "Network status module is aware of " << d->networks.count() << " networks";
00136     } else {
00137       kDebug( 1222 ) << "Network status module is not aware of any networks";
00138     }
00139     return d->networks.keys();
00140 }
00141 
00142 void NetworkStatusModule::setNetworkStatus( const QString & networkName, int st )
00143 {
00144     kDebug( 1222 ) << networkName << ", " << st;
00145     Solid::Networking::Status changedStatus = (Solid::Networking::Status)st;
00146     if ( d->networks.contains( networkName ) ) {
00147       Network * net = d->networks[ networkName ];
00148         net->setStatus( changedStatus );
00149         updateStatus();
00150     } else {
00151       kDebug( 1222 ) << "  No network named '" << networkName << "' known.";
00152     }
00153 }
00154 
00155 void NetworkStatusModule::registerNetwork( const QString & networkName, int status, const QString & serviceName )
00156 {
00157     QDBusConnection dbus = QDBusConnection::sessionBus();
00158     QDBusConnectionInterface * sessionBus = dbus.interface();
00159     QString uniqueOwner = sessionBus->serviceOwner( serviceName ).value();
00160 
00161     kDebug( 1222 ) << networkName << ", with status " << status << " is owned by " << uniqueOwner;
00162 
00163     d->networks.insert( networkName, new Network( networkName, status, uniqueOwner ) );
00164     updateStatus();
00165 }
00166 
00167 void NetworkStatusModule::unregisterNetwork( const QString & networkName )
00168 {
00169     if ( networkName != QLatin1String("SolidNetwork") ) {
00170         kDebug( 1222 ) << networkName << " unregistered.";
00171 
00172         d->networks.remove( networkName );
00173         updateStatus();
00174     }
00175 }
00176 
00177 void NetworkStatusModule::init()
00178 {
00179     d->notifier = Solid::Control::NetworkManager::notifier();
00180     connect( d->notifier, SIGNAL(statusChanged(Solid::Networking::Status)),
00181             this, SLOT(solidNetworkingStatusChanged(Solid::Networking::Status)));
00182     Solid::Networking::Status status = Solid::Control::NetworkManager::status();
00183     registerNetwork( QLatin1String("SolidNetwork"), status, QLatin1String("org.kde.kded") );
00184 }
00185 
00186 void NetworkStatusModule::solidNetworkingStatusChanged( Solid::Networking::Status status )
00187 {
00188     kDebug( 1222 ) << "SolidNetwork changed status: " << status;
00189     setNetworkStatus( QLatin1String("SolidNetwork"), status );
00190 }
00191 
00192 #include "networkstatus.moc"
00193 // vim: set noet sw=4 ts=4:

SolidModules

Skip menu "SolidModules"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal