end work on interfaces

This commit is contained in:
arcan1s
2015-03-14 06:42:06 +03:00
parent ef2694d7a7
commit f80d6aae6b
38 changed files with 676 additions and 569 deletions

View File

@ -19,11 +19,32 @@
#include <QDebug>
#include <listmap/listmap.h>
#include <pdebug/pdebug.h>
#include "dbusoperation.h"
InterfaceAnswer createProfileSlot(const QString profile, QMap<QString,QString> settings,
NetctlInterface* interface, const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (!useHelper) return interface->createProfile(profile, settings);
try {
QList<QVariant> args;
args.append(profile);
args.append(mapToList(settings));
int responce = sendRequestToInterfaceWithArgs(QString("Create"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug)
{
@ -43,6 +64,25 @@ InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interf
}
InterfaceAnswer removeProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (!useHelper) return interface->removeProfile(profile);
try {
QList<QVariant> args;
args.append(profile);
int responce = sendRequestToInterfaceWithArgs(QString("Remove"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug)
{
@ -114,3 +154,92 @@ InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *inte
return InterfaceAnswer::Error;
}
}
InterfaceAnswer connectToEssid(const QString essid, QMap<QString,QString> settings,
NetctlInterface* interface, const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
if (!useHelper) return interface->connectToEssid(essid, settings);
try {
QList<QVariant> args;
args.append(essid);
args.append(mapToList(settings));
int responce = sendRequestToInterfaceWithArgs(QString("Essid"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
netctlInformation generalInformation(NetctlInterface* interface, const bool useHelper,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (!useHelper) return interface->information();
try {
QList<QVariant> responce = sendRequestToInterface(QString("Information"), debug);
// main
netctlInformation info;
info.netctlAuto = responce[0].toStringList().takeFirst().toInt();
QList<netctlProfileInfo> profiles = parseOutputNetctl(responce);
for (int i=0; i<profiles.count(); i++) {
if (profiles[i].netctlAuto)
info.netctlAutoProfiles.append(profiles[i]);
else
info.netctlProfiles.append(profiles[i]);
}
return info;
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return netctlInformation();
}
}
QMap<QString, QString> profileInformation(const QString profile, NetctlInterface* interface,
const bool useHelper, const bool debug)
{
if (!useHelper) return interface->profileSettings(profile);
try {
QList<QVariant> args;
args.append(profile);
QStringList responce = sendRequestToInterfaceWithArgs(QString("Profile"), args, debug)[0].toStringList();
return listToMap(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return QMap<QString, QString>();
}
}
netctlCurrent trayInformation(NetctlInterface *interface, const bool useHelper,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (!useHelper) return interface->status();
try {
QStringList responce = sendRequestToInterface(QString("Status"), debug)[0].toStringList();
netctlCurrent status;
status.netctlAuto = responce[0].toInt();
status.profiles = responce[1].split(QChar('|'));
status.current = responce[2].split(QChar('|'));
QStringList enables = responce[3].split(QChar('|'));
for (int i=0; i<enables.count(); i++)
status.enables.append(enables[i].toInt());
return status;
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return netctlCurrent();
}
}