From 447bcf8a0e62813267052fa8bf73ce2d142efdb5 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 6 Aug 2014 19:01:03 +0400 Subject: [PATCH] add dbus interface proto --- CHANGELOG | 1 + sources/gui/src/CMakeLists.txt | 10 +++--- sources/gui/src/main.cpp | 18 ++++++++++ sources/gui/src/mainwindow.cpp | 16 +++++++++ sources/gui/src/mainwindow.h | 1 + sources/gui/src/netctlguiadaptor.cpp | 53 ++++++++++++++++++++++++++++ sources/gui/src/netctlguiadaptor.h | 46 ++++++++++++++++++++++++ sources/gui/src/trayicon.h | 1 + sources/netctlgui/src/CMakeLists.txt | 2 +- sources/version.h.in | 4 +++ 10 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 sources/gui/src/netctlguiadaptor.cpp create mode 100644 sources/gui/src/netctlguiadaptor.h diff --git a/CHANGELOG b/CHANGELOG index 0a77465..200379d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ Ver.1.3.0 * gui: + add 3rd party license information + add system tray icon + + add dbus interface org.netctlgui.netctlgui * update to library changes * rewrite tables to use toolTip * library: diff --git a/sources/gui/src/CMakeLists.txt b/sources/gui/src/CMakeLists.txt index 7647b1c..27d1e48 100644 --- a/sources/gui/src/CMakeLists.txt +++ b/sources/gui/src/CMakeLists.txt @@ -16,13 +16,15 @@ link_directories (${PROJECT_LIBRARY}/src/lib) if (USE_QT5) find_package(Qt5Core REQUIRED) + find_package(Qt5DBus REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5LinguistTools REQUIRED) add_definitions(${Qt5Core_DEFINITIONS}) + add_definitions(${Qt5DBus_DEFINITIONS}) add_definitions(${Qt5Widgets_DEFINITIONS}) add_definitions(${Qt5LinguistTools_DEFINITIONS}) - include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) - set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5Widgets_LIBRARIES}) + include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) + set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Widgets_LIBRARIES}) qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) qt5_wrap_ui (UI_HEADERS ${FORMS}) qt5_add_resources (QRC_SOURCES ${RESOURCES}) @@ -37,9 +39,9 @@ if (USE_QT5) add_custom_target (translations COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} ${UI_HEADERS} -ts ${TRANSLATIONS}) add_custom_command (TARGET translations COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TRANSLATIONS}) else () - find_package (Qt4 REQUIRED) + find_package (Qt4 COMPONENTS QtCore QtDBus QtGui REQUIRED) include (${QT_USE_FILE}) - set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) + set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTGUI_LIBRARY}) qt4_wrap_cpp (MOC_SOURCES ${HEADERS}) qt4_wrap_ui (UI_HEADERS ${FORMS}) qt4_add_resources (QRC_SOURCES ${RESOURCES}) diff --git a/sources/gui/src/main.cpp b/sources/gui/src/main.cpp index 3627314..796a6ca 100644 --- a/sources/gui/src/main.cpp +++ b/sources/gui/src/main.cpp @@ -18,6 +18,8 @@ #include +#include +#include #include #include #include @@ -30,6 +32,19 @@ using namespace std; +bool restoreExistSession() +{ + QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusMessage request = QDBusMessage::createMethodCall(DBUS_SERVICE, + DBUS_OBJECT_PATH, + DBUS_INTERFACE, + QString("RestoreWindow")); + QDBusMessage response = bus.call(request); + QList arguments = response.arguments(); + return ((arguments.size()==1) && arguments[0].toBool()); +} + + QChar isParametrEnable(const bool parametr) { if (parametr) @@ -41,6 +56,9 @@ QChar isParametrEnable(const bool parametr) int main(int argc, char *argv[]) { + if (restoreExistSession()) + return 0; + QApplication a(argc, argv); // config path diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index bc736e1..13eb75c 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -18,6 +18,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include #include #include #include @@ -36,6 +37,7 @@ #include "macvlanwidget.h" #include "mobilewidget.h" #include "netctlautowindow.h" +#include "netctlguiadaptor.h" #include "passwdwidget.h" #include "pppoewidget.h" #include "settingswindow.h" @@ -87,6 +89,7 @@ MainWindow::MainWindow(QWidget *parent, configuration[optionsDict.keys()[i]] = optionsDict[optionsDict.keys()[i]]; // backend + createDBusSession(); netctlCommand = new Netctl(debug, configuration); netctlProfile = new NetctlProfile(debug, configuration); wpaCommand = new WpaSup(debug, configuration); @@ -346,6 +349,19 @@ void MainWindow::createActions() } +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"; +} + + void MainWindow::keyPressEvent(QKeyEvent *pressedKey) { if (debug) qDebug() << "[MainWindow]" << "[keyPressEvent]"; diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index 070d2f7..7fdcece 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -142,6 +142,7 @@ private: bool checkExternalApps(const QString apps); QString checkStatus(const bool statusBool, const bool nullFalse = false); void createActions(); + void createDBusSession(); void keyPressEvent(QKeyEvent *pressedKey); void setIconsToTabs(); bool debug; diff --git a/sources/gui/src/netctlguiadaptor.cpp b/sources/gui/src/netctlguiadaptor.cpp new file mode 100644 index 0000000..a5d2f2d --- /dev/null +++ b/sources/gui/src/netctlguiadaptor.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** + * 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 "mainwindow.h" +#include "netctlguiadaptor.h" + + +NetctlGuiAdaptor::NetctlGuiAdaptor(MainWindow *parent, const bool debugCmd) + : QDBusAbstractAdaptor(parent), + debug(debugCmd), + mainWindow(parent) +{ +} + + +NetctlGuiAdaptor::~NetctlGuiAdaptor() +{ + if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[~NetctlGuiAdaptor]"; +} + + +QString NetctlGuiAdaptor::Information() +{ + if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[RestoreWindow]"; + + return mainWindow->getInformation(); +} + + +bool NetctlGuiAdaptor::RestoreWindow() +{ + if (debug) qDebug() << "[NetctlGuiAdaptor]" << "[RestoreWindow]"; + + mainWindow->show(); + return true; +} diff --git a/sources/gui/src/netctlguiadaptor.h b/sources/gui/src/netctlguiadaptor.h new file mode 100644 index 0000000..32fb9a7 --- /dev/null +++ b/sources/gui/src/netctlguiadaptor.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * 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 NETCTLGUIADAPTOR_H +#define NETCTLGUIADAPTOR_H + +#include + + +class MainWindow; + +class NetctlGuiAdaptor : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.netctlgui.netctlgui") + +public: + explicit NetctlGuiAdaptor(MainWindow *parent = 0, + const bool debugCmd = false); + ~NetctlGuiAdaptor(); + +public slots: + QString Information(); + bool RestoreWindow(); + +private: + bool debug; + MainWindow *mainWindow; +}; + + +#endif /* NETCTLGUIADAPTOR_H */ diff --git a/sources/gui/src/trayicon.h b/sources/gui/src/trayicon.h index 9982f68..3273eeb 100644 --- a/sources/gui/src/trayicon.h +++ b/sources/gui/src/trayicon.h @@ -28,6 +28,7 @@ class MainWindow; class TrayIcon : public QSystemTrayIcon { Q_OBJECT + public: explicit TrayIcon(QObject *parent = 0, const bool debugCmd = false); diff --git a/sources/netctlgui/src/CMakeLists.txt b/sources/netctlgui/src/CMakeLists.txt index 3f947ae..efc136b 100644 --- a/sources/netctlgui/src/CMakeLists.txt +++ b/sources/netctlgui/src/CMakeLists.txt @@ -16,7 +16,7 @@ if (USE_QT5) set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES}) qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) else () - find_package (Qt4 REQUIRED) + find_package (Qt4 COMPONENTS QtCore REQUIRED) include (${QT_USE_FILE}) set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY}) qt4_wrap_cpp (MOC_SOURCES ${HEADERS}) diff --git a/sources/version.h.in b/sources/version.h.in index f05caf9..c9e7c2d 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -27,4 +27,8 @@ #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" + #endif /* VERSION_H */