start work on dbus module

This commit is contained in:
arcan1s
2014-08-06 21:10:08 +04:00
parent 447bcf8a0e
commit ff78d390ae
10 changed files with 146 additions and 28 deletions

View File

@ -35,13 +35,13 @@ using namespace std;
bool restoreExistSession() bool restoreExistSession()
{ {
QDBusConnection bus = QDBusConnection::sessionBus(); QDBusConnection bus = QDBusConnection::sessionBus();
QDBusMessage request = QDBusMessage::createMethodCall(DBUS_SERVICE, QDBusMessage request = QDBusMessage::createMethodCall(QString(DBUS_SERVICE),
DBUS_OBJECT_PATH, QString(DBUS_OBJECT_PATH),
DBUS_INTERFACE, QString(DBUS_INTERFACE),
QString("RestoreWindow")); QString("RestoreWindow"));
QDBusMessage response = bus.call(request); QDBusMessage response = bus.call(request);
QList<QVariant> arguments = response.arguments(); QList<QVariant> arguments = response.arguments();
return ((arguments.size()==1) && arguments[0].toBool()); return ((arguments.size() == 1) && arguments[0].toBool());
} }
@ -56,11 +56,13 @@ QChar isParametrEnable(const bool parametr)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv);
QApplication::setQuitOnLastWindowClosed(false);
// check if exists
if (restoreExistSession()) if (restoreExistSession())
return 0; return 0;
QApplication a(argc, argv);
// config path // config path
QString configPath = QString(QDir::homePath() + QString("/.config/netctl-gui.conf")); QString configPath = QString(QDir::homePath() + QString("/.config/netctl-gui.conf"));
// translation // translation

View File

@ -36,6 +36,7 @@
#include "ipwidget.h" #include "ipwidget.h"
#include "macvlanwidget.h" #include "macvlanwidget.h"
#include "mobilewidget.h" #include "mobilewidget.h"
#include "netctladaptor.h"
#include "netctlautowindow.h" #include "netctlautowindow.h"
#include "netctlguiadaptor.h" #include "netctlguiadaptor.h"
#include "passwdwidget.h" #include "passwdwidget.h"
@ -186,6 +187,7 @@ MainWindow::~MainWindow()
{ {
if (debug) qDebug() << "[MainWindow]" << "[~MainWindow]"; if (debug) qDebug() << "[MainWindow]" << "[~MainWindow]";
QDBusConnection::sessionBus().unregisterService(QString(DBUS_SERVICE));
delete netctlCommand; delete netctlCommand;
delete netctlProfile; delete netctlProfile;
delete wpaCommand; delete wpaCommand;
@ -206,8 +208,8 @@ MainWindow::~MainWindow()
delete errorWin; delete errorWin;
delete netctlAutoWin; delete netctlAutoWin;
delete settingsWin; delete settingsWin;
delete ui;
delete trayIcon; delete trayIcon;
delete ui;
} }
@ -226,7 +228,7 @@ QString MainWindow::getInformation()
status = netctlCommand->getProfileStatus(profile); status = netctlCommand->getProfileStatus(profile);
} }
QString output = QString("%1: %2\n").arg(QApplication::translate("MainWindow", "Profile")).arg(profile); QString output = QString("%1: %2\n").arg(QApplication::translate("MainWindow", "Profile")).arg(profile);
output += QString("%1: %2\n").arg(QApplication::translate("MainWindow", "Status")).arg(status); output += QString("%1: %2").arg(QApplication::translate("MainWindow", "Status")).arg(status);
return output; return output;
} }
@ -353,12 +355,17 @@ void MainWindow::createDBusSession()
{ {
if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]"; if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]";
new NetctlGuiAdaptor(this, debug);
QDBusConnection bus = QDBusConnection::sessionBus(); QDBusConnection bus = QDBusConnection::sessionBus();
if (!bus.registerService(QString(DBUS_SERVICE))) if (!bus.registerService(QString(DBUS_SERVICE)))
if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register service"; if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register service";
if (!bus.registerObject(QString(DBUS_OBJECT_PATH), this)) if (!bus.registerObject(QString(DBUS_OBJECT_PATH),
if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register object"; new NetctlGuiAdaptor(this, debug),
QDBusConnection::ExportAllContents))
if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register GUI object";
if (!bus.registerObject(QString(DBUS_LIB_PATH),
new NetctlAdaptor(this, debug, configuration),
QDBusConnection::ExportAllContents))
if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register library object";
} }

View File

