Solid
networking.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2006-2007 Will Stephenson <wstephenson@kde.org> 00003 Copyright 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 Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) version 3, or any 00009 later version accepted by the membership of KDE e.V. (or its 00010 successor approved by the membership of KDE e.V.), which shall 00011 act as a proxy defined in Section 6 of version 3 of the license. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 //#include <KDebug> 00023 00024 #include "networking.h" 00025 #include "networking_p.h" 00026 00027 #include "soliddefs_p.h" 00028 #include "org_kde_solid_networking_client.h" 00029 00030 SOLID_GLOBAL_STATIC(Solid::NetworkingPrivate, globalNetworkManager) 00031 00032 Solid::NetworkingPrivate::NetworkingPrivate() 00033 : netStatus(Solid::Networking::Unknown), 00034 connectPolicy(Solid::Networking::Managed), 00035 disconnectPolicy(Solid::Networking::Managed), 00036 iface(0) 00037 { 00038 QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.kded", QDBusConnection::sessionBus(), 00039 QDBusServiceWatcher::WatchForOwnerChange, this); 00040 connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)), 00041 this, SLOT(serviceOwnerChanged(QString,QString,QString))); 00042 00043 initialize(); 00044 } 00045 00046 Solid::NetworkingPrivate::~NetworkingPrivate() 00047 { 00048 } 00049 00050 Solid::Networking::Notifier::Notifier() 00051 { 00052 } 00053 00054 void Solid::NetworkingPrivate::initialize() 00055 { 00056 delete iface; 00057 iface = new OrgKdeSolidNetworkingClientInterface( "org.kde.kded", 00058 "/modules/networkstatus", 00059 QDBusConnection::sessionBus(), 00060 this); 00061 00062 //connect( iface, SIGNAL(statusChanged(uint)), globalNetworkManager, SIGNAL(statusChanged(Networking::Status)) ); 00063 connect(iface, SIGNAL(statusChanged(uint)), this, SLOT(serviceStatusChanged(uint))); 00064 00065 QDBusReply<uint> reply = iface->status(); 00066 if (reply.isValid()) { 00067 netStatus = ( Solid::Networking::Status )reply.value(); 00068 } else { 00069 netStatus = Solid::Networking::Unknown; 00070 } 00071 } 00072 00073 uint Solid::NetworkingPrivate::status() const 00074 { 00075 return netStatus; 00076 } 00077 00078 /*=========================================================================*/ 00079 00080 Solid::Networking::Status Solid::Networking::status() 00081 { 00082 return static_cast<Solid::Networking::Status>( globalNetworkManager->status() ); 00083 } 00084 00085 Solid::Networking::Notifier *Solid::Networking::notifier() 00086 { 00087 return globalNetworkManager; 00088 } 00089 00090 void Solid::NetworkingPrivate::serviceStatusChanged( uint status ) 00091 { 00092 // kDebug( 921 ) ; 00093 netStatus = ( Solid::Networking::Status )status; 00094 switch ( netStatus ) { 00095 case Solid::Networking::Unknown: 00096 break; 00097 case Solid::Networking::Unconnected: 00098 case Solid::Networking::Disconnecting: 00099 case Solid::Networking::Connecting: 00100 if ( disconnectPolicy == Solid::Networking::Managed ) { 00101 emit globalNetworkManager->shouldDisconnect(); 00102 } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) { 00103 setDisconnectPolicy( Solid::Networking::Manual ); 00104 emit globalNetworkManager->shouldDisconnect(); 00105 } 00106 break; 00107 case Solid::Networking::Connected: 00108 if ( disconnectPolicy == Solid::Networking::Managed ) { 00109 emit globalNetworkManager->shouldConnect(); 00110 } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) { 00111 setConnectPolicy( Solid::Networking::Manual ); 00112 emit globalNetworkManager->shouldConnect(); 00113 } 00114 break; 00115 // default: 00116 // kDebug( 921 ) << "Unrecognised status code!"; 00117 } 00118 emit globalNetworkManager->statusChanged( netStatus ); 00119 } 00120 00121 void Solid::NetworkingPrivate::serviceOwnerChanged( const QString & name, const QString & oldOwner, const QString & newOwner ) 00122 { 00123 Q_UNUSED(name) 00124 Q_UNUSED(oldOwner) 00125 if ( newOwner.isEmpty() ) { 00126 // kded quit on us 00127 netStatus = Solid::Networking::Unknown; 00128 emit globalNetworkManager->statusChanged( netStatus ); 00129 00130 } else { 00131 // kded was replaced or started 00132 initialize(); 00133 emit globalNetworkManager->statusChanged( netStatus ); 00134 serviceStatusChanged( netStatus ); 00135 } 00136 } 00137 00138 Solid::Networking::ManagementPolicy Solid::Networking::connectPolicy() 00139 { 00140 return globalNetworkManager->connectPolicy; 00141 } 00142 00143 void Solid::Networking::setConnectPolicy( Solid::Networking::ManagementPolicy policy ) 00144 { 00145 globalNetworkManager->connectPolicy = policy; 00146 } 00147 00148 Solid::Networking::ManagementPolicy Solid::Networking::disconnectPolicy() 00149 { 00150 return globalNetworkManager->disconnectPolicy; 00151 } 00152 00153 void Solid::Networking::setDisconnectPolicy( Solid::Networking::ManagementPolicy policy ) 00154 { 00155 globalNetworkManager->disconnectPolicy = policy; 00156 } 00157 00158 #include "networking_p.moc" 00159 #include "networking.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:52:04 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:52:04 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.