mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-05 10:05:46 +00:00
some improvements in helper and gui APIs and replacement and restoring
sessions
This commit is contained in:
@ -34,11 +34,11 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
bool restoreExistSession()
|
||||
bool existingSessionOperation(const QString operation)
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
QDBusMessage request = QDBusMessage::createMethodCall(DBUS_SERVICE, DBUS_OBJECT_PATH,
|
||||
DBUS_INTERFACE, QString("Restore"));
|
||||
DBUS_INTERFACE, operation);
|
||||
QDBusMessage response = bus.call(request);
|
||||
QList<QVariant> arguments = response.arguments();
|
||||
|
||||
@ -46,6 +46,18 @@ bool restoreExistSession()
|
||||
}
|
||||
|
||||
|
||||
unsigned int getUidFromSession(const int type = 0)
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
QDBusMessage request = QDBusMessage::createMethodCall(DBUS_SERVICE, DBUS_OBJECT_PATH,
|
||||
DBUS_INTERFACE, QString("UIDs"));
|
||||
QDBusMessage response = bus.call(request);
|
||||
QList<QVariant> arguments = response.arguments();
|
||||
|
||||
return arguments[0].toStringList()[type].toUInt();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QMap<QString, QVariant> args = getArgs();
|
||||
@ -164,8 +176,20 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// check if exists
|
||||
if (restoreExistSession())
|
||||
return 0;
|
||||
if (existingSessionOperation(QString("Active"))) {
|
||||
if ((getuid() == getUidFromSession(0)) && (geteuid() == getUidFromSession(1))) {
|
||||
// restore session
|
||||
cout << QCoreApplication::translate("MainWindow", "Restore existing session.")
|
||||
.toUtf8().data() << endl;
|
||||
existingSessionOperation(QString("Restore"));
|
||||
return 0;
|
||||
} else if ((getuid() == getUidFromSession(0)) && (geteuid() != getUidFromSession(1))) {
|
||||
cout << QCoreApplication::translate("MainWindow", "Close existing session.")
|
||||
.toUtf8().data() << endl;
|
||||
existingSessionOperation(QString("Restore"));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
MainWindow w(0, args, &qtTranslator, &translator);
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "netctlguiadaptor.h"
|
||||
|
||||
#include <QTextCodec>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
@ -34,6 +35,12 @@ NetctlGuiAdaptor::~NetctlGuiAdaptor()
|
||||
}
|
||||
|
||||
|
||||
bool NetctlGuiAdaptor::Active()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void NetctlGuiAdaptor::ApiDocs()
|
||||
{
|
||||
return mainWindow->showApi();
|
||||
@ -119,6 +126,16 @@ bool NetctlGuiAdaptor::ShowSettings()
|
||||
}
|
||||
|
||||
|
||||
QStringList NetctlGuiAdaptor::UIDs()
|
||||
{
|
||||
QStringList uids;
|
||||
uids.append(QString::number(getuid()));
|
||||
uids.append(QString::number(geteuid()));
|
||||
|
||||
return uids;
|
||||
}
|
||||
|
||||
|
||||
QStringList NetctlGuiAdaptor::VerboseInformation()
|
||||
{
|
||||
return mainWindow->printTrayInformation();
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
~NetctlGuiAdaptor();
|
||||
|
||||
public slots:
|
||||
bool Active();
|
||||
void ApiDocs();
|
||||
bool Close();
|
||||
QStringList Information();
|
||||
@ -46,6 +47,7 @@ public slots:
|
||||
bool ShowMain();
|
||||
bool ShowNetctlAuto();
|
||||
bool ShowSettings();
|
||||
QStringList UIDs();
|
||||
QStringList VerboseInformation();
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user