Malte Veerman 9 tahun lalu
induk
melakukan
a5b4d28da1

+ 4 - 12
fancontrol-gui/package/contents/ui/Application.qml

@@ -100,28 +100,20 @@ ApplicationWindow {
 
         Tab {
             title: i18n("Sensors")
-            SensorsTab {
-                loader: Fancontrol.base.loader
-            }
+            SensorsTab {}
         }
         Tab {
             title: i18n("PwmFans")
-            PwmFansTab {
-                baseObject: Fancontrol.base
-            }
+            PwmFansTab {}
         }
         Tab {
             title: i18n("Configfile")
-            ConfigfileTab {
-                loader: Fancontrol.base.loader
-            }
+            ConfigfileTab {}
         }
         Tab {
             id: settingsTab
             title: i18n("Settings")
-            SettingsTab {
-                gui: Fancontrol.base
-            }
+            SettingsTab {}
         }
     }
 

+ 2 - 2
fancontrol-gui/package/contents/ui/ConfigfileTab.qml

@@ -21,11 +21,11 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.2
 import QtQuick.Layouts 1.1
-import Fancontrol.Qml 1.0
+import Fancontrol.Qml 1.0 as Fancontrol
 
 
 ColumnLayout {
-    property QtObject loader
+    property QtObject loader: Fancontrol.base.loader
 
     anchors.fill: parent
     anchors.margins: 10

+ 12 - 13
fancontrol-gui/package/contents/ui/PwmFansTab.qml

@@ -21,16 +21,15 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.4
 import QtQuick.Layouts 1.2
-import Fancontrol.Qml 1.0
+import Fancontrol.Qml 1.0 as Fancontrol
 
 
 ColumnLayout {
-    property QtObject baseObject
-    property QtObject loader: baseObject ? baseObject.loader : null
-    property QtObject systemdCom: baseObject && baseObject.hasSystemdCommunicator() ? baseObject.systemdCom : null
-    property QtObject pwmFanModel: baseObject ? baseObject.pwmFanModel : null
-    property QtObject tempModel: baseObject ? baseObject.tempModel : null
-    property var pwmFans: pwmFanModel ? pwmFanModel.fans : []
+    property QtObject loader: Fancontrol.base.loader
+    property QtObject systemdCom: Fancontrol.base.hasSystemdCommunicator() ? Fancontrol.base.systemdCom : null
+    property QtObject pwmFanModel: Fancontrol.base.pwmFanModel
+    property QtObject tempModel: Fancontrol.base.tempModel
+    property var pwmFans: pwmFanModel.fans
 
     id: root
     anchors.fill: parent
@@ -38,7 +37,7 @@ ColumnLayout {
 
     RowLayout {
         width: parent.width
-        visible: !!pwmFanModel && pwmFans.length > 0
+        visible: pwmFans.length > 0
 
         Label {
             text: i18n("Fan:")
@@ -61,15 +60,15 @@ ColumnLayout {
     Loader {
         Layout.fillHeight: true
         Layout.fillWidth: true
-        active: !!tempModel && !!systemdCom && pwmFans.length > fanComboBox.currentIndex
+        active: pwmFans.length > fanComboBox.currentIndex && fanComboBox.currentIndex >= 0
 
-        sourceComponent: FanItem {
-            unit: !!baseObject ? baseObject.unit : 0
+        sourceComponent: Fancontrol.FanItem {
+            unit: Fancontrol.base.unit
             fan: pwmFans[fanComboBox.currentIndex]
             tempModel: root.tempModel
             systemdCom: root.systemdCom
-            minTemp: !!baseObject ? baseObject.minTemp : 30
-            maxTemp: !!baseObject ? baseObject.maxTemp : 100
+            minTemp: Fancontrol.base.minTemp
+            maxTemp: Fancontrol.base.maxTemp
         }
     }
 

+ 4 - 4
fancontrol-gui/package/contents/ui/SensorsTab.qml

@@ -21,18 +21,18 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.2
 import QtQuick.Layouts 1.1
-import Fancontrol.Qml 1.0
+import Fancontrol.Qml 1.0 as Fancontrol
 
 
 RowLayout {
-    property QtObject loader
+    property QtObject loader: Fancontrol.base.loader 
 
     id: root
     anchors.fill: parent
     anchors.margins: 10
 
     Repeater {
-        model: !!loader ? loader.hwmons.length : 0
+        model: loader.hwmons.length
 
         Rectangle {
             property QtObject hwmon: loader.hwmons[index]
@@ -95,7 +95,7 @@ RowLayout {
                             id: tempValue
                             anchors.right: parent.right
                             anchors.rightMargin: padding
-                            text: hwmon.temps[index].value
+                            text: hwmon.temps[index].value + " " + Fancontrol.base.unit
                         }
                     }
                 }

+ 16 - 34
fancontrol-gui/package/contents/ui/SettingsTab.qml

@@ -21,15 +21,13 @@
 import QtQuick 2.4
 import QtQuick.Layouts 1.1
 import QtQuick.Controls 1.2
-import Fancontrol.Qml 1.0
+import Fancontrol.Qml 1.0 as Fancontrol
 
 
 Item {
-    property QtObject gui
-    property QtObject systemdCom: !!gui && gui.hasSystemdCommunicator() ? gui.systemdCom : null
-    property QtObject loader : !!gui ? gui.loader : null
+    property QtObject systemdCom: Fancontrol.base.hasSystemdCommunicator() ? Fancontrol.base.systemdCom : null
+    property QtObject loader : Fancontrol.base.loader
     property int padding: 10
-    property int unit: !!gui ? gui.unit : 0
     property real textWidth: 0
     property var locale: Qt.locale()
 
@@ -56,14 +54,10 @@ Item {
             SpinBox {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                value: !!loader ? loader.interval : 1
-                suffix: !!loader ? " " + i18np("second", "seconds", loader.interval): ""
+                value: loader.interval
+                suffix: " " + i18np("second", "seconds", loader.interval)
                 minimumValue: 1.0
-                onValueChanged: {
-                    if (!!loader) {
-                        loader.interval = value;
-                    }
-                }
+                onValueChanged: loader.interval = value
             }
         }
         RowLayout {
@@ -82,14 +76,10 @@ Item {
                 Layout.fillWidth: true
                 decimals: 2
                 maximumValue: maxTempBox.value
-                minimumValue: Units.fromKelvin(0, unit)
-                value: !!gui ? Units.fromCelsius(gui.minTemp, unit) : 0
-                suffix: unit == 0 ? i18n("°C") : unit == 1 ? i18n("K") : i18n("°F")
-                onValueChanged: {
-                    if (!!gui) {
-                        gui.minTemp = value;
-                    }
-                }
+                minimumValue: Units.fromKelvin(0, Fancontrol.base.unit)
+                value: Units.fromCelsius(Fancontrol.base.minTemp, Fancontrol.base.unit)
+                suffix: Fancontrol.base.unit
+                onValueChanged: Fancontrol.base.minTemp = value
             }
         }
         RowLayout {
@@ -109,13 +99,9 @@ Item {
                 decimals: 2
                 maximumValue: Number.POSITIVE_INFINITY
                 minimumValue: minTempBox.value
-                value: !!gui ? Units.fromCelsius(gui.maxTemp, unit) : 0
-                suffix: unit == 0 ? i18n("°C") : unit == 1 ? i18n("K") : i18n("°F")
-                onValueChanged: {
-                    if (!!gui) {
-                        gui.maxTemp = value;
-                    }
-                }
+                value: Units.fromCelsius(Fancontrol.base.maxTemp, Fancontrol.base.unit)
+                suffix: Fancontrol.base.unit
+                onValueChanged:Fancontrol.base.maxTemp = value
             }
         }
         Loader {
@@ -130,16 +116,12 @@ Item {
                     horizontalAlignment: Text.AlignRight
                     Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
                 }
-                OptionInput {
+                Fancontrol.OptionInput {
                     Layout.minimumWidth: implicitWidth
                     Layout.fillWidth: true
                     color: !!systemdCom && systemdCom.serviceExists ? "green" : "red"
-                    value: !!gui ? gui.serviceName : ""
-                    onTextChanged: {
-                        if (!!gui) {
-                            gui.serviceName = text;
-                        }
-                    }
+                    value: Fancontrol.base.serviceName
+                    onTextChanged: Fancontrol.base.serviceName = text
                 }
             }
         }

+ 10 - 5
import/qml/FanItem.qml

@@ -34,7 +34,7 @@ Rectangle {
     property real minTemp: 40.0
     property real maxTemp: 90.0
     property int margin: 5
-    property int unit: 0
+    property string unit: "°C"
     property real convertedMinTemp: Units.fromCelsius(minTemp, unit)
     property real convertedMaxTemp: Units.fromCelsius(maxTemp, unit)
 
@@ -60,6 +60,7 @@ Rectangle {
 
     TextEdit {
         id: nameField
+        
         anchors {
             left: parent.left
             leftMargin: margin
@@ -82,7 +83,12 @@ Rectangle {
                 fan.name = text;
             }
         }
-
+        
+        Connections {
+            target: fan
+            onNameChanged: if (fan.name != text) text = fan.name
+        }
+            
         MouseArea {
             anchors.fill: parent
             cursorShape: Qt.IBeamCursor
@@ -95,7 +101,6 @@ Rectangle {
 
         property int fontSize: MoreMath.bound(8, height / 20 + 1, 16)
         property QtObject pal: !!fan ? fan.hasTemp ? palette : disabledPalette : disabledPalette
-        property string suffix: (root.unit == 0) ? "°C" : (root.unit == 1) ? "K" : "°F"
         property int verticalScalaCount: 6
         property var horIntervals: MoreMath.intervals(root.convertedMinTemp, root.convertedMaxTemp, 10)
 
@@ -149,7 +154,7 @@ Rectangle {
                     x: Math.min(horizontalScala.width, background.width / (graph.horIntervals.length - 1) * index) - width / 2
                     y: horizontalScala.height / 2 - implicitHeight / 2
                     color: graph.pal.text
-                    text: graph.horIntervals[index] + graph.suffix
+                    text: graph.horIntervals[index] + unit
                     font.pixelSize: graph.fontSize
                 }
             }
@@ -444,7 +449,7 @@ Rectangle {
         }
 
         RowLayout {
-            visible: systemdCom
+            visible: !!systemdCom
 
             Item {
                 Layout.fillWidth: true

+ 2 - 4
import/qml/PwmPoint.qml

@@ -32,7 +32,7 @@ Rectangle {
     readonly property point center: Qt.point(centerX, centerY)
     property alias drag: pwmMouse.drag
     property int size: 10
-    property int unit: 0
+    property string unit: "°C"
     property var locale: Qt.locale()
 
     signal positionChanged()
@@ -79,11 +79,9 @@ Rectangle {
                 text: Number(Math.round(background.scalePwm(root.centerY)) / 2.55).toLocaleString(locale, 'f', 1) + '%'
             }
             Label {
-                property string suffix: (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
-
                 id: temp
                 font.pixelSize: root.size * 1.5
-                text: Math.round(Units.fromCelsius(background.scaleTemp(root.centerX)), unit) + suffix
+                text: Math.round(Units.fromCelsius(background.scaleTemp(root.centerX)), unit) + unit
             }
         }
     }

+ 2 - 4
import/qml/StatusPoint.qml

@@ -36,7 +36,7 @@ Rectangle {
     readonly property real centerY: y + height / 2
     readonly property point center: Qt.point(centerX, centerY)
     property int size: 10
-    property int unit: 0
+    property string unit: "°C"
 
     width: size
     height: size
@@ -78,11 +78,9 @@ Rectangle {
 
         Column {
             Label {
-                property string suffix: (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
-
                 id: temp
                 font.pixelSize: root.height * 1.5
-                text: (!!fan && fan.hasTemp ? Math.round(Units.fromCelsius(root.unscaledTemp, unit)) : "0") + suffix
+                text: (!!fan && fan.hasTemp ? Math.round(Units.fromCelsius(root.unscaledTemp, unit)) : "0") + unit
 
             }
             Label {

+ 5 - 5
import/qml/units.js

@@ -24,15 +24,15 @@ function round(number, dec) {
 
 function toCelsius(degrees, currentUnit) {
     var float = parseFloat(degrees);
-    if (currentUnit == 1) { return float - 273.15; }
-    if (currentUnit == 2) { return (float - 32) * 5 / 9; }
+    if (currentUnit == "K") { return float - 273.15; }
+    if (currentUnit == "°F") { return (float - 32) * 5 / 9; }
     return float;
 }
 
 function fromCelsius(degrees, newUnit) {
     var float = parseFloat(degrees);
-    if (newUnit == 1) { return float + 273.15; }
-    if (newUnit == 2) { return float * 9 / 5 + 32; }
+    if (newUnit == "K") { return float + 273.15; }
+    if (newUnit == "°F") { return float * 9 / 5 + 32; }
     return float;
 }
 
@@ -41,4 +41,4 @@ function fromKelvin(degrees, newUnit) {
     if (newUnit == 0) { return float - 273.15; }
     if (newUnit == 2) { return float * 9 / 5 - 459.67; }
     return float;
-}
+}    

+ 1 - 1
import/src/guibase.cpp

@@ -52,7 +52,7 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
 
     QLocale locale = QLocale::system();
     QLocale::MeasurementSystem system = locale.measurementSystem();
-    m_unit = (system != QLocale::ImperialUSSystem) ? 0 : 2;
+    m_unit = (system == QLocale::ImperialUSSystem) ? QStringLiteral("°F") : QStringLiteral("°C");
 
     m_tempModel->setUnit(m_unit);
     foreach (Hwmon *hwmon, m_loader->hwmons())

+ 4 - 4
import/src/guibase.h

@@ -56,7 +56,7 @@ class GUIBase : public QObject
 
     Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp NOTIFY minTempChanged)
     Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp NOTIFY maxTempChanged)
-    Q_PROPERTY(int unit READ unit WRITE setUnit NOTIFY unitChanged)
+    Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY unitChanged)
     Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
     Q_PROPERTY(QUrl configUrl READ configUrl WRITE setConfigUrl NOTIFY configUrlChanged)
     Q_PROPERTY(bool configValid READ configValid NOTIFY configUrlChanged)
@@ -78,12 +78,12 @@ public:
     QString serviceName() const;
     QUrl configUrl() const;
     bool configValid() const { return m_configValid; }
-    int unit() const { return m_unit; }
+    QString unit() const { return m_unit; }
     void setMinTemp(qreal minTemp);
     void setMaxTemp(qreal maxTemp);
     void setServiceName(const QString &name);
     void setConfigUrl(const QUrl &url);
-    void setUnit(int unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(); m_tempModel->setUnit(unit); } }
+    void setUnit(const QString &unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(); m_tempModel->setUnit(unit); } }
     PwmFanModel *pwmFanModel() const { return m_pwmFanModel; };
     TempModel *tempModel() const { return m_tempModel; };
     
@@ -119,7 +119,7 @@ private:
 #endif
 
     Loader *const m_loader;
-    int m_unit;
+    QString m_unit;
     bool m_configValid;
     PwmFanModel *m_pwmFanModel;
     TempModel *m_tempModel;

+ 2 - 4
import/src/tempmodel.cpp

@@ -31,15 +31,13 @@ namespace Fancontrol
 {
 
 TempModel::TempModel(QObject *parent) : QStringListModel(parent),
-m_unit(0)
+m_unit(QStringLiteral("°C"))
 {
 }
 
 QString TempModel::composeText(Temp *temp)
 {
-    QString suffix = m_unit == 0 ? QStringLiteral("°C") : m_unit == 2 ? QStringLiteral("°F") : QStringLiteral("K");
-
-    return temp->name() + ": " + QString::number(temp->value()) + suffix + "   (" + temp->path() + ")";
+    return temp->name() + ": " + QString::number(temp->value()) + m_unit + "   (" + temp->path() + ")";
 }
 
 

+ 2 - 2
import/src/tempmodel.h

@@ -45,7 +45,7 @@ public:
     void setTemps(const QList<Temp *> &temps);
     void addTemps(const QList<Temp *> &temps);
     QList<QObject *> temps() const;
-    void setUnit(int unit) { if (unit != m_unit) { m_unit = unit; updateAll(); } }
+    void setUnit(const QString &unit) { if (unit != m_unit) { m_unit = unit; updateAll(); } }
 
 
 protected:
@@ -76,7 +76,7 @@ signals:
 private:
 
     QList<Temp *> m_temps;
-    int m_unit;
+    QString m_unit;
 };
 
 }

+ 5 - 5
kcm/package/contents/ui/KCM.qml

@@ -33,7 +33,7 @@ Item {
     property QtObject tempModel: Fancontrol.base.tempModel
     property var locale: Qt.locale()
     property real textWidth: 0
-    property var pwmFans: pwmFanModel ? pwmFanModel.fans : []
+    property var pwmFans: pwmFanModel.fans
 
     id: root
     implicitWidth: 1024
@@ -141,7 +141,7 @@ Item {
         Loader {
             Layout.fillWidth: true
             Layout.fillHeight: true
-            active: !!pwmFans[fanComboBox.currentIndex]
+            active: pwmFans.length > fanComboBox.currentIndex
             sourceComponent: Fancontrol.FanItem {
                 unit: Fancontrol.base.unit
                 fan: pwmFans[fanComboBox.currentIndex]
@@ -231,7 +231,7 @@ Item {
             SpinBox {
                 Layout.minimumWidth: implicitWidth
                 Layout.fillWidth: true
-                value: !!loader ? loader.interval : 1
+                value: loader.interval
                 suffix: " " + i18np("second", "seconds", loader.interval)
                 minimumValue: 1.0
                 onValueChanged: loader.interval = value
@@ -255,7 +255,7 @@ Item {
                 maximumValue: maxTempBox.value
                 minimumValue: Units.fromKelvin(0, Fancontrol.base.unit)
                 value: Units.fromCelsius(Fancontrol.base.minTemp, Fancontrol.base.unit)
-                suffix: Fancontrol.base.unit == 0 ? i18n("°C") : Fancontrol.base.unit == 1 ? i18n("K") : i18n("°F")
+                suffix: Fancontrol.base.unit
                 onValueChanged: Fancontrol.base.minTemp = value
             }
         }
@@ -277,7 +277,7 @@ Item {
                 maximumValue: Number.POSITIVE_INFINITY
                 minimumValue: minTempBox.value
                 value: Units.fromCelsius(Fancontrol.base.maxTemp, Fancontrol.base.unit)
-                suffix: Fancontrol.base.unit == 0 ? i18n("°C") : Fancontrol.base.unit == 1 ? i18n("K") : i18n("°F")
+                suffix: Fancontrol.base.unit
                 onValueChanged: Fancontrol.base.maxTemp = value
             }
         }