Commit 0963c3c5 authored by Martin Kacej's avatar Martin Kacej

new utils class

parent f579d8d9
......@@ -14,6 +14,7 @@ set(plasmanm_internal_SRCS
debug.cpp
handler.cpp
uiutils.cpp
mobileutils.cpp
)
add_library(plasmanm_internal SHARED ${plasmanm_internal_SRCS})
......
......@@ -34,6 +34,7 @@
#include "kcmidentitymodel.h"
#include "networkmodel.h"
#include "mobileproxymodel.h"
#include "mobileutils.h"
#include "handler.h"
#include "enums.h"
......@@ -66,4 +67,5 @@ void QmlPlugins::registerTypes(const char* uri)
qmlRegisterType<CreatableConnectionsModel>(uri, 0, 2, "CreatableConnectionsModel");
// @uri org.kde.plasma.networkmanagement.MobileProxyModel
qmlRegisterType<MobileProxyModel>(uri, 0, 2, "MobileProxyModel");
qmlRegisterType<MobileUtils>(uri, 0, 2, "MobileUtils");
}
......@@ -511,40 +511,6 @@ void Handler::replyFinished(QDBusPendingCallWatcher * watcher)
watcher->deleteLater();
}
QVariantMap Handler::getConnectionSettings(const QString &connection, const QString &type)
{
if (type.isEmpty())
return QVariantMap();
NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection);
if (!con)
return QVariantMap();
QVariantMap map = con->settings()->toMap().value(type);
//qCWarning(PLASMA_NM) << "Map:" <<con->settings()->toMap().value(type);
return map;
}
QVariantMap Handler::getActiveConnectionInfo(const QString &connection)
{
if (connection.isEmpty())
return QVariantMap();
NetworkManager::ActiveConnection::Ptr activeCon;
NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection);
Q_FOREACH (const NetworkManager::ActiveConnection::Ptr &active, NetworkManager::activeConnections()) {
if (active->uuid() == con->uuid())
activeCon = active;
}
if(!activeCon){
qWarning(PLASMA_NM) << "Active" << connection << "not found";
return QVariantMap();
}
QVariantMap map;
map.insert("address",QVariant(activeCon->ipV4Config().addresses().first().ip().toString()));
map.insert("prefix",QVariant(activeCon->ipV4Config().addresses().first().netmask().toString()));
map.insert("gateway",QVariant(activeCon->ipV4Config().gateway()));
map.insert("dns",QVariant(activeCon->ipV4Config().nameservers().first().toString()));
//qWarning() << map;
return map;
}
void Handler::addConnectionFromQML(const QVariantMap &QMLmap)
{
......
......@@ -87,8 +87,6 @@ public Q_SLOTS:
void enableNetworking(bool enable);
void enableWireless(bool enable);
QVariantMap getConnectionSettings(const QString &connection, const QString &type);
QVariantMap getActiveConnectionInfo(const QString &connection);
void addConnectionFromQML(const QVariantMap &map);
void enableWwan(bool enable);
......
#include "mobileutils.h"
#include <NetworkManagerQt/Manager>
#include <NetworkManagerQt/AccessPoint>
#include <NetworkManagerQt/WiredDevice>
#include <NetworkManagerQt/WirelessDevice>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/Setting>
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/Utils>
#include <NetworkManagerQt/ConnectionSettings>
#include <NetworkManagerQt/GsmSetting>
#include <NetworkManagerQt/WiredSetting>
#include <NetworkManagerQt/WirelessSetting>
#include <NetworkManagerQt/ActiveConnection>
#include <NetworkManagerQt/Ipv4Setting>
#if WITH_MODEMMANAGER_SUPPORT
#include <ModemManagerQt/Manager>
#include <ModemManagerQt/ModemDevice>
#endif
MobileUtils::MobileUtils(QObject *parent) : QObject(parent)
{
}
QVariantMap MobileUtils::getConnectionSettings(const QString &connection, const QString &type)
{
if (type.isEmpty())
return QVariantMap();
NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection);
if (!con)
return QVariantMap();
QVariantMap map = con->settings()->toMap().value(type);
//qCWarning(PLASMA_NM) << "Map:" <<con->settings()->toMap().value(type);
return map;
}
QVariantMap MobileUtils::getActiveConnectionInfo(const QString &connection)
{
if (connection.isEmpty())
return QVariantMap();
NetworkManager::ActiveConnection::Ptr activeCon;
NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection);
Q_FOREACH (const NetworkManager::ActiveConnection::Ptr &active, NetworkManager::activeConnections()) {
if (active->uuid() == con->uuid())
activeCon = active;
}
if(!activeCon){
qWarning() << "Active" << connection << "not found";
return QVariantMap();
}
QVariantMap map;
map.insert("address",QVariant(activeCon->ipV4Config().addresses().first().ip().toString()));
map.insert("prefix",QVariant(activeCon->ipV4Config().addresses().first().netmask().toString()));
map.insert("gateway",QVariant(activeCon->ipV4Config().gateway()));
map.insert("dns",QVariant(activeCon->ipV4Config().nameservers().first().toString()));
//qWarning() << map;
return map;
}
#ifndef MOBILEUTILS_H
#define MOBILEUTILS_H
#include <QDBusInterface>
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/ConnectionSettings>
#if WITH_MODEMMANAGER_SUPPORT
#include <ModemManagerQt/GenericTypes>
#endif
class Q_DECL_EXPORT MobileUtils : public QObject
{
Q_OBJECT
public:
explicit MobileUtils(QObject *parent = nullptr);
signals:
public Q_SLOTS:
QVariantMap getConnectionSettings(const QString &connection, const QString &type);
QVariantMap getActiveConnectionInfo(const QString &connection);
};
#endif // MOBILEUTILS_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment