end work to dbus interface

This commit is contained in:
arcan1s 2014-08-06 22:36:10 +04:00
parent 86753070e8
commit dee47b0ffc
7 changed files with 147 additions and 52 deletions

View File

@ -363,11 +363,11 @@ void MainWindow::createDBusSession()
if (!bus.registerService(QString(DBUS_SERVICE)))
if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register service";
if (!bus.registerObject(QString(DBUS_OBJECT_PATH),
new NetctlGuiAdaptor(this, debug),
new NetctlGuiAdaptor(this),
QDBusConnection::ExportAllContents))
if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register GUI object";
if (!bus.registerObject(QString(DBUS_LIB_PATH),
new NetctlAdaptor(this, debug, configuration),
new NetctlAdaptor(this, configuration),
QDBusConnection::ExportAllContents))
if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register library object";
}

View File

@ -16,33 +16,139 @@
***************************************************************************/
#include <QDebug>
#include <netctlgui/netctlgui.h>
#include "netctladaptor.h"
NetctlAdaptor::NetctlAdaptor(QObject *parent, const bool debugCmd, const QMap<QString, QString> configuration)
: QDBusAbstractAdaptor(parent),
debug(debugCmd)
NetctlAdaptor::NetctlAdaptor(QObject *parent, const QMap<QString, QString> configuration)
: QDBusAbstractAdaptor(parent)
{
netctlCommand = new Netctl(debug, configuration);
netctlProfile = new NetctlProfile(debug, configuration);
wpaCommand = new WpaSup(debug, configuration);
netctlCommand = new Netctl(false, configuration);
netctlProfile = new NetctlProfile(false, configuration);
wpaCommand = new WpaSup(false, configuration);
}
NetctlAdaptor::~NetctlAdaptor()
{
if (debug) qDebug() << "[NetctlAdaptor]" << "[~NetctlAdaptor]";
delete netctlCommand;
delete netctlProfile;
delete wpaCommand;
}
QString NetctlAdaptor::Information()
// netctlCommand
QString NetctlAdaptor::ActiveProfile()
{
if (debug) qDebug() << "[NetctlAdaptor]" << "[Information]";
if (netctlCommand->isNetctlAutoRunning())
return netctlCommand->autoGetActiveProfile();
else
return netctlCommand->getActiveProfile();
}
QString NetctlAdaptor::ActiveProfileStatus()
{
if (netctlCommand->isNetctlAutoRunning())
return QString("netctl-auto");
else
return netctlCommand->getProfileStatus(ActiveProfile());
}
bool NetctlAdaptor::autoIsProfileActive(const QString profile)
{
return netctlCommand->autoIsProfileActive(profile);
}
bool NetctlAdaptor::autoIsProfileEnabled(const QString profile)
{
return netctlCommand->autoIsProfileEnabled(profile);
}
QStringList NetctlAdaptor::Information()
{
QStringList output;
output.append(QString("Profile: %1").arg(ActiveProfile()));
output.append(QString("Status: %1").arg(ActiveProfileStatus()));
return output;
}
bool NetctlAdaptor::isProfileActive(const QString profile)
{
return netctlCommand->isProfileActive(profile);
}
bool NetctlAdaptor::isProfileEnabled(const QString profile)
{
return netctlCommand->isProfileEnabled(profile);
}
QStringList NetctlAdaptor::ProfileList()
{
QList<netctlProfileInfo> profilesInfo;
if (netctlCommand->isNetctlAutoRunning())
profilesInfo = netctlCommand->getProfileListFromNetctlAuto();
else
profilesInfo = netctlCommand->getProfileList();
QStringList info;
for (int i=0; i<profilesInfo.count(); i++) {
QStringList profileInfo;
profileInfo.append(profilesInfo[i].name);
profileInfo.append(profilesInfo[i].description);
profileInfo.append(QString::number(profilesInfo[i].active));
profileInfo.append(QString::number(profilesInfo[i].enabled));
info.append(profileInfo.join(QChar('|')));
}
return info;
}
// netctlProfile
QStringList NetctlAdaptor::Profile(const QString profile)
{
QMap<QString, QString> settings = netctlProfile->getSettingsFromProfile(profile);
QStringList settingsList;
for (int i=0; i<settings.keys().count(); i++)
settingsList.append(settings.keys()[i] + QString("=") +
settings[settings.keys()[i]]);
return settingsList;
}
QString NetctlAdaptor::ProfileValue(const QString profile, const QString key)
{
return netctlProfile->getValueFromProfile(profile, key);
}
// wpaCommand
QString NetctlAdaptor::ProfileByEssid(const QString essid)
{
return wpaCommand->existentProfile(essid);
}
QStringList NetctlAdaptor::WiFi()
{
QList<netctlWifiInfo> wifiPoints = wpaCommand->scanWifi();
QStringList info;
for (int i=0; i<wifiPoints.count(); i++) {
QStringList point;
point.append(wifiPoints[i].name);
point.append(wifiPoints[i].security);
point.append(wifiPoints[i].signal);
point.append(QString::number(wifiPoints[i].active));
point.append(QString::number(wifiPoints[i].exists));
info.append(point.join(QChar('|')));
}
return info;
}

View File

