mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-06 10:35:46 +00:00
add support of netctl-auto to plasmoid and dataengine
This commit is contained in:
@ -45,6 +45,7 @@ Netctl::Netctl(QObject *parent, const QVariantList &args)
|
||||
Netctl::~Netctl()
|
||||
{
|
||||
// delete startProfileMenu;
|
||||
// delete switchToProfileMenu;
|
||||
// delete startProfile;
|
||||
// delete stopProfile;
|
||||
// delete restartProfile;
|
||||
@ -127,21 +128,29 @@ void Netctl::enableProfileSlot()
|
||||
|
||||
void Netctl::startProfileSlot(QAction *profile)
|
||||
{
|
||||
bool ready = true;
|
||||
QProcess command;
|
||||
QString commandLine;
|
||||
commandLine = QString("");
|
||||
sendNotification(QString("Info"), i18n("Start profile %1", profile->text().remove(QString("&"))));
|
||||
if (status)
|
||||
commandLine = paths[QString("netctl")] + QString(" stop ") +
|
||||
info[QString("name")] + QString(" && ");
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ") + commandLine +
|
||||
paths[QString("netctl")] + QString(" start ") +
|
||||
profile->text().remove(QString("&"));
|
||||
else
|
||||
commandLine = commandLine + paths[QString("netctl")] + QString(" start ") +
|
||||
profile->text().remove(QString("&"));
|
||||
command.startDetached(commandLine);
|
||||
if (status) {
|
||||
commandLine = paths[QString("netctl")] + QString(" stop ") + info[QString("name")];
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ") + commandLine;
|
||||
command.start(commandLine);
|
||||
command.waitForFinished(-1);
|
||||
if (command.exitCode() != 0)
|
||||
ready = false;
|
||||
}
|
||||
if (ready) {
|
||||
if (useSudo)
|
||||
commandLine = paths[QString("sudo")] + QString(" ") + paths[QString("netctl")] +
|
||||
QString(" start ") + profile->text().remove(QString("&"));
|
||||
else
|
||||
commandLine = paths[QString("netctl")] + QString(" start ") +
|
||||
profile->text().remove(QString("&"));
|
||||
command.startDetached(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -159,6 +168,18 @@ void Netctl::stopProfileSlot()
|
||||
}
|
||||
|
||||
|
||||
void Netctl::switchToProfileSlot(QAction *profile)
|
||||
{
|
||||
QProcess command;
|
||||
QString commandLine;
|
||||
commandLine = QString("");
|
||||
sendNotification(QString("Info"), i18n("Switch to profile %1", profile->text().remove(QString("&"))));
|
||||
commandLine = paths[QString("netctl-auto")] + QString(" switch-to ") +
|
||||
profile->text().remove(QString("&"));
|
||||
command.startDetached(commandLine);
|
||||
}
|
||||
|
||||
|
||||
void Netctl::restartProfileSlot()
|
||||
{
|
||||
QProcess command;
|
||||
@ -181,35 +202,55 @@ QList<QAction*> Netctl::contextualActions()
|
||||
contextMenu[QString("title")]->setIcon(QIcon(paths[QString("inactive")]));
|
||||
contextMenu[QString("title")]->setText(info[QString("name")] + QString(" ") + info[QString("status")]);
|
||||
|
||||
if (status) {
|
||||
contextMenu[QString("start")]->setText(i18n("Start another profile"));
|
||||
contextMenu[QString("stop")]->setVisible(true);
|
||||
contextMenu[QString("stop")]->setText(i18n("Stop %1", info[QString("name")]));
|
||||
contextMenu[QString("restart")]->setVisible(true);
|
||||
contextMenu[QString("restart")]->setText(i18n("Restart %1", info[QString("name")]));
|
||||
contextMenu[QString("enable")]->setVisible(true);
|
||||
if (info[QString("status")].contains(QString("enabled")))
|
||||
contextMenu[QString("enable")]->setText(i18n("Disable %1", info[QString("name")]));
|
||||
else
|
||||
contextMenu[QString("enable")]->setText(i18n("Enable %1", info[QString("name")]));
|
||||
}
|
||||
else {
|
||||
contextMenu[QString("start")]->setText(i18n("Start profile"));
|
||||
if (info[QString("status")] == QString("(netctl-auto)")) {
|
||||
contextMenu[QString("start")]->setVisible(false);
|
||||
contextMenu[QString("stop")]->setVisible(false);
|
||||
contextMenu[QString("switch")]->setVisible(true);
|
||||
contextMenu[QString("restart")]->setVisible(false);
|
||||
contextMenu[QString("enable")]->setVisible(false);
|
||||
|
||||
switchToProfileMenu->clear();
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
QAction *profile = new QAction(profileList[i], this);
|
||||
switchToProfileMenu->addAction(profile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
contextMenu[QString("start")]->setVisible(true);
|
||||
contextMenu[QString("stop")]->setVisible(true);
|
||||
contextMenu[QString("switch")]->setVisible(false);
|
||||
contextMenu[QString("restart")]->setVisible(true);
|
||||
contextMenu[QString("enable")]->setVisible(true);
|
||||
|
||||
if (status) {
|
||||
contextMenu[QString("start")]->setText(i18n("Start another profile"));
|
||||
contextMenu[QString("stop")]->setVisible(true);
|
||||
contextMenu[QString("stop")]->setText(i18n("Stop %1", info[QString("name")]));
|
||||
contextMenu[QString("restart")]->setVisible(true);
|
||||
contextMenu[QString("restart")]->setText(i18n("Restart %1", info[QString("name")]));
|
||||
contextMenu[QString("enable")]->setVisible(true);
|
||||
if (info[QString("status")].contains(QString("enabled")))
|
||||
contextMenu[QString("enable")]->setText(i18n("Disable %1", info[QString("name")]));
|
||||
else
|
||||
contextMenu[QString("enable")]->setText(i18n("Enable %1", info[QString("name")]));
|
||||
}
|
||||
else {
|
||||
contextMenu[QString("start")]->setText(i18n("Start profile"));
|
||||
contextMenu[QString("stop")]->setVisible(false);
|
||||
contextMenu[QString("restart")]->setVisible(false);
|
||||
contextMenu[QString("enable")]->setVisible(false);
|
||||
}
|
||||
startProfileMenu->clear();
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
QAction *profile = new QAction(profileList[i], this);
|
||||
startProfileMenu->addAction(profile);
|
||||
}
|
||||
}
|
||||
if (useWifi)
|
||||
contextMenu[QString("wifi")]->setVisible(true);
|
||||
else
|
||||
contextMenu[QString("wifi")]->setVisible(false);
|
||||
|
||||
startProfileMenu->clear();
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
QAction *profile = new QAction(profileList[i], this);
|
||||
startProfileMenu->addAction(profile);
|
||||
}
|
||||
|
||||
return menuActions;
|
||||
}
|
||||
|
||||
@ -234,6 +275,14 @@ void Netctl::createActions()
|
||||
connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot()));
|
||||
menuActions.append(contextMenu[QString("stop")]);
|
||||
|
||||
contextMenu[QString("switch")] = new QAction(i18n("Switch to profile"), this);
|
||||
contextMenu[QString("switch")]->setIcon(QIcon::fromTheme("dialog-apply"));
|
||||
switchToProfileMenu = new QMenu(NULL);
|
||||
contextMenu[QString("switch")]->setMenu(switchToProfileMenu);
|
||||
connect(switchToProfileMenu, SIGNAL(triggered(QAction *)), this,
|
||||
SLOT(switchToProfileSlot(QAction *)));
|
||||
menuActions.append(contextMenu[QString("switch")]);
|
||||
|
||||
contextMenu[QString("restart")] = new QAction(i18n("Restart profile"), this);
|
||||
contextMenu[QString("restart")]->setIcon(QIcon::fromTheme("stock-refresh"));
|
||||
connect(contextMenu[QString("restart")], SIGNAL(triggered(bool)), this, SLOT(restartProfileSlot()));
|
||||
@ -406,6 +455,14 @@ void Netctl::selectNetctlExe()
|
||||
}
|
||||
|
||||
|
||||
void Netctl::selectNetctlAutoExe()
|
||||
{
|
||||
KUrl url = KFileDialog::getOpenUrl(KUrl(), "*");
|
||||
if (!url.isEmpty())
|
||||
uiWidConfig.lineEdit_netctlAuto->setText(url.path());
|
||||
}
|
||||
|
||||
|
||||
void Netctl::selectSudoExe()
|
||||
{
|
||||
KUrl url = KFileDialog::getOpenUrl(KUrl(), "*");
|
||||
@ -435,6 +492,7 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
|
||||
uiWidConfig.spinBox_autoUpdate->setValue(autoUpdateInterval);
|
||||
uiWidConfig.lineEdit_gui->setText(paths[QString("gui")]);
|
||||
uiWidConfig.lineEdit_netctl->setText(paths[QString("netctl")]);
|
||||
uiWidConfig.lineEdit_netctlAuto->setText(paths[QString("netctlAuto")]);
|
||||
if (useSudo)
|
||||
uiWidConfig.checkBox_sudo->setCheckState(Qt::Checked);
|
||||
else
|
||||
@ -491,6 +549,7 @@ void Netctl::createConfigurationInterface(KConfigDialog *parent)
|
||||
|
||||
connect(uiWidConfig.pushButton_gui, SIGNAL(clicked()), this, SLOT(selectGuiExe()));
|
||||
connect(uiWidConfig.pushButton_netctl, SIGNAL(clicked()), this, SLOT(selectNetctlExe()));
|
||||
connect(uiWidConfig.pushButton_netctlAuto, SIGNAL(clicked()), this, SLOT(selectNetctlAutoExe()));
|
||||
connect(uiWidConfig.pushButton_sudo, SIGNAL(clicked()), this, SLOT(selectSudoExe()));
|
||||
connect(uiWidConfig.pushButton_wifi, SIGNAL(clicked()), this, SLOT(selecWifiExe()));
|
||||
connect(uiAppConfig.pushButton_activeIcon, SIGNAL(clicked()), this, SLOT(selectActiveIcon()));
|
||||
@ -509,6 +568,7 @@ void Netctl::configAccepted()
|
||||
cg.writeEntry("autoUpdateInterval", uiWidConfig.spinBox_autoUpdate->value());
|
||||
cg.writeEntry("guiPath", uiWidConfig.lineEdit_gui->text());
|
||||
cg.writeEntry("netctlPath", uiWidConfig.lineEdit_netctl->text());
|
||||
cg.writeEntry("netctlAutoPath", uiWidConfig.lineEdit_netctlAuto->text());
|
||||
if (uiWidConfig.checkBox_sudo->checkState() == 0)
|
||||
cg.writeEntry("useSudo", false);
|
||||
else
|
||||
@ -553,6 +613,7 @@ void Netctl::configChanged()
|
||||
autoUpdateInterval = cg.readEntry("autoUpdateInterval", 1000);
|
||||
paths[QString("gui")] = cg.readEntry("guiPath", "/usr/bin/netctl-gui");
|
||||
paths[QString("netctl")] = cg.readEntry("netctlPath", "/usr/bin/netctl");
|
||||
paths[QString("netctlAuto")] = cg.readEntry("netctlAutoPath", "/usr/bin/netctl-auto");
|
||||
paths[QString("sudo")] = cg.readEntry("sudoPath", "/usr/bin/kdesu");
|
||||
paths[QString("wifi")] = cg.readEntry("wifiPath", "/usr/bin/netctl-gui -t 3");
|
||||
useSudo = cg.readEntry("useSudo", true);
|
||||
|
@ -62,12 +62,14 @@ private slots:
|
||||
void selectGuiExe();
|
||||
void selectInactiveIcon();
|
||||
void selectNetctlExe();
|
||||
void selectNetctlAutoExe();
|
||||
void selectSudoExe();
|
||||
void selectWifiExe();
|
||||
// context menu
|
||||
void enableProfileSlot();
|
||||
void startProfileSlot(QAction *profile);
|
||||
void stopProfileSlot();
|
||||
void switchToProfileSlot(QAction *profile);
|
||||
void restartProfileSlot();
|
||||
|
||||
protected:
|
||||
@ -88,6 +90,7 @@ private:
|
||||
void createActions();
|
||||
QList<QAction*> menuActions;
|
||||
QMenu *startProfileMenu;
|
||||
QMenu *switchToProfileMenu;
|
||||
QMap<QString, QAction*> contextMenu;
|
||||
// data engine
|
||||
Plasma::DataEngine *netctlEngine;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>480</width>
|
||||
<height>341</height>
|
||||
<height>339</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
@ -19,8 +19,8 @@
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Configuration Window</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_info">
|
||||
<property name="text">
|
||||
<string/>
|
||||
@ -30,106 +30,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_showNetDev">
|
||||
<property name="text">
|
||||
<string>Show network devices</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<layout class="QHBoxLayout" name="layout_wifi">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_wifi">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show 'Start WiFi menu'</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_wifi"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_wifi">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_showBigInterface">
|
||||
<property name="text">
|
||||
<string>Show more detailed interface</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_showIntIp">
|
||||
<property name="text">
|
||||
<string>Show internal IP</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="layout_gui">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_gui">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Path to GUI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_gui"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_gui">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_autoUpdate">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_autoUpdate">
|
||||
@ -187,23 +88,46 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_showExtIp">
|
||||
<property name="text">
|
||||
<string>Show external IP</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_gui">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_gui">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Path to GUI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_gui"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_gui">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_netctl">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_netctl">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
@ -230,7 +154,40 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<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_sudo">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_sudo">
|
||||
@ -266,7 +223,83 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_wifi">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_wifi">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show 'Start WiFi menu'</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_wifi"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_wifi">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_showBigInterface">
|
||||
<property name="text">
|
||||
<string>Show more detailed interface</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_showNetDev">
|
||||
<property name="text">
|
||||
<string>Show network devices</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_showExtIp">
|
||||
<property name="text">
|
||||
<string>Show external IP</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_showIntIp">
|
||||
<property name="text">
|
||||
<string>Show internal IP</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_configuration">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
Reference in New Issue
Block a user