mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-10 04:15:52 +00:00
add calls
create interface dbus interface
This commit is contained in:
@ -24,160 +24,93 @@
|
||||
#include "dbusoperation.h"
|
||||
|
||||
|
||||
bool enableProfileSlot(const QString profile, Netctl *netctlCommand,
|
||||
const bool useHelper, const bool debug)
|
||||
InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface,
|
||||
const bool useHelper, const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
// enable
|
||||
if (!useHelper) return interface->enableProfile(profile);
|
||||
try {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("Enable"), args, debug);
|
||||
// check
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
// enable
|
||||
netctlCommand->enableProfile(profile);
|
||||
// check
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
int responce = sendRequestToInterfaceWithArgs(QString("Enable"), args, debug)[0].toInt();
|
||||
return static_cast<InterfaceAnswer>(responce);
|
||||
} catch (...) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
|
||||
return InterfaceAnswer::Error;
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool restartProfileSlot(const QString profile, Netctl *netctlCommand,
|
||||
const bool useHelper, const bool debug)
|
||||
InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface,
|
||||
const bool useHelper, const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
// restart
|
||||
if (!useHelper) return interface->restartProfile(profile);
|
||||
try {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("Restart"), args, debug);
|
||||
// check
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
// restart
|
||||
netctlCommand->restartProfile(profile);
|
||||
// check
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
int responce = sendRequestToInterfaceWithArgs(QString("Restart"), args, debug)[0].toInt();
|
||||
return static_cast<InterfaceAnswer>(responce);
|
||||
} catch (...) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
|
||||
return InterfaceAnswer::Error;
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool startProfileSlot(const QString profile, Netctl *netctlCommand,
|
||||
const bool useHelper, const bool debug)
|
||||
InterfaceAnswer startProfileSlot(const QString profile, NetctlInterface *interface,
|
||||
const bool useHelper, const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
// get current
|
||||
if (!useHelper) return interface->startProfile(profile);
|
||||
try {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QList<QVariant> responce = sendRequestToLib(QString("ActiveProfile"), debug);
|
||||
QStringList currentProfile;
|
||||
if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|'));
|
||||
// start or switch
|
||||
if ((currentProfile.isEmpty()) || (currentProfile.contains(profile)))
|
||||
sendRequestToCtrlWithArgs(QString("Start"), args, debug);
|
||||
else
|
||||
sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug);
|
||||
// check
|
||||
responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
// get current
|
||||
QStringList currentProfile = netctlCommand->getActiveProfile();
|
||||
// start or switch
|
||||
if ((currentProfile.isEmpty()) || (currentProfile.contains(profile)))
|
||||
netctlCommand->startProfile(profile);
|
||||
else
|
||||
netctlCommand->switchToProfile(profile);
|
||||
// check
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
int responce = sendRequestToInterfaceWithArgs(QString("Start"), args, debug)[0].toInt();
|
||||
return static_cast<InterfaceAnswer>(responce);
|
||||
} catch (...) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
|
||||
return InterfaceAnswer::Error;
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::stopAllProfilesSlot()
|
||||
InterfaceAnswer stopAllProfilesSlot(NetctlInterface *interface, const bool useHelper,
|
||||
const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (useHelper)
|
||||
sendRequestToCtrl(QString("StolAll"), debug);
|
||||
else
|
||||
netctlCommand->stopAllProfiles();
|
||||
|
||||
return true;
|
||||
if (!useHelper) return interface->stopAllProfiles();
|
||||
try {
|
||||
int responce = sendRequestToInterface(QString("StopAll"), debug)[0].toInt();
|
||||
return static_cast<InterfaceAnswer>(responce);
|
||||
} catch (...) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
|
||||
return InterfaceAnswer::Error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::switchToProfileSlot(const QString profile)
|
||||
InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *interface,
|
||||
const bool useHelper, const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool netctlAutoStatus = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> responce = sendRequestToLib(QString("isNetctlAutoActive"), debug);
|
||||
if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool();
|
||||
} else
|
||||
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
|
||||
|
||||
bool current;
|
||||
if (netctlAutoStatus) {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("autoStart"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->autoIsProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->autoStartProfile(profile);
|
||||
current = netctlCommand->autoIsProfileActive(profile);
|
||||
}
|
||||
} else {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->switchToProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
if (!useHelper) return interface->switchToProfile(profile);
|
||||
try {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
int responce = sendRequestToInterfaceWithArgs(QString("SwitchTo"), args, debug)[0].toInt();
|
||||
return static_cast<InterfaceAnswer>(responce);
|
||||
} catch (...) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
|
||||
return InterfaceAnswer::Error;
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
@ -24,8 +24,16 @@
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
|
||||
bool enableProfileSlot(const QString profile, Netctl *netctlCommand,
|
||||
const bool useHelper, const bool debug = false);
|
||||
InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface,
|
||||
const bool useHelper, const bool debug = false);
|
||||
InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface,
|
||||
const bool useHelper, const bool debug = false);
|
||||
InterfaceAnswer startProfileSlot(const QString profile, NetctlInterface *interface,
|
||||
const bool useHelper, const bool debug = false);
|
||||
InterfaceAnswer stopAllProfilesSlot(NetctlInterface *interface, const bool useHelper,
|
||||
const bool debug);
|
||||
InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *interface,
|
||||
const bool useHelper, const bool debug);
|
||||
|
||||
|
||||
#endif /* CALLS_H */
|
||||
|
@ -114,6 +114,26 @@ QList<QVariant> sendRequestToCtrlWithArgs(const QString cmd, const QList<QVarian
|
||||
}
|
||||
|
||||
|
||||
QList< QVariant > sendRequestToInterface(const QString cmd, const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
|
||||
|
||||
return sendRequestToInterfaceWithArgs(cmd, QList<QVariant>(), debug);
|
||||
}
|
||||
|
||||
|
||||
QList<QVariant> sendRequestToInterfaceWithArgs(const QString cmd, const QList<QVariant> args,
|
||||
const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "args" << args;
|
||||
|
||||
return sendRequestToHelper(DBUS_INTERFACE_PATH, cmd, args, debug);
|
||||
}
|
||||
|
||||
|
||||
QList<QVariant> sendRequestToLib(const QString cmd, const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
@ -30,6 +30,9 @@ QList<QVariant> sendRequestToHelper(const QString path, const QString cmd,
|
||||
QList<QVariant> sendRequestToCtrl(const QString cmd, const bool debug = false);
|
||||
QList<QVariant> sendRequestToCtrlWithArgs(const QString cmd, const QList<QVariant> args,
|
||||
const bool debug = false);
|
||||
QList<QVariant> sendRequestToInterface(const QString cmd, const bool debug = false);
|
||||
QList<QVariant> sendRequestToInterfaceWithArgs(const QString cmd, const QList<QVariant> args,
|
||||
const bool debug = false);
|
||||
QList<QVariant> sendRequestToLib(const QString cmd, const bool debug = false);
|
||||
QList<QVariant> sendRequestToLibWithArgs(const QString cmd, const QList<QVariant> args,
|
||||
const bool debug = false);
|
||||
|
Reference in New Issue
Block a user