add calls

create interface dbus interface
This commit is contained in:
arcan1s
2015-03-13 08:22:02 +03:00
parent 26afd90df9
commit ef2694d7a7
11 changed files with 311 additions and 118 deletions

View File

@ -0,0 +1,122 @@
/***************************************************************************
* This file is part of netctl-gui *
* *
* netctl-gui is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* netctl-gui is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "interfaceadaptor.h"
#include <QTextCodec>
#include <unistd.h>
#include "netctlhelper.h"
#include "version.h"
InterfaceAdaptor::InterfaceAdaptor(QObject *parent, const bool debugCmd, const QMap<QString, QString> configuration)
: QDBusAbstractAdaptor(parent),
debug(debugCmd)
{
netctlInterface = new NetctlInterface(debug, configuration);
}
InterfaceAdaptor::~InterfaceAdaptor()
{
if (netctlInterface != nullptr) delete netctlInterface;
}
int InterfaceAdaptor::autoEnable(const QString profile)
{
return netctlInterface->autoEnableProfile(profile);
}
int InterfaceAdaptor::Create(const QString profile, const QStringList settingsList)
{
QMap<QString, QString> settings;
for (int i=0; i<settingsList.count(); i++) {
if (!settingsList[i].contains(QString("=="))) continue;
QString key = settingsList[i].split(QString("=="))[0];
QString value = settingsList[i].split(QString("=="))[1];
settings[key] = value;
}
return netctlInterface->createProfile(profile, settings);
}
int InterfaceAdaptor::Enable(const QString profile)
{
return netctlInterface->enableProfile(profile);
}
int InterfaceAdaptor::Essid(const QString essid, QStringList settingsList)
{
QMap<QString, QString> settings;
for (int i=0; i<settingsList.count(); i++) {
if (!settingsList[i].contains(QString("=="))) continue;
QString key = settingsList[i].split(QString("=="))[0];
QString value = settingsList[i].split(QString("=="))[1];
settings[key] = value;
}
return netctlInterface->connectToEssid(essid, settings);
}
int InterfaceAdaptor::KnownEssid(const QString essid)
{
return netctlInterface->connectToKnownEssid(essid);
}
int InterfaceAdaptor::Restart(const QString profile)
{
return netctlInterface->restartProfile(profile);
}
int InterfaceAdaptor::Start(const QString profile)
{
return netctlInterface->startProfile(profile);
}
int InterfaceAdaptor::StopAll()
{
return netctlInterface->stopAllProfiles();
}
int InterfaceAdaptor::SwitchTo(const QString profile)
{
return netctlInterface->switchToProfile(profile);
}
int InterfaceAdaptor::UnknownEssid(const QString essid, QStringList settingsList)
{
QMap<QString, QString> settings;
for (int i=0; i<settingsList.count(); i++) {
if (!settingsList[i].contains(QString("=="))) continue;
QString key = settingsList[i].split(QString("=="))[0];
QString value = settingsList[i].split(QString("=="))[1];
settings[key] = value;
}
return netctlInterface->connectToUnknownEssid(essid, settings);
}

View File

@ -0,0 +1,56 @@
/***************************************************************************
* This file is part of netctl-gui *
* *
* netctl-gui is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* netctl-gui is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef INTERFACEADAPTOR_H
#define INTERFACEADAPTOR_H
#include <QDBusAbstractAdaptor>
#include <netctlgui/netctlgui.h>
class InterfaceAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.netctlgui.helper")
public:
explicit InterfaceAdaptor(QObject *parent = 0,
const bool debugCmd = false,
const QMap<QString, QString> configuration = QMap<QString, QString>());
~InterfaceAdaptor();
public slots:
// interface
int autoEnable(const QString profile);
int Create(const QString profile, const QStringList settingsList);
int Enable(const QString profile);
int Essid(const QString essid, QStringList settingsList);
int KnownEssid(const QString essid);
int Restart(const QString profile);
int Start(const QString profile);
int StopAll();
int SwitchTo(const QString profile);
int UnknownEssid(const QString essid, QStringList settingsList);
private:
bool debug;
NetctlInterface *netctlInterface = nullptr;
};
#endif /* INTERFACEADAPTOR_H */

View File

@ -28,6 +28,7 @@
#include <pdebug/pdebug.h>
#include "controladaptor.h"
#include "interfaceadaptor.h"
#include "netctladaptor.h"
#include "version.h"
@ -88,6 +89,13 @@ void NetctlHelper::createInterface()
if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
return quitHelper();
}
if (!bus.registerObject(DBUS_INTERFACE_PATH,
new InterfaceAdaptor(this, debug, configuration),
QDBusConnection::ExportAllContents)) {
if (debug) qDebug() << PDEBUG << ":" << "Could not register interface object";
if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
return quitHelper();
}
// session bus
if (!session) return;
QDBusConnection sessionBus = QDBusConnection::sessionBus();
@ -107,6 +115,13 @@ void NetctlHelper::createInterface()
if (debug) qDebug() << PDEBUG << ":" << "Could not register session control object";
if (debug) qDebug() << PDEBUG << ":" << sessionBus.lastError().message();
}
if (!sessionBus.registerObject(DBUS_INTERFACE_PATH,
new InterfaceAdaptor(this, debug, configuration),
QDBusConnection::ExportAllContents)) {
if (debug) qDebug() << PDEBUG << ":" << "Could not register session interface object";
if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
return quitHelper();
}
}
@ -116,11 +131,13 @@ void NetctlHelper::deleteInterface()
QDBusConnection::systemBus().unregisterObject(DBUS_LIB_PATH);
QDBusConnection::systemBus().unregisterObject(DBUS_CTRL_PATH);
QDBusConnection::systemBus().unregisterObject(DBUS_INTERFACE_PATH);
QDBusConnection::systemBus().unregisterService(DBUS_HELPER_SERVICE);
// session bus
if (!session) return;
QDBusConnection::sessionBus().unregisterObject(DBUS_LIB_PATH);
QDBusConnection::sessionBus().unregisterObject(DBUS_CTRL_PATH);
QDBusConnection::sessionBus().unregisterObject(DBUS_INTERFACE_PATH);
QDBusConnection::sessionBus().unregisterService(DBUS_HELPER_SERVICE);
}
@ -176,6 +193,14 @@ QMap<QString, QString> NetctlHelper::getSettings(const QString file)
config[QString("PREFERED_IFACE")] = settings.value(QString("PREFERED_IFACE"), QString("")).toString();
settings.endGroup();
settings.beginGroup(QString("Toolbars"));
config[QString("MAIN_TOOLBAR")] = settings.value(QString("MAIN_TOOLBAR"), Qt::TopToolBarArea).toString();
config[QString("NETCTL_TOOLBAR")] = settings.value(QString("NETCTL_TOOLBAR"), Qt::TopToolBarArea).toString();
config[QString("NETCTLAUTO_TOOLBAR")] = settings.value(QString("NETCTLAUTO_TOOLBAR"), Qt::TopToolBarArea).toString();
config[QString("PROFILE_TOOLBAR")] = settings.value(QString("PROFILE_TOOLBAR"), Qt::TopToolBarArea).toString();
config[QString("WIFI_TOOLBAR")] = settings.value(QString("WIFI_TOOLBAR"), Qt::TopToolBarArea).toString();
settings.endGroup();
for (int i=0; i<config.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << QString("%1=%2").arg(config.keys()[i]).arg(config[config.keys()[i]]);