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

Solid

networking.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2006-2007 Will Stephenson <wstephenson@kde.org>
00003     Copyright (C) 2006-2007 Kevin Ottens <ervin@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License version 2 as published by the Free Software Foundation.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 
00019 */
00020 
00021 //#include <KDebug>
00022 
00023 #include "networking.h"
00024 #include "networking_p.h"
00025 
00026 #include "soliddefs_p.h"
00027 #include "org_kde_solid_networking_client.h"
00028 
00029 SOLID_GLOBAL_STATIC(Solid::NetworkingPrivate, globalNetworkManager)
00030 
00031 Solid::NetworkingPrivate::NetworkingPrivate() : netStatus( Solid::Networking::Unknown ), connectPolicy( Solid::Networking::Managed ), disconnectPolicy( Solid::Networking::Managed ), iface(
00032         new OrgKdeSolidNetworkingClientInterface( "org.kde.kded",
00033             "/modules/networkstatus",
00034             QDBusConnection::sessionBus(),
00035             this ) )
00036 {
00037     //connect( iface, SIGNAL( statusChanged( uint ) ), globalNetworkManager, SIGNAL( statusChanged( Networking::Status ) ) );
00038     connect( iface, SIGNAL(statusChanged(uint)), this, SLOT(serviceStatusChanged(uint)) );
00039     connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(const QString&, const QString&, const QString & ) ), SLOT(serviceOwnerChanged(const QString&, const QString&, const QString & ) ) );
00040 
00041     initialize();
00042 }
00043 
00044 Solid::NetworkingPrivate::~NetworkingPrivate()
00045 {
00046 }
00047 
00048 void Solid::NetworkingPrivate::initialize()
00049 {
00050     netStatus = ( Solid::Networking::Status )iface->status().value();
00051 }
00052 
00053 uint Solid::NetworkingPrivate::status() const
00054 {
00055     return iface->status();
00056 }
00057 
00058 /*=========================================================================*/
00059 
00060 Solid::Networking::Status Solid::Networking::status()
00061 {
00062     return static_cast<Solid::Networking::Status>( globalNetworkManager->status() );
00063 }
00064 
00065 Solid::Networking::Notifier *Solid::Networking::notifier()
00066 {
00067     return globalNetworkManager;
00068 }
00069 
00070 void Solid::NetworkingPrivate::serviceStatusChanged( uint status )
00071 {
00072 //    kDebug( 921 ) ;
00073     netStatus = ( Solid::Networking::Status )status;
00074     switch ( netStatus ) {
00075       case Solid::Networking::Unknown:
00076         break;
00077       case Solid::Networking::Unconnected:
00078       case Solid::Networking::Disconnecting:
00079       case Solid::Networking::Connecting:
00080         if ( disconnectPolicy == Solid::Networking::Managed ) {
00081           emit globalNetworkManager->shouldDisconnect();
00082         } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) {
00083           setDisconnectPolicy( Solid::Networking::Manual );
00084           emit globalNetworkManager->shouldDisconnect();
00085         }
00086         break;
00087       case Solid::Networking::Connected:
00088         if ( disconnectPolicy == Solid::Networking::Managed ) {
00089           emit globalNetworkManager->shouldConnect();
00090         } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) {
00091           setConnectPolicy( Solid::Networking::Manual );
00092           emit globalNetworkManager->shouldConnect();
00093         }
00094         break;
00095 //      default:
00096 //        kDebug( 921 ) <<  "Unrecognised status code!";
00097     }
00098     emit globalNetworkManager->statusChanged( netStatus );
00099 }
00100 
00101 void Solid::NetworkingPrivate::serviceOwnerChanged( const QString & name, const QString & oldOwner, const QString & newOwner )
00102 {
00103   Q_UNUSED( oldOwner );
00104   if ( name == "org.kde.kded" ) {
00105     if ( newOwner.isEmpty() ) {
00106       // kded quit on us
00107       netStatus = Solid::Networking::Unknown;
00108       emit globalNetworkManager->statusChanged( netStatus );
00109 
00110     } else {
00111       // kded was replaced or started
00112       initialize();
00113       emit globalNetworkManager->statusChanged( netStatus );
00114       serviceStatusChanged( netStatus );
00115     }
00116   }
00117 }
00118 
00119 Solid::Networking::ManagementPolicy Solid::Networking::connectPolicy()
00120 {
00121     return globalNetworkManager->connectPolicy;
00122 }
00123 
00124 void Solid::Networking::setConnectPolicy( Solid::Networking::ManagementPolicy policy )
00125 {
00126     globalNetworkManager->connectPolicy = policy;
00127 }
00128 
00129 Solid::Networking::ManagementPolicy Solid::Networking::disconnectPolicy()
00130 {
00131     return globalNetworkManager->disconnectPolicy;
00132 }
00133 
00134 void Solid::Networking::setDisconnectPolicy( Solid::Networking::ManagementPolicy policy )
00135 {
00136     globalNetworkManager->disconnectPolicy = policy;
00137 }
00138 
00139 #include "networking_p.moc"
00140 #include "networking.moc"

Solid

Skip menu "Solid"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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