aboutsummaryrefslogtreecommitdiff
path: root/src-qt5
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-12-15 13:56:26 -0500
committerKen Moore <ken@ixsystems.com>2017-12-15 13:56:26 -0500
commit496a3cb583a2f5fb2da7c1808077c1fc5a9bfc28 (patch)
tree4a57b239aea12a98265a35580552f3fa45e48cfd /src-qt5
parentMerge branch 'master' of github.com:trueos/lumina (diff)
downloadlumina-496a3cb583a2f5fb2da7c1808077c1fc5a9bfc28.tar.gz
lumina-496a3cb583a2f5fb2da7c1808077c1fc5a9bfc28.tar.bz2
lumina-496a3cb583a2f5fb2da7c1808077c1fc5a9bfc28.zip
A bit more work on the networking side of the OSInterface.
Also add a test project for running tests against particular frameworks.
Diffstat (limited to 'src-qt5')
-rw-r--r--src-qt5/src-cpp/framework-OSInterface-template.cpp35
-rw-r--r--src-qt5/src-cpp/framework-OSInterface.h4
-rw-r--r--src-qt5/src-cpp/framework-OSInterface.pri9
-rw-r--r--src-qt5/src-cpp/framework-OSInterface_private.cpp13
-rw-r--r--src-qt5/src-cpp/tests/main.cpp38
-rw-r--r--src-qt5/src-cpp/tests/test.pro7
6 files changed, 85 insertions, 21 deletions
diff --git a/src-qt5/src-cpp/framework-OSInterface-template.cpp b/src-qt5/src-cpp/framework-OSInterface-template.cpp
index 625acae4..972e02e0 100644
--- a/src-qt5/src-cpp/framework-OSInterface-template.cpp
+++ b/src-qt5/src-cpp/framework-OSInterface-template.cpp
@@ -4,7 +4,9 @@
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
-#include <OSInterface.h>
+#include <framework-OSInterface.h>
+#include <QNetworkConfiguration>
+#include <QNetworkInterface>
//Start/stop interface watchers/notifications
void OSInterface::start(){
@@ -34,7 +36,7 @@ void OSInterface::setVolume(int){}
// = Network Information =
bool OSInterface::networkAvailable(){
- if(INFO.contains()){ return INFO.value("netaccess/available").toBool(); }
+ if(INFO.contains("netaccess/available")){ return INFO.value("netaccess/available").toBool(); }
return false;
}
@@ -113,27 +115,36 @@ void OSInterface::iodeviceAboutToClose(){}
//NetworkAccessManager slots
void OSInterface::netAccessChanged(QNetworkAccessManager::NetworkAccessibility stat){
- INFO.setValue("netaccess/available", stat== QNetworkAccessManager::Accessible);
+ INFO.insert("netaccess/available", stat== QNetworkAccessManager::Accessible);
//Update all the other network status info at the same time
QNetworkConfiguration active = netman->activeConfiguration();
//Type of connection
QString type;
- switch(active->bearerTypeFamily()){
+ switch(active.bearerTypeFamily()){
case QNetworkConfiguration::BearerEthernet: type="wired"; break;
- case QNetworkConfiguration::BearnerWLAN: type="wifi"; break;
+ case QNetworkConfiguration::BearerWLAN: type="wifi"; break;
case QNetworkConfiguration::Bearer2G: type="cell-2G"; break;
case QNetworkConfiguration::Bearer3G: type="cell-3G"; break;
case QNetworkConfiguration::Bearer4G: type="cell-4G"; break;
+ default: type="";
}
- INFO.setValue("netaccess/type", type);
- qDebug() << "Detected Device Status:" << active->identifier() << type << stat;
- QNetworkInterface iface = QNetworkInterface::interfaceFromName(active->identifier());
- QString address = iface.hardwareAddress();
- qDebug() << " - Address:" << address;
- INFO.setValue("netaccess/address", address);
-
+ INFO.insert("netaccess/type", type);
+ qDebug() << "Detected Device Status:" << active.identifier() << type << stat;
+ QNetworkInterface iface = QNetworkInterface::interfaceFromName(active.name());
+ qDebug() << " - Configuration: Name:" << active.name() << active.bearerTypeName() << active.identifier();
+ qDebug() << " - Interface: MAC Address:" << iface.hardwareAddress() << "Name:" << iface.name() << iface.humanReadableName() << iface.isValid();
+ QList<QNetworkAddressEntry> addressList = iface.addressEntries();
+ QStringList address;
+ //NOTE: There are often 2 addresses, IPv4 and IPv6
+ for(int i=0; i<addressList.length(); i++){
+ address << addressList[i].ip().toString();
+ }
+ qDebug() << " - IP Address:" << address;
+ qDebug() << " - Hostname:" << networkHostname();
+ INFO.insert("netaccess/address", address.join(", "));
emit networkStatusChanged();
}
void OSInterface::netRequestFinished(QNetworkReply*){}
void OSInterface::netSslErrors(QNetworkReply*, const QList<QSslError>&){}
+void OSInterface::timerUpdate(){}
diff --git a/src-qt5/src-cpp/framework-OSInterface.h b/src-qt5/src-cpp/framework-OSInterface.h
index c48fc9f8..a173ad5a 100644
--- a/src-qt5/src-cpp/framework-OSInterface.h
+++ b/src-qt5/src-cpp/framework-OSInterface.h
@@ -17,6 +17,7 @@
#include <QObject>
#include <QVariant>
#include <QHash>
+#include <QTimer>
#include <QIODevice>
#include <QFileSystemWatcher>
@@ -138,7 +139,6 @@ private slots:
void timerUpdate();
signals:
- void interfaceChanged(OSInterface::Interface);
void batteryChargeChanged();
void batteryChargingChanged();
void batterySecondsLeftChanged();
@@ -151,7 +151,7 @@ signals:
private:
//Internal persistant data storage, OS-specific usage implementation
- QHash< QString, QList<QVariant> > INFO;
+ QHash< QString, QVariant> INFO;
// ============
// Internal possibilities for watching the system (OS-Specific usage/implementation)
diff --git a/src-qt5/src-cpp/framework-OSInterface.pri b/src-qt5/src-cpp/framework-OSInterface.pri
index 92fb8889..be705e44 100644
--- a/src-qt5/src-cpp/framework-OSInterface.pri
+++ b/src-qt5/src-cpp/framework-OSInterface.pri
@@ -1,4 +1,9 @@
QT *= core network
-HEADERS *= framework-OSInterface.h
-SOURCES *= framework-OSInterface_private.cpp
+HEADERS *= $${PWD}/framework-OSInterface.h
+SOURCES *= $${PWD}/framework-OSInterface_private.cpp
+
+_os=template
+SOURCES *= $${PWD}/framework-OSInterface-$${_os}.cpp
+
+INCLUDEPATH *= $${PWD}
diff --git a/src-qt5/src-cpp/framework-OSInterface_private.cpp b/src-qt5/src-cpp/framework-OSInterface_private.cpp
index 7dfc8606..b4f4235e 100644
--- a/src-qt5/src-cpp/framework-OSInterface_private.cpp
+++ b/src-qt5/src-cpp/framework-OSInterface_private.cpp
@@ -6,7 +6,10 @@
//===========================================
// Internal, OS-agnostic functionality for managing the object itself
//===========================================
-#include <OSInterface.h>
+#include <framework-OSInterface.h>
+#include <QFile>
+#include <QDir>
+#include <QVariant>
OSInterface::OSInterface(QObject *parent) : QObject(parent){
watcher = 0;
@@ -29,7 +32,7 @@ OSInterface::~OSInterface(){
}
}
-OSInterface::OSInterface* instance(){
+OSInterface* OSInterface::instance(){
static OSInterface* m_os_object = 0;
if(m_os_object==0){
m_os_object = new OSInterface();
@@ -81,7 +84,7 @@ bool OSInterface::handleMediaDirChange(QString dir){ //returns true if directory
for(int i=0; i<files.length(); i++){ files[i] = qdir.absoluteFilePath(files[i]); }
QString key = "media_files/"+dir;
if(files.isEmpty() && INFO.contains(key)){ INFO.remove(key); emit mediaShortcutsChanged(); } //no files for this directory at the moment
- else{ INFO.setValue("media_files/"+dir, files); emit mediaShortcutsChanged(); } //save these file paths for later
+ else{ INFO.insert("media_files/"+dir, files); emit mediaShortcutsChanged(); } //save these file paths for later
//Make sure the directory is still watched (sometimes the dir is removed/recreated on modification)
if(!watcher->directories().contains(dir)){ watcher->addPath(dir); }
return true;
@@ -91,7 +94,7 @@ QStringList OSInterface::autoHandledMediaFiles(){
QStringList files;
QStringList keys = INFO.keys().filter("media_files/");
for(int i=0; i<keys.length(); i++){
- if(keys[i].startsWith("media_files/")){ files.append( INFO[keys[i]] ); }
+ if(keys[i].startsWith("media_files/")){ files << INFO[keys[i]].toStringList(); }
}
return files;
}
@@ -103,5 +106,5 @@ void OSInterface::setupNetworkManager(){
connectNetman();
}
//Load the initial state of the network accessibility
- netAccessChanged(netman->networkAccessibility());
+ netAccessChanged(netman->networkAccessible());
}
diff --git a/src-qt5/src-cpp/tests/main.cpp b/src-qt5/src-cpp/tests/main.cpp
new file mode 100644
index 00000000..682c318a
--- /dev/null
+++ b/src-qt5/src-cpp/tests/main.cpp
@@ -0,0 +1,38 @@
+#include <QDebug>
+#include <QApplication>
+
+#include <framework-OSInterface.h>
+
+/*
+class tester : public QObject{
+ Q_OBJECT
+public slots:
+ void finished(){ QApplication::exit(0); }
+
+public:
+ QTimer *timer;
+
+ tester(){
+ timer = new QTimer(this);
+ timer->setInterval(5000);
+ timer->setSingleShot(true);
+ connect(timer, SIGNAL(timeout()), this, SLOT(finished()) );
+ }
+
+};
+*/
+
+int main(int argc, char** argv){
+
+ QApplication A(argc,argv);
+ OSInterface OS;
+ OS.start();
+ QTimer *timer = new QTimer();
+ timer->setInterval(5000);
+ timer->setSingleShot(true);
+ QObject::connect(timer, SIGNAL(timeout()), &A, SLOT(quit()) );
+ timer->start();
+ int ret = A.exec();
+ qDebug() << " - Finished";
+ return ret;
+}
diff --git a/src-qt5/src-cpp/tests/test.pro b/src-qt5/src-cpp/tests/test.pro
new file mode 100644
index 00000000..425e7de6
--- /dev/null
+++ b/src-qt5/src-cpp/tests/test.pro
@@ -0,0 +1,7 @@
+QT = core gui widgets
+
+include(../framework-OSInterface.pri)
+
+TARGET = test
+
+SOURCES += main.cpp
bgstack15