File indexing completed on 2024-04-21 14:56:10
0001 /* This file is part of the KDE project 0002 0003 Copyright (c) 2010 Klarälvdalens Datakonsult AB, 0004 a KDAB Group company <info@kdab.com> 0005 Author: Kevin Ottens <kevin.ottens@kdab.com> 0006 0007 Copyright (c) 2011 Lukas Tinkl <ltinkl@redhat.com> 0008 Copyright (c) 2011-2012 Lamarque V. Souza <lamarque@kde.org> 0009 0010 This library is free software; you can redistribute it and/or 0011 modify it under the terms of the GNU Lesser General Public 0012 License as published by the Free Software Foundation; either 0013 version 2.1 of the License, or (at your option) version 3, or any 0014 later version accepted by the membership of KDE e.V. (or its 0015 successor approved by the membership of KDE e.V.), which shall 0016 act as a proxy defined in Section 6 of version 3 of the license. 0017 0018 This library is distributed in the hope that it will be useful, 0019 but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0021 Lesser General Public License for more details. 0022 0023 You should have received a copy of the GNU Lesser General Public 0024 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #include "networkmanagerstatus.h" 0028 0029 #include <QDBusReply> 0030 0031 #include <NetworkManager.h> 0032 0033 #if !defined(NM_CHECK_VERSION) 0034 #define NM_CHECK_VERSION(x,y,z) 0 0035 #endif 0036 0037 NetworkManagerStatus::NetworkManagerStatus( QObject *parent ) 0038 : SystemStatusInterface( parent ), 0039 m_manager( NM_DBUS_SERVICE, 0040 NM_DBUS_PATH, 0041 NM_DBUS_INTERFACE, 0042 QDBusConnection::systemBus() ) 0043 { 0044 connect( &m_manager, SIGNAL(StateChanged(uint)), 0045 this, SLOT(nmStateChanged(uint))); 0046 0047 QDBusReply<uint> reply = m_manager.call( "state" ); 0048 0049 if ( reply.isValid() ) { 0050 m_status = convertNmState( reply ); 0051 } else { 0052 m_status = Solid::Networking::Unknown; 0053 } 0054 } 0055 0056 Solid::Networking::Status NetworkManagerStatus::status() const 0057 { 0058 return m_status; 0059 } 0060 0061 bool NetworkManagerStatus::isSupported() const 0062 { 0063 return m_manager.isValid(); 0064 } 0065 0066 QString NetworkManagerStatus::serviceName() const 0067 { 0068 return QString(NM_DBUS_SERVICE); 0069 } 0070 0071 void NetworkManagerStatus::nmStateChanged( uint nmState ) 0072 { 0073 m_status = convertNmState( nmState ); 0074 emit statusChanged( m_status ); 0075 } 0076 0077 Solid::Networking::Status NetworkManagerStatus::convertNmState( uint nmState ) 0078 { 0079 Solid::Networking::Status status = Solid::Networking::Unknown; 0080 0081 switch (nmState) { 0082 case NM_STATE_UNKNOWN: 0083 case NM_STATE_ASLEEP: 0084 break; 0085 case NM_STATE_CONNECTING: 0086 status = Solid::Networking::Connecting; 0087 break; 0088 #if NM_CHECK_VERSION(0,8,992) 0089 case NM_STATE_CONNECTED_LOCAL: 0090 case NM_STATE_CONNECTED_SITE: 0091 case NM_STATE_CONNECTED_GLOBAL: 0092 #else 0093 case NM_STATE_CONNECTED: 0094 #endif 0095 status = Solid::Networking::Connected; 0096 break; 0097 case NM_STATE_DISCONNECTED: 0098 status = Solid::Networking::Unconnected; 0099 break; 0100 #if NM_CHECK_VERSION(0,8,992) 0101 case NM_STATE_DISCONNECTING: 0102 status = Solid::Networking::Disconnecting; 0103 break; 0104 #endif 0105 } 0106 0107 return status; 0108 } 0109 0110 #include "moc_networkmanagerstatus.cpp"