@ -0,0 +1,48 @@
/***************************************************************************
* 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 <QDebug>
#include <netctlgui/netctlgui.h>
#include "netctladaptor.h"
NetctlAdaptor::NetctlAdaptor(QObject *parent, const bool debugCmd, const QMap<QString, QString> configuration)
: QDBusAbstractAdaptor(parent),
debug(debugCmd)
{
netctlCommand = new Netctl(debug, configuration);
netctlProfile = new NetctlProfile(debug, configuration);
wpaCommand = new WpaSup(debug, configuration);
}
NetctlAdaptor::~NetctlAdaptor()
{
if (debug) qDebug() << "[NetctlAdaptor]" << "[~NetctlAdaptor]";
delete netctlCommand;
delete netctlProfile;
delete wpaCommand;
}
QString NetctlAdaptor::Information()
{
if (debug) qDebug() << "[NetctlAdaptor]" << "[Information]";
}

View File

@ -0,0 +1,50 @@
/***************************************************************************
* 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 NETCTLADAPTOR_H
#define NETCTLADAPTOR_H
#include <QDBusAbstractAdaptor>
class Netctl;
class NetctlProfile;
class WpaSup;
class NetctlAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.netctlgui.netctlgui")
public:
explicit NetctlAdaptor(QObject *parent = 0,
const bool debugCmd = false,
const QMap<QString, QString> configuration = QMap<QString, QString>());
~NetctlAdaptor();
public slots:
QString Information();
private:
bool debug;
Netctl *netctlCommand;
NetctlProfile *netctlProfile;
WpaSup *wpaCommand;
};
#endif /* NETCTLADAPTOR_H */

View File

@ -36,14 +36,6 @@ NetctlGuiAdaptor::~NetctlGuiAdaptor()
} }
QString NetctlGuiAdaptor::Information()
{
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[RestoreWindow]";
return mainWindow->getInformation();
}
bool NetctlGuiAdaptor::RestoreWindow() bool NetctlGuiAdaptor::RestoreWindow()
{ {
if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[RestoreWindow]"; if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[RestoreWindow]";

View File

@ -34,7 +34,6 @@ public:
~NetctlGuiAdaptor(); ~NetctlGuiAdaptor();
public slots: public slots:
QString Information();
bool RestoreWindow(); bool RestoreWindow();
private: private:

View File

@ -46,17 +46,29 @@ TrayIcon::~TrayIcon()
} }
void TrayIcon::showInformation() int TrayIcon::showInformation()
{ {
if (debug) qDebug() << "[TrayIcon]" << "[showInformation]"; if (debug) qDebug() << "[TrayIcon]" << "[showInformation]";
if (supportsMessages()) {
QString title = QApplication::translate("TrayIcon", "netctl status");
QString message = mainWindow->getInformation();
showMessage(title, message, QSystemTrayIcon::Information);
}
else
return showInformationInWindow();
return 0;
}
int TrayIcon::showInformationInWindow()
{
if (debug) qDebug() << "[TrayIcon]" << "[showInformationInWindow]";
QString title = QApplication::translate("TrayIcon", "netctl status"); QString title = QApplication::translate("TrayIcon", "netctl status");
QString message = mainWindow->getInformation(); QString message = mainWindow->getInformation();
if (supportsMessages()) return QMessageBox::information(0, title, message);
showMessage(title, message, QSystemTrayIcon::Information);
else
QMessageBox::information(0, title, message);
} }
@ -85,6 +97,7 @@ void TrayIcon::init()
menu->addAction(exit); menu->addAction(exit);
setContextMenu(menu); setContextMenu(menu);
connect(this, SIGNAL(messageClicked()), this, SLOT(showInformationInWindow()));
connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(itemActivated(QSystemTrayIcon::ActivationReason))); this, SLOT(itemActivated(QSystemTrayIcon::ActivationReason)));
} }

View File

@ -35,7 +35,8 @@ public:
~TrayIcon(); ~TrayIcon();
public slots: public slots:
void showInformation(); int showInformation();
int showInformationInWindow();
private slots: private slots:
void itemActivated(const QSystemTrayIcon::ActivationReason reason); void itemActivated(const QSystemTrayIcon::ActivationReason reason);

View File

@ -465,6 +465,11 @@ void Netctl::createActions()
connect(contextMenu[QString("enable")], SIGNAL(triggered(bool)), this, SLOT(enableProfileSlot())); connect(contextMenu[QString("enable")], SIGNAL(triggered(bool)), this, SLOT(enableProfileSlot()));
menuActions.append(contextMenu[QString("enable")]); menuActions.append(contextMenu[QString("enable")]);
contextMenu[QString("gui")] = new QAction(i18n("Show netctl-gui"), this);
contextMenu[QString("gui")]->setIcon(QIcon(":icon"));
connect(contextMenu[QString("gui")], SIGNAL(triggered(bool)), this, SLOT(showGui()));
menuActions.append(contextMenu[QString("gui")]);
contextMenu[QString("wifi")] = new QAction(i18n("Show WiFi menu"), this); contextMenu[QString("wifi")] = new QAction(i18n("Show WiFi menu"), this);
contextMenu[QString("wifi")]->setIcon(QIcon(":wifi")); contextMenu[QString("wifi")]->setIcon(QIcon(":wifi"));
connect(contextMenu[QString("wifi")], SIGNAL(triggered(bool)), this, SLOT(showWifi())); connect(contextMenu[QString("wifi")], SIGNAL(triggered(bool)), this, SLOT(showWifi()));

View File

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