File indexing completed on 2024-04-21 14:56:10
0001 /* This file is part of the KDE project 0002 0003 Copyright (c) 2011 Lamarque V. Souza <lamarque@gmail.com> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Lesser General Public 0007 License as published by the Free Software Foundation; either 0008 version 2.1 of the License, or (at your option) version 3, or any 0009 later version accepted by the membership of KDE e.V. (or its 0010 successor approved by the membership of KDE e.V.), which shall 0011 act as a proxy defined in Section 6 of version 3 of the license. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Lesser General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public 0019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0020 */ 0021 0022 #include "wicdstatus.h" 0023 #include "wicdcustomtypes.h" 0024 0025 #include <QDBusReply> 0026 #include <QDBusMetaType> 0027 0028 #include <kdebug.h> 0029 0030 #define WICD_DBUS_SERVICE "org.wicd.daemon" 0031 #define WICD_DAEMON_DBUS_PATH "/org/wicd/daemon" 0032 #define WICD_DAEMON_DBUS_INTERFACE "org.wicd.daemon" 0033 0034 WicdStatus::WicdStatus( QObject *parent ) 0035 : SystemStatusInterface( parent ), 0036 m_wicd( WICD_DBUS_SERVICE, 0037 WICD_DAEMON_DBUS_PATH, 0038 WICD_DAEMON_DBUS_INTERFACE, 0039 QDBusConnection::systemBus() ), 0040 cachedState(Solid::Networking::Unknown) 0041 { 0042 qDBusRegisterMetaType<WicdConnectionInfo>(); 0043 QDBusConnection::systemBus().connect(WICD_DBUS_SERVICE, WICD_DAEMON_DBUS_PATH, WICD_DAEMON_DBUS_INTERFACE, 0044 "StatusChanged", this, SLOT(wicdStateChanged())); 0045 wicdStateChanged(); 0046 } 0047 0048 Solid::Networking::Status WicdStatus::status() const 0049 { 0050 return cachedState; 0051 } 0052 0053 bool WicdStatus::isSupported() const 0054 { 0055 return m_wicd.isValid(); 0056 } 0057 0058 QString WicdStatus::serviceName() const 0059 { 0060 return QString(WICD_DBUS_SERVICE); 0061 } 0062 0063 void WicdStatus::wicdStateChanged() 0064 { 0065 Solid::Networking::Status status = Solid::Networking::Unknown; 0066 QDBusMessage message = m_wicd.call("GetConnectionStatus"); 0067 0068 if (message.type() == QDBusMessage::ErrorMessage) { 0069 emit statusChanged( status ); 0070 return; 0071 } 0072 0073 if (message.arguments().count() == 0) { 0074 emit statusChanged( status ); 0075 return; 0076 } 0077 0078 if (!message.arguments().at(0).isValid()) { 0079 emit statusChanged( status ); 0080 return; 0081 } 0082 0083 WicdConnectionInfo s; 0084 message.arguments().at(0).value<QDBusArgument>() >> s; 0085 kDebug() << "State: " << s.status << " Info: " << s.info; 0086 0087 switch (static_cast<Wicd::ConnectionStatus>(s.status)) { 0088 case Wicd::CONNECTING: 0089 status = Solid::Networking::Connecting; 0090 break; 0091 case Wicd::WIRED: 0092 case Wicd::WIRELESS: 0093 status = Solid::Networking::Connected; 0094 break; 0095 case Wicd::NOT_CONNECTED: 0096 status = Solid::Networking::Unconnected; 0097 break; 0098 default: 0099 case Wicd::SUSPENDED: 0100 status = Solid::Networking::Unknown; 0101 break; 0102 } 0103 0104 emit statusChanged( status ); 0105 } 0106 0107 #include "moc_wicdstatus.cpp"