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