@ -19,28 +19,39 @@
#define NETCTLADAPTOR_H
#include <QDBusAbstractAdaptor>
#include <QStringList>
#include <netctlgui/netctlgui.h>
class Netctl;
class NetctlProfile;
class WpaSup;
class NetctlAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.netctlgui.netctlgui")
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.netctlgui")
public:
explicit NetctlAdaptor(QObject *parent = 0,
const bool debugCmd = false,
const QMap<QString, QString> configuration = QMap<QString, QString>());
~NetctlAdaptor();
public slots:
QString Information();
// netctlCommand
QString ActiveProfile();
QString ActiveProfileStatus();
bool autoIsProfileActive(const QString profile);
bool autoIsProfileEnabled(const QString profile);
QStringList Information();
bool isProfileActive(const QString profile);
bool isProfileEnabled(const QString profile);
QStringList ProfileList();
// netctlProfile
QStringList Profile(const QString profile);
QString ProfileValue(const QString profile, const QString key);
// wpaCommand
QString ProfileByEssid(const QString essid);
QStringList WiFi();
private:
bool debug;
Netctl *netctlCommand;
NetctlProfile *netctlProfile;
WpaSup *wpaCommand;

View File

@ -16,15 +16,12 @@
***************************************************************************/
#include <QDebug>
#include "mainwindow.h"
#include "netctlguiadaptor.h"
NetctlGuiAdaptor::NetctlGuiAdaptor(MainWindow *parent, const bool debugCmd)
NetctlGuiAdaptor::NetctlGuiAdaptor(MainWindow *parent)
: QDBusAbstractAdaptor(parent),
debug(debugCmd),
mainWindow(parent)
{
}
@ -32,14 +29,11 @@ NetctlGuiAdaptor::NetctlGuiAdaptor(MainWindow *parent, const bool debugCmd)
NetctlGuiAdaptor::~NetctlGuiAdaptor()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[~NetctlGuiAdaptor]";
}
bool NetctlGuiAdaptor::Close()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[Close]";
mainWindow->closeMainWindow();
return true;
}
@ -47,16 +41,12 @@ bool NetctlGuiAdaptor::Close()
QString NetctlGuiAdaptor::Information()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[Information]";
return mainWindow->getInformation();
}
bool NetctlGuiAdaptor::RestoreWindow()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[RestoreWindow]";
mainWindow->show();
return true;
}
@ -64,16 +54,12 @@ bool NetctlGuiAdaptor::RestoreWindow()
QStringList NetctlGuiAdaptor::Settings()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[Settings]";
return mainWindow->getSettings();
}
bool NetctlGuiAdaptor::ShowAbout()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[ShowAbout]";
mainWindow->showAboutWindow();
return true;
}
@ -81,8 +67,6 @@ bool NetctlGuiAdaptor::ShowAbout()
bool NetctlGuiAdaptor::ShowMain()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[ShowMain]";
mainWindow->showMainWindow();
return true;
}
@ -90,8 +74,6 @@ bool NetctlGuiAdaptor::ShowMain()
bool NetctlGuiAdaptor::ShowNetctlAuto()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[ShowNetctlAuto]";
mainWindow->showNetctlAutoWindow();
return true;
}
@ -99,8 +81,6 @@ bool NetctlGuiAdaptor::ShowNetctlAuto()
bool NetctlGuiAdaptor::ShowSettings()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[ShowSettings]";
mainWindow->showSettingsWindow();
return true;
}

View File

@ -27,11 +27,10 @@ class MainWindow;
class NetctlGuiAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.netctlgui.netctlgui")
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.netctlgui")
public:
explicit NetctlGuiAdaptor(MainWindow *parent = 0,
const bool debugCmd = false);
explicit NetctlGuiAdaptor(MainWindow *parent = 0);
~NetctlGuiAdaptor();
public slots:
@ -45,7 +44,6 @@ public slots:
bool ShowSettings();
private:
bool debug;
MainWindow *mainWindow;
};

View File

@ -336,11 +336,11 @@ bool Netctl::autoIsProfileEnabled(const QString profile)
if (debug) qDebug() << "[Netctl]" << "[autoIsProfileEnabled]";
if (debug) qDebug() << "[Netctl]" << "[autoIsProfileEnabled]" << ":" << "Profile" << profile;
bool status = true;
bool status = false;
QList<netctlProfileInfo> profiles = getProfileListFromNetctlAuto();
for (int i=0; i<profiles.count(); i++)
if ((profiles[i].name == profile) && (!profiles[i].enabled)) {
status = false;
if ((profiles[i].name == profile) && (profiles[i].enabled)) {
status = true;
break;
}

View File

@ -27,9 +27,9 @@
#define PROJECT_BUILD_PLASMOID "@BUILD_PLASMOID@"
#define PROJECT_USE_QT5 "@USE_QT5@"
#define DBUS_INTERFACE "org.netctlgui.netctlgui"
#define DBUS_INTERFACE "org.freedesktop.netctlgui"
#define DBUS_LIB_PATH "/netctl"
#define DBUS_OBJECT_PATH "/netctlgui"
#define DBUS_SERVICE "org.netctlgui.netctlgui"
#define DBUS_SERVICE "org.freedesktop.netctlgui"
#endif /* VERSION_H */