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(new OrgKdeSolidNetworkingClientInterface( "org.kde.kded", 00037 "/modules/networkstatus", 00038 QDBusConnection::sessionBus(), 00039 this)) 00040 { 00041 //connect( iface, SIGNAL( statusChanged( uint ) ), globalNetworkManager, SIGNAL( statusChanged( Networking::Status ) ) ); 00042 connect(iface, SIGNAL(statusChanged(uint)), this, SLOT(serviceStatusChanged(uint))); 00043 QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.kded", QDBusConnection::sessionBus(), 00044 QDBusServiceWatcher::WatchForOwnerChange, this); 00045 connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)), 00046 this, SLOT(serviceOwnerChanged(QString,QString,QString))); 00047 00048 initialize(); 00049 } 00050 00051 Solid::NetworkingPrivate::~NetworkingPrivate() 00052 { 00053 } 00054 00055 Solid::Networking::Notifier::Notifier() 00056 { 00057 } 00058 00059 void Solid::NetworkingPrivate::initialize() 00060 { 00061 QDBusPendingReply<uint> reply = iface->status(); 00062 reply.waitForFinished(); 00063 if (reply.isValid()) { 00064 netStatus = ( Solid::Networking::Status )reply.value(); 00065 } else { 00066 netStatus = Solid::Networking::Unknown; 00067 } 00068 } 00069 00070 uint Solid::NetworkingPrivate::status() const 00071 { 00072 return netStatus; 00073 } 00074 00075 /*=========================================================================*/ 00076 00077 Solid::Networking::Status Solid::Networking::status() 00078 { 00079 return static_cast<Solid::Networking::Status>( globalNetworkManager->status() ); 00080 } 00081 00082 Solid::Networking::Notifier *Solid::Networking::notifier() 00083 { 00084 return globalNetworkManager; 00085 } 00086 00087 void Solid::NetworkingPrivate::serviceStatusChanged( uint status ) 00088 { 00089 // kDebug( 921 ) ; 00090 netStatus = ( Solid::Networking::Status )status; 00091 switch ( netStatus ) { 00092 case Solid::Networking::Unknown: 00093 break; 00094 case Solid::Networking::Unconnected: 00095 case Solid::Networking::Disconnecting: 00096 case Solid::Networking::Connecting: 00097 if ( disconnectPolicy == Solid::Networking::Managed ) { 00098 emit globalNetworkManager->shouldDisconnect(); 00099 } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) { 00100 setDisconnectPolicy( Solid::Networking::Manual ); 00101 emit globalNetworkManager->shouldDisconnect(); 00102 } 00103 break; 00104 case Solid::Networking::Connected: 00105 if ( disconnectPolicy == Solid::Networking::Managed ) { 00106 emit globalNetworkManager->shouldConnect(); 00107 } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) { 00108 setConnectPolicy( Solid::Networking::Manual ); 00109 emit globalNetworkManager->shouldConnect(); 00110 } 00111 break; 00112 // default: 00113 // kDebug( 921 ) << "Unrecognised status code!"; 00114 } 00115 emit globalNetworkManager->statusChanged( netStatus ); 00116 } 00117 00118 void Solid::NetworkingPrivate::serviceOwnerChanged( const QString & name, const QString & oldOwner, const QString & newOwner ) 00119 { 00120 Q_UNUSED(name) 00121 Q_UNUSED(oldOwner) 00122 if ( newOwner.isEmpty() ) { 00123 // kded quit on us 00124 netStatus = Solid::Networking::Unknown; 00125 emit globalNetworkManager->statusChanged( netStatus ); 00126 00127 } else { 00128 // kded was replaced or started 00129 initialize(); 00130 emit globalNetworkManager->statusChanged( netStatus ); 00131 serviceStatusChanged( netStatus ); 00132 } 00133 } 00134 00135 Solid::Networking::ManagementPolicy Solid::Networking::connectPolicy() 00136 { 00137 return globalNetworkManager->connectPolicy; 00138 } 00139 00140 void Solid::Networking::setConnectPolicy( Solid::Networking::ManagementPolicy policy ) 00141 { 00142 globalNetworkManager->connectPolicy = policy; 00143 } 00144 00145 Solid::Networking::ManagementPolicy Solid::Networking::disconnectPolicy() 00146 { 00147 return globalNetworkManager->disconnectPolicy; 00148 } 00149 00150 void Solid::Networking::setDisconnectPolicy( Solid::Networking::ManagementPolicy policy ) 00151 { 00152 globalNetworkManager->disconnectPolicy = policy; 00153 } 00154 00155 #include "networking_p.moc" 00156 #include "networking.moc"
KDE 4.7 API Reference