mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
implement actions
This commit is contained in:
parent
a830fc9372
commit
924beacc23
@ -1,45 +1,7 @@
|
||||
# set project name
|
||||
set (SUBPROJECT plasma_applet_netctl)
|
||||
message (STATUS "Subproject ${SUBPROJECT}")
|
||||
# find resources
|
||||
# set (RESOURCES ${PROJECT_RESOURCE_DIR}/resources-plasmoid.qrc)
|
||||
#
|
||||
# # find required libaries
|
||||
# find_package (KDE4 REQUIRED)
|
||||
# include (KDE4Defaults)
|
||||
#
|
||||
# add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
|
||||
# include_directories (${CMAKE_SOURCE_DIR}
|
||||
# ${CMAKE_BINARY_DIR}
|
||||
# ${KDE4_INCLUDES}
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
# ${PROJECT_TRDPARTY_DIR})
|
||||
#
|
||||
# # add_subdirectory (po)
|
||||
#
|
||||
# # set sources
|
||||
# set (PLUGIN_NAME ${SUBPROJECT})
|
||||
# file (GLOB SUBPROJECT_DESKTOP_IN *.desktop)
|
||||
# file (RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN})
|
||||
# file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
||||
# file (GLOB SUBPROJECT_SOURCE *.cpp)
|
||||
# file (GLOB_RECURSE SUBPROJECT_UI *.ui ${PROJECT_TRDPARTY_DIR}/about/*.ui)
|
||||
#
|
||||
# # prepare
|
||||
# configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
|
||||
#
|
||||
# # make
|
||||
# qt4_add_resources (QRC_SOURCES ${RESOURCES})
|
||||
# kde4_add_ui_files (SUBPROJECT_SOURCE ${SUBPROJECT_UI})
|
||||
# kde4_add_plugin (${PLUGIN_NAME} ${SUBPROJECT_SOURCE} ${QRC_SOURCES})
|
||||
# target_link_libraries (${PLUGIN_NAME} ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS})
|
||||
#
|
||||
# # install
|
||||
# install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||
# install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR})
|
||||
# install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME})
|
||||
# plasma_install_package(plasmoid org.kde.plasma.netctl)
|
||||
|
||||
find_package (Qt5 REQUIRED COMPONENTS Core DBus Qml Widgets)
|
||||
find_package (ECM 0.0.12 REQUIRED NO_MODULE)
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
|
||||
@ -64,22 +26,4 @@ set (Kf5_INCLUDE ${ConfigCore_INCLUDE_DIR}
|
||||
|
||||
set (PLUGIN_NAME netctlplugin)
|
||||
add_subdirectory (plugin)
|
||||
|
||||
# set(dir plasmoid)
|
||||
# set(component org.kde.plasma.netctl)
|
||||
# set(root ${ARGV2})
|
||||
# set(type ${ARGV3})
|
||||
# if(NOT root)
|
||||
# set(root plasmoids)
|
||||
# endif()
|
||||
# if(NOT type)
|
||||
# set(type applet)
|
||||
# endif()
|
||||
# install(DIRECTORY ${dir}/ DESTINATION ${PLASMA_DATA_INSTALL_DIR}/${root}/${component}
|
||||
# PATTERN CMakeLists.txt EXCLUDE
|
||||
# PATTERN README.txt EXCLUDE
|
||||
# PATTERN Messages.sh EXCLUDE
|
||||
# PATTERN dummydata EXCLUDE)
|
||||
#
|
||||
# install(FILES ${dir}/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME plasma-${type}-${component}.desktop)
|
||||
plasma_install_package (plasmoid org.kde.plasma.netctl)
|
||||
|
@ -1,185 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DataEngineWindow</class>
|
||||
<widget class="QWidget" name="DataEngineWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>480</width>
|
||||
<height>333</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>480</width>
|
||||
<height>320</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Configuration Window</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_netctl">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_netctl">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Path to netctl</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_netctl"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_netctl">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_netctlAuto">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_netctlAuto">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Path to netctl-auto</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_netctlAuto"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_netctlAuto">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_extIp4">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_extIp4">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Check external IPv4</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_extIp4"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_extIp4">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_extIp6">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_extIp6">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Check external IPv6</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_extIp6"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_extIp6">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_dataengine">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>lineEdit_netctl</tabstop>
|
||||
<tabstop>pushButton_netctl</tabstop>
|
||||
<tabstop>checkBox_extIp4</tabstop>
|
||||
<tabstop>lineEdit_extIp4</tabstop>
|
||||
<tabstop>pushButton_extIp4</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
File diff suppressed because it is too large
Load Diff
@ -1,112 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 NETCTL_PLASMOID_H
|
||||
#define NETCTL_PLASMOID_H
|
||||
|
||||
|
||||
class Netctl : public Plasma::PopupApplet
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Netctl(QObject *parent, const QVariantList &args);
|
||||
~Netctl();
|
||||
void init();
|
||||
QString parsePattern(const QString rawLine);
|
||||
QMap<QString, QString> readDataEngineConfiguration();
|
||||
void writeDataEngineConfiguration(const QMap<QString, QString> settings);
|
||||
QMap<QString, QString> updateDataEngineConfiguration(const QMap<QString, QString> rawConfig);
|
||||
|
||||
public slots:
|
||||
// events
|
||||
void sendNotification(const QString eventId, const QString message);
|
||||
void showGui();
|
||||
void showWifi();
|
||||
// dataengine
|
||||
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
||||
// configuration interface
|
||||
void configAccepted();
|
||||
void configChanged();
|
||||
void setBigInterface();
|
||||
void setDataEngineExternalIp4();
|
||||
void setDataEngineExternalIp6();
|
||||
void setHelper();
|
||||
void setSudo();
|
||||
void setWifi();
|
||||
|
||||
private slots:
|
||||
// ui
|
||||
void updateIcon();
|
||||
void updateInterface(bool setHidden);
|
||||
// configuration interface
|
||||
void selectAbstractSomething();
|
||||
// context menu
|
||||
void enableProfileSlot();
|
||||
void restartProfileSlot();
|
||||
void startProfileSlot(QAction *profile);
|
||||
void stopProfileSlot();
|
||||
void stopAllProfilesSlot();
|
||||
void switchToProfileSlot(QAction *profile);
|
||||
// helper
|
||||
void checkHelperStatus();
|
||||
void startHelper();
|
||||
|
||||
protected:
|
||||
void createConfigurationInterface(KConfigDialog *parent);
|
||||
QList<QAction*> contextualActions();
|
||||
|
||||
private:
|
||||
// ui
|
||||
QWidget *graphicsWidget;
|
||||
QHBoxLayout *layout;
|
||||
IconLabel *iconLabel;
|
||||
QLabel *textLabel;
|
||||
// information
|
||||
bool status;
|
||||
QMap<QString, QString> info;
|
||||
QStringList profileList;
|
||||
// context menu
|
||||
void createActions();
|
||||
QList<QAction*> menuActions;
|
||||
QMenu *startProfileMenu;
|
||||
QMenu *switchToProfileMenu;
|
||||
QMap<QString, QAction*> contextMenu;
|
||||
// data engine
|
||||
Plasma::DataEngine *netctlEngine;
|
||||
void connectToEngine();
|
||||
void disconnectFromEngine();
|
||||
QList<QVariant> sendDBusRequest(const QString cmd, const QList<QVariant> args = QList<QVariant>());
|
||||
// configuration interface
|
||||
Ui::AppearanceWindow uiAppConfig;
|
||||
Ui::DataEngineWindow uiDEConfig;
|
||||
Ui::ConfigWindow uiWidConfig;
|
||||
Ui::About uiAboutConfig;
|
||||
// configuration
|
||||
int autoUpdateInterval;
|
||||
bool bigInterface;
|
||||
bool debug;
|
||||
QString textPattern;
|
||||
QStringList formatLine;
|
||||
QMap<QString, QString> paths;
|
||||
bool useHelper, useSudo, useWifi;
|
||||
};
|
||||
|
||||
K_EXPORT_PLASMA_APPLET(netctl, Netctl)
|
||||
|
||||
|
||||
#endif /* NETCTL_PLASMOID_H */
|
@ -59,12 +59,7 @@ Item {
|
||||
}
|
||||
property int interval: plasmoid.configuration.autoUpdateInterval
|
||||
property string pattern: plasmoid.configuration.textPattern
|
||||
property variant paths: {
|
||||
"netctl": plasmoid.configuration.netctlPath,
|
||||
"sudo": plasmoid.configuration.sudoPath
|
||||
}
|
||||
property bool status: false
|
||||
property bool useHelper: plasmoid.configuration.useHelper
|
||||
|
||||
// init
|
||||
Plasmoid.icon: icon.source
|
||||
@ -76,15 +71,17 @@ Item {
|
||||
interval: main.interval
|
||||
|
||||
onNewData: {
|
||||
if (data.isEmpty) return
|
||||
if (data.value == "N\\A") return
|
||||
if (sourceName == "active") {
|
||||
main.status = data.value == "true" ? true : false
|
||||
status = data.value == "true"
|
||||
icon.source = iconPath[data.value]
|
||||
} else if (sourceName == "current") {
|
||||
info["current"] = data.value
|
||||
// text update
|
||||
info["info"] = NetctlAdds.getInfo(info["current"], info["status"])
|
||||
text.text = NetctlAdds.parsePattern(pattern, info)
|
||||
// update menus
|
||||
menuUpdate()
|
||||
} else if (sourceName == "extip4") {
|
||||
info["extip4"] = data.value
|
||||
} else if (sourceName == "extip6") {
|
||||
@ -125,19 +122,113 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
QtControls.Action {
|
||||
id: stopProfile
|
||||
text: i18n("Stop profile")
|
||||
iconSource: "dialog-close"
|
||||
onTriggered: NetctlAdds.stopProfileSlot(info, useHelper, paths["netctl"], paths["sudo"])
|
||||
Component.onCompleted: {
|
||||
plasmoid.setAction("titleAction", "netctl-gui", plasmoid.icon)
|
||||
plasmoid.setAction("startProfile", i18n("Start profile"), "dialog-apply")
|
||||
plasmoid.setAction("stopProfile", i18n("Stop profile"), "dialog-close")
|
||||
plasmoid.setAction("stopAllProfiles", i18n("Stop all profiles"), "dialog-close")
|
||||
plasmoid.setAction("switchToProfile", i18n("Switch to profile"))
|
||||
plasmoid.setAction("restartProfile", i18n("Restart profile"), "stock-refresh")
|
||||
plasmoid.setAction("enableProfile", i18n("Enable profile"))
|
||||
// FIXME: icon from resources
|
||||
plasmoid.setAction("startWifi", i18n("Show WiFi menu"))
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
plasmoid.setAction("stopProfile", i18n("Stop profile"), "dialog-close")
|
||||
// plasmoid.setAction("powerdevilkcm", i18n("&Configure Power Saving..."), "preferences-system-power-management");
|
||||
function menuUpdate() {
|
||||
var titleAction = plasmoid.action("titleAction")
|
||||
var startAction = plasmoid.action("startProfile")
|
||||
var stopAction = plasmoid.action("stopProfile")
|
||||
var stopAllAction = plasmoid.action("stopAllProfiles")
|
||||
var switchToAction = plasmoid.action("switchToProfile")
|
||||
var restartAction = plasmoid.action("restartProfile")
|
||||
var enableAction = plasmoid.action("enableProfile")
|
||||
var wifiAction = plasmoid.action("startWifi")
|
||||
|
||||
titleAction.iconSource = plasmoid.icon
|
||||
titleAction.text = info["current"] + " " + info["status"]
|
||||
|
||||
// FIXME: menu to actions
|
||||
if (info["status"] == "(netctl-auto)") {
|
||||
startAction.visible = false
|
||||
stopAction.visible = false
|
||||
stopAllAction.visible = false
|
||||
switchToAction.visible = true
|
||||
restartAction.visible = false
|
||||
enableAction.visible = false
|
||||
// MENU UPDATE
|
||||
} else {
|
||||
if (info["current"].indexOf("|") > -1) {
|
||||
startAction.visible = true
|
||||
stopAction.visible = false
|
||||
stopAllAction.visible = true
|
||||
switchToAction.visible = false
|
||||
restartAction.visible = false
|
||||
enableAction.visible = false
|
||||
} else {
|
||||
startAction.visible = true
|
||||
stopAction.visible = status
|
||||
stopAllAction.visible = false
|
||||
switchToAction.visible = false
|
||||
restartAction.visible = status
|
||||
enableAction.visible = status
|
||||
}
|
||||
if (status) {
|
||||
startAction.text = i18n("Start another profile")
|
||||
stopAction.text = i18n("Stop %1", info["current"])
|
||||
restartAction.text = i18n("Restart %1", info["current"])
|
||||
if (info["status"].indexOf("enabled") > -1)
|
||||
enableAction.text = i18n("Disable %1", info["current"])
|
||||
else
|
||||
enableAction.text = i18n("Enable %1", info["current"])
|
||||
} else
|
||||
startAction.text = i18n("Start profile")
|
||||
// MENU UPDATE
|
||||
}
|
||||
|
||||
wifiAction.visible = plasmoid.configuration.useWifi
|
||||
}
|
||||
|
||||
// actions
|
||||
function action_titleAction() {
|
||||
NetctlAdds.startApplication(plasmoid.configuration.guiPath)
|
||||
}
|
||||
|
||||
function action_startProfile() {
|
||||
// NetctlAdds.startProfileSlot(profile, status, plasmoid.configuration.useHelper,
|
||||
// plasmoid.configuration.netctlPath,
|
||||
// plasmoid.configuration.sudoPath)
|
||||
}
|
||||
|
||||
function action_stopProfile() {
|
||||
NetctlAdds.stopProfileSlot(info, useHelper, paths["netctl"], paths["sudo"])
|
||||
NetctlAdds.stopProfileSlot(info, plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
plasmoid.configuration.sudoPath)
|
||||
}
|
||||
|
||||
function action_stopAllProfiles() {
|
||||
NetctlAdds.stopAllProfilesSlot(plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
plasmoid.configuration.sudoPath)
|
||||
}
|
||||
|
||||
function action_switchToProfile() {
|
||||
// NetctlAdds.switchToProfileSlot(profile, plasmoid.configuration.useHelper,
|
||||
// plasmoid.configuration.netctlAutoPath)
|
||||
}
|
||||
|
||||
function action_restartProfile() {
|
||||
NetctlAdds.restartProfileSlot(info, plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
plasmoid.configuration.sudoPath)
|
||||
}
|
||||
|
||||
function action_enableProfile() {
|
||||
NetctlAdds.enableProfileSlot(info, plasmoid.configuration.useHelper,
|
||||
plasmoid.configuration.netctlPath,
|
||||
plasmoid.configuration.sudoPath)
|
||||
}
|
||||
|
||||
function action_startWifi() {
|
||||
NetctlAdds.startApplication(plasmoid.configuration.wifiPath)
|
||||
}
|
||||
}
|
||||
|
@ -49,16 +49,14 @@ bool NetctlAdds::checkHelperStatus(const bool useHelper)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (useHelper)
|
||||
return !sendDBusRequest(QString("Active"), QList<QVariant>()).isEmpty();
|
||||
else
|
||||
return useHelper;
|
||||
return (useHelper && !sendDBusRequest(QString("Active"), QList<QVariant>()).isEmpty());
|
||||
}
|
||||
|
||||
|
||||
void NetctlAdds::startHelper(const QString cmd)
|
||||
void NetctlAdds::startApplication(const QString cmd)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
|
||||
|
||||
QProcess command;
|
||||
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
bool debug = false;
|
||||
// helper
|
||||
bool checkHelperStatus(const bool useHelper = true);
|
||||
void startHelper(const QString cmd = QString("/usr/bin/netctlgui-helper"));
|
||||
void startApplication(const QString cmd = QString("/usr/bin/true"));
|
||||
// dbus
|
||||
QList<QVariant> sendDBusRequest(const QString cmd, const QList<QVariant> args = QList<QVariant>());
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user