/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2016 Simon Stürz * * * * This file is part of guh. * * * * Guh is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, version 2 of the License. * * * * Guh is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with guh. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "networkconnection.h" #include "dbus-interfaces.h" #include "loggingcategories.h" #include namespace guhserver { NetworkConnection::NetworkConnection(const QDBusObjectPath &objectPath, QObject *parent) : QObject(parent), m_objectPath(objectPath) { qDBusRegisterMetaType(); m_connectionInterface = new QDBusInterface(serviceString, m_objectPath.path(), connectionsInterfaceString, QDBusConnection::systemBus(), this); if(!m_connectionInterface->isValid()) { qCWarning(dcNetworkManager()) << "Invalid connection dbus interface"; return; } QDBusMessage query = m_connectionInterface->call("GetSettings"); if(query.type() != QDBusMessage::ReplyMessage) { qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage(); return; } if (query.arguments().isEmpty()) return; const QDBusArgument &argument = query.arguments().at(0).value(); m_connectionSettings = qdbus_cast(argument); } void NetworkConnection::deleteConnection() { QDBusMessage query = m_connectionInterface->call("Delete"); if(query.type() != QDBusMessage::ReplyMessage) qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage(); } QDBusObjectPath NetworkConnection::objectPath() const { return m_objectPath; } QString NetworkConnection::id() const { return m_connectionSettings.value("connection").value("id").toString(); } QString NetworkConnection::name() const { return m_connectionSettings.value("connection").value("name").toString(); } QString NetworkConnection::type() const { return m_connectionSettings.value("connection").value("type").toString(); } QUuid NetworkConnection::uuid() const { return m_connectionSettings.value("connection").value("uuid").toUuid(); } QString NetworkConnection::interfaceName() const { return m_connectionSettings.value("connection").value("interface-name").toString(); } bool NetworkConnection::autoconnect() const { return m_connectionSettings.value("connection").value("autoconnect").toBool(); } QDateTime NetworkConnection::timeStamp() const { return QDateTime::fromTime_t(m_connectionSettings.value("connection").value("timestamp").toUInt()); } QDebug operator<<(QDebug debug, NetworkConnection *networkConnection) { debug.nospace() << "NetworkConnection(" << networkConnection->id() << ", "; debug.nospace() << networkConnection->uuid().toString() << ", "; debug.nospace() << networkConnection->interfaceName() << ", "; debug.nospace() << networkConnection->type() << ", "; debug.nospace() << networkConnection->timeStamp().toString("dd.MM.yyyy hh:mm") << ") "; return debug; } }