some improvements in helper and gui APIs and replacement and restoring

sessions
This commit is contained in:
arcan1s
2014-08-12 14:01:00 +04:00
parent fddd4703cc
commit b65f761520
11 changed files with 128 additions and 16 deletions

View File

@ -18,11 +18,13 @@
# variables
_netctlgui_helper_arglist=(
'--nodaemon'
'-c'
'--config'
'-d'
'--debug'
'--nodaemon'
'--replace'
'--restore'
'-v'
'--version'
'-i'

View File

@ -11,13 +11,17 @@ is a Qt based helper daemon which provides a DBus interface for interaction with
without any additional permissions. To have access to DBus interface user should have group
.B network
.SH OPTIONS
.IP "--nodaemon"
do not run as daemon
.IP "-c, --config FILE"
read configuration from file
.I FILE
.IP "-d, --debug"
print debug information
.IP "--nodaemon"
do not run as daemon
.IP "--replace"
force replace the existing session
.IP "--restore"
force restore the existing session
.IP "-v, --version"
show version and exit
.IP "-i, --info"

View File

@ -18,6 +18,7 @@
#include "controladaptor.h"
#include <QTextCodec>
#include <unistd.h>
#include "netctlhelper.h"
#include "version.h"
@ -93,6 +94,16 @@ QStringList ControlAdaptor::Settings()
}
QStringList ControlAdaptor::UIDs()
{
QStringList uids;
uids.append(QString::number(getuid()));
uids.append(QString::number(geteuid()));
return uids;
}
bool ControlAdaptor::Update()
{
helper->updateConfiguration();

View File

@ -44,6 +44,7 @@ public slots:
QString Pony();
QString SecurityDocs();
QStringList Settings();
QStringList UIDs();
bool Update();
// netctlCommand
bool autoDisableAll();

View File

@ -34,13 +34,14 @@
using namespace std;
bool checkExistSession()
bool existingSessionOperation(const QString operation)
{
QDBusConnection bus = QDBusConnection::systemBus();
QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Active"));
DBUS_HELPER_INTERFACE, operation);
QDBusMessage response = bus.call(request);
QList<QVariant> arguments = response.arguments();
return !arguments.isEmpty();
}
@ -60,6 +61,12 @@ int main(int argc, char *argv[])
} else if (QString(argv[i]) == QString("--nodaemon")) {
// daemonized
args[QString("nodaemon")] = true;
} else if (QString(argv[i]) == QString("--replace")) {
// replace
args[QString("state")] = (int) 1;
} else if (QString(argv[i]) == QString("--restore")) {
// restore
args[QString("state")] = (int) 2;
} else if ((QString(argv[i]) == QString("-h")) || (QString(argv[i]) == QString("--help"))) {
// help message
args[QString("help")] = true;
@ -119,8 +126,31 @@ int main(int argc, char *argv[])
}
// check if exists
if (checkExistSession())
return 0;
if (existingSessionOperation(QString("Active"))) {
if (args[QString("state")].toInt() == 1) {
// replace session
cout << QCoreApplication::translate("NetctlHelper", "Replace existing session.")
.toUtf8().data() << endl;
existingSessionOperation(QString("Close"));
} else if (args[QString("state")].toInt() == 2) {
// restore session
cout << QCoreApplication::translate("NetctlHelper", "Restore existing session.")
.toUtf8().data() << endl;
return 0;
}
else if (geteuid() == 0) {
// replace if running as root
cout << QCoreApplication::translate("NetctlHelper", "Replace existing session.")
.toUtf8().data() << endl;
existingSessionOperation(QString("Close"));
}
else {
// restore if running as non-root
cout << QCoreApplication::translate("NetctlHelper", "Restore existing session.")
.toUtf8().data() << endl;
return 0;
}
}
NetctlHelper w(0, args);
return a.exec();
}

View File

@ -37,6 +37,7 @@ QMap<QString, QVariant> getArgs()
args[QString("config")] = QString(QDir::homePath() + QString("/.config/netctl-gui.conf"));
args[QString("debug")] = false;
args[QString("nodaemon")] = false;
args[QString("state")] = (int) 0;
args[QString("help")] = false;
args[QString("info")] = false;
args[QString("version")] = false;
@ -59,6 +60,10 @@ QString helpMessage()
.arg(QCoreApplication::translate("NetctlHelper", "print debug information"));
helpMessage += QString(" --nodaemon - %1\n")
.arg(QCoreApplication::translate("NetctlHelper", "do not start as daemon"));
helpMessage += QString(" --replace - %1\n")
.arg(QCoreApplication::translate("NetctlHelper", "force replace the existing session"));
helpMessage += QString(" --restore - %1\n")
.arg(QCoreApplication::translate("NetctlHelper", "force restore the existing session"));
helpMessage += QString(" %1\n").arg(QCoreApplication::translate("NetctlHelper", "Show messages:"));
helpMessage += QString(" -v, --version - %1\n")
.arg(QCoreApplication::translate("NetctlHelper", "show version and exit"));

View File

@ -19,9 +19,11 @@
# variables
_netctlgui_helper_arglist=(
{'--nodaemon','--nodaemon'}'[do not start as daemon]'
{'(--config)-c','(-c)--config'}'[read configuration from this file]:select file:->files'
{'(--debug)-d','(-d)--debug'}'[print debug information]'
{'--nodaemon','--nodaemon'}'[do not start as daemon]'
{'--replace','--replace'}'[force replace the existing session]'
{'--restore','--restore'}'[force restore the existing session]'
{'(--version)-v','(-v)--version'}'[show version and exit]'
{'(--info)-i','(-i)--info'}'[show build information and exit]'
{'(--help)-h','(-h)--help'}'[show help and exit]'