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 if (reply.isValid()) { 00063 netStatus = ( Solid::Networking::Status )reply.value(); 00064 } else { 00065 netStatus = Solid::Networking::Unknown; 00066 } 00067 } 00068 00069 uint Solid::NetworkingPrivate::status() const 00070 { 00071 return netStatus; 00072 } 00073 00074 /*=========================================================================*/ 00075 00076 Solid::Networking::Status Solid::Networking::status() 00077 { 00078 return static_cast<Solid::Networking::Status>( globalNetworkManager->status() ); 00079 } 00080 00081 Solid::Networking::Notifier *Solid::Networking::notifier() 00082 { 00083 return globalNetworkManager; 00084 } 00085 00086 void Solid::NetworkingPrivate::serviceStatusChanged( uint status ) 00087 { 00088 // kDebug( 921 ) ; 00089 netStatus = ( Solid::Networking::Status )status; 00090 switch ( netStatus ) { 00091 case Solid::Networking::Unknown: 00092 break; 00093 case Solid::Networking::Unconnected: 00094 case Solid::Networking::Disconnecting: 00095 case Solid::Networking::Connecting: 00096 if ( disconnectPolicy == Solid::Networking::Managed ) { 00097 emit globalNetworkManager->shouldDisconnect(); 00098 } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) { 00099 setDisconnectPolicy( Solid::Networking::Manual ); 00100 emit globalNetworkManager->shouldDisconnect(); 00101 } 00102 break; 00103 case Solid::Networking::Connected: 00104 if ( disconnectPolicy == Solid::Networking::Managed ) { 00105 emit globalNetworkManager->shouldConnect(); 00106 } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) { 00107 setConnectPolicy( Solid::Networking::Manual ); 00108 emit globalNetworkManager->shouldConnect(); 00109 } 00110 break; 00111 // default: 00112 // kDebug( 921 ) << "Unrecognised status code!"; 00113 } 00114 emit globalNetworkManager->statusChanged( netStatus ); 00115 } 00116 00117 void Solid::NetworkingPrivate::serviceOwnerChanged( const QString & name, const QString & oldOwner, const QString & newOwner ) 00118 { 00119 Q_UNUSED(name) 00120 Q_UNUSED(oldOwner) 00121 if ( newOwner.isEmpty() ) { 00122 // kded quit on us 00123 netStatus = Solid::Networking::Unknown; 00124 emit globalNetworkManager->statusChanged( netStatus ); 00125 00126 } else { 00127 // kded was replaced or started 00128 initialize(); 00129 emit globalNetworkManager->statusChanged( netStatus ); 00130 serviceStatusChanged( netStatus ); 00131 } 00132 } 00133 00134 Solid::Networking::ManagementPolicy Solid::Networking::connectPolicy() 00135 { 00136 return globalNetworkManager->connectPolicy; 00137 } 00138 00139 void Solid::Networking::setConnectPolicy( Solid::Networking::ManagementPolicy policy ) 00140 { 00141 globalNetworkManager->connectPolicy = policy; 00142 } 00143 00144 Solid::Networking::ManagementPolicy Solid::Networking::disconnectPolicy() 00145 { 00146 return globalNetworkManager->disconnectPolicy; 00147 } 00148 00149 void Solid::Networking::setDisconnectPolicy( Solid::Networking::ManagementPolicy policy ) 00150 { 00151 globalNetworkManager->disconnectPolicy = policy; 00152 } 00153 00154 #include "networking_p.moc" 00155 #include "networking.moc"
KDE 4.6 API Reference