diff --git a/sources/plasmoid/plasmoid/contents/config/main.xml b/sources/plasmoid/plasmoid/contents/config/main.xml index a6936dd..e3af196 100644 --- a/sources/plasmoid/plasmoid/contents/config/main.xml +++ b/sources/plasmoid/plasmoid/contents/config/main.xml @@ -58,8 +58,8 @@ IPv6: $intip6 #000000 - - 400 + + normal normal diff --git a/sources/plasmoid/plasmoid/contents/ui/appearance.qml b/sources/plasmoid/plasmoid/contents/ui/appearance.qml index 434f4b7..ac59fd6 100644 --- a/sources/plasmoid/plasmoid/contents/ui/appearance.qml +++ b/sources/plasmoid/plasmoid/contents/ui/appearance.qml @@ -17,6 +17,7 @@ import QtQuick 2.0 import QtQuick.Controls 1.0 as QtControls +import QtQuick.Controls.Styles 1.3 as QtStyles import QtQuick.Dialogs 1.1 as QtDialogs import QtQuick.Layouts 1.0 as QtLayouts @@ -26,10 +27,18 @@ Item { width: childrenRect.width height: childrenRect.height + property variant weight: { + 25: 0, + 50: 1, + 63: 3, + 75: 4, + 87: 5 + } + property string cfg_textAlign: textAlign.currentText property alias cfg_fontFamily: selectFont.text property alias cfg_fontSize: fontSize.value - property alias cfg_fontWeight: fontWeight.value + property string cfg_fontWeight: fontWeight.currentText property string cfg_fontStyle: fontStyle.currentText property alias cfg_fontColor: selectColor.text property alias cfg_activeIconPath: activeIcon.text @@ -101,12 +110,39 @@ Item { QtControls.Label { text: i18n("Font weight") } - QtControls.SpinBox { + QtControls.ComboBox { id: fontWeight - minimumValue: 100 - maximumValue: 900 - stepSize: 100 - value: plasmoid.configuration.fontWeight + textRole: "label" + model: [ + { + 'label': i18n("light"), + 'name': "light" + }, + { + 'label': i18n("normal"), + 'name': "normal" + }, + { + 'label': i18n("demi bold"), + 'name': "demibold" + }, + { + 'label': i18n("bold"), + 'name': "bold" + }, + { + 'label': i18n("black"), + 'name': "black" + } + ] + onCurrentIndexChanged: cfg_fontWeight = model[currentIndex]["name"] + Component.onCompleted: { + for (var i = 0; i < model.length; i++) { + if (model[i]["name"] == plasmoid.configuration.fontWeight) { + fontWeight.currentIndex = i; + } + } + } } } @@ -144,6 +180,11 @@ Item { } QtControls.Button { id: selectColor + style: QtStyles.ButtonStyle { + background: Rectangle { + color: plasmoid.configuration.fontColor + } + } text: plasmoid.configuration.fontColor onClicked: colorDialog.visible = true } @@ -224,6 +265,8 @@ Item { onAccepted: { selectFont.text = fontDialog.font.family fontSize.value = fontDialog.font.pointSize + fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0 + fontWeight.currentIndex = weight[fontDialog.font.weight] } } } diff --git a/sources/plasmoid/plasmoid/contents/ui/main.qml b/sources/plasmoid/plasmoid/contents/ui/main.qml index 4417e41..01c8039 100644 --- a/sources/plasmoid/plasmoid/contents/ui/main.qml +++ b/sources/plasmoid/plasmoid/contents/ui/main.qml @@ -27,6 +27,25 @@ Item { id: main // variables + // internal + property variant weight: { + "light": Font.Light, + "normal": Font.Normal, + "demibold": Font.DemiBold, + "bold": Font.Bold, + "black": Font.Black + } + property variant align: { + "left": Text.AlignLeft, + "center": Text.AlignHCenter, + "right": Text.AlignRight, + "justify": Text.AlignJustify + } + // external + property variant iconPath: { + "true": plasmoid.configuration.activeIconPath, + "false": plasmoid.configuration.inactiveIconPath + } property variant info: { "current": "N\\A", "extip4": "127.0.0.1", @@ -37,12 +56,8 @@ Item { "profiles": "", "status": "N\\A" } - Text { - id: iconPath - property string active: plasmoid.configuration.activeIconPath - property string inactive: plasmoid.configuration.inactiveIconPath - } property int interval: plasmoid.configuration.autoUpdateInterval + property string pattern: plasmoid.configuration.textPattern property bool status: false // init @@ -57,19 +72,13 @@ Item { onNewData: { if (data.isEmpty) return if (sourceName == "active") { - if (data.value == "true") { - main.status = true - icon.source = iconPath.active - } else { - main.status = false - icon.source = iconPath.inactive - } + main.status = data.value == "true" ? true : false + icon.source = iconPath[data.value] } else if (sourceName == "current") { info["current"] = data.value // text update - for (var prop in info) { - console.log(prop + " = " + info[prop]) - } + info["info"] = NetctlAdds.getInfo(info["current"], info["status"]) + text.text = NetctlAdds.parsePattern(pattern, info) } else if (sourceName == "extip4") { info["extip4"] = data.value } else if (sourceName == "extip6") { @@ -94,10 +103,17 @@ Item { Image { id: icon - source: iconPath.inactive + source: iconPath["inactive"] } Text { id: text + color: plasmoid.configuration.fontColor + font.family: plasmoid.configuration.fontFamily + font.italic: plasmoid.configuration.fontStyle == "italic" ? true : false + font.pointSize: plasmoid.configuration.fontSize + font.weight: weight[plasmoid.configuration.fontWeight] + horizontalAlignment: align[plasmoid.configuration.textAlign] + textFormat: Text.RichText text: "N\\A" } } diff --git a/sources/plasmoid/plugin/netctl.cpp b/sources/plasmoid/plugin/netctl.cpp index d9668ef..4e17fb0 100644 --- a/sources/plasmoid/plugin/netctl.cpp +++ b/sources/plasmoid/plugin/netctl.cpp @@ -17,18 +17,22 @@ #include -#include - #include "netctl.h" #include "netctladds.h" -#include "version.h" + + +static QObject *netctl_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + + return new NetctlAdds(); +} void NetctlPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.netctl")); - qmlRegisterType(uri, 1, 0, "NetctlAdds"); -// qmlRegisterType(uri, 1, 0, "TimeZoneModel"); -// qmlRegisterSingletonType(uri, 1, 0, "TimezonesI18n", timezonesi18n_singletontype_provider); + qmlRegisterSingletonType(uri, 1, 0, "NetctlAdds", netctl_singletontype_provider); } diff --git a/sources/plasmoid/plugin/netctladds.cpp b/sources/plasmoid/plugin/netctladds.cpp index 8854263..816a33a 100644 --- a/sources/plasmoid/plugin/netctladds.cpp +++ b/sources/plasmoid/plugin/netctladds.cpp @@ -15,7 +15,10 @@ * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ -//#include +#include +#include + +#include #include "netctladds.h" #include "version.h" @@ -24,19 +27,45 @@ NetctlAdds::NetctlAdds(QObject *parent) : QObject(parent) { + // debug + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); + QString debugEnv = environment.value(QString("NETCTLGUI_DEBUG"), QString("no")); + debug = (debugEnv == QString("yes")); } NetctlAdds::~NetctlAdds() { -// if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG; } -QString NetctlAdds::parsePattern(QString pattern, const QString key, const QString value) +QString NetctlAdds::getInfo(const QString current, const QString status) { -// if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Current profiles" << current; + if (debug) qDebug() << PDEBUG << ":" << "Statuses" << status; - return pattern.replace(QString("$") + key, value); + QStringList profiles; + for (int i=0; i dict) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Dictionary" << dict; + + QString parsed = pattern; + for (int i=0; i")); + + return parsed; } diff --git a/sources/plasmoid/plugin/netctladds.h b/sources/plasmoid/plugin/netctladds.h index ff341e7..f5dfea5 100644 --- a/sources/plasmoid/plugin/netctladds.h +++ b/sources/plasmoid/plugin/netctladds.h @@ -19,11 +19,11 @@ #ifndef NETCTLADDS_H #define NETCTLADDS_H +#include #include +#include -class QQmlEngine; - class NetctlAdds : public QObject { Q_OBJECT @@ -32,7 +32,11 @@ public: NetctlAdds(QObject *parent = 0); ~NetctlAdds(); - Q_INVOKABLE QString parsePattern(QString pattern, const QString key, const QString value); + Q_INVOKABLE QString getInfo(const QString current, const QString status); + Q_INVOKABLE QString parsePattern(const QString pattern, const QMap dict); + +private: + bool debug = false; };