summaryrefslogtreecommitdiffstats
path: root/src/config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.cpp')
-rw-r--r--src/config.cpp117
1 files changed, 0 insertions, 117 deletions
diff --git a/src/config.cpp b/src/config.cpp
deleted file mode 100644
index c8327f7..0000000
--- a/src/config.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-#include <QDebug>
-#include <QStringList>
-#include <stdio.h>
-#include <sys/types.h>
-#include <ifaddrs.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <arpa/inet.h>
-#include "config.h"
-
-#define GROUP_GENERAL "General"
-#define GROUP_MODELINES "Modelines"
-#define GROUP_SPECIFIC "SpecificSettings"
-#define DISPLAY_KEY "display"
-#define DISPLAY_DEFAULT ":0"
-#define IFACE_KEY "interface"
-#define IFACE_DEFAULT "eth0"
-
-Config * Config::Instance = NULL;
-
-//_____________________________________________________________________________
-
-
-Config::Config()
-{
- // Defaults
- display = ":0";
- interface = "eth0";
-}
-
-//_____________________________________________________________________________
-
-
-void Config::loadSettings(QString _file)
-{
- // Open setting file
- settingsPath = _file;
- QSettings settings(settingsPath, QSettings::NativeFormat);
-
- // Get general information
- settings.beginGroup(GROUP_GENERAL);
- display = settings.value(DISPLAY_KEY, DISPLAY_DEFAULT).toString();
- interface = settings.value(IFACE_KEY, IFACE_DEFAULT).toString();
- settings.endGroup();
-
-
- /* Check for ip specific settings */
- // Get local ip
- QString IPV4 = getIPV4ofInterface(interface);
-
- // Find any information saved about this ip
- settings.beginGroup(GROUP_SPECIFIC);
- if ( settings.contains(IPV4) )
- ipSpecificXConf = settings.value(IPV4).toStringList();
- settings.endGroup();
-
-
- /* Get the "must-have-modelines" */
-
- int size = settings.beginReadArray(GROUP_MODELINES);
- for (int i = 0; i < size; ++i) {
- settings.setArrayIndex(i);
- qDebug()<< settings.value("Modeline").toString();
- modeLines.append(settings.value("Modeline").toString());
- }
- settings.endArray();
-
-
-
-// // Get all keys in this group (Keys are modenames)
-// QStringList modeKeys = settings.allKeys();
-
-// // Get the modeline for each key
-// for (QStringList::const_iterator i = modeKeys.constBegin(); i != modeKeys.constEnd(); ++i)
-// {
-// qDebug()<< "found" << *i;
-// // Prepend the name and save in list
-// modeLines.insert(*i, settings.value(*i).toStringList());
-// }
-// settings.endGroup();
-
-}
-
-//_____________________________________________________________________________
-
-
-QString Config::getIPV4ofInterface(QString _if) const
-{
- struct ifaddrs * ifAddrStruct=NULL;
- struct ifaddrs * ifa=NULL;
- void * tmpAddrPtr=NULL;
- QString result;
-
- getifaddrs(&ifAddrStruct);
-
- // Iterate through the adresses.
- for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next)
- {
- // If the address is IP V4 and the interface is _if
- if (ifa ->ifa_addr->sa_family==AF_INET && ( strcmp(ifa->ifa_name, _if.toUtf8().constData()) == 0) )
- {
- // Get the IP
- tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
-
- // convert to readable form
- char addressBuffer[INET_ADDRSTRLEN];
- inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
- result = addressBuffer;
- }
- }
-
- // clean up
- if (ifAddrStruct!=NULL)
- freeifaddrs(ifAddrStruct);
-
- return result;
-}