summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kacej <[email protected]>2018-04-14 22:02:28 +0200
committerMartin Kacej <[email protected]>2018-04-14 22:02:28 +0200
commit0963c3c5efa9597baff8c3a35cf380d13f9d3041 (patch)
treea5fe069572103b67b895431f307417e3c3e7f6fe
parentf579d8d9d817e0cb8b5061e2de8b4987e702556c (diff)
new utils class
-rw-r--r--libs/CMakeLists.txt1
-rw-r--r--libs/declarative/qmlplugins.cpp2
-rw-r--r--libs/handler.cpp34
-rw-r--r--libs/handler.h2
-rw-r--r--libs/mobileutils.cpp61
-rw-r--r--libs/mobileutils.h27
6 files changed, 91 insertions, 36 deletions
diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt
index 0468e51..4c1ce48 100644
--- a/libs/CMakeLists.txt
+++ b/libs/CMakeLists.txt
@@ -14,6 +14,7 @@ set(plasmanm_internal_SRCS
debug.cpp
handler.cpp
uiutils.cpp
+ mobileutils.cpp
)
add_library(plasmanm_internal SHARED ${plasmanm_internal_SRCS})
diff --git a/libs/declarative/qmlplugins.cpp b/libs/declarative/qmlplugins.cpp
index 683231e..d6bd4f5 100644
--- a/libs/declarative/qmlplugins.cpp
+++ b/libs/declarative/qmlplugins.cpp
@@ -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");
}
diff --git a/libs/handler.cpp b/libs/handler.cpp
index 580bfbc..5fe2a8d 100644
--- a/libs/handler.cpp
+++ b/libs/handler.cpp
@@ -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)
{
diff --git a/libs/handler.h b/libs/handler.h
index aa7b73c..33e1e21 100644
--- a/libs/handler.h
+++ b/libs/handler.h
@@ -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);
diff --git a/libs/mobileutils.cpp b/libs/mobileutils.cpp
new file mode 100644
index 0000000..027ff8d
--- /dev/null
+++ b/libs/mobileutils.cpp
@@ -0,0 +1,61 @@
+#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;
+}
diff --git a/libs/mobileutils.h b/libs/mobileutils.h
new file mode 100644
index 0000000..d641331
--- /dev/null
+++ b/libs/mobileutils.h
@@ -0,0 +1,27 @@
+#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