mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-07 11:05:45 +00:00
add helper proto
This commit is contained in:
12
sources/helper/CMakeLists.txt
Normal file
12
sources/helper/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
# set project name
|
||||
set (SUBPROJECT netctlgui-helper)
|
||||
message (STATUS "Subproject ${SUBPROJECT}")
|
||||
|
||||
# set directories
|
||||
set (SUBPROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
# additional targets
|
||||
set (TARGETS "")
|
||||
set (HEADERS "")
|
||||
|
||||
add_subdirectory (${SUBPROJECT_SOURCE_DIR})
|
32
sources/helper/src/CMakeLists.txt
Normal file
32
sources/helper/src/CMakeLists.txt
Normal file
@ -0,0 +1,32 @@
|
||||
# set files
|
||||
file (GLOB SOURCES *.cpp)
|
||||
file (GLOB HEADERS *.h)
|
||||
|
||||
# include_path
|
||||
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/include/
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
link_directories (${PROJECT_LIBRARY}/src/lib)
|
||||
|
||||
if (USE_QT5)
|
||||
find_package(Qt5Core REQUIRED)
|
||||
find_package(Qt5DBus REQUIRED)
|
||||
add_definitions(${Qt5Core_DEFINITIONS})
|
||||
add_definitions(${Qt5DBus_DEFINITIONS})
|
||||
include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS})
|
||||
set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES})
|
||||
qt5_wrap_cpp (MOC_SOURCES ${HEADERS})
|
||||
else ()
|
||||
find_package (Qt4 COMPONENTS QtCore QtDBus REQUIRED)
|
||||
include (${QT_USE_FILE})
|
||||
set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY})
|
||||
qt4_wrap_cpp (MOC_SOURCES ${HEADERS})
|
||||
endif()
|
||||
|
||||
add_executable (${SUBPROJECT} ${SOURCES} ${HEADERS} ${MOC_SOURCES})
|
||||
target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS})
|
||||
# install properties
|
||||
install (TARGETS ${SUBPROJECT} DESTINATION bin
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE SETUID)
|
125
sources/helper/src/controladaptor.cpp
Normal file
125
sources/helper/src/controladaptor.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
/***************************************************************************
|
||||
* 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 "netctlhelper.h"
|
||||
#include "controladaptor.h"
|
||||
|
||||
|
||||
ControlAdaptor::ControlAdaptor(NetctlHelper *parent, const QMap<QString, QString> configuration)
|
||||
: QDBusAbstractAdaptor(parent),
|
||||
helper(parent)
|
||||
|
||||
{
|
||||
netctlCommand = new Netctl(false, configuration);
|
||||
netctlProfile = new NetctlProfile(false, configuration);
|
||||
}
|
||||
|
||||
|
||||
ControlAdaptor::~ControlAdaptor()
|
||||
{
|
||||
delete netctlCommand;
|
||||
delete netctlProfile;
|
||||
}
|
||||
|
||||
|
||||
// helper
|
||||
bool ControlAdaptor::Active()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::Close()
|
||||
{
|
||||
helper->quitHelper();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// netctlCommand
|
||||
bool ControlAdaptor::autoDisableAll()
|
||||
{
|
||||
return netctlCommand->autoDisableAllProfiles();
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::autoEnable(const QString profile)
|
||||
{
|
||||
return netctlCommand->autoEnableProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::autoEnableAll()
|
||||
{
|
||||
return netctlCommand->autoEnableAllProfiles();
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::autoStart(const QString profile)
|
||||
{
|
||||
return netctlCommand->autoStartProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::autoServiceEnable()
|
||||
{
|
||||
return netctlCommand->autoEnableService();
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::autoServiceRestart()
|
||||
{
|
||||
return netctlCommand->autoRestartService();
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::autoServiceStart()
|
||||
{
|
||||
return netctlCommand->autoStartService();
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::Enable(const QString profile)
|
||||
{
|
||||
return netctlCommand->enableProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::Restart(const QString profile)
|
||||
{
|
||||
return netctlCommand->restartProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::Start(const QString profile)
|
||||
{
|
||||
return netctlCommand->startProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::SwitchTo(const QString profile)
|
||||
{
|
||||
return netctlCommand->switchToProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
// netctlProfile
|
||||
bool ControlAdaptor::Remove(const QString profile)
|
||||
{
|
||||
return netctlProfile->removeProfile(profile);
|
||||
}
|
64
sources/helper/src/controladaptor.h
Normal file
64
sources/helper/src/controladaptor.h
Normal file
@ -0,0 +1,64 @@
|
||||
/***************************************************************************
|
||||
* 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 CONTROLADAPTOR_H
|
||||
#define CONTROLADAPTOR_H
|
||||
|
||||
#include <QDBusAbstractAdaptor>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
|
||||
class NetctlHelper;
|
||||
|
||||
class ControlAdaptor : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.netctlgui.helper")
|
||||
|
||||
public:
|
||||
explicit ControlAdaptor(NetctlHelper *parent = 0,
|
||||
const QMap<QString, QString> configuration = QMap<QString, QString>());
|
||||
~ControlAdaptor();
|
||||
|
||||
public slots:
|
||||
// helper
|
||||
bool Active();
|
||||
bool Close();
|
||||
// netctlCommand
|
||||
bool autoDisableAll();
|
||||
bool autoEnable(const QString profile);
|
||||
bool autoEnableAll();
|
||||
bool autoStart(const QString profile);
|
||||
bool autoServiceEnable();
|
||||
bool autoServiceRestart();
|
||||
bool autoServiceStart();
|
||||
bool Enable(const QString profile);
|
||||
bool Restart(const QString profile);
|
||||
bool Start(const QString profile);
|
||||
bool SwitchTo(const QString profile);
|
||||
// netctlProfile
|
||||
bool Remove(const QString profile);
|
||||
|
||||
private:
|
||||
NetctlHelper *helper;
|
||||
Netctl *netctlCommand;
|
||||
NetctlProfile *netctlProfile;
|
||||
};
|
||||
|
||||
|
||||
#endif /* CONTROLADAPTOR_H */
|
121
sources/helper/src/main.cpp
Normal file
121
sources/helper/src/main.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/***************************************************************************
|
||||
* 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 <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDir>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "messages.h"
|
||||
#include "netctlhelper.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
bool checkExistSession()
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
QDBusMessage request = QDBusMessage::createMethodCall(QString(DBUS_HELPER_SERVICE),
|
||||
QString(DBUS_CONTROL_PATH),
|
||||
QString(DBUS_HELPER_INTERFACE),
|
||||
QString("Active"));
|
||||
QDBusMessage response = bus.call(request);
|
||||
QList<QVariant> arguments = response.arguments();
|
||||
return ((arguments.size() == 1) && arguments[0].toBool());
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// detach from console
|
||||
bool isDaemon = true;
|
||||
for (int i=0; i<argc; i++)
|
||||
if (QString(argv[i]) == QString("--nodaemon")) {
|
||||
isDaemon = false;
|
||||
break;
|
||||
}
|
||||
if (isDaemon)
|
||||
daemon(0, 0);
|
||||
#if QT_VERSION >= 0x050000
|
||||
QCoreApplication::setSetuidAllowed(true);
|
||||
#endif
|
||||
QCoreApplication a(argc, argv);
|
||||
// check if exists
|
||||
if (checkExistSession())
|
||||
return 0;
|
||||
|
||||
QMap<QString, QVariant> args = getArgs();
|
||||
// reading
|
||||
for (int i=1; i<argc; i++) {
|
||||
// config path
|
||||
if ((QString(argv[i]) == QString("-c")) || (QString(argv[i]) == QString("--config"))) {
|
||||
args[QString("config")] = QDir().absoluteFilePath(argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
// debug
|
||||
else if ((QString(argv[i]) == QString("-d")) || (QString(argv[i]) == QString("--debug"))) {
|
||||
args[QString("debug")] = true;
|
||||
}
|
||||
// daemonized
|
||||
else if (QString(argv[i]) == QString("--nodaemon")) {
|
||||
args[QString("nodaemon")] = true;
|
||||
}
|
||||
// messages
|
||||
// help message
|
||||
else if ((QString(argv[i]) == QString("-h")) || (QString(argv[i]) == QString("--help"))) {
|
||||
args[QString("help")] = true;
|
||||
}
|
||||
// info message
|
||||
else if ((QString(argv[i]) == QString("-i")) || (QString(argv[i]) == QString("--info"))) {
|
||||
args[QString("info")] = true;
|
||||
}
|
||||
// version message
|
||||
else if ((QString(argv[i]) == QString("-v")) || (QString(argv[i]) == QString("--version"))) {
|
||||
args[QString("version")] = true;
|
||||
}
|
||||
else {
|
||||
args[QString("error")] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// running
|
||||
if (args[QString("error")].toBool()) {
|
||||
cout << errorMessage().toUtf8().data() << endl;
|
||||
cout << helpMessage().toUtf8().data();
|
||||
return 127;
|
||||
}
|
||||
if (args[QString("help")].toBool()) {
|
||||
cout << helpMessage().toUtf8().data();
|
||||
return 0;
|
||||
}
|
||||
if (args[QString("info")].toBool()) {
|
||||
cout << versionMessage().toUtf8().data() << endl;
|
||||
cout << infoMessage().toUtf8().data();
|
||||
return 0;
|
||||
}
|
||||
if (args[QString("version")].toBool()) {
|
||||
cout << versionMessage().toUtf8().data();
|
||||
return 0;
|
||||
}
|
||||
NetctlHelper w(0, args);
|
||||
return a.exec();
|
||||
}
|
116
sources/helper/src/messages.cpp
Normal file
116
sources/helper/src/messages.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
/***************************************************************************
|
||||
* 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 <QCoreApplication>
|
||||
#include <QDir>
|
||||
|
||||
#include "messages.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
QString errorMessage()
|
||||
{
|
||||
QString errorMessage = QCoreApplication::translate("NetctlHelper", "Unknown flag\n");
|
||||
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> getArgs()
|
||||
{
|
||||
QMap<QString, QVariant> args;
|
||||
args[QString("config")] = QString(QDir::homePath() + QString("/.config/netctl-gui.conf"));
|
||||
args[QString("debug")] = false;
|
||||
args[QString("nodaemon")] = false;
|
||||
args[QString("help")] = false;
|
||||
args[QString("info")] = false;
|
||||
args[QString("version")] = false;
|
||||
args[QString("error")] = false;
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
QString helpMessage()
|
||||
{
|
||||
QString helpMessage = QString("");
|
||||
helpMessage += QString("%1\n").arg(QCoreApplication::translate("NetctlHelper", "Usage:"));
|
||||
helpMessage += QString("netctlgui-helper [ options ]\n");
|
||||
helpMessage += QString("%1\n").arg(QCoreApplication::translate("NetctlHelper", "Options:"));
|
||||
// windows
|
||||
helpMessage += QString(" -c, --config <arg> - %1\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "read configuration from this file"));
|
||||
helpMessage += QString(" -d, --debug - %1\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "print debug information"));
|
||||
helpMessage += QString(" --nodaemon - %1\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "do not start as daemon"));
|
||||
helpMessage += QString(" %1\n").arg(QCoreApplication::translate("NetctlHelper", "Show messages:"));
|
||||
helpMessage += QString(" -v, --version - %1\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "show version and exit"));
|
||||
helpMessage += QString(" -i, --info - %1\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "show build information and exit"));
|
||||
helpMessage += QString(" -h, --help - %1\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "show this help and exit"));
|
||||
|
||||
return helpMessage;
|
||||
}
|
||||
|
||||
|
||||
QString infoMessage()
|
||||
{
|
||||
QString infoMessage = QString("");
|
||||
// build information
|
||||
infoMessage += QCoreApplication::translate("NetctlHelper", "Build date: %1").
|
||||
arg(QString(BUILD_DATE));
|
||||
infoMessage += QString("\n%1:\n").arg(QCoreApplication::translate("NetctlHelper", "cmake flags"));
|
||||
infoMessage += QString("\t-DCMAKE_BUILD_TYPE=%1 \\\n").arg(QString(CMAKE_BUILD_TYPE));
|
||||
infoMessage += QString("\t-DCMAKE_INSTALL_PREFIX=%1 \\\n").arg(QString(CMAKE_INSTALL_PREFIX));
|
||||
infoMessage += QString("\t-DBUILD_DOCS=%1 \\\n").arg(QString(PROJECT_BUILD_DOCS));
|
||||
infoMessage += QString("\t-DBUILD_LIBRARY=%1 \\\n").arg(QString(PROJECT_BUILD_LIBRARY));
|
||||
infoMessage += QString("\t-DBUILD_GUI=%1 \\\n").arg(QString(PROJECT_BUILD_GUI));
|
||||
infoMessage += QString("\t-DUSE_QT5=%1 \\\n").arg(QString(PROJECT_USE_QT5));
|
||||
infoMessage += QString("\t-DBUILD_DATAENGINE=%1 \\\n").arg(QString(PROJECT_BUILD_DATAENGINE));
|
||||
infoMessage += QString("\t-DBUILD_PLASMOID=%1\n").arg(QString(PROJECT_BUILD_PLASMOID));
|
||||
// transport information
|
||||
infoMessage += QString("%1:\n").arg(QCoreApplication::translate("NetctlHelper", "DBus configuration"));
|
||||
infoMessage += QString("\tDBUS_SERVICE=%1\n").arg(QString(DBUS_SERVICE));
|
||||
infoMessage += QString("\tDBUS_INTERFACE=%1\n").arg(QString(DBUS_INTERFACE));
|
||||
infoMessage += QString("\tDBUS_CONTROL_PATH=%1\n").arg(QString(DBUS_CONTROL_PATH));
|
||||
infoMessage += QString("\tDBUS_LIB_PATH=%1\n").arg(QString(DBUS_LIB_PATH));
|
||||
infoMessage += QString("\tDBUS_OBJECT_PATH=%1\n").arg(QString(DBUS_OBJECT_PATH));
|
||||
|
||||
return infoMessage;
|
||||
}
|
||||
|
||||
|
||||
QString versionMessage()
|
||||
{
|
||||
QString versionMessage = QString("");
|
||||
versionMessage += QString("%1\n").arg(QString(NAME));
|
||||
versionMessage += QString("%1 : %2\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "Version"))
|
||||
.arg(QString(VERSION));
|
||||
versionMessage += QString("%1 : %2\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "Author"))
|
||||
.arg(QString(AUTHOR));
|
||||
versionMessage += QString("%1 : %2\n")
|
||||
.arg(QCoreApplication::translate("NetctlHelper", "License"))
|
||||
.arg(QString(LICENSE));
|
||||
|
||||
return versionMessage;
|
||||
}
|
34
sources/helper/src/messages.h
Normal file
34
sources/helper/src/messages.h
Normal file
@ -0,0 +1,34 @@
|
||||
/***************************************************************************
|
||||
* 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 MESSAGES_H
|
||||
#define MESSAGES_H
|
||||
|
||||
#include <QChar>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
QString errorMessage();
|
||||
QMap<QString, QVariant> getArgs();
|
||||
QString helpMessage();
|
||||
QString infoMessage();
|
||||
QString versionMessage();
|
||||
|
||||
|
||||
#endif /* MESSAGES_H */
|
154
sources/helper/src/netctladaptor.cpp
Normal file
154
sources/helper/src/netctladaptor.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
/***************************************************************************
|
||||
* 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 "netctladaptor.h"
|
||||
|
||||
|
||||
NetctlAdaptor::NetctlAdaptor(QObject *parent, const QMap<QString, QString> configuration)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
netctlCommand = new Netctl(false, configuration);
|
||||
netctlProfile = new NetctlProfile(false, configuration);
|
||||
wpaCommand = new WpaSup(false, configuration);
|
||||
}
|
||||
|
||||
|
||||
NetctlAdaptor::~NetctlAdaptor()
|
||||
{
|
||||
delete netctlCommand;
|
||||
delete netctlProfile;
|
||||
delete wpaCommand;
|
||||
}
|
||||
|
||||
|
||||
// netctlCommand
|
||||
QString NetctlAdaptor::ActiveProfile()
|
||||
{
|
||||
if (netctlCommand->isNetctlAutoRunning())
|
||||
return netctlCommand->autoGetActiveProfile();
|
||||
else
|
||||
return netctlCommand->getActiveProfile();
|
||||
}
|
||||
|
||||
|
||||
QString NetctlAdaptor::ActiveProfileStatus()
|
||||
{
|
||||
if (netctlCommand->isNetctlAutoRunning())
|
||||
return QString("netctl-auto");
|
||||
else
|
||||
return netctlCommand->getProfileStatus(ActiveProfile());
|
||||
}
|
||||
|
||||
|
||||
bool NetctlAdaptor::autoIsProfileActive(const QString profile)
|
||||
{
|
||||
return netctlCommand->autoIsProfileActive(profile);
|
||||
}
|
||||
|
||||
|
||||
bool NetctlAdaptor::autoIsProfileEnabled(const QString profile)
|
||||
{
|
||||
return netctlCommand->autoIsProfileEnabled(profile);
|
||||
}
|
||||
|
||||
|
||||
QStringList NetctlAdaptor::Information()
|
||||
{
|
||||
QStringList output;
|
||||
output.append(QString("Profile: %1").arg(ActiveProfile()));
|
||||
output.append(QString("Status: %1").arg(ActiveProfileStatus()));
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
bool NetctlAdaptor::isProfileActive(const QString profile)
|
||||
{
|
||||
return netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
|
||||
|
||||
bool NetctlAdaptor::isProfileEnabled(const QString profile)
|
||||
{
|
||||
return netctlCommand->isProfileEnabled(profile);
|
||||
}
|
||||
|
||||
|
||||
QStringList NetctlAdaptor::ProfileList()
|
||||
{
|
||||
QList<netctlProfileInfo> profilesInfo;
|
||||
if (netctlCommand->isNetctlAutoRunning())
|
||||
profilesInfo = netctlCommand->getProfileListFromNetctlAuto();
|
||||
else
|
||||
profilesInfo = netctlCommand->getProfileList();
|
||||
QStringList info;
|
||||
for (int i=0; i<profilesInfo.count(); i++) {
|
||||
QStringList profileInfo;
|
||||
profileInfo.append(profilesInfo[i].name);
|
||||
profileInfo.append(profilesInfo[i].description);
|
||||
profileInfo.append(QString::number(profilesInfo[i].active));
|
||||
profileInfo.append(QString::number(profilesInfo[i].enabled));
|
||||
info.append(profileInfo.join(QChar('|')));
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
// netctlProfile
|
||||
QStringList NetctlAdaptor::Profile(const QString profile)
|
||||
{
|
||||
QMap<QString, QString> settings = netctlProfile->getSettingsFromProfile(profile);
|
||||
QStringList settingsList;
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
settingsList.append(settings.keys()[i] + QString("=") +
|
||||
settings[settings.keys()[i]]);
|
||||
|
||||
return settingsList;
|
||||
}
|
||||
|
||||
|
||||
QString NetctlAdaptor::ProfileValue(const QString profile, const QString key)
|
||||
{
|
||||
return netctlProfile->getValueFromProfile(profile, key);
|
||||
}
|
||||
|
||||
|
||||
// wpaCommand
|
||||
QString NetctlAdaptor::ProfileByEssid(const QString essid)
|
||||
{
|
||||
return wpaCommand->existentProfile(essid);
|
||||
}
|
||||
|
||||
|
||||
QStringList NetctlAdaptor::WiFi()
|
||||
{
|
||||
QList<netctlWifiInfo> wifiPoints = wpaCommand->scanWifi();
|
||||
QStringList info;
|
||||
for (int i=0; i<wifiPoints.count(); i++) {
|
||||
QStringList point;
|
||||
point.append(wifiPoints[i].name);
|
||||
point.append(wifiPoints[i].security);
|
||||
point.append(wifiPoints[i].signal);
|
||||
point.append(QString::number(wifiPoints[i].active));
|
||||
point.append(QString::number(wifiPoints[i].exists));
|
||||
info.append(point.join(QChar('|')));
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
61
sources/helper/src/netctladaptor.h
Normal file
61
sources/helper/src/netctladaptor.h
Normal file
@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* 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>
|
||||
#include <QStringList>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
|
||||
class NetctlAdaptor : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.netctlgui.helper")
|
||||
|
||||
public:
|
||||
explicit NetctlAdaptor(QObject *parent = 0,
|
||||
const QMap<QString, QString> configuration = QMap<QString, QString>());
|
||||
~NetctlAdaptor();
|
||||
|
||||
public slots:
|
||||
// netctlCommand
|
||||
QString ActiveProfile();
|
||||
QString ActiveProfileStatus();
|
||||
bool autoIsProfileActive(const QString profile);
|
||||
bool autoIsProfileEnabled(const QString profile);
|
||||
QStringList Information();
|
||||
bool isProfileActive(const QString profile);
|
||||
bool isProfileEnabled(const QString profile);
|
||||
QStringList ProfileList();
|
||||
// netctlProfile
|
||||
QStringList Profile(const QString profile);
|
||||
QString ProfileValue(const QString profile, const QString key);
|
||||
// wpaCommand
|
||||
QString ProfileByEssid(const QString essid);
|
||||
QStringList WiFi();
|
||||
|
||||
private:
|
||||
Netctl *netctlCommand;
|
||||
NetctlProfile *netctlProfile;
|
||||
WpaSup *wpaCommand;
|
||||
};
|
||||
|
||||
|
||||
#endif /* NETCTLADAPTOR_H */
|
152
sources/helper/src/netctlhelper.cpp
Normal file
152
sources/helper/src/netctlhelper.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
/***************************************************************************
|
||||
* 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 <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDebug>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
#include "controladaptor.h"
|
||||
#include "netctladaptor.h"
|
||||
#include "netctlhelper.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
NetctlHelper::NetctlHelper(QObject *parent, QMap<QString, QVariant> args)
|
||||
: QObject(parent),
|
||||
configPath(args[QString("config")].toString()),
|
||||
debug(args[QString("debug")].toBool())
|
||||
{
|
||||
updateConfiguration();
|
||||
}
|
||||
|
||||
|
||||
NetctlHelper::~NetctlHelper()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[~NetctlHelper]";
|
||||
|
||||
deleteInterface();
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString> NetctlHelper::getDefault()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[getDefault]";
|
||||
|
||||
QMap<QString, QString> settings;
|
||||
settings[QString("CLOSETOTRAY")] = QString("true");
|
||||
settings[QString("CTRL_DIR")] = QString("/run/wpa_supplicant_netctl-gui");
|
||||
settings[QString("CTRL_GROUP")] = QString("users");
|
||||
settings[QString("IFACE_DIR")] = QString("/sys/class/net/");
|
||||
settings[QString("LANGUAGE")] = QString("en");
|
||||
settings[QString("NETCTL_PATH")] = QString("/usr/bin/netctl");
|
||||
settings[QString("NETCTLAUTO_PATH")] = QString("/usr/bin/netctl-auto");
|
||||
settings[QString("NETCTLAUTO_SERVICE")] = QString("netctl-auto");
|
||||
settings[QString("PID_FILE")] = QString("/run/wpa_supplicant_netctl-gui.pid");
|
||||
settings[QString("PREFERED_IFACE")] = QString("");
|
||||
settings[QString("PROFILE_DIR")] = QString("/etc/netctl/");
|
||||
settings[QString("RFKILL_DIR")] = QString("/sys/class/rfkill/");
|
||||
settings[QString("STARTTOTRAY")] = QString("false");
|
||||
settings[QString("SUDO_PATH")] = QString("/usr/bin/kdesu");
|
||||
settings[QString("SYSTEMCTL_PATH")] = QString("/usr/bin/systemctl");
|
||||
settings[QString("SYSTRAY")] = QString("true");
|
||||
settings[QString("WPACLI_PATH")] = QString("/usr/bin/wpa_cli");
|
||||
settings[QString("WPASUP_PATH")] = QString("/usr/bin/wpa_supplicant");
|
||||
settings[QString("WPA_DRIVERS")] = QString("nl80211,wext");
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[getDefault]" << ":" <<
|
||||
settings.keys()[i] + QString("=") + settings[settings.keys()[i]];
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString> NetctlHelper::getSettings()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[getSettings]";
|
||||
|
||||
QMap<QString, QString> settings = getDefault();
|
||||
QFile configFile(configPath);
|
||||
QString fileStr;
|
||||
if (!configFile.open(QIODevice::ReadOnly))
|
||||
return settings;
|
||||
while (true) {
|
||||
fileStr = QString(configFile.readLine()).trimmed();
|
||||
if ((fileStr.isEmpty()) && (!configFile.atEnd())) continue;
|
||||
if ((fileStr[0] == QChar('#')) && (!configFile.atEnd())) continue;
|
||||
if ((fileStr[0] == QChar(';')) && (!configFile.atEnd())) continue;
|
||||
if (fileStr.contains(QChar('=')))
|
||||
settings[fileStr.split(QChar('='))[0]] = fileStr.split(QChar('='))[1];
|
||||
if (configFile.atEnd()) break;
|
||||
}
|
||||
configFile.close();
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[getSettings]" << ":" <<
|
||||
settings.keys()[i] + QString("=") + settings[settings.keys()[i]];
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
void NetctlHelper::quitHelper()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[quitHelper]";
|
||||
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
|
||||
void NetctlHelper::createInterface()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[createInterface]";
|
||||
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
if (!bus.registerService(QString(DBUS_HELPER_SERVICE)))
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[createInterface]" << ":" << "Could not register service";
|
||||
if (!bus.registerObject(QString(DBUS_LIB_PATH),
|
||||
new NetctlAdaptor(this, configuration),
|
||||
QDBusConnection::ExportAllContents))
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[createInterface]" << ":" << "Could not register library object";
|
||||
if (!bus.registerObject(QString(DBUS_CONTROL_PATH),
|
||||
new ControlAdaptor(this, configuration),
|
||||
QDBusConnection::ExportAllContents))
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[createInterface]" << ":" << "Could not register control object";
|
||||
}
|
||||
|
||||
|
||||
void NetctlHelper::deleteInterface()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[deleteInterface]";
|
||||
|
||||
QDBusConnection::sessionBus().unregisterObject(QString(DBUS_LIB_PATH));
|
||||
QDBusConnection::sessionBus().unregisterObject(QString(DBUS_CONTROL_PATH));
|
||||
QDBusConnection::sessionBus().unregisterService(QString(DBUS_HELPER_SERVICE));
|
||||
}
|
||||
|
||||
|
||||
void NetctlHelper::updateConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[updateConfiguration]";
|
||||
|
||||
deleteInterface();
|
||||
|
||||
configuration = getSettings();
|
||||
|
||||
createInterface();
|
||||
}
|
50
sources/helper/src/netctlhelper.h
Normal file
50
sources/helper/src/netctlhelper.h
Normal 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 NETCTLHELPER_H
|
||||
#define NETCTLHELPER_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class NetctlHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NetctlHelper(QObject *parent = 0,
|
||||
QMap<QString, QVariant> args = QMap<QString, QVariant>());
|
||||
~NetctlHelper();
|
||||
|
||||
public slots:
|
||||
QMap<QString, QString> getDefault();
|
||||
QMap<QString, QString> getSettings();
|
||||
void quitHelper();
|
||||
|
||||
private:
|
||||
QString configPath;
|
||||
QMap<QString, QString> configuration;
|
||||
bool debug;
|
||||
void createInterface();
|
||||
void deleteInterface();
|
||||
void updateConfiguration();
|
||||
};
|
||||
|
||||
|
||||
#endif /* NETCTLHELPER_H */
|
Reference in New Issue
Block a user