68 Commits

Author SHA1 Message Date
824a11457b release 1.4.1 2015-03-20 00:20:44 +03:00
b7fa17df4e improve dataengine permofrmance (fix #39) - TODO: need to be tested 2015-03-19 11:45:13 +03:00
35af460b7b fix crash on null connection 2015-03-18 06:13:35 +03:00
9aa1f6d715 implement #38
freeze code base to release 1.4.1
2015-03-18 03:33:30 +03:00
308f9824b4 implement #37 2015-03-17 14:07:05 +03:00
bf7521481a implement #36
update translations
2015-03-17 13:22:45 +03:00
e4bcfb1653 fix kde4 build
fix tray destruction on KF5
2015-03-16 08:52:23 +03:00
a2b1d46900 Prepare to release 1.4.1
update docs, update ui
deprecate description function
2015-03-16 05:14:53 +03:00
3f49988cef update submodule
update netctl-auto
update interfaces
2015-03-15 18:17:49 +03:00
f80d6aae6b end work on interfaces 2015-03-14 06:42:06 +03:00
ef2694d7a7 add calls
create interface dbus interface
2015-03-13 08:22:02 +03:00
26afd90df9 + add toolbar config
+ create interface class
* update UI
2015-03-13 05:12:06 +03:00
02432be630 edit ui
* remove margins
* create more pretty toolbars
* edit toolbar update action (s/setVisible/setEnabled/g)
2015-03-12 02:02:20 +03:00
275d71d75f rewrite ui (refactoring, simplification, improvement of user expierence) 2015-03-11 07:19:20 +03:00
b90f441fde roll back interfaces to wpa_cli
improvement of wpa_supplicant control
2015-03-10 07:53:15 +03:00
19976819a1 + add CurrentWiFi method
+ add support of pid files with interface name to provide compability
with netctl module
* change default wpa_sup ctrl paths
* optimization of wifi calls
2015-03-10 00:52:45 +03:00
362a11f0bc + new Verbose* DBus calls
+ new force request to netctl (DBus)
+ PointType enum
+ notification on hidding,
+ new columns in WiFi menu
* improve user expierence
* fix language definition
* fix tests
* update 3rdparty components
* small refactoring
2015-03-09 08:29:26 +03:00
d94aa4ebf7 update KDE4 plasmoid 2015-03-08 19:24:21 +03:00
2cf876cf32 * edit WiFi and ProfileList calls
* optimization of WifiMenu
* small refactoring
2015-03-07 17:12:33 +03:00
9993fee336 rewrite netctlautowindow ui 2015-03-05 12:05:34 +03:00
de0c1f208d edit dbus calls
TODO edit dbus call in netctlautowindow (create callbacks too)
2015-03-03 16:11:38 +03:00
25ca2ef1d9 rewrite private slots
TODO: add more methods to dbusinteraction, check dbus calls
2015-03-02 06:00:42 +03:00
1333967535 rewrite ui part (except for privateslots) 2015-02-28 04:05:34 +03:00
e70ebe318d small refactoring 2015-02-27 18:46:28 +03:00
dcdf03f639 refactoring of profile widgets 2015-02-27 18:10:23 +03:00
8b33ec859b refactoring of library part 2015-02-26 06:20:23 +03:00
53ff63b792 + add ja to available langs
+ add signals to lineEdits
* rewrite errorwindow class to static methods
* replace mask in ip lineedits to validators (fix #34)
* fix advanced lines
* move AdHoc and Hidden options to advanced (#28)
* fix default wpa_supplicant conf path (#28)
* update toolbars to #2
* replace General settings section to Common (see http://doc.qt.io/qt-5/qsettings.html#Format-enum)
2015-02-24 05:32:37 +03:00
b46ce1620b fix #25 2015-02-19 13:06:06 +03:00
4c20a54d7e small update 2015-02-18 16:23:07 +03:00
a73968f98b * refactoring and optimization KF5 part (#26, #31)
* add info instrument
* implement needToBeConfigured() slot, see #29
* fix (#30)
some improvements
2015-02-17 10:44:51 +03:00
9033c51bb4 update files
add _DEFAULT_SOURCE to avoid warnings
fix cppcheck messages
2015-01-14 00:59:42 +03:00
d23429891e release 1.4.0 2015-01-12 19:30:49 +03:00
cf12b3627e update ChangeLog
update CmakeLists
update PKGBUILDs
fix GUI building
2015-01-12 01:14:40 +03:00
582459d174 fix #24
update gitignore
2015-01-11 00:38:47 +03:00
08e7390f6c Merge branch 'master' of github.com:arcan1s/netctl-gui 2015-01-10 00:36:26 +03:00
c8eae4b222 fix painting
update translations
fix PKGBUILD
2015-01-10 00:35:52 +03:00
54583eae6e update interface painting 2015-01-09 02:40:24 +03:00
634b4c3b41 try to paint more pretty interface 2015-01-08 02:00:59 +03:00
54c5e7958a kf5 update
* implement resizing
* implement debug
* implement notifications
* update interface
* correct work with helper
2015-01-07 07:03:41 +03:00
6ed45fa7a5 change in updates 2015-01-06 00:46:28 +03:00
73ba838685 + add de page
* rewrite de configuration to use qsettings
- remove cppcheck
+ add notifyrc
2015-01-05 00:29:52 +03:00
924beacc23 implement actions 2015-01-04 02:01:07 +03:00
a830fc9372 Merge branch 'kf5' 2015-01-03 13:58:17 +03:00
4c7459e833 Merge branch 'kf5' of github.com:arcan1s/netctl-gui into kf5 2015-01-03 13:56:33 +03:00
00a35d75d2 add ability to build kde4 and kf5 packages 2015-01-03 13:56:00 +03:00
3e92ec2aae Update CMakeLists.txt
bump to 1.4.0
2015-01-03 13:23:16 +03:00
3ac0484f21 some test with actions 2014-12-31 08:09:53 +03:00
cbac07b29e move method from original one 2014-12-30 14:39:25 +03:00
7972f2d6d3 some configuration interface changes 2014-12-29 23:37:21 +03:00
afed94745a fix plugin 2014-12-29 20:56:35 +03:00
c8f260c8e2 rename applet to *plasma* 2014-12-29 08:35:23 +03:00
edb386d24e implement binary module 2014-12-28 17:42:08 +03:00
f188dea8a7 add wdiget.qml 2014-12-27 12:24:05 +03:00
6fb7da4b5b add appearance.qml 2014-12-27 03:50:31 +03:00
a35e9b0164 first work on plasmoid 2014-12-26 08:22:26 +03:00
4bc428f8b5 add workaround to #23
(fix?)
2014-12-05 03:52:27 +03:00
030dec5e14 end porting of DE to KF5 2014-10-21 16:26:35 +04:00
0898a99878 updte dataengine skel 2014-10-21 13:06:57 +04:00
8dd48fa7cc release 1.3.3
fix #19
2014-10-19 17:50:24 +04:00
287405f81a try fix #19 2014-10-18 01:17:15 +04:00
fa27b80060 add some w\o 2014-10-17 13:52:46 +04:00
c2c14c4911 Merge pull request #18 from nosada/translate_to_ja
Fix translation on plasmoid
2014-10-13 11:58:23 +04:00
e2deb8751d fix translation at plasmoid 2014-10-13 16:43:37 +09:00
1fe7d6e21f change translation at plasmoid (again) 2014-10-13 16:43:37 +09:00
e68be6d4f1 change translation at plasmoid 2014-10-13 16:43:37 +09:00
45d3a42754 update tasks 2014-10-09 22:58:13 +04:00
cb0410a182 update pkgbuild #17 2014-09-27 18:25:41 +04:00
9d349461cf release 1.3.2 2014-09-22 00:56:12 +04:00
175 changed files with 18778 additions and 10319 deletions

131
CHANGELOG
View File

@ -1,9 +1,92 @@
Ver.1.4.1
---------
* all
+ some Easter eggs
+ add _DEFAULT_SOURCE to avoid gcc warnings
* refactoring
* fix cppcheck warnings
* update 3rdparty components
* fix language defilition
* replace General section to Common in settings (see http://doc.qt.io/qt-5/qsettings.html#Format-enum)
* gui
+ allow to change helper control group from UI (#36)
+ allow to open profile in an external editor (#38)
+ add IP validators (#34)
+ add toolbar configuration
+ add notification on hidding to tray
+ add returnPressed() signal to lineEdits
+ implement needToBeConfigured() signal
- remove margins
- fix bug with segfault on updating UI with KF5
* rewrite ErrorWindow class
* split MainWindow class
* update WiFi menu to new library functions
* improve UI (#25, #28)
* more correct component checking (#29, #37)
* more correct callbacks with exceptions
* dataengine
+ add desktop reconfiguration (#30)
* improve performance
* helper
+ add /interface interface
+ add /ctrl/{CurrentWiFi,VerboseWiFi} calls
+ add /netctl/VerboseProfiles call
+ add /netctl/{netctlActiveProfile,netctlProfileList,netctlVerboseProfileList) calls
* library
+ add NetctlInterface class
+ add WpaSup::CurrentWiFi method
+ append structures some additional information
+ mark Netctl::getProfileDescription() as deprecated
+ now WpaSup can connect to already created session (by default)
* improve performance
* plasmoid
+ add desktop reconfiguration (#30)
- remove legacy functions from KDE4 plasmoid
* improve performance of KF5 plasmoid (#26)
* test
* fix netctl tests
***
Ver.1.4.0
---------
* all
* change settings format from shell-like to ini (#24)
* dataengine
+ create package for KF5
* change NETCTLGUI_DEBUG=yes to DEBUG=yes
* update url
* gui
+ add workarounds to #22 and #23
* plasmoid
+ create package and plugin for KF5
* change NETCTLGUI_DEBUG=yes to DEBUG=yes
* update url
***
Ver.1.3.3
---------
* all
* update Japanese translation
* dataengine
- fix #19
***
Ver.1.3.2
---------
* all
+ add Japanese translation (thanks to @nosada)
***
Ver.1.3.1 Ver.1.3.1
--------- ---------
* gui: * gui
* more correct calls of boolean DBus methods * more correct calls of boolean DBus methods
* edit helper icon * edit helper icon
* helper: * helper
* more correct calls of boolean DBus methods * more correct calls of boolean DBus methods
* more correct systemd service * more correct systemd service
* add ability to create session bus * add ability to create session bus
@ -12,18 +95,18 @@ Ver.1.3.1
Ver.1.3.0 Ver.1.3.0
--------- ---------
* all: * all
+ add processes error messages + add processes error messages
+ add support of several active profiles + add support of several active profiles
* some bug fixes and refactoring * some bug fixes and refactoring
* rewrite debug messages * rewrite debug messages
* dataengine: * dataengine
+ add new sources: intIp6, extIp6, netctlAutoStatus + add new sources: intIp6, extIp6, netctlAutoStatus
* rewrite to use [tasks](https://github.com/mhogomchungu/tasks) (see #7) * rewrite to use [tasks](https://github.com/mhogomchungu/tasks) (see #7)
* change default command to define external IP * change default command to define external IP
* change interface list definition * change interface list definition
* change internal IP definition * change internal IP definition
* gui: * gui
+ add 3rd party license information + add 3rd party license information
+ add system tray icon as an alternative to the plasmoid + add system tray icon as an alternative to the plasmoid
+ add DBus session interface org.netctlgui.netctlgui + add DBus session interface org.netctlgui.netctlgui
@ -40,11 +123,11 @@ Ver.1.3.0
* rewrite tables to use toolTip * rewrite tables to use toolTip
* edit about window * edit about window
* change menuBar * change menuBar
* helper: * helper
+ create daemon DBus system interface org.netctlgui.helper to the library: + create daemon DBus system interface org.netctlgui.helper to the library:
self control slots, netctl control slots and netctl information slots self control slots, netctl control slots and netctl information slots
+ add tests + add tests
* library: * library
+ add custom structures netctlWifiInfo and netctlProfileInfo + add custom structures netctlWifiInfo and netctlProfileInfo
+ add methods getActiveProfile(), autoGetActiveProfile() + add methods getActiveProfile(), autoGetActiveProfile()
+ add slot switchToProfile() + add slot switchToProfile()
@ -59,7 +142,7 @@ Ver.1.3.0
* rewrite to use [tasks](https://github.com/mhogomchungu/tasks) (see #7) * rewrite to use [tasks](https://github.com/mhogomchungu/tasks) (see #7)
* rename getInterfaceList() to getWirelessInterfaceList() * rename getInterfaceList() to getWirelessInterfaceList()
* change temporary directory from $HOME/.cache to system one * change temporary directory from $HOME/.cache to system one
* plasmoid: * plasmoid
+ add 3rd party license information + add 3rd party license information
+ allow plasmoid to use system tray + allow plasmoid to use system tray
+ add ability to use helper + add ability to use helper
@ -72,14 +155,14 @@ Ver.1.3.0
Ver.1.2.0 Ver.1.2.0
--------- ---------
* all: * all
+ add icons + add icons
+ add support of netctl-auto + add support of netctl-auto
* changes in the project architecture * changes in the project architecture
* refactoring * refactoring
* dataengine: * dataengine
+ add debug information (NETCTLGUI_DEBUG=yes) + add debug information (NETCTLGUI_DEBUG=yes)
* gui: * gui
+ add support of macvlan + add support of macvlan
+ add ability to remove profile + add ability to remove profile
+ add support of hidden wifi network + add support of hidden wifi network
@ -97,13 +180,13 @@ Ver.1.2.0
* refactoring of configuration interface * refactoring of configuration interface
* change setting of the interface to profile tab * change setting of the interface to profile tab
* rewrite ErrorWindow class * rewrite ErrorWindow class
* library: * library
+ detach backend from frontend + detach backend from frontend
+ add error checking + add error checking
+ add doxygen documentation + add doxygen documentation
* more debug information * more debug information
* rewrite getSettingsFromProfile() function * rewrite getSettingsFromProfile() function
* plasmoid: * plasmoid
+ add dataengine configuration + add dataengine configuration
+ add about window + add about window
+ add debug information (NETCTLGUI_DEBUG=yes) + add debug information (NETCTLGUI_DEBUG=yes)
@ -115,26 +198,26 @@ Ver.1.2.0
Ver.1.1.0 (netctl-1.7 update) Ver.1.1.0 (netctl-1.7 update)
----------------------------- -----------------------------
* dataengine: * dataengine
* change definition if profile is enabled * change definition if profile is enabled
* gui: * gui
+ add frequency + add frequency
* change definition if profile is enabled * change definition if profile is enabled
* plasmoid: * plasmoid
+ add menu title + add menu title
*** ***
Ver.1.0.6 Ver.1.0.6
--------- ---------
* gui: * gui
* fix error checking * fix error checking
*** ***
Ver.1.0.5 Ver.1.0.5
--------- ---------
* plasmoid: * plasmoid
+ add "Start WiFi menu" function + add "Start WiFi menu" function
* refactoring * refactoring
* edit icon * edit icon
@ -143,9 +226,9 @@ Ver.1.0.5
Ver.1.0.4 Ver.1.0.4
--------- ---------
* gui: * gui
+ add Qt5 gui (by default) + add Qt5 gui (by default)
* plasmoid: * plasmoid
+ add notifications + add notifications
* fix run command with sudo from plasmoid * fix run command with sudo from plasmoid
@ -153,23 +236,23 @@ Ver.1.0.4
Ver.1.0.3 Ver.1.0.3
--------- ---------
* all: * all
* refactoring * refactoring
* plasmoid: * plasmoid
+ edit russian translation + edit russian translation
*** ***
Ver.1.0.2 Ver.1.0.2
--------- ---------
* plasmoid: * plasmoid
- fix layout margins - fix layout margins
*** ***
Ver.1.0.1 Ver.1.0.1
--------- ---------
* all: * all
- remove scripts - remove scripts
*** ***

View File

@ -4,7 +4,7 @@ Netctl GUI
Information Information
----------- -----------
Qt4/Qt5 graphical interface for netctl. It may work with profiles and may create new profiles. Also it may create a connection to WiFi. Moreover, it provides a widget and DataEngine for KDE. Qt4/Qt5 graphical interface for netctl. It may work with profiles and may create new profiles. Also it may create a connection to WiFi. Moreover, it provides a widget and DataEngine for KDE4/KF5.
**NOTE** [LOOKING FOR TRANSLATORS!](https://github.com/arcan1s/netctl-gui/issues/3) **NOTE** [LOOKING FOR TRANSLATORS!](https://github.com/arcan1s/netctl-gui/issues/3)
@ -15,8 +15,8 @@ It is recommended to use graphical interface for configuration. Configuration fi
* `$HOME/.config/netctl-gui.conf` - GUI/helper user configuration * `$HOME/.config/netctl-gui.conf` - GUI/helper user configuration
* `/etc/netctl-gui.conf` - helper system-wide configuration * `/etc/netctl-gui.conf` - helper system-wide configuration
* `$KDEHOME/share/config/netctl.conf` - DataEngine user configuration * `$HOME/.config/plasma-dataengine-netctl.conf` - DataEngine user configuration
* `$KDESYSTEM/share/config/netctl.conf` - DataEngine system-wide configuration * `/etc/xdg/plasma-dataengine-netctl.conf` - DataEngine system-wide configuration
Instruction Instruction
=========== ===========
@ -30,7 +30,8 @@ Dependencies
Optional dependencies Optional dependencies
--------------------- ---------------------
* kdebase-workspace (widget) * kdebase-workspace (KDE4 widget)
* plasma-framework (KF5 widget)
* sudo (sudo support) * sudo (sudo support)
* wpa_supplicant (WiFi support) * wpa_supplicant (WiFi support)
@ -68,6 +69,7 @@ Installation
* `-DDBUS_SYSTEMCONF_PATH=/etc/dbus-1/system.d/` - path to dbus system configuration files * `-DDBUS_SYSTEMCONF_PATH=/etc/dbus-1/system.d/` - path to dbus system configuration files
* `-DSYSTEMD_SERVICE_PATH=lib/systemd/system` - path to systemd services * `-DSYSTEMD_SERVICE_PATH=lib/systemd/system` - path to systemd services
* `-DUSE_CAPABILITIES:BOOL=0` - do not use setcap to get privileges to the helper * `-DUSE_CAPABILITIES:BOOL=0` - do not use setcap to get privileges to the helper
* `-DBUILD_KDE4:BOOL=1` - build KDE4 plasmoid instead of KF5 one
* `-DUSE_QT5:BOOL=0` - use Qt4 instead of Qt5 for GUI * `-DUSE_QT5:BOOL=0` - use Qt4 instead of Qt5 for GUI
Additional information Additional information

View File

@ -2,22 +2,21 @@
pkgbase=netctl-gui pkgbase=netctl-gui
pkgname=('libnetctlgui' 'netctlgui-helper' 'netctl-gui' pkgname=('libnetctlgui' 'netctlgui-helper' 'netctl-gui'
'libnetctlgui-qt4' 'netctlgui-helper-qt4' 'netctl-gui-qt4' 'plasma5-applet-netctl-gui')
'kdeplasma-applets-netctl-gui') pkgver=1.4.1
pkgver=1.3.1 pkgrel=1
pkgrel=2
pkgdesc="Qt4/Qt5 GUI for netctl. Also provides a widget for KDE" pkgdesc="Qt4/Qt5 GUI for netctl. Also provides a widget for KDE"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')
url="http://arcanis.name/projects/netctl-gui" url="http://arcanis.name/projects/netctl-gui"
license=('GPL3') license=('GPL3')
makedepends=('automoc4' 'cmake' 'kdelibs' 'qt5-base' 'qt5-tools') makedepends=('cmake' 'extra-cmake-modules' 'plasma-framework' 'qt5-tools')
source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${pkgbase}-${pkgver}-src.tar.xz") source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${pkgbase}-${pkgver}-src.tar.xz")
md5sums=('d57bf3773f6cd9ead91c2669a02360fb') md5sums=('f93be4d72fa63007f39d3b5516ccd3e4')
prepare() { prepare() {
rm -rf "${srcdir}/build-"{plasmoid,qt4,qt5} rm -rf "${srcdir}/build-"{plasmoid,qt5}
mkdir "${srcdir}/build-"{plasmoid,qt4,qt5} mkdir "${srcdir}/build-"{plasmoid,qt5}
} }
@ -25,22 +24,13 @@ build() {
cd "${srcdir}/build-plasmoid" cd "${srcdir}/build-plasmoid"
cmake -DCMAKE_INSTALL_PREFIX=/usr \ cmake -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DKDE_INSTALL_USE_QT_SYS_PATHS=ON \
-DBUILD_GUI:BOOL=0 \ -DBUILD_GUI:BOOL=0 \
-DBUILD_LIBRARY:BOOL=0 \ -DBUILD_LIBRARY:BOOL=0 \
-DBUILD_HELPER:BOOL=0 \ -DBUILD_HELPER:BOOL=0 \
"../${pkgbase}" "../${pkgbase}"
make make
cd "${srcdir}/build-qt4"
cmake -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_DATAENGINE:BOOL=0 \
-DBUILD_PLASMOID:BOOL=0 \
-DUSE_CAPABILITIES:BOOL=0 \
-DUSE_QT5:BOOL=0 \
"../${pkgbase}"
make
cd "${srcdir}/build-qt5" cd "${srcdir}/build-qt5"
cmake -DCMAKE_INSTALL_PREFIX=/usr \ cmake -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
@ -52,15 +42,13 @@ build() {
} }
package_kdeplasma-applets-netctl-gui() { package_plasma5-applet-netctl-gui() {
pkgdesc="A plasmoid, which interacts with netctl. A part of netctl-gui" pkgdesc="A KF5 plasmoid, which interacts with netctl. A part of netctl-gui"
depends=('netctl' 'kdebase-workspace') depends=('netctl' 'plasma-framework')
optdepends=('netctlgui-helper: DBus helper daemon' optdepends=('netctlgui-helper: DBus helper daemon'
'netctlgui-helper-qt4: DBus helper daemon'
'netctl-gui: graphical front-end' 'netctl-gui: graphical front-end'
'netctl-gui-qt4: graphical front-end'
'sudo: sudo support') 'sudo: sudo support')
install="kdeplasma-applets-netctl-gui.install" install="plasma-netctl-gui.install"
cd "${srcdir}/build-plasmoid" cd "${srcdir}/build-plasmoid"
make DESTDIR="${pkgdir}" install make DESTDIR="${pkgdir}" install
@ -83,7 +71,7 @@ package_libnetctlgui() {
package_netctlgui-helper() { package_netctlgui-helper() {
pkgdesc="Helper daemon for netctl-gui. A part of netctl-gui" pkgdesc="Helper daemon for netctl-gui. A part of netctl-gui"
depends=('libnetctlgui') depends=("libnetctlgui=${pkgver}")
provides=('netctlgui-helper-qt4') provides=('netctlgui-helper-qt4')
conflicts=('netctlgui-helper-qt4') conflicts=('netctlgui-helper-qt4')
backup=('etc/netctl-gui.conf' backup=('etc/netctl-gui.conf'
@ -97,8 +85,8 @@ package_netctlgui-helper() {
package_netctl-gui() { package_netctl-gui() {
pkgdesc="Qt5 graphical front-end for netctl. A part of netctl-gui" pkgdesc="Qt5 graphical front-end for netctl. A part of netctl-gui"
depends=('libnetctlgui' 'xdg-utils') depends=("libnetctlgui=${pkgver}" 'xdg-utils')
optdepends=('kdeplasma-applets-netctl-gui: KDE widget' optdepends=('plasma-netctl-gui: KF5 widget'
'netctlgui-helper: DBus helper daemon') 'netctlgui-helper: DBus helper daemon')
provides=('netctl-gui-qt4') provides=('netctl-gui-qt4')
conflicts=('netctl-gui-qt4') conflicts=('netctl-gui-qt4')
@ -106,47 +94,6 @@ package_netctl-gui() {
cd "${srcdir}/build-qt5/gui" cd "${srcdir}/build-qt5/gui"
make DESTDIR="${pkgdir}" install make DESTDIR="${pkgdir}" install
} cd "${srcdir}/build-qt5/resources"
package_libnetctlgui-qt4() {
pkgdesc="Qt4 library which interacts with netctl. A part of netctl-gui"
depends=('netctl' 'qt4')
optdepends=('netctlgui-helper-qt4: DBus helper daemon'
'sudo: sudo support'
'wpa_supplicant: wifi support')
provides=('libnetctlgui')
conflicts=('libnetctlgui')
install=""
cd "${srcdir}/build-qt4/netctlgui"
make DESTDIR="${pkgdir}" install
}
package_netctlgui-helper-qt4() {
pkgdesc="Helper daemon for netctl-gui. A part of netctl-gui"
depends=('libnetctlgui-qt4')
provides=('netctlgui-helper')
conflicts=('netctlgui-helper')
backup=('etc/netctl-gui.conf'
'etc/dbus-1/system.d/org.netctlgui.helper.conf')
install="netctlgui-helper.install"
cd "${srcdir}/build-qt4/helper"
make DESTDIR="${pkgdir}" install
}
package_netctl-gui-qt4() {
pkgdesc="Qt4 graphical front-end for netctl. A part of netctl-gui"
depends=('libnetctlgui-qt4')
optdepends=('kdeplasma-applets-netctl-gui: KDE widget'
'netctlgui-helper-qt4: DBus helper daemon')
provides=('netctl-gui')
conflicts=('netctl-gui')
install="netctl-gui.install"
cd "${srcdir}/build-qt4/gui"
make DESTDIR="${pkgdir}" install make DESTDIR="${pkgdir}" install
} }

101
arch/PKGBUILD-qt4 Normal file
View File

@ -0,0 +1,101 @@
# Maintainer: Evgeniy "arcanis" Alexeev <arcanis.arch at gmail dot com>
pkgbase=netctl-gui-qt4
pkgname=('libnetctlgui-qt4' 'netctlgui-helper-qt4' 'netctl-gui-qt4'
'kdeplasma-applets-netctl-gui')
pkgver=1.4.1
pkgrel=1
pkgdesc="Qt4 GUI for netctl. Also provides a widget for KDE4"
arch=('i686' 'x86_64')
url="http://arcanis.name/projects/netctl-gui"
license=('GPL3')
makedepends=('automoc4' 'cmake' 'kdelibs')
source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${pkgbase}-${pkgver}-src.tar.xz")
md5sums=('f93be4d72fa63007f39d3b5516ccd3e4')
prepare() {
rm -rf "${srcdir}/build-"{plasmoid,qt4}
mkdir "${srcdir}/build-"{plasmoid,qt4}
}
build() {
cd "${srcdir}/build-plasmoid"
cmake -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_GUI:BOOL=0 \
-DBUILD_LIBRARY:BOOL=0 \
-DBUILD_HELPER:BOOL=0 \
-DBUILD_KDE4:BOOL=1 \
"../${pkgbase}"
make
cd "${srcdir}/build-qt4"
cmake -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_DATAENGINE:BOOL=0 \
-DBUILD_PLASMOID:BOOL=0 \
-DUSE_CAPABILITIES:BOOL=0 \
-DUSE_QT5:BOOL=0 \
"../${pkgbase}"
make
}
package_kdeplasma-applets-netctl-gui() {
pkgdesc="A KDE4 plasmoid, which interacts with netctl. A part of netctl-gui"
depends=('netctl' 'kdebase-workspace')
optdepends=('netctlgui-helper-qt4: DBus helper daemon'
'netctl-gui-qt4: graphical front-end'
'sudo: sudo support')
install="kdeplasma-applets-netctl-gui.install"
cd "${srcdir}/build-plasmoid"
make DESTDIR="${pkgdir}" install
}
package_libnetctlgui-qt4() {
pkgdesc="Qt4 library which interacts with netctl. A part of netctl-gui"
depends=('netctl' 'qt4')
optdepends=('netctlgui-helper-qt4: DBus helper daemon'
'sudo: sudo support'
'wpa_supplicant: wifi support')
provides=('libnetctlgui')
conflicts=('libnetctlgui')
install=""
cd "${srcdir}/build-qt4/netctlgui"
make DESTDIR="${pkgdir}" install
}
package_netctlgui-helper-qt4() {
pkgdesc="Helper daemon for netctl-gui. A part of netctl-gui"
depends=("libnetctlgui-qt4=${pkgver}")
provides=('netctlgui-helper')
conflicts=('netctlgui-helper')
backup=('etc/netctl-gui.conf'
'etc/dbus-1/system.d/org.netctlgui.helper.conf')
install="netctlgui-helper.install"
cd "${srcdir}/build-qt4/helper"
make DESTDIR="${pkgdir}" install
}
package_netctl-gui-qt4() {
pkgdesc="Qt4 graphical front-end for netctl. A part of netctl-gui"
depends=("libnetctlgui-qt4=${pkgver}")
optdepends=('kdeplasma-applets-netctl-gui: KDE widget'
'netctlgui-helper-qt4: DBus helper daemon')
provides=('netctl-gui')
conflicts=('netctl-gui')
install="netctl-gui.install"
cd "${srcdir}/build-qt4/gui"
make DESTDIR="${pkgdir}" install
cd "${srcdir}/build-qt4/resources"
make DESTDIR="${pkgdir}" install
}

View File

@ -0,0 +1,14 @@
post_install() {
cat << EOF
Update plasmoids...
EOF
kbuildsycoca5 > /dev/null 2>&1
}
post_upgrade() {
post_install "$1"
}
post_remove() {
post_install "$1"
}

View File

@ -1,12 +1,14 @@
#!/bin/bash #!/bin/bash
ARCHIVE="netctl-gui"
SRCDIR="sources" SRCDIR="sources"
MAJOR=$(grep -m1 PROJECT_VERSION_MAJOR ${SRCDIR}/CMakeLists.txt | awk '{print $3}' | sed 's/.$//g')
MINOR=$(grep -m1 PROJECT_VERSION_MINOR ${SRCDIR}/CMakeLists.txt | awk '{print $3}' | sed 's/.$//g')
PATCH=$(grep -m1 PROJECT_VERSION_PATCH ${SRCDIR}/CMakeLists.txt | awk '{print $3}' | sed 's/.$//g')
VERSION="${MAJOR}.${MINOR}.${PATCH}"
ARCHIVE="netctl-gui"
FILES="AUTHORS CHANGELOG COPYING README.md" FILES="AUTHORS CHANGELOG COPYING README.md"
IGNORELIST="build *.qm *.cppcheck .git*" IGNORELIST="build *.qm *.cppcheck .git* .kdev4 sources.kdev4"
VERSION=$(grep -m1 PROJECT_VERSION_MAJOR sources/CMakeLists.txt | awk '{print $3}' | cut -c 1).\
$(grep -m1 PROJECT_VERSION_MINOR sources/CMakeLists.txt | awk '{print $3}' | cut -c 1).\
$(grep -m1 PROJECT_VERSION_PATCH sources/CMakeLists.txt | awk '{print $3}' | cut -c 1)
# update submodules # update submodules
git submodule update --init --recursive git submodule update --init --recursive
# create archive # create archive
@ -18,10 +20,11 @@ for FILE in ${IGNORELIST[*]}; do find "${ARCHIVE}" -name "${FILE}" -exec rm -rf
tar cJf "${ARCHIVE}-${VERSION}-src.tar.xz" "${ARCHIVE}" tar cJf "${ARCHIVE}-${VERSION}-src.tar.xz" "${ARCHIVE}"
ln -sf "../${ARCHIVE}-${VERSION}-src.tar.xz" arch ln -sf "../${ARCHIVE}-${VERSION}-src.tar.xz" arch
rm -rf "${ARCHIVE}" rm -rf "${ARCHIVE}"
# update md5sum # update md5sum
MD5SUMS=$(md5sum ${ARCHIVE}-${VERSION}-src.tar.xz | awk '{print $1}') MD5SUMS=$(md5sum ${ARCHIVE}-${VERSION}-src.tar.xz | awk '{print $1}')
sed -i "/md5sums=('[0-9A-Fa-f]*/s/[^'][^)]*/md5sums=('${MD5SUMS}'/" arch/PKGBUILD sed -i "/md5sums=('[0-9A-Fa-f]*/s/[^'][^)]*/md5sums=('${MD5SUMS}'/" arch/PKGBUILD{,-qt4}
sed -i "s/pkgver=[0-9.]*/pkgver=${VERSION}/" arch/PKGBUILD sed -i "s/pkgver=[0-9.]*/pkgver=${VERSION}/" arch/PKGBUILD{,-qt4}
# clear # clear
find . -type f -name '*src.tar.xz' -not -name "*${VERSION}-src.tar.xz" -exec rm -rf {} \; find . -type f -name '*src.tar.xz' -not -name "*${VERSION}-src.tar.xz" -exec rm -rf {} \;
find arch -type l -xtype l -exec rm -rf {} \; find arch -type l -xtype l -exec rm -rf {} \;

View File

@ -0,0 +1,23 @@
[Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x14\x00n\x00e\x00t\x00c\x00t\x00l\x00-\x00g\x00u\x00i)
[CMake]
Build Directory Count=1
Current Build Directory Index=0
ProjectRootRelative=./
[CMake][CMake Build Directory 0]
Build Directory Path=file:///home/arcanis/Documents/github/netctl-gui/build
Build Type=Debug
CMake Binary=file:///usr/bin/cmake
Environment Profile=
Extra Arguments=
Install Directory=file:///usr
[Defines And Includes][Compiler]
Name=GCC
Path=gcc
Type=GCC
[Project]
VersionControlSupport=kdevgit

View File

@ -4,7 +4,7 @@
// put your languages here comma separated // put your languages here comma separated
// the first language is default language // the first language is default language
#define LANGUAGES "en,ru" #define LANGUAGES "en,ja,ru"
// language key in the configuration file // language key in the configuration file
#define LANGUAGE_KEY "LANGUAGE" #define LANGUAGE_KEY "LANGUAGE"

41
sources/3rdparty/listmap/listmap.cpp vendored Normal file
View File

@ -0,0 +1,41 @@
/***************************************************************************
* 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 "listmap.h"
QMap<QString, QString> listToMap(const QStringList list)
{
QMap<QString, QString> map;
for (int i=0; i<list.count(); i++) {
QStringList str = list[i].split(QString("=="));
if (str.count() != 2) continue;
map[str[0]] = str[1];
}
return map;
}
QStringList mapToList(const QMap<QString, QString> map)
{
QStringList list;
for (int i=0; i<map.keys().count(); i++)
list.append(QString("%1==%2").arg(map.keys()[i]).arg(map[map.keys()[i]]));
return list;
}

29
sources/3rdparty/listmap/listmap.h vendored Normal file
View File

@ -0,0 +1,29 @@
/***************************************************************************
* 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 LISTMAP_H
#define LISTMAP_H
#include <QMap>
#include <QStringList>
QMap<QString, QString> listToMap(const QStringList list);
QStringList mapToList(const QMap<QString,QString> map);
#endif /* LISTMAP_H */

View File

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8) cmake_minimum_required (VERSION 2.8.12)
cmake_policy (SET CMP0003 OLD) cmake_policy (SET CMP0003 OLD)
cmake_policy (SET CMP0002 OLD) cmake_policy (SET CMP0002 OLD)
@ -10,8 +10,8 @@ set (PROJECT_AUTHOR "Evgeniy Alekseev")
set (PROJECT_CONTACT "esalexeev@gmail.com") set (PROJECT_CONTACT "esalexeev@gmail.com")
set (PROJECT_LICENSE "GPLv3") set (PROJECT_LICENSE "GPLv3")
set (PROJECT_VERSION_MAJOR 1) set (PROJECT_VERSION_MAJOR 1)
set (PROJECT_VERSION_MINOR 3) set (PROJECT_VERSION_MINOR 4)
set (PROJECT_VERSION_PATCH 2) set (PROJECT_VERSION_PATCH 1)
set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
string (TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M" UTC) string (TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M" UTC)
string (TIMESTAMP CURRENT_YEAR "%Y") string (TIMESTAMP CURRENT_YEAR "%Y")
@ -29,21 +29,22 @@ option (BUILD_HELPER "Build helper" ON)
option (BUILD_LIBRARY "Build library" ON) option (BUILD_LIBRARY "Build library" ON)
option (BUILD_DATAENGINE "Build DataEngine" ON) option (BUILD_DATAENGINE "Build DataEngine" ON)
option (BUILD_PLASMOID "Build plasmoid" ON) option (BUILD_PLASMOID "Build plasmoid" ON)
option (BUILD_KDE4 "Build on KDE4" OFF)
if (BUILD_GUI OR BUILD_HELPER) if (BUILD_GUI OR BUILD_HELPER)
set (BUILD_LIBRARY ON) set (BUILD_LIBRARY ON)
endif () endif ()
if (BUILD_PLASMOID) if (BUILD_PLASMOID)
set (BUILD_DATAENGINE ON) set (BUILD_DATAENGINE ON)
endif () endif ()
# documentation # documentation
option (BUILD_DOCS "Build Doxygen documentation" OFF) option (BUILD_DOCS "Build Doxygen documentation" OFF)
if (BUILD_DOCS) if (BUILD_DOCS)
set (BUILD_LIBRARY ON) set (BUILD_LIBRARY ON)
endif () endif ()
# test # test
option (BUILD_TEST "Build unit tests" OFF) option (BUILD_TEST "Build unit tests" OFF)
if (BUILD_TEST) if (BUILD_TEST)
set (BUILD_LIBRARY ON) set (BUILD_LIBRARY ON)
endif () endif ()
# FIXME: dbus path # FIXME: dbus path
set (DBUS_SYSTEMCONF_PATH "/etc/dbus-1/system.d/" CACHE STRING "Path to dbus system configuration files") set (DBUS_SYSTEMCONF_PATH "/etc/dbus-1/system.d/" CACHE STRING "Path to dbus system configuration files")
@ -51,11 +52,13 @@ set (SYSTEMD_SERVICE_PATH "lib/systemd/system" CACHE STRING "Path to systemd ser
# flags # flags
if (CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_COMPILER_IS_GNUCXX)
set (CMAKE_CXX_FLAGS "-Wall -std=c++11") set (CMAKE_CXX_FLAGS "-Wall -std=c++11")
set (CMAKE_CXX_FLAGS_DEBUG "-g -O0") set (CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
# avoid newer gcc warnings
add_definitions (-D_DEFAULT_SOURCE)
else () else ()
message (STATUS "Unknown compiler") message (STATUS "Unknown compiler")
endif () endif ()
configure_file (${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h) configure_file (${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
@ -68,21 +71,25 @@ add_subdirectory (${PROJECT_RESOURCE_DIR})
# components # components
if (BUILD_LIBRARY) if (BUILD_LIBRARY)
add_subdirectory (${PROJECT_LIBRARY}) add_subdirectory (${PROJECT_LIBRARY})
endif () endif ()
if (BUILD_HELPER) if (BUILD_HELPER)
add_subdirectory (helper) add_subdirectory (helper)
endif () endif ()
if (BUILD_TEST) if (BUILD_TEST)
enable_testing () enable_testing ()
add_subdirectory (test) add_subdirectory (test)
endif () endif ()
if (BUILD_GUI) if (BUILD_GUI)
add_subdirectory (gui) add_subdirectory (gui)
endif () endif ()
if (BUILD_DATAENGINE) if (BUILD_DATAENGINE)
add_subdirectory (dataengine) add_subdirectory (dataengine)
endif () endif ()
if (BUILD_PLASMOID) if (BUILD_PLASMOID)
add_subdirectory (plasmoid) if (BUILD_KDE4)
add_subdirectory (plasmoid-kde4)
else ()
add_subdirectory (plasmoid-kf5)
endif (BUILD_KDE4)
endif () endif ()

View File

@ -3,16 +3,38 @@ set (SUBPROJECT plasma_engine_netctl)
message (STATUS "Subproject ${SUBPROJECT}") message (STATUS "Subproject ${SUBPROJECT}")
# find required libaries # find required libaries
find_package (KDE4 REQUIRED) if (BUILD_KDE4)
include (KDE4Defaults) find_package (KDE4 REQUIRED)
include (KDE4Defaults)
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
set (KDE_INCLUDE ${KDE4_INCLUDES})
else ()
find_package (Qt5 REQUIRED COMPONENTS Widgets Network)
find_package (ECM 0.0.11 REQUIRED NO_MODULE)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
find_package(KF5 REQUIRED COMPONENTS Plasma Service)
include (KDEInstallDirs)
include (KDECMakeSettings)
include (KDECompilerSettings)
add_definitions (${Qt5Core_DEFINITIONS} ${Qt5Network_DEFINITIONS})
set (Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS})
set (KDE_INCLUDE ${ConfigCore_INCLUDE_DIR}
${CoreAddons_INCLUDE_DIR}
${Plasma_INCLUDE_DIR}
${Service_INCLUDE_DIR})
endif ()
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories (${CMAKE_SOURCE_DIR} include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${KDE4_INCLUDES}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../ ${CMAKE_CURRENT_BINARY_DIR}/../
${PROJECT_TRDPARTY_DIR}) ${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${KDE_INCLUDE})
set (PLUGIN_NAME ${SUBPROJECT}) set (PLUGIN_NAME ${SUBPROJECT})
file (GLOB SUBPROJECT_DESKTOP_IN *.desktop) file (GLOB SUBPROJECT_DESKTOP_IN *.desktop)
@ -25,11 +47,22 @@ file (GLOB SUBPROJECT_CONF *.conf)
configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}) configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
# make # make
qt4_wrap_cpp (TASK_MOC_SOURCE ${TASK_HEADER}) if (BUILD_KDE4)
kde4_add_plugin (${PLUGIN_NAME} ${SUBPROJECT_SOURCE} ${TASK_MOC_SOURCE}) qt4_wrap_cpp (TASK_MOC_SOURCE ${TASK_HEADER})
target_link_libraries (${PLUGIN_NAME} ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS} ${QT_QTNETWORK_LIBRARY}) kde4_add_plugin (${PLUGIN_NAME} ${SUBPROJECT_SOURCE} ${TASK_MOC_SOURCE})
target_link_libraries (${PLUGIN_NAME} ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS} ${QT_QTNETWORK_LIBRARY})
else ()
qt5_wrap_cpp (TASK_MOC_SOURCE ${TASK_HEADER})
add_library (${PLUGIN_NAME} MODULE ${SUBPROJECT_SOURCE} ${TASK_MOC_SOURCE})
target_link_libraries (${PLUGIN_NAME} ${Plasma_LIBRARIES} ${Qt5Network_LIBRARIES})
kcoreaddons_desktop_to_json (${PLUGIN_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
endif ()
# install # install
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR}) if (BUILD_KDE4)
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR})
else ()
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR}/plasma/dataengine)
endif ()
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR}) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR})
install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR}) install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR})

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<libraries>
<library>qt</library>
</libraries>
</project>

View File

@ -1,17 +0,0 @@
# Configuration file for netctl data engine
## Commands
# command
NETCTLCMD=/usr/bin/netctl
# netctl-auto command
NETCTLAUTOCMD=/usr/bin/netctl-auto
## External IP
# external IPv4 check command
EXTIP4CMD=curl ip4.telize.com
# 'true' - check external IPv4
EXTIP4=false
# external IPv6 check command
EXTIP6CMD=curl ip6.telize.com
# 'true' - check external IPv6
EXTIP6=false

View File

@ -17,18 +17,26 @@
#include "netctl.h" #include "netctl.h"
#include <KGlobal>
#include <KStandardDirs>
#include <Plasma/DataContainer> #include <Plasma/DataContainer>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QNetworkInterface> #include <QNetworkInterface>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QSettings>
#include <QTextCodec> #include <QTextCodec>
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include <task/taskadds.h> #include <task/taskadds.h>
#include <version.h>
// KF5-KDE4 compability
#ifdef BUILD_KDE4
#include <KGlobal>
#include <KStandardDirs>
#else
#include <QStandardPaths>
#endif /* BUILD_KDE4 */
Netctl::Netctl(QObject *parent, const QVariantList &args) Netctl::Netctl(QObject *parent, const QVariantList &args)
@ -38,14 +46,12 @@ Netctl::Netctl(QObject *parent, const QVariantList &args)
// debug // debug
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QString debugEnv = environment.value(QString("NETCTLGUI_DEBUG"), QString("no")); QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
if (debugEnv == QString("yes")) debug = (debugEnv == QString("yes"));
debug = true;
else
debug = false;
setMinimumPollingInterval(333); setMinimumPollingInterval(333);
readConfiguration(); readConfiguration();
initSources();
} }
@ -64,6 +70,7 @@ QStringList Netctl::sources() const
sources.append(QString("current")); sources.append(QString("current"));
sources.append(QString("extip4")); sources.append(QString("extip4"));
sources.append(QString("extip6")); sources.append(QString("extip6"));
sources.append(QString("info"));
sources.append(QString("interfaces")); sources.append(QString("interfaces"));
sources.append(QString("intip4")); sources.append(QString("intip4"));
sources.append(QString("intip6")); sources.append(QString("intip6"));
@ -75,71 +82,44 @@ QStringList Netctl::sources() const
} }
QString Netctl::getCmdOutput(const QString cmd)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
TaskResult process = runTask(cmd);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return QTextCodec::codecForMib(106)->toUnicode(process.output);
}
void Netctl::readConfiguration() void Netctl::readConfiguration()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
// default configuration QString fileName;
QMap<QString, QString> rawConfig; #ifdef BUILD_KDE4
rawConfig[QString("EXTIP4")] = QString("false"); fileName = KGlobal::dirs()->findResource("config", "plasma-dataengine-netctl.conf");
rawConfig[QString("EXTIP4CMD")] = QString("curl ip4.telize.com"); #else
rawConfig[QString("EXTIP6")] = QString("false"); fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString("plasma-dataengine-netctl.conf"));
rawConfig[QString("EXTIP6CMD")] = QString("curl ip6.telize.com"); #endif /* BUILD_KDE4 */
rawConfig[QString("NETCTLCMD")] = QString("/usr/bin/netctl");
rawConfig[QString("NETCTLAUTOCMD")] = QString("/usr/bin/netctl-auto");
QString fileName = KGlobal::dirs()->findResource("config", "netctl.conf");
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName; if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
QFile configFile(fileName); QSettings settings(fileName, QSettings::IniFormat);
if (!configFile.open(QIODevice::ReadOnly)) {
configuration = updateConfiguration(rawConfig);
return;
}
QString fileStr;
QStringList value;
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('='))) {
value.clear();
for (int i=1; i<fileStr.split(QChar('=')).count(); i++)
value.append(fileStr.split(QChar('='))[i]);
rawConfig[fileStr.split(QChar('='))[0]] = value.join(QChar('='));
}
if (configFile.atEnd()) break;
}
configFile.close();
configuration = updateConfiguration(rawConfig);
return; settings.beginGroup(QString("Netctl commands"));
} configuration[QString("NETCTLCMD")] = settings.value(QString("NETCTLCMD"), QString("/usr/bin/netctl")).toString();
configuration[QString("NETCTLAUTOCMD")] = settings.value(QString("NETCTLAUTOCMD"), QString("/usr/bin/netctl-auto")).toString();
settings.endGroup();
settings.beginGroup(QString("External IP"));
QMap<QString, QString> Netctl::updateConfiguration(const QMap<QString, QString> rawConfig) configuration[QString("EXTIP4")] = settings.value(QString("EXTIP4"), QString("false")).toString();
{ configuration[QString("EXTIP4CMD")] = settings.value(QString("EXTIP4CMD"), QString("curl ip4.telize.com")).toString();
if (debug) qDebug() << PDEBUG; configuration[QString("EXTIP6")] = settings.value(QString("EXTIP6"), QString("false")).toString();
configuration[QString("EXTIP6CMD")] = settings.value(QString("EXTIP6CMD"), QString("curl ip6.telize.com")).toString();
QMap<QString, QString> config; settings.endGroup();
QString key, value;
// remove spaces and copy source map
for (int i=0; i<rawConfig.keys().count(); i++) {
key = rawConfig.keys()[i];
value = rawConfig[key];
key.remove(QChar(' '));
if ((key != QString("EXTIP4CMD")) &&
(key != QString("EXTIP6CMD")) &&
(key != QString("NETCTLCMD")) &&
(key != QString("NETCTLAUTOCMD")))
value.remove(QChar(' '));
config[key] = value;
}
for (int i=0; i<config.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << config.keys()[i] + QString("=") + config[config.keys()[i]];
return config;
} }
@ -152,46 +132,29 @@ bool Netctl::sourceRequestEvent(const QString &name)
} }
QStringList Netctl::getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto)
{
if (debug) qDebug() << PDEBUG;
getNetctlAutoStatus(cmdNetctlAuto);
QString cmd;
if (netctlAutoStatus)
cmd = cmdNetctlAuto;
else
cmd = cmdNetctl;
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
TaskResult process = runTask(cmd + QString(" list"));
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
QStringList currentProfile;
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output);
QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts);
for (int i=0; i<profileList.count(); i++)
if (profileList[i][0] == QChar('*'))
currentProfile.append(profileList[i]);
for (int i=0; i<currentProfile.count(); i++)
currentProfile[i].remove(0, 2);
return currentProfile;
}
QString Netctl::getExtIp(const QString cmd) QString Netctl::getExtIp(const QString cmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
TaskResult process = runTask(cmd); // test network connection
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (!isNetworkActive()) return QString("N\\A");
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
QString extIp = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
return extIp; return getCmdOutput(cmd).trimmed();
}
QString Netctl::getInfo(const QStringList profiles, const QStringList statuses)
{
if (debug) qDebug() << PDEBUG;
if (profiles.count() != statuses.count()) return QString("N\\A");
QStringList list;
for (int i=0; i<profiles.count(); i++)
list.append(QString("%1 (%2)").arg(profiles[i]).arg(statuses[i]));
if (list.isEmpty()) list.append(QString("N\\A"));
return list.join(QString(" | "));
} }
@ -221,99 +184,91 @@ QString Netctl::getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol)
for (int i=0; i<rawList.count(); i++) { for (int i=0; i<rawList.count(); i++) {
if(rawList[i] == QHostAddress(QHostAddress::LocalHost)) continue; if(rawList[i] == QHostAddress(QHostAddress::LocalHost)) continue;
if(rawList[i] == QHostAddress(QHostAddress::LocalHostIPv6)) continue; if(rawList[i] == QHostAddress(QHostAddress::LocalHostIPv6)) continue;
if (rawList[i].protocol() == protocol) { if (rawList[i].protocol() != protocol) continue;
intIp = rawList[i].toString(); intIp = rawList[i].toString();
break; break;
}
} }
return intIp; return intIp;
} }
QString Netctl::getNetctlAutoStatus(const QString cmdNetctlAuto)
{
if (debug) qDebug() << PDEBUG;
TaskResult process = runTask(cmdNetctlAuto + QString(" list"));
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
QString status;
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output);
if (cmdOutput.isEmpty()) {
netctlAutoStatus = false;
status = QString("false");
} else {
netctlAutoStatus = true;
status = QString("true");
}
return status;
}
QStringList Netctl::getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto) QStringList Netctl::getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
getNetctlAutoStatus(cmdNetctlAuto);
QString cmd; netctlAutoStatus = true;
if (netctlAutoStatus) QString output = getCmdOutput(QString("%1 list").arg(cmdNetctlAuto));
cmd = cmdNetctlAuto; if (output.isEmpty()) {
else output = getCmdOutput(QString("%1 list").arg(cmdNetctl));
cmd = cmdNetctl; netctlAutoStatus = false;
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd; }
TaskResult process = runTask(cmd + QString(" list")); qDebug() << output;
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0) // parse
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; QStringList currentProfiles;
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output); QStringList profileList = output.split(QChar('\n'), QString::SkipEmptyParts);
QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts); for (int i=0; i<profileList.count(); i++) {
if (profileList[i][0] != QChar('*')) continue;
currentProfiles.append(profileList[i]);
}
// remove first symbols
for (int i=0; i<profileList.count(); i++) for (int i=0; i<profileList.count(); i++)
profileList[i].remove(0, 2); profileList[i].remove(0, 2);
for (int i=0; i<currentProfiles.count(); i++)
currentProfiles[i].remove(0, 2);
// return profiles
currentProfile = currentProfiles;
status = !currentProfiles.isEmpty();
return profileList; return profileList;
} }
QStringList Netctl::getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto) QStringList Netctl::getProfileStringStatus(const QString cmdNetctl)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
getNetctlAutoStatus(cmdNetctlAuto);
QStringList status; QStringList status;
if (netctlAutoStatus) if (netctlAutoStatus) {
status.append(QString("netctl-auto")); status.append(QString("netctl-auto"));
else { return status;
QStringList profiles = getCurrentProfile(cmdNetctl, cmdNetctlAuto); }
for (int i=0; i<profiles.count(); i++) {
TaskResult process = runTask(cmdNetctl + QString(" is-enabled ") + profiles[i]); for (int i=0; i<currentProfile.count(); i++) {
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; TaskResult process = runTask(QString("%1 is-enabled %2").arg(cmdNetctl).arg(currentProfile[i]));
if (process.exitCode != 0) if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode != 0) {
if (process.exitCode == 0) if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
status.append(QString("enabled")); status.append(QString("static"));
else } else
status.append(QString("static")); status.append(QString("enabled"));
}
} }
return status; return status;
} }
QString Netctl::getStatus(const QString cmdNetctl, const QString cmdNetctlAuto) void Netctl::initSources()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
getNetctlAutoStatus(cmdNetctlAuto);
QString status = QString("false"); QStringList sourcesList = sources();
QStringList currentProfile = getCurrentProfile(cmdNetctl, cmdNetctlAuto); for (int i=0; i<sourcesList.count(); i++)
if (!currentProfile.isEmpty()) setData(sourcesList[i], QString("value"), QString("N\\A"));
status = QString("true"); }
return status;
bool Netctl::isNetworkActive()
{
if (debug) qDebug() << PDEBUG;
QString cmd = QString("ping -c 1 google.com");
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
TaskResult process = runTask(cmd);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
return (process.exitCode == 0);
} }
@ -324,18 +279,17 @@ bool Netctl::updateSourceEvent(const QString &source)
QString value = QString("N\\A"); QString value = QString("N\\A");
if (source == QString("active")) { if (source == QString("active")) {
value = getStatus(configuration[QString("NETCTLCMD")], value = status ? QString("true") : QString("false");
configuration[QString("NETCTLAUTOCMD")]);
} else if (source == QString("current")) { } else if (source == QString("current")) {
value = getCurrentProfile(configuration[QString("NETCTLCMD")], value = currentProfile.join(QChar('|'));
configuration[QString("NETCTLAUTOCMD")])
.join(QChar('|'));
} else if (source == QString("extip4")) { } else if (source == QString("extip4")) {
if (configuration[QString("EXTIP4")] == QString("true")) if (configuration[QString("EXTIP4")] == QString("true"))
value = getExtIp(configuration[QString("EXTIP4CMD")]); value = getExtIp(configuration[QString("EXTIP4CMD")]);
} else if (source == QString("extip6")) { } else if (source == QString("extip6")) {
if (configuration[QString("EXTIP6")] == QString("true")) if (configuration[QString("EXTIP6")] == QString("true"))
value = getExtIp(configuration[QString("EXTIP6CMD")]); value = getExtIp(configuration[QString("EXTIP6CMD")]);
} else if (source == QString("info")) {
value = getInfo(currentProfile, currentStatus);
} else if (source == QString("interfaces")) { } else if (source == QString("interfaces")) {
value = getInterfaceList().join(QChar(',')); value = getInterfaceList().join(QChar(','));
} else if (source == QString("intip4")) { } else if (source == QString("intip4")) {
@ -343,15 +297,13 @@ bool Netctl::updateSourceEvent(const QString &source)
} else if (source == QString("intip6")) { } else if (source == QString("intip6")) {
value = getIntIp(QAbstractSocket::IPv6Protocol); value = getIntIp(QAbstractSocket::IPv6Protocol);
} else if (source == QString("netctlauto")) { } else if (source == QString("netctlauto")) {
value = getNetctlAutoStatus(configuration[QString("NETCTLAUTOCMD")]); value = netctlAutoStatus ? QString("true") : QString("false");
} else if (source == QString("profiles")) { } else if (source == QString("profiles")) {
value = getProfileList(configuration[QString("NETCTLCMD")], value = getProfileList(configuration[QString("NETCTLCMD")],
configuration[QString("NETCTLAUTOCMD")]) configuration[QString("NETCTLAUTOCMD")]).join(QChar(','));
.join(QChar(','));
} else if (source == QString("status")) { } else if (source == QString("status")) {
value = getProfileStringStatus(configuration[QString("NETCTLCMD")], currentStatus = getProfileStringStatus(configuration[QString("NETCTLCMD")]);
configuration[QString("NETCTLAUTOCMD")]) value = currentStatus.join(QChar('|'));
.join(QChar('|'));
} }
setData(source, QString("value"), value); setData(source, QString("value"), value);
@ -359,6 +311,10 @@ bool Netctl::updateSourceEvent(const QString &source)
} }
#ifdef BUILD_KDE4
K_EXPORT_PLASMA_DATAENGINE(netctl, Netctl) K_EXPORT_PLASMA_DATAENGINE(netctl, Netctl)
#else
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(netctl, Netctl, "plasma-dataengine-netctl.json")
#endif /* BUILD_KDE4 */
#include "netctl.moc" #include "netctl.moc"

View File

@ -29,14 +29,16 @@ class Netctl : public Plasma::DataEngine
public: public:
Netctl(QObject *parent, const QVariantList &args); Netctl(QObject *parent, const QVariantList &args);
~Netctl(); ~Netctl();
QStringList getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto);
QString getExtIp(const QString cmd); QString getExtIp(const QString cmd);
QString getInfo(const QStringList profiles, const QStringList statuses);
QStringList getInterfaceList(); QStringList getInterfaceList();
QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol); QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol);
QString getNetctlAutoStatus(const QString cmdNetctlAuto);
QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto); QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto);
QStringList getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto); QStringList getProfileStringStatus(const QString cmdNetctl);
QString getStatus(const QString cmdNetctl, const QString cmdNetctlAuto); bool isNetworkActive();
public slots:
void initSources();
protected: protected:
bool sourceRequestEvent(const QString &name); bool sourceRequestEvent(const QString &name);
@ -44,13 +46,15 @@ protected:
QStringList sources() const; QStringList sources() const;
private: private:
bool netctlAutoStatus; bool netctlAutoStatus = false;
QString currentProfile; bool status = false;
QStringList currentProfile;
QStringList currentStatus;
// configuration // configuration
bool debug; bool debug;
QMap<QString, QString> configuration; QMap<QString, QString> configuration;
QString getCmdOutput(const QString cmd);
void readConfiguration(); void readConfiguration();
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);
}; };

View File

@ -0,0 +1,9 @@
[Netctl commands]
NETCTLCMD=/usr/bin/netctl
NETCTLAUTOCMD=/usr/bin/netctl-auto
[External IP]
EXTIP4CMD=curl ip4.telize.com
EXTIP4=false
EXTIP6CMD=curl ip6.telize.com
EXTIP6=false

View File

@ -10,11 +10,11 @@ X-KDE-ServiceTypes=Plasma/DataEngine
X-KDE-Library=plasma_engine_netctl X-KDE-Library=plasma_engine_netctl
X-Plasma-EngineName=netctl X-Plasma-EngineName=netctl
X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis X-KDE-PluginInfo-Author=Evgeniy Alekseev
X-KDE-PluginInfo-Email=esalexeev@gmail.com X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=netctl X-KDE-PluginInfo-Name=netctl
X-KDE-PluginInfo-Version=@PROJECT_VERSION@ X-KDE-PluginInfo-Version=@PROJECT_VERSION@
X-KDE-PluginInfo-Website=http://arcan1s.github.io/projects/netctlplasmoid X-KDE-PluginInfo-Website=http://arcanis.name/projects/netctl-gui/
X-KDE-PluginInfo-Category=Network X-KDE-PluginInfo-Category=Network
X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPLv3 X-KDE-PluginInfo-License=GPLv3

View File

@ -1,12 +1,12 @@
# build pages # build pages
file (GLOB SUBPROJECT_DOCS_IN *.html) file (GLOB SUBPROJECT_DOCS_IN *.html)
file (GLOB SUBPROJECT_IMGS *.png) file (GLOB SUBPROJECT_IMGS *.png)
foreach (DOC_IN ${SUBPROJECT_DOCS_IN})
file (RELATIVE_PATH ONE_DOC ${CMAKE_SOURCE_DIR} ${DOC_IN})
configure_file (${DOC_IN} ${CMAKE_CURRENT_BINARY_DIR}/${ONE_DOC})
set (SUBPROJECT_DOCS ${SUBPROJECT_DOCS} ${CMAKE_CURRENT_BINARY_DIR}/${ONE_DOC})
endforeach ()
foreach (DOC_IN ${SUBPROJECT_DOCS_IN})
file (RELATIVE_PATH ONE_DOC ${CMAKE_SOURCE_DIR} ${DOC_IN})
configure_file (${DOC_IN} ${CMAKE_CURRENT_BINARY_DIR}/${ONE_DOC})
set (SUBPROJECT_DOCS ${SUBPROJECT_DOCS} ${CMAKE_CURRENT_BINARY_DIR}/${ONE_DOC})
endforeach ()
install (FILES ${SUBPROJECT_DOCS} DESTINATION share/doc/${PROJECT_NAME}) install (FILES ${SUBPROJECT_DOCS} DESTINATION share/doc/${PROJECT_NAME})
install (FILES ${SUBPROJECT_IMGS} DESTINATION share/doc/${PROJECT_NAME}) install (FILES ${SUBPROJECT_IMGS} DESTINATION share/doc/${PROJECT_NAME})

View File

@ -35,6 +35,7 @@ small {
<li><a href="#api">DBus API</a></li> <li><a href="#api">DBus API</a></li>
<li><a href="#helper">Helper API</a></li> <li><a href="#helper">Helper API</a></li>
<li><a href="#ctrl">Helper ctrl API</a></li> <li><a href="#ctrl">Helper ctrl API</a></li>
<li><a href="#interface">Helper interface API</a></li>
<li><a href="#netctl">Helper netctl API</a></li> <li><a href="#netctl">Helper netctl API</a></li>
<li><a href="#gui">GUI API</a></li> <li><a href="#gui">GUI API</a></li>
<li><a href="#netctlgui">GUI netctlgui API</a></li> <li><a href="#netctlgui">GUI netctlgui API</a></li>
@ -74,7 +75,7 @@ small {
</tr> </tr>
<tr> <tr>
<td>QStringList FindSettings()</td> <td>QStringList FindSettings()</td>
<td>scans system and suggests the recommended configuration which will be used by the library</td> <td>scans system and suggests the recommended configuration which may be used by the library</td>
<td>no</td> <td>no</td>
</tr> </tr>
<tr> <tr>
@ -196,11 +197,93 @@ small {
<td>yes</td> <td>yes</td>
</tr> </tr>
<!-- wpa_supplicant actions --> <!-- wpa_supplicant actions -->
<tr>
<td>QStringList CurrentWiFi()</td>
<td>returns current WiFi point in format <code>NAME|SECURITY|TYPE|FREQ|MAC|SIGNAL|ACTIVE|EXISTS</code></td>
<td>yes</td>
</tr>
<tr>
<td>QStringList VerboseWiFi()</td>
<td>returns available WiFi points in format <code>NAME|SECURITY|TYPE|FREQS|MACS|SIGNAL|ACTIVE|EXISTS</code>. First line is always active connection (see <code>CurrentWiFi()</code>)</td>
<td>yes</td>
</tr>
<tr> <tr>
<td>QStringList WiFi()</td> <td>QStringList WiFi()</td>
<td>returns available WiFi points in format <code>NAME|SECURITY|SIGNAL|ACTIVE|EXISTS</code></td> <td>returns available WiFi points in format <code>NAME|SECURITY|SIGNAL|ACTIVE|EXISTS</code></td>
<td>yes</td> <td>yes</td>
</tr> </tr>
<!-- /interface path -->
<tr>
<th colspan="3" class="sub"><a href="#interface" class="anchor" id="interface"></a><code>/interface</code> path</th>
</tr>
<!-- netctl control -->
<tr>
<td>int Enable(QString profile)</td>
<td>enables or disables the profile. Returns is the profile enabled or <code>2</code> if there was an another error</td>
<td>yes</td>
</tr>
<tr>
<td>int Restart(QString profile)</td>
<td>restarts the profile. Returns is the profile active or <code>2</code> if there was an error</td>
<td>yes</td>
</tr>
<tr>
<td>int Start(QString profile)</td>
<td>starts or stops the profile. Returns is the profile active or <code>2</code> if there was an error</td>
<td>yes</td>
</tr>
<tr>
<td>bool StopAll()</td>
<td>synonym of <code>/ctlr/StopAll()</code></td>
<td>yes</td>
</tr>
<tr>
<td>bool SwitchTo(QString profile)</td>
<td>switchs to the profile (works with netctl and netctl-auto). Returns is the profile active or <code>2</code> if there was an error</td>
<td>yes</td>
</tr>
<tr>
<td>int Create(QString profile, QStringList settingsList)</td>
<td>>creates the profile with specified settings. Settings should be given in the format <code>KEY==VALUE</code>. Returns <code>1</code> if action has been performed successfully, <code>0</code> if there was an error in the profile copying and <code>2</code> if there was an another error</td>
<td>yes</td>
</tr>
<tr>
<td>QStringList Profile(QString profile)</td>
<td>synonym of <code>/netctl/Profile()</code></td>
<td>no</td>
</tr>
<tr>
<td>int Remove(QString profile)</td>
<td>synonym of <code>/ctrl/Remove()</code></td>
<td>yes</td>
</tr>
<!-- information -->
<tr>
<td>QStringList Information()</td>
<td>returns general information in format <code>[IsNetctlAutoActive, NetctlProfiles, NetctlAutoProfiles]</code></td>
<td>no</td>
</tr>
<tr>
<td>QStringList Status()</td>
<td>returns actual information in format <code>[IsNetctlAutoActive, ProfilesNames, ActiveProfile, ActiveProfileEnables]</code></td>
<td>no</td>
</tr>
<!-- wpa_supplicant actions -->
<tr>
<td>int Essid(QString essid, QStringList settingsList)</td>
<td>connects to WiFi point with the given ESSID, calls KnownEssid or UnknownESSID depending on whether there is a profile. Settings may be empty. To get return codes refer to <code>KnownEssid()</code> and <code>UnknownEssid()</code></td>
<td>yes</td>
</tr>
<tr>
<td>int KnownEssid(QString essid)</td>
<td>connects to WiFi point with the given ESSID with existent profile. Returns <code>Start()</code> if ok, in other cases returns <code>2</code></td>
<td>yes</td>
</tr>
<tr>
<td>int UnknownEssid(QString essid, QStringList settingsList)</td>
<td>creates a profile and connects to WiFi point with the given ESSID. Returns <code>Start()</code> if ok, in other cases returns <code>2</code></td>
<td>yes</td>
</tr>
<!-- /netctl path --> <!-- /netctl path -->
<tr> <tr>
<th colspan="3" class="sub"><a href="#netctl" class="anchor" id="netctl"></a><code>/netctl</code> path</th> <th colspan="3" class="sub"><a href="#netctl" class="anchor" id="netctl"></a><code>/netctl</code> path</th>
@ -221,11 +304,31 @@ small {
<td>returns general information in format <code>[ActiveProfile, ActiveProfileStatus]</code></td> <td>returns general information in format <code>[ActiveProfile, ActiveProfileStatus]</code></td>
<td>no</td> <td>no</td>
</tr> </tr>
<tr>
<td>QString netctlActiveProfile()</td>
<td>returns active profile from netctl even if netctl-auto is running</td>
<td>no</td>
</tr>
<tr>
<td>QStringList netctlProfileList()</td>
<td>returns available profiles in format <code>NAME|DESCRIPTION|ACTIVE|ENABLED</code> from netctl even if netctl-auto is running</td>
<td>no</td>
</tr>
<tr>
<td>QStringList netctlVerboseProfileList()</td>
<td>returns available profiles in format <code>NAME|DESCRIPTION|TYPE|INTERFACE|ESSID|ACTIVE|ENABLED|NETCTL-AUTO</code> from netctl even if netctl-auto is running</td>
<td>no</td>
</tr>
<tr> <tr>
<td>QStringList ProfileList()</td> <td>QStringList ProfileList()</td>
<td>returns available profiles in format <code>NAME|DESCRIPTION|ACTIVE|ENABLED</code></td> <td>returns available profiles in format <code>NAME|DESCRIPTION|ACTIVE|ENABLED</code></td>
<td>no</td> <td>no</td>
</tr> </tr>
<tr>
<td>QStringList VerboseProfileList()</td>
<td>returns available profiles in format <code>NAME|DESCRIPTION|TYPE|INTERFACE|ESSID|ACTIVE|ENABLED|NETCTL-AUTO</code></td>
<td>no</td>
</tr>
<tr> <tr>
<td>QStringList WirelessInterface()</td> <td>QStringList WirelessInterface()</td>
<td>returns wireless interfaces</td> <td>returns wireless interfaces</td>
@ -279,11 +382,15 @@ small {
<td>returns value of the key by the given profile or empty line</td> <td>returns value of the key by the given profile or empty line</td>
<td>no</td> <td>no</td>
</tr> </tr>
<tr>
<td>QStringList ProfileValues(QString profile, QStringList keys)</td>
<td>returns values of the keys by the given profile or empty lines</td>
<td>no</td>
</tr>
<!-- gui service --> <!-- gui service -->
<tr> <tr>
<th colspan="3"><a href="#gui" class="anchor" id="gui"></a><code>org.netctlgui.netctlgui</code> service (session bus)</th> <th colspan="3"><a href="#gui" class="anchor" id="gui"></a><code>org.netctlgui.netctlgui</code> service (session bus)</th>
</tr> </tr>
<!-- /netctlgui path -->
<tr> <tr>
<th colspan="3" class="sub"><a href="#netctlgui" class="anchor" id="netctlgui"></a><code>/netctlgui</code> path</th> <th colspan="3" class="sub"><a href="#netctlgui" class="anchor" id="netctlgui"></a><code>/netctlgui</code> path</th>
</tr> </tr>
@ -303,11 +410,6 @@ small {
<td><code>true</code> and closes the application</td> <td><code>true</code> and closes the application</td>
<td>no</td> <td>no</td>
</tr> </tr>
<tr>
<td>QString Information()</td>
<td>returns general information in format <code>[ActiveProfile, ActiveProfileStatus]</code></td>
<td>no</td>
</tr>
<tr> <tr>
<td>void LibraryDocs()</td> <td>void LibraryDocs()</td>
<td>opens the library documentation</td> <td>opens the library documentation</td>
@ -358,11 +460,6 @@ small {
<td>returns the application process UIDs <code>[UID, EUID]</code></td> <td>returns the application process UIDs <code>[UID, EUID]</code></td>
<td>no</td> <td>no</td>
</tr> </tr>
<tr>
<td>QStringList VerboseInformation()</td>
<td>returns information in format <code>[isNetctlAutoActive, ProfileList, ActiveProfile, isProfileEnabled/autoIsProfileEnabled]</code></td>
<td>no</td>
</tr>
</table> </table>
<h2><a href="#links" class="anchor" id="links"></a>External links</h2> <h2><a href="#links" class="anchor" id="links"></a>External links</h2>
@ -378,4 +475,4 @@ small {
</small> </small>
</body> </body>
</html> </html>

View File

@ -1,6 +1,7 @@
# set files # set files
file (GLOB_RECURSE SOURCES *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp file (GLOB_RECURSE SOURCES *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp
${PROJECT_TRDPARTY_DIR}/language/*.cpp) ${PROJECT_TRDPARTY_DIR}/language/*.cpp
${PROJECT_TRDPARTY_DIR}/listmap/*.cpp)
file (GLOB_RECURSE HEADERS *.h ${PROJECT_TRDPARTY_DIR}/task/*.h file (GLOB_RECURSE HEADERS *.h ${PROJECT_TRDPARTY_DIR}/task/*.h
${PROJECT_TRDPARTY_DIR}/language/*.h) ${PROJECT_TRDPARTY_DIR}/language/*.h)
file (GLOB_RECURSE FORMS *.ui ${PROJECT_TRDPARTY_DIR}/about/*.ui) file (GLOB_RECURSE FORMS *.ui ${PROJECT_TRDPARTY_DIR}/about/*.ui)
@ -18,40 +19,40 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/includ
link_directories (${PROJECT_LIBRARY}/src/lib) link_directories (${PROJECT_LIBRARY}/src/lib)
if (USE_QT5) if (USE_QT5)
find_package(Qt5 COMPONENTS Core DBus Widgets LinguistTools REQUIRED) find_package (Qt5 COMPONENTS Core DBus Widgets LinguistTools REQUIRED)
add_definitions(${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5LinguistTools_DEFINITIONS}) add_definitions (${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5LinguistTools_DEFINITIONS})
include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Widgets_LIBRARIES}) set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Widgets_LIBRARIES})
qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) qt5_wrap_cpp (MOC_SOURCES ${HEADERS})
qt5_wrap_ui (UI_HEADERS ${FORMS}) qt5_wrap_ui (UI_HEADERS ${FORMS})
qt5_add_resources (QRC_SOURCES ${RESOURCES}) qt5_add_resources (QRC_SOURCES ${RESOURCES})
foreach (LANGUAGE ${LANGUAGES}) foreach (LANGUAGE ${LANGUAGES})
set (TS ${LANGUAGE}) set (TS ${LANGUAGE})
string (REPLACE ".ts" ".qm" QM ${TS}) string (REPLACE ".ts" ".qm" QM ${TS})
set (TRANSLATIONS ${TRANSLATIONS} ${TS}) set (TRANSLATIONS ${TRANSLATIONS} ${TS})
set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM}) set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM})
add_custom_command (OUTPUT ${QM} COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS}) add_custom_command (OUTPUT ${QM} COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS})
endforeach () endforeach ()
add_custom_target (translations COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} ${UI_HEADERS} -ts ${TRANSLATIONS}) add_custom_target (translations COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} ${UI_HEADERS} -ts ${TRANSLATIONS})
add_custom_command (TARGET translations COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TRANSLATIONS}) add_custom_command (TARGET translations COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TRANSLATIONS})
else () else ()
find_package (Qt4 COMPONENTS QtCore QtDBus QtGui REQUIRED) find_package (Qt4 COMPONENTS QtCore QtDBus QtGui REQUIRED)
include (${QT_USE_FILE}) include (${QT_USE_FILE})
set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_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_cpp (MOC_SOURCES ${HEADERS})
qt4_wrap_ui (UI_HEADERS ${FORMS}) qt4_wrap_ui (UI_HEADERS ${FORMS})
qt4_add_resources (QRC_SOURCES ${RESOURCES}) qt4_add_resources (QRC_SOURCES ${RESOURCES})
foreach (LANGUAGE ${LANGUAGES}) foreach (LANGUAGE ${LANGUAGES})
set (TS ${LANGUAGE}) set (TS ${LANGUAGE})
string (REPLACE ".ts" ".qm" QM ${TS}) string (REPLACE ".ts" ".qm" QM ${TS})
set (TRANSLATIONS ${TRANSLATIONS} ${TS}) set (TRANSLATIONS ${TRANSLATIONS} ${TS})
set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM}) set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM})
add_custom_command (OUTPUT ${QM} COMMAND ${QT_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS}) add_custom_command (OUTPUT ${QM} COMMAND ${QT_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS})
endforeach () endforeach ()
add_custom_target (translations COMMAND ${QT_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} ${UI_HEADERS} -ts ${TRANSLATIONS}) add_custom_target (translations COMMAND ${QT_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} ${UI_HEADERS} -ts ${TRANSLATIONS})
add_custom_command (TARGET translations COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS}) add_custom_command (TARGET translations COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS})
endif() endif()
add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS}) add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS})

View File

@ -40,26 +40,16 @@ void BridgeWidget::clear()
} }
void BridgeWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
QMap<QString, QString> BridgeWidget::getSettings() QMap<QString, QString> BridgeWidget::getSettings()
{ {
QMap<QString, QString> bridgeSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return bridgeSettings;
if (ui->checkBox_skip->checkState() == Qt::Checked) if (ui->checkBox_skip->checkState() == Qt::Checked)
bridgeSettings[QString("SkipForwardingDelay")] = QString("yes"); settings[QString("SkipForwardingDelay")] = QString("yes");
return bridgeSettings; return settings;
} }
@ -73,9 +63,8 @@ int BridgeWidget::isOk()
void BridgeWidget::setSettings(const QMap<QString, QString> settings) void BridgeWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> bridgeSettings = settings;
if (bridgeSettings.contains(QString("SkipForwardingDelay"))) if (settings.contains(QString("SkipForwardingDelay")))
if (bridgeSettings[QString("SkipForwardingDelay")] == QString("yes")) if (settings[QString("SkipForwardingDelay")] == QString("yes"))
ui->checkBox_skip->setCheckState(Qt::Checked); ui->checkBox_skip->setCheckState(Qt::Checked);
} }

View File

@ -38,7 +38,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private: private:
Ui::BridgeWidget *ui; Ui::BridgeWidget *ui;

View File

@ -6,14 +6,14 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>424</width> <width>550</width>
<height>76</height> <height>44</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_bridge"> <widget class="QDockWidget" name="dockWidget_bridge">
<property name="features"> <property name="features">
@ -24,15 +24,38 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_bridge"> <widget class="QWidget" name="dockWidgetContents_bridge">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QCheckBox" name="checkBox_skip"> <layout class="QHBoxLayout" name="layout_skip">
<property name="toolTip"> <item>
<string>Skip (R)STP and immediately activate all bridge members</string> <widget class="QLabel" name="labe_skip">
</property> <property name="sizePolicy">
<property name="text"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<string>Skip forwarding delay</string> <horstretch>1</horstretch>
</property> <verstretch>0</verstretch>
</widget> </sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_skip">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Skip (R)STP and immediately activate all bridge members</string>
</property>
<property name="text">
<string>Skip forwarding delay</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>

243
sources/gui/src/calls.cpp Normal file
View File

@ -0,0 +1,243 @@
/***************************************************************************
* 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 "calls.h"
#include <QDebug>
#include <listmap/listmap.h>
#include <pdebug/pdebug.h>
#include "dbusoperation.h"
InterfaceAnswer createProfileSlot(const QString profile, QMap<QString,QString> settings,
NetctlInterface* interface, const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (!useHelper) return interface->createProfile(profile, settings);
try {
QList<QVariant> args;
args.append(profile);
args.append(mapToList(settings));
int responce = sendRequestToInterfaceWithArgs(QString("Create"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (!useHelper) return interface->enableProfile(profile);
try {
QList<QVariant> args;
args.append(profile);
int responce = sendRequestToInterfaceWithArgs(QString("Enable"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer removeProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (!useHelper) return interface->removeProfile(profile);
try {
QList<QVariant> args;
args.append(profile);
int responce = sendRequestToInterfaceWithArgs(QString("Remove"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (!useHelper) return interface->restartProfile(profile);
try {
QList<QVariant> args;
args.append(profile);
int responce = sendRequestToInterfaceWithArgs(QString("Restart"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer startProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (!useHelper) return interface->startProfile(profile);
try {
QList<QVariant> args;
args.append(profile);
int responce = sendRequestToInterfaceWithArgs(QString("Start"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer stopAllProfilesSlot(NetctlInterface *interface, const bool useHelper,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (!useHelper) return interface->stopAllProfiles();
try {
int responce = sendRequestToInterface(QString("StopAll"), debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (!useHelper) return interface->switchToProfile(profile);
try {
QList<QVariant> args;
args.append(profile);
int responce = sendRequestToInterfaceWithArgs(QString("SwitchTo"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
InterfaceAnswer connectToEssid(const QString essid, QMap<QString,QString> settings,
NetctlInterface* interface, const bool useHelper, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
if (!useHelper) return interface->connectToEssid(essid, settings);
try {
QList<QVariant> args;
args.append(essid);
args.append(mapToList(settings));
int responce = sendRequestToInterfaceWithArgs(QString("Essid"), args, debug)[0].toInt();
return static_cast<InterfaceAnswer>(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return InterfaceAnswer::Error;
}
}
netctlInformation generalInformation(NetctlInterface* interface, const bool useHelper,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (!useHelper) return interface->information();
try {
QList<QVariant> responce = sendRequestToInterface(QString("Information"), debug);
// main
netctlInformation info;
info.netctlAuto = responce[0].toStringList().takeFirst().toInt();
info.netctlAutoEnabled = responce[0].toStringList().takeFirst().toInt();
QList<netctlProfileInfo> profiles = parseOutputNetctl(responce);
for (int i=0; i<profiles.count(); i++) {
if (profiles[i].netctlAuto)
info.netctlAutoProfiles.append(profiles[i]);
else
info.netctlProfiles.append(profiles[i]);
}
return info;
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return netctlInformation();
}
}
QMap<QString, QString> profileInformation(const QString profile, NetctlInterface* interface,
const bool useHelper, const bool debug)
{
if (!useHelper) return interface->profileSettings(profile);
try {
QList<QVariant> args;
args.append(profile);
QStringList responce = sendRequestToInterfaceWithArgs(QString("Profile"), args, debug)[0].toStringList();
return listToMap(responce);
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return QMap<QString, QString>();
}
}
netctlCurrent trayInformation(NetctlInterface *interface, const bool useHelper,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (!useHelper) return interface->status();
try {
QStringList responce = sendRequestToInterface(QString("Status"), debug)[0].toStringList();
netctlCurrent status;
status.netctlAuto = responce[0].toInt();
status.profiles = responce[1].split(QChar('|'));
status.current = responce[2].split(QChar('|'));
QStringList enables = responce[3].split(QChar('|'));
for (int i=0; i<enables.count(); i++)
status.enables.append(enables[i].toInt());
return status;
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return netctlCurrent();
}
}

55
sources/gui/src/calls.h Normal file
View File

@ -0,0 +1,55 @@
/***************************************************************************
* 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 CALLS_H
#define CALLS_H
#include <QString>
#include <netctlgui/netctlgui.h>
// control
InterfaceAnswer createProfileSlot(const QString profile, const QMap<QString,QString> settings,
NetctlInterface *interface, const bool useHelper,
const bool debug = false);
InterfaceAnswer enableProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug = false);
InterfaceAnswer removeProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug = false);
InterfaceAnswer restartProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug = false);
InterfaceAnswer startProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug = false);
InterfaceAnswer stopAllProfilesSlot(NetctlInterface *interface, const bool useHelper,
const bool debug = false);
InterfaceAnswer switchToProfileSlot(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug = false);
// wireless connection
InterfaceAnswer connectToEssid(const QString essid, QMap<QString,QString> settings,
NetctlInterface *interface, const bool useHelper,
const bool debug = false);
// information
netctlInformation generalInformation(NetctlInterface *interface, const bool useHelper,
const bool debug = false);
QMap<QString, QString> profileInformation(const QString profile, NetctlInterface *interface,
const bool useHelper, const bool debug = false);
netctlCurrent trayInformation(NetctlInterface *interface, const bool useHelper,
const bool debug = false);
#endif /* CALLS_H */

View File

@ -0,0 +1,88 @@
/***************************************************************************
* 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 "commonfunctions.h"
#include <QApplication>
#include <QDebug>
#include <pdebug/pdebug.h>
#include <task/taskadds.h>
bool checkExternalApps(const QString apps, const QMap<QString, QString> configuration,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Applications" << apps;
if (configuration[QString("SKIPCOMPONENTS")] == QString("true")) return true;
QStringList cmd;
cmd.append("which");
// avoid null-lines arguments
cmd.append("true");
cmd.append(externalApps(apps, configuration));
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd.join(QChar(' '));
TaskResult process = runTask(cmd.join(QChar(' ')), false);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return (process.exitCode == 0);
}
QString checkStatus(const bool statusBool, const bool nullFalse)
{
if (statusBool) return QApplication::translate("MainWindow", "yes");
if (!nullFalse) return QApplication::translate("MainWindow", "no");
return QString("");
}
QStringList externalApps(const QString apps, const QMap<QString, QString> configuration)
{
QStringList app;
// editor works always over cmd
if ((apps == QString("editor")) || (apps == QString("all"))) {
app.append(configuration[QString("EDITOR_PATH")]);
app.append(configuration[QString("SUDO_PATH")]);
}
if ((apps == QString("helper")) || (apps == QString("all"))) {
app.append(configuration[QString("HELPER_PATH")]);
}
if ((apps == QString("netctl")) || (apps == QString("all"))) {
app.append(configuration[QString("NETCTL_PATH")]);
app.append(configuration[QString("NETCTLAUTO_PATH")]);
}
if ((apps == QString("systemctl")) || (apps == QString("all"))) {
app.append(configuration[QString("SYSTEMCTL_PATH")]);
}
if ((apps == QString("wpasup")) || (apps == QString("wpasup-only")) || (apps == QString("all"))) {
app.append(configuration[QString("WPACLI_PATH")]);
app.append(configuration[QString("WPASUP_PATH")]);
}
// append sudo
// FORCE_SUDO is always true if helper is not running
if ((apps.contains(QRegExp(QString("(^all$|^editor$|^netctl$|^sudo$|^systemctl$|^wpasup$)")))) &&
(configuration[QString("FORCE_SUDO")] == QString("true")))
app.append(configuration[QString("SUDO_PATH")]);
return app;
}

View File

@ -0,0 +1,33 @@
/***************************************************************************
* 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 COMMONFUNCTIONS_H
#define COMMONFUNCTIONS_H
#include <QMap>
#include <QStringList>
bool checkExternalApps(const QString apps = QString("all"),
const QMap<QString, QString> configuration = QMap<QString, QString>(),
const bool debug = false);
QString checkStatus(const bool statusBool, const bool nullFalse = false);
QStringList externalApps(const QString apps,
const QMap<QString, QString> configuration = QMap<QString, QString>());
#endif /* COMMONFUNCTIONS_H */

View File

@ -23,22 +23,26 @@
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include "version.h"
QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw,
const bool debug) QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw)
{ {
if (debug) qDebug() << PDEBUG;
QList<netctlProfileInfo> profileInfo; QList<netctlProfileInfo> profileInfo;
if (raw.size() == 0) if (raw.isEmpty()) return profileInfo;
return profileInfo; QStringList list = raw[0].toStringList();
for (int i=0; i<raw[0].toStringList().count(); i++) { for (int i=0; i<list.count(); i++) {
QStringList info = list[i].split(QChar('|'));
if (info.count() != 8) continue;
netctlProfileInfo profile; netctlProfileInfo profile;
QStringList info = raw[0].toStringList()[i].split(QChar('|'));
profile.name = info[0]; profile.name = info[0];
profile.description = info[1]; profile.description = info[1];
profile.active = info[2].toInt(); profile.type = info[2];
profile.enabled = info[3].toInt(); profile.interface = info[3];
profile.essid = info[4];
profile.active = info[5].toInt();
profile.enabled = info[6].toInt();
profile.netctlAuto = info[7].toInt();
profileInfo.append(profile); profileInfo.append(profile);
} }
@ -46,22 +50,24 @@ QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw,
} }
QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw, QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw)
const bool debug)
{ {
if (debug) qDebug() << PDEBUG;
QList<netctlWifiInfo> wifiInfo; QList<netctlWifiInfo> wifiInfo;
if (raw.size() == 0) if (raw.isEmpty()) return wifiInfo;
return wifiInfo; QStringList list = raw[0].toStringList();
for (int i=0; i<raw[0].toStringList().count(); i++) { for (int i=0; i<list.count(); i++) {
QStringList info = list[i].split(QChar('|'));
if (info.count() != 8) continue;
netctlWifiInfo wifi; netctlWifiInfo wifi;
QStringList info = raw[0].toStringList()[i].split(QChar('|'));
wifi.name = info[0]; wifi.name = info[0];
wifi.security = info[1]; wifi.security = info[1];
wifi.signal = info[2]; wifi.type = static_cast<PointType>(info[2].toInt());
wifi.active = info[3].toInt(); for (int j=0; j<info[3].split(QChar(',')).count(); j++)
wifi.exists = info[4].toInt(); wifi.frequencies.append(info[3].split(QChar(','))[j].toInt());
wifi.macs = info[4].split(QChar(','));
wifi.signal = info[5].toInt();
wifi.active = info[6].toInt();
wifi.exists = info[7].toInt();
wifiInfo.append(wifi); wifiInfo.append(wifi);
} }
@ -69,37 +75,81 @@ QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw,
} }
QList<QVariant> sendDBusRequest(const QString service, const QString path, QList<QVariant> sendRequestToHelper(const QString path, const QString cmd,
const QString interface, const QString cmd, const QList<QVariant> args, const bool debug)
const QList<QVariant> args, const bool system,
const bool debug)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Service" << service;
if (debug) qDebug() << PDEBUG << ":" << "Path" << path;
if (debug) qDebug() << PDEBUG << ":" << "Interface" << interface;
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
if (debug) qDebug() << PDEBUG << ":" << "args" << args; if (debug) qDebug() << PDEBUG << ":" << "args" << args;
if (debug) qDebug() << PDEBUG << ":" << "is system bus" << system;
QList<QVariant> arguments; QDBusConnection bus = QDBusConnection::systemBus();
QDBusMessage response; QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, path,
if (system) { DBUS_HELPER_INTERFACE, cmd);
QDBusConnection bus = QDBusConnection::systemBus(); if (!args.isEmpty()) request.setArguments(args);
QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd); QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
if (!args.isEmpty()) QList<QVariant> arguments = response.arguments();
request.setArguments(args); if (arguments.isEmpty())
response = bus.call(request, QDBus::BlockWithGui);
} else {
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd);
if (!args.isEmpty())
request.setArguments(args);
response = bus.call(request, QDBus::BlockWithGui);
}
arguments = response.arguments();
if (arguments.size() == 0)
if (debug) qDebug() << PDEBUG << ":" << "Error message" << response.errorMessage(); if (debug) qDebug() << PDEBUG << ":" << "Error message" << response.errorMessage();
return arguments; return arguments;
} }
QList<QVariant> sendRequestToCtrl(const QString cmd, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
return sendRequestToCtrlWithArgs(cmd, QList<QVariant>(), debug);
}
QList<QVariant> sendRequestToCtrlWithArgs(const QString cmd, const QList<QVariant> args,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
if (debug) qDebug() << PDEBUG << ":" << "args" << args;
return sendRequestToHelper(DBUS_CTRL_PATH, cmd, args, debug);
}
QList< QVariant > sendRequestToInterface(const QString cmd, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
return sendRequestToInterfaceWithArgs(cmd, QList<QVariant>(), debug);
}
QList<QVariant> sendRequestToInterfaceWithArgs(const QString cmd, const QList<QVariant> args,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
if (debug) qDebug() << PDEBUG << ":" << "args" << args;
return sendRequestToHelper(DBUS_INTERFACE_PATH, cmd, args, debug);
}
QList<QVariant> sendRequestToLib(const QString cmd, const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
return sendRequestToLibWithArgs(cmd, QList<QVariant>(), debug);
}
QList<QVariant> sendRequestToLibWithArgs(const QString cmd, const QList<QVariant> args,
const bool debug)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
if (debug) qDebug() << PDEBUG << ":" << "args" << args;
return sendRequestToHelper(DBUS_LIB_PATH, cmd, args, debug);
}

View File

@ -23,14 +23,19 @@
#include <netctlgui/netctlgui.h> #include <netctlgui/netctlgui.h>
QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw, QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw);
const bool debug = false); QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw);
QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw, QList<QVariant> sendRequestToHelper(const QString path, const QString cmd,
const bool debug = false); const QList<QVariant> args, const bool debug = false);
QList<QVariant> sendDBusRequest(const QString service, const QString path, QList<QVariant> sendRequestToCtrl(const QString cmd, const bool debug = false);
const QString interface, const QString cmd, QList<QVariant> sendRequestToCtrlWithArgs(const QString cmd, const QList<QVariant> args,
const QList<QVariant> args = QList<QVariant>(), const bool debug = false);
const bool system = true, const bool debug = false); QList<QVariant> sendRequestToInterface(const QString cmd, const bool debug = false);
QList<QVariant> sendRequestToInterfaceWithArgs(const QString cmd, const QList<QVariant> args,
const bool debug = false);
QList<QVariant> sendRequestToLib(const QString cmd, const bool debug = false);
QList<QVariant> sendRequestToLibWithArgs(const QString cmd, const QList<QVariant> args,
const bool debug = false);
#endif /* DBUSOPERATION_H */ #endif /* DBUSOPERATION_H */

View File

@ -37,11 +37,10 @@ ErrorWindow::~ErrorWindow()
} }
QStringList ErrorWindow::getMessage(const int mess, const QString custom) QStringList ErrorWindow::getMessage(const int mess)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Message" << mess; if (debug) qDebug() << PDEBUG << ":" << "Message" << mess;
if (debug) qDebug() << PDEBUG << ":" << "Custom message" << custom;
QString message, title; QString message, title;
switch(mess) { switch(mess) {
@ -99,7 +98,7 @@ QStringList ErrorWindow::getMessage(const int mess, const QString custom)
break; break;
case 14: case 14:
title = QApplication::translate("ErrorWindow", "Error!"); title = QApplication::translate("ErrorWindow", "Error!");
message = QApplication::translate("ErrorWindow", "APN is not set"); message = QApplication::translate("ErrorWindow", "User is not in network group, helper will not be started");
break; break;
case 15: case 15:
title = QApplication::translate("ErrorWindow", "Error!"); title = QApplication::translate("ErrorWindow", "Error!");
@ -121,13 +120,15 @@ QStringList ErrorWindow::getMessage(const int mess, const QString custom)
title = QApplication::translate("ErrorWindow", "Error!"); title = QApplication::translate("ErrorWindow", "Error!");
message = QApplication::translate("ErrorWindow", "Could not run helper"); message = QApplication::translate("ErrorWindow", "Could not run helper");
break; break;
case 20:
title = QApplication::translate("ErrorWindow", "Error!");
message = QApplication::translate("ErrorWindow", "IP address does not match the standard");
break;
default: default:
title = QApplication::translate("ErrorWindow", "Error!"); title = QApplication::translate("ErrorWindow", "Error!");
message = QApplication::translate("ErrorWindow", "Unknown error"); message = QApplication::translate("ErrorWindow", "Unknown error");
break; break;
} }
if (!custom.isEmpty())
message = custom;
QStringList fullMessage; QStringList fullMessage;
fullMessage.append(title); fullMessage.append(title);
@ -162,6 +163,7 @@ QMessageBox::Icon ErrorWindow::getIcon(const int mess)
case 17: case 17:
case 18: case 18:
case 19: case 19:
case 20:
icon = QMessageBox::Critical; icon = QMessageBox::Critical;
break; break;
default: default:
@ -173,21 +175,22 @@ QMessageBox::Icon ErrorWindow::getIcon(const int mess)
} }
void ErrorWindow::showWindow(const int mess, const QString sender, const QString custom) void ErrorWindow::showWindow(const int mess, const QString sender, const bool debugCmd)
{ {
if (debug) qDebug() << PDEBUG; if (debugCmd) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Message" << mess; if (debugCmd) qDebug() << PDEBUG << ":" << "Message" << mess;
if (debug) qDebug() << PDEBUG << ":" << "Sender" << sender; if (debugCmd) qDebug() << PDEBUG << ":" << "Sender" << sender;
if (debug) qDebug() << PDEBUG << ":" << "Custom message" << custom;
QStringList message = getMessage(mess, custom); ErrorWindow *errorWin = new ErrorWindow(0, debugCmd);
QStringList message = errorWin->getMessage(mess);
QMessageBox messageBox; QMessageBox messageBox;
messageBox.setText(message[0]); messageBox.setText(message[0]);
messageBox.setInformativeText(message[1]); messageBox.setInformativeText(message[1]);
if (debug) if (mess == 1)
messageBox.setDetailedText(QApplication::translate("ErrorWindow", "Sender : %1"). messageBox.setDetailedText(sender);
arg(sender)); else if (debugCmd)
messageBox.setIcon(getIcon(mess)); messageBox.setDetailedText(QApplication::translate("ErrorWindow", "Sender : %1").arg(sender));
messageBox.setIcon(errorWin->getIcon(mess));
messageBox.setStandardButtons(QMessageBox::Ok); messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.setDefaultButton(QMessageBox::Ok); messageBox.setDefaultButton(QMessageBox::Ok);
@ -196,5 +199,5 @@ void ErrorWindow::showWindow(const int mess, const QString sender, const QString
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
messageBox.exec(); messageBox.exec();
return; delete errorWin;
} }

View File

@ -32,13 +32,13 @@ public:
~ErrorWindow(); ~ErrorWindow();
public slots: public slots:
void showWindow(const int mess = 0, static void showWindow(const int mess = 0,
const QString sender = QString(), const QString sender = QString(),
const QString custom = QString()); const bool debugCmd = false);
private: private:
bool debug; bool debug;
QStringList getMessage(const int mess, const QString custom = QString()); QStringList getMessage(const int mess);
QMessageBox::Icon getIcon(const int mess); QMessageBox::Icon getIcon(const int mess);
}; };

View File

@ -54,15 +54,6 @@ void EthernetWidget::clear()
} }
void EthernetWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void EthernetWidget::createActions() void EthernetWidget::createActions()
{ {
connect(ui->pushButton_ethernetAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced())); connect(ui->pushButton_ethernetAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced()));
@ -73,8 +64,7 @@ void EthernetWidget::createActions()
void EthernetWidget::selectWpaConfig() void EthernetWidget::selectWpaConfig()
{ {
QString filename = QFileDialog::getOpenFileName( QString filename = QFileDialog::getOpenFileName(this,
this,
QApplication::translate("EthernetWidget", "Select wpa configuration file"), QApplication::translate("EthernetWidget", "Select wpa configuration file"),
QDir::currentPath(), QDir::currentPath(),
QApplication::translate("EthernetWidget", "Configuration files (*.conf)")); QApplication::translate("EthernetWidget", "Configuration files (*.conf)"));
@ -87,43 +77,39 @@ void EthernetWidget::showAdvanced()
{ {
if (ui->pushButton_ethernetAdvanced->isChecked()) { if (ui->pushButton_ethernetAdvanced->isChecked()) {
ui->widget_ethernetAdvanced->setHidden(false); ui->widget_ethernetAdvanced->setHidden(false);
ui->pushButton_ethernetAdvanced->setText(QApplication::translate("EthernetWidget", "Hide advanced")); ui->pushButton_ethernetAdvanced->setArrowType(Qt::UpArrow);
} else { } else {
ui->widget_ethernetAdvanced->setHidden(true); ui->widget_ethernetAdvanced->setHidden(true);
ui->pushButton_ethernetAdvanced->setText(QApplication::translate("EthernetWidget", "Show advanced")); ui->pushButton_ethernetAdvanced->setArrowType(Qt::DownArrow);
} }
} }
void EthernetWidget::showWpa(const int state) void EthernetWidget::showWpa(const int state)
{ {
if (state == 0) ui->widget_wpa->setHidden(state == 0);
ui->widget_wpa->setHidden(true);
else
ui->widget_wpa->setHidden(false);
} }
QMap<QString, QString> EthernetWidget::getSettings() QMap<QString, QString> EthernetWidget::getSettings()
{ {
QMap<QString, QString> ethernetSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return ethernetSettings;
if (ui->checkBox_skip->checkState() == Qt::Checked) if (ui->checkBox_skip->checkState() == Qt::Checked)
ethernetSettings[QString("SkipNoCarrier")] = QString("yes"); settings[QString("SkipNoCarrier")] = QString("yes");
if (ui->checkBox_8021x->checkState() == Qt::Checked) { if (ui->checkBox_8021x->checkState() == Qt::Checked) {
ethernetSettings[QString("Auth8021X")] = QString("yes"); settings[QString("Auth8021X")] = QString("yes");
ethernetSettings[QString("WPAConfigFile")] = QString("'") + ui->lineEdit_wpaConfig->text() + QString("'"); settings[QString("WPAConfigFile")] = QString("'%1'").arg(ui->lineEdit_wpaConfig->text());
ethernetSettings[QString("WPADriver")] = ui->comboBox_driver->currentText(); settings[QString("WPADriver")] = ui->comboBox_driver->currentText();
} }
if (ui->spinBox_timeoutCarrier->value() != 5) if (ui->spinBox_timeoutCarrier->value() != 5)
ethernetSettings[QString("TimeoutCarrier")] = QString::number(ui->spinBox_timeoutCarrier->value()); settings[QString("TimeoutCarrier")] = QString::number(ui->spinBox_timeoutCarrier->value());
if (ui->spinBox_timeoutWpa->value() != 15) if (ui->spinBox_timeoutWpa->value() != 15)
ethernetSettings[QString("TimeoutWPA")] = QString::number(ui->spinBox_timeoutWpa->value()); settings[QString("TimeoutWPA")] = QString::number(ui->spinBox_timeoutWpa->value());
return ethernetSettings; return settings;
} }
@ -131,8 +117,7 @@ int EthernetWidget::isOk()
{ {
// file wpa_supplicant doesn't exists // file wpa_supplicant doesn't exists
if (!ui->lineEdit_wpaConfig->text().isEmpty()) if (!ui->lineEdit_wpaConfig->text().isEmpty())
if (!QFile(ui->lineEdit_wpaConfig->text()).exists()) if (!QFile(ui->lineEdit_wpaConfig->text()).exists()) return 1;
return 1;
// all fine // all fine
return 0; return 0;
} }
@ -141,24 +126,23 @@ int EthernetWidget::isOk()
void EthernetWidget::setSettings(const QMap<QString, QString> settings) void EthernetWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> ethernetSettings = settings;
if (ethernetSettings.contains(QString("SkipNoCarrier"))) if (settings.contains(QString("SkipNoCarrier")))
if (ethernetSettings[QString("SkipNoCarrier")] == QString("yes")) if (settings[QString("SkipNoCarrier")] == QString("yes"))
ui->checkBox_skip->setCheckState(Qt::Checked); ui->checkBox_skip->setCheckState(Qt::Checked);
if (ethernetSettings.contains(QString("Auth8021X"))) if (settings.contains(QString("Auth8021X")))
if (ethernetSettings[QString("Auth8021X")] == QString("yes")) if (settings[QString("Auth8021X")] == QString("yes"))
ui->checkBox_8021x->setCheckState(Qt::Checked); ui->checkBox_8021x->setCheckState(Qt::Checked);
if (ethernetSettings.contains(QString("WPAConfigFile"))) if (settings.contains(QString("WPAConfigFile")))
ui->lineEdit_wpaConfig->setText(ethernetSettings[QString("WPAConfigFile")]); ui->lineEdit_wpaConfig->setText(settings[QString("WPAConfigFile")]);
if (ethernetSettings.contains(QString("WPADriver"))) if (settings.contains(QString("WPADriver"))) {
for (int i=0; i<ui->comboBox_driver->count(); i++) int index = ui->comboBox_driver->findText(settings[QString("WPADriver")]);
if (ethernetSettings[QString("WPADriver")] == ui->comboBox_driver->itemText(i)) ui->comboBox_driver->setCurrentIndex(index);
ui->comboBox_driver->setCurrentIndex(i); }
if (ethernetSettings.contains(QString("TimeoutCarrier"))) if (settings.contains(QString("TimeoutCarrier")))
ui->spinBox_timeoutCarrier->setValue(ethernetSettings[QString("TimeoutCarrier")].toInt()); ui->spinBox_timeoutCarrier->setValue(settings[QString("TimeoutCarrier")].toInt());
if (ethernetSettings.contains(QString("TimeoutWPA"))) if (settings.contains(QString("TimeoutWPA")))
ui->spinBox_timeoutWpa->setValue(ethernetSettings[QString("TimeoutWPA")].toInt()); ui->spinBox_timeoutWpa->setValue(settings[QString("TimeoutWPA")].toInt());
showWpa(ui->checkBox_8021x->checkState()); showWpa(ui->checkBox_8021x->checkState());
} }

View File

@ -39,7 +39,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private slots: private slots:
void selectWpaConfig(); void selectWpaConfig();

View File

@ -6,14 +6,14 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>431</width> <width>550</width>
<height>296</height> <height>227</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_ethernet"> <widget class="QDockWidget" name="dockWidget_ethernet">
<property name="features"> <property name="features">
@ -24,29 +24,29 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_ethernet"> <widget class="QWidget" name="dockWidgetContents_ethernet">
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_ethernetAdvanced"> <layout class="QHBoxLayout" name="layout_ethernetAdvanced">
<item> <item>
<spacer name="spacer_ethernetAdvanced"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_ethernetAdvanced"> <widget class="QToolButton" name="pushButton_ethernetAdvanced">
<property name="text">
<string>Hide advanced</string>
</property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -54,49 +54,104 @@
<item> <item>
<widget class="QWidget" name="widget_ethernetAdvanced" native="true"> <widget class="QWidget" name="widget_ethernetAdvanced" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QCheckBox" name="checkBox_skip"> <layout class="QHBoxLayout" name="layout_skip">
<property name="toolTip"> <item>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Whether or not the absence of a carrier is acceptable&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <widget class="QLabel" name="label_skip">
</property> <property name="sizePolicy">
<property name="text"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<string>Skip no carrier</string> <horstretch>1</horstretch>
</property> <verstretch>0</verstretch>
</widget> </sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_skip">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Whether or not the absence of a carrier is acceptable&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Skip no carrier</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkBox_8021x"> <layout class="QHBoxLayout" name="layout_8021x">
<property name="toolTip"> <item>
<string>Set to yes to use 802.1x authentication</string> <widget class="QLabel" name="label_8021x">
</property> <property name="sizePolicy">
<property name="text"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<string>802.1x authentication</string> <horstretch>1</horstretch>
</property> <verstretch>0</verstretch>
<property name="checked"> </sizepolicy>
<bool>true</bool> </property>
</property> </widget>
</widget> </item>
<item>
<widget class="QCheckBox" name="checkBox_8021x">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Set to yes to use 802.1x authentication</string>
</property>
<property name="text">
<string>802.1x authentication</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QWidget" name="widget_wpa" native="true"> <widget class="QWidget" name="widget_wpa" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_wpaConfig"> <layout class="QHBoxLayout" name="layout_wpaConfig">
<item> <item>
<widget class="QLabel" name="label_wpaConfig"> <widget class="QLabel" name="label_wpaConfig">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>WPA config file</string> <string>WPA config file</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_wpaConfig"> <widget class="QLineEdit" name="lineEdit_wpaConfig">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Path to a wpa_supplicant configuration file</string> <string>Path to a wpa_supplicant configuration file</string>
</property> </property>
@ -104,6 +159,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_wpaConfig"> <widget class="QPushButton" name="pushButton_wpaConfig">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Browse</string> <string>Browse</string>
</property> </property>
@ -115,19 +176,28 @@
<layout class="QHBoxLayout" name="layout_driver"> <layout class="QHBoxLayout" name="layout_driver">
<item> <item>
<widget class="QLabel" name="label_driver"> <widget class="QLabel" name="label_driver">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>WPA driver</string> <string>WPA driver</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_driver"> <widget class="QComboBox" name="comboBox_driver">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>14</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The wpa_supplicant driver to use for 802.1x authentication</string> <string>The wpa_supplicant driver to use for 802.1x authentication</string>
</property> </property>
@ -157,19 +227,28 @@
<layout class="QHBoxLayout" name="layout_timeoutCarrier"> <layout class="QHBoxLayout" name="layout_timeoutCarrier">
<item> <item>
<widget class="QLabel" name="label_timeoutCarrier"> <widget class="QLabel" name="label_timeoutCarrier">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Timeout carrier</string> <string>Timeout carrier</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_timeoutCarrier"> <widget class="QSpinBox" name="spinBox_timeoutCarrier">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Maximum time, in seconds, to wait for a carrier</string> <string>Maximum time, in seconds, to wait for a carrier</string>
</property> </property>
@ -187,19 +266,28 @@
<layout class="QHBoxLayout" name="layout_timeoutWpa"> <layout class="QHBoxLayout" name="layout_timeoutWpa">
<item> <item>
<widget class="QLabel" name="label_timeoutWpa"> <widget class="QLabel" name="label_timeoutWpa">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Timeout WPA</string> <string>Timeout WPA</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_timeoutWpa"> <widget class="QSpinBox" name="spinBox_timeoutWpa">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Maximum time, in seconds, to wait for 802.1x authentication to succeed</string> <string>Maximum time, in seconds, to wait for 802.1x authentication to succeed</string>
</property> </property>
@ -223,9 +311,6 @@
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>pushButton_ethernetAdvanced</tabstop>
<tabstop>checkBox_skip</tabstop>
<tabstop>checkBox_8021x</tabstop>
<tabstop>lineEdit_wpaConfig</tabstop> <tabstop>lineEdit_wpaConfig</tabstop>
<tabstop>pushButton_wpaConfig</tabstop> <tabstop>pushButton_wpaConfig</tabstop>
<tabstop>comboBox_driver</tabstop> <tabstop>comboBox_driver</tabstop>

View File

@ -67,20 +67,13 @@ void GeneralWidget::clear()
} }
void GeneralWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void GeneralWidget::createActions() void GeneralWidget::createActions()
{ {
connect(ui->pushButton_generalAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced())); connect(ui->pushButton_generalAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced()));
connect(ui->pushButton_after, SIGNAL(clicked(bool)), this, SLOT(addAfter())); connect(ui->pushButton_after, SIGNAL(clicked(bool)), this, SLOT(addAfter()));
connect(ui->comboBox_after->lineEdit(), SIGNAL(returnPressed()), this, SLOT(addAfter()));
connect(ui->pushButton_bindto, SIGNAL(clicked(bool)), this, SLOT(addBindTo())); connect(ui->pushButton_bindto, SIGNAL(clicked(bool)), this, SLOT(addBindTo()));
connect(ui->comboBox_bindto->lineEdit(), SIGNAL(returnPressed()), this, SLOT(addBindTo()));
} }
@ -100,10 +93,10 @@ void GeneralWidget::keyPressEvent(QKeyEvent *pressedKey)
{ {
if (pressedKey->key() == Qt::Key_Delete) { if (pressedKey->key() == Qt::Key_Delete) {
if (ui->listWidget_bindto->hasFocus() && if (ui->listWidget_bindto->hasFocus() &&
(ui->listWidget_bindto->currentItem() != 0)) (ui->listWidget_bindto->currentItem() != nullptr))
delete ui->listWidget_bindto->currentItem(); delete ui->listWidget_bindto->currentItem();
else if (ui->listWidget_after->hasFocus() && else if (ui->listWidget_after->hasFocus() &&
(ui->listWidget_after->currentItem() != 0)) (ui->listWidget_after->currentItem() != nullptr))
delete ui->listWidget_after->currentItem(); delete ui->listWidget_after->currentItem();
} }
} }
@ -123,36 +116,35 @@ void GeneralWidget::showAdvanced()
QMap<QString, QString> GeneralWidget::getSettings() QMap<QString, QString> GeneralWidget::getSettings()
{ {
QMap<QString, QString> generalSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return generalSettings;
generalSettings[QString("Description")] = QString("'") + ui->lineEdit_description->text() + QString("'"); settings[QString("Description")] = QString("'%1'").arg(ui->lineEdit_description->text());
generalSettings[QString("Connection")] = ui->comboBox_connection->currentText(); settings[QString("Connection")] = ui->comboBox_connection->currentText();
generalSettings[QString("Interface")] = ui->comboBox_interface->currentText(); settings[QString("Interface")] = ui->comboBox_interface->currentText();
if (ui->listWidget_bindto->count() != 0) { if (ui->listWidget_bindto->count() != 0) {
QStringList interfaces; QStringList interfaces;
for (int i=0; i<ui->listWidget_bindto->count(); i++) for (int i=0; i<ui->listWidget_bindto->count(); i++)
interfaces.append(ui->listWidget_bindto->item(i)->text()); interfaces.append(ui->listWidget_bindto->item(i)->text());
generalSettings[QString("BindsToInterfaces")] = interfaces.join(QChar(' ')); settings[QString("BindsToInterfaces")] = interfaces.join(QChar(' '));
} }
if (ui->listWidget_after->count() != 0) { if (ui->listWidget_after->count() != 0) {
QStringList profiles; QStringList profiles;
for (int i=0; i<ui->listWidget_after->count(); i++) for (int i=0; i<ui->listWidget_after->count(); i++)
profiles.append(ui->listWidget_after->item(i)->text()); profiles.append(ui->listWidget_after->item(i)->text());
generalSettings[QString("After")] = profiles.join(QChar(' ')); settings[QString("After")] = profiles.join(QChar(' '));
} }
if (!ui->lineEdit_execUpPost->text().isEmpty()) if (!ui->lineEdit_execUpPost->text().isEmpty())
generalSettings[QString("ExecUpPost")] = QString("'") + ui->lineEdit_execUpPost->text() + QString("'"); settings[QString("ExecUpPost")] = QString("'%1'").arg(ui->lineEdit_execUpPost->text());
if (!ui->lineEdit_execDownPre->text().isEmpty()) if (!ui->lineEdit_execDownPre->text().isEmpty())
generalSettings[QString("ExecDownPre")] = QString("'") + ui->lineEdit_execDownPre->text() + QString("'"); settings[QString("ExecDownPre")] = QString("'%1'").arg(ui->lineEdit_execDownPre->text());
if (ui->checkBox_forceConnect->checkState() == Qt::Checked) if (ui->checkBox_forceConnect->checkState() == Qt::Checked)
generalSettings[QString("ForceConnect")] = QString("yes"); settings[QString("ForceConnect")] = QString("yes");
if (ui->checkBox_debug->checkState() == Qt::Checked) if (ui->checkBox_debug->checkState() == Qt::Checked)
generalSettings[QString("NETCTL_DEBUG")] = QString("yes"); settings[QString("NETCTL_DEBUG")] = QString("yes");
return generalSettings; return settings;
} }
@ -160,15 +152,13 @@ int GeneralWidget::isOk()
{ {
// bind interfaces is not set // bind interfaces is not set
if ((ui->comboBox_connection->currentText() == QString("bond")) || if ((ui->comboBox_connection->currentText() == QString("bond")) ||
(ui->comboBox_connection->currentText() == QString("bridge")) || (ui->comboBox_connection->currentText() == QString("bridge")) ||
(ui->comboBox_connection->currentText() == QString("vlan")) || (ui->comboBox_connection->currentText() == QString("vlan")) ||
(ui->comboBox_connection->currentText() == QString("macvlan")) || (ui->comboBox_connection->currentText() == QString("macvlan")) ||
(ui->comboBox_connection->currentText() == QString("openvswitch"))) (ui->comboBox_connection->currentText() == QString("openvswitch")))
if (ui->listWidget_bindto->count() == 0) if (ui->listWidget_bindto->count() == 0) return 1;
return 1;
// empty description // empty description
if (ui->lineEdit_description->text().isEmpty()) if (ui->lineEdit_description->text().isEmpty()) return 2;
return 2;
// all fine // all fine
return 0; return 0;
} }
@ -177,30 +167,29 @@ int GeneralWidget::isOk()
void GeneralWidget::setSettings(const QMap<QString, QString> settings) void GeneralWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> generalSettings = settings;
if (generalSettings.contains(QString("Description"))) if (settings.contains(QString("Description")))
ui->lineEdit_description->setText(generalSettings[QString("Description")]); ui->lineEdit_description->setText(settings[QString("Description")]);
if (generalSettings.contains(QString("Connection"))) if (settings.contains(QString("Connection"))) {
for (int i=0; i<ui->comboBox_connection->count(); i++) int index = ui->comboBox_connection->findText(settings[QString("Connection")]);
if (generalSettings[QString("Connection")] == ui->comboBox_connection->itemText(i)) ui->comboBox_connection->setCurrentIndex(index);
ui->comboBox_connection->setCurrentIndex(i);
if (generalSettings.contains(QString("Interface"))) {
ui->comboBox_interface->addItem(generalSettings[QString("Interface")]);
ui->comboBox_interface->setCurrentIndex(ui->comboBox_interface->count()-1);
} }
if (generalSettings.contains(QString("BindsToInterfaces"))) if (settings.contains(QString("Interface"))) {
ui->listWidget_bindto->addItems(generalSettings[QString("BindsToInterfaces")].split(QChar('\n'))); ui->comboBox_interface->addItem(settings[QString("Interface")]);
if (generalSettings.contains(QString("After"))) ui->comboBox_interface->setCurrentIndex(ui->comboBox_interface->count() - 1);
ui->listWidget_after->addItems(generalSettings[QString("After")].split(QChar('\n'))); }
if (generalSettings.contains(QString("ExecUpPost"))) if (settings.contains(QString("BindsToInterfaces")))
ui->lineEdit_execUpPost->setText(generalSettings[QString("ExecUpPost")]); ui->listWidget_bindto->addItems(settings[QString("BindsToInterfaces")].split(QChar('\n')));
if (generalSettings.contains(QString("ExecDownPre"))) if (settings.contains(QString("After")))
ui->lineEdit_execDownPre->setText(generalSettings[QString("ExecDownPre")]); ui->listWidget_after->addItems(settings[QString("After")].split(QChar('\n')));
if (generalSettings.contains(QString("ForceConnect"))) if (settings.contains(QString("ExecUpPost")))
if (generalSettings[QString("ForceConnect")] == QString("yes")) ui->lineEdit_execUpPost->setText(settings[QString("ExecUpPost")]);
if (settings.contains(QString("ExecDownPre")))
ui->lineEdit_execDownPre->setText(settings[QString("ExecDownPre")]);
if (settings.contains(QString("ForceConnect")))
if (settings[QString("ForceConnect")] == QString("yes"))
ui->checkBox_forceConnect->setCheckState(Qt::Checked); ui->checkBox_forceConnect->setCheckState(Qt::Checked);
if (generalSettings.contains(QString("NETCTL_DEBUG"))) if (settings.contains(QString("NETCTL_DEBUG")))
if (generalSettings[QString("NETCTL_DEBUG")] == QString("yes")) if (settings[QString("NETCTL_DEBUG")] == QString("yes"))
ui->checkBox_debug->setCheckState(Qt::Checked); ui->checkBox_debug->setCheckState(Qt::Checked);
} }

View File

@ -43,7 +43,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private slots: private slots:
void addAfter(); void addAfter();

View File

@ -6,16 +6,22 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>425</width> <width>550</width>
<height>531</height> <height>452</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_general"> <widget class="QDockWidget" name="dockWidget_general">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="features"> <property name="features">
<set>QDockWidget::NoDockWidgetFeatures</set> <set>QDockWidget::NoDockWidgetFeatures</set>
</property> </property>
@ -24,25 +30,37 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_general"> <widget class="QWidget" name="dockWidgetContents_general">
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_description"> <layout class="QHBoxLayout" name="layout_description">
<item> <item>
<widget class="QLabel" name="label_description"> <widget class="QLabel" name="label_description">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Description</string> <string>Description</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_description"> <widget class="QLineEdit" name="lineEdit_description">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;A description of the profile&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>A description of the profile</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -52,19 +70,28 @@
<layout class="QHBoxLayout" name="layout_connection"> <layout class="QHBoxLayout" name="layout_connection">
<item> <item>
<widget class="QLabel" name="label_connection"> <widget class="QLabel" name="label_connection">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Connection</string> <string>Connection</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_connection"> <widget class="QComboBox" name="comboBox_connection">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The connection type used by the profile</string> <string>The connection type used by the profile</string>
</property> </property>
@ -136,19 +163,28 @@
<layout class="QHBoxLayout" name="layout_interface"> <layout class="QHBoxLayout" name="layout_interface">
<item> <item>
<widget class="QLabel" name="label_interface"> <widget class="QLabel" name="label_interface">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Interface</string> <string>Interface</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_interface"> <widget class="QComboBox" name="comboBox_interface">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The name of the associated network interface</string> <string>The name of the associated network interface</string>
</property> </property>
@ -165,18 +201,27 @@
<layout class="QHBoxLayout" name="layout_bindtoButton"> <layout class="QHBoxLayout" name="layout_bindtoButton">
<item> <item>
<widget class="QLabel" name="label_bindto"> <widget class="QLabel" name="label_bindto">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>7</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Binds to interfaces</string> <string>Binds to interfaces</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_bindto"> <widget class="QComboBox" name="comboBox_bindto">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<width>150</width> <horstretch>10</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="editable"> <property name="editable">
<bool>true</bool> <bool>true</bool>
@ -185,6 +230,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_bindto"> <widget class="QPushButton" name="pushButton_bindto">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Add</string> <string>Add</string>
</property> </property>
@ -210,26 +261,23 @@
<item> <item>
<layout class="QHBoxLayout" name="layout_generalAdvanced"> <layout class="QHBoxLayout" name="layout_generalAdvanced">
<item> <item>
<spacer name="spacer_generalAdvanced"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_generalAdvanced"> <widget class="QToolButton" name="pushButton_generalAdvanced">
<property name="text">
<string>Hide advanced</string>
</property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -237,24 +285,36 @@
<item> <item>
<widget class="QWidget" name="widget_generalAdvanced" native="true"> <widget class="QWidget" name="widget_generalAdvanced" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QVBoxLayout" name="layout_after"> <layout class="QVBoxLayout" name="layout_after">
<item> <item>
<layout class="QHBoxLayout" name="layout_afterButton"> <layout class="QHBoxLayout" name="layout_afterButton">
<item> <item>
<widget class="QLabel" name="label_after"> <widget class="QLabel" name="label_after">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>7</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>After</string> <string>After</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_after"> <widget class="QComboBox" name="comboBox_after">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<width>150</width> <horstretch>10</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="editable"> <property name="editable">
<bool>true</bool> <bool>true</bool>
@ -263,6 +323,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_after"> <widget class="QPushButton" name="pushButton_after">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Add</string> <string>Add</string>
</property> </property>
@ -289,19 +355,28 @@
<layout class="QHBoxLayout" name="layout_execUpPost"> <layout class="QHBoxLayout" name="layout_execUpPost">
<item> <item>
<widget class="QLabel" name="label_execUpPost"> <widget class="QLabel" name="label_execUpPost">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Command after starting</string> <string>Command after starting</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_execUpPost"> <widget class="QLineEdit" name="lineEdit_execUpPost">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>14</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>A command that is executed after a connection is established</string> <string>A command that is executed after a connection is established</string>
</property> </property>
@ -313,19 +388,28 @@
<layout class="QHBoxLayout" name="layout_execDownPre"> <layout class="QHBoxLayout" name="layout_execDownPre">
<item> <item>
<widget class="QLabel" name="label_execDownPre"> <widget class="QLabel" name="label_execDownPre">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Command before stoping</string> <string>Command before stoping</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_execDownPre"> <widget class="QLineEdit" name="lineEdit_execDownPre">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>14</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>A command that is executed before a connection is brought down</string> <string>A command that is executed before a connection is brought down</string>
</property> </property>
@ -334,21 +418,61 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkBox_forceConnect"> <layout class="QHBoxLayout" name="layout_forceConnect">
<property name="toolTip"> <item>
<string>Set to yes to force connecting even if the interface is up</string> <widget class="QLabel" name="label_forceConnect">
</property> <property name="sizePolicy">
<property name="text"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<string>Force connect</string> <horstretch>7</horstretch>
</property> <verstretch>0</verstretch>
</widget> </sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_forceConnect">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>14</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Set to yes to force connecting even if the interface is up</string>
</property>
<property name="text">
<string>Force connect</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkBox_debug"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="text"> <item>
<string>Debug mode</string> <widget class="QLabel" name="label">
</property> <property name="sizePolicy">
</widget> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>7</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_debug">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>14</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Debug mode</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<libraries>
<library>qt</library>
</libraries>
</project>

View File

@ -0,0 +1,83 @@
/***************************************************************************
* 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 "ipregexp.h"
IpRegExp::IpRegExp(QObject *parent)
: QObject(parent)
{
}
IpRegExp::~IpRegExp()
{
}
QRegExp IpRegExp::ip4Regex()
{
return QRegExp(QString("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"));
}
QRegExp IpRegExp::ip4CidrRegex()
{
return QRegExp(QString("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(/([0-9]|[1-2][0-9]|3[0-2]))$"));
}
QRegExp IpRegExp::ip6Regex()
{
return QRegExp(QString("^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*"));
}
QRegExp IpRegExp::ip6CidrRegex()
{
return QRegExp(QString("^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(/(d|dd|1[0-1]d|12[0-8]))$"));
}
QRegExpValidator *IpRegExp::ipv4Validator()
{
return new QRegExpValidator(IpRegExp::ip4Regex());
}
QRegExpValidator *IpRegExp::ipv4CidrValidator()
{
return new QRegExpValidator(IpRegExp::ip4CidrRegex());
}
QRegExpValidator *IpRegExp::ipv6Validator()
{
return new QRegExpValidator(IpRegExp::ip6Regex());
}
QRegExpValidator *IpRegExp::ipv6CidrValidator()
{
return new QRegExpValidator(IpRegExp::ip6CidrRegex());
}
bool IpRegExp::checkString(const QString input, const QRegExp regexp)
{
return regexp.exactMatch(input);
}

View File

@ -0,0 +1,49 @@
/***************************************************************************
* 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 IPREGEXP_H
#define IPREGEXP_H
#include <QObject>
#include <QRegExp>
#include <QRegExpValidator>
class IpRegExp : public QObject {
Q_OBJECT
public:
explicit IpRegExp(QObject *parent = 0);
~IpRegExp();
// ipv4
static QRegExp ip4Regex();
static QRegExp ip4CidrRegex();
// ipv6
static QRegExp ip6Regex();
static QRegExp ip6CidrRegex();
// validators
static QRegExpValidator *ipv4Validator();
static QRegExpValidator *ipv4CidrValidator();
static QRegExpValidator *ipv6Validator();
static QRegExpValidator *ipv6CidrValidator();
// check
static bool checkString(const QString input, const QRegExp regexp);
};
#endif /* IPREGEXP_H */

View File

@ -20,6 +20,9 @@
#include <QKeyEvent> #include <QKeyEvent>
#include "errorwindow.h"
#include "ipregexp.h"
IpWidget::IpWidget(QWidget *parent) IpWidget::IpWidget(QWidget *parent)
: QWidget(parent), : QWidget(parent),
@ -89,15 +92,6 @@ void IpWidget::clear()
} }
void IpWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void IpWidget::createActions() void IpWidget::createActions()
{ {
connect(ui->pushButton_ipAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced())); connect(ui->pushButton_ipAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced()));
@ -111,32 +105,36 @@ void IpWidget::createActions()
connect(ui->comboBox_dhcp, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeDhcpClient(QString))); connect(ui->comboBox_dhcp, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeDhcpClient(QString)));
// buttons // buttons
connect(ui->pushButton_ipAddress, SIGNAL(clicked(bool)), this, SLOT(addIp())); connect(ui->pushButton_ipAddress, SIGNAL(clicked(bool)), this, SLOT(addIp()));
connect(ui->lineEdit_ipAddress, SIGNAL(returnPressed()), this, SLOT(addIp()));
connect(ui->pushButton_ipRoutes, SIGNAL(clicked(bool)), this, SLOT(addIpRoutes())); connect(ui->pushButton_ipRoutes, SIGNAL(clicked(bool)), this, SLOT(addIpRoutes()));
connect(ui->pushButton_ipAddress6, SIGNAL(clicked(bool)), this, SLOT(addIp6())); connect(ui->pushButton_ipAddress6, SIGNAL(clicked(bool)), this, SLOT(addIp6()));
connect(ui->lineEdit_ipAddress6, SIGNAL(returnPressed()), this, SLOT(addIp6()));
connect(ui->pushButton_ipRoutes6, SIGNAL(clicked(bool)), this, SLOT(addIpRoutes6())); connect(ui->pushButton_ipRoutes6, SIGNAL(clicked(bool)), this, SLOT(addIpRoutes6()));
connect(ui->pushButton_custom, SIGNAL(clicked(bool)), this, SLOT(addCustom())); connect(ui->pushButton_custom, SIGNAL(clicked(bool)), this, SLOT(addCustom()));
connect(ui->lineEdit_custom, SIGNAL(returnPressed()), this, SLOT(addCustom()));
connect(ui->pushButton_dns, SIGNAL(clicked(bool)), this, SLOT(addDns())); connect(ui->pushButton_dns, SIGNAL(clicked(bool)), this, SLOT(addDns()));
connect(ui->lineEdit_dns, SIGNAL(returnPressed()), this, SLOT(addDns()));
connect(ui->pushButton_dnsOptions, SIGNAL(clicked(bool)), this, SLOT(addDnsOpt())); connect(ui->pushButton_dnsOptions, SIGNAL(clicked(bool)), this, SLOT(addDnsOpt()));
connect(ui->lineEdit_dnsOptions, SIGNAL(returnPressed()), this, SLOT(addDnsOpt()));
} }
void IpWidget::createFilter() void IpWidget::createFilter()
{ {
// using input mask because validators is not comfortable
// ipv4 // ipv4
ui->lineEdit_ipAddress->setInputMask(QString("999.999.999.999/99")); ui->lineEdit_ipAddress->setValidator(IpRegExp::ipv4CidrValidator());
ui->lineEdit_gateway->setInputMask(QString("999.999.999.999")); ui->lineEdit_gateway->setValidator(IpRegExp::ipv4Validator());
ui->lineEdit_ipRoutes->setInputMask(QString("999.999.999.999/99")); ui->lineEdit_ipRoutes->setValidator(IpRegExp::ipv4CidrValidator());
ui->lineEdit_ipRoutes2->setInputMask(QString("999.999.999.999")); ui->lineEdit_ipRoutes2->setValidator(IpRegExp::ipv4Validator());
// ipv6 // ipv6
ui->lineEdit_ipAddress6->setInputMask(QString("<hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh/999")); ui->lineEdit_ipAddress6->setValidator(IpRegExp::ipv6CidrValidator());
ui->lineEdit_gateway6->setInputMask(QString("<hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh")); ui->lineEdit_gateway6->setValidator(IpRegExp::ipv6Validator());
ui->lineEdit_ipRoutes6->setInputMask(QString("<hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh/999")); ui->lineEdit_ipRoutes6->setValidator(IpRegExp::ipv6CidrValidator());
ui->lineEdit_ipRoutes62->setInputMask(QString("<hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh")); ui->lineEdit_ipRoutes62->setValidator(IpRegExp::ipv6Validator());
// dns // dns
ui->lineEdit_dns->setInputMask(QString("999.999.999.999")); ui->lineEdit_dns->setValidator(IpRegExp::ipv4Validator());
} }
@ -144,110 +142,47 @@ void IpWidget::keyPressEvent(QKeyEvent *pressedKey)
{ {
if (pressedKey->key() == Qt::Key_Delete) { if (pressedKey->key() == Qt::Key_Delete) {
if (ui->listWidget_ipAddress->hasFocus() && if (ui->listWidget_ipAddress->hasFocus() &&
(ui->listWidget_ipAddress->currentItem() != 0)) (ui->listWidget_ipAddress->currentItem() != nullptr))
delete ui->listWidget_ipAddress->currentItem(); delete ui->listWidget_ipAddress->currentItem();
else if (ui->listWidget_ipRoutes->hasFocus() && else if (ui->listWidget_ipRoutes->hasFocus() &&
(ui->listWidget_ipRoutes->currentItem() != 0)) (ui->listWidget_ipRoutes->currentItem() != nullptr))
delete ui->listWidget_ipRoutes->currentItem(); delete ui->listWidget_ipRoutes->currentItem();
else if (ui->listWidget_ipAddress6->hasFocus() && else if (ui->listWidget_ipAddress6->hasFocus() &&
(ui->listWidget_ipAddress6->currentItem() != 0)) (ui->listWidget_ipAddress6->currentItem() != nullptr))
delete ui->listWidget_ipAddress6->currentItem(); delete ui->listWidget_ipAddress6->currentItem();
else if (ui->listWidget_ipRoutes6->hasFocus() && else if (ui->listWidget_ipRoutes6->hasFocus() &&
(ui->listWidget_ipRoutes6->currentItem() != 0)) (ui->listWidget_ipRoutes6->currentItem() != nullptr))
delete ui->listWidget_ipRoutes6->currentItem(); delete ui->listWidget_ipRoutes6->currentItem();
else if (ui->listWidget_custom->hasFocus() && else if (ui->listWidget_custom->hasFocus() &&
(ui->listWidget_custom->currentItem() != 0)) (ui->listWidget_custom->currentItem() != nullptr))
delete ui->listWidget_custom->currentItem(); delete ui->listWidget_custom->currentItem();
else if (ui->listWidget_dns->hasFocus() && else if (ui->listWidget_dns->hasFocus() &&
(ui->listWidget_dns->currentItem() != 0)) (ui->listWidget_dns->currentItem() != nullptr))
delete ui->listWidget_dns->currentItem(); delete ui->listWidget_dns->currentItem();
else if (ui->listWidget_dnsOptions->hasFocus() && else if (ui->listWidget_dnsOptions->hasFocus() &&
(ui->listWidget_dnsOptions->currentItem() != 0)) (ui->listWidget_dnsOptions->currentItem() != nullptr))
delete ui->listWidget_dnsOptions->currentItem(); delete ui->listWidget_dnsOptions->currentItem();
} }
} }
QString IpWidget::getIp(const QString rawIp)
{
QStringList ip = rawIp.split(QChar('.'));
// fix empty fields
if (ip[0].isEmpty())
ip[0] = QString("127");
if (ip[1].isEmpty())
ip[1] = QString("0");
if (ip[2].isEmpty())
ip[2] = QString("0");
if (ip[3].isEmpty())
ip[3] = QString("1");
// fix numbers
for (int i=0; i<4; i++)
if (ip[i].toInt() > 255)
ip[i] = QString("255");
return ip.join(QChar('.'));
}
QString IpWidget::getPrefix(const QString rawPrefix)
{
QString prefix;
if (rawPrefix.isEmpty())
prefix = QString("24");
else if (rawPrefix.toInt() > 32)
prefix = QString("32");
else
prefix = rawPrefix;
return prefix;
}
QString IpWidget::getIp6(const QString rawIp)
{
QString ip = rawIp;
for (int i=0; i<5; i++)
ip.replace(QString(":::"), QString("::"));
return ip;
}
QString IpWidget::getPrefix6(const QString rawPrefix)
{
QString prefix;
if (rawPrefix.isEmpty())
prefix = QString("64");
else if (rawPrefix.toInt() > 128)
prefix = QString("128");
else
prefix = rawPrefix;
return prefix;
}
void IpWidget::addIp() void IpWidget::addIp()
{ {
QString ip = getIp(ui->lineEdit_ipAddress->text().remove(QChar(' ')).split(QChar('/'))[0]); if (!IpRegExp::checkString(ui->lineEdit_ipAddress->text(), IpRegExp::ip4CidrRegex()))
QString prefix = getPrefix(ui->lineEdit_ipAddress->text().remove(QChar(' ')).split(QChar('/'))[1]); return ErrorWindow::showWindow(20, QString("[IpWidget::addIp]"));
ui->listWidget_ipAddress->addItem(ip + QString("/") + prefix); ui->listWidget_ipAddress->addItem(ui->lineEdit_ipAddress->text());
ui->lineEdit_ipAddress->clear(); ui->lineEdit_ipAddress->clear();
} }
void IpWidget::addIpRoutes() void IpWidget::addIpRoutes()
{ {
QString ip = getIp(ui->lineEdit_ipRoutes->text().remove(QChar(' ')).split(QChar('/'))[0]); if ((!IpRegExp::checkString(ui->lineEdit_ipRoutes->text(), IpRegExp::ip4CidrRegex())) ||
QString prefix = getPrefix(ui->lineEdit_ipRoutes->text().remove(QChar(' ')).split(QChar('/'))[1]); (!IpRegExp::checkString(ui->lineEdit_ipRoutes2->text(), IpRegExp::ip4Regex())))
QString ipVia = getIp(ui->lineEdit_ipRoutes2->text().remove(QChar(' '))); return ErrorWindow::showWindow(20, QString("[IpWidget::addIpRoutes]"));
ui->listWidget_ipRoutes->addItem(ip + QString("/") + prefix + QString(" via ") + ipVia); ui->listWidget_ipRoutes->addItem(QString("%1 via %2").arg(ui->lineEdit_ipRoutes->text()).arg(ui->lineEdit_ipRoutes2->text()));
ui->lineEdit_ipRoutes->clear(); ui->lineEdit_ipRoutes->clear();
ui->lineEdit_ipRoutes2->clear(); ui->lineEdit_ipRoutes2->clear();
} }
@ -255,21 +190,21 @@ void IpWidget::addIpRoutes()
void IpWidget::addIp6() void IpWidget::addIp6()
{ {
QString ip = getIp6(ui->lineEdit_ipAddress6->text().remove(QChar(' ')).split(QChar('/'))[0]); if (!IpRegExp::checkString(ui->lineEdit_ipAddress6->text(), IpRegExp::ip6CidrRegex()))
QString prefix = getPrefix6(ui->lineEdit_ipAddress6->text().remove(QChar(' ')).split(QChar('/'))[1]); return ErrorWindow::showWindow(20, QString("[IpWidget::addIp6]"));
ui->listWidget_ipAddress6->addItem(ip + QString("/") + prefix); ui->listWidget_ipAddress6->addItem(ui->lineEdit_ipAddress6->text());
ui->lineEdit_ipAddress6->clear(); ui->lineEdit_ipAddress6->clear();
} }
void IpWidget::addIpRoutes6() void IpWidget::addIpRoutes6()
{ {
QString ip = getIp6(ui->lineEdit_ipRoutes6->text().remove(QChar(' ')).split(QChar('/'))[0]); if ((!IpRegExp::checkString(ui->lineEdit_ipRoutes6->text(), IpRegExp::ip6CidrRegex())) ||
QString prefix = getPrefix6(ui->lineEdit_ipRoutes6->text().remove(QChar(' ')).split(QChar('/'))[1]); (!IpRegExp::checkString(ui->lineEdit_ipRoutes62->text(), IpRegExp::ip6Regex())))
QString ipVia = getIp6(ui->lineEdit_ipRoutes62->text().remove(QChar(' '))); return ErrorWindow::showWindow(20, QString("[IpWidget::addIp6Routes]"));
ui->listWidget_ipRoutes6->addItem(ip + QString("/") + prefix + QString(" via ") + ipVia); ui->listWidget_ipRoutes6->addItem(QString("%1 via %2").arg(ui->lineEdit_ipRoutes6->text()).arg(ui->lineEdit_ipRoutes62->text()));
ui->lineEdit_ipRoutes6->clear(); ui->lineEdit_ipRoutes6->clear();
ui->lineEdit_ipRoutes62->clear(); ui->lineEdit_ipRoutes62->clear();
} }
@ -285,9 +220,10 @@ void IpWidget::addCustom()
void IpWidget::addDns() void IpWidget::addDns()
{ {
QString ip = getIp(ui->lineEdit_dns->text().remove(QChar(' '))); if (!IpRegExp::checkString(ui->lineEdit_dns->text(), IpRegExp::ip4Regex()))
return ErrorWindow::showWindow(20, QString("[IpWidget::addDns]"));
ui->listWidget_dns->addItem(ip); ui->listWidget_dns->addItem(ui->lineEdit_dns->text());
ui->lineEdit_dns->clear(); ui->lineEdit_dns->clear();
} }
@ -302,61 +238,36 @@ void IpWidget::addDnsOpt()
void IpWidget::changeIpMode(const QString currentText) void IpWidget::changeIpMode(const QString currentText)
{ {
if (currentText == QString("dhcp")) ui->widget_ip->setHidden(currentText == QString("dhcp"));
ui->widget_ip->setHidden(true);
else if (currentText == QString("static"))
ui->widget_ip->setHidden(false);
} }
void IpWidget::ipEnable(const int state) void IpWidget::ipEnable(const int state)
{ {
if (state == 0) { ui->comboBox_ip->setDisabled(state == 0);
ui->comboBox_ip->setDisabled(true); ui->widget_ip->setDisabled(state == 0);
ui->widget_ip->setDisabled(true); ui->widget_ipRoutes->setDisabled(state == 0);
ui->widget_ipRoutes->setDisabled(true);
} else {
ui->comboBox_ip->setEnabled(true);
ui->widget_ip->setEnabled(true);
ui->widget_ipRoutes->setEnabled(true);
}
} }
void IpWidget::changeIp6Mode(const QString currentText) void IpWidget::changeIp6Mode(const QString currentText)
{ {
if ((currentText == QString("dhcp")) || ui->widget_ip6->setHidden(currentText.startsWith(QString("dhcp")));
(currentText == QString("dhcp-noaddr")))
ui->widget_ip6->setHidden(true);
else if ((currentText == QString("static")) ||
(currentText == QString("stateless")))
ui->widget_ip6->setHidden(false);
} }
void IpWidget::ip6Enable(const int state) void IpWidget::ip6Enable(const int state)
{ {
if (state == 0) { ui->comboBox_ip6->setDisabled(state == 0);
ui->comboBox_ip6->setDisabled(true); ui->widget_ip6->setDisabled(state == 0);
ui->widget_ip6->setDisabled(true); ui->widget_ipRoutes6->setDisabled(state == 0);
ui->widget_ipRoutes6->setDisabled(true);
} else {
ui->comboBox_ip6->setEnabled(true);
ui->widget_ip6->setEnabled(true);
ui->widget_ipRoutes6->setEnabled(true);
}
} }
void IpWidget::changeDhcpClient(const QString currentText) void IpWidget::changeDhcpClient(const QString currentText)
{ {
if (currentText == QString("dhcpcd")) { ui->widget_dhcpcdOpt->setHidden(currentText != QString("dhcpcd"));
ui->widget_dhcpcdOpt->setHidden(false); ui->widget_dhclientOpt->setHidden(currentText == QString("dhcpcd"));
ui->widget_dhclientOpt->setHidden(true);
} else if (currentText == QString("dhclient")) {
ui->widget_dhcpcdOpt->setHidden(true);
ui->widget_dhclientOpt->setHidden(false);
}
} }
@ -364,116 +275,113 @@ void IpWidget::showAdvanced()
{ {
if (ui->pushButton_ipAdvanced->isChecked()) { if (ui->pushButton_ipAdvanced->isChecked()) {
ui->widget_ipAdvanced->setHidden(false); ui->widget_ipAdvanced->setHidden(false);
ui->pushButton_ipAdvanced->setText(QApplication::translate("IpWidget", "Hide advanced")); ui->pushButton_ipAdvanced->setArrowType(Qt::UpArrow);
} else { } else {
ui->widget_ipAdvanced->setHidden(true); ui->widget_ipAdvanced->setHidden(true);
ui->pushButton_ipAdvanced->setText(QApplication::translate("IpWidget", "Show advanced")); ui->pushButton_ipAdvanced->setArrowType(Qt::DownArrow);
} }
} }
QMap<QString, QString> IpWidget::getSettings() QMap<QString, QString> IpWidget::getSettings()
{ {
QMap<QString, QString> ipSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return ipSettings;
if (ui->checkBox_ip->checkState() == Qt::Checked) { if (ui->checkBox_ip->checkState() == Qt::Checked) {
ipSettings[QString("IP")] = ui->comboBox_ip->currentText(); settings[QString("IP")] = ui->comboBox_ip->currentText();
if (ui->comboBox_ip->currentText() == QString("static")) { if (ui->comboBox_ip->currentText() == QString("static")) {
QStringList addresses; QStringList addresses;
for (int i=0; i<ui->listWidget_ipAddress->count(); i++) for (int i=0; i<ui->listWidget_ipAddress->count(); i++)
addresses.append(QString("'") + ui->listWidget_ipAddress->item(i)->text() + QString("'")); addresses.append(QString("'%1'").arg(ui->listWidget_ipAddress->item(i)->text()));
ipSettings[QString("Address")] = addresses.join(QChar(' ')); settings[QString("Address")] = addresses.join(QChar(' '));
ipSettings[QString("Gateway")] = QString("'") + ui->lineEdit_gateway->text() + QString("'"); settings[QString("Gateway")] = QString("'%1'").arg(ui->lineEdit_gateway->text());
} }
if (ui->listWidget_ipRoutes->count() > 0) { if (ui->listWidget_ipRoutes->count() > 0) {
QStringList routes; QStringList routes;
for (int i=0; i<ui->listWidget_ipRoutes->count(); i++) for (int i=0; i<ui->listWidget_ipRoutes->count(); i++)
routes.append(QString("'") + ui->listWidget_ipRoutes->item(i)->text() + QString("'")); routes.append(QString("'%1'").arg(ui->listWidget_ipRoutes->item(i)->text()));
ipSettings[QString("Routes")] = routes.join(QChar(' ')); settings[QString("Routes")] = routes.join(QChar(' '));
} }
} else } else
ipSettings[QString("IP")] = QString("no"); settings[QString("IP")] = QString("no");
if (ui->checkBox_ip6->checkState() == Qt::Checked) { if (ui->checkBox_ip6->checkState() == Qt::Checked) {
ipSettings[QString("IP6")] = ui->comboBox_ip6->currentText(); settings[QString("IP6")] = ui->comboBox_ip6->currentText();
if ((ui->comboBox_ip6->currentText() == QString("static")) || if ((ui->comboBox_ip6->currentText() == QString("static")) ||
(ui->comboBox_ip6->currentText() == QString("stateless"))) { (ui->comboBox_ip6->currentText() == QString("stateless"))) {
QStringList addresses; QStringList addresses;
for (int i=0; i<ui->listWidget_ipAddress6->count(); i++) for (int i=0; i<ui->listWidget_ipAddress6->count(); i++)
addresses.append(QString("'") + ui->listWidget_ipAddress6->item(i)->text() + QString("'")); addresses.append(QString("'%1'").arg(ui->listWidget_ipAddress6->item(i)->text()));
ipSettings[QString("Address6")] = addresses.join(QChar(' ')); settings[QString("Address6")] = addresses.join(QChar(' '));
ipSettings[QString("Gateway6")] = QString("'") + ui->lineEdit_gateway6->text() + QString("'"); settings[QString("Gateway6")] = QString("'%1'").arg(ui->lineEdit_gateway6->text());
} }
if (ui->listWidget_ipRoutes6->count() > 0) { if (ui->listWidget_ipRoutes6->count() > 0) {
QStringList routes; QStringList routes;
for (int i=0; i<ui->listWidget_ipRoutes6->count(); i++) for (int i=0; i<ui->listWidget_ipRoutes6->count(); i++)
routes.append(QString("'") + ui->listWidget_ipRoutes6->item(i)->text() + QString("'")); routes.append(QString("'%1'").arg(ui->listWidget_ipRoutes6->item(i)->text()));
ipSettings[QString("Routes6")] = routes.join(QChar(' ')); settings[QString("Routes6")] = routes.join(QChar(' '));
} }
} else } else
ipSettings[QString("IP6")] = QString("no"); settings[QString("IP6")] = QString("no");
if (ui->listWidget_custom->count() > 0) { if (ui->listWidget_custom->count() > 0) {
QStringList custom; QStringList custom;
for (int i=0; i<ui->listWidget_custom->count(); i++) for (int i=0; i<ui->listWidget_custom->count(); i++)
custom.append(QString("'") + ui->listWidget_custom->item(i)->text() + QString("'")); custom.append(QString("'%1'").arg(ui->listWidget_custom->item(i)->text()));
ipSettings[QString("IPCustom")] = custom.join(QChar(' ')); settings[QString("IPCustom")] = custom.join(QChar(' '));
} }
if (!ui->lineEdit_hostname->text().isEmpty()) if (!ui->lineEdit_hostname->text().isEmpty())
ipSettings[QString("Hostname")] = QString("'") + ui->lineEdit_hostname->text() + QString("'"); settings[QString("Hostname")] = QString("'%1'").arg(ui->lineEdit_hostname->text());
if (ui->spinBox_timeoutDad->value() != 3) if (ui->spinBox_timeoutDad->value() != 3)
ipSettings[QString("TimeoutDAD")] = QString::number(ui->spinBox_timeoutDad->value()); settings[QString("TimeoutDAD")] = QString::number(ui->spinBox_timeoutDad->value());
if (ui->comboBox_dhcp->currentText() == QString("dhcpcd")) { if (ui->comboBox_dhcp->currentText() == QString("dhcpcd")) {
if (!ui->lineEdit_dhcpcdOpt->text().isEmpty()) if (!ui->lineEdit_dhcpcdOpt->text().isEmpty())
ipSettings[QString("DhcpcdOptions")] = QString("'") + ui->lineEdit_dhcpcdOpt->text() + QString("'"); settings[QString("DhcpcdOptions")] = QString("'%1'").arg(ui->lineEdit_dhcpcdOpt->text());
} else if (ui->comboBox_dhcp->currentText() == QString("dhclient")) { } else if (ui->comboBox_dhcp->currentText() == QString("dhclient")) {
ipSettings[QString("DHCPClient")] = ui->comboBox_dhcp->currentText(); settings[QString("DHCPClient")] = ui->comboBox_dhcp->currentText();
if (!ui->lineEdit_dhclientOpt->text().isEmpty()) if (!ui->lineEdit_dhclientOpt->text().isEmpty())
ipSettings[QString("DhclientOptions")] = QString("'") + ui->lineEdit_dhclientOpt->text() + QString("'"); settings[QString("DhclientOptions")] = QString("'%1'").arg(ui->lineEdit_dhclientOpt->text());
if (!ui->lineEdit_dhclientOpt6->text().isEmpty()) if (!ui->lineEdit_dhclientOpt6->text().isEmpty())
ipSettings[QString("DhclientOptions6")] = QString("'") + ui->lineEdit_dhclientOpt6->text() + QString("'"); settings[QString("DhclientOptions6")] = QString("'%1'").arg(ui->lineEdit_dhclientOpt6->text());
} }
if (ui->spinBox_timeoutDhcp->value() != 30) if (ui->spinBox_timeoutDhcp->value() != 30)
ipSettings[QString("TimeoutDHCP")] = QString::number(ui->spinBox_timeoutDhcp->value()); settings[QString("TimeoutDHCP")] = QString::number(ui->spinBox_timeoutDhcp->value());
if (ui->checkBox_dhcp->checkState() == Qt::Checked) if (ui->checkBox_dhcp->checkState() == Qt::Checked)
ipSettings[QString("DHCPReleaseOnStop")] = QString("yes"); settings[QString("DHCPReleaseOnStop")] = QString("yes");
if (ui->listWidget_dns->count() > 0) { if (ui->listWidget_dns->count() > 0) {
QStringList dns; QStringList dns;
for (int i=0; i<ui->listWidget_dns->count(); i++) for (int i=0; i<ui->listWidget_dns->count(); i++)
dns.append(QString("'") + ui->listWidget_dns->item(i)->text() + QString("'")); dns.append(QString("'%1'").arg(ui->listWidget_dns->item(i)->text()));
ipSettings[QString("DNS")] = dns.join(QChar(' ')); settings[QString("DNS")] = dns.join(QChar(' '));
} }
if (!ui->lineEdit_dnsDomain->text().isEmpty()) if (!ui->lineEdit_dnsDomain->text().isEmpty())
ipSettings[QString("DNSDomain")] = QString("'") + ui->lineEdit_dnsDomain->text() + QString("'"); settings[QString("DNSDomain")] = QString("'%1'").arg(ui->lineEdit_dnsDomain->text());
if (!ui->lineEdit_dnsSearch->text().isEmpty()) if (!ui->lineEdit_dnsSearch->text().isEmpty())
ipSettings[QString("DNSSearch")] = QString("'") + ui->lineEdit_dnsSearch->text() + QString("'"); settings[QString("DNSSearch")] = QString("'%1'").arg(ui->lineEdit_dnsSearch->text());
if (ui->listWidget_dnsOptions->count() > 0) { if (ui->listWidget_dnsOptions->count() > 0) {
QStringList dnsOpt; QStringList dnsOpt;
for (int i=0; i<ui->listWidget_dnsOptions->count(); i++) for (int i=0; i<ui->listWidget_dnsOptions->count(); i++)
dnsOpt.append(QString("'") + ui->listWidget_dnsOptions->item(i)->text() + QString("'")); dnsOpt.append(QString("'%1'").arg(ui->listWidget_dnsOptions->item(i)->text()));
ipSettings[QString("DNSOptions")] = dnsOpt.join(QChar(' ')); settings[QString("DNSOptions")] = dnsOpt.join(QChar(' '));
} }
return ipSettings; return settings;
} }
int IpWidget::isOk() int IpWidget::isOk()
{ {
// ip settings is not set // ip settings is not set
if (ui->checkBox_ip->checkState() == Qt::Checked) if ((ui->checkBox_ip->checkState() == Qt::Checked) &&
if (ui->comboBox_ip->currentText() == QString("static")) (ui->comboBox_ip->currentText() == QString("static")))
if ((ui->listWidget_ipAddress->count() == 0) || if ((ui->listWidget_ipAddress->count() == 0) ||
(ui->lineEdit_gateway->text().isEmpty())) (ui->lineEdit_gateway->text().isEmpty())) return 1;
return 1;
// ipv6 settings is not set // ipv6 settings is not set
if (ui->checkBox_ip6->checkState() == Qt::Checked) if ((ui->checkBox_ip6->checkState() == Qt::Checked) &&
if ((ui->comboBox_ip6->currentText() == QString("static")) || ((ui->comboBox_ip6->currentText() == QString("static")) ||
(ui->comboBox_ip6->currentText() == QString("stateless"))) (ui->comboBox_ip6->currentText() == QString("stateless"))))
if ((ui->listWidget_ipAddress6->count() == 0) || if ((ui->listWidget_ipAddress6->count() == 0) ||
(ui->lineEdit_gateway6->text().isEmpty())) (ui->lineEdit_gateway6->text().isEmpty())) return 2;
return 2;
// all fine // all fine
return 0; return 0;
} }
@ -482,70 +390,66 @@ int IpWidget::isOk()
void IpWidget::setSettings(const QMap<QString, QString> settings) void IpWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> ipSettings = settings;
if (ipSettings.contains(QString("IP"))) { if (settings.contains(QString("IP"))) {
if (ipSettings[QString("IP")] == QString("no")) if (settings[QString("IP")] == QString("no"))
ui->checkBox_ip->setCheckState(Qt::Unchecked); ui->checkBox_ip->setCheckState(Qt::Unchecked);
else { else {
ui->checkBox_ip->setCheckState(Qt::Checked); ui->checkBox_ip->setCheckState(Qt::Checked);
for (int i=0; i<ui->comboBox_ip->count(); i++) int index = ui->comboBox_ip->findText(settings[QString("IP")]);
if (ipSettings[QString("IP")] == ui->comboBox_ip->itemText(i)) ui->comboBox_ip->setCurrentIndex(index);
ui->comboBox_ip->setCurrentIndex(i);
} }
} }
if (ipSettings.contains(QString("Address"))) if (settings.contains(QString("Address")))
ui->listWidget_ipAddress->addItems(ipSettings[QString("Address")].split(QChar('\n'))); ui->listWidget_ipAddress->addItems(settings[QString("Address")].split(QChar('\n')));
if (ipSettings.contains(QString("Gateway"))) if (settings.contains(QString("Gateway")))
ui->lineEdit_gateway->setText(ipSettings[QString("Gateway")]); ui->lineEdit_gateway->setText(settings[QString("Gateway")]);
if (ipSettings.contains(QString("Routes"))) if (settings.contains(QString("Routes")))
ui->listWidget_ipRoutes->addItems(ipSettings[QString("Routes")].split(QChar('\n'))); ui->listWidget_ipRoutes->addItems(settings[QString("Routes")].split(QChar('\n')));
if (ipSettings.contains(QString("IP6"))) { if (settings.contains(QString("IP6"))) {
if (ipSettings[QString("IP6")] == QString("no")) if (settings[QString("IP6")] == QString("no"))
ui->checkBox_ip6->setCheckState(Qt::Unchecked); ui->checkBox_ip6->setCheckState(Qt::Unchecked);
else { else {
ui->checkBox_ip6->setCheckState(Qt::Checked); ui->checkBox_ip6->setCheckState(Qt::Checked);
for (int i=0; i<ui->comboBox_ip6->count(); i++) int index = ui->comboBox_ip6->findText(settings[QString("IP6")]);
if (ipSettings[QString("IP6")] == ui->comboBox_ip6->itemText(i)) ui->comboBox_ip6->setCurrentIndex(index);
ui->comboBox_ip6->setCurrentIndex(i);
} }
} }
if (ipSettings.contains(QString("Address6"))) if (settings.contains(QString("Address6")))
ui->listWidget_ipAddress6->addItems(ipSettings[QString("Address6")].split(QChar('\n'))); ui->listWidget_ipAddress6->addItems(settings[QString("Address6")].split(QChar('\n')));
if (ipSettings.contains(QString("Gateway6"))) if (settings.contains(QString("Gateway6")))
ui->lineEdit_gateway6->setText(ipSettings[QString("Gateway6")]); ui->lineEdit_gateway6->setText(settings[QString("Gateway6")]);
if (ipSettings.contains(QString("Routes6"))) if (settings.contains(QString("Routes6")))
ui->listWidget_ipRoutes6->addItems(ipSettings[QString("Routes6")].split(QChar('\n'))); ui->listWidget_ipRoutes6->addItems(settings[QString("Routes6")].split(QChar('\n')));
if (ipSettings.contains(QString("IPCustom"))) if (settings.contains(QString("IPCustom")))
ui->listWidget_custom->addItems(ipSettings[QString("IPCustom")].split(QChar('\n'))); ui->listWidget_custom->addItems(settings[QString("IPCustom")].split(QChar('\n')));
if (ipSettings.contains(QString("Hostname"))) if (settings.contains(QString("Hostname")))
ui->lineEdit_hostname->setText(ipSettings[QString("Hostname")]); ui->lineEdit_hostname->setText(settings[QString("Hostname")]);
if (ipSettings.contains(QString("TimeoutDAD"))) if (settings.contains(QString("TimeoutDAD")))
ui->spinBox_timeoutDad->setValue(ipSettings[QString("TimeoutDAD")].toInt()); ui->spinBox_timeoutDad->setValue(settings[QString("TimeoutDAD")].toInt());
if (ipSettings.contains(QString("DHCPClient"))) if (settings.contains(QString("DHCPClient"))) {
for (int i=0; i<ui->comboBox_dhcp->count(); i++) int index = ui->comboBox_dhcp->findText(settings[QString("DHCPClient")]);
if (ipSettings[QString("DHCPClient")] == ui->comboBox_dhcp->itemText(i)) ui->comboBox_dhcp->setCurrentIndex(index);
ui->comboBox_dhcp->setCurrentIndex(i); }
if (ipSettings.contains(QString("DhcpcdOptions"))) if (settings.contains(QString("DhcpcdOptions")))
ui->lineEdit_dhcpcdOpt->setText(ipSettings[QString("DhcpcdOptions")] ui->lineEdit_dhcpcdOpt->setText(settings[QString("DhcpcdOptions")]);
.remove(QChar('\'')).remove(QChar('"'))); if (settings.contains(QString("DhclientOptions")))
if (ipSettings.contains(QString("DhclientOptions"))) ui->lineEdit_dhclientOpt->setText(settings[QString("DhclientOptions")]);
ui->lineEdit_dhclientOpt->setText(ipSettings[QString("DhclientOptions")]); if (settings.contains(QString("DhclientOptions6")))
if (ipSettings.contains(QString("DhclientOptions6"))) ui->lineEdit_dhclientOpt6->setText(settings[QString("DhclientOptions6")]);
ui->lineEdit_dhclientOpt6->setText(ipSettings[QString("DhclientOptions6")]); if (settings.contains(QString("TimeoutDHCP")))
if (ipSettings.contains(QString("TimeoutDHCP"))) ui->spinBox_timeoutDhcp->setValue(settings[QString("TimeoutDHCP")].toInt());
ui->spinBox_timeoutDhcp->setValue(ipSettings[QString("TimeoutDHCP")].toInt()); if (settings.contains(QString("DHCPReleaseOnStop")))
if (ipSettings.contains(QString("DHCPReleaseOnStop"))) if (settings[QString("DHCPReleaseOnStop")] == QString("yes"))
if (ipSettings[QString("DHCPReleaseOnStop")] == QString("yes"))
ui->checkBox_dhcp->setCheckState(Qt::Checked); ui->checkBox_dhcp->setCheckState(Qt::Checked);
if (ipSettings.contains(QString("DNS"))) if (settings.contains(QString("DNS")))
ui->listWidget_dns->addItems(ipSettings[QString("DNS")].split(QChar('\n'))); ui->listWidget_dns->addItems(settings[QString("DNS")].split(QChar('\n')));
if (ipSettings.contains(QString("DNSDomain"))) if (settings.contains(QString("DNSDomain")))
ui->lineEdit_dnsDomain->setText(ipSettings[QString("DNSDomain")]); ui->lineEdit_dnsDomain->setText(settings[QString("DNSDomain")]);
if (ipSettings.contains(QString("DNSSearch"))) if (settings.contains(QString("DNSSearch")))
ui->lineEdit_dnsSearch->setText(ipSettings[QString("DNSSearch")]); ui->lineEdit_dnsSearch->setText(settings[QString("DNSSearch")]);
if (ipSettings.contains(QString("DNSOptions"))) if (settings.contains(QString("DNSOptions")))
ui->listWidget_dnsOptions->addItems(ipSettings[QString("DNSOptions")].split(QChar('\n'))); ui->listWidget_dnsOptions->addItems(settings[QString("DNSOptions")].split(QChar('\n')));
ipEnable(ui->checkBox_ip->checkState()); ipEnable(ui->checkBox_ip->checkState());
changeIpMode(ui->comboBox_ip->currentText()); changeIpMode(ui->comboBox_ip->currentText());

View File

@ -38,7 +38,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private slots: private slots:
// buttons // buttons
@ -64,10 +63,6 @@ private:
void createActions(); void createActions();
void createFilter(); void createFilter();
void keyPressEvent(QKeyEvent *pressedKey); void keyPressEvent(QKeyEvent *pressedKey);
QString getIp(const QString rawIp);
QString getPrefix(const QString rawPrefix);
QString getIp6(const QString rawIp);
QString getPrefix6(const QString rawPrefix);
}; };

File diff suppressed because it is too large Load Diff

View File

@ -42,34 +42,24 @@ void MacvlanWidget::clear()
} }
void MacvlanWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void MacvlanWidget::createFilter() void MacvlanWidget::createFilter()
{ {
// mac // mac
ui->lineEdit_mac->setInputMask(QString(">HH:HH:HH:HH:HH:HH")); ui->lineEdit_mac->setInputMask(QString(">hh:hh:hh:hh:hh:hh"));
} }
QMap<QString, QString> MacvlanWidget::getSettings() QMap<QString, QString> MacvlanWidget::getSettings()
{ {
QMap<QString, QString> macvlanSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return macvlanSettings;
macvlanSettings[QString("Mode")] = ui->comboBox_mode->currentText(); settings[QString("Mode")] = ui->comboBox_mode->currentText();
if (!ui->lineEdit_mac->text().remove(QChar(':')).remove(QChar(' ')).isEmpty()) if (!ui->lineEdit_mac->text().remove(QChar(':')).isEmpty())
macvlanSettings[QString("MACAddress")] = ui->lineEdit_mac->text(); settings[QString("MACAddress")] = ui->lineEdit_mac->text();
return macvlanSettings; return settings;
} }
@ -83,12 +73,11 @@ int MacvlanWidget::isOk()
void MacvlanWidget::setSettings(const QMap<QString, QString> settings) void MacvlanWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> macvlanSettings = settings;
if (macvlanSettings.contains(QString("Mode"))) if (settings.contains(QString("Mode"))) {
for (int i=0; i<ui->comboBox_mode->count(); i++) int index = ui->comboBox_mode->findText(settings[QString("Mode")]);
if (macvlanSettings[QString("Mode")] == ui->comboBox_mode->itemText(i)) ui->comboBox_mode->setCurrentIndex(index);
ui->comboBox_mode->setCurrentIndex(i); }
if (macvlanSettings.contains(QString("MACAddress"))) if (settings.contains(QString("MACAddress")))
ui->lineEdit_mac->setText(macvlanSettings[QString("MACAddress")]); ui->lineEdit_mac->setText(settings[QString("MACAddress")]);
} }

View File

@ -38,7 +38,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private: private:
Ui::MacvlanWidget *ui; Ui::MacvlanWidget *ui;

View File

@ -7,13 +7,13 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>396</width> <width>396</width>
<height>101</height> <height>79</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_macvlan"> <widget class="QDockWidget" name="dockWidget_macvlan">
<property name="features"> <property name="features">
@ -24,17 +24,35 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_macvlan"> <widget class="QWidget" name="dockWidgetContents_macvlan">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QHBoxLayout" name="layout_mode"> <layout class="QHBoxLayout" name="layout_mode">
<item> <item>
<widget class="QLabel" name="label_mode"> <widget class="QLabel" name="label_mode">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Mode</string> <string>Mode</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_mode"> <widget class="QComboBox" name="comboBox_mode">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">bridge</string> <string notr="true">bridge</string>
@ -63,19 +81,28 @@
<layout class="QHBoxLayout" name="layout_mac"> <layout class="QHBoxLayout" name="layout_mac">
<item> <item>
<widget class="QLabel" name="label_mac"> <widget class="QLabel" name="label_mac">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>MAC address</string> <string>MAC address</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_mac"> <widget class="QLineEdit" name="lineEdit_mac">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Optional static MAC address</string> <string>Optional static MAC address</string>
</property> </property>

View File

@ -21,6 +21,7 @@
#include <QDBusMessage> #include <QDBusMessage>
#include <QDir> #include <QDir>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QProcessEnvironment>
#include <QTranslator> #include <QTranslator>
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
@ -43,7 +44,7 @@ bool existingSessionOperation(const QString operation)
QDBusMessage response = bus.call(request); QDBusMessage response = bus.call(request);
QList<QVariant> arguments = response.arguments(); QList<QVariant> arguments = response.arguments();
return (!arguments.isEmpty() && bool(arguments[0].toInt())); return (!arguments.isEmpty() && arguments[0].toBool());
} }
@ -130,6 +131,9 @@ int main(int argc, char *argv[])
args[QString("error")] = true; args[QString("error")] = true;
} }
} }
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
if (!args[QString("debug")].toBool()) args[QString("debug")] = (debugEnv == QString("yes"));
if ((args[QString("debug")].toBool()) || if ((args[QString("debug")].toBool()) ||
(args[QString("help")].toBool()) || (args[QString("help")].toBool()) ||
(args[QString("info")].toBool()) || (args[QString("info")].toBool()) ||
@ -137,11 +141,18 @@ int main(int argc, char *argv[])
(args[QString("error")].toBool())) (args[QString("error")].toBool()))
args[QString("detached")] = false; args[QString("detached")] = false;
if (args[QString("essid")].toString() != QString("ESSID")) if (args[QString("essid")].toString() != QString("ESSID"))
args[QString("tab")] = (int) 3; args[QString("tab")] = static_cast<int>(3);
if (args[QString("open")].toString() != QString("PROFILE")) if (args[QString("open")].toString() != QString("PROFILE"))
args[QString("tab")] = (int) 2; args[QString("tab")] = static_cast<int>(2);
if (args[QString("select")].toString() != QString("PROFILE")) if (args[QString("select")].toString() != QString("PROFILE"))
args[QString("tab")] = (int) 1; args[QString("tab")] = static_cast<int>(1);
// check
QString robotEnv = environment.value(QString("SKYNET"), QString(""));
if (!robotEnv.isEmpty()) {
cout << "Sorry, this software is only for humans" << endl;
return 2;
}
// detach from console // detach from console
if (args[QString("detached")].toBool()) if (args[QString("detached")].toBool())
@ -152,17 +163,17 @@ int main(int argc, char *argv[])
QString language = Language::defineLanguage(args[QString("config")].toString(), QString language = Language::defineLanguage(args[QString("config")].toString(),
args[QString("options")].toString()); args[QString("options")].toString());
QTranslator qtTranslator; QTranslator qtTranslator;
qtTranslator.load(QString("qt_") + language, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); qtTranslator.load(QString("qt_%1").arg(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
a.installTranslator(&qtTranslator); a.installTranslator(&qtTranslator);
QTranslator translator; QTranslator translator;
translator.load(QString(":/translations/") + language); translator.load(QString(":/translations/%1").arg(language));
a.installTranslator(&translator); a.installTranslator(&translator);
// running // running
if (args[QString("error")].toBool()) { if (args[QString("error")].toBool()) {
cout << errorMessage().toUtf8().data() << endl; cout << errorMessage().toUtf8().data() << endl;
cout << helpMessage().toUtf8().data(); cout << helpMessage().toUtf8().data();
return 127; return 1;
} else if (args[QString("help")].toBool()) { } else if (args[QString("help")].toBool()) {
cout << helpMessage().toUtf8().data(); cout << helpMessage().toUtf8().data();
return 0; return 0;

File diff suppressed because it is too large Load Diff

View File

@ -1,523 +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/ *
***************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QDesktopServices>
#include <QLibraryInfo>
#include <QTranslator>
#include <QUrl>
#include <language/language.h>
#include <pdebug/pdebug.h>
#include <task/taskadds.h>
#include "aboutwindow.h"
#include "dbusoperation.h"
#include "errorwindow.h"
#include "netctlautowindow.h"
#include "passwdwidget.h"
#include "settingswindow.h"
#include "trayicon.h"
#include "version.h"
void MainWindow::closeMainWindow()
{
if (debug) qDebug() << PDEBUG;
qApp->quit();
}
void MainWindow::showAboutWindow()
{
if (debug) qDebug() << PDEBUG;
aboutWin->show();
}
void MainWindow::showMainWindow()
{
if (debug) qDebug() << PDEBUG;
if (isHidden()) {
updateTabs(ui->tabWidget->currentIndex());
show();
} else
hide();
}
void MainWindow::showNetctlAutoWindow()
{
if (debug) qDebug() << PDEBUG;
netctlAutoWin->showWindow();
}
void MainWindow::showSettingsWindow()
{
if (debug) qDebug() << PDEBUG;
settingsWin->showWindow();
}
bool MainWindow::enableProfileSlot(const QString profile)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
bool current;
if (useHelper) {
QList<QVariant> args;
args.append(profile);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Enable"),
args, true, debug);
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isProfileEnabled"),
args, true, debug)[0].toBool();
} else {
netctlCommand->enableProfile(profile);
current = netctlCommand->isProfileEnabled(profile);
}
return current;
}
bool MainWindow::restartProfileSlot(const QString profile)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
bool current;
if (useHelper) {
QList<QVariant> args;
args.append(profile);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Restart"),
args, true, debug)[0].toBool();
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
args, true, debug)[0].toBool();
} else {
netctlCommand->restartProfile(profile);
current = netctlCommand->isProfileActive(profile);
}
return current;
}
bool MainWindow::startProfileSlot(const QString profile)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
bool current;
if (useHelper) {
QList<QVariant> args;
args.append(profile);
QStringList currentProfile = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("ActiveProfile"),
QList<QVariant>(), true, debug)[0]
.toString().split(QChar('|'));
if ((currentProfile.isEmpty()) || (currentProfile.contains(profile)))
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Start"),
args, true, debug);
else
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("SwitchTo"),
args, true, debug);
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
args, true, debug)[0].toBool();
} else {
QStringList currentProfile = netctlCommand->getActiveProfile();
if ((currentProfile.isEmpty()) || (currentProfile.contains(profile)))
netctlCommand->startProfile(profile);
else
netctlCommand->switchToProfile(profile);
current = netctlCommand->isProfileActive(profile);
}
return current;
}
bool MainWindow::stopAllProfilesSlot()
{
if (debug) qDebug() << PDEBUG;
if (useHelper)
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("StopAll"),
QList<QVariant>(), true, debug);
else
netctlCommand->stopAllProfiles();
return true;
}
bool MainWindow::switchToProfileSlot(const QString profile)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
bool netctlAutoStatus = false;
if (useHelper)
netctlAutoStatus = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"),
QList<QVariant>(), true, debug)[0].toBool();
else
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
bool current;
if (netctlAutoStatus) {
if (useHelper) {
QList<QVariant> args;
args.append(profile);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("autoStart"),
args, true, debug);
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("autoIsProfileActive"),
args, true, debug)[0].toBool();
} else {
netctlCommand->autoStartProfile(profile);
current = netctlCommand->autoIsProfileActive(profile);
}
} else {
if (useHelper) {
QList<QVariant> args;
args.append(profile);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("SwitchTo"),
args, true, debug);
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
args, true, debug)[0].toBool();
} else {
netctlCommand->switchToProfile(profile);
current = netctlCommand->isProfileActive(profile);
}
}
return current;
}
void MainWindow::showApi()
{
if (debug) qDebug() << PDEBUG;
if (QDesktopServices::openUrl(QUrl(QString(DOCS_PATH) + QString("netctl-gui-dbus-api.html"))))
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
}
void MainWindow::showLibrary()
{
if (debug) qDebug() << PDEBUG;
if (QDesktopServices::openUrl(QUrl(QString(DOCS_PATH) + QString("html/index.html"))))
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
}
void MainWindow::showSecurityNotes()
{
if (debug) qDebug() << PDEBUG;
if (QDesktopServices::openUrl(QUrl(QString(DOCS_PATH) + QString("netctl-gui-security-notes.html"))))
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
}
bool MainWindow::forceStartHelper()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("helper"))) {
errorWin->showWindow(1, QString(PDEBUG));
return false;
}
QString cmd = configuration[QString("HELPER_PATH")] + QString(" -c ") + configPath;
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, false);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
if (process.exitCode == 0)
return true;
else
return false;
}
bool MainWindow::forceStopHelper()
{
if (debug) qDebug() << PDEBUG;
QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Close"),
QList<QVariant>(), true, debug);
return !responce.isEmpty();
}
bool MainWindow::startHelper()
{
if (debug) qDebug() << PDEBUG;
if (isHelperActive())
return forceStopHelper();
else
return forceStartHelper();
}
void MainWindow::setTab(int tab)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Update tab" << tab;
switch (tab) {
case 0:
case 1:
case 2:
break;
default:
tab = 0;
break;
}
ui->tabWidget->setCurrentIndex(tab);
updateTabs(tab);
}
void MainWindow::updateConfiguration(const QMap<QString, QVariant> args)
{
if (debug) qDebug() << PDEBUG;
deleteObjects();
settingsWin = new SettingsWindow(this, debug, configPath);
if (args[QString("default")].toBool())
settingsWin->setDefault();
configuration = settingsWin->getSettings();
delete settingsWin;
QMap<QString, QString> optionsDict = parseOptions(args[QString("options")].toString());
for (int i=0; i<optionsDict.keys().count(); i++)
configuration[optionsDict.keys()[i]] = optionsDict[optionsDict.keys()[i]];
if ((configuration[QString("USE_HELPER")] == QString("true")) &&
(checkExternalApps(QString("helper"))))
useHelper = true;
else {
useHelper = false;
configuration[QString("USE_HELPER")] = QString("false");
}
// update translation
qApp->removeTranslator(translator);
QString language = Language::defineLanguage(configPath,
args[QString("options")].toString());
qtTranslator->load(QString("qt_") + language, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
qApp->installTranslator(qtTranslator);
translator->load(QString(":/translations/") + language);
qApp->installTranslator(translator);
createObjects();
createActions();
createToolBars();
// tray
if ((QSystemTrayIcon::isSystemTrayAvailable()) &&
(configuration[QString("SYSTRAY")] == QString("true")))
trayIcon->setVisible(true);
else
trayIcon->setVisible(false);
if (trayIcon->isVisible()) {
if (configuration[QString("STARTTOTRAY")] == QString("true"))
hide();
else
show();
if (args[QString("minimized")].toInt() == 1)
show();
else if (args[QString("minimized")].toInt() == 2)
hide();
}
else
show();
// update ui
setTab(args[QString("tab")].toInt() - 1);
}
void MainWindow::updateMenu()
{
if (debug) qDebug() << PDEBUG;
int tab = ui->tabWidget->currentIndex();
setMenuActionsShown(false);
if (tab == 0)
updateMenuMain();
else if (tab == 1)
updateMenuProfile();
else if (tab == 2)
updateMenuWifi();
}
void MainWindow::updateTabs(const int tab)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Update tab" << tab;
if (tab == 0)
updateMainTab();
else if (tab == 1)
updateProfileTab();
else if (tab == 2)
updateWifiTab();
updateMenu();
}
void MainWindow::connectToUnknownEssid(const QString passwd)
{
if (debug) qDebug() << PDEBUG;
if (passwdWid != 0)
delete passwdWid;
QStringList interfaces;
if (useHelper)
interfaces = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("WirelessInterfaces"),
QList<QVariant>(), true, debug)[0].toStringList();
else
interfaces = netctlCommand->getWirelessInterfaceList();
if (interfaces.isEmpty()) return;
QMap<QString, QString> settings;
settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'");
settings[QString("Interface")] = interfaces[0];
settings[QString("Connection")] = QString("wireless");
QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 2)->text();
if (security.contains(QString("WPA")))
settings[QString("Security")] = QString("wpa");
else if (security.contains(QString("WEP")))
settings[QString("Security")] = QString("wep");
else
settings[QString("Security")] = QString("none");
settings[QString("ESSID")] = QString("'") +
ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text() +
QString("'");
if (!passwd.isEmpty())
settings[QString("Key")] = QString("'") + passwd + QString("'");
settings[QString("IP")] = QString("dhcp");
if (hiddenNetwork)
settings[QString("Hidden")] = QString("yes");
QString profile = QString("netctl-gui-") + settings[QString("ESSID")];
profile.remove(QChar('"')).remove(QChar('\''));
bool status = false;
if (useHelper) {
QStringList settingsList;
for (int i=0; i<settings.keys().count(); i++)
settingsList.append(settings.keys()[i] + QString("==") + settings[settings.keys()[i]]);
QList<QVariant> args;
args.append(profile);
args.append(settingsList);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Create"),
args, true, debug);
args.clear();
args.append(profile);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Start"),
args, true, debug);
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
args, true, debug)[0].toBool();
} else {
QString profileTempName = netctlProfile->createProfile(profile, settings);
netctlProfile->copyProfile(profileTempName);
netctlCommand->startProfile(profile);
status = netctlCommand->isProfileActive(profile);
}
QString message;
if (status) {
message = QApplication::translate("MainWindow", "Connection is successfully.");
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
} else {
message = QApplication::translate("MainWindow", "Connection failed.");
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
}
message += QString("\n");
message += QApplication::translate("MainWindow", "Do you want to save profile %1?").arg(profile);
int select = QMessageBox::question(this, QApplication::translate("MainWindow", "WiFi menu"),
message, QMessageBox::Save | QMessageBox::Discard, QMessageBox::Save);
switch (select) {
case QMessageBox::Save:
break;
case QMessageBox::Discard:
default:
if (useHelper) {
QList<QVariant> args;
args.append(profile);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Remove"),
args, true, debug)[0].toBool();
} else
netctlProfile->removeProfile(profile);
break;
}
updateWifiTab();
}
void MainWindow::setHiddenName(const QString name)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Set name" << name;
ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->setText(name);
wifiTabStart();
}

View File

@ -0,0 +1,427 @@
/***************************************************************************
* 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 "mainwidget.h"
#include "ui_mainwidget.h"
#include <QDebug>
#include <QMenu>
#include <pdebug/pdebug.h>
#include "calls.h"
#include "commonfunctions.h"
#include "dbusoperation.h"
#include "errorwindow.h"
#include "mainwindow.h"
MainWidget::MainWidget(QWidget *parent, const QMap<QString, QString> settings, const bool debugCmd)
: QMainWindow(parent),
debug(debugCmd),
configuration(settings)
{
mainWindow = dynamic_cast<MainWindow *>(parent);
useHelper = (configuration[QString("USE_HELPER")] == QString("true"));
// windows
ui = new Ui::MainWidget;
ui->setupUi(this);
ui->tableWidget_main->setColumnHidden(2, true);
ui->tableWidget_main->setColumnHidden(3, true);
updateToolBarState(static_cast<Qt::ToolBarArea>(configuration[QString("NETCTL_TOOLBAR")].toInt()));
// append toolbar
QMenu *actionMenu = new QMenu(this);
actionMenu->addAction(ui->actionSwitch);
actionMenu->addAction(ui->actionRestart);
actionMenu->addAction(ui->actionEnable);
ui->actionStart->setMenu(actionMenu);
createActions();
}
MainWidget::~MainWidget()
{
if (debug) qDebug() << PDEBUG;
if (ui != nullptr) delete ui;
}
Qt::ToolBarArea MainWidget::getToolBarArea()
{
if (debug) qDebug() << PDEBUG;
return toolBarArea(ui->toolBar);
}
bool MainWidget::mainTabSelectProfileSlot(const QString profile)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
for (int i=0; i<ui->tableWidget_main->rowCount(); i++) {
if (ui->tableWidget_main->item(i, 0)->text() != profile) continue;
ui->tableWidget_main->setCurrentCell(i, 0);
}
return (ui->tableWidget_main->currentItem() != nullptr);
}
void MainWidget::update()
{
if (debug) qDebug() << PDEBUG;
updateMainTab();
updateMenuMain();
}
void MainWidget::updateToolBarState(const Qt::ToolBarArea area)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area;
removeToolBar(ui->toolBar);
if (area != Qt::NoToolBarArea) {
addToolBar(area, ui->toolBar);
ui->toolBar->show();
}
}
void MainWidget::updateMenuMain()
{
if (debug) qDebug() << PDEBUG;
bool selected = (ui->tableWidget_main->currentItem() != nullptr);
ui->actionStart->setEnabled(selected);
ui->actionEnable->setEnabled(selected);
ui->actionEdit->setEnabled(selected);
ui->actionRemove->setEnabled(selected);
if (selected && !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) {
// visible
ui->actionRestart->setEnabled(true);
ui->actionSwitch->setEnabled(false);
// text
ui->actionStart->setText(QApplication::translate("MainWidget", "Stop"));
ui->actionStart->setIcon(QIcon::fromTheme("process-stop"));
} else {
// visible
ui->actionRestart->setEnabled(false);
ui->actionSwitch->setEnabled(selected);
// text
ui->actionStart->setText(QApplication::translate("MainWidget", "Start"));
ui->actionStart->setIcon(QIcon::fromTheme("system-run"));
}
if (selected && !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) {
ui->actionEnable->setText(QApplication::translate("MainWidget", "Disable"));
ui->actionEnable->setIcon(QIcon::fromTheme("edit-remove"));
} else {
ui->actionEnable->setText(QApplication::translate("MainWidget", "Enable"));
ui->actionEnable->setIcon(QIcon::fromTheme("list-add"));
}
}
void MainWidget::updateMainTab()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
mainWindow->setDisabled(true);
netctlInformation info = generalInformation(mainWindow->netctlInterface,
useHelper, debug);
ui->label_netctlAuto->setHidden(!info.netctlAuto);
ui->tableWidget_main->setSortingEnabled(false);
ui->tableWidget_main->selectRow(-1);
ui->tableWidget_main->sortByColumn(0, Qt::AscendingOrder);
ui->tableWidget_main->clear();
ui->tableWidget_main->setRowCount(info.netctlProfiles.count());
// create header
QStringList headerList;
headerList.append(QApplication::translate("MainWidget", "Name"));
headerList.append(QApplication::translate("MainWidget", "Description"));
headerList.append(QApplication::translate("MainWidget", "Active"));
headerList.append(QApplication::translate("MainWidget", "Enabled"));
ui->tableWidget_main->setHorizontalHeaderLabels(headerList);
// create items
for (int i=0; i<info.netctlProfiles.count(); i++) {
// font
QFont font;
font.setBold(info.netctlProfiles[i].active);
font.setItalic(info.netctlProfiles[i].enabled);
// tooltip
QString toolTip = QString("");
toolTip += QString("%1: %2@%3\n").arg(QApplication::translate("MainWidget", "Type"))
.arg(info.netctlProfiles[i].type)
.arg(info.netctlProfiles[i].interface);
toolTip += QString("%1: %2\n").arg(QApplication::translate("MainWidget", "Active"))
.arg(checkStatus(info.netctlProfiles[i].active));
toolTip += QString("%1: %2\n").arg(QApplication::translate("MainWidget", "Enabled"))
.arg(checkStatus(info.netctlProfiles[i].enabled));
toolTip += QString("%1: %2").arg(QApplication::translate("MainWidget", "Is wireless"))
.arg(checkStatus(!info.netctlProfiles[i].essid.isEmpty()));
// name
ui->tableWidget_main->setItem(i, 0, new QTableWidgetItem(info.netctlProfiles[i].name));
ui->tableWidget_main->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
ui->tableWidget_main->item(i, 0)->setToolTip(toolTip);
ui->tableWidget_main->item(i, 0)->setFont(font);
// description
ui->tableWidget_main->setItem(i, 1, new QTableWidgetItem(info.netctlProfiles[i].description));
ui->tableWidget_main->item(i, 1)->setTextAlignment(Qt::AlignJustify | Qt::AlignVCenter);
ui->tableWidget_main->item(i, 1)->setToolTip(toolTip);
// active
ui->tableWidget_main->setItem(i, 2, new QTableWidgetItem(checkStatus(info.netctlProfiles[i].active, true)));
ui->tableWidget_main->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// enabled
ui->tableWidget_main->setItem(i, 3, new QTableWidgetItem(checkStatus(info.netctlProfiles[i].enabled, true)));
ui->tableWidget_main->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
ui->tableWidget_main->setSortingEnabled(true);
ui->tableWidget_main->resizeRowsToContents();
ui->tableWidget_main->resizeColumnsToContents();
ui->tableWidget_main->resizeRowsToContents();
#if QT_VERSION >= 0x050000
ui->tableWidget_main->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
ui->tableWidget_main->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
#endif
mainWindow->setDisabled(false);
mainWindow->showMessage(true);
}
void MainWidget::mainTabContextualMenu(const QPoint &pos)
{
if (debug) qDebug() << PDEBUG;
if (ui->tableWidget_main->currentItem() == nullptr) return;
// create menu
QMenu menu(this);
QAction *refreshTable = menu.addAction(QApplication::translate("MainWidget", "Refresh"));
refreshTable->setIcon(QIcon::fromTheme("view-refresh"));
menu.addSeparator();
QAction *startProfile = menu.addAction(QApplication::translate("MainWidget", "Start profile"));
QAction *restartProfile = menu.addAction(QApplication::translate("MainWidget", "Restart profile"));
restartProfile->setIcon(QIcon::fromTheme("view-refresh"));
QAction *enableProfile = menu.addAction(QApplication::translate("MainWidget", "Enable profile"));
menu.addSeparator();
QAction *editProfile = menu.addAction(QApplication::translate("MainWidget", "Edit profile"));
editProfile->setIcon(QIcon::fromTheme("document-edit"));
QAction *removeProfile = menu.addAction(QApplication::translate("MainWidget", "Remove profile"));
removeProfile->setIcon(QIcon::fromTheme("edit-delete"));
// set text
if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) {
restartProfile->setVisible(true);
startProfile->setText(QApplication::translate("MainWidget", "Stop profile"));
startProfile->setIcon(QIcon::fromTheme("process-stop"));
} else {
restartProfile->setVisible(false);
startProfile->setText(QApplication::translate("MainWidget", "Start profile"));
startProfile->setIcon(QIcon::fromTheme("system-run"));
}
if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) {
enableProfile->setText(QApplication::translate("MainWidget", "Disable profile"));
enableProfile->setIcon(QIcon::fromTheme("edit-remove"));
} else {
enableProfile->setText(QApplication::translate("MainWidget", "Enable profile"));
enableProfile->setIcon(QIcon::fromTheme("list-add"));
}
// actions
QAction *action = menu.exec(ui->tableWidget_main->viewport()->mapToGlobal(pos));
if (action == refreshTable) {
if (debug) qDebug() << PDEBUG << ":" << "Refresh table";
updateMainTab();
} else if (action == startProfile) {
if (debug) qDebug() << PDEBUG << ":" << "Start profile";
mainTabStartProfile();
} else if (action == restartProfile) {
if (debug) qDebug() << PDEBUG << ":" << "Restart profile";
mainTabRestartProfile();
} else if (action == enableProfile) {
if (debug) qDebug() << PDEBUG << ":" << "Enable profile";
mainTabEnableProfile();
} else if (action == editProfile) {
if (debug) qDebug() << PDEBUG << ":" << "Edit profile";
mainTabEditProfile();
} else if (action == removeProfile) {
if (debug) qDebug() << PDEBUG << ":" << "Remove profile";
mainTabRemoveProfile();
}
}
void MainWidget::mainTabEditProfile()
{
if (debug) qDebug() << PDEBUG;
if (ui->tableWidget_main->currentItem() == nullptr) return;
mainWindow->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
mainWindow->setTab(1);
mainWindow->openProfileSlot(profile);
}
void MainWidget::mainTabEnableProfile()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget_main->currentItem() == nullptr) return;
mainWindow->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
InterfaceAnswer answer = enableProfileSlot(profile, mainWindow->netctlInterface,
useHelper, debug);
// TODO check if status has been changed?
mainWindow->showMessage(answer != InterfaceAnswer::Error);
updateMainTab();
}
void MainWidget::mainTabRemoveProfile()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("sudo"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("sudo"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget_main->currentItem() == nullptr) return;
mainWindow->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
InterfaceAnswer answer = removeProfileSlot(profile, mainWindow->netctlInterface,
useHelper, debug);
mainWindow->showMessage(answer == InterfaceAnswer::True);
updateMainTab();
}
void MainWidget::mainTabRestartProfile()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget_main->currentItem() == nullptr) return;
mainWindow->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
InterfaceAnswer answer = restartProfileSlot(profile, mainWindow->netctlInterface,
useHelper, debug);
mainWindow->showMessage(answer == InterfaceAnswer::True);
updateMainTab();
}
void MainWidget::mainTabStartProfile()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget_main->currentItem() == nullptr) return;
mainWindow->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
InterfaceAnswer answer = startProfileSlot(profile, mainWindow->netctlInterface,
useHelper, debug);
mainWindow->showMessage(answer == InterfaceAnswer::True);
updateMainTab();
}
void MainWidget::mainTabStopAllProfiles()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
mainWindow->setDisabled(true);
InterfaceAnswer answer = stopAllProfilesSlot(mainWindow->netctlInterface,
useHelper, debug);
mainWindow->showMessage(answer == InterfaceAnswer::True);
updateMainTab();
}
void MainWidget::mainTabSwitchToProfile()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget_main->currentItem() == nullptr) return;
mainWindow->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
InterfaceAnswer answer = switchToProfileSlot(profile, mainWindow->netctlInterface,
useHelper, debug);
mainWindow->showMessage(answer == InterfaceAnswer::True);
updateMainTab();
}
void MainWidget::createActions()
{
if (debug) qDebug() << PDEBUG;
// menu actions
connect(ui->actionEnable, SIGNAL(triggered(bool)), this, SLOT(mainTabEnableProfile()));
connect(ui->actionEdit, SIGNAL(triggered(bool)), this, SLOT(mainTabEditProfile()));
connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(updateMainTab()));
connect(ui->actionRemove, SIGNAL(triggered(bool)), this, SLOT(mainTabRemoveProfile()));
connect(ui->actionRestart, SIGNAL(triggered(bool)), this, SLOT(mainTabRestartProfile()));
connect(ui->actionStart, SIGNAL(triggered(bool)), this, SLOT(mainTabStartProfile()));
connect(ui->actionStop_all, SIGNAL(triggered(bool)), this, SLOT(mainTabStopAllProfiles()));
connect(ui->actionSwitch, SIGNAL(triggered(bool)), this, SLOT(mainTabSwitchToProfile()));
// main tab events
connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile()));
connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
this, SLOT(updateMenuMain()));
connect(ui->tableWidget_main, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(mainTabContextualMenu(QPoint)));
}

View File

@ -0,0 +1,77 @@
/***************************************************************************
* 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 MAINWIDGET_H
#define MAINWIDGET_H
#include <QMainWindow>
#include <QTableWidgetItem>
#include <netctlgui/netctlgui.h>
class MainWindow;
namespace Ui {
class MainWidget;
}
class MainWidget : public QMainWindow
{
Q_OBJECT
public:
explicit MainWidget(QWidget *parent = 0,
const QMap<QString,QString> settings = QMap<QString,QString>(),
const bool debugCmd = false);
~MainWidget();
Qt::ToolBarArea getToolBarArea();
public slots:
bool mainTabSelectProfileSlot(const QString profile);
void update();
void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea);
private slots:
// update slots
void updateMenuMain();
void updateMainTab();
// main tab slots
void mainTabContextualMenu(const QPoint &pos);
void mainTabEditProfile();
void mainTabEnableProfile();
void mainTabRemoveProfile();
void mainTabRestartProfile();
void mainTabStartProfile();
void mainTabStopAllProfiles();
void mainTabSwitchToProfile();
private:
// ui
MainWindow *mainWindow = nullptr;
Ui::MainWidget *ui = nullptr;
// backend
void createActions();
QString configPath;
bool debug = false;
bool useHelper = true;
// configuration
QMap<QString, QString> configuration;
};
#endif /* MAINWIDGET_H */

View File

@ -0,0 +1,208 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWidget</class>
<widget class="QMainWindow" name="MainWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>515</width>
<height>477</height>
</rect>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_netctlAuto">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>netctl-auto is running</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget_main">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="columnCount">
<number>4</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Description</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column/>
<column/>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>Main actions toolbar</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonFollowStyle</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionRefresh"/>
<addaction name="separator"/>
<addaction name="actionStart"/>
<addaction name="actionStop_all"/>
<addaction name="separator"/>
<addaction name="actionEdit"/>
<addaction name="actionRemove"/>
</widget>
<action name="actionRefresh">
<property name="icon">
<iconset theme="view-refresh">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Refresh</string>
</property>
<property name="toolTip">
<string>Refresh table</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="actionStart">
<property name="icon">
<iconset theme="system-run">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Start</string>
</property>
<property name="toolTip">
<string>Start or stop selected profile</string>
</property>
</action>
<action name="actionSwitch">
<property name="text">
<string>Switch</string>
</property>
<property name="toolTip">
<string>Switch to selected profile</string>
</property>
</action>
<action name="actionRestart">
<property name="icon">
<iconset theme="view-refresh">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Restart</string>
</property>
<property name="toolTip">
<string>Restart selected profile</string>
</property>
</action>
<action name="actionEnable">
<property name="icon">
<iconset theme="list-add">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Enable</string>
</property>
<property name="toolTip">
<string>Enable or disable selected profile</string>
</property>
</action>
<action name="actionStop_all">
<property name="icon">
<iconset theme="process-stop">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Stop all</string>
</property>
<property name="toolTip">
<string>Stop all profiles</string>
</property>
</action>
<action name="actionEdit">
<property name="icon">
<iconset theme="document-edit">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Edit</string>
</property>
<property name="toolTip">
<string>Edit selected profile</string>
</property>
</action>
<action name="actionRemove">
<property name="icon">
<iconset theme="edit-delete">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="toolTip">
<string>Remove selected profile</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -21,31 +21,34 @@
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusMessage> #include <QDBusMessage>
#include <QDebug> #include <QDebug>
#include <QMenu> #include <QDesktopServices>
#include <QFileDialog>
#include <QFileInfo>
#include <QLibraryInfo>
#include <QProcessEnvironment>
#include <QSettings>
#include <QTranslator>
#include <QUrl>
#include <language/language.h>
#include <listmap/listmap.h>
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include <task/taskadds.h> #include <task/taskadds.h>
#include "aboutwindow.h" #include "aboutwindow.h"
#include "bridgewidget.h" #include "calls.h"
#include "commonfunctions.h"
#include "dbusoperation.h" #include "dbusoperation.h"
#include "errorwindow.h" #include "errorwindow.h"
#include "ethernetwidget.h" #include "mainwidget.h"
#include "generalwidget.h"
#include "ipwidget.h"
#include "macvlanwidget.h"
#include "mobilewidget.h"
#include "netctlautowindow.h" #include "netctlautowindow.h"
#include "netctlguiadaptor.h" #include "netctlguiadaptor.h"
#include "newprofilewidget.h"
#include "passwdwidget.h" #include "passwdwidget.h"
#include "pppoewidget.h"
#include "settingswindow.h" #include "settingswindow.h"
#include "trayicon.h" #include "trayicon.h"
#include "tunnelwidget.h"
#include "tuntapwidget.h"
#include "version.h" #include "version.h"
#include "vlanwidget.h" #include "wifimenuwidget.h"
#include "wirelesswidget.h"
MainWindow::MainWindow(QWidget *parent, MainWindow::MainWindow(QWidget *parent,
@ -72,24 +75,19 @@ MainWindow::MainWindow(QWidget *parent,
if (debug) qDebug() << PDEBUG << ":" << "settings" << args[QString("settings")].toBool(); if (debug) qDebug() << PDEBUG << ":" << "settings" << args[QString("settings")].toBool();
if (debug) qDebug() << PDEBUG << ":" << "tab" << args[QString("tab")].toInt(); if (debug) qDebug() << PDEBUG << ":" << "tab" << args[QString("tab")].toInt();
ui = new Ui::MainWindow;
ui->setupUi(this);
updateConfiguration(args); updateConfiguration(args);
// main actions // main actions
if (args[QString("essid")].toString() != QString("ESSID")) { if (args[QString("essid")].toString() != QString("ESSID")) {
for (int i=0; i<ui->tableWidget_wifi->rowCount(); i++) if (!wifiMenuWidget->wifiTabSelectEssidSlot(args[QString("essid")].toString()))
if (ui->tableWidget_wifi->item(i, 0)->text() == args[QString("essid")].toString()) ErrorWindow::showWindow(18, QString(PDEBUG), debug);
ui->tableWidget_wifi->setCurrentCell(i, 0);
if (ui->tableWidget_wifi->currentItem() == 0)
errorWin->showWindow(18, QString(PDEBUG));
} else if (args[QString("open")].toString() != QString("PROFILE")) { } else if (args[QString("open")].toString() != QString("PROFILE")) {
ui->comboBox_profile->addItem(args[QString("open")].toString()); newProfileWidget->profileTabOpenProfileSlot(args[QString("open")].toString());
ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count()-1);
} else if (args[QString("select")].toString() != QString("PROFILE")) { } else if (args[QString("select")].toString() != QString("PROFILE")) {
for (int i=0; i<ui->tableWidget_main->rowCount(); i++) if (!mainWidget->mainTabSelectProfileSlot(args[QString("select")].toString()))
if (ui->tableWidget_main->item(i, 0)->text() == args[QString("select")].toString()) ErrorWindow::showWindow(17, QString(PDEBUG), debug);
ui->tableWidget_main->setCurrentCell(i, 0);
if (ui->tableWidget_main->currentItem() == 0)
errorWin->showWindow(17, QString(PDEBUG));
} }
// show windows // show windows
@ -111,39 +109,23 @@ MainWindow::~MainWindow()
if ((useHelper) && (configuration[QString("CLOSE_HELPER")] == QString("true"))) if ((useHelper) && (configuration[QString("CLOSE_HELPER")] == QString("true")))
forceStopHelper(); forceStopHelper();
deleteObjects(); deleteObjects();
delete ui;
} }
QStringList MainWindow::printInformation() Qt::ToolBarArea MainWindow::getToolBarArea()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QString profile; return toolBarArea(ui->toolBar);
QString status; }
if (useHelper) {
QStringList request = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("Information"),
QList<QVariant>(), true, debug)[0].toStringList();
profile = request[0];
status = request[1];
} else {
if (netctlCommand->isNetctlAutoRunning()) {
profile = netctlCommand->autoGetActiveProfile();
status = QString("netctl-auto");
} else {
QStringList currentProfiles = netctlCommand->getActiveProfile();
profile = currentProfiles.join(QChar('|'));
QStringList statusList;
for (int i=0; i<currentProfiles.count(); i++)
statusList.append(netctlCommand->getProfileStatus(currentProfiles[i]));
status = statusList.join(QChar('|'));
}
}
QStringList output;
output.append(profile);
output.append(status);
return output;
void MainWindow::emitNeedToBeConfigured()
{
if (debug) qDebug() << PDEBUG;
emit(needToBeConfigured());
} }
@ -151,79 +133,15 @@ QStringList MainWindow::printSettings()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QStringList settingsList; return mapToList(configuration);
for (int i=0; i<configuration.keys().count(); i++)
settingsList.append(configuration.keys()[i] + QString("==") +
configuration[configuration.keys()[i]]);
return settingsList;
} }
QStringList MainWindow::printTrayInformation() netctlCurrent MainWindow::printTrayInformation()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QStringList information; return trayInformation(netctlInterface, useHelper, debug);
QString current;
QString enabled;
bool netctlAutoStatus = false;
QList<netctlProfileInfo> profiles;
if (useHelper) {
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("ActiveProfile"),
QList<QVariant>(), true, debug)[0].toString();
netctlAutoStatus = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"),
QList<QVariant>(), true, debug)[0].toBool();
profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("ProfileList"),
QList<QVariant>(), true, debug), debug);
if (netctlAutoStatus) {
QList<QVariant> args;
args.append(current);
enabled = QString::number(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("autoIsProfileEnabled"),
args, true, debug)[0].toBool());
} else {
QStringList currentProfiles = current.split(QChar('|'));
QStringList enabledList;
for (int i=0; i<currentProfiles.count(); i++) {
QList<QVariant> args;
args.append(currentProfiles[i]);
enabledList.append(QString::number(
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isProfileEnabled"),
args, true, debug)[0].toBool()));
enabled = enabledList.join(QChar('|'));
}
}
} else {
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
if (netctlAutoStatus) {
current = netctlCommand->autoGetActiveProfile();
enabled = QString::number(netctlCommand->autoIsProfileEnabled(current));
profiles = netctlCommand->getProfileListFromNetctlAuto();
} else {
QStringList currentProfiles = netctlCommand->getActiveProfile();
current = currentProfiles.join(QChar('|'));
QStringList enabledList;
for (int i=0; i<currentProfiles.count(); i++)
enabledList.append(QString::number(netctlCommand->isProfileEnabled(currentProfiles[i])));
enabled = enabledList.join(QChar('|'));
profiles = netctlCommand->getProfileList();
}
}
information.append(QString::number(netctlAutoStatus));
QStringList profileList;
for (int i=0; i<profiles.count(); i++)
profileList.append(profiles[i].name);
information.append(profileList.join(QChar('|')));
information.append(current);
information.append(enabled);
return information;
} }
@ -231,11 +149,9 @@ bool MainWindow::isHelperActive()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, QList<QVariant> responce = sendRequestToCtrl(QString("Active"), debug);
DBUS_HELPER_INTERFACE, QString("Active"),
QList<QVariant>(), true, debug);
return (!responce.isEmpty() && bool(responce[0].toInt())); return (!responce.isEmpty());
} }
@ -243,18 +159,15 @@ bool MainWindow::isHelperServiceActive()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QString cmd = configuration[QString("SYSTEMCTL_PATH")] + QString(" is-active ") + QString cmd = QString("%1 is-active %2").arg(configuration[QString("SYSTEMCTL_PATH")])
configuration[QString("HELPER_SERVICE")]; .arg(configuration[QString("HELPER_SERVICE")]);
if (debug) qDebug() << PDEBUG << "Run cmd" << cmd; if (debug) qDebug() << PDEBUG << "Run cmd" << cmd;
TaskResult process = runTask(cmd, false); TaskResult process = runTask(cmd, false);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0) if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
if (process.exitCode != 0) return (process.exitCode == 0);
return false;
else
return true;
} }
@ -262,62 +175,299 @@ void MainWindow::closeEvent(QCloseEvent *event)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if ((QSystemTrayIcon::isSystemTrayAvailable()) && if ((QSystemTrayIcon::isSystemTrayAvailable()) && (configuration[QString("SYSTRAY")] == QString("true"))) {
(configuration[QString("SYSTRAY")] == QString("true"))) {
hide(); hide();
trayIcon->showMessage(QApplication::translate("MainWindow", "Information"),
QApplication::translate("MainWindow", "Application has been hidden to tray"));
event->ignore(); event->ignore();
} else } else
closeMainWindow(); closeMainWindow();
} }
bool MainWindow::checkExternalApps(const QString apps = QString("all")) // tray icon
void MainWindow::closeMainWindow()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (configuration[QString("SKIPCOMPONENTS")] == QString("true")) return true; storeToolBars();
QStringList cmd; qApp->quit();
cmd.append("which"); }
cmd.append(configuration[QString("SUDO_PATH")]);
if ((apps == QString("helper")) || (apps == QString("all"))) {
cmd.append(configuration[QString("HELPER_PATH")]); void MainWindow::openProfileSlot(const QString profile)
} {
if ((apps == QString("netctl")) || (apps == QString("all"))) { if (debug) qDebug() << PDEBUG;
cmd.append(configuration[QString("NETCTL_PATH")]);
cmd.append(configuration[QString("NETCTLAUTO_PATH")]); newProfileWidget->profileTabOpenProfileSlot(profile);
} }
if ((apps == QString("systemctl")) || (apps == QString("all"))) {
cmd.append(configuration[QString("SYSTEMCTL_PATH")]);
} void MainWindow::showAboutWindow()
if ((apps == QString("wpasup")) || (apps == QString("all"))) { {
cmd.append(configuration[QString("WPACLI_PATH")]); if (debug) qDebug() << PDEBUG;
cmd.append(configuration[QString("WPASUP_PATH")]);
aboutWin->show();
}
void MainWindow::showMainWindow()
{
if (debug) qDebug() << PDEBUG;
if (isHidden()) {
setTab(ui->stackedWidget->currentIndex());
show();
} else
hide();
}
void MainWindow::showNetctlAutoWindow()
{
if (debug) qDebug() << PDEBUG;
netctlAutoWin->showWindow();
}
void MainWindow::showSettingsWindow()
{
if (debug) qDebug() << PDEBUG;
storeToolBars();
settingsWin->showWindow();
}
void MainWindow::showApi()
{
if (debug) qDebug() << PDEBUG;
showMessage(QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-dbus-api.html").arg(QString(DOCS_PATH)))));
}
void MainWindow::showLibrary()
{
if (debug) qDebug() << PDEBUG;
showMessage(QDesktopServices::openUrl(QUrl(QString("%1html/index.html").arg(QString(DOCS_PATH)))));
}
void MainWindow::showSecurityNotes()
{
if (debug) qDebug() << PDEBUG;
showMessage(QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-security-notes.html").arg(QString(DOCS_PATH)))));
}
bool MainWindow::forceStartHelper()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("helper"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("helper"), configuration).join(QChar('\n')), debug);
emit(needToBeConfigured());
return false;
} }
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd.join(QChar(' ')); QString cmd = QString("%1 -c %2").arg(configuration[QString("HELPER_PATH")]).arg(configPath);
TaskResult process = runTask(cmd.join(QChar(' ')), false); if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, false);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0) if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
if (process.exitCode != 0) return (process.exitCode == 0);
return false;
else
return true;
} }
bool MainWindow::forceStopHelper()
{
if (debug) qDebug() << PDEBUG;
QList<QVariant> responce = sendRequestToCtrl(QString("Close"), debug);
return (!responce.isEmpty());
}
bool MainWindow::startHelper()
{
if (debug) qDebug() << PDEBUG;
if (isHelperActive())
return forceStopHelper();
else
return forceStartHelper();
}
void MainWindow::setDisabled(const bool disabled)
{
if (debug) qDebug() << PDEBUG;
ui->toolBar->setDisabled(disabled);
ui->stackedWidget->setDisabled(disabled);
}
void MainWindow::setTab(int tab)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Set tab" << tab;
if (ui->stackedWidget->currentWidget() == nullptr) return;
if ((tab > 2) || (tab < 0)) tab = 0;
if (tab != ui->stackedWidget->currentIndex())
return ui->stackedWidget->setCurrentIndex(tab);
switch (tab) {
case 1:
newProfileWidget->update();
break;
case 2:
wifiMenuWidget->update();
break;
case 0:
default:
mainWidget->update();
break;
}
}
void MainWindow::showMessage(const bool status)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Status" << status;
if (status)
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
}
void MainWindow::storeToolBars()
{
if (debug) qDebug() << PDEBUG;
QSettings settings(configPath, QSettings::IniFormat);
settings.beginGroup(QString("Toolbars"));
settings.setValue(QString("MAIN_TOOLBAR"), QString::number(getToolBarArea()));
settings.setValue(QString("NETCTL_TOOLBAR"), QString::number(mainWidget->getToolBarArea()));
settings.setValue(QString("NETCTLAUTO_TOOLBAR"), QString::number(netctlAutoWin->getToolBarArea()));
settings.setValue(QString("PROFILE_TOOLBAR"), QString::number(newProfileWidget->getToolBarArea()));
settings.setValue(QString("WIFI_TOOLBAR"), QString::number(wifiMenuWidget->getToolBarArea()));
settings.endGroup();
settings.sync();
}
void MainWindow::updateConfiguration(const QMap<QString, QVariant> args)
{
if (debug) qDebug() << PDEBUG;
deleteObjects();
settingsWin = new SettingsWindow(this, debug, configPath);
if (args[QString("default")].toBool())
settingsWin->setDefault();
configuration = settingsWin->getSettings();
delete settingsWin;
QMap<QString, QString> optionsDict = parseOptions(args[QString("options")].toString());
for (int i=0; i<optionsDict.keys().count(); i++)
configuration[optionsDict.keys()[i]] = optionsDict[optionsDict.keys()[i]];
if ((configuration[QString("USE_HELPER")] == QString("true")) &&
(checkExternalApps(QString("helper"), configuration, debug)))
useHelper = true;
else {
useHelper = false;
configuration[QString("USE_HELPER")] = QString("false");
}
// update translation
qApp->removeTranslator(translator);
QString language = Language::defineLanguage(configPath, args[QString("options")].toString());
if (debug) qDebug() << PDEBUG << ":" << "Language is" << language;
qtTranslator->load(QString("qt_%1").arg(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
qApp->installTranslator(qtTranslator);
translator->load(QString(":/translations/%1").arg(language));
qApp->installTranslator(translator);
createObjects();
createActions();
// tray
trayIcon->setVisible(QSystemTrayIcon::isSystemTrayAvailable() && (configuration[QString("SYSTRAY")] == QString("true")));
if (trayIcon->isVisible()) {
setHidden(configuration[QString("STARTTOTRAY")] == QString("true"));
if (args[QString("minimized")].toInt() == 1)
show();
else if (args[QString("minimized")].toInt() == 2)
hide();
}
else
show();
// update ui
setTab(args[QString("tab")].toInt() - 1);
}
void MainWindow::updateToolBarState(const Qt::ToolBarArea area)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area;
removeToolBar(ui->toolBar);
if (area != Qt::NoToolBarArea) {
addToolBar(area, ui->toolBar);
ui->toolBar->show();
}
}
// private slots
void MainWindow::setTabByAction(QAction *action)
{
if (debug) qDebug() << PDEBUG;
if (action == nullptr) return;
if (action == ui->actionNetctl)
setTab(0);
else if (action == ui->actionProfiles)
setTab(1);
else if (action == ui->actionWiFi_menu)
setTab(2);
}
void MainWindow::reportABug()
{
if (debug) qDebug() << PDEBUG;
showMessage(QDesktopServices::openUrl(QUrl(QString(BUGTRACKER))));
}
// window signals
bool MainWindow::checkHelperStatus() bool MainWindow::checkHelperStatus()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (useHelper) useHelper = isHelperActive(); if (useHelper) useHelper = isHelperActive();
if (useHelper) if (useHelper)
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, sendRequestToCtrl(QString("Update"), debug);
DBUS_HELPER_INTERFACE, QString("Update"), else {
QList<QVariant>(), true, debug);
else
configuration[QString("FORCE_SUDO")] = QString("true"); configuration[QString("FORCE_SUDO")] = QString("true");
configuration[QString("USE_HELPER")] = QString("false");
}
if (isHelperServiceActive()) if (isHelperServiceActive())
configuration[QString("CLOSE_HELPER")] = QString("false"); configuration[QString("CLOSE_HELPER")] = QString("false");
@ -325,48 +475,23 @@ bool MainWindow::checkHelperStatus()
} }
QString MainWindow::checkStatus(const bool statusBool, const bool nullFalse)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Status" << statusBool;
if (debug) qDebug() << PDEBUG << ":" << "Return null false" << nullFalse;
if (statusBool)
return QApplication::translate("MainWindow", "yes");
if (nullFalse)
return QString("");
else
return QApplication::translate("MainWindow", "no");
}
// window signals
void MainWindow::createActions() void MainWindow::createActions()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int))); connect(ui->toolBar, SIGNAL(actionTriggered(QAction *)), this, SLOT(setTabByAction(QAction *)));
connect(ui->pushButton_menu, SIGNAL(clicked(bool)), this, SLOT(updateToolBars())); connect(ui->actionNetctl_auto, SIGNAL(triggered()), this, SLOT(showNetctlAutoWindow()));
connect(ui->pushButton_action, SIGNAL(clicked(bool)), this, SLOT(updateToolBars())); connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(setTab(int)));
connect(ui->pushButton_help, SIGNAL(clicked(bool)), this, SLOT(updateToolBars())); connect(this, SIGNAL(needToBeConfigured()), this, SLOT(showSettingsWindow()));
// main tab events // menu
connect(ui->pushButton_netctlAuto, SIGNAL(clicked(bool)), this, SLOT(showNetctlAutoWindow())); connect(ui->actionSettings, SIGNAL(triggered()), this, SLOT(showSettingsWindow()));
connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile())); connect(ui->actionSecurity, SIGNAL(triggered()), this, SLOT(showSecurityNotes()));
connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), connect(ui->actionDBus_API, SIGNAL(triggered()), this, SLOT(showApi()));
this, SLOT(updateMenuMain())); connect(ui->actionLibrary, SIGNAL(triggered()), this, SLOT(showLibrary()));
connect(ui->tableWidget_main, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(mainTabContextualMenu(QPoint))); connect(ui->actionReport_a_bug, SIGNAL(triggered()), this, SLOT(reportABug()));
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutWindow()));
// profile tab events connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(closeMainWindow()));
connect(ui->comboBox_profile, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabLoadProfile()));
connect(ui->comboBox_profile, SIGNAL(editTextChanged(QString)), this, SLOT(updateMenuProfile()));
connect(generalWid->connectionType, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabChangeState(QString)));
// wifi tab events
connect(ui->tableWidget_wifi, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(wifiTabStart()));
connect(ui->tableWidget_wifi, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
this, SLOT(updateMenuWifi()));
connect(ui->tableWidget_wifi, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(wifiTabContextualMenu(QPoint)));
} }
@ -392,154 +517,31 @@ void MainWindow::createObjects()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
// error messages
errorWin = new ErrorWindow(this, debug);
// backend // backend
createDBusSession(); createDBusSession();
if (useHelper) if ((useHelper) && (!forceStartHelper())) {
if (!forceStartHelper()) { ErrorWindow::showWindow(19, QString(PDEBUG), debug);
errorWin->showWindow(19, QString(PDEBUG)); useHelper = false;
useHelper = false; }
}
checkHelperStatus(); checkHelperStatus();
netctlCommand = new Netctl(debug, configuration); netctlCommand = new Netctl(debug, configuration);
netctlProfile = new NetctlProfile(debug, configuration); netctlInterface = new NetctlInterface(debug, configuration);
wpaCommand = new WpaSup(debug, configuration); wpaCommand = new WpaSup(debug, configuration);
// frontend // frontend
trayIcon = new TrayIcon(this, debug); mainWidget = new MainWidget(this, configuration, debug);
netctlAutoWin = new NetctlAutoWindow(this, configuration, debug);
newProfileWidget = new NewProfileWidget(this, configuration, debug);
wifiMenuWidget = new WiFiMenuWidget(this, configuration, debug);
trayIcon = new TrayIcon(this, configuration, debug);
// windows // windows
ui = new Ui::MainWindow; ui->retranslateUi(this);
ui->setupUi(this); ui->stackedWidget->addWidget(mainWidget);
ui->tableWidget_main->setColumnHidden(2, true); ui->stackedWidget->addWidget(newProfileWidget);
ui->tableWidget_main->setColumnHidden(3, true); ui->stackedWidget->addWidget(wifiMenuWidget);
ui->tableWidget_wifi->setColumnHidden(3, true); updateToolBarState(static_cast<Qt::ToolBarArea>(configuration[QString("MAIN_TOOLBAR")].toInt()));
ui->tableWidget_wifi->setColumnHidden(4, true);
aboutWin = new AboutWindow(this, debug); aboutWin = new AboutWindow(this, debug);
netctlAutoWin = new NetctlAutoWindow(this, debug, configuration);
settingsWin = new SettingsWindow(this, debug, configPath); settingsWin = new SettingsWindow(this, debug, configPath);
// profile widgets
generalWid = new GeneralWidget(this, configuration);
ui->scrollAreaWidgetContents->layout()->addWidget(generalWid);
ipWid = new IpWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(ipWid);
bridgeWid = new BridgeWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(bridgeWid);
ethernetWid = new EthernetWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(ethernetWid);
macvlanWid = new MacvlanWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(macvlanWid);
mobileWid = new MobileWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(mobileWid);
pppoeWid = new PppoeWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(pppoeWid);
tunnelWid = new TunnelWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(tunnelWid);
tuntapWid = new TuntapWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(tuntapWid);
vlanWid = new VlanWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(vlanWid);
wirelessWid = new WirelessWidget(this, configuration);
ui->scrollAreaWidgetContents->layout()->addWidget(wirelessWid);
}
void MainWindow::createToolBars()
{
if (debug) qDebug() << PDEBUG;
mainToolBar = new QToolBar(this);
mainToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
toolBarActions[QString("netctlAuto")] = mainToolBar->addAction(QApplication::translate("MainWindow", "netctl-auto"),
this, SLOT(showNetctlAutoWindow()));
toolBarActions[QString("settings")] = mainToolBar->addAction(QIcon::fromTheme(QString("configure")),
QApplication::translate("MainWindow", "Settings"),
this, SLOT(showSettingsWindow()));
appShortcuts[QString("settingsShortcut")] = new QShortcut(QKeySequence(QApplication::translate("MainWindow", "Ctrl+S")),
this, SLOT(showSettingsWindow()));
toolBarActions[QString("quit")] = mainToolBar->addAction(QIcon::fromTheme(QString("exit")),
QApplication::translate("MainWindow", "Quit"),
this, SLOT(closeMainWindow()));
appShortcuts[QString("quitShortcut")] = new QShortcut(QKeySequence(QApplication::translate("MainWindow", "Ctrl+Q")),
this, SLOT(closeMainWindow()));
ui->centralLayout->insertWidget(1, mainToolBar);
mainToolBar->setHidden(true);
actionToolBar = new QToolBar(this);
actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
toolBarActions[QString("mainRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("stock-refresh")),
QApplication::translate("MainWindow", "Refresh"),
this, SLOT(updateMainTab()));
toolBarActions[QString("profileClear")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-clear")),
QApplication::translate("MainWindow", "Clear"),
this, SLOT(profileTabClear()));
toolBarActions[QString("wifiRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("stock-refresh")),
QApplication::translate("MainWindow", "Refresh"),
this, SLOT(updateWifiTab()));
actionMenu = new QToolButton(this);
actionMenu->setPopupMode(QToolButton::DelayedPopup);
actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle);
QMenu *menu = new QMenu(actionMenu);
toolBarActions[QString("mainStart")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
QApplication::translate("MainWindow", "Start"),
this, SLOT(mainTabStartProfile()));
toolBarActions[QString("mainSwitch")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
QApplication::translate("MainWindow", "Switch"),
this, SLOT(mainTabSwitchToProfile()));
toolBarActions[QString("mainRestart")] = menu->addAction(QIcon::fromTheme(QString("stock-refresh")),
QApplication::translate("MainWindow", "Restart"),
this, SLOT(mainTabRestartProfile()));
toolBarActions[QString("mainEnable")] = menu->addAction(QIcon::fromTheme(QString("edit-add")),
QApplication::translate("MainWindow", "Enable"),
this, SLOT(mainTabEnableProfile()));
toolBarActions[QString("mainStopAll")] = menu->addAction(QIcon::fromTheme(QString("process-stop")),
QApplication::translate("MainWindow", "Stop all"),
this, SLOT(mainTabStopAllProfiles()));
toolBarActions[QString("profileLoad")] = menu->addAction(QIcon::fromTheme(QString("document-open")),
QApplication::translate("MainWindow", "Load"),
this, SLOT(profileTabLoadProfile()));
toolBarActions[QString("profileSave")] = menu->addAction(QIcon::fromTheme(QString("document-save")),
QApplication::translate("MainWindow", "Save"),
this, SLOT(profileTabCreateProfile()));
toolBarActions[QString("wifiStart")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
QApplication::translate("MainWindow", "Start"),
this, SLOT(wifiTabStart()));
actionMenu->setMenu(menu);
actionToolBar->addWidget(actionMenu);
toolBarActions[QString("mainEdit")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit")),
QApplication::translate("MainWindow", "Edit"),
this, SLOT(mainTabEditProfile()));
toolBarActions[QString("mainRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")),
QApplication::translate("MainWindow", "Remove"),
this, SLOT(mainTabRemoveProfile()));
toolBarActions[QString("profileRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")),
QApplication::translate("MainWindow", "Remove"),
this, SLOT(profileTabRemoveProfile()));
ui->centralLayout->insertWidget(1, actionToolBar);
actionToolBar->setHidden(true);
helpToolBar = new QToolBar(this);
helpToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
toolBarActions[QString("security")] = helpToolBar->addAction(QIcon::fromTheme(QString("security-medium")),
QApplication::translate("MainWindow", "Security"),
this, SLOT(showSecurityNotes()));
toolBarActions[QString("api")] = helpToolBar->addAction(QApplication::translate("MainWindow", "DBus API"),
this, SLOT(showApi()));
toolBarActions[QString("library")] = helpToolBar->addAction(QApplication::translate("MainWindow", "Library"),
this, SLOT(showLibrary()));
helpToolBar->addSeparator();
toolBarActions[QString("report")] = helpToolBar->addAction(QIcon::fromTheme(QString("tools-report-bug")),
QApplication::translate("MainWindow", "Report a bug"),
this, SLOT(reportABug()));
toolBarActions[QString("about")] = helpToolBar->addAction(QIcon::fromTheme(QString("help-about")),
QApplication::translate("MainWindow", "About"),
this, SLOT(showAboutWindow()));
ui->centralLayout->insertWidget(1, helpToolBar);
helpToolBar->setHidden(true);
ui->pushButton_menu->click();
} }
@ -547,58 +549,22 @@ void MainWindow::deleteObjects()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
// workaround to avoid crash on window closing
disconnect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(setTab(int)));
QDBusConnection::sessionBus().unregisterObject(DBUS_OBJECT_PATH); QDBusConnection::sessionBus().unregisterObject(DBUS_OBJECT_PATH);
QDBusConnection::sessionBus().unregisterService(DBUS_SERVICE); QDBusConnection::sessionBus().unregisterService(DBUS_SERVICE);
if (netctlCommand != nullptr) delete netctlCommand; if (netctlCommand != nullptr) delete netctlCommand;
if (netctlProfile != nullptr) delete netctlProfile; if (netctlInterface != nullptr) delete netctlInterface;
if (wpaCommand != nullptr) delete wpaCommand; if (wpaCommand != nullptr) delete wpaCommand;
if (bridgeWid != nullptr) delete bridgeWid;
if (ethernetWid != nullptr) delete ethernetWid;
if (generalWid != nullptr) delete generalWid;
if (ipWid != nullptr) delete ipWid;
if (macvlanWid != nullptr) delete macvlanWid;
if (mobileWid != nullptr) delete mobileWid;
if (pppoeWid != nullptr) delete pppoeWid;
if (tunnelWid != nullptr) delete tunnelWid;
if (tuntapWid != nullptr) delete tuntapWid;
if (vlanWid != nullptr) delete vlanWid;
if (wirelessWid != nullptr) delete wirelessWid;
if (aboutWin != nullptr) delete aboutWin; if (aboutWin != nullptr) delete aboutWin;
if (errorWin != nullptr) delete errorWin;
if (netctlAutoWin != nullptr) delete netctlAutoWin;
if (settingsWin != nullptr) delete settingsWin; if (settingsWin != nullptr) delete settingsWin;
if (actionMenu != nullptr) {
actionMenu->menu()->clear();
delete actionMenu;
}
if (actionToolBar != nullptr) {
actionToolBar->clear();
delete actionToolBar;
}
if (helpToolBar != nullptr) {
helpToolBar->clear();
delete helpToolBar;
}
if (mainToolBar != nullptr) {
mainToolBar->clear();
delete mainToolBar;
delete appShortcuts[QString("settingsShortcut")];
delete appShortcuts[QString("quitShortcut")];
}
if (trayIcon != nullptr) delete trayIcon; if (trayIcon != nullptr) delete trayIcon;
if (ui != nullptr) delete ui; if (mainWidget != nullptr) delete mainWidget;
} if (netctlAutoWin != nullptr) delete netctlAutoWin;
if (newProfileWidget != nullptr) delete newProfileWidget;
if (wifiMenuWidget != nullptr) delete wifiMenuWidget;
void MainWindow::keyPressEvent(QKeyEvent *pressedKey)
{
if (debug) qDebug() << PDEBUG;
if (pressedKey->key() == Qt::Key_Return)
if (ui->comboBox_profile->hasFocus())
profileTabLoadProfile();
} }
@ -608,12 +574,12 @@ QMap<QString, QString> MainWindow::parseOptions(const QString options)
QMap<QString, QString> settings; QMap<QString, QString> settings;
for (int i=0; i<options.split(QChar(',')).count(); i++) { for (int i=0; i<options.split(QChar(',')).count(); i++) {
if (options.split(QChar(','))[i].split(QChar('=')).count() < 2) continue; QStringList option = options.split(QChar(','))[i].split(QChar('='));
settings[options.split(QChar(','))[i].split(QChar('='))[0]] = if (option.count() != 2) continue;
options.split(QChar(','))[i].split(QChar('='))[1]; settings[option[0]] = option[1];
} }
for (int i=0; i<settings.keys().count(); i++) for (int i=0; i<settings.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << settings.keys()[i] + QString("=") + settings[settings.keys()[i]]; if (debug) qDebug() << PDEBUG << ":" << QString("%1=%2").arg(settings.keys()[i]).arg(settings[settings.keys()[i]]);
return settings; return settings;
} }

View File

@ -20,31 +20,18 @@
#include <QApplication> #include <QApplication>
#include <QMainWindow> #include <QMainWindow>
#include <QShortcut> #include <QTreeWidgetItem>
#include <QTableWidgetItem>
#include <QToolBar>
#include <QToolButton>
#include <netctlgui/netctlgui.h> #include <netctlgui/netctlgui.h>
class AboutWindow; class AboutWindow;
class BridgeWidget; class MainWidget;
class ErrorWindow;
class EthernetWidget;
class GeneralWidget;
class IpWidget;
class MacvlanWidget;
class MobileWidget;
class NetctlAutoWindow; class NetctlAutoWindow;
class PasswdWidget; class NewProfileWidget;
class PppoeWidget;
class SettingsWindow; class SettingsWindow;
class TrayIcon; class TrayIcon;
class TunnelWidget; class WiFiMenuWidget;
class TuntapWidget;
class VlanWidget;
class WirelessWidget;
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
@ -60,11 +47,16 @@ public:
QTranslator *qtAppTranslator = 0, QTranslator *qtAppTranslator = 0,
QTranslator *appTranslator = 0); QTranslator *appTranslator = 0);
~MainWindow(); ~MainWindow();
QStringList printInformation(); Qt::ToolBarArea getToolBarArea();
void emitNeedToBeConfigured();
QStringList printSettings(); QStringList printSettings();
QStringList printTrayInformation(); netctlCurrent printTrayInformation();
bool isHelperActive(); bool isHelperActive();
bool isHelperServiceActive(); bool isHelperServiceActive();
// library interfaces
Netctl *netctlCommand = nullptr;
NetctlInterface *netctlInterface = nullptr;
WpaSup *wpaCommand = nullptr;
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
@ -72,16 +64,11 @@ protected:
public slots: public slots:
// actions from trayicon // actions from trayicon
void closeMainWindow(); void closeMainWindow();
void openProfileSlot(const QString profile);
void showAboutWindow(); void showAboutWindow();
void showMainWindow(); void showMainWindow();
void showNetctlAutoWindow(); void showNetctlAutoWindow();
void showSettingsWindow(); void showSettingsWindow();
// trayicon control slots
bool enableProfileSlot(const QString profile);
bool startProfileSlot(const QString profile);
bool stopAllProfilesSlot();
bool switchToProfileSlot(const QString profile);
bool restartProfileSlot(const QString profile);
// open docs // open docs
void showApi(); void showApi();
void showLibrary(); void showLibrary();
@ -91,89 +78,38 @@ public slots:
bool forceStopHelper(); bool forceStopHelper();
bool startHelper(); bool startHelper();
// main // main
void setDisabled(const bool disabled = true);
void setTab(int tab); void setTab(int tab);
void showMessage(const bool status);
void storeToolBars();
void updateConfiguration(const QMap<QString, QVariant> args = QMap<QString, QVariant>()); void updateConfiguration(const QMap<QString, QVariant> args = QMap<QString, QVariant>());
void updateMenu(); void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea);
void updateTabs(const int tab);
// wifi tab slots signals:
void connectToUnknownEssid(const QString passwd); void needToBeConfigured();
void setHiddenName(const QString name);
private slots: private slots:
void setTabByAction(QAction *action);
void reportABug(); void reportABug();
// menu update slots
void setMenuActionsShown(const bool state = true);
void updateMenuMain();
void updateMenuProfile();
void updateMenuWifi();
void updateToolBars();
// tab update slots
void updateMainTab();
void updateProfileTab();
void updateWifiTab();
// main tab slots
void mainTabContextualMenu(const QPoint &pos);
void mainTabEditProfile();
void mainTabEnableProfile();
QStringList mainTabGetActiveProfiles();
void mainTabRemoveProfile();
void mainTabRestartProfile();
void mainTabStartProfile();
void mainTabStopAllProfiles();
void mainTabSwitchToProfile();
// profile tab slots
void profileTabChangeState(const QString current);
void profileTabClear();
void profileTabCreateProfile();
void profileTabLoadProfile();
void profileTabRemoveProfile();
// wifi tab slots
void wifiTabContextualMenu(const QPoint &pos);
void wifiTabSetEnabled(const bool state);
void wifiTabStart();
private: private:
// ui // ui
TrayIcon *trayIcon = nullptr; TrayIcon *trayIcon = nullptr;
QMap<QString, QShortcut *> appShortcuts;
QMap<QString, QAction *> toolBarActions;
QToolButton *actionMenu = nullptr;
QToolBar *actionToolBar = nullptr;
QToolBar *helpToolBar = nullptr;
QToolBar *mainToolBar = nullptr;
Ui::MainWindow *ui = nullptr; Ui::MainWindow *ui = nullptr;
AboutWindow *aboutWin = nullptr; AboutWindow *aboutWin = nullptr;
ErrorWindow *errorWin = nullptr; MainWidget *mainWidget = nullptr;
NetctlAutoWindow *netctlAutoWin = nullptr; NetctlAutoWindow *netctlAutoWin = nullptr;
PasswdWidget *passwdWid = nullptr; NewProfileWidget *newProfileWidget = nullptr;
SettingsWindow *settingsWin = nullptr; SettingsWindow *settingsWin = nullptr;
BridgeWidget *bridgeWid = nullptr; WiFiMenuWidget *wifiMenuWidget = nullptr;
EthernetWidget *ethernetWid = nullptr;
GeneralWidget *generalWid = nullptr;
IpWidget *ipWid = nullptr;
MacvlanWidget *macvlanWid = nullptr;
MobileWidget *mobileWid = nullptr;
PppoeWidget *pppoeWid = nullptr;
TunnelWidget *tunnelWid = nullptr;
TuntapWidget *tuntapWid = nullptr;
VlanWidget *vlanWid = nullptr;
WirelessWidget *wirelessWid = nullptr;
// backend // backend
Netctl *netctlCommand = nullptr;
NetctlProfile *netctlProfile = nullptr;
WpaSup *wpaCommand = nullptr;
bool checkExternalApps(const QString apps);
bool checkHelperStatus(); bool checkHelperStatus();
QString checkStatus(const bool statusBool, const bool nullFalse = false);
void createActions(); void createActions();
void createDBusSession(); void createDBusSession();
void createObjects(); void createObjects();
void createToolBars();
void deleteObjects(); void deleteObjects();
void keyPressEvent(QKeyEvent *pressedKey);
QString configPath; QString configPath;
bool debug = false; bool debug = false;
bool hiddenNetwork;
bool useHelper = true; bool useHelper = true;
QTranslator *qtTranslator = nullptr; QTranslator *qtTranslator = nullptr;
QTranslator *translator = nullptr; QTranslator *translator = nullptr;

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>469</width> <width>600</width>
<height>497</height> <height>497</height>
</rect> </rect>
</property> </property>
@ -16,283 +16,189 @@
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="centralLayout"> <layout class="QVBoxLayout" name="centralLayout">
<item> <item>
<layout class="QHBoxLayout" name="layout_menus"> <widget class="QStackedWidget" name="stackedWidget">
<item> <property name="sizePolicy">
<widget class="QPushButton" name="pushButton_menu"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<property name="styleSheet"> <horstretch>0</horstretch>
<string notr="true">border: none;</string> <verstretch>0</verstretch>
</property> </sizepolicy>
<property name="text">
<string>Menu</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_action">
<property name="styleSheet">
<string notr="true">border: none;</string>
</property>
<property name="text">
<string>Actions</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_help">
<property name="styleSheet">
<string notr="true">border: none;</string>
</property>
<property name="text">
<string>Help</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property> </property>
<widget class="QWidget" name="tab_main">
<attribute name="icon">
<iconset resource="../../resources/resources.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</attribute>
<attribute name="title">
<string>Connect to profile</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget_netctlAuto" native="true">
<layout class="QHBoxLayout" name="layout_netctlAuto">
<item>
<widget class="QLabel" name="label_netctlAuto">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>netctl-auto is running</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_netctlAuto">
<property name="text">
<string>Show</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget_main">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="columnCount">
<number>4</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Description</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column/>
<column/>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_new">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset theme="document-new">
<normaloff/>
</iconset>
</attribute>
<attribute name="title">
<string>Create a new profile</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="layout_profile">
<item>
<widget class="QLabel" name="label_profile">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_profile">
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>437</width>
<height>368</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="scrollArea_layout"/>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_wifi">
<attribute name="icon">
<iconset resource="../../resources/resources.qrc">
<normaloff>:/wifi.png</normaloff>:/wifi.png</iconset>
</attribute>
<attribute name="title">
<string>WiFi menu</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_wifi">
<property name="text">
<string>Please install 'wpa_supplicant' before using it</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget_wifi">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="columnCount">
<number>5</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Signal</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Security</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column/>
<column/>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuMenu">
<property name="title">
<string>Menu</string>
</property>
<addaction name="actionSettings"/>
<addaction name="separator"/>
<addaction name="actionSecurity"/>
<addaction name="actionDBus_API"/>
<addaction name="actionLibrary"/>
<addaction name="separator"/>
<addaction name="actionReport_a_bug"/>
<addaction name="actionAbout"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<addaction name="menuMenu"/>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>Toolbar</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonFollowStyle</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionNetctl_auto"/>
<addaction name="actionNetctl"/>
<addaction name="actionProfiles"/>
<addaction name="actionWiFi_menu"/>
</widget>
<action name="actionSecurity">
<property name="icon">
<iconset theme="security-medium">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Security</string>
</property>
<property name="toolTip">
<string>Show security notes</string>
</property>
</action>
<action name="actionDBus_API">
<property name="text">
<string>DBus API</string>
</property>
<property name="toolTip">
<string>Show DBus API</string>
</property>
</action>
<action name="actionLibrary">
<property name="text">
<string>Library</string>
</property>
<property name="toolTip">
<string>Show library docs</string>
</property>
</action>
<action name="actionReport_a_bug">
<property name="icon">
<iconset theme="tools-report-bug">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Report a bug</string>
</property>
</action>
<action name="actionAbout">
<property name="icon">
<iconset theme="help-about">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>About</string>
</property>
<property name="toolTip">
<string>About this application</string>
</property>
</action>
<action name="actionQuit">
<property name="icon">
<iconset theme="application-exit">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Quit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionSettings">
<property name="icon">
<iconset theme="configure">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Settings</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionNetctl">
<property name="icon">
<iconset resource="../../resources/resources.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<property name="text">
<string>netctl control</string>
</property>
<property name="toolTip">
<string>netctl control</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
<action name="actionProfiles">
<property name="icon">
<iconset theme="document-new">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Profiles</string>
</property>
<property name="toolTip">
<string>Profiles</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="actionWiFi_menu">
<property name="icon">
<iconset resource="../../resources/resources.qrc">
<normaloff>:/wifi.png</normaloff>:/wifi.png</iconset>
</property>
<property name="text">
<string>WiFi menu</string>
</property>
<property name="shortcut">
<string>Ctrl+W</string>
</property>
</action>
<action name="actionNetctl_auto">
<property name="text">
<string>netctl-auto</string>
</property>
</action>
</widget> </widget>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>tableWidget_main</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>tableWidget_wifi</tabstop>
</tabstops>
<resources> <resources>
<include location="../../resources/resources.qrc"/> <include location="../../resources/resources.qrc"/>
</resources> </resources>

View File

@ -25,9 +25,7 @@
QString errorMessage() QString errorMessage()
{ {
QString errorMessage = QApplication::translate("MainWindow", "Unknown flag\n"); return QApplication::translate("MainWindow", "Unknown flag\n");
return errorMessage;
} }
@ -36,7 +34,7 @@ QMap<QString, QVariant> getArgs()
QMap<QString, QVariant> args; QMap<QString, QVariant> args;
// windows // windows
args[QString("detached")] = false; args[QString("detached")] = false;
args[QString("minimized")] = (int) 0; args[QString("minimized")] = static_cast<int>(0);
args[QString("about")] = false; args[QString("about")] = false;
args[QString("auto")] = false; args[QString("auto")] = false;
args[QString("settings")] = false; args[QString("settings")] = false;
@ -45,11 +43,11 @@ QMap<QString, QVariant> getArgs()
args[QString("open")] = QString("PROFILE"); args[QString("open")] = QString("PROFILE");
args[QString("select")] = QString("PROFILE"); args[QString("select")] = QString("PROFILE");
// additional functions // additional functions
args[QString("config")] = QString(QDir::homePath() + QString("/.config/netctl-gui.conf")); args[QString("config")] = QString("%1/.config/netctl-gui.conf").arg(QDir::homePath());
args[QString("debug")] = false; args[QString("debug")] = false;
args[QString("defaults")] = false; args[QString("defaults")] = false;
args[QString("options")] = QString("OPTIONS"); args[QString("options")] = QString("OPTIONS");
args[QString("tab")] = (int) 1; args[QString("tab")] = static_cast<int>(1);
// messages // messages
args[QString("error")] = false; args[QString("error")] = false;
args[QString("help")] = false; args[QString("help")] = false;
@ -68,46 +66,29 @@ QString helpMessage()
helpMessage += QString("%1\n").arg(QApplication::translate("MainWindow", "Options:")); helpMessage += QString("%1\n").arg(QApplication::translate("MainWindow", "Options:"));
// windows // windows
helpMessage += QString(" %1\n").arg(QApplication::translate("MainWindow", "Open window:")); helpMessage += QString(" %1\n").arg(QApplication::translate("MainWindow", "Open window:"));
helpMessage += QString(" --detached - %1\n") helpMessage += QString(" --detached - %1\n").arg(QApplication::translate("MainWindow", "start detached from console"));
.arg(QApplication::translate("MainWindow", "start detached from console")); helpMessage += QString(" --maximized - %1\n").arg(QApplication::translate("MainWindow", "start maximized"));
helpMessage += QString(" --maximized - %1\n") helpMessage += QString(" --minimized - %1\n").arg(QApplication::translate("MainWindow", "start minimized to tray"));
.arg(QApplication::translate("MainWindow", "start maximized")); helpMessage += QString(" --about - %1\n").arg(QApplication::translate("MainWindow", "show about window"));
helpMessage += QString(" --minimized - %1\n") helpMessage += QString(" --netctl-auto - %1\n").arg(QApplication::translate("MainWindow", "show netctl-auto window"));
.arg(QApplication::translate("MainWindow", "start minimized to tray")); helpMessage += QString(" --settings - %1\n").arg(QApplication::translate("MainWindow", "show settings window"));
helpMessage += QString(" --about - %1\n")
.arg(QApplication::translate("MainWindow", "show about window"));
helpMessage += QString(" --netctl-auto - %1\n")
.arg(QApplication::translate("MainWindow", "show netctl-auto window"));
helpMessage += QString(" --settings - %1\n")
.arg(QApplication::translate("MainWindow", "show settings window"));
// main functions // main functions
helpMessage += QString(" %1\n").arg(QApplication::translate("MainWindow", "Functions:")); helpMessage += QString(" %1\n").arg(QApplication::translate("MainWindow", "Functions:"));
helpMessage += QString(" -e, --essid <arg> - %1\n") helpMessage += QString(" -e, --essid <arg> - %1\n").arg(QApplication::translate("MainWindow", "select this ESSID"));
.arg(QApplication::translate("MainWindow", "select this ESSID")); helpMessage += QString(" -o, --open <arg> - %1\n").arg(QApplication::translate("MainWindow", "open this profile"));
helpMessage += QString(" -o, --open <arg> - %1\n") helpMessage += QString(" -s, --select <arg> - %1\n").arg(QApplication::translate("MainWindow", "select this profile"));
.arg(QApplication::translate("MainWindow", "open this profile"));
helpMessage += QString(" -s, --select <arg> - %1\n")
.arg(QApplication::translate("MainWindow", "select this profile"));
// additional functions // additional functions
helpMessage += QString(" %1\n").arg(QApplication::translate("MainWindow", "Additional flags:")); helpMessage += QString(" %1\n").arg(QApplication::translate("MainWindow", "Additional flags:"));
helpMessage += QString(" -c, --config <arg> - %1\n") helpMessage += QString(" -c, --config <arg> - %1\n").arg(QApplication::translate("MainWindow", "read configuration from this file"));
.arg(QApplication::translate("MainWindow", "read configuration from this file")); helpMessage += QString(" -d, --debug - %1\n").arg(QApplication::translate("MainWindow", "print debug information"));
helpMessage += QString(" -d, --debug - %1\n") helpMessage += QString(" --default - %1\n").arg(QApplication::translate("MainWindow", "start with default settings"));
.arg(QApplication::translate("MainWindow", "print debug information")); helpMessage += QString(" --set-opts <arg> - %1\n").arg(QApplication::translate("MainWindow", "set options for this run, comma separated"));
helpMessage += QString(" --default - %1\n") helpMessage += QString(" -t, --tab <arg> - %1\n").arg(QApplication::translate("MainWindow", "open a tab with this number"));
.arg(QApplication::translate("MainWindow", "start with default settings"));
helpMessage += QString(" --set-opts <arg> - %1\n")
.arg(QApplication::translate("MainWindow", "set options for this run, comma separated"));
helpMessage += QString(" -t, --tab <arg> - %1\n")
.arg(QApplication::translate("MainWindow", "open a tab with this number"));
// messages // messages
helpMessage += QString(" %1\n").arg(QApplication::translate("MainWindow", "Show messages:")); helpMessage += QString(" %1\n").arg(QApplication::translate("MainWindow", "Show messages:"));
helpMessage += QString(" -v, --version - %1\n") helpMessage += QString(" -v, --version - %1\n").arg(QApplication::translate("MainWindow", "show version and exit"));
.arg(QApplication::translate("MainWindow", "show version and exit")); helpMessage += QString(" -i, --info - %1\n").arg(QApplication::translate("MainWindow", "show build information and exit"));
helpMessage += QString(" -i, --info - %1\n") helpMessage += QString(" -h, --help - %1\n").arg(QApplication::translate("MainWindow", "show this help and exit"));
.arg(QApplication::translate("MainWindow", "show build information and exit"));
helpMessage += QString(" -h, --help - %1\n")
.arg(QApplication::translate("MainWindow", "show this help and exit"));
return helpMessage; return helpMessage;
} }
@ -117,8 +98,7 @@ QString infoMessage()
{ {
QString infoMessage = QString(""); QString infoMessage = QString("");
// build information // build information
infoMessage += QApplication::translate("MainWindow", "Build date: %1"). infoMessage += QApplication::translate("MainWindow", "Build date: %1").arg(QString(BUILD_DATE));
arg(QString(BUILD_DATE));
// cmake // cmake
infoMessage += QString("\n%1:\n").arg(QApplication::translate("MainWindow", "cmake flags")); infoMessage += QString("\n%1:\n").arg(QApplication::translate("MainWindow", "cmake flags"));
// cmake properties // cmake properties
@ -141,6 +121,7 @@ QString infoMessage()
infoMessage += QString("\t-DDBUS_SYSTEMCONF_PATH=%1\n").arg(QString(PROJECT_DBUS_SYSTEMCONF_PATH)); infoMessage += QString("\t-DDBUS_SYSTEMCONF_PATH=%1\n").arg(QString(PROJECT_DBUS_SYSTEMCONF_PATH));
infoMessage += QString("\t-DSYSTEMD_SERVICE_PATH=%1\n").arg(QString(PROJECT_SYSTEMD_SERVICE_PATH)); infoMessage += QString("\t-DSYSTEMD_SERVICE_PATH=%1\n").arg(QString(PROJECT_SYSTEMD_SERVICE_PATH));
infoMessage += QString("\t-DUSE_CAPABILITIES=%1\n").arg(QString(PROJECT_USE_CAPABILITIES)); infoMessage += QString("\t-DUSE_CAPABILITIES=%1\n").arg(QString(PROJECT_USE_CAPABILITIES));
infoMessage += QString("\t-DUSE_KDE4=%1\n").arg(QString(PROJECT_USE_KDE4));
infoMessage += QString("\t-DUSE_QT5=%1\n").arg(QString(PROJECT_USE_QT5)); infoMessage += QString("\t-DUSE_QT5=%1\n").arg(QString(PROJECT_USE_QT5));
// transport information // transport information
infoMessage += QString("%1:\n").arg(QApplication::translate("MainWindow", "DBus configuration")); infoMessage += QString("%1:\n").arg(QApplication::translate("MainWindow", "DBus configuration"));
@ -163,15 +144,9 @@ QString versionMessage()
{ {
QString versionMessage = QString(""); QString versionMessage = QString("");
versionMessage += QString("%1\n").arg(QString(NAME)); versionMessage += QString("%1\n").arg(QString(NAME));
versionMessage += QString("%1 : %2\n") versionMessage += QString("%1 : %2\n").arg(QApplication::translate("MainWindow", "Version")).arg(QString(VERSION));
.arg(QApplication::translate("MainWindow", "Version")) versionMessage += QString("%1 : %2\n").arg(QApplication::translate("MainWindow", "Author")).arg(QString(AUTHOR));
.arg(QString(VERSION)); versionMessage += QString("%1 : %2\n").arg(QApplication::translate("MainWindow", "License")).arg(QString(LICENSE));
versionMessage += QString("%1 : %2\n")
.arg(QApplication::translate("MainWindow", "Author"))
.arg(QString(AUTHOR));
versionMessage += QString("%1 : %2\n")
.arg(QApplication::translate("MainWindow", "License"))
.arg(QString(LICENSE));
return versionMessage; return versionMessage;
} }

View File

@ -56,15 +56,6 @@ void MobileWidget::clear()
} }
void MobileWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void MobileWidget::createActions() void MobileWidget::createActions()
{ {
connect(ui->pushButton_mobileAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced())); connect(ui->pushButton_mobileAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced()));
@ -74,8 +65,7 @@ void MobileWidget::createActions()
void MobileWidget::selectOptionsFile() void MobileWidget::selectOptionsFile()
{ {
QString filename = QFileDialog::getOpenFileName( QString filename = QFileDialog::getOpenFileName(this,
this,
QApplication::translate("MobileWidget", "Select options file"), QApplication::translate("MobileWidget", "Select options file"),
QDir::currentPath(), QDir::currentPath(),
QApplication::translate("MobileWidget", "Configuration files (*.conf)")); QApplication::translate("MobileWidget", "Configuration files (*.conf)"));
@ -88,53 +78,50 @@ void MobileWidget::showAdvanced()
{ {
if (ui->pushButton_mobileAdvanced->isChecked()) { if (ui->pushButton_mobileAdvanced->isChecked()) {
ui->widget_mobileAdvanced->setHidden(false); ui->widget_mobileAdvanced->setHidden(false);
ui->pushButton_mobileAdvanced->setText(QApplication::translate("MobileWidget", "Hide advanced")); ui->pushButton_mobileAdvanced->setArrowType(Qt::UpArrow);
} else { } else {
ui->widget_mobileAdvanced->setHidden(true); ui->widget_mobileAdvanced->setHidden(true);
ui->pushButton_mobileAdvanced->setText(QApplication::translate("MobileWidget", "Show advanced")); ui->pushButton_mobileAdvanced->setArrowType(Qt::DownArrow);
} }
} }
QMap<QString, QString> MobileWidget::getSettings() QMap<QString, QString> MobileWidget::getSettings()
{ {
QMap<QString, QString> mobileSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return mobileSettings;
if (!ui->lineEdit_username->text().isEmpty()) if (!ui->lineEdit_username->text().isEmpty())
mobileSettings[QString("User")] = QString("'") + ui->lineEdit_username->text() + QString("'"); settings[QString("User")] = QString("'%1'").arg(ui->lineEdit_username->text());
if (!ui->lineEdit_password->text().isEmpty()) if (!ui->lineEdit_password->text().isEmpty())
mobileSettings[QString("Password")] = QString("'") + ui->lineEdit_password->text() + QString("'"); settings[QString("Password")] = QString("'%1'").arg(ui->lineEdit_password->text());
mobileSettings[QString("AccessPointName")] = ui->lineEdit_apn->text(); settings[QString("AccessPointName")] = ui->lineEdit_apn->text();
if (!ui->lineEdit_pin->text().isEmpty()) if (!ui->lineEdit_pin->text().isEmpty())
mobileSettings[QString("PIN")] = QString("'") + ui->lineEdit_pin->text() + QString("'"); settings[QString("PIN")] = QString("'%1'").arg(ui->lineEdit_pin->text());
else else
mobileSettings[QString("PIN")] = QString("None"); settings[QString("PIN")] = QString("None");
mobileSettings[QString("Mode")] = ui->comboBox_mode->currentText(); settings[QString("Mode")] = ui->comboBox_mode->currentText();
if (ui->spinBox_fail->value() != 5) if (ui->spinBox_fail->value() != 5)
mobileSettings[QString("MaxFail")] = QString::number(ui->spinBox_fail->value()); settings[QString("MaxFail")] = QString::number(ui->spinBox_fail->value());
if (ui->checkBox_route->checkState() == Qt::Unchecked) if (ui->checkBox_route->checkState() == Qt::Unchecked)
mobileSettings[QString("DefaultRoute")] = QString("false"); settings[QString("DefaultRoute")] = QString("false");
if (ui->checkBox_dns->checkState() == Qt::Unchecked) if (ui->checkBox_dns->checkState() == Qt::Unchecked)
mobileSettings[QString("UsePeerDNS")] = QString("false"); settings[QString("UsePeerDNS")] = QString("false");
if (!ui->lineEdit_options->text().isEmpty()) if (!ui->lineEdit_options->text().isEmpty())
mobileSettings[QString("OptionsFile")] = QString("'") + ui->lineEdit_options->text() + QString("'"); settings[QString("OptionsFile")] = QString("'%1'").arg(ui->lineEdit_options->text());
return mobileSettings; return settings;
} }
int MobileWidget::isOk() int MobileWidget::isOk()
{ {
// APN is not set // APN is not set
if (ui->lineEdit_apn->text().isEmpty()) if (ui->lineEdit_apn->text().isEmpty()) return 1;
return 1;
// config file doesn't exist // config file doesn't exist
if (!ui->lineEdit_options->text().isEmpty()) if (!ui->lineEdit_options->text().isEmpty())
if (!QFile(ui->lineEdit_options->text()).exists()) if (!QFile(ui->lineEdit_options->text()).exists()) return 2;
return 2;
// all fine // all fine
return 0; return 0;
} }
@ -143,28 +130,27 @@ int MobileWidget::isOk()
void MobileWidget::setSettings(const QMap<QString, QString> settings) void MobileWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> mobileSettings = settings;
if (mobileSettings.contains(QString("User"))) if (settings.contains(QString("User")))
ui->lineEdit_username->setText(mobileSettings[QString("User")]); ui->lineEdit_username->setText(settings[QString("User")]);
if (mobileSettings.contains(QString("Password"))) if (settings.contains(QString("Password")))
ui->lineEdit_password->setText(mobileSettings[QString("Password")]); ui->lineEdit_password->setText(settings[QString("Password")]);
if (mobileSettings.contains(QString("AccessPointName"))) if (settings.contains(QString("AccessPointName")))
ui->lineEdit_apn->setText(mobileSettings[QString("AccessPointName")]); ui->lineEdit_apn->setText(settings[QString("AccessPointName")]);
if (mobileSettings.contains(QString("PIN"))) if (settings.contains(QString("PIN")))
ui->lineEdit_pin->setText(mobileSettings[QString("PIN")]); ui->lineEdit_pin->setText(settings[QString("PIN")]);
if (mobileSettings.contains(QString("Mode"))) if (settings.contains(QString("Mode"))) {
for (int i=0; i<ui->comboBox_mode->count(); i++) int index = ui->comboBox_mode->findText(settings[QString("Mode")]);
if (mobileSettings[QString("Mode")] == ui->comboBox_mode->itemText(i)) ui->comboBox_mode->setCurrentIndex(index);
ui->comboBox_mode->setCurrentIndex(i); }
if (mobileSettings.contains(QString("MaxFail"))) if (settings.contains(QString("MaxFail")))
ui->spinBox_fail->setValue(mobileSettings[QString("MaxFail")].toInt()); ui->spinBox_fail->setValue(settings[QString("MaxFail")].toInt());
if (mobileSettings.contains(QString("DefaultRoute"))) if (settings.contains(QString("DefaultRoute")))
if (mobileSettings[QString("DefaultRoute")] == QString("false")) if (settings[QString("DefaultRoute")] == QString("false"))
ui->checkBox_route->setCheckState(Qt::Unchecked); ui->checkBox_route->setCheckState(Qt::Unchecked);
if (mobileSettings.contains(QString("UsePeerDNS"))) if (settings.contains(QString("UsePeerDNS")))
if (mobileSettings[QString("UsePeerDNS")] == QString("false")) if (settings[QString("UsePeerDNS")] == QString("false"))
ui->checkBox_dns->setCheckState(Qt::Unchecked); ui->checkBox_dns->setCheckState(Qt::Unchecked);
if (mobileSettings.contains(QString("OptionsFile"))) if (settings.contains(QString("OptionsFile")))
ui->lineEdit_options->setText(mobileSettings[QString("OptionsFile")]); ui->lineEdit_options->setText(settings[QString("OptionsFile")]);
} }

View File

@ -38,7 +38,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private slots: private slots:
void selectOptionsFile(); void selectOptionsFile();

View File

@ -7,13 +7,13 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>445</width> <width>445</width>
<height>370</height> <height>314</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_mobile"> <widget class="QDockWidget" name="dockWidget_mobile">
<property name="features"> <property name="features">
@ -24,23 +24,35 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_mobile"> <widget class="QWidget" name="dockWidgetContents_mobile">
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_username"> <layout class="QHBoxLayout" name="layout_username">
<item> <item>
<widget class="QLabel" name="label_username"> <widget class="QLabel" name="label_username">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Username</string> <string>Username</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_username"> <widget class="QLineEdit" name="lineEdit_username">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The username and password to connect with</string> <string>The username and password to connect with</string>
</property> </property>
@ -52,22 +64,34 @@
<layout class="QHBoxLayout" name="layout_password"> <layout class="QHBoxLayout" name="layout_password">
<item> <item>
<widget class="QLabel" name="label_password"> <widget class="QLabel" name="label_password">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Password</string> <string>Password</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_password"> <widget class="QLineEdit" name="lineEdit_password">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The username and password to connect with</string> <string>The username and password to connect with</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -76,22 +100,34 @@
<layout class="QHBoxLayout" name="layout_apn"> <layout class="QHBoxLayout" name="layout_apn">
<item> <item>
<widget class="QLabel" name="label_apn"> <widget class="QLabel" name="label_apn">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Access point name</string> <string>Access point name</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_apn"> <widget class="QLineEdit" name="lineEdit_apn">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The access point (apn) to connect on</string> <string>The access point (apn) to connect on</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -100,19 +136,28 @@
<layout class="QHBoxLayout" name="layout_pin"> <layout class="QHBoxLayout" name="layout_pin">
<item> <item>
<widget class="QLabel" name="label_pin"> <widget class="QLabel" name="label_pin">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>PIN</string> <string>PIN</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_pin"> <widget class="QLineEdit" name="lineEdit_pin">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>If your modem requires a PIN to unlock, use this option</string> <string>If your modem requires a PIN to unlock, use this option</string>
</property> </property>
@ -124,19 +169,28 @@
<layout class="QHBoxLayout" name="layout_mode"> <layout class="QHBoxLayout" name="layout_mode">
<item> <item>
<widget class="QLabel" name="label_mode"> <widget class="QLabel" name="label_mode">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Mode</string> <string>Mode</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_mode"> <widget class="QComboBox" name="comboBox_mode">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>This option is used to specify the connection mode</string> <string>This option is used to specify the connection mode</string>
</property> </property>
@ -172,26 +226,23 @@
<item> <item>
<layout class="QHBoxLayout" name="layout_mobileAdvanced"> <layout class="QHBoxLayout" name="layout_mobileAdvanced">
<item> <item>
<spacer name="spacer_mobileAdvanced"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_mobileAdvanced"> <widget class="QToolButton" name="pushButton_mobileAdvanced">
<property name="text">
<string>Show advanced</string>
</property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -199,23 +250,101 @@
<item> <item>
<widget class="QWidget" name="widget_mobileAdvanced" native="true"> <widget class="QWidget" name="widget_mobileAdvanced" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="layout_route">
<item>
<widget class="QLabel" name="label_route">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_route">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Use the default route provided by the peer</string>
</property>
<property name="text">
<string>Default route</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_dns">
<item>
<widget class="QLabel" name="label_dns">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_dns">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Use the DNS provided by the peer</string>
</property>
<property name="text">
<string>Use peer DNS</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="layout_fail"> <layout class="QHBoxLayout" name="layout_fail">
<item> <item>
<widget class="QLabel" name="label_fail"> <widget class="QLabel" name="label_fail">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Max fail</string> <string>Max fail</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_fail"> <widget class="QSpinBox" name="spinBox_fail">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The number of consecutive failed connection attempts to tolerate</string> <string>The number of consecutive failed connection attempts to tolerate</string>
</property> </property>
@ -229,49 +358,32 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBox_route">
<property name="toolTip">
<string>Use the default route provided by the peer</string>
</property>
<property name="text">
<string>Default route</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_dns">
<property name="toolTip">
<string>Use the DNS provided by the peer</string>
</property>
<property name="text">
<string>Use peer DNS</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="layout_options"> <layout class="QHBoxLayout" name="layout_options">
<item> <item>
<widget class="QLabel" name="label_options"> <widget class="QLabel" name="label_options">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Options file</string> <string>Options file</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_options"> <widget class="QLineEdit" name="lineEdit_options">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>A file to read additional pppd options from</string> <string>A file to read additional pppd options from</string>
</property> </property>
@ -279,6 +391,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_options"> <widget class="QPushButton" name="pushButton_options">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Browse</string> <string>Browse</string>
</property> </property>
@ -301,10 +419,7 @@
<tabstop>lineEdit_apn</tabstop> <tabstop>lineEdit_apn</tabstop>
<tabstop>lineEdit_pin</tabstop> <tabstop>lineEdit_pin</tabstop>
<tabstop>comboBox_mode</tabstop> <tabstop>comboBox_mode</tabstop>
<tabstop>pushButton_mobileAdvanced</tabstop>
<tabstop>spinBox_fail</tabstop> <tabstop>spinBox_fail</tabstop>
<tabstop>checkBox_route</tabstop>
<tabstop>checkBox_dns</tabstop>
<tabstop>lineEdit_options</tabstop> <tabstop>lineEdit_options</tabstop>
<tabstop>pushButton_options</tabstop> <tabstop>pushButton_options</tabstop>
</tabstops> </tabstops>

View File

@ -20,26 +20,29 @@
#include <QDebug> #include <QDebug>
#include <netctlgui/netctlgui.h>
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include "calls.h"
#include "commonfunctions.h"
#include "dbusoperation.h" #include "dbusoperation.h"
#include "version.h" #include "errorwindow.h"
#include "mainwindow.h"
NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const QMap<QString, QString> settings) NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const QMap<QString, QString> settings, const bool debugCmd)
: QMainWindow(parent), : QMainWindow(parent),
ui(new Ui::NetctlAutoWindow), debug(debugCmd),
debug(debugCmd) configuration(settings)
{ {
if (settings[QString("USE_HELPER")] == QString("true")) mainWindow = dynamic_cast<MainWindow *>(parent);
useHelper = true; useHelper = (configuration[QString("USE_HELPER")] == QString("true"));
else
useHelper = false; // ui
ui = new Ui::NetctlAutoWindow;
ui->setupUi(this); ui->setupUi(this);
ui->tableWidget->setColumnHidden(2, true); ui->tableWidget->setColumnHidden(2, true);
ui->tableWidget->setColumnHidden(3, true); ui->tableWidget->setColumnHidden(3, true);
netctlCommand = new Netctl(debug, settings); updateToolBarState(static_cast<Qt::ToolBarArea>(settings[QString("NETCTLAUTO_TOOLBAR")].toInt()));
createActions(); createActions();
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Ready")); ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Ready"));
@ -51,22 +54,14 @@ NetctlAutoWindow::~NetctlAutoWindow()
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
delete ui; delete ui;
delete netctlCommand;
} }
QString NetctlAutoWindow::checkStatus(const bool statusBool, const bool nullFalse) Qt::ToolBarArea NetctlAutoWindow::getToolBarArea()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Status" << statusBool;
if (debug) qDebug() << PDEBUG << ":" << "Return null false" << nullFalse;
if (statusBool) return toolBarArea(ui->toolBar);
return QApplication::translate("NetctlAutoWindow", "yes");
if (nullFalse)
return QString("");
else
return QApplication::translate("NetctlAutoWindow", "no");
} }
@ -78,9 +73,9 @@ void NetctlAutoWindow::createActions()
connect(ui->actionClose, SIGNAL(triggered(bool)), this, SLOT(close())); connect(ui->actionClose, SIGNAL(triggered(bool)), this, SLOT(close()));
connect(ui->actionDisableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoDisableAllProfiles())); connect(ui->actionDisableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoDisableAllProfiles()));
connect(ui->actionEnable, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableProfile())); connect(ui->actionEnable, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableProfile()));
connect(ui->actionEnableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableAllProfiles()));\ connect(ui->actionEnableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableAllProfiles()));
connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(netctlAutoUpdateTable()));
connect(ui->actionSwitch, SIGNAL(triggered(bool)), this, SLOT(netctlAutoStartProfile())); connect(ui->actionSwitch, SIGNAL(triggered(bool)), this, SLOT(netctlAutoStartProfile()));
connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(netctlAutoUpdateTable()));
// service // service
connect(ui->actionEnableService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableService())); connect(ui->actionEnableService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableService()));
connect(ui->actionRestartService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoRestartService())); connect(ui->actionRestartService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoRestartService()));
@ -90,11 +85,17 @@ void NetctlAutoWindow::createActions()
connect(ui->tableWidget, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(netctlAutoStartProfile())); connect(ui->tableWidget, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(netctlAutoStartProfile()));
connect(ui->tableWidget, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(netctlAutoRefreshButtons(QTableWidgetItem *, QTableWidgetItem *))); connect(ui->tableWidget, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(netctlAutoRefreshButtons(QTableWidgetItem *, QTableWidgetItem *)));
connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(netctlAutoContextualMenu(QPoint))); connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(netctlAutoContextualMenu(QPoint)));
}
// buttons
connect(ui->pushButton_enable, SIGNAL(clicked(bool)), this, SLOT(netctlAutoEnableProfile())); void NetctlAutoWindow::showMessage(const bool status)
connect(ui->pushButton_refresh, SIGNAL(clicked(bool)), this, SLOT(netctlAutoUpdateTable())); {
connect(ui->pushButton_switch, SIGNAL(clicked(bool)), this, SLOT(netctlAutoStartProfile())); if (debug) qDebug() << PDEBUG;
if (status)
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
} }
@ -108,12 +109,24 @@ void NetctlAutoWindow::showWindow()
} }
void NetctlAutoWindow::updateToolBarState(const Qt::ToolBarArea area)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area;
removeToolBar(ui->toolBar);
if (area != Qt::NoToolBarArea) {
addToolBar(area, ui->toolBar);
ui->toolBar->show();
}
}
void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos) void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (ui->tableWidget->currentItem() == 0) if (ui->tableWidget->currentItem() == nullptr) return;
return;
// create menu // create menu
QMenu menu(this); QMenu menu(this);
QAction *startProfile = menu.addAction(QApplication::translate("NetctlAutoWindow", "Switch to profile")); QAction *startProfile = menu.addAction(QApplication::translate("NetctlAutoWindow", "Switch to profile"));
@ -121,24 +134,18 @@ void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos)
QAction *enableProfile = menu.addAction(QApplication::translate("NetctlAutoWindow", "Enable profile")); QAction *enableProfile = menu.addAction(QApplication::translate("NetctlAutoWindow", "Enable profile"));
menu.addSeparator(); menu.addSeparator();
QAction *enableAllProfiles = menu.addAction(QApplication::translate("NetctlAutoWindow", "Enable all profiles")); QAction *enableAllProfiles = menu.addAction(QApplication::translate("NetctlAutoWindow", "Enable all profiles"));
enableAllProfiles->setIcon(QIcon::fromTheme("edit-add")); enableAllProfiles->setIcon(QIcon::fromTheme("list-add"));
QAction *disableAllProfiles = menu.addAction(QApplication::translate("NetctlAutoWindow", "Disable all profiles")); QAction *disableAllProfiles = menu.addAction(QApplication::translate("NetctlAutoWindow", "Disable all profiles"));
disableAllProfiles->setIcon(QIcon::fromTheme("edit-delete")); disableAllProfiles->setIcon(QIcon::fromTheme("edit-delete"));
// set text // set text
if (!ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 2)->text().isEmpty()) { startProfile->setVisible(ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 2)->text().isEmpty());
enableProfile->setVisible(false); if (!ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 3)->text().isEmpty()) {
startProfile->setVisible(false); enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
enableProfile->setIcon(QIcon::fromTheme("list-add"));
} else { } else {
enableProfile->setVisible(true); enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Enable"));
startProfile->setVisible(true); enableProfile->setIcon(QIcon::fromTheme("edit-delete"));
if (!ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 3)->text().isEmpty()) {
enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Enable"));
enableProfile->setIcon(QIcon::fromTheme("edit-add"));
} else {
enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
enableProfile->setIcon(QIcon::fromTheme("edit-delete"));
}
} }
// actions // actions
@ -162,88 +169,74 @@ void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos)
void NetctlAutoWindow::netctlAutoUpdateTable() void NetctlAutoWindow::netctlAutoUpdateTable()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
ui->tableWidget->setDisabled(true); ui->tableWidget->setDisabled(true);
netctlInformation info = generalInformation(mainWindow->netctlInterface,
useHelper, debug);
// actions // actions
bool enabled = false; ui->actionDisableAll->setEnabled(info.netctlAuto);
bool running = false; ui->actionEnableAll->setEnabled(info.netctlAuto);
if (useHelper) { ui->actionRestartService->setEnabled(info.netctlAuto);
enabled = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, if (info.netctlAutoEnabled)
DBUS_HELPER_INTERFACE, QString("isNetctlAutoEnabled"),
QList<QVariant>(), true, debug)[0].toBool();
running = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"),
QList<QVariant>(), true, debug)[0].toBool();
} else {
enabled = netctlCommand->isNetctlAutoEnabled();
running = netctlCommand->isNetctlAutoRunning();
}
if (enabled)
ui->actionEnableService->setText(QApplication::translate("NetctlAutoWindow", "Disable service")); ui->actionEnableService->setText(QApplication::translate("NetctlAutoWindow", "Disable service"));
else else
ui->actionEnableService->setText(QApplication::translate("NetctlAutoWindow", "Enable service")); ui->actionEnableService->setText(QApplication::translate("NetctlAutoWindow", "Enable service"));
ui->actionEnableService->setVisible(true); if (info.netctlAuto) {
if (running) {
ui->label_info->setText(QApplication::translate("NetctlAutoWindow", "netctl-auto is running")); ui->label_info->setText(QApplication::translate("NetctlAutoWindow", "netctl-auto is running"));
ui->actionStartService->setText(QApplication::translate("NetctlAutoWindow", "Stop service")); ui->actionStartService->setText(QApplication::translate("NetctlAutoWindow", "Stop service"));
ui->actionDisableAll->setVisible(true);
ui->actionEnableAll->setVisible(true);
ui->actionRestartService->setVisible(true);
} else { } else {
ui->label_info->setText(QApplication::translate("NetctlAutoWindow", "netctl-auto is not running")); ui->label_info->setText(QApplication::translate("NetctlAutoWindow", "netctl-auto is not running"));
ui->actionStartService->setText(QApplication::translate("NetctlAutoWindow", "Start service")); ui->actionStartService->setText(QApplication::translate("NetctlAutoWindow", "Start service"));
ui->actionDisableAll->setVisible(false); netctlAutoRefreshButtons(nullptr, nullptr);
ui->actionEnableAll->setVisible(false);
ui->actionRestartService->setVisible(false);
netctlAutoRefreshButtons(0, 0);
return; return;
} }
QList<netctlProfileInfo> profiles;
if (useHelper)
profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("ProfileList"),
QList<QVariant>(), true, debug), debug);
else
profiles = netctlCommand->getProfileListFromNetctlAuto();
ui->tableWidget->setSortingEnabled(false); ui->tableWidget->setSortingEnabled(false);
ui->tableWidget->selectRow(-1); ui->tableWidget->selectRow(-1);
ui->tableWidget->sortByColumn(0, Qt::AscendingOrder); ui->tableWidget->sortByColumn(0, Qt::AscendingOrder);
ui->tableWidget->clear(); ui->tableWidget->clear();
ui->tableWidget->setRowCount(profiles.count()); ui->tableWidget->setRowCount(info.netctlAutoProfiles.count());
// create header // create header
QStringList headerList; QStringList headerList;
headerList.append(QApplication::translate("NetctlAutoWindow", "Name")); headerList.append(QApplication::translate("NetctlAutoWindow", "Name"));
headerList.append(QApplication::translate("NetctlAutoWindow", "Description")); headerList.append(QApplication::translate("NetctlAutoWindow", "Description"));
headerList.append(QApplication::translate("NetctlAutoWindow", "Active")); headerList.append(QApplication::translate("NetctlAutoWindow", "Active"));
headerList.append(QApplication::translate("NetctlAutoWindow", "Disabled")); headerList.append(QApplication::translate("NetctlAutoWindow", "Enabled"));
ui->tableWidget->setHorizontalHeaderLabels(headerList); ui->tableWidget->setHorizontalHeaderLabels(headerList);
// create items // create items
for (int i=0; i<profiles.count(); i++) { for (int i=0; i<info.netctlAutoProfiles.count(); i++) {
// font // font
QFont font; QFont font;
font.setBold(profiles[i].active); font.setBold(info.netctlAutoProfiles[i].active);
font.setItalic(profiles[i].enabled); font.setItalic(info.netctlAutoProfiles[i].enabled);
// tooltip // tooltip
QString toolTip = QString(""); QString toolTip = QString("");
toolTip += QString("%1: %2\n").arg(QApplication::translate("NetctlAutoWindow", "Profile")).arg(profiles[i].name); toolTip += QString("%1: %2\n").arg(QApplication::translate("NetctlAutoWindow", "Profile"))
toolTip += QString("%1: %2\n").arg(QApplication::translate("NetctlAutoWindow", "Active")).arg(checkStatus(profiles[i].active)); .arg(info.netctlAutoProfiles[i].name);
toolTip += QString("%1: %2").arg(QApplication::translate("NetctlAutoWindow", "Disabled")).arg(checkStatus(!profiles[i].enabled)); toolTip += QString("%1: %2\n").arg(QApplication::translate("NetctlAutoWindow", "Active"))
.arg(checkStatus(info.netctlAutoProfiles[i].active));
toolTip += QString("%1: %2").arg(QApplication::translate("NetctlAutoWindow", "Disabled"))
.arg(checkStatus(!info.netctlAutoProfiles[i].enabled));
// name // name
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(profiles[i].name)); ui->tableWidget->setItem(i, 0, new QTableWidgetItem(info.netctlAutoProfiles[i].name));
ui->tableWidget->item(i, 0)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); ui->tableWidget->item(i, 0)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
ui->tableWidget->item(i, 0)->setToolTip(toolTip); ui->tableWidget->item(i, 0)->setToolTip(toolTip);
ui->tableWidget->item(i, 0)->setFont(font); ui->tableWidget->item(i, 0)->setFont(font);
// description // description
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(profiles[i].description)); ui->tableWidget->setItem(i, 1, new QTableWidgetItem(info.netctlAutoProfiles[i].description));
ui->tableWidget->item(i, 1)->setTextAlignment(Qt::AlignJustify | Qt::AlignVCenter); ui->tableWidget->item(i, 1)->setTextAlignment(Qt::AlignJustify | Qt::AlignVCenter);
ui->tableWidget->item(i, 1)->setToolTip(toolTip); ui->tableWidget->item(i, 1)->setToolTip(toolTip);
// active // active
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(checkStatus(profiles[i].active, true))); ui->tableWidget->setItem(i, 2, new QTableWidgetItem(checkStatus(info.netctlAutoProfiles[i].active, true)));
ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); ui->tableWidget->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// enabled // enabled
ui->tableWidget->setItem(i, 3, new QTableWidgetItem(checkStatus(!profiles[i].enabled, true))); ui->tableWidget->setItem(i, 3, new QTableWidgetItem(checkStatus(info.netctlAutoProfiles[i].enabled, true)));
ui->tableWidget->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); ui->tableWidget->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
} }
@ -258,10 +251,11 @@ void NetctlAutoWindow::netctlAutoUpdateTable()
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
#endif #endif
ui->tableWidget->setEnabled(true); ui->tableWidget->setCurrentCell(-1, -1);
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Updated")); ui->tableWidget->setDisabled(false);
showMessage(true);
netctlAutoRefreshButtons(0, 0); netctlAutoRefreshButtons(nullptr, nullptr);
update(); update();
} }
@ -269,19 +263,21 @@ void NetctlAutoWindow::netctlAutoUpdateTable()
void NetctlAutoWindow::netctlAutoDisableAllProfiles() void NetctlAutoWindow::netctlAutoDisableAllProfiles()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
ui->tableWidget->setDisabled(true); ui->tableWidget->setDisabled(true);
bool status = false; bool responce = false;
if (useHelper) if (!useHelper)
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, responce = mainWindow->netctlCommand->autoDisableAllProfiles();
DBUS_HELPER_INTERFACE, QString("autoDisableAll"), else try {
QList<QVariant>(), true, debug)[0].toBool(); responce = sendRequestToCtrl(QString("autoDisableAll"), debug)[0].toBool();
else } catch (...) {
status = netctlCommand->autoDisableAllProfiles(); if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
if (status) }
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); showMessage(responce);
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoUpdateTable(); netctlAutoUpdateTable();
} }
@ -290,24 +286,25 @@ void NetctlAutoWindow::netctlAutoDisableAllProfiles()
void NetctlAutoWindow::netctlAutoEnableProfile() void NetctlAutoWindow::netctlAutoEnableProfile()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget->currentItem() == nullptr) return;
if (ui->tableWidget->currentItem() == 0)
return;
ui->tableWidget->setDisabled(true); ui->tableWidget->setDisabled(true);
QString profile = ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 0)->text(); QString profile = ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 0)->text();
bool status = false; bool responce = false;
if (useHelper) { if (!useHelper)
responce = mainWindow->netctlCommand->autoEnableProfile(profile);
else try {
QList<QVariant> args; QList<QVariant> args;
args.append(profile); args.append(profile);
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, responce = sendRequestToCtrlWithArgs(QString("autoEnable"), args, debug)[0].toBool();
DBUS_HELPER_INTERFACE, QString("autoEnable"), } catch (...) {
args, true, debug)[0].toBool(); if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
} else }
status = netctlCommand->autoEnableProfile(profile); showMessage(responce);
if (status)
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoUpdateTable(); netctlAutoUpdateTable();
} }
@ -316,19 +313,21 @@ void NetctlAutoWindow::netctlAutoEnableProfile()
void NetctlAutoWindow::netctlAutoEnableAllProfiles() void NetctlAutoWindow::netctlAutoEnableAllProfiles()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
ui->tableWidget->setDisabled(true); ui->tableWidget->setDisabled(true);
bool status = false; bool responce = false;
if (useHelper) if (!useHelper)
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, responce = mainWindow->netctlCommand->autoEnableAllProfiles();
DBUS_HELPER_INTERFACE, QString("autoEnableAll"), else try {
QList<QVariant>(), true, debug)[0].toBool(); responce = sendRequestToCtrl(QString("autoEnableAll"), debug)[0].toBool();
else } catch (...) {
status = netctlCommand->autoEnableAllProfiles(); if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
if (status) }
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); showMessage(responce);
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoUpdateTable(); netctlAutoUpdateTable();
} }
@ -337,24 +336,25 @@ void NetctlAutoWindow::netctlAutoEnableAllProfiles()
void NetctlAutoWindow::netctlAutoStartProfile() void NetctlAutoWindow::netctlAutoStartProfile()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget->currentItem() == nullptr) return;
if (ui->tableWidget->currentItem() == 0)
return;
ui->tableWidget->setDisabled(true); ui->tableWidget->setDisabled(true);
QString profile = ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 0)->text(); QString profile = ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 0)->text();
bool status = false; bool responce = false;
if (useHelper) { if (!useHelper)
responce = mainWindow->netctlCommand->autoStartProfile(profile);
else try {
QList<QVariant> args; QList<QVariant> args;
args.append(profile); args.append(profile);
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, responce = sendRequestToCtrlWithArgs(QString("autoStart"), args, debug)[0].toBool();
DBUS_HELPER_INTERFACE, QString("autoStart"), } catch (...) {
args, true, debug)[0].toBool(); if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
} else }
status = netctlCommand->autoStartProfile(profile); showMessage(responce);
if (status)
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoUpdateTable(); netctlAutoUpdateTable();
} }
@ -363,18 +363,20 @@ void NetctlAutoWindow::netctlAutoStartProfile()
void NetctlAutoWindow::netctlAutoEnableService() void NetctlAutoWindow::netctlAutoEnableService()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
bool status = false; bool responce = false;
if (useHelper) if (!useHelper)
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, responce = mainWindow->netctlCommand->autoEnableService();
DBUS_HELPER_INTERFACE, QString("autoServiceEnable"), else try {
QList<QVariant>(), true, debug)[0].toBool(); responce = sendRequestToCtrl(QString("autoServiceEnable"), debug)[0].toBool();
else } catch (...) {
status = netctlCommand->autoEnableService(); if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
if (status) }
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); showMessage(responce);
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoUpdateTable(); netctlAutoUpdateTable();
} }
@ -383,18 +385,20 @@ void NetctlAutoWindow::netctlAutoEnableService()
void NetctlAutoWindow::netctlAutoRestartService() void NetctlAutoWindow::netctlAutoRestartService()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("systemctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("systemctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
bool status = false; bool responce = false;
if (useHelper) if (!useHelper)
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, responce = mainWindow->netctlCommand->autoRestartService();
DBUS_HELPER_INTERFACE, QString("autoServiceRestart"), else try {
QList<QVariant>(), true, debug)[0].toBool(); responce = sendRequestToCtrl(QString("autoServiceRestart"), debug)[0].toBool();
else } catch (...) {
status = netctlCommand->autoRestartService(); if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
if (status) }
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); showMessage(responce);
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoUpdateTable(); netctlAutoUpdateTable();
} }
@ -403,18 +407,20 @@ void NetctlAutoWindow::netctlAutoRestartService()
void NetctlAutoWindow::netctlAutoStartService() void NetctlAutoWindow::netctlAutoStartService()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("systemctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("systemctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
bool status = false; bool responce = false;
if (useHelper) if (!useHelper)
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, responce = mainWindow->netctlCommand->autoStartService();
DBUS_HELPER_INTERFACE, QString("autoServiceStart"), else try {
QList<QVariant>(), true, debug)[0].toBool(); responce = sendRequestToCtrl(QString("autoServiceStart"), debug)[0].toBool();
else } catch (...) {
status = netctlCommand->autoStartService(); if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
if (status) }
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Done")); showMessage(responce);
else
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Error"));
netctlAutoUpdateTable(); netctlAutoUpdateTable();
} }
@ -425,43 +431,14 @@ void NetctlAutoWindow::netctlAutoRefreshButtons(QTableWidgetItem *current, QTabl
Q_UNUSED(previous); Q_UNUSED(previous);
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (current == 0) { bool selected = (current != nullptr);
// buttons ui->actionEnable->setEnabled(selected);
ui->pushButton_enable->setDisabled(true); ui->actionSwitch->setEnabled(selected && ui->tableWidget->item(current->row(), 2)->text().isEmpty());
ui->pushButton_switch->setDisabled(true); if (selected && !ui->tableWidget->item(current->row(), 3)->text().isEmpty()) {
// menu ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
ui->actionEnable->setVisible(false); ui->actionEnable->setIcon(QIcon::fromTheme("edit-delete"));
ui->actionSwitch->setVisible(false);
return;
}
if (!ui->tableWidget->item(current->row(), 2)->text().isEmpty()) {
// buttons
ui->pushButton_enable->setDisabled(true);
ui->pushButton_switch->setDisabled(true);
// menu
ui->actionEnable->setVisible(false);
ui->actionSwitch->setVisible(false);
} else { } else {
// buttons ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Enable"));
ui->pushButton_enable->setEnabled(true); ui->actionEnable->setIcon(QIcon::fromTheme("list-add"));
ui->pushButton_switch->setEnabled(true);
// menu
ui->actionEnable->setVisible(true);
ui->actionSwitch->setVisible(true);
if (!ui->tableWidget->item(current->row(), 3)->text().isEmpty()) {
// buttons
ui->pushButton_enable->setText(QApplication::translate("NetctlAutoWindow", "Enable"));
ui->pushButton_enable->setIcon(QIcon::fromTheme("edit-add"));
// menu
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Enable profile"));
ui->actionEnable->setIcon(QIcon::fromTheme("edit-add"));
} else {
// buttons
ui->pushButton_enable->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
ui->pushButton_enable->setIcon(QIcon::fromTheme("edit-delete"));
// menu
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Disable profile"));
ui->actionEnable->setIcon(QIcon::fromTheme("edit-delete"));
}
} }
} }

View File

@ -18,12 +18,11 @@
#ifndef NETCTLAUTOWINDOW_H #ifndef NETCTLAUTOWINDOW_H
#define NETCTLAUTOWINDOW_H #define NETCTLAUTOWINDOW_H
#include <QKeyEvent>
#include <QMainWindow> #include <QMainWindow>
#include <QTableWidgetItem> #include <QTableWidgetItem>
class Netctl; class MainWindow;
namespace Ui { namespace Ui {
class NetctlAutoWindow; class NetctlAutoWindow;
@ -35,12 +34,15 @@ class NetctlAutoWindow : public QMainWindow
public: public:
explicit NetctlAutoWindow(QWidget *parent = 0, explicit NetctlAutoWindow(QWidget *parent = 0,
const bool debugCmd = false, const QMap<QString, QString> settings = QMap<QString, QString>(),
const QMap<QString, QString> settings = QMap<QString, QString>()); const bool debugCmd = false);
~NetctlAutoWindow(); ~NetctlAutoWindow();
Qt::ToolBarArea getToolBarArea();
public slots: public slots:
void showMessage(const bool status);
void showWindow(); void showWindow();
void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea);
private slots: private slots:
// table // table
@ -58,12 +60,14 @@ private slots:
void netctlAutoStartService(); void netctlAutoStartService();
private: private:
Netctl *netctlCommand = nullptr; // ui
Ui::NetctlAutoWindow *ui = nullptr; Ui::NetctlAutoWindow *ui = nullptr;
MainWindow *mainWindow = nullptr;
// backend
void createActions();
bool debug = false; bool debug = false;
bool useHelper = true; bool useHelper = true;
QString checkStatus(const bool statusBool, const bool nullFalse = false); QMap<QString, QString> configuration;
void createActions();
}; };

View File

@ -14,12 +14,9 @@
<string>netctl-auto</string> <string>netctl-auto</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="centralLayout">
<item> <item>
<widget class="QLabel" name="label_info"> <widget class="QLabel" name="label_info">
<property name="text">
<string/>
</property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
@ -65,65 +62,27 @@
<column/> <column/>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="layout_buttons">
<item>
<widget class="QPushButton" name="pushButton_refresh">
<property name="text">
<string>Refresh</string>
</property>
<property name="icon">
<iconset theme="stock-refresh">
<normaloff/>
</iconset>
</property>
</widget>
</item>
<item>
<spacer name="spacer_buttons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_enable">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Enable</string>
</property>
<property name="icon">
<iconset theme="edit-add"/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_switch">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Switch</string>
</property>
<property name="icon">
<iconset theme="system-run">
<normaloff/>
</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>Toolbar</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonFollowStyle</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionRefresh"/>
<addaction name="separator"/>
<addaction name="actionSwitch"/>
<addaction name="actionEnable"/>
</widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">
<property name="geometry"> <property name="geometry">
<rect> <rect>
@ -137,11 +96,6 @@
<property name="title"> <property name="title">
<string>Menu</string> <string>Menu</string>
</property> </property>
<addaction name="actionRefresh"/>
<addaction name="separator"/>
<addaction name="actionSwitch"/>
<addaction name="actionEnable"/>
<addaction name="separator"/>
<addaction name="actionEnableAll"/> <addaction name="actionEnableAll"/>
<addaction name="actionDisableAll"/> <addaction name="actionDisableAll"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -153,27 +107,6 @@
</widget> </widget>
<addaction name="menuMenu"/> <addaction name="menuMenu"/>
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionEnable">
<property name="icon">
<iconset theme="edit-add">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Enable profile</string>
</property>
</action>
<action name="actionSwitch">
<property name="icon">
<iconset theme="system-run">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Switch to profile</string>
</property>
</action>
<action name="actionClose"> <action name="actionClose">
<property name="icon"> <property name="icon">
<iconset theme="exit"> <iconset theme="exit">
@ -189,7 +122,7 @@
</action> </action>
<action name="actionEnableAll"> <action name="actionEnableAll">
<property name="icon"> <property name="icon">
<iconset theme="edit-add"> <iconset theme="list-add">
<normaloff/> <normaloff/>
</iconset> </iconset>
</property> </property>
@ -211,6 +144,9 @@
<property name="text"> <property name="text">
<string>Start service</string> <string>Start service</string>
</property> </property>
<property name="toolTip">
<string>Start or stop service</string>
</property>
</action> </action>
<action name="actionRestartService"> <action name="actionRestartService">
<property name="text"> <property name="text">
@ -221,16 +157,51 @@
<property name="text"> <property name="text">
<string>Enable service</string> <string>Enable service</string>
</property> </property>
<property name="toolTip">
<string>Enable or disable service</string>
</property>
</action> </action>
<action name="actionRefresh"> <action name="actionRefresh">
<property name="icon"> <property name="icon">
<iconset theme="stock-refresh"> <iconset theme="view-refresh">
<normaloff/> <normaloff/>
</iconset> </iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Refresh</string> <string>Refresh</string>
</property> </property>
<property name="toolTip">
<string>Refresh table</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="actionEnable">
<property name="icon">
<iconset theme="list-add">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Enable</string>
</property>
<property name="toolTip">
<string>Enable or disable profile</string>
</property>
</action>
<action name="actionSwitch">
<property name="icon">
<iconset theme="system-run">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Switch</string>
</property>
<property name="toolTip">
<string>Switch to profile</string>
</property>
</action> </action>
</widget> </widget>
<resources/> <resources/>

View File

@ -54,12 +54,6 @@ bool NetctlGuiAdaptor::Close()
} }
QStringList NetctlGuiAdaptor::Information()
{
return mainWindow->printInformation();
}
void NetctlGuiAdaptor::LibraryDocs() void NetctlGuiAdaptor::LibraryDocs()
{ {
return mainWindow->showLibrary(); return mainWindow->showLibrary();
@ -70,8 +64,7 @@ QString NetctlGuiAdaptor::Pony()
{ {
QString pony; QString pony;
QFile ponyFile(QString(":pinkiepie")); QFile ponyFile(QString(":pinkiepie"));
if (!ponyFile.open(QIODevice::ReadOnly)) if (!ponyFile.open(QIODevice::ReadOnly)) return pony;
return pony;
pony = QTextCodec::codecForMib(106)->toUnicode(ponyFile.readAll()); pony = QTextCodec::codecForMib(106)->toUnicode(ponyFile.readAll());
ponyFile.close(); ponyFile.close();
@ -134,9 +127,3 @@ QStringList NetctlGuiAdaptor::UIDs()
return uids; return uids;
} }
QStringList NetctlGuiAdaptor::VerboseInformation()
{
return mainWindow->printTrayInformation();
}

View File

@ -37,7 +37,6 @@ public slots:
bool Active(); bool Active();
void ApiDocs(); void ApiDocs();
bool Close(); bool Close();
QStringList Information();
void LibraryDocs(); void LibraryDocs();
QString Pony(); QString Pony();
bool Restore(); bool Restore();
@ -48,7 +47,6 @@ public slots:
bool ShowNetctlAuto(); bool ShowNetctlAuto();
bool ShowSettings(); bool ShowSettings();
QStringList UIDs(); QStringList UIDs();
QStringList VerboseInformation();
private: private:
MainWindow *mainWindow; MainWindow *mainWindow;

View File

@ -0,0 +1,475 @@
/***************************************************************************
* 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 "newprofilewidget.h"
#include "ui_newprofilewidget.h"
#include <QDebug>
#include <QLineEdit>
#include <QMenu>
#include <pdebug/pdebug.h>
#include <task/taskadds.h>
#include "calls.h"
#include "bridgewidget.h"
#include "commonfunctions.h"
#include "dbusoperation.h"
#include "errorwindow.h"
#include "ethernetwidget.h"
#include "generalwidget.h"
#include "ipwidget.h"
#include "mainwindow.h"
#include "macvlanwidget.h"
#include "mobilewidget.h"
#include "pppoewidget.h"
#include "tunnelwidget.h"
#include "tuntapwidget.h"
#include "vlanwidget.h"
#include "wirelesswidget.h"
NewProfileWidget::NewProfileWidget(QWidget *parent, const QMap<QString, QString> settings, const bool debugCmd)
: QMainWindow(parent),
debug(debugCmd),
configuration(settings)
{
mainWindow = dynamic_cast<MainWindow *>(parent);
useHelper = (configuration[QString("USE_HELPER")] == QString("true"));
// windows
ui = new Ui::NewProfileWidget;
ui->setupUi(this);
updateToolBarState(static_cast<Qt::ToolBarArea>(configuration[QString("PROFILE_TOOLBAR")].toInt()));
// profile widgets
generalWid = new GeneralWidget(this, configuration);
ui->scrollAreaWidgetContents->layout()->addWidget(generalWid);
ipWid = new IpWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(ipWid);
bridgeWid = new BridgeWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(bridgeWid);
ethernetWid = new EthernetWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(ethernetWid);
macvlanWid = new MacvlanWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(macvlanWid);
mobileWid = new MobileWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(mobileWid);
pppoeWid = new PppoeWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(pppoeWid);
tunnelWid = new TunnelWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(tunnelWid);
tuntapWid = new TuntapWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(tuntapWid);
vlanWid = new VlanWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(vlanWid);
wirelessWid = new WirelessWidget(this, configuration);
ui->scrollAreaWidgetContents->layout()->addWidget(wirelessWid);
createActions();
}
NewProfileWidget::~NewProfileWidget()
{
if (debug) qDebug() << PDEBUG;
if (bridgeWid != nullptr) delete bridgeWid;
if (ethernetWid != nullptr) delete ethernetWid;
if (generalWid != nullptr) delete generalWid;
if (ipWid != nullptr) delete ipWid;
if (macvlanWid != nullptr) delete macvlanWid;
if (mobileWid != nullptr) delete mobileWid;
if (pppoeWid != nullptr) delete pppoeWid;
if (tunnelWid != nullptr) delete tunnelWid;
if (tuntapWid != nullptr) delete tuntapWid;
if (vlanWid != nullptr) delete vlanWid;
if (wirelessWid != nullptr) delete wirelessWid;
if (ui != nullptr) delete ui;
}
Qt::ToolBarArea NewProfileWidget::getToolBarArea()
{
if (debug) qDebug() << PDEBUG;
return toolBarArea(ui->toolBar);
}
void NewProfileWidget::profileTabOpenProfileSlot(const QString profile)
{
if (debug) qDebug() << PDEBUG;
ui->comboBox_profile->addItem(profile);
ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count() - 1);
}
void NewProfileWidget::update()
{
if (debug) qDebug() << PDEBUG;
updateProfileTab();
updateMenuProfile();
}
void NewProfileWidget::updateToolBarState(const Qt::ToolBarArea area)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area;
removeToolBar(ui->toolBar);
if (area != Qt::NoToolBarArea) {
addToolBar(area, ui->toolBar);
ui->toolBar->show();
}
}
void NewProfileWidget::updateMenuProfile()
{
if (debug) qDebug() << PDEBUG;
bool selected = !ui->comboBox_profile->currentText().isEmpty();
ui->actionLoad->setEnabled(selected);
ui->actionRemove->setEnabled(selected);
ui->actionSave->setEnabled(selected);
ui->actionEditor->setEnabled(selected);
}
void NewProfileWidget::updateProfileTab()
{
if (debug) qDebug() << PDEBUG;
mainWindow->setDisabled(true);
ui->comboBox_profile->clear();
QList<netctlProfileInfo> profiles = generalInformation(mainWindow->netctlInterface,
useHelper, debug).netctlProfiles;
for (int i=0; i<profiles.count(); i++)
ui->comboBox_profile->addItem(profiles[i].name);
ui->comboBox_profile->setCurrentIndex(-1);
generalWid->clear();
ipWid->clear();
bridgeWid->clear();
ethernetWid->clear();
macvlanWid->clear();
mobileWid->clear();
pppoeWid->clear();
tunnelWid->clear();
tuntapWid->clear();
vlanWid->clear();
wirelessWid->clear();
profileTabChangeState(generalWid->connectionType->currentText());
mainWindow->setDisabled(false);
mainWindow->showMessage(true);
}
void NewProfileWidget::profileTabChangeState(const QString current)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Current type" << current;
generalWid->setVisible(true);
ipWid->setVisible((current != QString("pppoe")) && (current != QString("mobile_ppp")));
bridgeWid->setVisible(current == QString("bridge"));
ethernetWid->setVisible((current == QString("ethernet")) ||
(current == QString("vlan")) ||
(current == QString("macvlan")));
macvlanWid->setVisible(current == QString("macvlan"));
mobileWid->setVisible(current == QString("mobile_ppp"));
pppoeWid->setVisible(current == QString("pppoe"));
tunnelWid->setVisible(current == QString("tunnel"));
tuntapWid->setVisible(current == QString("tuntap"));
vlanWid->setVisible(current == QString("vlan"));
wirelessWid->setVisible(current == QString("wireless"));
}
void NewProfileWidget::profileTabCreateProfile()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("sudo"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("sudo"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
// error checking
if (ui->comboBox_profile->currentText().isEmpty())
return ErrorWindow::showWindow(3, QString(PDEBUG), debug);
if (generalWid->isOk() == 1)
return ErrorWindow::showWindow(4, QString(PDEBUG), debug);
else if (generalWid->isOk() == 2)
return ErrorWindow::showWindow(5, QString(PDEBUG), debug);
if ((generalWid->connectionType->currentText() == QString("ethernet")) ||
(generalWid->connectionType->currentText() == QString("wireless")) ||
(generalWid->connectionType->currentText() == QString("bond")) ||
(generalWid->connectionType->currentText() == QString("dummy")) ||
(generalWid->connectionType->currentText() == QString("bridge")) ||
(generalWid->connectionType->currentText() == QString("tunnel")) ||
(generalWid->connectionType->currentText() == QString("tuntap")) ||
(generalWid->connectionType->currentText() == QString("vlan")) ||
(generalWid->connectionType->currentText() == QString("macvlan")) ||
(generalWid->connectionType->currentText() == QString("openvswitch"))) {
if (ipWid->isOk() == 1)
return ErrorWindow::showWindow(6, QString(PDEBUG), debug);
else if (ipWid->isOk() == 2)
return ErrorWindow::showWindow(6, QString(PDEBUG), debug);
}
if (generalWid->connectionType->currentText() == QString("ethernet")) {
if (ethernetWid->isOk() == 1)
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
} else if (generalWid->connectionType->currentText() == QString("wireless")) {
if (wirelessWid->isOk() == 1)
return ErrorWindow::showWindow(8, QString(PDEBUG), debug);
else if (wirelessWid->isOk() == 2)
return ErrorWindow::showWindow(9, QString(PDEBUG), debug);
else if (wirelessWid->isOk() == 3)
return ErrorWindow::showWindow(10, QString(PDEBUG), debug);
else if (wirelessWid->isOk() == 4)
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
else if (wirelessWid->isOk() == 5)
return ErrorWindow::showWindow(11, QString(PDEBUG), debug);
} else if (generalWid->connectionType->currentText() == QString("bridge")) {
} else if (generalWid->connectionType->currentText() == QString("pppoe")) {
if (pppoeWid->isOk() == 1)
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
else if (pppoeWid->isOk() == 2)
return ErrorWindow::showWindow(12, QString(PDEBUG), debug);
else if (pppoeWid->isOk() == 3)
return ErrorWindow::showWindow(13, QString(PDEBUG), debug);
else if (pppoeWid->isOk() == 4)
return ErrorWindow::showWindow(12, QString(PDEBUG), debug);
} else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) {
if (mobileWid->isOk() == 1)
return ErrorWindow::showWindow(15, QString(PDEBUG), debug);
if (mobileWid->isOk() == 2)
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
}
else if (generalWid->connectionType->currentText() == QString("tunnel")) {
if (tunnelWid->isOk() == 1)
return ErrorWindow::showWindow(20, QString(PDEBUG), debug);
}
else if (generalWid->connectionType->currentText() == QString("tuntap")) {
if (tuntapWid->isOk() == 1)
return ErrorWindow::showWindow(15, QString(PDEBUG), debug);
if (tuntapWid->isOk() == 2)
return ErrorWindow::showWindow(15, QString(PDEBUG), debug);
}
else if (generalWid->connectionType->currentText() == QString("vlan")) {
if (ethernetWid->isOk() == 1)
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
}
else if (generalWid->connectionType->currentText() == QString("macvlan")) {
if (ethernetWid->isOk() == 1)
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
}
mainWindow->setDisabled(true);
// read settings
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
QMap<QString, QString> settings;
settings = generalWid->getSettings();
if (generalWid->connectionType->currentText() == QString("ethernet")) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = ethernetWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if (generalWid->connectionType->currentText() == QString("wireless")) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = wirelessWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if ((generalWid->connectionType->currentText() == QString("bond")) ||
(generalWid->connectionType->currentText() == QString("dummy")) ||
(generalWid->connectionType->currentText() == QString("openvswitch"))) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if (generalWid->connectionType->currentText() == QString("bridge")) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = bridgeWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if (generalWid->connectionType->currentText() == QString("pppoe")) {
QMap<QString, QString> addSettings = pppoeWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) {
QMap<QString, QString> addSettings = mobileWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if (generalWid->connectionType->currentText() == QString("tunnel")) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = tunnelWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if (generalWid->connectionType->currentText() == QString("tuntap")) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = tuntapWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if (generalWid->connectionType->currentText() == QString("vlan")) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = ethernetWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = vlanWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
} else if (generalWid->connectionType->currentText() == QString("macvlan")) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = ethernetWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = macvlanWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
}
// call netctlprofile
InterfaceAnswer answer = createProfileSlot(profile, settings, mainWindow->netctlInterface,
useHelper, debug);
mainWindow->showMessage(answer == InterfaceAnswer::True);
updateProfileTab();
}
void NewProfileWidget::profileTabLoadProfile()
{
if (debug) qDebug() << PDEBUG;
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
if (profile.isEmpty()) return;
QMap<QString, QString> settings = profileInformation(profile, mainWindow->netctlInterface,
useHelper, debug);
if (settings.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug);
generalWid->setSettings(settings);
if (generalWid->connectionType->currentText() == QString("ethernet")) {
ipWid->setSettings(settings);
ethernetWid->setSettings(settings);
} else if (generalWid->connectionType->currentText() == QString("wireless")) {
ipWid->setSettings(settings);
wirelessWid->setSettings(settings);
} else if ((generalWid->connectionType->currentText() == QString("bond")) ||
(generalWid->connectionType->currentText() == QString("dummy")) ||
(generalWid->connectionType->currentText() == QString("openvswitch"))) {
ipWid->setSettings(settings);
} else if (generalWid->connectionType->currentText() == QString("bridge")) {
ipWid->setSettings(settings);
bridgeWid->setSettings(settings);
} else if (generalWid->connectionType->currentText() == QString("pppoe")) {
pppoeWid->setSettings(settings);
} else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) {
mobileWid->setSettings(settings);
} else if (generalWid->connectionType->currentText() == QString("tunnel")) {
ipWid->setSettings(settings);
tunnelWid->setSettings(settings);
} else if (generalWid->connectionType->currentText() == QString("tuntap")) {
ipWid->setSettings(settings);
tuntapWid->setSettings(settings);
} else if (generalWid->connectionType->currentText() == QString("vlan")) {
ipWid->setSettings(settings);
ethernetWid->setSettings(settings);
vlanWid->setSettings(settings);
} else if (generalWid->connectionType->currentText() == QString("macvlan")) {
ipWid->setSettings(settings);
ethernetWid->setSettings(settings);
macvlanWid->setSettings(settings);
}
}
void NewProfileWidget::profileTabOpenInEditor()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("editor"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("editor"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
QString cmd = QString("%1 %2 %3").arg(configuration[QString("SUDO_PATH")])
.arg(configuration[QString("EDITOR_PATH")])
.arg(profile);
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, false);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
mainWindow->showMessage(process.exitCode == 0);
}
void NewProfileWidget::profileTabRemoveProfile()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("sudo"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("sudo"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
mainWindow->setDisabled(true);
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
InterfaceAnswer answer = removeProfileSlot(profile, mainWindow->netctlInterface,
useHelper, debug);
mainWindow->showMessage(answer == InterfaceAnswer::True);
updateProfileTab();
}
void NewProfileWidget::createActions()
{
if (debug) qDebug() << PDEBUG;
// menu actions
connect(ui->actionClear, SIGNAL(triggered(bool)), this, SLOT(updateProfileTab()));
connect(ui->actionEditor, SIGNAL(triggered(bool)), this, SLOT(profileTabOpenInEditor()));
connect(ui->actionLoad, SIGNAL(triggered(bool)), this, SLOT(profileTabLoadProfile()));
connect(ui->actionRemove, SIGNAL(triggered(bool)), this, SLOT(profileTabRemoveProfile()));
connect(ui->actionSave, SIGNAL(triggered(bool)), this, SLOT(profileTabCreateProfile()));
// main tab events
connect(ui->comboBox_profile, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabLoadProfile()));
connect(ui->comboBox_profile, SIGNAL(editTextChanged(QString)), this, SLOT(updateMenuProfile()));
connect(ui->comboBox_profile->lineEdit(), SIGNAL(returnPressed()), this, SLOT(profileTabLoadProfile()));
connect(generalWid->connectionType, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabChangeState(QString)));
}

View File

@ -0,0 +1,94 @@
/***************************************************************************
* 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 NEWPROFILEWIDGET_H
#define NEWPROFILEWIDGET_H
#include <QMainWindow>
#include <netctlgui/netctlgui.h>
class BridgeWidget;
class EthernetWidget;
class GeneralWidget;
class IpWidget;
class MainWindow;
class MacvlanWidget;
class MobileWidget;
class PppoeWidget;
class TunnelWidget;
class TuntapWidget;
class VlanWidget;
class WirelessWidget;
namespace Ui {
class NewProfileWidget;
}
class NewProfileWidget : public QMainWindow
{
Q_OBJECT
public:
explicit NewProfileWidget(QWidget *parent = 0,
const QMap<QString,QString> settings = QMap<QString,QString>(),
const bool debugCmd = false);
~NewProfileWidget();
Qt::ToolBarArea getToolBarArea();
public slots:
void profileTabOpenProfileSlot(const QString profile);
void update();
void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea);
private slots:
// update slots
void updateMenuProfile();
void updateProfileTab();
// profile tab slots
void profileTabChangeState(const QString current);
void profileTabCreateProfile();
void profileTabLoadProfile();
void profileTabOpenInEditor();
void profileTabRemoveProfile();
private:
// ui
MainWindow *mainWindow;
Ui::NewProfileWidget *ui = nullptr;
BridgeWidget *bridgeWid = nullptr;
EthernetWidget *ethernetWid = nullptr;
GeneralWidget *generalWid = nullptr;
IpWidget *ipWid = nullptr;
MacvlanWidget *macvlanWid = nullptr;
MobileWidget *mobileWid = nullptr;
PppoeWidget *pppoeWid = nullptr;
TunnelWidget *tunnelWid = nullptr;
TuntapWidget *tuntapWid = nullptr;
VlanWidget *vlanWid = nullptr;
WirelessWidget *wirelessWid = nullptr;
// backend
void createActions();
bool debug = false;
bool useHelper = true;
// configuration
QMap<QString, QString> configuration;
};
#endif /* NEWPROFILEWIDGET_H */

View File

@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewProfileWidget</class>
<widget class="QMainWindow" name="NewProfileWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<height>409</height>
</rect>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="layout_profile">
<item>
<widget class="QLabel" name="label_profile">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Profile</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_profile">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>459</width>
<height>342</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="scrollArea_layout">
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>New profile toolbar</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonFollowStyle</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionClear"/>
<addaction name="separator"/>
<addaction name="actionLoad"/>
<addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionRemove"/>
<addaction name="actionEditor"/>
</widget>
<action name="actionClear">
<property name="icon">
<iconset theme="edit-clear">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Clear</string>
</property>
<property name="toolTip">
<string>Clear data</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="actionLoad">
<property name="icon">
<iconset theme="document-open">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Load</string>
</property>
<property name="toolTip">
<string>Load selected profile</string>
</property>
</action>
<action name="actionSave">
<property name="icon">
<iconset theme="document-save">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="toolTip">
<string>Save selected profile</string>
</property>
</action>
<action name="actionRemove">
<property name="icon">
<iconset theme="edit-delete">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="toolTip">
<string>Remove selected profile</string>
</property>
</action>
<action name="actionEditor">
<property name="icon">
<iconset theme="document-open">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Open in editor</string>
</property>
<property name="toolTip">
<string>Open in an external editor</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -20,10 +20,10 @@
#include <QLineEdit> #include <QLineEdit>
#include "mainwindow.h" #include "wifimenuwidget.h"
PasswdWidget::PasswdWidget(MainWindow *wid) PasswdWidget::PasswdWidget(WiFiMenuWidget *wid)
: QWidget(wid), : QWidget(wid),
parent(wid), parent(wid),
ui(new Ui::PasswdWidget) ui(new Ui::PasswdWidget)
@ -49,6 +49,7 @@ void PasswdWidget::keyPressEvent(QKeyEvent *pressedKey)
void PasswdWidget::createActions() void PasswdWidget::createActions()
{ {
connect(ui->checkBox_showSymbols, SIGNAL(stateChanged(int)), this, SLOT(setEchoMode(int)));
connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(passwdApply())); connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(passwdApply()));
connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked(bool)), this, SLOT(cancel())); connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked(bool)), this, SLOT(cancel()));
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(passwdApply())); connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(passwdApply()));
@ -64,19 +65,21 @@ void PasswdWidget::setFocusToLineEdit()
void PasswdWidget::setPassword(const bool mode) void PasswdWidget::setPassword(const bool mode)
{ {
if (mode) { if (mode) {
ui->lineEdit->setEchoMode(QLineEdit::Password); ui->checkBox_showSymbols->setCheckState(Qt::Checked);
setEchoMode(ui->checkBox_showSymbols->checkState());
ui->label->setText(QApplication::translate("PasswdWidget", "Password")); ui->label->setText(QApplication::translate("PasswdWidget", "Password"));
} else { } else {
ui->lineEdit->setEchoMode(QLineEdit::Normal); ui->lineEdit->setEchoMode(QLineEdit::Normal);
ui->label->setText(QApplication::translate("PasswdWidget", "ESSID")); ui->label->setText(QApplication::translate("PasswdWidget", "ESSID"));
} }
passwdMode = mode;
} }
void PasswdWidget::cancel() void PasswdWidget::cancel()
{ {
hide(); hide();
parent->updateTabs(2); parent->update();
this->~PasswdWidget(); this->~PasswdWidget();
} }
@ -84,8 +87,17 @@ void PasswdWidget::cancel()
void PasswdWidget::passwdApply() void PasswdWidget::passwdApply()
{ {
hide(); hide();
if (ui->lineEdit->echoMode() == QLineEdit::Normal) if (passwdMode)
return parent->setHiddenName(ui->lineEdit->text());
else
return parent->connectToUnknownEssid(ui->lineEdit->text()); return parent->connectToUnknownEssid(ui->lineEdit->text());
else
return parent->setHiddenName(ui->lineEdit->text());
}
void PasswdWidget::setEchoMode(const int mode)
{
if (mode == 0)
ui->lineEdit->setEchoMode(QLineEdit::Password);
else
ui->lineEdit->setEchoMode(QLineEdit::Normal);
} }

View File

@ -23,7 +23,7 @@
#include <QWidget> #include <QWidget>
class MainWindow; class WiFiMenuWidget;
namespace Ui { namespace Ui {
class PasswdWidget; class PasswdWidget;
@ -34,7 +34,7 @@ class PasswdWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit PasswdWidget(MainWindow *wid = 0); explicit PasswdWidget(WiFiMenuWidget *wid = 0);
~PasswdWidget(); ~PasswdWidget();
public slots: public slots:
@ -44,13 +44,15 @@ public slots:
private slots: private slots:
void cancel(); void cancel();
void passwdApply(); void passwdApply();
void setEchoMode(const int mode);
private: private:
MainWindow *parent; WiFiMenuWidget *parent;
Ui::PasswdWidget *ui; Ui::PasswdWidget *ui;
// ESC pressed event // ESC pressed event
void keyPressEvent(QKeyEvent *pressedKey); void keyPressEvent(QKeyEvent *pressedKey);
void createActions(); void createActions();
bool passwdMode = true;
}; };

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>264</width> <width>264</width>
<height>86</height> <height>109</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -16,9 +16,6 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<spacer name="spacer2"> <spacer name="spacer2">
@ -37,13 +34,28 @@
<layout class="QHBoxLayout" name="layout_passwd"> <layout class="QHBoxLayout" name="layout_passwd">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Password</string> <string>Password</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit"> <widget class="QLineEdit" name="lineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="echoMode"> <property name="echoMode">
<enum>QLineEdit::Password</enum> <enum>QLineEdit::Password</enum>
</property> </property>
@ -51,6 +63,36 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="layout_showSymbols">
<item>
<widget class="QLabel" name="label_showSymbols">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_showSymbols">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show symbols</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<spacer name="spacer1"> <spacer name="spacer1">
<property name="orientation"> <property name="orientation">
@ -65,41 +107,11 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="layout_button"> <widget class="QDialogButtonBox" name="buttonBox">
<item> <property name="standardButtons">
<spacer name="spacer_button1"> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="orientation"> </property>
<enum>Qt::Horizontal</enum> </widget>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item>
<spacer name="spacer_button2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -65,21 +65,12 @@ void PppoeWidget::clear()
} }
void PppoeWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void PppoeWidget::createFilter() void PppoeWidget::createFilter()
{ {
// session mac // session mac
ui->lineEdit_session->setInputMask(QString(">99999:HH:HH:HH:HH:HH:HH")); ui->lineEdit_session->setInputMask(QString(">00000:hh:hh:hh:hh:hh:hh"));
// mac // mac
ui->lineEdit_mac->setInputMask(QString(">HH:HH:HH:HH:HH:HH")); ui->lineEdit_mac->setInputMask(QString(">hh:hh:hh:hh:hh:hh"));
} }
@ -93,17 +84,13 @@ void PppoeWidget::createActions()
void PppoeWidget::changeMode(const QString currentText) void PppoeWidget::changeMode(const QString currentText)
{ {
if (currentText == QString("persist")) ui->widget_timeout->setHidden(currentText == QString("persist"));
ui->widget_timeout->setHidden(true);
else if (currentText == QString("demand"))
ui->widget_timeout->setHidden(false);
} }
void PppoeWidget::selectOptionsFile() void PppoeWidget::selectOptionsFile()
{ {
QString filename = QFileDialog::getOpenFileName( QString filename = QFileDialog::getOpenFileName(this,
this,
QApplication::translate("PppoeWidget", "Select options file"), QApplication::translate("PppoeWidget", "Select options file"),
QDir::currentPath(), QDir::currentPath(),
QApplication::translate("PppoeWidget", "Configuration files (*.conf)")); QApplication::translate("PppoeWidget", "Configuration files (*.conf)"));
@ -116,55 +103,53 @@ void PppoeWidget::showAdvanced()
{ {
if (ui->pushButton_pppoeAdvanced->isChecked()) { if (ui->pushButton_pppoeAdvanced->isChecked()) {
ui->widget_pppoeAdvanced->setHidden(false); ui->widget_pppoeAdvanced->setHidden(false);
ui->pushButton_pppoeAdvanced->setText(QApplication::translate("PppoeWidget", "Hide advanced")); ui->pushButton_pppoeAdvanced->setArrowType(Qt::UpArrow);
} else { } else {
ui->widget_pppoeAdvanced->setHidden(true); ui->widget_pppoeAdvanced->setHidden(true);
ui->pushButton_pppoeAdvanced->setText(QApplication::translate("PppoeWidget", "Show advanced")); ui->pushButton_pppoeAdvanced->setArrowType(Qt::DownArrow);
} }
} }
QMap<QString, QString> PppoeWidget::getSettings() QMap<QString, QString> PppoeWidget::getSettings()
{ {
QMap<QString, QString> pppoeSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return pppoeSettings;
if (!ui->lineEdit_username->text().isEmpty()) if (!ui->lineEdit_username->text().isEmpty())
pppoeSettings[QString("User")] = QString("'") + ui->lineEdit_username->text() + QString("'"); settings[QString("User")] = QString("'%1'").arg(ui->lineEdit_username->text());
if (!ui->lineEdit_password->text().isEmpty()) if (!ui->lineEdit_password->text().isEmpty())
pppoeSettings[QString("Password")] = QString("'") + ui->lineEdit_password->text() + QString("'"); settings[QString("Password")] = QString("'%1'").arg(ui->lineEdit_password->text());
pppoeSettings[QString("ConnectionMode")] = QString("'") + ui->comboBox_connection->currentText() + QString("'"); settings[QString("ConnectionMode")] = QString("'%1'").arg(ui->comboBox_connection->currentText());
if (ui->comboBox_connection->currentText() == QString("demand")) if (ui->comboBox_connection->currentText() == QString("demand"))
pppoeSettings[QString("IdleTimeout")] = QString::number(ui->spinBox_timeout->value()); settings[QString("IdleTimeout")] = QString::number(ui->spinBox_timeout->value());
if (ui->spinBox_fail->value() != 5) if (ui->spinBox_fail->value() != 5)
pppoeSettings[QString("MaxFail")] = QString::number(ui->spinBox_fail->value()); settings[QString("MaxFail")] = QString::number(ui->spinBox_fail->value());
if (ui->checkBox_route->checkState() == Qt::Unchecked) if (ui->checkBox_route->checkState() == Qt::Unchecked)
pppoeSettings[QString("DefaultRoute")] = QString("false"); settings[QString("DefaultRoute")] = QString("false");
if (ui->checkBox_dns->checkState() == Qt::Unchecked) if (ui->checkBox_dns->checkState() == Qt::Unchecked)
pppoeSettings[QString("UsePeerDNS")] = QString("false"); settings[QString("UsePeerDNS")] = QString("false");
if (!ui->lineEdit_unit->text().isEmpty()) if (!ui->lineEdit_unit->text().isEmpty())
pppoeSettings[QString("PPPUnit")] = ui->lineEdit_unit->text(); settings[QString("PPPUnit")] = ui->lineEdit_unit->text();
if (ui->spinBox_lcpInterval->value() != 30) if (ui->spinBox_lcpInterval->value() != 30)
pppoeSettings[QString("LCPEchoInterval")] = QString::number(ui->spinBox_lcpInterval->value()); settings[QString("LCPEchoInterval")] = QString::number(ui->spinBox_lcpInterval->value());
if (ui->spinBox_lcpFailure->value() != 4) if (ui->spinBox_lcpFailure->value() != 4)
pppoeSettings[QString("LCPEchoFailure")] = QString::number(ui->spinBox_lcpFailure->value()); settings[QString("LCPEchoFailure")] = QString::number(ui->spinBox_lcpFailure->value());
if (!ui->lineEdit_options->text().isEmpty()) if (!ui->lineEdit_options->text().isEmpty())
pppoeSettings[QString("OptionsFile")] = QString("'") + ui->lineEdit_options->text() + QString("'"); settings[QString("OptionsFile")] = QString("'%1'").arg(ui->lineEdit_options->text());
if (!ui->lineEdit_service->text().isEmpty()) if (!ui->lineEdit_service->text().isEmpty())
pppoeSettings[QString("PPPoEService")] = QString("'") + ui->lineEdit_service->text() + QString("'"); settings[QString("PPPoEService")] = QString("'%1'").arg(ui->lineEdit_service->text());
if (!ui->lineEdit_ac->text().isEmpty()) if (!ui->lineEdit_ac->text().isEmpty())
pppoeSettings[QString("PPPoEAC")] = QString("'") + ui->lineEdit_ac->text() + QString("'"); settings[QString("PPPoEAC")] = QString("'%1'").arg(ui->lineEdit_ac->text());
if (!ui->lineEdit_session->text().remove(QChar(':')).remove(QChar(' ')).isEmpty()) if (!ui->lineEdit_session->text().remove(QChar(':')).isEmpty())
pppoeSettings[QString("PPPoESession")] = QString("'") + ui->lineEdit_session->text() settings[QString("PPPoESession")] = QString("'%1'").arg(ui->lineEdit_session->text());
.remove(QChar('\'')).remove(QChar('"')) + QString("'"); if (!ui->lineEdit_mac->text().remove(QChar(':')).isEmpty())
if (!ui->lineEdit_mac->text().remove(QChar(':')).remove(QChar(' ')).isEmpty()) settings[QString("PPPoEMAC")] = QString("'%1'").arg(ui->lineEdit_mac->text());
pppoeSettings[QString("PPPoEMAC")] = QString("'") + ui->lineEdit_mac->text() + QString("'");
if (ui->checkBox_ipv6->checkState() == Qt::Checked) if (ui->checkBox_ipv6->checkState() == Qt::Checked)
pppoeSettings[QString("PPPoEIP6")] = QString("yes"); settings[QString("PPPoEIP6")] = QString("yes");
return pppoeSettings; return settings;
} }
@ -172,22 +157,18 @@ int PppoeWidget::isOk()
{ {
// config file doesn't exist // config file doesn't exist
if (!ui->lineEdit_options->text().isEmpty()) if (!ui->lineEdit_options->text().isEmpty())
if (!QFile(ui->lineEdit_options->text()).exists()) if (!QFile(ui->lineEdit_options->text()).exists()) return 1;
return 1;
// mac address // mac address
if (!ui->lineEdit_mac->text().remove(QChar(':')).remove(QChar(' ')).isEmpty()) if (!ui->lineEdit_mac->text().remove(QChar(':')).isEmpty())
if (ui->lineEdit_mac->text().contains(QChar(' '))) if (ui->lineEdit_mac->text().length() != (6 * 2 + 5)) return 2;
return 2;
// session id is not set // session id is not set
if (!ui->lineEdit_session->text().remove(QChar(':')).remove(QChar(' ')).isEmpty()) if (!ui->lineEdit_session->text().remove(QChar(':')).isEmpty())
if (ui->lineEdit_session->text().split(QChar(':'))[0].remove(QChar(' ')).isEmpty()) if (ui->lineEdit_session->text().split(QChar(':'))[0].isEmpty()) return 3;
return 3;
// session mac address // session mac address
if (!ui->lineEdit_session->text().remove(QChar(':')).remove(QChar(' ')).isEmpty()) { if (!ui->lineEdit_session->text().remove(QChar(':')).isEmpty()) {
QStringList item = ui->lineEdit_session->text().split(QChar(':')); QStringList item = ui->lineEdit_session->text().split(QChar(':'));
for (int i=1; i<7; i++) item.removeFirst();
if (item[i].contains(QChar(' '))) if (item.join(QChar(':')).length() != (6 * 2 + 5)) return 4;
return 4;
} }
// all fine // all fine
return 0; return 0;
@ -197,44 +178,43 @@ int PppoeWidget::isOk()
void PppoeWidget::setSettings(const QMap<QString, QString> settings) void PppoeWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> pppoeSettings = settings;
if (pppoeSettings.contains(QString("User"))) if (settings.contains(QString("User")))
ui->lineEdit_username->setText(pppoeSettings[QString("User")]); ui->lineEdit_username->setText(settings[QString("User")]);
if (pppoeSettings.contains(QString("Password"))) if (settings.contains(QString("Password")))
ui->lineEdit_password->setText(pppoeSettings[QString("Password")]); ui->lineEdit_password->setText(settings[QString("Password")]);
if (pppoeSettings.contains(QString("ConnectionMode"))) if (settings.contains(QString("ConnectionMode"))) {
for (int i=0; i<ui->comboBox_connection->count(); i++) int index = ui->comboBox_connection->findText(settings[QString("ConnectionMode")]);
if (pppoeSettings[QString("ConnectionMode")] == ui->comboBox_connection->itemText(i)) ui->comboBox_connection->setCurrentIndex(index);
ui->comboBox_connection->setCurrentIndex(i); }
if (pppoeSettings.contains(QString("IdleTimeout"))) if (settings.contains(QString("IdleTimeout")))
ui->spinBox_timeout->setValue(pppoeSettings[QString("IdleTimeout")].toInt()); ui->spinBox_timeout->setValue(settings[QString("IdleTimeout")].toInt());
if (pppoeSettings.contains(QString("MaxFail"))) if (settings.contains(QString("MaxFail")))
ui->spinBox_fail->setValue(pppoeSettings[QString("MaxFail")].toInt()); ui->spinBox_fail->setValue(settings[QString("MaxFail")].toInt());
if (pppoeSettings.contains(QString("DefaultRoute"))) if (settings.contains(QString("DefaultRoute")))
if (pppoeSettings[QString("DefaultRoute")] == QString("false")) if (settings[QString("DefaultRoute")] == QString("false"))
ui->checkBox_route->setCheckState(Qt::Unchecked); ui->checkBox_route->setCheckState(Qt::Unchecked);
if (pppoeSettings.contains(QString("UsePeerDNS"))) if (settings.contains(QString("UsePeerDNS")))
if (pppoeSettings[QString("UsePeerDNS")] == QString("false")) if (settings[QString("UsePeerDNS")] == QString("false"))
ui->checkBox_dns->setCheckState(Qt::Unchecked); ui->checkBox_dns->setCheckState(Qt::Unchecked);
if (pppoeSettings.contains(QString("PPPUnit"))) if (settings.contains(QString("PPPUnit")))
ui->lineEdit_unit->setText(pppoeSettings[QString("PPPUnit")]); ui->lineEdit_unit->setText(settings[QString("PPPUnit")]);
if (pppoeSettings.contains(QString("LCPEchoInterval"))) if (settings.contains(QString("LCPEchoInterval")))
ui->spinBox_lcpInterval->setValue(pppoeSettings[QString("LCPEchoInterval")].toInt()); ui->spinBox_lcpInterval->setValue(settings[QString("LCPEchoInterval")].toInt());
if (pppoeSettings.contains(QString("LCPEchoFailure"))) if (settings.contains(QString("LCPEchoFailure")))
ui->spinBox_lcpFailure->setValue(pppoeSettings[QString("LCPEchoFailure")].toInt()); ui->spinBox_lcpFailure->setValue(settings[QString("LCPEchoFailure")].toInt());
if (pppoeSettings.contains(QString("OptionsFile"))) if (settings.contains(QString("OptionsFile")))
ui->lineEdit_options->setText(pppoeSettings[QString("OptionsFile")]); ui->lineEdit_options->setText(settings[QString("OptionsFile")]);
if (pppoeSettings.contains(QString("PPPoEService"))) if (settings.contains(QString("PPPoEService")))
ui->lineEdit_service->setText(pppoeSettings[QString("PPPoEService")]); ui->lineEdit_service->setText(settings[QString("PPPoEService")]);
if (pppoeSettings.contains(QString("PPPoEAC"))) if (settings.contains(QString("PPPoEAC")))
ui->lineEdit_ac->setText(pppoeSettings[QString("PPPoEAC")]); ui->lineEdit_ac->setText(settings[QString("PPPoEAC")]);
if (pppoeSettings.contains(QString("PPPoESession"))) if (settings.contains(QString("PPPoESession")))
ui->lineEdit_session->setText(pppoeSettings[QString("PPPoESession")]); ui->lineEdit_session->setText(settings[QString("PPPoESession")]);
if (pppoeSettings.contains(QString("PPPoEMAC"))) if (settings.contains(QString("PPPoEMAC")))
ui->lineEdit_mac->setText(pppoeSettings[QString("PPPoEMAC")]); ui->lineEdit_mac->setText(settings[QString("PPPoEMAC")]);
if (pppoeSettings.contains(QString("PPPoEIP6"))) if (settings.contains(QString("PPPoEIP6")))
if (pppoeSettings[QString("PPPoEIP6")] == QString("yes")) if (settings[QString("PPPoEIP6")] == QString("yes"))
ui->checkBox_dns->setCheckState(Qt::Checked); ui->checkBox_dns->setCheckState(Qt::Checked);
changeMode(ui->comboBox_connection->currentText()); changeMode(ui->comboBox_connection->currentText());

View File

@ -38,7 +38,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private slots: private slots:
void changeMode(const QString currentText); void changeMode(const QString currentText);

View File

@ -6,13 +6,10 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>431</width> <width>484</width>
<height>602</height> <height>561</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QDockWidget" name="dockWidget_pppoe"> <widget class="QDockWidget" name="dockWidget_pppoe">
@ -28,19 +25,28 @@
<layout class="QHBoxLayout" name="layout_username"> <layout class="QHBoxLayout" name="layout_username">
<item> <item>
<widget class="QLabel" name="label_username"> <widget class="QLabel" name="label_username">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Username</string> <string>Username</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_username"> <widget class="QLineEdit" name="lineEdit_username">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The username and password to connect with</string> <string>The username and password to connect with</string>
</property> </property>
@ -52,19 +58,28 @@
<layout class="QHBoxLayout" name="layout_password"> <layout class="QHBoxLayout" name="layout_password">
<item> <item>
<widget class="QLabel" name="label_password"> <widget class="QLabel" name="label_password">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Password</string> <string>Password</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_password"> <widget class="QLineEdit" name="lineEdit_password">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The username and password to connect with</string> <string>The username and password to connect with</string>
</property> </property>
@ -76,19 +91,28 @@
<layout class="QHBoxLayout" name="layout_connection"> <layout class="QHBoxLayout" name="layout_connection">
<item> <item>
<widget class="QLabel" name="label_connection"> <widget class="QLabel" name="label_connection">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Connection mode</string> <string>Connection mode</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_connection"> <widget class="QComboBox" name="comboBox_connection">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>This option specifies how a connection should be established</string> <string>This option specifies how a connection should be established</string>
</property> </property>
@ -111,19 +135,28 @@
<layout class="QHBoxLayout" name="layout_timeout"> <layout class="QHBoxLayout" name="layout_timeout">
<item> <item>
<widget class="QLabel" name="label_timeout"> <widget class="QLabel" name="label_timeout">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Idle timeout</string> <string>Idle timeout</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_timeout"> <widget class="QSpinBox" name="spinBox_timeout">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>This option specifies the idle time (in seconds) after which pppd should disconnect</string> <string>This option specifies the idle time (in seconds) after which pppd should disconnect</string>
</property> </property>
@ -157,13 +190,16 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_pppoeAdvanced"> <widget class="QToolButton" name="pushButton_pppoeAdvanced">
<property name="text">
<string>Show advanced</string>
</property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -171,23 +207,174 @@
<item> <item>
<widget class="QWidget" name="widget_pppoeAdvanced" native="true"> <widget class="QWidget" name="widget_pppoeAdvanced" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="layout_route">
<item>
<widget class="QLabel" name="label_route">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_route">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Use the default route provided by the peer</string>
</property>
<property name="text">
<string>Default route</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_dns">
<item>
<widget class="QLabel" name="label_dns">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_dns">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Use the DNS provided by the peer</string>
</property>
<property name="text">
<string>Use peer DNS</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_ipv6">
<item>
<widget class="QLabel" name="label_ipv6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_ipv6">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Enable IPv6 support</string>
</property>
<property name="text">
<string>PPPoE IPv6</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_options">
<item>
<widget class="QLabel" name="label_options">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>7</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Options file</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_options">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>A file to read additional pppd options from</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_options">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="layout_fail"> <layout class="QHBoxLayout" name="layout_fail">
<item> <item>
<widget class="QLabel" name="label_fail"> <widget class="QLabel" name="label_fail">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Max fail</string> <string>Max fail</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_fail"> <widget class="QSpinBox" name="spinBox_fail">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The number of consecutive failed connection attempts to tolerate</string> <string>The number of consecutive failed connection attempts to tolerate</string>
</property> </property>
@ -201,49 +388,32 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBox_route">
<property name="toolTip">
<string>Use the default route provided by the peer</string>
</property>
<property name="text">
<string>Default route</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_dns">
<property name="toolTip">
<string>Use the DNS provided by the peer</string>
</property>
<property name="text">
<string>Use peer DNS</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="layout_unit"> <layout class="QHBoxLayout" name="layout_unit">
<item> <item>
<widget class="QLabel" name="label_unit"> <widget class="QLabel" name="label_unit">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>PPP unit</string> <string>PPP unit</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_unit"> <widget class="QLineEdit" name="lineEdit_unit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Set the ppp unit number in the interface name (ppp0, ppp1, etc.)</string> <string>Set the ppp unit number in the interface name (ppp0, ppp1, etc.)</string>
</property> </property>
@ -255,19 +425,28 @@
<layout class="QHBoxLayout" name="layout_lcpInterval"> <layout class="QHBoxLayout" name="layout_lcpInterval">
<item> <item>
<widget class="QLabel" name="label_lcpInterval"> <widget class="QLabel" name="label_lcpInterval">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>LCP echo interval</string> <string>LCP echo interval</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_lcpInterval"> <widget class="QSpinBox" name="spinBox_lcpInterval">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>These options override default LCP parameters from /etc/ppp/options</string> <string>These options override default LCP parameters from /etc/ppp/options</string>
</property> </property>
@ -288,19 +467,28 @@
<layout class="QHBoxLayout" name="layout_lcpFailure"> <layout class="QHBoxLayout" name="layout_lcpFailure">
<item> <item>
<widget class="QLabel" name="label_lcpFailure"> <widget class="QLabel" name="label_lcpFailure">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>LCP echo failure</string> <string>LCP echo failure</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_lcpFailure"> <widget class="QSpinBox" name="spinBox_lcpFailure">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>These options override default LCP parameters from /etc/ppp/options</string> <string>These options override default LCP parameters from /etc/ppp/options</string>
</property> </property>
@ -314,54 +502,32 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="layout_options">
<item>
<widget class="QLabel" name="label_options">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Options file</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_options">
<property name="toolTip">
<string>A file to read additional pppd options from</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_options">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="layout_service"> <layout class="QHBoxLayout" name="layout_service">
<item> <item>
<widget class="QLabel" name="label_service"> <widget class="QLabel" name="label_service">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>PPPoE service</string> <string>PPPoE service</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_service"> <widget class="QLineEdit" name="lineEdit_service">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>This option specifies the PPPoE service name</string> <string>This option specifies the PPPoE service name</string>
</property> </property>
@ -373,19 +539,28 @@
<layout class="QHBoxLayout" name="layout_ac"> <layout class="QHBoxLayout" name="layout_ac">
<item> <item>
<widget class="QLabel" name="label_ac"> <widget class="QLabel" name="label_ac">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>PPPoE AC</string> <string>PPPoE AC</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_ac"> <widget class="QLineEdit" name="lineEdit_ac">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>This option specifies the PPPoE access concentrator name</string> <string>This option specifies the PPPoE access concentrator name</string>
</property> </property>
@ -397,19 +572,28 @@
<layout class="QHBoxLayout" name="layout_session"> <layout class="QHBoxLayout" name="layout_session">
<item> <item>
<widget class="QLabel" name="label_session"> <widget class="QLabel" name="label_session">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>PPPoE session</string> <string>PPPoE session</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_session"> <widget class="QLineEdit" name="lineEdit_session">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>This option specifies an existing session to attach to, MAC address</string> <string>This option specifies an existing session to attach to, MAC address</string>
</property> </property>
@ -421,19 +605,28 @@
<layout class="QHBoxLayout" name="layout_mac"> <layout class="QHBoxLayout" name="layout_mac">
<item> <item>
<widget class="QLabel" name="label_mac"> <widget class="QLabel" name="label_mac">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>PPPoE MAC</string> <string>PPPoE MAC</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_mac"> <widget class="QLineEdit" name="lineEdit_mac">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Only connect to specified MAC address</string> <string>Only connect to specified MAC address</string>
</property> </property>
@ -441,16 +634,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBox_ipv6">
<property name="toolTip">
<string>Enable IPv6 support</string>
</property>
<property name="text">
<string>PPPoE IPv6</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -22,11 +22,15 @@
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QTextStream> #include <QTextStream>
#include <QSettings>
#include <grp.h>
#include <language/language.h> #include <language/language.h>
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include <task/taskadds.h>
#include "mainwindow.h" #include "mainwindow.h"
#include "version.h"
SettingsWindow::SettingsWindow(QWidget *parent, const bool debugCmd, const QString configFile) SettingsWindow::SettingsWindow(QWidget *parent, const bool debugCmd, const QString configFile)
@ -37,6 +41,7 @@ SettingsWindow::SettingsWindow(QWidget *parent, const bool debugCmd, const QStri
{ {
ui->setupUi(this); ui->setupUi(this);
addLanguages(); addLanguages();
addGroups();
createActions(); createActions();
} }
@ -57,10 +62,12 @@ void SettingsWindow::createActions()
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(closeWindow())); connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(closeWindow()));
connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked(bool)), this, SLOT(restoreSettings())); connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked(bool)), this, SLOT(restoreSettings()));
connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked(bool)), this, SLOT(setDefault())); connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked(bool)), this, SLOT(setDefault()));
connect(ui->buttonBox_applyGroup->button(QDialogButtonBox::Apply), SIGNAL(clicked(bool)), this, SLOT(applyHelperGroup()));
connect(ui->checkBox_enableTray, SIGNAL(stateChanged(int)), this, SLOT(setTray())); connect(ui->checkBox_enableTray, SIGNAL(stateChanged(int)), this, SLOT(setTray()));
connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
this, SLOT(changePage(QTreeWidgetItem *, QTreeWidgetItem *))); this, SLOT(changePage(QTreeWidgetItem *, QTreeWidgetItem *)));
// buttons // buttons
connect(ui->pushButton_editorPath, SIGNAL(clicked(bool)), this, SLOT(selectAbstractSomething()));
connect(ui->pushButton_helperPath, SIGNAL(clicked(bool)), this, SLOT(selectAbstractSomething())); connect(ui->pushButton_helperPath, SIGNAL(clicked(bool)), this, SLOT(selectAbstractSomething()));
connect(ui->pushButton_interfacesDir, SIGNAL(clicked(bool)), this, SLOT(selectAbstractSomething())); connect(ui->pushButton_interfacesDir, SIGNAL(clicked(bool)), this, SLOT(selectAbstractSomething()));
connect(ui->pushButton_netctlPath, SIGNAL(clicked(bool)), this, SLOT(selectAbstractSomething())); connect(ui->pushButton_netctlPath, SIGNAL(clicked(bool)), this, SLOT(selectAbstractSomething()));
@ -75,6 +82,48 @@ void SettingsWindow::createActions()
} }
int SettingsWindow::indexByToolBarPosition(const Qt::ToolBarArea area)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Area" << area;
switch (area) {
case Qt::LeftToolBarArea:
return 0;
case Qt::RightToolBarArea:
return 1;
case Qt::TopToolBarArea:
return 2;
case Qt::BottomToolBarArea:
return 3;
case Qt::NoToolBarArea:
default:
return 4;
}
}
Qt::ToolBarArea SettingsWindow::indexToToolBarPosition(const int index)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Index" << index;
switch (index) {
case 0:
return Qt::LeftToolBarArea;
case 1:
return Qt::RightToolBarArea;
case 2:
return Qt::TopToolBarArea;
case 3:
return Qt::BottomToolBarArea;
case 4:
default:
return Qt::NoToolBarArea;
}
}
// ESC press event // ESC press event
void SettingsWindow::keyPressEvent(QKeyEvent *pressedKey) void SettingsWindow::keyPressEvent(QKeyEvent *pressedKey)
{ {
@ -94,9 +143,81 @@ void SettingsWindow::addLanguages()
} }
void SettingsWindow::applyHelperGroup()
{
if (debug) qDebug() << PDEBUG;
QString group = ui->comboBox_group->currentText();
if (debug) qDebug() << PDEBUG << ":" << "Group" << group;
if (group.isEmpty()) return;
// create
QFile policyFile(QString("%1/org.netctlgui.helper.conf").arg(QDir::tempPath()));
if (debug) qDebug() << PDEBUG << ":" << "Save to" << policyFile.fileName();
if (!policyFile.open(QIODevice::WriteOnly | QIODevice::Text)) return;
// write
QTextStream out(&policyFile);
// header
out << "<!DOCTYPE busconfig PUBLIC" << endl;
out << " \"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN\"" << endl;
out << " \"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd\">" << endl;
out << "<busconfig>" << endl;
// group body
out << " <policy group=\"" << group << "\">" << endl;
out << " <allow own=\"org.netctlgui.helper\"/>" << endl;
out << " <allow send_destination=\"org.netctlgui.helper\"/>" << endl;
out << " <allow receive_sender=\"org.netctlgui.helper\"/>" << endl;
out << " </policy>" << endl;
// root body
out << " <policy user=\"root\">" << endl;
out << " <allow own=\"org.netctlgui.helper\"/>" << endl;
out << " <allow send_destination=\"org.netctlgui.helper\"/>" << endl;
out << " <allow receive_sender=\"org.netctlgui.helper\"/>" << endl;
out << " </policy>" << endl;
// footer
out << "</busconfig>" << endl;
policyFile.close();
// copy
QString newPath = QString("%1/org.netctlgui.helper.conf").arg(PROJECT_DBUS_SYSTEMCONF_PATH);
QString cmd = QString("%1 /usr/bin/mv \"%2\" \"%3\"").arg(ui->lineEdit_sudo->text())
.arg(policyFile.fileName())
.arg(newPath);
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, false);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
// update
setHelperGroup();
}
void SettingsWindow::addGroups()
{
if (debug) qDebug() << PDEBUG;
ui->comboBox_group->clear();
QFile groupFile(QString("/etc/group"));
if (!groupFile.open(QIODevice::ReadOnly)) return;
while (true) {
QString fileStr = QString(groupFile.readLine()).trimmed();
if ((fileStr.isEmpty()) && (!groupFile.atEnd())) continue;
if ((fileStr[0] == QChar('#')) && (!groupFile.atEnd())) continue;
if ((fileStr[0] == QChar(';')) && (!groupFile.atEnd())) continue;
if (fileStr.contains(QChar(':'))) ui->comboBox_group->addItem(fileStr.split(QChar(':'))[0]);
if (groupFile.atEnd()) break;
}
groupFile.close();
}
void SettingsWindow::changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous) void SettingsWindow::changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{ {
Q_UNUSED(previous) Q_UNUSED(previous);
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
for (int i=0; i<ui->treeWidget->topLevelItemCount(); i++) for (int i=0; i<ui->treeWidget->topLevelItemCount(); i++)
@ -113,7 +234,7 @@ void SettingsWindow::closeWindow()
saveSettings(); saveSettings();
close(); close();
((MainWindow *)parent())->updateConfiguration(); dynamic_cast<MainWindow *>(parent())->updateConfiguration();
} }
@ -121,14 +242,94 @@ void SettingsWindow::saveSettings()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QMap<QString, QString> settings = readSettings(); QMap<QString, QString> config = readSettings();
QFile configFile(file); QSettings settings(file, QSettings::IniFormat);
if (!configFile.open(QIODevice::WriteOnly | QIODevice::Text))
return; settings.beginGroup(QString("Common"));
QTextStream out(&configFile); settings.setValue(QString("LANGUAGE"), config[QString("LANGUAGE")]);
for (int i=0; i<settings.keys().count(); i++) settings.setValue(QString("SYSTRAY"), config[QString("SYSTRAY")]);
out << settings.keys()[i] << QString("=") << settings[settings.keys()[i]] << endl; settings.setValue(QString("CLOSETOTRAY"), config[QString("CLOSETOTRAY")]);
configFile.close(); settings.setValue(QString("STARTTOTRAY"), config[QString("STARTTOTRAY")]);
settings.setValue(QString("SKIPCOMPONENTS"), config[QString("SKIPCOMPONENTS")]);
settings.endGroup();
settings.beginGroup(QString("Helper"));
settings.setValue(QString("USE_HELPER"), config[QString("USE_HELPER")]);
settings.setValue(QString("FORCE_SUDO"), config[QString("FORCE_SUDO")]);
settings.setValue(QString("CLOSE_HELPER"), config[QString("CLOSE_HELPER")]);
settings.setValue(QString("HELPER_PATH"), config[QString("HELPER_PATH")]);
settings.setValue(QString("HELPER_SERVICE"), config[QString("HELPER_SERVICE")]);
settings.endGroup();
settings.beginGroup(QString("netctl"));
settings.setValue(QString("SYSTEMCTL_PATH"), config[QString("SYSTEMCTL_PATH")]);
settings.setValue(QString("NETCTL_PATH"), config[QString("NETCTL_PATH")]);
settings.setValue(QString("NETCTLAUTO_PATH"), config[QString("NETCTLAUTO_PATH")]);
settings.setValue(QString("NETCTLAUTO_PATH"), config[QString("NETCTLAUTO_PATH")]);
settings.setValue(QString("PROFILE_DIR"), config[QString("PROFILE_DIR")]);
settings.endGroup();
settings.beginGroup(QString("sudo"));
settings.setValue(QString("SUDO_PATH"), config[QString("SUDO_PATH")]);
settings.endGroup();
settings.beginGroup(QString("wpa_supplicant"));
settings.setValue(QString("WPASUP_PATH"), config[QString("WPASUP_PATH")]);
settings.setValue(QString("WPACLI_PATH"), config[QString("WPACLI_PATH")]);
settings.setValue(QString("PID_FILE"), config[QString("PID_FILE")]);
settings.setValue(QString("WPA_DRIVERS"), config[QString("WPA_DRIVERS")]);
settings.setValue(QString("CTRL_DIR"), config[QString("CTRL_DIR")]);
settings.setValue(QString("CTRL_GROUP"), config[QString("CTRL_GROUP")]);
settings.endGroup();
settings.beginGroup(QString("Other"));
settings.setValue(QString("EDITOR_PATH"), config[QString("EDITOR_PATH")]);
settings.setValue(QString("IFACE_DIR"), config[QString("IFACE_DIR")]);
settings.setValue(QString("RFKILL_DIR"), config[QString("RFKILL_DIR")]);
settings.setValue(QString("PREFERED_IFACE"), config[QString("PREFERED_IFACE")]);
settings.endGroup();
settings.beginGroup(QString("Toolbars"));
settings.setValue(QString("MAIN_TOOLBAR"), config[QString("MAIN_TOOLBAR")]);
settings.setValue(QString("NETCTL_TOOLBAR"), config[QString("NETCTL_TOOLBAR")]);
settings.setValue(QString("NETCTLAUTO_TOOLBAR"), config[QString("NETCTLAUTO_TOOLBAR")]);
settings.setValue(QString("PROFILE_TOOLBAR"), config[QString("PROFILE_TOOLBAR")]);
settings.setValue(QString("WIFI_TOOLBAR"), config[QString("WIFI_TOOLBAR")]);
settings.endGroup();
settings.sync();
}
void SettingsWindow::setHelperGroup()
{
if (debug) qDebug() << PDEBUG;
QString group;
QFile policyFile(QString("%1/org.netctlgui.helper.conf").arg(QString(PROJECT_DBUS_SYSTEMCONF_PATH)));
if (!policyFile.open(QIODevice::ReadOnly)) return;
while (true) {
QString fileStr = QString(policyFile.readLine()).trimmed();
if ((fileStr.isEmpty()) && (!policyFile.atEnd())) continue;
if ((fileStr[0] == QChar('#')) && (!policyFile.atEnd())) continue;
if ((fileStr[0] == QChar(';')) && (!policyFile.atEnd())) continue;
if (fileStr.contains(QString("policy group"))) try {
// line is ' <policy group="network">'
QStringList fields = fileStr.split(QChar(' '), QString::SkipEmptyParts);
group = fields[1].split(QChar('='))[1];
group.remove(QChar('<')).remove(QChar('>')).remove(QChar('\'')).remove(QChar('"'));
if (debug) qDebug() << PDEBUG << ":" << "Group detected" << group;
} catch (...) {
if (debug) qDebug() << PDEBUG << ":" << "An exception recevied";
return;
}
if (policyFile.atEnd()) break;
}
policyFile.close();
if (group.isEmpty()) return;
int index = ui->comboBox_group->findText(group);
ui->comboBox_group->setCurrentIndex(index);
} }
@ -136,13 +337,8 @@ void SettingsWindow::setTray()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (ui->checkBox_enableTray->checkState() == 0) { ui->checkBox_closeToTray->setDisabled(ui->checkBox_enableTray->checkState() == 0);
ui->checkBox_closeToTray->setDisabled(true); ui->checkBox_startToTray->setDisabled(ui->checkBox_enableTray->checkState() == 0);
ui->checkBox_startToTray->setDisabled(true);
} else if (ui->checkBox_enableTray->checkState() == 2) {
ui->checkBox_closeToTray->setEnabled(true);
ui->checkBox_startToTray->setEnabled(true);
}
} }
@ -171,8 +367,11 @@ void SettingsWindow::selectAbstractSomething()
bool isDir = false; bool isDir = false;
QString path = QString("/usr/bin"); QString path = QString("/usr/bin");
QString text = QApplication::translate("SettingsWindow", "Select helper command"); QString text = QApplication::translate("SettingsWindow", "Select helper command");
QLineEdit *lineEdit = ui->lineEdit_helperPath; QLineEdit *lineEdit = ui->lineEdit_editorPath;
if (sender() == ui->pushButton_helperPath) { if (sender() == ui->pushButton_editorPath) {
text = QApplication::translate("SettingsWindow", "Select editor command");
lineEdit = ui->lineEdit_editorPath;
} else if (sender() == ui->pushButton_helperPath) {
text = QApplication::translate("SettingsWindow", "Select helper command"); text = QApplication::translate("SettingsWindow", "Select helper command");
lineEdit = ui->lineEdit_helperPath; lineEdit = ui->lineEdit_helperPath;
} else if (sender() == ui->pushButton_interfacesDir) { } else if (sender() == ui->pushButton_interfacesDir) {
@ -225,6 +424,7 @@ void SettingsWindow::showWindow()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
setHelperGroup();
setSettings(getSettings()); setSettings(getSettings());
setTray(); setTray();
updateHelper(); updateHelper();
@ -237,115 +437,133 @@ QMap<QString, QString> SettingsWindow::readSettings()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QMap<QString, QString> settings; QMap<QString, QString> config;
if (ui->checkBox_helperClose->checkState() == 2)
settings[QString("CLOSE_HELPER")] = QString("true");
else
settings[QString("CLOSE_HELPER")] = QString("false");
if (ui->checkBox_closeToTray->checkState() == 2)
settings[QString("CLOSETOTRAY")] = QString("true");
else
settings[QString("CLOSETOTRAY")] = QString("false");
settings[QString("CTRL_DIR")] = ui->lineEdit_wpaDir->text();
settings[QString("CTRL_GROUP")] = ui->lineEdit_wpaGroup->text();
if (ui->checkBox_forceSudo->checkState() == 2)
settings[QString("FORCE_SUDO")] = QString("true");
else
settings[QString("FORCE_SUDO")] = QString("false");
settings[QString("HELPER_PATH")] = ui->lineEdit_helperPath->text();
settings[QString("HELPER_SERVICE")] = ui->lineEdit_helperService->text();
settings[QString("IFACE_DIR")] = ui->lineEdit_interfacesDir->text();
settings[QString("LANGUAGE")] = ui->comboBox_language->currentText();
settings[QString("NETCTL_PATH")] = ui->lineEdit_netctlPath->text();
settings[QString("NETCTLAUTO_PATH")] = ui->lineEdit_netctlAutoPath->text();
settings[QString("NETCTLAUTO_SERVICE")] = ui->lineEdit_netctlAutoService->text();
settings[QString("PID_FILE")] = ui->lineEdit_pid->text();
settings[QString("PREFERED_IFACE")] = ui->lineEdit_interface->text();
settings[QString("PROFILE_DIR")] = ui->lineEdit_profilePath->text();
settings[QString("RFKILL_DIR")] = ui->lineEdit_rfkill->text();
if (ui->checkBox_components->checkState() == 2)
settings[QString("SKIPCOMPONENTS")] = QString("true");
else
settings[QString("SKIPCOMPONENTS")] = QString("false");
if (ui->checkBox_startToTray->checkState() == 2)
settings[QString("STARTTOTRAY")] = QString("true");
else
settings[QString("STARTTOTRAY")] = QString("false");
settings[QString("SUDO_PATH")] = ui->lineEdit_sudo->text();
settings[QString("SYSTEMCTL_PATH")] = ui->lineEdit_systemctlPath->text();
if (ui->checkBox_enableTray->checkState() == 2)
settings[QString("SYSTRAY")] = QString("true");
else
settings[QString("SYSTRAY")] = QString("false");
if (ui->checkBox_useHelper->checkState() == 2)
settings[QString("USE_HELPER")] = QString("true");
else
settings[QString("USE_HELPER")] = QString("false");
settings[QString("WPACLI_PATH")] = ui->lineEdit_wpaCliPath->text();
settings[QString("WPASUP_PATH")] = ui->lineEdit_wpaSupPath->text();
settings[QString("WPA_DRIVERS")] = ui->lineEdit_wpaSupDrivers->text();
for (int i=0; i<settings.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << settings.keys()[i] + QString("=") + settings[settings.keys()[i]];
return settings; if (ui->checkBox_helperClose->checkState() == 2)
config[QString("CLOSE_HELPER")] = QString("true");
else
config[QString("CLOSE_HELPER")] = QString("false");
if (ui->checkBox_closeToTray->checkState() == 2)
config[QString("CLOSETOTRAY")] = QString("true");
else
config[QString("CLOSETOTRAY")] = QString("false");
config[QString("CTRL_DIR")] = ui->lineEdit_wpaDir->text();
config[QString("CTRL_GROUP")] = ui->lineEdit_wpaGroup->text();
if (ui->checkBox_forceSudo->checkState() == 2)
config[QString("FORCE_SUDO")] = QString("true");
else
config[QString("FORCE_SUDO")] = QString("false");
config[QString("EDITOR_PATH")] = ui->lineEdit_editorPath->text();
config[QString("HELPER_PATH")] = ui->lineEdit_helperPath->text();
config[QString("HELPER_SERVICE")] = ui->lineEdit_helperService->text();
config[QString("IFACE_DIR")] = ui->lineEdit_interfacesDir->text();
config[QString("LANGUAGE")] = ui->comboBox_language->currentText();
config[QString("MAIN_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_mainToolbar->currentIndex()));
config[QString("NETCTL_PATH")] = ui->lineEdit_netctlPath->text();
config[QString("NETCTL_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_netctlToolbar->currentIndex()));
config[QString("NETCTLAUTO_PATH")] = ui->lineEdit_netctlAutoPath->text();
config[QString("NETCTLAUTO_SERVICE")] = ui->lineEdit_netctlAutoService->text();
config[QString("NETCTLAUTO_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_netctlAutoToolbar->currentIndex()));
config[QString("PID_FILE")] = ui->lineEdit_pid->text();
config[QString("PREFERED_IFACE")] = ui->lineEdit_interface->text();
config[QString("PROFILE_DIR")] = ui->lineEdit_profilePath->text();
config[QString("PROFILE_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_profilesToolbar->currentIndex()));
config[QString("RFKILL_DIR")] = ui->lineEdit_rfkill->text();
if (ui->checkBox_components->checkState() == 2)
config[QString("SKIPCOMPONENTS")] = QString("true");
else
config[QString("SKIPCOMPONENTS")] = QString("false");
if (ui->checkBox_startToTray->checkState() == 2)
config[QString("STARTTOTRAY")] = QString("true");
else
config[QString("STARTTOTRAY")] = QString("false");
config[QString("SUDO_PATH")] = ui->lineEdit_sudo->text();
config[QString("SYSTEMCTL_PATH")] = ui->lineEdit_systemctlPath->text();
if (ui->checkBox_enableTray->checkState() == 2)
config[QString("SYSTRAY")] = QString("true");
else
config[QString("SYSTRAY")] = QString("false");
if (ui->checkBox_useHelper->checkState() == 2)
config[QString("USE_HELPER")] = QString("true");
else
config[QString("USE_HELPER")] = QString("false");
config[QString("WIFI_TOOLBAR")] = QString::number(indexToToolBarPosition(ui->comboBox_wifiToolbar->currentIndex()));
config[QString("WPACLI_PATH")] = ui->lineEdit_wpaCliPath->text();
config[QString("WPASUP_PATH")] = ui->lineEdit_wpaSupPath->text();
config[QString("WPA_DRIVERS")] = ui->lineEdit_wpaSupDrivers->text();
for (int i=0; i<config.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << QString("%1=%2").arg(config.keys()[i]).arg(config[config.keys()[i]]);
return config;
} }
void SettingsWindow::setSettings(const QMap<QString, QString> settings) void SettingsWindow::setSettings(const QMap<QString, QString> config)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (settings[QString("CLOSE_HELPER")] == QString("true")) if (config[QString("CLOSE_HELPER")] == QString("true"))
ui->checkBox_helperClose->setCheckState(Qt::Checked); ui->checkBox_helperClose->setCheckState(Qt::Checked);
else else
ui->checkBox_helperClose->setCheckState(Qt::Unchecked); ui->checkBox_helperClose->setCheckState(Qt::Unchecked);
if (settings[QString("CLOSETOTRAY")] == QString("true")) if (config[QString("CLOSETOTRAY")] == QString("true"))
ui->checkBox_closeToTray->setCheckState(Qt::Checked); ui->checkBox_closeToTray->setCheckState(Qt::Checked);
else else
ui->checkBox_closeToTray->setCheckState(Qt::Unchecked); ui->checkBox_closeToTray->setCheckState(Qt::Unchecked);
ui->lineEdit_wpaDir->setText(settings[QString("CTRL_DIR")]); ui->lineEdit_wpaDir->setText(config[QString("CTRL_DIR")]);
ui->lineEdit_wpaGroup->setText(settings[QString("CTRL_GROUP")]); ui->lineEdit_wpaGroup->setText(config[QString("CTRL_GROUP")]);
if (settings[QString("FORCE_SUDO")] == QString("true")) if (config[QString("FORCE_SUDO")] == QString("true"))
ui->checkBox_forceSudo->setCheckState(Qt::Checked); ui->checkBox_forceSudo->setCheckState(Qt::Checked);
else else
ui->checkBox_forceSudo->setCheckState(Qt::Unchecked); ui->checkBox_forceSudo->setCheckState(Qt::Unchecked);
ui->lineEdit_helperPath->setText(settings[QString("HELPER_PATH")]); ui->lineEdit_editorPath->setText(config[QString("EDITOR_PATH")]);
ui->lineEdit_helperService->setText(settings[QString("HELPER_SERVICE")]); ui->lineEdit_helperPath->setText(config[QString("HELPER_PATH")]);
ui->lineEdit_interfacesDir->setText(settings[QString("IFACE_DIR")]); ui->lineEdit_helperService->setText(config[QString("HELPER_SERVICE")]);
ui->comboBox_language->setCurrentIndex(0); ui->lineEdit_interfacesDir->setText(config[QString("IFACE_DIR")]);
for (int i=0; i<ui->comboBox_language->count(); i++) int index = ui->comboBox_language->findText(config[QString("LANGUAGE")]);
if (ui->comboBox_language->itemText(i) == settings[QString("LANGUAGE")]) ui->comboBox_language->setCurrentIndex(index);
ui->comboBox_language->setCurrentIndex(i); index = indexByToolBarPosition(static_cast<Qt::ToolBarArea>(config[QString("MAIN_TOOLBAR")].toInt()));
ui->lineEdit_netctlPath->setText(settings[QString("NETCTL_PATH")]); ui->comboBox_mainToolbar->setCurrentIndex(index);
ui->lineEdit_netctlAutoPath->setText(settings[QString("NETCTLAUTO_PATH")]); ui->lineEdit_netctlPath->setText(config[QString("NETCTL_PATH")]);
ui->lineEdit_netctlAutoService->setText(settings[QString("NETCTLAUTO_SERVICE")]); index = indexByToolBarPosition(static_cast<Qt::ToolBarArea>(config[QString("NETCTL_TOOLBAR")].toInt()));
ui->lineEdit_pid->setText(settings[QString("PID_FILE")]); ui->comboBox_netctlToolbar->setCurrentIndex(index);
ui->lineEdit_interface->setText(settings[QString("PREFERED_IFACE")]); ui->lineEdit_netctlAutoPath->setText(config[QString("NETCTLAUTO_PATH")]);
ui->lineEdit_profilePath->setText(settings[QString("PROFILE_DIR")]); ui->lineEdit_netctlAutoService->setText(config[QString("NETCTLAUTO_SERVICE")]);
ui->lineEdit_rfkill->setText(settings[QString("RFKILL_DIR")]); index = indexByToolBarPosition(static_cast<Qt::ToolBarArea>(config[QString("NETCTLAUTO_TOOLBAR")].toInt()));
if (settings[QString("SKIPCOMPONENTS")] == QString("true")) ui->comboBox_netctlAutoToolbar->setCurrentIndex(index);
ui->lineEdit_pid->setText(config[QString("PID_FILE")]);
ui->lineEdit_interface->setText(config[QString("PREFERED_IFACE")]);
index = indexByToolBarPosition(static_cast<Qt::ToolBarArea>(config[QString("PROFILE_TOOLBAR")].toInt()));
ui->comboBox_profilesToolbar->setCurrentIndex(index);
ui->lineEdit_profilePath->setText(config[QString("PROFILE_DIR")]);
ui->lineEdit_rfkill->setText(config[QString("RFKILL_DIR")]);
if (config[QString("SKIPCOMPONENTS")] == QString("true"))
ui->checkBox_components->setCheckState(Qt::Checked); ui->checkBox_components->setCheckState(Qt::Checked);
else else
ui->checkBox_components->setCheckState(Qt::Unchecked); ui->checkBox_components->setCheckState(Qt::Unchecked);
if (settings[QString("STARTTOTRAY")] == QString("true")) if (config[QString("STARTTOTRAY")] == QString("true"))
ui->checkBox_startToTray->setCheckState(Qt::Checked); ui->checkBox_startToTray->setCheckState(Qt::Checked);
else else
ui->checkBox_startToTray->setCheckState(Qt::Unchecked); ui->checkBox_startToTray->setCheckState(Qt::Unchecked);
ui->lineEdit_sudo->setText(settings[QString("SUDO_PATH")]); ui->lineEdit_sudo->setText(config[QString("SUDO_PATH")]);
ui->lineEdit_systemctlPath->setText(settings[QString("SYSTEMCTL_PATH")]); ui->lineEdit_systemctlPath->setText(config[QString("SYSTEMCTL_PATH")]);
if (settings[QString("SYSTRAY")] == QString("true")) if (config[QString("SYSTRAY")] == QString("true"))
ui->checkBox_enableTray->setCheckState(Qt::Checked); ui->checkBox_enableTray->setCheckState(Qt::Checked);
else else
ui->checkBox_enableTray->setCheckState(Qt::Unchecked); ui->checkBox_enableTray->setCheckState(Qt::Unchecked);
if (settings[QString("USE_HELPER")] == QString("true")) if (config[QString("USE_HELPER")] == QString("true"))
ui->checkBox_useHelper->setCheckState(Qt::Checked); ui->checkBox_useHelper->setCheckState(Qt::Checked);
else else
ui->checkBox_useHelper->setCheckState(Qt::Unchecked); ui->checkBox_useHelper->setCheckState(Qt::Unchecked);
ui->lineEdit_wpaCliPath->setText(settings[QString("WPACLI_PATH")]); index = indexByToolBarPosition(static_cast<Qt::ToolBarArea>(config[QString("WIFI_TOOLBAR")].toInt()));
ui->lineEdit_wpaSupPath->setText(settings[QString("WPASUP_PATH")]); ui->comboBox_wifiToolbar->setCurrentIndex(index);
ui->lineEdit_wpaSupDrivers->setText(settings[QString("WPA_DRIVERS")]); ui->lineEdit_wpaCliPath->setText(config[QString("WPACLI_PATH")]);
for (int i=0; i<settings.keys().count(); i++) ui->lineEdit_wpaSupPath->setText(config[QString("WPASUP_PATH")]);
if (debug) qDebug() << PDEBUG << ":" << settings.keys()[i] + QString("=") + settings[settings.keys()[i]]; ui->lineEdit_wpaSupDrivers->setText(config[QString("WPA_DRIVERS")]);
for (int i=0; i<config.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << QString("%1=%2").arg(config.keys()[i]).arg(config[config.keys()[i]]);
} }
@ -353,62 +571,75 @@ QMap<QString, QString> SettingsWindow::getDefault()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QMap<QString, QString> settings; return getSettings(QString("/dev/null"));
settings[QString("CLOSE_HELPER")] = QString("false");
settings[QString("CLOSETOTRAY")] = QString("true");
settings[QString("CTRL_DIR")] = QString("/run/wpa_supplicant_netctl-gui");
settings[QString("CTRL_GROUP")] = QString("users");
settings[QString("FORCE_SUDO")] = QString("false");
settings[QString("HELPER_PATH")] = QString("/usr/bin/netctlgui-helper");
settings[QString("HELPER_SERVICE")] = QString("netctlgui-helper.service");
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("SKIPCOMPONENTS")] = QString("false");
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("USE_HELPER")] = 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() << PDEBUG << ":" << settings.keys()[i] + QString("=") + settings[settings.keys()[i]];
return settings;
} }
QMap<QString, QString> SettingsWindow::getSettings() QMap<QString, QString> SettingsWindow::getSettings(QString fileName)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (fileName.isEmpty()) fileName = file;
QMap<QString, QString> settings = getDefault(); QMap<QString, QString> config;
QFile configFile(file); QSettings settings(fileName, QSettings::IniFormat);
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() << PDEBUG << ":" << settings.keys()[i] + QString("=") + settings[settings.keys()[i]];
return settings; config[QString("LANGUAGE")] = Language::defineLanguage(fileName, QString());
settings.beginGroup(QString("Common"));
config[QString("LANGUAGE")] = settings.value(QString("LANGUAGE"), QString("en")).toString();
config[QString("SYSTRAY")] = settings.value(QString("SYSTRAY"), QString("true")).toString();
config[QString("CLOSETOTRAY")] = settings.value(QString("CLOSETOTRAY"), QString("true")).toString();
config[QString("STARTTOTRAY")] = settings.value(QString("STARTTOTRAY"), QString("false")).toString();
config[QString("SKIPCOMPONENTS")] = settings.value(QString("SKIPCOMPONENTS"), QString("false")).toString();
settings.endGroup();
settings.beginGroup(QString("Helper"));
config[QString("USE_HELPER")] = settings.value(QString("USE_HELPER"), QString("true")).toString();
config[QString("FORCE_SUDO")] = settings.value(QString("FORCE_SUDO"), QString("false")).toString();
config[QString("CLOSE_HELPER")] = settings.value(QString("CLOSE_HELPER"), QString("false")).toString();
config[QString("HELPER_PATH")] = settings.value(QString("HELPER_PATH"), QString("/usr/bin/netctlgui-helper")).toString();
config[QString("HELPER_SERVICE")] = settings.value(QString("HELPER_SERVICE"), QString("netctlgui-helper.service")).toString();
settings.endGroup();
settings.beginGroup(QString("netctl"));
config[QString("SYSTEMCTL_PATH")] = settings.value(QString("SYSTEMCTL_PATH"), QString("/usr/bin/systemctl")).toString();
config[QString("NETCTL_PATH")] = settings.value(QString("NETCTL_PATH"), QString("/usr/bin/netctl")).toString();
config[QString("NETCTLAUTO_PATH")] = settings.value(QString("NETCTLAUTO_PATH"), QString("/usr/bin/netctl-auto")).toString();
config[QString("NETCTLAUTO_SERVICE")] = settings.value(QString("NETCTLAUTO_SERVICE"), QString("netctl-auto")).toString();
config[QString("PROFILE_DIR")] = settings.value(QString("PROFILE_DIR"), QString("/etc/netctl")).toString();
settings.endGroup();
settings.beginGroup(QString("sudo"));
config[QString("SUDO_PATH")] = settings.value(QString("SUDO_PATH"), QString("/usr/bin/kdesu")).toString();
settings.endGroup();
settings.beginGroup(QString("wpa_supplicant"));
config[QString("WPASUP_PATH")] = settings.value(QString("WPASUP_PATH"), QString("/usr/bin/wpa_supplicant")).toString();
config[QString("WPACLI_PATH")] = settings.value(QString("WPACLI_PATH"), QString("/usr/bin/wpa_cli")).toString();
config[QString("PID_FILE")] = settings.value(QString("PID_FILE"), QString("/run/wpa_supplicant_$i.pid")).toString();
config[QString("WPA_DRIVERS")] = settings.value(QString("WPA_DRIVERS"), QString("nl80211,wext")).toString();
config[QString("CTRL_DIR")] = settings.value(QString("CTRL_DIR"), QString("/run/wpa_supplicant")).toString();
config[QString("CTRL_GROUP")] = settings.value(QString("CTRL_GROUP"), QString("users")).toString();
settings.endGroup();
settings.beginGroup(QString("Other"));
config[QString("EDITOR_PATH")] = settings.value(QString("EDITOR_PATH"), QString("/usr/bin/gvim")).toString();
config[QString("IFACE_DIR")] = settings.value(QString("IFACE_DIR"), QString("/sys/class/net/")).toString();
config[QString("RFKILL_DIR")] = settings.value(QString("RFKILL_DIR"), QString("/sys/class/rfkill/")).toString();
config[QString("PREFERED_IFACE")] = settings.value(QString("PREFERED_IFACE"), QString("")).toString();
settings.endGroup();
settings.beginGroup(QString("Toolbars"));
config[QString("MAIN_TOOLBAR")] = settings.value(QString("MAIN_TOOLBAR"), Qt::TopToolBarArea).toString();
config[QString("NETCTL_TOOLBAR")] = settings.value(QString("NETCTL_TOOLBAR"), Qt::TopToolBarArea).toString();
config[QString("NETCTLAUTO_TOOLBAR")] = settings.value(QString("NETCTLAUTO_TOOLBAR"), Qt::TopToolBarArea).toString();
config[QString("PROFILE_TOOLBAR")] = settings.value(QString("PROFILE_TOOLBAR"), Qt::TopToolBarArea).toString();
config[QString("WIFI_TOOLBAR")] = settings.value(QString("WIFI_TOOLBAR"), Qt::TopToolBarArea).toString();
settings.endGroup();
for (int i=0; i<config.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << QString("%1=%2").arg(config.keys()[i]).arg(config[config.keys()[i]]);
return config;
} }
@ -416,7 +647,7 @@ void SettingsWindow::startHelper()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
((MainWindow *)parent())->startHelper(); dynamic_cast<MainWindow *>(parent())->startHelper();
updateHelper(); updateHelper();
} }
@ -425,12 +656,12 @@ void SettingsWindow::updateHelper()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (((MainWindow *)parent())->isHelperServiceActive()) { if (dynamic_cast<MainWindow *>(parent())->isHelperServiceActive()) {
ui->label_status->setText(QApplication::translate("SettingsWindow", "Active (systemd)")); ui->label_status->setText(QApplication::translate("SettingsWindow", "Active (systemd)"));
ui->pushButton_status->setText(QApplication::translate("SettingsWindow", "Stop")); ui->pushButton_status->setText(QApplication::translate("SettingsWindow", "Stop"));
ui->pushButton_status->setIcon(QIcon::fromTheme("process-stop")); ui->pushButton_status->setIcon(QIcon::fromTheme("process-stop"));
ui->pushButton_status->setDisabled(true); ui->pushButton_status->setDisabled(true);
} else if (((MainWindow *)parent())->isHelperActive()) { } else if (dynamic_cast<MainWindow *>(parent())->isHelperActive()) {
ui->label_status->setText(QApplication::translate("SettingsWindow", "Active")); ui->label_status->setText(QApplication::translate("SettingsWindow", "Active"));
ui->pushButton_status->setText(QApplication::translate("SettingsWindow", "Stop")); ui->pushButton_status->setText(QApplication::translate("SettingsWindow", "Stop"));
ui->pushButton_status->setIcon(QIcon::fromTheme("process-stop")); ui->pushButton_status->setIcon(QIcon::fromTheme("process-stop"));

View File

@ -39,7 +39,7 @@ public:
const QString configFile = QString("")); const QString configFile = QString(""));
~SettingsWindow(); ~SettingsWindow();
QMap<QString, QString> getDefault(); QMap<QString, QString> getDefault();
QMap<QString, QString> getSettings(); QMap<QString, QString> getSettings(QString fileName = QString(""));
public slots: public slots:
void closeWindow(); void closeWindow();
@ -48,9 +48,12 @@ public slots:
void showWindow(); void showWindow();
private slots: private slots:
void addGroups();
void addLanguages(); void addLanguages();
void applyHelperGroup();
void changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous); void changePage(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void saveSettings(); void saveSettings();
void setHelperGroup();
void setTray(); void setTray();
void updateHelper(); void updateHelper();
// buttons // buttons
@ -62,10 +65,12 @@ private:
QString file; QString file;
Ui::SettingsWindow *ui; Ui::SettingsWindow *ui;
void createActions(); void createActions();
int indexByToolBarPosition(const Qt::ToolBarArea area);
Qt::ToolBarArea indexToToolBarPosition(const int index);
// ESC pressed event // ESC pressed event
void keyPressEvent(QKeyEvent *pressedKey); void keyPressEvent(QKeyEvent *pressedKey);
QMap<QString, QString> readSettings(); QMap<QString, QString> readSettings();
void setSettings(const QMap<QString, QString> settings); void setSettings(const QMap<QString, QString> config);
}; };

File diff suppressed because it is too large Load Diff

View File

@ -19,18 +19,19 @@
#include <QDebug> #include <QDebug>
#include <QMenu> #include <QMenu>
#include <QMessageBox>
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include "calls.h"
#include "mainwindow.h" #include "mainwindow.h"
TrayIcon::TrayIcon(QObject *parent, const bool debugCmd) TrayIcon::TrayIcon(QObject *parent, const QMap<QString, QString> settings, const bool debugCmd)
: QSystemTrayIcon(parent), : QSystemTrayIcon(parent),
debug(debugCmd) debug(debugCmd)
{ {
mainWindow = (MainWindow *)parent; mainWindow = dynamic_cast<MainWindow *>(parent);
useHelper = (settings[QString("USE_HELPER")] == QString("true"));
init(); init();
} }
@ -40,45 +41,10 @@ TrayIcon::~TrayIcon()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
setContextMenu(0); setContextMenu(nullptr);
startProfileMenu->clear(); startProfileMenu->clear();
switchToProfileMenu->clear(); switchToProfileMenu->clear();
menuActions->clear(); menuActions->clear();
delete startProfileMenu;
delete switchToProfileMenu;
delete menuActions;
for (int i=0; i<contextMenu.keys().count(); i++)
delete contextMenu[contextMenu.keys()[i]];
}
int TrayIcon::showInformation()
{
if (debug) qDebug() << PDEBUG;
if (supportsMessages()) {
QString title = QApplication::translate("TrayIcon", "netctl status");
QStringList info = mainWindow->printInformation();
QString message = QString("%1: %2\n").arg(QApplication::translate("TrayIcon", "Profile")).arg(info[0]);
message += QString("%1: %2").arg(QApplication::translate("TrayIcon", "Status")).arg(info[1]);
showMessage(title, message, QSystemTrayIcon::Information);
}
else
return showInformationInWindow();
return 0;
}
int TrayIcon::showInformationInWindow()
{
if (debug) qDebug() << PDEBUG;
QString title = QApplication::translate("TrayIcon", "netctl status");
QStringList info = mainWindow->printInformation();
QString message = QString("%1: %2\n").arg(QApplication::translate("TrayIcon", "Profile")).arg(info[0]);
message += QString("%1: %2").arg(QApplication::translate("TrayIcon", "Status")).arg(info[1]);
return QMessageBox::information(0, title, message);
} }
@ -86,87 +52,53 @@ void TrayIcon::updateMenu()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QStringList info = mainWindow->printTrayInformation(); netctlCurrent info = mainWindow->printTrayInformation();
bool netctlAutoStatus = info[0].toInt();
QStringList profiles = info[1].split(QChar('|'));
QString current = info[2];
QString enabled = info[3];
if (current.isEmpty()) { if (info.current.isEmpty()) {
contextMenu[QString("title")]->setIcon(QIcon(QString(":network-offline-64x64"))); contextMenu[QString("title")]->setIcon(QIcon(QString(":network-offline-64x64")));
contextMenu[QString("title")]->setText(QApplication::translate("TrayIcon", "(inactive)")); contextMenu[QString("title")]->setText(QApplication::translate("TrayIcon", "(inactive)"));
} else { } else {
contextMenu[QString("title")]->setIcon(QIcon(QString(":network-idle-64x64"))); contextMenu[QString("title")]->setIcon(QIcon(QString(":network-idle-64x64")));
QStringList currentProfiles, status;
if (netctlAutoStatus) {
currentProfiles.append(current);
status.append(QApplication::translate("TrayIcon", "(netctl-auto)"));
} else {
for (int i=0; i<enabled.split(QChar('|')).count(); i++) {
currentProfiles.append(current.split(QChar('|'))[i]);
if (enabled.split(QChar('|'))[i] == QString("0"))
status.append(QApplication::translate("TrayIcon", "static"));
else
status.append(QApplication::translate("TrayIcon", "enabled"));
}
}
QStringList profiles; QStringList profiles;
for (int i=0; i<currentProfiles.count(); i++) if (info.netctlAuto)
profiles.append(currentProfiles[i] + QString(" (") + status[i] + QString(")")); profiles.append(QString("%1 (%2)").arg(info.current[0])
.arg(QApplication::translate("TrayIcon", "netctl-auto")));
else
for (int i=0; i<info.current.count(); i++) {
QString status;
if (info.enables[i])
status = QApplication::translate("TrayIcon", "enabled");
else
status = QApplication::translate("TrayIcon", "static");
profiles.append(QString("%1 (%2)").arg(info.current[i]).arg(status));
}
contextMenu[QString("title")]->setText(profiles.join(QString(" | "))); contextMenu[QString("title")]->setText(profiles.join(QString(" | ")));
} }
if (netctlAutoStatus) { startProfileMenu->menuAction()->setVisible(!info.netctlAuto);
contextMenu[QString("start")]->setVisible(false); contextMenu[QString("stop")]->setVisible(!info.netctlAuto && (info.current.count() == 1));
contextMenu[QString("stop")]->setVisible(false); contextMenu[QString("stopall")]->setVisible(!info.netctlAuto && (info.current.count() > 1));
contextMenu[QString("stopall")]->setVisible(false); switchToProfileMenu->menuAction()->setVisible(info.netctlAuto);
contextMenu[QString("switch")]->setVisible(true); contextMenu[QString("restart")]->setVisible(!info.netctlAuto && (info.current.count() == 1));
contextMenu[QString("restart")]->setVisible(false); contextMenu[QString("enable")]->setVisible(!info.netctlAuto && (info.current.count() == 1));
contextMenu[QString("enable")]->setVisible(false);
if (info.netctlAuto) {
switchToProfileMenu->clear(); switchToProfileMenu->clear();
for (int i=0; i<profiles.count(); i++) { for (int i=0; i<info.profiles.count(); i++)
QAction *profile = new QAction(profiles[i], this); switchToProfileMenu->addAction(info.profiles[i]);
switchToProfileMenu->addAction(profile);
}
} else { } else {
if (current.contains(QChar('|'))) { if (info.current.count() == 1) {
contextMenu[QString("start")]->setVisible(true); contextMenu[QString("stop")]->setText(QApplication::translate("TrayIcon", "Stop %1").arg(info.current[0]));
contextMenu[QString("stop")]->setVisible(false); contextMenu[QString("restart")]->setText(QApplication::translate("TrayIcon", "Restart %1").arg(info.current[0]));
contextMenu[QString("stopall")]->setVisible(true); if (info.enables[0])
contextMenu[QString("switch")]->setVisible(false); contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Disable %1").arg(info.current[0]));
contextMenu[QString("restart")]->setVisible(false);
contextMenu[QString("enable")]->setVisible(false);
} else {
contextMenu[QString("start")]->setVisible(true);
contextMenu[QString("stop")]->setVisible(!current.isEmpty());
contextMenu[QString("switch")]->setVisible(false);
contextMenu[QString("stopall")]->setVisible(false);
contextMenu[QString("restart")]->setVisible(!current.isEmpty());
contextMenu[QString("enable")]->setVisible(!current.isEmpty());
}
if (!current.isEmpty()) {
contextMenu[QString("start")]->setText(QApplication::translate("TrayIcon", "Start another profile"));
contextMenu[QString("stop")]->setText(QApplication::translate("TrayIcon", "Stop %1").arg(current));
contextMenu[QString("restart")]->setText(QApplication::translate("TrayIcon", "Restart %1").arg(current));
if (enabled.split(QChar('|'))[0].toInt())
contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Disable %1").arg(current));
else else
contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Enable %1").arg(current)); contextMenu[QString("enable")]->setText(QApplication::translate("TrayIcon", "Enable %1").arg(info.current[0]));
} else
contextMenu[QString("start")]->setText(QApplication::translate("TrayIcon", "Start profile"));
startProfileMenu->clear();
for (int i=0; i<profiles.count(); i++) {
QAction *profile = new QAction(profiles[i], this);
startProfileMenu->addAction(profile);
} }
startProfileMenu->clear();
for (int i=0; i<info.profiles.count(); i++)
startProfileMenu->addAction(info.profiles[i]);
} }
if (mainWindow->isHidden())
contextMenu[QString("gui")]->setText(QApplication::translate("TrayIcon", "Show"));
else
contextMenu[QString("gui")]->setText(QApplication::translate("TrayIcon", "Hide"));
setContextMenu(menuActions);
} }
@ -176,55 +108,43 @@ void TrayIcon::createActions()
menuActions = new QMenu(); menuActions = new QMenu();
contextMenu[QString("title")] = new QAction(QIcon(":icon"), QApplication::translate("TrayIcon", "Status"), this); contextMenu[QString("title")] = menuActions->addAction(QIcon(":icon"),
menuActions->addAction(contextMenu[QString("title")]); QApplication::translate("TrayIcon", "Status"),
connect(contextMenu[QString("title")], SIGNAL(triggered(bool)), this, SLOT(showInformationInWindow())); mainWindow,
SLOT(showMainWindow()));
menuActions->addSeparator(); menuActions->addSeparator();
contextMenu[QString("start")] = new QAction(QIcon::fromTheme("system-run"), QApplication::translate("TrayIcon", "Start profile"), this); startProfileMenu = menuActions->addMenu(QIcon::fromTheme("system-run"),
startProfileMenu = new QMenu(); QApplication::translate("TrayIcon", "Start profile"));
contextMenu[QString("start")]->setMenu(startProfileMenu); connect(startProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(startProfileTraySlot(QAction *)));
connect(startProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(startProfileSlot(QAction *)));
menuActions->addAction(contextMenu[QString("start")]);
contextMenu[QString("stop")] = new QAction(QIcon::fromTheme("process-stop"), QApplication::translate("TrayIcon", "Stop profile"), this); contextMenu[QString("stop")] = menuActions->addAction(QIcon::fromTheme("process-stop"),
connect(contextMenu[QString("stop")], SIGNAL(triggered(bool)), this, SLOT(stopProfileSlot())); QApplication::translate("TrayIcon", "Stop profile"),
menuActions->addAction(contextMenu[QString("stop")]); this,
SLOT(startProfileTraySlot()));
contextMenu[QString("stopall")] = menuActions->addAction(QIcon::fromTheme("process-stop"),
QApplication::translate("TrayIcon", "Stop all profiles"),
this,
SLOT(stopAllProfilesTraySlot()));
contextMenu[QString("stopall")] = new QAction(QIcon::fromTheme("process-stop"), QApplication::translate("TrayIcon", "Stop all profiles"), this); switchToProfileMenu = menuActions->addMenu(QIcon::fromTheme("system-run"),
connect(contextMenu[QString("stopall")], SIGNAL(triggered(bool)), this, SLOT(stopAllProfilesSlot())); QApplication::translate("TrayIcon", "Switch to profile"));
menuActions->addAction(contextMenu[QString("stopall")]); connect(switchToProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(switchToProfileTraySlot(QAction *)));
contextMenu[QString("switch")] = new QAction(QIcon::fromTheme("system-run"), QApplication::translate("TrayIcon", "Switch to profile"), this);
switchToProfileMenu = new QMenu();
contextMenu[QString("switch")]->setMenu(switchToProfileMenu);
connect(switchToProfileMenu, SIGNAL(triggered(QAction *)), this, SLOT(switchToProfileSlot(QAction *)));
menuActions->addAction(contextMenu[QString("switch")]);
contextMenu[QString("restart")] = new QAction(QIcon::fromTheme("stock-refresh"), QApplication::translate("TrayIcon", "Restart profile"), this);
connect(contextMenu[QString("restart")], SIGNAL(triggered(bool)), this, SLOT(restartProfileSlot()));
menuActions->addAction(contextMenu[QString("restart")]);
contextMenu[QString("enable")] = new QAction(QApplication::translate("TrayIcon", "Enable profile"), this);
connect(contextMenu[QString("enable")], SIGNAL(triggered(bool)), this, SLOT(enableProfileSlot()));
menuActions->addAction(contextMenu[QString("enable")]);
contextMenu[QString("restart")] = menuActions->addAction(QIcon::fromTheme("view-refresh"),
QApplication::translate("TrayIcon", "Restart profile"),
this,
SLOT(restartProfileTraySlot()));
contextMenu[QString("enable")] = menuActions->addAction(QIcon::fromTheme("list-add"),
QApplication::translate("TrayIcon", "Enable profile"),
this,
SLOT(enableProfileTraySlot()));
menuActions->addSeparator(); menuActions->addSeparator();
contextMenu[QString("gui")] = new QAction(QApplication::translate("TrayIcon", "Show"), this); contextMenu[QString("quit")] = menuActions->addAction(QIcon::fromTheme("application-exit"),
connect(contextMenu[QString("gui")], SIGNAL(triggered(bool)), mainWindow, SLOT(showMainWindow())); QApplication::translate("TrayIcon", "Quit"),
menuActions->addAction(contextMenu[QString("gui")]); mainWindow,
SLOT(closeMainWindow()));
contextMenu[QString("auto")] = new QAction(QApplication::translate("TrayIcon", "Show netctl-auto"), this);
connect(contextMenu[QString("auto")], SIGNAL(triggered(bool)), mainWindow, SLOT(showNetctlAutoWindow()));
menuActions->addAction(contextMenu[QString("auto")]);
menuActions->addSeparator();
contextMenu[QString("quit")] = new QAction(QApplication::translate("TrayIcon", "Quit"), this);
connect(contextMenu[QString("quit")], SIGNAL(triggered(bool)), mainWindow, SLOT(closeMainWindow()));
menuActions->addAction(contextMenu[QString("quit")]);
} }
@ -236,6 +156,7 @@ void TrayIcon::init()
setToolTip(QString("netctl-gui")); setToolTip(QString("netctl-gui"));
createActions(); createActions();
setContextMenu(menuActions);
connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(itemActivated(QSystemTrayIcon::ActivationReason))); this, SLOT(itemActivated(QSystemTrayIcon::ActivationReason)));
@ -249,14 +170,9 @@ void TrayIcon::itemActivated(const QSystemTrayIcon::ActivationReason reason)
switch (reason) { switch (reason) {
case QSystemTrayIcon::Trigger: case QSystemTrayIcon::Trigger:
showInformation();
break;
case QSystemTrayIcon::DoubleClick:
mainWindow->showMainWindow(); mainWindow->showMainWindow();
break; break;
case QSystemTrayIcon::Context: case QSystemTrayIcon::Context:
// clear menu before update
setContextMenu(0);
updateMenu(); updateMenu();
break; break;
default: default:
@ -265,59 +181,59 @@ void TrayIcon::itemActivated(const QSystemTrayIcon::ActivationReason reason)
} }
bool TrayIcon::enableProfileSlot() void TrayIcon::enableProfileTraySlot()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QString profile = mainWindow->printInformation()[0]; QStringList profiles = mainWindow->printTrayInformation().current;
if (profiles.isEmpty()) return;
return mainWindow->enableProfileSlot(profile); enableProfileSlot(profiles[0], mainWindow->netctlInterface, useHelper, debug);
} }
bool TrayIcon::restartProfileSlot() void TrayIcon::restartProfileTraySlot()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QString profile = mainWindow->printInformation()[0]; QStringList profiles = mainWindow->printTrayInformation().current;
if (profiles.isEmpty()) return;
return mainWindow->restartProfileSlot(profile); restartProfileSlot(profiles[0], mainWindow->netctlInterface, useHelper, debug);
} }
bool TrayIcon::startProfileSlot(QAction *action) void TrayIcon::startProfileTraySlot(QAction *action)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QString profile = action->text().remove(QChar('&')); QString profile;
if (action == nullptr) {
QStringList profiles = mainWindow->printTrayInformation().current;
if (profiles.isEmpty()) return;
profile = profiles[0];
} else
profile = action->text().remove(QChar('&'));
return mainWindow->switchToProfileSlot(profile); startProfileSlot(profile, mainWindow->netctlInterface, useHelper, debug);
} }
bool TrayIcon::stopProfileSlot() void TrayIcon::stopAllProfilesTraySlot()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QString profile = mainWindow->printInformation()[0]; stopAllProfilesSlot(mainWindow->netctlInterface, useHelper, debug);
return mainWindow->startProfileSlot(profile);
} }
bool TrayIcon::stopAllProfilesSlot() void TrayIcon::switchToProfileTraySlot(QAction *action)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (action == nullptr) return;
return mainWindow->stopAllProfilesSlot(); QStringList profiles = mainWindow->printTrayInformation().current;
} if (profiles.isEmpty()) return;
switchToProfileSlot(profiles[0], mainWindow->netctlInterface, useHelper, debug);
bool TrayIcon::switchToProfileSlot(QAction *action)
{
if (debug) qDebug() << PDEBUG;
QString profile = action->text().remove(QChar('&'));
return mainWindow->switchToProfileSlot(profile);
} }

View File

@ -31,25 +31,24 @@ class TrayIcon : public QSystemTrayIcon
public: public:
explicit TrayIcon(QObject *parent = 0, explicit TrayIcon(QObject *parent = 0,
const QMap<QString,QString> settings = QMap<QString,QString>(),
const bool debugCmd = false); const bool debugCmd = false);
~TrayIcon(); ~TrayIcon();
public slots: public slots:
int showInformation();
int showInformationInWindow();
void updateMenu(); void updateMenu();
private slots: private slots:
void itemActivated(const QSystemTrayIcon::ActivationReason reason); void itemActivated(const QSystemTrayIcon::ActivationReason reason);
bool enableProfileSlot(); void enableProfileTraySlot();
bool restartProfileSlot(); void restartProfileTraySlot();
bool startProfileSlot(QAction *action); void startProfileTraySlot(QAction *action = nullptr);
bool stopProfileSlot(); void stopAllProfilesTraySlot();
bool stopAllProfilesSlot(); void switchToProfileTraySlot(QAction *action);
bool switchToProfileSlot(QAction *action);
private: private:
bool debug; bool debug;
bool useHelper = true;
MainWindow *mainWindow; MainWindow *mainWindow;
// contextual actions // contextual actions
QMenu *menuActions; QMenu *menuActions;

View File

@ -18,6 +18,8 @@
#include "tunnelwidget.h" #include "tunnelwidget.h"
#include "ui_tunnelwidget.h" #include "ui_tunnelwidget.h"
#include "ipregexp.h"
TunnelWidget::TunnelWidget(QWidget *parent) TunnelWidget::TunnelWidget(QWidget *parent)
: QWidget(parent), : QWidget(parent),
@ -43,65 +45,32 @@ void TunnelWidget::clear()
} }
void TunnelWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void TunnelWidget::createFilter() void TunnelWidget::createFilter()
{ {
// using input mask because validators is not comfortable ui->lineEdit_local->setValidator(IpRegExp::ipv4Validator());
// ipv4 ui->lineEdit_remote->setValidator(IpRegExp::ipv4Validator());
ui->lineEdit_local->setInputMask(QString("999.999.999.999"));
ui->lineEdit_remote->setInputMask(QString("999.999.999.999"));
}
QString TunnelWidget::getIp(const QString rawIp)
{
QStringList ip = rawIp.split(QChar('.'));
// fix empty fields
if (ip[0].isEmpty())
ip[0] = QString("127");
if (ip[1].isEmpty())
ip[1] = QString("0");
if (ip[2].isEmpty())
ip[2] = QString("0");
if (ip[3].isEmpty())
ip[3] = QString("1");
// fix numbers
for (int i=0; i<4; i++)
if (ip[i].toInt() > 255)
ip[i] = QString("255");
return ip.join(QChar('.'));
} }
QMap<QString, QString> TunnelWidget::getSettings() QMap<QString, QString> TunnelWidget::getSettings()
{ {
QMap<QString, QString> tunnelSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return tunnelSettings;
tunnelSettings[QString("Mode")] = QString("'") + ui->comboBox_mode->currentText() + QString("'"); settings[QString("Mode")] = QString("'%1'").arg(ui->comboBox_mode->currentText());
if (!ui->lineEdit_local->text().remove(QChar('.')).remove(QChar(' ')).isEmpty()) if (!IpRegExp::checkString(ui->lineEdit_local->text(), IpRegExp::ip4Regex()))
tunnelSettings[QString("Local")] = QString("'") + getIp(ui->lineEdit_local->text().remove(QChar(' '))) + QString("'"); settings[QString("Local")] = QString("'%1'").arg(ui->lineEdit_local->text());
if (!ui->lineEdit_remote->text().remove(QChar('.')).remove(QChar(' ')).isEmpty()) settings[QString("Remote")] = QString("'%1'").arg(ui->lineEdit_remote->text());
tunnelSettings[QString("Remote")] = QString("'") + getIp(ui->lineEdit_remote->text().remove(QChar(' '))) + QString("'");
return tunnelSettings; return settings;
} }
int TunnelWidget::isOk() int TunnelWidget::isOk()
{ {
// ip is not correct
if (!IpRegExp::checkString(ui->lineEdit_remote->text(), IpRegExp::ip4Regex())) return 1;
// all fine // all fine
return 0; return 0;
} }
@ -110,14 +79,13 @@ int TunnelWidget::isOk()
void TunnelWidget::setSettings(const QMap<QString, QString> settings) void TunnelWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> tunnelSettings = settings;
if (tunnelSettings.contains(QString("Mode"))) if (settings.contains(QString("Mode"))) {
for (int i=0; i<ui->comboBox_mode->count(); i++) int index = ui->comboBox_mode->findText(settings[QString("Mode")]);
if (tunnelSettings[QString("Mode")] == ui->comboBox_mode->itemText(i)) ui->comboBox_mode->setCurrentIndex(index);
ui->comboBox_mode->setCurrentIndex(i); }
if (tunnelSettings.contains(QString("Local"))) if (settings.contains(QString("Local")))
ui->lineEdit_local->setText(tunnelSettings[QString("Local")]); ui->lineEdit_local->setText(settings[QString("Local")]);
if (tunnelSettings.contains(QString("Remote"))) if (settings.contains(QString("Remote")))
ui->lineEdit_remote->setText(tunnelSettings[QString("Remote")]); ui->lineEdit_remote->setText(settings[QString("Remote")]);
} }

View File

@ -38,12 +38,10 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private: private:
Ui::TunnelWidget *ui; Ui::TunnelWidget *ui;
void createFilter(); void createFilter();
QString getIp(const QString rawIp);
}; };

View File

@ -7,13 +7,13 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>411</width> <width>411</width>
<height>146</height> <height>108</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_tunnel"> <widget class="QDockWidget" name="dockWidget_tunnel">
<property name="features"> <property name="features">
@ -24,23 +24,35 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_tunnel"> <widget class="QWidget" name="dockWidgetContents_tunnel">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_mode"> <layout class="QHBoxLayout" name="layout_mode">
<item> <item>
<widget class="QLabel" name="label_mode"> <widget class="QLabel" name="label_mode">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Mode</string> <string>Mode</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_mode"> <widget class="QComboBox" name="comboBox_mode">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The tunnel type</string> <string>The tunnel type</string>
</property> </property>
@ -92,19 +104,28 @@
<layout class="QHBoxLayout" name="layout_local"> <layout class="QHBoxLayout" name="layout_local">
<item> <item>
<widget class="QLabel" name="label_local"> <widget class="QLabel" name="label_local">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Local</string> <string>Local</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_local"> <widget class="QLineEdit" name="lineEdit_local">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The address of the local end of the tunnel</string> <string>The address of the local end of the tunnel</string>
</property> </property>
@ -116,19 +137,28 @@
<layout class="QHBoxLayout" name="layout_remote"> <layout class="QHBoxLayout" name="layout_remote">
<item> <item>
<widget class="QLabel" name="label_remote"> <widget class="QLabel" name="label_remote">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Remote</string> <string>Remote</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_remote"> <widget class="QLineEdit" name="lineEdit_remote">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The address of the remote end of the tunnel</string> <string>The address of the remote end of the tunnel</string>
</property> </property>

View File

@ -42,38 +42,26 @@ void TuntapWidget::clear()
} }
void TuntapWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
QMap<QString, QString> TuntapWidget::getSettings() QMap<QString, QString> TuntapWidget::getSettings()
{ {
QMap<QString, QString> tuntapSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return tuntapSettings;
tuntapSettings[QString("Mode")] = QString("'") + ui->comboBox_mode->currentText() + QString("'"); settings[QString("Mode")] = QString("'%1'").arg(ui->comboBox_mode->currentText());
tuntapSettings[QString("User")] = QString("'") + ui->lineEdit_user->text() + QString("'"); settings[QString("User")] = QString("'%1'").arg(ui->lineEdit_user->text());
tuntapSettings[QString("Group")] = QString("'") + ui->lineEdit_group->text() + QString("'"); settings[QString("Group")] = QString("'%1'").arg(ui->lineEdit_group->text());
return tuntapSettings; return settings;
} }
int TuntapWidget::isOk() int TuntapWidget::isOk()
{ {
// empty username // empty username
if (ui->lineEdit_user->text().isEmpty()) if (ui->lineEdit_user->text().isEmpty()) return 1;
return 1;
// empty group name // empty group name
if (ui->lineEdit_group->text().isEmpty()) if (ui->lineEdit_group->text().isEmpty()) return 2;
return 2;
// all fine // all fine
return 0; return 0;
} }
@ -82,14 +70,13 @@ int TuntapWidget::isOk()
void TuntapWidget::setSettings(const QMap<QString, QString> settings) void TuntapWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> tuntapSettings = settings;
if (tuntapSettings.contains(QString("Mode"))) if (settings.contains(QString("Mode"))) {
for (int i=0; i<ui->comboBox_mode->count(); i++) int index = ui->comboBox_mode->findText(settings[QString("Mode")]);
if (tuntapSettings[QString("Mode")] == ui->comboBox_mode->itemText(i)) ui->comboBox_mode->setCurrentIndex(index);
ui->comboBox_mode->setCurrentIndex(i); }
if (tuntapSettings.contains(QString("User"))) if (settings.contains(QString("User")))
ui->lineEdit_user->setText(tuntapSettings[QString("User")]); ui->lineEdit_user->setText(settings[QString("User")]);
if (tuntapSettings.contains(QString("Group"))) if (settings.contains(QString("Group")))
ui->lineEdit_group->setText(tuntapSettings[QString("Group")]); ui->lineEdit_group->setText(settings[QString("Group")]);
} }

View File

@ -38,7 +38,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private: private:
Ui::TuntapWidget *ui; Ui::TuntapWidget *ui;

View File

@ -7,13 +7,13 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>424</width> <width>424</width>
<height>146</height> <height>108</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_tuntap"> <widget class="QDockWidget" name="dockWidget_tuntap">
<property name="features"> <property name="features">
@ -24,23 +24,35 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_tuntap"> <widget class="QWidget" name="dockWidgetContents_tuntap">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_mode"> <layout class="QHBoxLayout" name="layout_mode">
<item> <item>
<widget class="QLabel" name="label_mode"> <widget class="QLabel" name="label_mode">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Mode</string> <string>Mode</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_mode"> <widget class="QComboBox" name="comboBox_mode">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Either tun, or tap</string> <string>Either tun, or tap</string>
</property> </property>
@ -62,19 +74,28 @@
<layout class="QHBoxLayout" name="layout_user"> <layout class="QHBoxLayout" name="layout_user">
<item> <item>
<widget class="QLabel" name="label_user"> <widget class="QLabel" name="label_user">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>User</string> <string>User</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_user"> <widget class="QLineEdit" name="lineEdit_user">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The owning user of the tun/tap interface</string> <string>The owning user of the tun/tap interface</string>
</property> </property>
@ -86,19 +107,28 @@
<layout class="QHBoxLayout" name="layout_group"> <layout class="QHBoxLayout" name="layout_group">
<item> <item>
<widget class="QLabel" name="label_group"> <widget class="QLabel" name="label_group">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Group</string> <string>Group</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_group"> <widget class="QLineEdit" name="lineEdit_group">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The owning group of the tun/tap interface</string> <string>The owning group of the tun/tap interface</string>
</property> </property>

View File

@ -40,25 +40,15 @@ void VlanWidget::clear()
} }
void VlanWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
QMap<QString, QString> VlanWidget::getSettings() QMap<QString, QString> VlanWidget::getSettings()
{ {
QMap<QString, QString> vlanSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return vlanSettings;
vlanSettings[QString("VLANID")] = QString::number(ui->spinBox_vlan->value()); settings[QString("VLANID")] = QString::number(ui->spinBox_vlan->value());
return vlanSettings; return settings;
} }
@ -72,8 +62,7 @@ int VlanWidget::isOk()
void VlanWidget::setSettings(const QMap<QString, QString> settings) void VlanWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> vlanSettings = settings;
if (vlanSettings.contains(QString("VLANID"))) if (settings.contains(QString("VLANID")))
ui->spinBox_vlan->setValue(vlanSettings[QString("VLANID")].toInt()); ui->spinBox_vlan->setValue(settings[QString("VLANID")].toInt());
} }

View File

@ -38,7 +38,6 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private: private:
Ui::VlanWidget *ui; Ui::VlanWidget *ui;

View File

@ -7,13 +7,13 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>393</width> <width>393</width>
<height>81</height> <height>46</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_vlan"> <widget class="QDockWidget" name="dockWidget_vlan">
<property name="features"> <property name="features">
@ -24,23 +24,35 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_vlan"> <widget class="QWidget" name="dockWidgetContents_vlan">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_vlan"> <layout class="QHBoxLayout" name="layout_vlan">
<item> <item>
<widget class="QLabel" name="label_vlan"> <widget class="QLabel" name="label_vlan">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>vlan ID</string> <string>vlan ID</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_vlan"> <widget class="QSpinBox" name="spinBox_vlan">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>vlan identifier</string> <string>vlan identifier</string>
</property> </property>

View File

@ -0,0 +1,441 @@
/***************************************************************************
* 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 "wifimenuwidget.h"
#include "ui_wifimenuwidget.h"
#include <QDebug>
#include <QMenu>
#include <QMessageBox>
#include <pdebug/pdebug.h>
#include "calls.h"
#include "commonfunctions.h"
#include "dbusoperation.h"
#include "errorwindow.h"
#include "mainwindow.h"
#include "passwdwidget.h"
WiFiMenuWidget::WiFiMenuWidget(QWidget *parent, const QMap<QString, QString> settings, const bool debugCmd)
: QMainWindow(parent),
debug(debugCmd),
configuration(settings)
{
mainWindow = dynamic_cast<MainWindow *>(parent);
useHelper = (configuration[QString("USE_HELPER")] == QString("true"));
// windows
ui = new Ui::WiFiMenuWidget;
ui->setupUi(this);
ui->tableWidget_wifi->setColumnHidden(5, true);
ui->tableWidget_wifi->setColumnHidden(6, true);
updateToolBarState(static_cast<Qt::ToolBarArea>(configuration[QString("WIFI_TOOLBAR")].toInt()));
createActions();
}
WiFiMenuWidget::~WiFiMenuWidget()
{
if (debug) qDebug() << PDEBUG;
if (ui != nullptr) delete ui;
}
Qt::ToolBarArea WiFiMenuWidget::getToolBarArea()
{
if (debug) qDebug() << PDEBUG;
return toolBarArea(ui->toolBar);
}
void WiFiMenuWidget::update()
{
if (debug) qDebug() << PDEBUG;
updateWifiTab();
updateMenuWifi();
}
void WiFiMenuWidget::updateToolBarState(const Qt::ToolBarArea area)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Toolbar area" << area;
removeToolBar(ui->toolBar);
if (area != Qt::NoToolBarArea) {
addToolBar(area, ui->toolBar);
ui->toolBar->show();
}
}
bool WiFiMenuWidget::wifiTabSelectEssidSlot(const QString essid)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Essid" << essid;
for (int i=0; i<ui->tableWidget_wifi->rowCount(); i++) {
if (ui->tableWidget_wifi->item(i, 0)->text() != essid) continue;
ui->tableWidget_wifi->setCurrentCell(i, 0);
}
return (ui->tableWidget_wifi->currentItem() != nullptr);
}
void WiFiMenuWidget::connectToUnknownEssid(const QString passwd)
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget_wifi->currentItem() == nullptr) return;
if (passwdWid != nullptr) delete passwdWid;
QMap<QString, QString> settings;
QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 2)->text();
if (security.contains(QString("WPA")))
settings[QString("Security")] = QString("wpa");
else if (security.contains(QString("WEP")))
settings[QString("Security")] = QString("wep");
else
settings[QString("Security")] = QString("none");
if (!passwd.isEmpty())
settings[QString("Key")] = QString("'%1'").arg(passwd);
if (hiddenNetwork)
settings[QString("Hidden")] = QString("yes");
QString essid = QString("'%1'").arg(ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text());
InterfaceAnswer answer = connectToEssid(essid, settings, mainWindow->netctlInterface,
useHelper, debug);
QString profile = QString("netctl-gui-%1").arg(essid);
profile.remove(QChar('"')).remove(QChar('\''));
QString message;
if (answer == InterfaceAnswer::True) {
message = QApplication::translate("MainWindow", "Connection is successfully");
mainWindow->showMessage(true);
} else {
message = QApplication::translate("MainWindow", "Connection failed");
mainWindow->showMessage(false);
}
message += QString("\n");
message += QApplication::translate("MainWindow", "Do you want to save profile %1?").arg(profile);
int select = QMessageBox::question(this, QApplication::translate("MainWindow", "WiFi menu"),
message, QMessageBox::Save | QMessageBox::Discard, QMessageBox::Save);
switch (select) {
case QMessageBox::Save:
break;
case QMessageBox::Discard:
default:
removeProfileSlot(profile, mainWindow->netctlInterface, useHelper, debug);
break;
}
updateWifiTab();
}
void WiFiMenuWidget::setHiddenName(const QString name)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Set name" << name;
ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->setText(name);
wifiTabStart();
}
void WiFiMenuWidget::updateMenuWifi()
{
if (debug) qDebug() << PDEBUG;
bool selected = (ui->tableWidget_wifi->currentItem() != nullptr);
ui->actionStart->setEnabled(selected);
if (selected && ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 5)->text().isEmpty()) {
ui->actionStart->setText(QApplication::translate("WiFiMenuWidget", "Start"));
ui->actionStart->setIcon(QIcon::fromTheme("system-run"));
} else {
ui->actionStart->setText(QApplication::translate("WiFiMenuWidget", "Stop"));
ui->actionStart->setIcon(QIcon::fromTheme("process-stop"));
}
}
void WiFiMenuWidget::updateText(const netctlWifiInfo current)
{
if (debug) qDebug() << PDEBUG;
if (!wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug))) return;
QString text = QString("");
if (!current.macs.isEmpty()) {
text += QString("%1 - %2 - %3 ").arg(current.name).arg(current.security).arg(current.macs[0]);
text += QString("(%1 %2)").arg(current.frequencies[0]).arg(QApplication::translate("WiFiMenuWidget", "MHz"));
}
ui->label_wifi->setText(text);
}
void WiFiMenuWidget::updateWifiTab()
{
if (debug) qDebug() << PDEBUG;
if (!wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug))) return;
if (!checkExternalApps(QString("wpasup"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("wpasup"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
mainWindow->setDisabled(true);
QList<netctlWifiInfo> scanResults;
if (useHelper)
scanResults = parseOutputWifi(sendRequestToCtrl(QString("VerboseWiFi"), debug));
else
scanResults = mainWindow->wpaCommand->scanWifi();
ui->tableWidget_wifi->setSortingEnabled(false);
ui->tableWidget_wifi->selectRow(-1);
ui->tableWidget_wifi->sortByColumn(3, Qt::AscendingOrder);
ui->tableWidget_wifi->clear();
// -1 because the first is always current point
ui->tableWidget_wifi->setRowCount(scanResults.count() - 1);
// create header
QStringList headerList;
headerList.append(QApplication::translate("WiFiMenuWidget", "Name"));
headerList.append(QApplication::translate("WiFiMenuWidget", "Type"));
headerList.append(QApplication::translate("WiFiMenuWidget", "# of points"));
headerList.append(QApplication::translate("WiFiMenuWidget", "Signal"));
headerList.append(QApplication::translate("WiFiMenuWidget", "Security"));
headerList.append(QApplication::translate("WiFiMenuWidget", "Active"));
headerList.append(QApplication::translate("WiFiMenuWidget", "Exists"));
ui->tableWidget_wifi->setHorizontalHeaderLabels(headerList);
// create items
netctlWifiInfo current = scanResults.isEmpty() ? netctlWifiInfo() : scanResults.takeFirst();
for (int i=0; i<scanResults.count(); i++) {
// font
QFont font;
font.setBold(scanResults[i].active);
font.setItalic(scanResults[i].exists);
// type
QString type;
switch (scanResults[i].type) {
case PointType::TwoG:
type = QApplication::translate("WiFiMenuWidget", "2GHz");
break;
case PointType::FiveG:
type = QApplication::translate("WiFiMenuWidget", "5GHz");
break;
case PointType::TwoAndFiveG:
type = QApplication::translate("WiFiMenuWidget", "2GHz and 5GHz");
break;
case PointType::None:
default:
type = QApplication::translate("WiFiMenuWidget", "N\\A");
break;
}
// tooltip
QString toolTip = QString("");
for (int j=0; j<scanResults[i].macs.count(); j++)
toolTip += QString("%1 %2: %3 (%4 %5)\n").arg(QApplication::translate("WiFiMenuWidget", "Point"))
.arg(j + 1)
.arg(scanResults[i].macs[j])
.arg(scanResults[i].frequencies[j])
.arg(QApplication::translate("WiFiMenuWidget", "MHz"));
toolTip += QString("%1: %2\n").arg(QApplication::translate("WiFiMenuWidget", "Type"))
.arg(type);
toolTip += QString("%1: %2\n").arg(QApplication::translate("WiFiMenuWidget", "Active"))
.arg(checkStatus(scanResults[i].active));
toolTip += QString("%1: %2").arg(QApplication::translate("WiFiMenuWidget", "Exists"))
.arg(checkStatus(scanResults[i].exists));
// name
ui->tableWidget_wifi->setItem(i, 0, new QTableWidgetItem(scanResults[i].name));
ui->tableWidget_wifi->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
ui->tableWidget_wifi->item(i, 0)->setToolTip(toolTip);
ui->tableWidget_wifi->item(i, 0)->setFont(font);
// type
ui->tableWidget_wifi->setItem(i, 1, new QTableWidgetItem(type));
ui->tableWidget_wifi->item(i, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget_wifi->item(i, 1)->setToolTip(toolTip);
// count
ui->tableWidget_wifi->setItem(i, 2, new QTableWidgetItem(QString::number(scanResults[i].frequencies.count())));
ui->tableWidget_wifi->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget_wifi->item(i, 2)->setToolTip(toolTip);
// signal
ui->tableWidget_wifi->setItem(i, 3, new QTableWidgetItem(QString::number(scanResults[i].signal)));
ui->tableWidget_wifi->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget_wifi->item(i, 3)->setToolTip(toolTip);
// security
ui->tableWidget_wifi->setItem(i, 4, new QTableWidgetItem(scanResults[i].security));
ui->tableWidget_wifi->item(i, 4)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget_wifi->item(i, 4)->setToolTip(toolTip);
// active
ui->tableWidget_wifi->setItem(i, 5, new QTableWidgetItem(checkStatus(scanResults[i].active, true)));
ui->tableWidget_wifi->item(i, 5)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// exists
ui->tableWidget_wifi->setItem(i, 6, new QTableWidgetItem(checkStatus(scanResults[i].exists, true)));
ui->tableWidget_wifi->item(i, 6)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
ui->tableWidget_wifi->setSortingEnabled(true);
ui->tableWidget_wifi->resizeRowsToContents();
ui->tableWidget_wifi->resizeColumnsToContents();
ui->tableWidget_wifi->resizeRowsToContents();
#if QT_VERSION >= 0x050000
ui->tableWidget_wifi->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
ui->tableWidget_wifi->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
#endif
updateText(current);
mainWindow->setDisabled(false);
mainWindow->showMessage(true);
}
void WiFiMenuWidget::wifiTabContextualMenu(const QPoint &pos)
{
if (debug) qDebug() << PDEBUG;
if (ui->tableWidget_wifi->currentItem() == nullptr) return;
// create menu
QMenu menu(this);
QAction *refreshTable = menu.addAction(QApplication::translate("WiFiMenuWidget", "Refresh"));
refreshTable->setIcon(QIcon::fromTheme("view-refresh"));
menu.addSeparator();
QAction *startWifi = menu.addAction(QApplication::translate("WiFiMenuWidget", "Start WiFi"));
// set text
if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 5)->text().isEmpty()) {
startWifi->setText(QApplication::translate("WiFiMenuWidget", "Start WiFi"));
startWifi->setIcon(QIcon::fromTheme("system-run"));
} else {
startWifi->setText(QApplication::translate("WiFiMenuWidget", "Stop WiFi"));
startWifi->setIcon(QIcon::fromTheme("process-stop"));
}
// actions
QAction *action = menu.exec(ui->tableWidget_wifi->viewport()->mapToGlobal(pos));
if (action == refreshTable) {
if (debug) qDebug() << PDEBUG << ":" << "Refresh WiFi";
updateWifiTab();
} else if (action == startWifi) {
if (debug) qDebug() << PDEBUG << ":" << "Start WiFi";
wifiTabStart();
}
}
bool WiFiMenuWidget::wifiTabSetEnabled(const bool state)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << state;
ui->actionFunc->setEnabled(!state);
ui->tableWidget_wifi->setEnabled(state);
if (!state) ui->label_wifi->setText(QApplication::translate("WiFiMenuWidget", "Please install 'wpa_supplicant' before use it"));
return state;
}
int WiFiMenuWidget::wifiTabShowInfo()
{
if (debug) qDebug() << PDEBUG;
return QMessageBox::information(this, QApplication::translate("WiFiMenuWidget", "Information"),
QApplication::translate("WiFiMenuWidget", "This isn't the functionality you're looking for"));
}
void WiFiMenuWidget::wifiTabStart()
{
if (debug) qDebug() << PDEBUG;
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug);
return mainWindow->emitNeedToBeConfigured();
}
if (ui->tableWidget_wifi->currentItem() == nullptr) return;
mainWindow->setDisabled(true);
// name is hidden
if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text() == QString("<hidden>")) {
hiddenNetwork = true;
passwdWid = new PasswdWidget(this);
passwdWid->setPassword(false);
int widgetWidth = 2 * width() / 3;
int widgetHeight = 110;
int x = (width() - widgetWidth) / 2;
int y = (height() - widgetHeight) / 2;
passwdWid->setGeometry(x, y, widgetWidth, widgetHeight);
passwdWid->show();
passwdWid->setFocusToLineEdit();
return;
}
// name isn't hidden
hiddenNetwork = false;
QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text();
if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 6)->text().isEmpty()) {
InterfaceAnswer answer = startProfileSlot(profile, mainWindow->netctlInterface,
useHelper, debug);
mainWindow->showMessage(answer == InterfaceAnswer::True);
} else {
QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text();
if (security == QString("none")) return connectToUnknownEssid(QString(""));
else {
passwdWid = new PasswdWidget(this);
passwdWid->setPassword(true);
int widgetWidth = 2 * width() / 3;
int widgetHeight = 110;
int x = (width() - widgetWidth) / 2;
int y = (height() - widgetHeight) / 2;
passwdWid->setGeometry(x, y, widgetWidth, widgetHeight);
passwdWid->show();
passwdWid->setFocusToLineEdit();
return;
}
}
updateWifiTab();
}
void WiFiMenuWidget::createActions()
{
if (debug) qDebug() << PDEBUG;
// menu actions
connect(ui->actionFunc, SIGNAL(triggered(bool)), this, SLOT(wifiTabShowInfo()));
connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(updateWifiTab()));
connect(ui->actionStart, SIGNAL(triggered(bool)), this, SLOT(wifiTabStart()));
// wifi tab events
connect(ui->tableWidget_wifi, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(wifiTabStart()));
connect(ui->tableWidget_wifi, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
this, SLOT(updateMenuWifi()));
connect(ui->tableWidget_wifi, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(wifiTabContextualMenu(QPoint)));
}

View File

@ -0,0 +1,79 @@
/***************************************************************************
* 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 WIFIMENUWIDGET_H
#define WIFIMENUWIDGET_H
#include <QApplication>
#include <QMainWindow>
#include <netctlgui/netctlgui.h>
class MainWindow;
class PasswdWidget;
namespace Ui {
class WiFiMenuWidget;
}
class WiFiMenuWidget : public QMainWindow
{
Q_OBJECT
public:
explicit WiFiMenuWidget(QWidget *parent = 0,
const QMap<QString,QString> settings = QMap<QString,QString>(),
const bool debugCmd = false);
~WiFiMenuWidget();
Qt::ToolBarArea getToolBarArea();
public slots:
void update();
void updateToolBarState(const Qt::ToolBarArea area = Qt::TopToolBarArea);
bool wifiTabSelectEssidSlot(const QString essid);
// wifi tab slots
void connectToUnknownEssid(const QString passwd);
void setHiddenName(const QString name);
private slots:
// update slots
void updateMenuWifi();
void updateText(const netctlWifiInfo current);
void updateWifiTab();
// wifi tab slots
void wifiTabContextualMenu(const QPoint &pos);
bool wifiTabSetEnabled(const bool state);
int wifiTabShowInfo();
void wifiTabStart();
private:
// ui
MainWindow *mainWindow = nullptr;
Ui::WiFiMenuWidget *ui = nullptr;
PasswdWidget *passwdWid = nullptr;
// backend
void createActions();
bool debug = false;
bool hiddenNetwork = false;
bool useHelper = true;
// configuration
QMap<QString, QString> configuration;
};
#endif /* WIFIMENUWIDGET_H */

View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WiFiMenuWidget</class>
<widget class="QMainWindow" name="WiFiMenuWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>570</width>
<height>467</height>
</rect>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_wifi">
<property name="text">
<string>Please install 'wpa_supplicant' before using it</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget_wifi">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="columnCount">
<number>7</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string># of points</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Signal</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Security</string>
</property>
<property name="textAlignment">
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
</property>
</column>
<column/>
<column/>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>WiFi menu toolbar</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonFollowStyle</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionRefresh"/>
<addaction name="separator"/>
<addaction name="actionStart"/>
<addaction name="actionFunc"/>
</widget>
<action name="actionRefresh">
<property name="icon">
<iconset theme="view-refresh">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Refresh</string>
</property>
<property name="toolTip">
<string>Refresh table</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="actionStart">
<property name="icon">
<iconset theme="system-run">
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Start</string>
</property>
<property name="toolTip">
<string>Connect or disconnect from selected ESSID</string>
</property>
</action>
<action name="actionFunc"/>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -49,7 +49,8 @@ void WirelessWidget::clear()
ui->lineEdit_wpaConfigSection->clear(); ui->lineEdit_wpaConfigSection->clear();
ui->listWidget_wpaConfigSection->setCurrentRow(-1); ui->listWidget_wpaConfigSection->setCurrentRow(-1);
ui->listWidget_wpaConfigSection->clear(); ui->listWidget_wpaConfigSection->clear();
ui->lineEdit_wpaConfig->setText(QString("/etc/wpa_supplicant.conf")); ui->lineEdit_wpaConfig->setText(QString("/etc/wpa_supplicant/wpa_supplicant.conf"));
ui->checkBox_key->setCheckState(Qt::Unchecked);
ui->lineEdit_key->clear(); ui->lineEdit_key->clear();
ui->checkBox_hidden->setCheckState(Qt::Unchecked); ui->checkBox_hidden->setCheckState(Qt::Unchecked);
ui->checkBox_adhoc->setCheckState(Qt::Unchecked); ui->checkBox_adhoc->setCheckState(Qt::Unchecked);
@ -68,12 +69,10 @@ void WirelessWidget::clear()
if (rfkillDirectory->exists()) { if (rfkillDirectory->exists()) {
QStringList rfkillDevices = rfkillDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); QStringList rfkillDevices = rfkillDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
for (int i=0; i<rfkillDevices.count(); i++) { for (int i=0; i<rfkillDevices.count(); i++) {
QFile device(rfkillDirectory->absolutePath() + QDir::separator() + rfkillDevices[i] + QFile device(QString("%1/%2/name").arg(rfkillDirectory->absolutePath()).arg(rfkillDevices[i]));
QDir::separator() + QString("name")); if (!device.open(QIODevice::ReadOnly)) continue;
QString deviceName; ui->comboBox_rfkill->addItem(QString(device.readLine()).trimmed());
if (device.open(QIODevice::ReadOnly)) device.close();
deviceName = QString(device.readLine()).trimmed();
ui->comboBox_rfkill->addItem(deviceName);
} }
} }
ui->comboBox_rfkill->setCurrentIndex(0); ui->comboBox_rfkill->setCurrentIndex(0);
@ -85,23 +84,17 @@ void WirelessWidget::clear()
} }
void WirelessWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void WirelessWidget::createActions() void WirelessWidget::createActions()
{ {
connect(ui->pushButton_wirelessAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced())); connect(ui->pushButton_wirelessAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced()));
connect(ui->pushButton_drivers, SIGNAL(clicked(bool)), this, SLOT(addDriver())); connect(ui->pushButton_drivers, SIGNAL(clicked(bool)), this, SLOT(addDriver()));
connect(ui->pushButton_freq, SIGNAL(clicked(bool)), this, SLOT(addFreq())); connect(ui->pushButton_freq, SIGNAL(clicked(bool)), this, SLOT(addFreq()));
connect(ui->spinBox_freq, SIGNAL(editingFinished()), this, SLOT(addFreq()));
connect(ui->pushButton_wpaConfigSection, SIGNAL(clicked(bool)), this, SLOT(addOption())); connect(ui->pushButton_wpaConfigSection, SIGNAL(clicked(bool)), this, SLOT(addOption()));
connect(ui->lineEdit_wpaConfigSection, SIGNAL(returnPressed()), this, SLOT(addOption()));
connect(ui->pushButton_wpaConfig, SIGNAL(clicked(bool)), this, SLOT(selectWpaConfig())); connect(ui->pushButton_wpaConfig, SIGNAL(clicked(bool)), this, SLOT(selectWpaConfig()));
connect(ui->comboBox_security, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeSecurity(QString))); connect(ui->comboBox_security, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeSecurity(QString)));
connect(ui->checkBox_key, SIGNAL(stateChanged(int)), this, SLOT(setKeyEchoMode(int)));
} }
@ -109,13 +102,13 @@ void WirelessWidget::keyPressEvent(QKeyEvent *pressedKey)
{ {
if (pressedKey->key() == Qt::Key_Delete) { if (pressedKey->key() == Qt::Key_Delete) {
if (ui->listWidget_wpaConfigSection->hasFocus() && if (ui->listWidget_wpaConfigSection->hasFocus() &&
(ui->listWidget_wpaConfigSection->currentItem() != 0)) (ui->listWidget_wpaConfigSection->currentItem() != nullptr))
delete ui->listWidget_wpaConfigSection->currentItem(); delete ui->listWidget_wpaConfigSection->currentItem();
else if (ui->listWidget_freq->hasFocus() && else if (ui->listWidget_freq->hasFocus() &&
(ui->listWidget_freq->currentItem() != 0)) (ui->listWidget_freq->currentItem() != nullptr))
delete ui->listWidget_freq->currentItem(); delete ui->listWidget_freq->currentItem();
else if (ui->listWidget_drivers->hasFocus() && else if (ui->listWidget_drivers->hasFocus() &&
(ui->listWidget_drivers->currentItem() != 0)) (ui->listWidget_drivers->currentItem() != nullptr))
delete ui->listWidget_drivers->currentItem(); delete ui->listWidget_drivers->currentItem();
} }
} }
@ -124,11 +117,7 @@ void WirelessWidget::keyPressEvent(QKeyEvent *pressedKey)
void WirelessWidget::addDriver() void WirelessWidget::addDriver()
{ {
QString driver = ui->comboBox_drivers->currentText(); QString driver = ui->comboBox_drivers->currentText();
bool exists = false; if (ui->listWidget_drivers->findItems(driver, Qt::MatchExactly).count() == 0)
for (int i=0; i<ui->listWidget_drivers->count(); i++)
if (ui->listWidget_drivers->item(i)->text() == driver)
exists = true;
if (!exists)
ui->listWidget_drivers->addItem(driver); ui->listWidget_drivers->addItem(driver);
} }
@ -136,11 +125,7 @@ void WirelessWidget::addDriver()
void WirelessWidget::addFreq() void WirelessWidget::addFreq()
{ {
QString freq = QString::number(ui->spinBox_freq->value()); QString freq = QString::number(ui->spinBox_freq->value());
bool exists = false; if (ui->listWidget_freq->findItems(freq, Qt::MatchExactly).count() == 0)
for (int i=0; i<ui->listWidget_freq->count(); i++)
if (ui->listWidget_freq->item(i)->text() == freq)
exists = true;
if (!exists)
ui->listWidget_freq->addItem(freq); ui->listWidget_freq->addItem(freq);
} }
@ -154,35 +139,18 @@ void WirelessWidget::addOption()
void WirelessWidget::changeSecurity(const QString currentText) void WirelessWidget::changeSecurity(const QString currentText)
{ {
if (currentText == QString("none")) { ui->widget_essid->setHidden((currentText != QString("none")) &&
ui->widget_essid->setHidden(false); (currentText != QString("wep")) &&
ui->widget_wpaConfigSection->setHidden(true); (currentText != QString("wpa")));
ui->widget_wpaConfig->setHidden(true); ui->widget_key->setHidden((currentText != QString("wep")) && (currentText != QString("wpa")));
ui->widget_key->setHidden(true); ui->widget_wpaConfig->setHidden(currentText != QString("wpa-config"));
} else if ((currentText == QString("wep")) || ui->widget_wpaConfigSection->setHidden(currentText != QString("wpa-configsection"));
(currentText == QString("wpa"))) {
ui->widget_essid->setHidden(false);
ui->widget_wpaConfigSection->setHidden(true);
ui->widget_wpaConfig->setHidden(true);
ui->widget_key->setHidden(false);
} else if (currentText == QString("wpa-configsection")) {
ui->widget_essid->setHidden(true);
ui->widget_wpaConfigSection->setHidden(false);
ui->widget_wpaConfig->setHidden(true);
ui->widget_key->setHidden(true);
} else if (currentText == QString("wpa-config")) {
ui->widget_essid->setHidden(true);
ui->widget_wpaConfigSection->setHidden(true);
ui->widget_wpaConfig->setHidden(false);
ui->widget_key->setHidden(true);
}
} }
void WirelessWidget::selectWpaConfig() void WirelessWidget::selectWpaConfig()
{ {
QString filename = QFileDialog::getOpenFileName( QString filename = QFileDialog::getOpenFileName(this,
this,
QApplication::translate("EthernetWidget", "Select wpa configuration file"), QApplication::translate("EthernetWidget", "Select wpa configuration file"),
QDir::currentPath(), QDir::currentPath(),
QApplication::translate("EthernetWidget", "Configuration files (*.conf)")); QApplication::translate("EthernetWidget", "Configuration files (*.conf)"));
@ -191,74 +159,82 @@ void WirelessWidget::selectWpaConfig()
} }
void WirelessWidget::setKeyEchoMode(const int mode)
{
if (mode == 0)
ui->lineEdit_key->setEchoMode(QLineEdit::Password);
else
ui->lineEdit_key->setEchoMode(QLineEdit::Normal);
}
void WirelessWidget::showAdvanced() void WirelessWidget::showAdvanced()
{ {
if (ui->pushButton_wirelessAdvanced->isChecked()) { if (ui->pushButton_wirelessAdvanced->isChecked()) {
ui->widget_wirelessAdvanced->setHidden(false); ui->widget_wirelessAdvanced->setHidden(false);
ui->pushButton_wirelessAdvanced->setText(QApplication::translate("WirelessWidget", "Hide advanced")); ui->pushButton_wirelessAdvanced->setArrowType(Qt::UpArrow);
} else { } else {
ui->widget_wirelessAdvanced->setHidden(true); ui->widget_wirelessAdvanced->setHidden(true);
ui->pushButton_wirelessAdvanced->setText(QApplication::translate("WirelessWidget", "Show advanced")); ui->pushButton_wirelessAdvanced->setArrowType(Qt::DownArrow);
} }
} }
QMap<QString, QString> WirelessWidget::getSettings() QMap<QString, QString> WirelessWidget::getSettings()
{ {
QMap<QString, QString> wirelessSettings; QMap<QString, QString> settings;
if (isOk() != 0) if (isOk() != 0) return settings;
return wirelessSettings;
wirelessSettings[QString("Security")] = ui->comboBox_security->currentText(); settings[QString("Security")] = ui->comboBox_security->currentText();
wirelessSettings[QString("ESSID")] = QString("'") + ui->lineEdit_essid->text() + QString("'"); settings[QString("ESSID")] = QString("'%1'").arg(ui->lineEdit_essid->text());
if (ui->comboBox_security->currentText() == QString("wep")) { if (ui->comboBox_security->currentText() == QString("wep")) {
if (ui->lineEdit_key->text().indexOf(QString("\\\"")) == 0) if (ui->lineEdit_key->text().indexOf(QString("\\\"")) == 0)
wirelessSettings[QString("Key")] = ui->lineEdit_key->text(); settings[QString("Key")] = ui->lineEdit_key->text();
else else
wirelessSettings[QString("Key")] = QString("'") + ui->lineEdit_key->text() + QString("'"); settings[QString("Key")] = QString("'%1'").arg(ui->lineEdit_key->text());
} else if (ui->comboBox_security->currentText() == QString("wpa")) } else if (ui->comboBox_security->currentText() == QString("wpa"))
wirelessSettings[QString("Key")] = QString("'") + ui->lineEdit_key->text() + QString("'"); settings[QString("Key")] = QString("'%1'").arg(ui->lineEdit_key->text());
if (ui->comboBox_security->currentText() == QString("wpa-configsection")) { if (ui->comboBox_security->currentText() == QString("wpa-configsection")) {
QStringList section; QStringList section;
for (int i=0; i<ui->listWidget_wpaConfigSection->count(); i++) for (int i=0; i<ui->listWidget_wpaConfigSection->count(); i++)
section.append(QString("'") + ui->listWidget_wpaConfigSection->item(i)->text() + QString("'")); section.append(QString("'%1'").arg(ui->listWidget_wpaConfigSection->item(i)->text()));
wirelessSettings[QString("WPAConfigSection")] = QString("\n") + section.join(QChar('\n')) + QString("\n"); settings[QString("WPAConfigSection")] = QString("\n%1\n").arg(section.join(QChar('\n')));
} }
if (ui->comboBox_security->currentText() == QString("wpa-config")) if (ui->comboBox_security->currentText() == QString("wpa-config"))
wirelessSettings[QString("WPAConfigFile")] = QString("'") + ui->lineEdit_wpaConfig->text() + QString("'"); settings[QString("WPAConfigFile")] = QString("'%1'").arg(ui->lineEdit_wpaConfig->text());
if (ui->checkBox_hidden->checkState() == Qt::Checked) if (ui->checkBox_hidden->checkState() == Qt::Checked)
wirelessSettings[QString("Hidden")] = QString("yes"); settings[QString("Hidden")] = QString("yes");
if (ui->checkBox_adhoc->checkState() == Qt::Checked) if (ui->checkBox_adhoc->checkState() == Qt::Checked)
wirelessSettings[QString("AdHoc")] = QString("yes"); settings[QString("AdHoc")] = QString("yes");
if (ui->listWidget_freq->count() != 0) { if (ui->listWidget_freq->count() != 0) {
QStringList freqs; QStringList freqs;
for (int i=0; i<ui->listWidget_freq->count(); i++) for (int i=0; i<ui->listWidget_freq->count(); i++)
freqs.append(ui->listWidget_freq->item(i)->text()); freqs.append(ui->listWidget_freq->item(i)->text());
wirelessSettings[QString("ScanFrequencies")] = freqs.join(QChar(' ')); settings[QString("ScanFrequencies")] = freqs.join(QChar(' '));
} }
if (ui->spinBox_frequency->value() != 2000) if (ui->spinBox_frequency->value() != 2000)
wirelessSettings[QString("Frequency")] = QString::number(ui->spinBox_frequency->value()); settings[QString("Frequency")] = QString::number(ui->spinBox_frequency->value());
if (ui->spinBox_priority->value() != 0) if (ui->spinBox_priority->value() != 0)
wirelessSettings[QString("Priority")] = QString::number(ui->spinBox_priority->value()); settings[QString("Priority")] = QString::number(ui->spinBox_priority->value());
if (!ui->lineEdit_country->text().isEmpty()) if (!ui->lineEdit_country->text().isEmpty())
wirelessSettings[QString("Country")] = QString("'") + ui->lineEdit_country->text() + QString("'"); settings[QString("Country")] = QString("'%1'").arg(ui->lineEdit_country->text());
if (ui->lineEdit_wpaGroup->text() != QString("wheel")) if (ui->lineEdit_wpaGroup->text() != QString("wheel"))
wirelessSettings[QString("WPAGroup")] = QString("'") + ui->lineEdit_wpaGroup->text() + QString("'"); settings[QString("WPAGroup")] = QString("'%1'").arg(ui->lineEdit_wpaGroup->text());
if (ui->listWidget_drivers->count() != 0) { if (ui->listWidget_drivers->count() != 0) {
QStringList drivers; QStringList drivers;
for (int i=0; i<ui->listWidget_drivers->count(); i++) for (int i=0; i<ui->listWidget_drivers->count(); i++)
drivers.append(ui->listWidget_drivers->item(i)->text()); drivers.append(ui->listWidget_drivers->item(i)->text());
wirelessSettings[QString("WPADriver")] = QString("'") + drivers.join(QChar(',')) + QString("'"); settings[QString("WPADriver")] = QString("'%1'").arg(drivers.join(QChar(',')));
} }
if (ui->comboBox_rfkill->currentText() != QString("auto")) if (ui->comboBox_rfkill->currentText() != QString("auto"))
wirelessSettings[QString("RFKill")] = ui->comboBox_rfkill->currentText(); settings[QString("RFKill")] = ui->comboBox_rfkill->currentText();
if (ui->spinBox_timeoutWpa->value() != 15) if (ui->spinBox_timeoutWpa->value() != 15)
wirelessSettings[QString("TimeoutWPA")] = QString::number(ui->spinBox_timeoutWpa->value()); settings[QString("TimeoutWPA")] = QString::number(ui->spinBox_timeoutWpa->value());
if (ui->checkBox_exclude->checkState() == Qt::Checked) if (ui->checkBox_exclude->checkState() == Qt::Checked)
wirelessSettings[QString("ExcludeAuto")] = QString("yes"); settings[QString("ExcludeAuto")] = QString("yes");
return wirelessSettings; return settings;
} }
@ -266,27 +242,22 @@ int WirelessWidget::isOk()
{ {
// empty key // empty key
if ((ui->comboBox_security->currentText() == QString("wep")) || if ((ui->comboBox_security->currentText() == QString("wep")) ||
(ui->comboBox_security->currentText() == QString("wpa"))) (ui->comboBox_security->currentText() == QString("wpa")))
if (ui->lineEdit_key->text().isEmpty()) if (ui->lineEdit_key->text().isEmpty()) return 1;
return 1;
// empty settings // empty settings
if (ui->comboBox_security->currentText() == QString("wpa-configsection")) if (ui->comboBox_security->currentText() == QString("wpa-configsection"))
if (ui->listWidget_wpaConfigSection->count() == 0) if (ui->listWidget_wpaConfigSection->count() == 0) return 2;
return 2;
// file is not set // file is not set
if (ui->comboBox_security->currentText() == QString("wpa-config")) if (ui->comboBox_security->currentText() == QString("wpa-config"))
if (ui->lineEdit_wpaConfig->text().isEmpty()) if (ui->lineEdit_wpaConfig->text().isEmpty()) return 3;
return 3;
// file wpa_supplicant doesn't exists // file wpa_supplicant doesn't exists
if (ui->comboBox_security->currentText() == QString("wpa-config")) if (ui->comboBox_security->currentText() == QString("wpa-config"))
if (!QFile(ui->lineEdit_wpaConfig->text()).exists()) if (!QFile(ui->lineEdit_wpaConfig->text()).exists()) return 4;
return 4;
// essid is not set // essid is not set
if ((ui->comboBox_security->currentText() == QString("none")) || if ((ui->comboBox_security->currentText() == QString("none")) ||
(ui->comboBox_security->currentText() == QString("wep")) || (ui->comboBox_security->currentText() == QString("wep")) ||
(ui->comboBox_security->currentText() == QString("wpa"))) (ui->comboBox_security->currentText() == QString("wpa")))
if (ui->lineEdit_essid->text().isEmpty()) if (ui->lineEdit_essid->text().isEmpty()) return 5;
return 5;
// all fine // all fine
return 0; return 0;
} }
@ -295,52 +266,52 @@ int WirelessWidget::isOk()
void WirelessWidget::setSettings(const QMap<QString, QString> settings) void WirelessWidget::setSettings(const QMap<QString, QString> settings)
{ {
clear(); clear();
QMap<QString, QString> wirelessSettings = settings;
if (wirelessSettings.contains(QString("Security"))) if (settings.contains(QString("Security"))) {
for (int i=0; i<ui->comboBox_security->count(); i++) int index = ui->comboBox_security->findText(settings[QString("Security")]);
if (wirelessSettings[QString("Security")] == ui->comboBox_security->itemText(i)) ui->comboBox_security->setCurrentIndex(index);
ui->comboBox_security->setCurrentIndex(i);
if (wirelessSettings.contains(QString("ESSID")))
ui->lineEdit_essid->setText(wirelessSettings[QString("ESSID")]);
if (wirelessSettings.contains(QString("Key"))) {
// workaround for wireless-wep example
if (wirelessSettings.contains(QString("Security")))
if ((wirelessSettings[QString("Security")] == QString("wep")) &&
(wirelessSettings[QString("Key")][0] == QChar('"')))
wirelessSettings[QString("Key")] = QChar('\\') + wirelessSettings[QString("Key")];
ui->lineEdit_key->setText(wirelessSettings[QString("Key")]);
} }
if (wirelessSettings.contains(QString("WPAConfigSection"))) if (settings.contains(QString("ESSID")))
ui->listWidget_wpaConfigSection->addItems(wirelessSettings[QString("WPAConfigSection")].split(QChar('\n'))); ui->lineEdit_essid->setText(settings[QString("ESSID")]);
if (wirelessSettings.contains(QString("WPAConfigFile"))) if (settings.contains(QString("Key"))) {
ui->lineEdit_wpaConfig->setText(wirelessSettings[QString("WPAConfigFile")]); QString key = settings[QString("Key")];
if (wirelessSettings.contains(QString("Hidden"))) // workaround for wireless-wep example
if (wirelessSettings[QString("Hidden")] == QString("yes")) if (settings.contains(QString("Security")))
if ((settings[QString("Security")] == QString("wep")) &&
(key[0] == QChar('"')))
key = QChar('\\') + key;
ui->lineEdit_key->setText(key);
}
if (settings.contains(QString("WPAConfigSection")))
ui->listWidget_wpaConfigSection->addItems(settings[QString("WPAConfigSection")].split(QChar('\n')));
if (settings.contains(QString("WPAConfigFile")))
ui->lineEdit_wpaConfig->setText(settings[QString("WPAConfigFile")]);
if (settings.contains(QString("Hidden")))
if (settings[QString("Hidden")] == QString("yes"))
ui->checkBox_hidden->setCheckState(Qt::Checked); ui->checkBox_hidden->setCheckState(Qt::Checked);
if (wirelessSettings.contains(QString("AdHoc"))) if (settings.contains(QString("AdHoc")))
if (wirelessSettings[QString("AdHoc")] == QString("yes")) if (settings[QString("AdHoc")] == QString("yes"))
ui->checkBox_adhoc->setCheckState(Qt::Checked); ui->checkBox_adhoc->setCheckState(Qt::Checked);
if (wirelessSettings.contains(QString("ScanFrequencies"))) if (settings.contains(QString("ScanFrequencies")))
ui->listWidget_freq->addItems(wirelessSettings[QString("ScanFrequencies")].split(QChar('\n'))); ui->listWidget_freq->addItems(settings[QString("ScanFrequencies")].split(QChar('\n')));
if (wirelessSettings.contains(QString("Frequency"))) if (settings.contains(QString("Frequency")))
ui->spinBox_frequency->setValue(wirelessSettings[QString("Frequency")].toInt()); ui->spinBox_frequency->setValue(settings[QString("Frequency")].toInt());
if (wirelessSettings.contains(QString("Priority"))) if (settings.contains(QString("Priority")))
ui->spinBox_priority->setValue(wirelessSettings[QString("Priority")].toInt()); ui->spinBox_priority->setValue(settings[QString("Priority")].toInt());
if (wirelessSettings.contains(QString("Country"))) if (settings.contains(QString("Country")))
ui->lineEdit_country->setText(wirelessSettings[QString("Country")]); ui->lineEdit_country->setText(settings[QString("Country")]);
if (wirelessSettings.contains(QString("WPAGroup"))) if (settings.contains(QString("WPAGroup")))
ui->lineEdit_wpaGroup->setText(wirelessSettings[QString("WPAGroup")]); ui->lineEdit_wpaGroup->setText(settings[QString("WPAGroup")]);
if (wirelessSettings.contains(QString("WPADriver"))) if (settings.contains(QString("WPADriver")))
ui->listWidget_drivers->addItems(wirelessSettings[QString("WPADriver")].split(QChar(','))); ui->listWidget_drivers->addItems(settings[QString("WPADriver")].split(QChar(',')));
if (wirelessSettings.contains(QString("RFKill"))) if (settings.contains(QString("RFKill"))) {
for (int i=0; i<ui->comboBox_rfkill->count(); i++) int index = ui->comboBox_rfkill->findText(settings[QString("RFKill")]);
if (wirelessSettings[QString("RFKill")] == ui->comboBox_rfkill->itemText(i)) ui->comboBox_rfkill->setCurrentIndex(index);
ui->comboBox_rfkill->setCurrentIndex(i); }
if (wirelessSettings.contains(QString("TimeoutWPA"))) if (settings.contains(QString("TimeoutWPA")))
ui->spinBox_timeoutWpa->setValue(wirelessSettings[QString("TimeoutWPA")].toInt()); ui->spinBox_timeoutWpa->setValue(settings[QString("TimeoutWPA")].toInt());
if (wirelessSettings.contains(QString("ExcludeAuto"))) if (settings.contains(QString("ExcludeAuto")))
if (wirelessSettings[QString("ExcludeAuto")] == QString("yes")) if (settings[QString("ExcludeAuto")] == QString("yes"))
ui->checkBox_exclude->setCheckState(Qt::Checked); ui->checkBox_exclude->setCheckState(Qt::Checked);
changeSecurity(ui->comboBox_security->currentText()); changeSecurity(ui->comboBox_security->currentText());

View File

@ -41,13 +41,13 @@ public:
public slots: public slots:
void clear(); void clear();
void setShown(const bool state);
private slots: private slots:
void addDriver(); void addDriver();
void addFreq(); void addFreq();
void addOption(); void addOption();
void changeSecurity(const QString currentText); void changeSecurity(const QString currentText);
void setKeyEchoMode(const int mode);
void showAdvanced(); void showAdvanced();
void selectWpaConfig(); void selectWpaConfig();

View File

@ -6,14 +6,14 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>431</width> <width>584</width>
<height>776</height> <height>697</height>
</rect> </rect>
</property> </property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QDockWidget" name="dockWidget_wireless"> <widget class="QDockWidget" name="dockWidget_wireless">
<property name="features"> <property name="features">
@ -24,23 +24,35 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents_wireless"> <widget class="QWidget" name="dockWidgetContents_wireless">
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_security"> <layout class="QHBoxLayout" name="layout_security">
<item> <item>
<widget class="QLabel" name="label_security"> <widget class="QLabel" name="label_security">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Security</string> <string>Security</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_security"> <widget class="QComboBox" name="comboBox_security">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>none</string> <string>none</string>
@ -73,21 +85,33 @@
<item> <item>
<widget class="QWidget" name="widget_essid" native="true"> <widget class="QWidget" name="widget_essid" native="true">
<layout class="QHBoxLayout" name="layout_essid"> <layout class="QHBoxLayout" name="layout_essid">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="label_essid"> <widget class="QLabel" name="label_essid">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>ESSID</string> <string>ESSID</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_essid"> <widget class="QLineEdit" name="lineEdit_essid">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The name of the network to connect to</string> <string>The name of the network to connect to</string>
</property> </property>
@ -99,26 +123,45 @@
<item> <item>
<widget class="QWidget" name="widget_wpaConfigSection" native="true"> <widget class="QWidget" name="widget_wpaConfigSection" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="layout_wpaConfigSection"> <layout class="QHBoxLayout" name="layout_wpaConfigSection">
<item> <item>
<widget class="QLabel" name="label_wpaConfigSection"> <widget class="QLabel" name="label_wpaConfigSection">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Wpa config section</string> <string>Wpa config section</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_wpaConfigSection"/> <widget class="QLineEdit" name="lineEdit_wpaConfigSection">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_wpaConfigSection"> <widget class="QPushButton" name="pushButton_wpaConfigSection">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Add</string> <string>Add</string>
</property> </property>
@ -145,21 +188,33 @@
<item> <item>
<widget class="QWidget" name="widget_wpaConfig" native="true"> <widget class="QWidget" name="widget_wpaConfig" native="true">
<layout class="QHBoxLayout" name="layout_wpaConfigFile"> <layout class="QHBoxLayout" name="layout_wpaConfigFile">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="label_wpaConfig"> <widget class="QLabel" name="label_wpaConfig">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Wpa config file</string> <string>Wpa config file</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_wpaConfig"> <widget class="QLineEdit" name="lineEdit_wpaConfig">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Path to a wpa_supplicant configuration file</string> <string>Path to a wpa_supplicant configuration file</string>
</property> </property>
@ -167,6 +222,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_wpaConfig"> <widget class="QPushButton" name="pushButton_wpaConfig">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Browse</string> <string>Browse</string>
</property> </property>
@ -178,13 +239,19 @@
<item> <item>
<widget class="QWidget" name="widget_key" native="true"> <widget class="QWidget" name="widget_key" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="label_key"> <widget class="QCheckBox" name="checkBox_key">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property> </property>
<property name="text"> <property name="text">
<string>Key</string> <string>Key</string>
@ -193,34 +260,23 @@
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_key"> <widget class="QLineEdit" name="lineEdit_key">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The secret key to a WEP, or WPA encrypted network</string> <string>The secret key to a WEP, or WPA encrypted network</string>
</property> </property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBox_hidden">
<property name="toolTip">
<string>Whether or not the specified network is a hidden network</string>
</property>
<property name="text">
<string>Hidden</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_adhoc">
<property name="toolTip">
<string>Whether or not to use ad-hoc mode</string>
</property>
<property name="text">
<string>Ad-hoc</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="layout_wirelessAdvanced"> <layout class="QHBoxLayout" name="layout_wirelessAdvanced">
<item> <item>
@ -237,13 +293,16 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_wirelessAdvanced"> <widget class="QToolButton" name="pushButton_wirelessAdvanced">
<property name="text">
<string>Show advanced</string>
</property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -251,25 +310,127 @@
<item> <item>
<widget class="QWidget" name="widget_wirelessAdvanced" native="true"> <widget class="QWidget" name="widget_wirelessAdvanced" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="layout_exclude">
<item>
<widget class="QLabel" name="label_exclude">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_exclude">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Whether or not to exclude this profile from automatic profile selection</string>
</property>
<property name="text">
<string>Exclude auto</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_hidden">
<item>
<widget class="QLabel" name="label_hidden">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_hidden">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Whether or not the specified network is a hidden network</string>
</property>
<property name="text">
<string>Hidden</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_adhoc">
<item>
<widget class="QLabel" name="label_adhoc">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_adhoc">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Whether or not to use ad-hoc mode</string>
</property>
<property name="text">
<string>Ad-hoc</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QVBoxLayout" name="layout_freq"> <layout class="QVBoxLayout" name="layout_freq">
<item> <item>
<layout class="QHBoxLayout" name="layout_freqLine"> <layout class="QHBoxLayout" name="layout_freqLine">
<item> <item>
<widget class="QLabel" name="label_freq"> <widget class="QLabel" name="label_freq">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Scan frequencies</string> <string>Scan frequencies</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_freq"> <widget class="QSpinBox" name="spinBox_freq">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum"> <property name="minimum">
<number>2000</number> <number>2000</number>
</property> </property>
@ -283,6 +444,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_freq"> <widget class="QPushButton" name="pushButton_freq">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Add</string> <string>Add</string>
</property> </property>
@ -309,19 +476,28 @@
<layout class="QHBoxLayout" name="layout_frequency"> <layout class="QHBoxLayout" name="layout_frequency">
<item> <item>
<widget class="QLabel" name="label_frequency"> <widget class="QLabel" name="label_frequency">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Frequency</string> <string>Frequency</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_frequency"> <widget class="QSpinBox" name="spinBox_frequency">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Priority group for the network</string> <string>Priority group for the network</string>
</property> </property>
@ -339,19 +515,28 @@
<layout class="QHBoxLayout" name="layout_priority"> <layout class="QHBoxLayout" name="layout_priority">
<item> <item>
<widget class="QLabel" name="label_priority"> <widget class="QLabel" name="label_priority">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Priority</string> <string>Priority</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_priority"> <widget class="QSpinBox" name="spinBox_priority">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Priority group for the network</string> <string>Priority group for the network</string>
</property> </property>
@ -363,19 +548,28 @@
<layout class="QHBoxLayout" name="layout_country"> <layout class="QHBoxLayout" name="layout_country">
<item> <item>
<widget class="QLabel" name="label_country"> <widget class="QLabel" name="label_country">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Country</string> <string>Country</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_country"> <widget class="QLineEdit" name="lineEdit_country">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The country for which frequency regulations will be enforced</string> <string>The country for which frequency regulations will be enforced</string>
</property> </property>
@ -387,19 +581,28 @@
<layout class="QHBoxLayout" name="layourt_wpaGroup"> <layout class="QHBoxLayout" name="layourt_wpaGroup">
<item> <item>
<widget class="QLabel" name="label_wpaGroup"> <widget class="QLabel" name="label_wpaGroup">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>WPA group</string> <string>WPA group</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_wpaGroup"> <widget class="QLineEdit" name="lineEdit_wpaGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Group that has the authority to configure wpa_supplicant via its control interface</string> <string>Group that has the authority to configure wpa_supplicant via its control interface</string>
</property> </property>
@ -413,19 +616,28 @@
<layout class="QHBoxLayout" name="layout_driversLine"> <layout class="QHBoxLayout" name="layout_driversLine">
<item> <item>
<widget class="QLabel" name="label_drivers"> <widget class="QLabel" name="label_drivers">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>7</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Drivers</string> <string>Drivers</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_drivers"> <widget class="QComboBox" name="comboBox_drivers">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>west</string> <string>west</string>
@ -445,6 +657,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_drivers"> <widget class="QPushButton" name="pushButton_drivers">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Add</string> <string>Add</string>
</property> </property>
@ -471,19 +689,28 @@
<layout class="QHBoxLayout" name="layout_rfkill"> <layout class="QHBoxLayout" name="layout_rfkill">
<item> <item>
<widget class="QLabel" name="label_rfkill"> <widget class="QLabel" name="label_rfkill">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>RFkill device</string> <string>RFkill device</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_rfkill"> <widget class="QComboBox" name="comboBox_rfkill">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The name of an rfkill device</string> <string>The name of an rfkill device</string>
</property> </property>
@ -495,19 +722,28 @@
<layout class="QHBoxLayout" name="layout_timeoutWpa"> <layout class="QHBoxLayout" name="layout_timeoutWpa">
<item> <item>
<widget class="QLabel" name="label_timeoutWpa"> <widget class="QLabel" name="label_timeoutWpa">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<width>150</width> <horstretch>1</horstretch>
<height>0</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Timeout WPA</string> <string>Timeout WPA</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_timeoutWpa"> <widget class="QSpinBox" name="spinBox_timeoutWpa">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Maximum time, in seconds, to wait for steps in the association and authentication to succeed</string> <string>Maximum time, in seconds, to wait for steps in the association and authentication to succeed</string>
</property> </property>
@ -521,16 +757,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="checkBox_exclude">
<property name="toolTip">
<string>Whether or not to exclude this profile from automatic profile selection</string>
</property>
<property name="text">
<string>Exclude auto</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -549,9 +775,6 @@
<tabstop>lineEdit_wpaConfig</tabstop> <tabstop>lineEdit_wpaConfig</tabstop>
<tabstop>pushButton_wpaConfig</tabstop> <tabstop>pushButton_wpaConfig</tabstop>
<tabstop>lineEdit_key</tabstop> <tabstop>lineEdit_key</tabstop>
<tabstop>checkBox_hidden</tabstop>
<tabstop>checkBox_adhoc</tabstop>
<tabstop>pushButton_wirelessAdvanced</tabstop>
<tabstop>spinBox_freq</tabstop> <tabstop>spinBox_freq</tabstop>
<tabstop>pushButton_freq</tabstop> <tabstop>pushButton_freq</tabstop>
<tabstop>listWidget_freq</tabstop> <tabstop>listWidget_freq</tabstop>
@ -564,7 +787,6 @@
<tabstop>listWidget_drivers</tabstop> <tabstop>listWidget_drivers</tabstop>
<tabstop>comboBox_rfkill</tabstop> <tabstop>comboBox_rfkill</tabstop>
<tabstop>spinBox_timeoutWpa</tabstop> <tabstop>spinBox_timeoutWpa</tabstop>
<tabstop>checkBox_exclude</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -1,63 +1,79 @@
# Configuration file for Netctl GUI project # Configuration file for Netctl GUI project
# man 5 netctl-gui.conf
# /etc/netctl-gui.conf - system-wide configuration # /etc/netctl-gui.conf - system-wide configuration
# $HOME/.config/netctl-gui.conf - user configuration # $HOME/.config/netctl-gui.conf - user configuration
[Common]
# application language
LANGUAGE=en
# create system tray icon.
# This option is not recognized by netctlgui-helper
SYSTRAY=true
# close helper after GUI application quit. # close helper after GUI application quit.
# This option is not recognized by netctlgui-helper # This option is not recognized by netctlgui-helper
CLOSETOTRAY=true CLOSETOTRAY=true
# start netctl-gui minimized to tray if it is available.
# This option is not recognized by netctlgui-helper
STARTTOTRAY=false
# skip external components checking
# This option is not recognized by netctlgui-helper
SKIPCOMPONENTS=false
[Helper]
# use netctlgui-helper if it is available.
# This option is not recognized by netctlgui-helper
USE_HELPER=true
# force use SUDO_PATH for helper instead of using setuid(3) to child processes
FORCE_SUDO=false
# hide application to tray on exit if tray is available. # hide application to tray on exit if tray is available.
# This option is not recognized by netctlgui-helper # This option is not recognized by netctlgui-helper
CLOSE_HELPER=false CLOSE_HELPER=false
# path to control directory which is required by wpa_supplicant
CTRL_DIR=/run/wpa_supplicant_netctl-gui
# group which is owner of CTRL_DIR
CTRL_GROUP=users
# force use SUDO_PATH for helper instead of using setuid(3) to child processes
FORCE_SUDO=false
# path to netctlgui-helper. # path to netctlgui-helper.
# This option is not recognized by netctlgui-helper # This option is not recognized by netctlgui-helper
HELPER_PATH=/usr/bin/netctlgui-helper HELPER_PATH=/usr/bin/netctlgui-helper
# netctlgui-helper service name. # netctlgui-helper service name.
# This option is not recognized by netctlgui-helper # This option is not recognized by netctlgui-helper
HELPER_SERVICE=netctlgui-helper.service HELPER_SERVICE=netctlgui-helper.service
# path to directory which contains interface information
IFACE_DIR=/sys/class/net/ [netctl]
# application language # path to systemctl
LANGUAGE=en SYSTEMCTL_PATH=/usr/bin/systemctl
# path to netctl
NETCTL_PATH=/usr/bin/netctl
# path to netctl-auto # path to netctl-auto
NETCTLAUTO_PATH=/usr/bin/netctl-auto NETCTLAUTO_PATH=/usr/bin/netctl-auto
# netctl-auto service name without .service suffix # netctl-auto service name without .service suffix
NETCTLAUTO_SERVICE=netctl-auto NETCTLAUTO_SERVICE=netctl-auto
# path to netctl
NETCTL_PATH=/usr/bin/netctl
# wpa_supplicant PID file
PID_FILE=/run/wpa_supplicant_netctl-gui.pid
# prefered wireless interface
PREFERED_IFACE=
# path to netctl profile directory # path to netctl profile directory
PROFILE_DIR=/etc/netctl/ PROFILE_DIR=/etc/netctl/
[sudo]
# path to sudo frontend
SUDO_PATH=/usr/bin/sudo
[wpa_supplicant]
# path to wpa_supplicant
WPASUP_PATH=/usr/bin/wpa_supplicant
# path to wpa_cli
WPACLI_PATH=/usr/bin/wpa_cli
# wpa_supplicant PID file
# $i is interface
PID_FILE=/run/wpa_supplicant_$i.pid
# wpa_supplicant drivers for wireless interface comma separated
WPA_DRIVERS=nl80211,wext
# path to control directory which is required by wpa_supplicant
CTRL_DIR=/run/wpa_supplicant
# group which is owner of CTRL_DIR
CTRL_GROUP=users
[Other]
# path to external editor
# This option is not recognized by netctlgui-helper
EDITOR_PATH=/usr/bin/gvim
# path to directory which contains interface information
IFACE_DIR=/sys/class/net/
# path to directory with rfkill devices. # path to directory with rfkill devices.
# This option is not recognized by netctlgui-helper # This option is not recognized by netctlgui-helper
RFKILL_DIR=/sys/class/rfkill/ RFKILL_DIR=/sys/class/rfkill/
# skip external components checking # prefered wireless interface
# This option is not recognized by netctlgui-helper PREFERED_IFACE=
SKIPCOMPONENTS=false
# start netctl-gui minimized to tray if it is available.
# This option is not recognized by netctlgui-helper
STARTTOTRAY=false
# path to sudo frontend
SUDO_PATH=/usr/bin/sudo
# path to systemctl
SYSTEMCTL_PATH=/usr/bin/systemctl
# create system tray icon.
# This option is not recognized by netctlgui-helper
SYSTRAY=true
# use netctlgui-helper if it is available.
# This option is not recognized by netctlgui-helper
USE_HELPER=true
# path to wpa_cli
WPACLI_PATH=/usr/bin/wpa_cli
# path to wpa_supplicant
WPASUP_PATH=/usr/bin/wpa_supplicant
# wpa_supplicant drivers for wireless interface comma separated
WPA_DRIVERS=nl80211,wext

View File

@ -20,7 +20,7 @@ close helper after GUI application quit. This option is not recognized by
.IP "CLOSETOTRAY=true" .IP "CLOSETOTRAY=true"
hide application to tray on exit if tray is available. This option is not recognized by hide application to tray on exit if tray is available. This option is not recognized by
.BR netctlgui-helper (1) .BR netctlgui-helper (1)
.IP "CTRL_DIR=/run/wpa_supplicant_netctl-gui" .IP "CTRL_DIR=/run/wpa_supplicant"
path to control directory which is required by path to control directory which is required by
.BR wpa_supplicant (8) .BR wpa_supplicant (8)
.IP "CTRL_GROUP=users" .IP "CTRL_GROUP=users"
@ -32,6 +32,9 @@ force use
for helper instead of using for helper instead of using
.BR setuid (3) .BR setuid (3)
to child processes to child processes
.IP "EDITOR_PATH=/usr/bin/gvim"
path to an external editor. This option is not recognized by
.BR netctlgui-helper (1)
.IP "HELPER_PATH=/usr/bin/netctlgui-helper" .IP "HELPER_PATH=/usr/bin/netctlgui-helper"
path to path to
.BR netctlgui-helper (1) .BR netctlgui-helper (1)
@ -56,7 +59,7 @@ path to
service name without service name without
.I .service .I .service
suffix suffix
.IP "PID_FILE=/run/wpa_supplicant_netctl-gui.pid" .IP "PID_FILE=/run/wpa_supplicant_$i.pid"
.BR wpa_supplicant (8) .BR wpa_supplicant (8)
PID file PID file
.IP "PREFERED_IFACE=" .IP "PREFERED_IFACE="

View File

@ -1,6 +1,7 @@
# set files # set files
file (GLOB_RECURSE SOURCES *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp file (GLOB_RECURSE SOURCES *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp
${PROJECT_TRDPARTY_DIR}/language/*.cpp) ${PROJECT_TRDPARTY_DIR}/language/*.cpp
${PROJECT_TRDPARTY_DIR}/listmap/*.cpp)
file (GLOB_RECURSE HEADERS *.h ${PROJECT_TRDPARTY_DIR}/task/*.h file (GLOB_RECURSE HEADERS *.h ${PROJECT_TRDPARTY_DIR}/task/*.h
${PROJECT_TRDPARTY_DIR}/language/*.h) ${PROJECT_TRDPARTY_DIR}/language/*.h)
@ -17,38 +18,38 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/includ
link_directories (${PROJECT_LIBRARY}/src/lib) link_directories (${PROJECT_LIBRARY}/src/lib)
if (USE_QT5) if (USE_QT5)
find_package(Qt5 COMPONENTS Core DBus LinguistTools REQUIRED) find_package (Qt5 COMPONENTS Core DBus LinguistTools REQUIRED)
add_definitions(${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5LinguistTools_DEFINITIONS}) add_definitions (${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5LinguistTools_DEFINITIONS})
include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS})
set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES}) set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES})
qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) qt5_wrap_cpp (MOC_SOURCES ${HEADERS})
qt5_add_resources (QRC_SOURCES ${RESOURCES}) qt5_add_resources (QRC_SOURCES ${RESOURCES})
foreach (LANGUAGE ${LANGUAGES}) foreach (LANGUAGE ${LANGUAGES})
set (TS ${LANGUAGE}) set (TS ${LANGUAGE})
string (REPLACE ".ts" ".qm" QM ${TS}) string (REPLACE ".ts" ".qm" QM ${TS})
set (TRANSLATIONS ${TRANSLATIONS} ${TS}) set (TRANSLATIONS ${TRANSLATIONS} ${TS})
set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM}) set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM})
add_custom_command (OUTPUT ${QM} COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS}) add_custom_command (OUTPUT ${QM} COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS})
endforeach () endforeach ()
add_custom_target (translations-helper COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} -ts ${TRANSLATIONS}) add_custom_target (translations-helper COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} -ts ${TRANSLATIONS})
add_custom_command (TARGET translations-helper COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TRANSLATIONS}) add_custom_command (TARGET translations-helper COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${TRANSLATIONS})
else () else ()
find_package (Qt4 COMPONENTS QtCore QtDBus REQUIRED) find_package (Qt4 COMPONENTS QtCore QtDBus REQUIRED)
include (${QT_USE_FILE}) include (${QT_USE_FILE})
set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY}) set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY})
qt4_wrap_cpp (MOC_SOURCES ${HEADERS}) qt4_wrap_cpp (MOC_SOURCES ${HEADERS})
qt4_add_resources (QRC_SOURCES ${RESOURCES}) qt4_add_resources (QRC_SOURCES ${RESOURCES})
foreach (LANGUAGE ${LANGUAGES}) foreach (LANGUAGE ${LANGUAGES})
set (TS ${LANGUAGE}) set (TS ${LANGUAGE})
string (REPLACE ".ts" ".qm" QM ${TS}) string (REPLACE ".ts" ".qm" QM ${TS})
set (TRANSLATIONS ${TRANSLATIONS} ${TS}) set (TRANSLATIONS ${TRANSLATIONS} ${TS})
set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM}) set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM})
add_custom_command (OUTPUT ${QM} COMMAND ${QT_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS}) add_custom_command (OUTPUT ${QM} COMMAND ${QT_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS})
endforeach () endforeach ()
add_custom_target (translations-helper COMMAND ${QT_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} -ts ${TRANSLATIONS}) add_custom_target (translations-helper COMMAND ${QT_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} -ts ${TRANSLATIONS})
add_custom_command (TARGET translations-helper COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS}) add_custom_command (TARGET translations-helper COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS})
endif() endif()
add_executable (${SUBPROJECT} ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS}) add_executable (${SUBPROJECT} ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS})
@ -56,5 +57,5 @@ target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS})
# install properties # install properties
install (TARGETS ${SUBPROJECT} DESTINATION bin) install (TARGETS ${SUBPROJECT} DESTINATION bin)
if (USE_CAPABILITIES) if (USE_CAPABILITIES)
install (CODE "exec_program (setcap ARGS \"cap_setuid=ep\" \"$ENV{DESTDIR}/bin/${SUBPROJECT}\")") install (CODE "exec_program (setcap ARGS \"cap_setuid=ep\" \"$ENV{DESTDIR}/bin/${SUBPROJECT}\")")
endif () endif ()

Some files were not shown because too many files have changed in this diff Show More