mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-07 02:55:47 +00:00
some improvements in helper and gui APIs and replacement and restoring
sessions
This commit is contained in:
@ -58,7 +58,7 @@ th.sub {
|
||||
<!-- helper actions -->
|
||||
<tr>
|
||||
<td>bool Active()</td>
|
||||
<td><code>true</code> if helper is active</td>
|
||||
<td><code>true</code> if the helper is active</td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -91,9 +91,14 @@ th.sub {
|
||||
<td>current helper settings <code>KEY==VALUE</code></td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>QStringList UIDs()</td>
|
||||
<td>returns the helper process UIDs <code>[UID, EUID]</code></td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>bool Update()</td>
|
||||
<td>calls update helper configuration. Returns <code>true</code></td>
|
||||
<td>calls update the helper configuration. Returns <code>true</code></td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<!-- netctl actions -->
|
||||
@ -257,6 +262,11 @@ th.sub {
|
||||
<th colspan="3" class="sub"><a href="#netctlgui" class="anchor" name="netctlgui"></a><code>/netctlgui</code> path</th>
|
||||
</tr>
|
||||
<!-- gui actions -->
|
||||
<tr>
|
||||
<td>bool Active()</td>
|
||||
<td><code>true</code> if the application is active</td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>void ApiDocs()</td>
|
||||
<td>opens this API documentation</td>
|
||||
@ -269,7 +279,7 @@ th.sub {
|
||||
</tr>
|
||||
<tr>
|
||||
<td>QString Information()</td>
|
||||
<td>the same as <code>org.netctlgui.helper /netctl Information</code></td>
|
||||
<td>returns general information in format <code>[ActiveProfile, ActiveProfileStatus]</code></td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -317,11 +327,15 @@ th.sub {
|
||||
<td><code>true</code> and shows settings window</td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>QStringList UIDs()</td>
|
||||
<td>returns the application process UIDs <code>[UID, EUID]</code></td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>QStringList VerboseInformation()</td>
|
||||
<td>returns information in format <code>[isNetctlAutoActive, ProfileList, ActiveProfile, isProfileEnabled/autoIsProfileEnabled]</code></td>
|
||||
<td>no</td>
|
||||
<td>no</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
@ -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