add dbus interface proto

This commit is contained in:
arcan1s 2014-08-06 19:01:03 +04:00
parent e8a7865e99
commit 447bcf8a0e
10 changed files with 147 additions and 5 deletions

View File

@ -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:

View File

@ -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})

View File

@ -18,6 +18,8 @@
#include <QApplication>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDir>
#include <QTranslator>
#include <iostream>
@ -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<QVariant> 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

View File

@ -18,6 +18,7 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDBusConnection>
#include <QDebug>
#include <QDesktopServices>
#include <QFileDialog>
@ -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]";

View File

@ -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;

View File

@ -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 <QDebug>
#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;
}

View File

@ -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 <QDBusAbstractAdaptor>
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 */

View File

@ -28,6 +28,7 @@ class MainWindow;
class TrayIcon : public QSystemTrayIcon
{
Q_OBJECT
public:
explicit TrayIcon(QObject *parent = 0,
const bool debugCmd = false);

View File

@ -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})

View File

@ -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 */