diff --git a/sources/gui/src/main.cpp b/sources/gui/src/main.cpp index 796a6ca..b558aa3 100644 --- a/sources/gui/src/main.cpp +++ b/sources/gui/src/main.cpp @@ -35,13 +35,13 @@ using namespace std; bool restoreExistSession() { QDBusConnection bus = QDBusConnection::sessionBus(); - QDBusMessage request = QDBusMessage::createMethodCall(DBUS_SERVICE, - DBUS_OBJECT_PATH, - DBUS_INTERFACE, + QDBusMessage request = QDBusMessage::createMethodCall(QString(DBUS_SERVICE), + QString(DBUS_OBJECT_PATH), + QString(DBUS_INTERFACE), QString("RestoreWindow")); QDBusMessage response = bus.call(request); QList 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[]) { + QApplication a(argc, argv); + QApplication::setQuitOnLastWindowClosed(false); + + // check if exists if (restoreExistSession()) return 0; - QApplication a(argc, argv); - // config path QString configPath = QString(QDir::homePath() + QString("/.config/netctl-gui.conf")); // translation diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index 13eb75c..b16a92c 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -36,6 +36,7 @@ #include "ipwidget.h" #include "macvlanwidget.h" #include "mobilewidget.h" +#include "netctladaptor.h" #include "netctlautowindow.h" #include "netctlguiadaptor.h" #include "passwdwidget.h" @@ -186,6 +187,7 @@ MainWindow::~MainWindow() { if (debug) qDebug() << "[MainWindow]" << "[~MainWindow]"; + QDBusConnection::sessionBus().unregisterService(QString(DBUS_SERVICE)); delete netctlCommand; delete netctlProfile; delete wpaCommand; @@ -206,8 +208,8 @@ MainWindow::~MainWindow() delete errorWin; delete netctlAutoWin; delete settingsWin; - delete ui; delete trayIcon; + delete ui; } @@ -226,7 +228,7 @@ QString MainWindow::getInformation() status = netctlCommand->getProfileStatus(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; } @@ -353,12 +355,17 @@ void MainWindow::createDBusSession() { if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]"; - new NetctlGuiAdaptor(this, debug); QDBusConnection bus = QDBusConnection::sessionBus(); if (!bus.registerService(QString(DBUS_SERVICE))) if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register service"; - if (!bus.registerObject(QString(DBUS_OBJECT_PATH), this)) - if (debug) qDebug() << "[MainWindow]" << "[createDBusSession]" << ":" << "Could not register object"; + if (!bus.registerObject(QString(DBUS_OBJECT_PATH), + 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"; } diff --git a/sources/gui/src/netctladaptor.cpp b/sources/gui/src/netctladaptor.cpp new file mode 100644 index 0000000..ad5089e --- /dev/null +++ b/sources/gui/src/netctladaptor.cpp @@ -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 + +#include +#include "netctladaptor.h" + + +NetctlAdaptor::NetctlAdaptor(QObject *parent, const bool debugCmd, const QMap 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]"; +} diff --git a/sources/gui/src/netctladaptor.h b/sources/gui/src/netctladaptor.h new file mode 100644 index 0000000..2e52c4e --- /dev/null +++ b/sources/gui/src/netctladaptor.h @@ -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 + + +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 configuration = QMap()); + ~NetctlAdaptor(); + +public slots: + QString Information(); + +private: + bool debug; + Netctl *netctlCommand; + NetctlProfile *netctlProfile; + WpaSup *wpaCommand; +}; + + +#endif /* NETCTLADAPTOR_H */ diff --git a/sources/gui/src/netctlguiadaptor.cpp b/sources/gui/src/netctlguiadaptor.cpp index a5d2f2d..7b67b87 100644 --- a/sources/gui/src/netctlguiadaptor.cpp +++ b/sources/gui/src/netctlguiadaptor.cpp @@ -36,14 +36,6 @@ NetctlGuiAdaptor::~NetctlGuiAdaptor() } -QString NetctlGuiAdaptor::Information() -{ - if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[RestoreWindow]"; - - return mainWindow->getInformation(); -} - - bool NetctlGuiAdaptor::RestoreWindow() { if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[RestoreWindow]"; diff --git a/sources/gui/src/netctlguiadaptor.h b/sources/gui/src/netctlguiadaptor.h index 32fb9a7..0679d3f 100644 --- a/sources/gui/src/netctlguiadaptor.h +++ b/sources/gui/src/netctlguiadaptor.h @@ -34,7 +34,6 @@ public: ~NetctlGuiAdaptor(); public slots: - QString Information(); bool RestoreWindow(); private: diff --git a/sources/gui/src/trayicon.cpp b/sources/gui/src/trayicon.cpp index 933b43f..677d978 100644 --- a/sources/gui/src/trayicon.cpp +++ b/sources/gui/src/trayicon.cpp @@ -46,17 +46,29 @@ TrayIcon::~TrayIcon() } -void TrayIcon::showInformation() +int 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 message = mainWindow->getInformation(); - if (supportsMessages()) - showMessage(title, message, QSystemTrayIcon::Information); - else - QMessageBox::information(0, title, message); + return QMessageBox::information(0, title, message); } @@ -85,6 +97,7 @@ void TrayIcon::init() menu->addAction(exit); setContextMenu(menu); + connect(this, SIGNAL(messageClicked()), this, SLOT(showInformationInWindow())); connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(itemActivated(QSystemTrayIcon::ActivationReason))); } diff --git a/sources/gui/src/trayicon.h b/sources/gui/src/trayicon.h index 3273eeb..0c1fa9b 100644 --- a/sources/gui/src/trayicon.h +++ b/sources/gui/src/trayicon.h @@ -35,7 +35,8 @@ public: ~TrayIcon(); public slots: - void showInformation(); + int showInformation(); + int showInformationInWindow(); private slots: void itemActivated(const QSystemTrayIcon::ActivationReason reason); diff --git a/sources/plasmoid/netctl.cpp b/sources/plasmoid/netctl.cpp index 58cf1e6..2612995 100644 --- a/sources/plasmoid/netctl.cpp +++ b/sources/plasmoid/netctl.cpp @@ -465,6 +465,11 @@ void Netctl::createActions() connect(contextMenu[QString("enable")], SIGNAL(triggered(bool)), this, SLOT(enableProfileSlot())); 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")]->setIcon(QIcon(":wifi")); connect(contextMenu[QString("wifi")], SIGNAL(triggered(bool)), this, SLOT(showWifi())); diff --git a/sources/version.h.in b/sources/version.h.in index c9e7c2d..b21fc3e 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -27,8 +27,9 @@ #define PROJECT_BUILD_PLASMOID "@BUILD_PLASMOID@" #define PROJECT_USE_QT5 "@USE_QT5@" -#define DBUS_SERVICE "org.netctlgui.netctlgui" -#define DBUS_OBJECT_PATH "/" #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 */