Pārlūkot izejas kodu

removed arrayfunctions and moved functionality into custom stringlistmodels

Malte Veerman 9 gadi atpakaļ
vecāks
revīzija
2c748bcbbc

+ 7 - 5
lib/CMakeLists.txt

@@ -5,15 +5,17 @@ set(LIB_SRCS src/hwmon.cpp
              src/pwmfan.cpp
              src/loader.cpp
              src/guibase.cpp
-             src/config.cpp)
-                        
+             src/config.cpp
+             src/pwmfanmodel.cpp
+             src/tempmodel.cpp)
+
 set(LIB_PRIVATE_LIBRARIES Qt5::Qml
                           KF5::Auth
                           KF5::ConfigCore
                           KF5::I18n)
 
 set(LIB_PUBLIC_LIBRARIES Qt5::Core)
-              
+
 if(NOT NO_SYSTEMD)
 
     set(LIB_SRCS ${LIB_SRCS}
@@ -39,5 +41,5 @@ generate_export_header(fancontrol_gui_lib)
 if(INSTALL_SHARED)
 
     install(TARGETS fancontrol_gui_lib ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
-    
-endif(INSTALL_SHARED)
+
+endif(INSTALL_SHARED)

+ 9 - 1
lib/src/guibase.cpp

@@ -41,7 +41,9 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
 #endif
 
     m_loader(new Loader(this)),
-    m_configValid(false)
+    m_configValid(false),
+    m_pwmFanModel(new PwmFanModel(this)),
+    m_tempModel(new TempModel(this))
 {
     connect(m_config, &Config::configChanged, this, &GUIBase::emitConfigChanged);
 
@@ -59,6 +61,12 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
     qmlRegisterType<SystemdCommunicator>();
 #endif
 
+    m_tempModel->setUnit(m_unit);
+    foreach (Hwmon *hwmon, m_loader->hwmons())
+    {
+        m_pwmFanModel->addPwmFans(hwmon->pwmFans());
+        m_tempModel->addTemps(hwmon->temps());
+    }
 }
 
 void GUIBase::load()

+ 11 - 1
lib/src/guibase.h

@@ -25,8 +25,11 @@
 #define GUIBASE_H
 
 #include <QtCore/QObject>
+#include <QtCore/QStringListModel>
 
 #include "loader.h"
+#include "pwmfanmodel.h"
+#include "tempmodel.h"
 
 #ifndef NO_SYSTEMD
 #include "systemdcommunicator.h"
@@ -60,6 +63,8 @@ class FANCONTROL_GUI_LIB_EXPORT GUIBase : public QObject
     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)
+    Q_PROPERTY(PwmFanModel *pwmFanModel READ pwmFanModel CONSTANT)
+    Q_PROPERTY(TempModel *tempModel READ tempModel CONSTANT)
 
 public:
 
@@ -81,8 +86,11 @@ public:
     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(); } }
+    void setUnit(int unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(); m_tempModel->setUnit(unit); } }
     void load();
+    PwmFanModel *pwmFanModel() const { return m_pwmFanModel; };
+    TempModel *tempModel() const { return m_tempModel; };
+
 
     Q_INVOKABLE void save(bool saveLoader = false, const QUrl &url = QUrl());
     Q_INVOKABLE bool hasSystemdCommunicator() const { return SYSTEMD_BOOL; }
@@ -113,6 +121,8 @@ private:
     Loader *const m_loader;
     int m_unit;
     bool m_configValid;
+    PwmFanModel *m_pwmFanModel;
+    TempModel *m_tempModel;
 };
 
 }

+ 3 - 3
lib/src/hwmon.cpp

@@ -149,7 +149,7 @@ void Hwmon::initialize()
     }
 }
 
-QList<QObject *> Hwmon::fans() const
+QList<QObject *> Hwmon::fansAsObjects() const
 {
     QList<QObject *> list;
     foreach (Fan *fan, m_fans)
@@ -159,7 +159,7 @@ QList<QObject *> Hwmon::fans() const
     return list;
 }
 
-QList<QObject *> Hwmon::pwmFans() const
+QList<QObject *> Hwmon::pwmFansAsObjects() const
 {
     QList<QObject *> list;
     foreach (PwmFan *pwmFan, m_pwmFans)
@@ -169,7 +169,7 @@ QList<QObject *> Hwmon::pwmFans() const
     return list;
 }
 
-QList<QObject *> Hwmon::temps() const
+QList<QObject *> Hwmon::tempsAsObjects() const
 {
     QList<QObject *> list;
     foreach (Temp *temp, m_temps)

+ 13 - 10
lib/src/hwmon.h

@@ -39,9 +39,9 @@ class Hwmon : public QObject
     Q_PROPERTY(QString name READ name CONSTANT)
     Q_PROPERTY(QString path READ path CONSTANT)
     Q_PROPERTY(int index READ index CONSTANT)
-    Q_PROPERTY(QList<QObject *> fans READ fans NOTIFY fansChanged)
-    Q_PROPERTY(QList<QObject *> pwmFans READ pwmFans NOTIFY pwmFansChanged)
-    Q_PROPERTY(QList<QObject *> temps READ temps NOTIFY tempsChanged)
+    Q_PROPERTY(QList<QObject *> fans READ fansAsObjects NOTIFY fansChanged)
+    Q_PROPERTY(QList<QObject *> pwmFans READ pwmFansAsObjects NOTIFY pwmFansChanged)
+    Q_PROPERTY(QList<QObject *> temps READ tempsAsObjects NOTIFY tempsChanged)
 
 
 public:
@@ -52,25 +52,28 @@ public:
     QString name() const { return m_name; }
     QString path() const { return m_path; }
     int index() const { return m_index; }
-    QList<QObject *> fans() const;
-    QList<QObject *> pwmFans() const;
-    QList<QObject *> temps() const;
+    QList<Fan *> fans() const { return m_fans; }
+    QList<PwmFan *> pwmFans() const { return m_pwmFans; }
+    QList<Temp *> temps() const { return m_temps; }
+    QList<QObject *> fansAsObjects() const;
+    QList<QObject *> pwmFansAsObjects() const;
+    QList<QObject *> tempsAsObjects() const;
     Q_INVOKABLE void testFans();
     Q_INVOKABLE void abortTestingFans();
     Fan * fan(int i) const;
     PwmFan * pwmFan(int i) const;
     Temp * temp(int i) const;
     bool isValid() const { return m_valid; }
-    
+
 
 public slots:
 
     void updateConfig() { emit configUpdateNeeded(); }
     void updateSensors() { emit sensorsUpdateNeeded(); }
-    
-    
+
+
 protected slots:
-    
+
     void setError(const QString &error);
 
 

+ 4 - 14
lib/src/loader.cpp

@@ -326,7 +326,7 @@ bool Loader::load(const QUrl &url)
     while(!stream.atEnd());
 
     foreach (QString line, lines)
-    {        
+    {
         if (line.startsWith("INTERVAL="))
         {
             line.remove("INTERVAL=");
@@ -442,7 +442,7 @@ bool Loader::load(const QUrl &url)
             //Connect hwmons again
             foreach (Hwmon *hwmon, m_hwmons)
                 connect(hwmon, SIGNAL(configUpdateNeeded()), this, SLOT(createConfigFile()));
-            
+
             setError(i18n("Unrecognized line in config:\n%1", line), true);
             return false;
         }
@@ -686,7 +686,7 @@ void Loader::handleDetectSensorsResult(KJob *job)
         parseHwmons();
 }
 
-QList<QObject *> Loader::hwmons() const
+QList<QObject *> Loader::hwmonsAsObjects() const
 {
     QList<QObject *> list;
     foreach (Hwmon *hwmon, m_hwmons)
@@ -696,22 +696,12 @@ QList<QObject *> Loader::hwmons() const
     return list;
 }
 
-QList<QObject *> Loader::allPwmFans() const
-{
-    QList<QObject *> list;
-    foreach (const Hwmon *hwmon, m_hwmons)
-    {
-        list += hwmon->pwmFans();
-    }
-    return list;
-}
-
 QList<QObject *> Loader::allTemps() const
 {
     QList<QObject *> list;
     foreach (const Hwmon *hwmon, m_hwmons)
     {
-        list += hwmon->temps();
+        list += hwmon->tempsAsObjects();
     }
     return list;
 }

+ 3 - 4
lib/src/loader.h

@@ -45,8 +45,7 @@ class FANCONTROL_GUI_LIB_EXPORT Loader : public QObject
     Q_OBJECT
     Q_PROPERTY(QUrl configUrl READ configUrl NOTIFY configUrlChanged)
     Q_PROPERTY(QString configFile READ configFile NOTIFY configFileChanged)
-    Q_PROPERTY(QList<QObject *> hwmons READ hwmons NOTIFY hwmonsChanged)
-    Q_PROPERTY(QList<QObject *> allPwmFans READ allPwmFans NOTIFY allPwmFansChanged)
+    Q_PROPERTY(QList<QObject *> hwmons READ hwmonsAsObjects NOTIFY hwmonsChanged)
     Q_PROPERTY(QList<QObject *> allTemps READ allTemps NOTIFY allTempsChanged)
     Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
     Q_PROPERTY(QString error READ error NOTIFY errorChanged)
@@ -64,8 +63,8 @@ public:
     Q_INVOKABLE void detectSensors();
     QUrl configUrl() const { return m_configUrl; }
     QString configFile() const { return m_configFile; }
-    QList<QObject *> hwmons() const;
-    QList<QObject *> allPwmFans() const;
+    QList<Hwmon *> hwmons() const { return m_hwmons; }
+    QList<QObject *> hwmonsAsObjects() const;
     QList<QObject *> allTemps() const;
     int interval() const { return m_interval; }
     void setInterval(int interval, bool writeNewConfig = true);

+ 108 - 0
lib/src/pwmfanmodel.cpp

@@ -0,0 +1,108 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015  Malte Veerman maldela@halloarsch.de
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#include "pwmfanmodel.h"
+#include "pwmfan.h"
+
+
+namespace Fancontrol
+{
+
+PwmFanModel::PwmFanModel(QObject *parent) : QStringListModel(parent)
+{
+}
+
+void PwmFanModel::setPwmFans(const QList<PwmFan *> &fans)
+{
+    m_fans = fans;
+    emit fansChanged();
+
+    QStringList list;
+
+    foreach (PwmFan *const fan, fans)
+    {
+        connect(fan, SIGNAL(nameChanged()), this, SLOT(updateFan()));
+        list << fan->name() + "  (" + fan->path() + ")";
+    }
+
+    setStringList(list);
+}
+
+void PwmFanModel::addPwmFans(const QList<PwmFan *> &fans)
+{
+    if (!fans.isEmpty())
+    {
+        m_fans += fans;
+        emit fansChanged();
+
+        int oldSize = rowCount();
+
+        insertRows(oldSize, fans.size());
+
+        foreach (PwmFan *const fan, fans)
+        {
+            connect(fan, SIGNAL(nameChanged()), this, SLOT(updateFan()));
+            updateFan(fan);
+        }
+    }
+}
+
+void PwmFanModel::updateFan(PwmFan *fan)
+{
+    if (!fan)
+        return;
+
+    int i = m_fans.indexOf(fan);
+    if (i == -1)
+        return;
+
+    QString string = fan->name() + "  (" + fan->path() + ")";
+    setData(index(i, 0), string);
+    emit dataChanged(index(i, 0), index(i, 0));
+}
+
+void PwmFanModel::updateFan()
+{
+    PwmFan *fan = qobject_cast<PwmFan *>(sender());
+
+    if (!fan)
+        return;
+
+    int i = m_fans.indexOf(fan);
+    if (i == -1)
+        return;
+
+    QString string = fan->name() + "  (" + fan->path() + ")";
+    setData(index(i, 0), string);
+    emit dataChanged(index(i, 0), index(i, 0));
+}
+
+QList<QObject *> PwmFanModel::fans() const
+{
+    QList<QObject *> list;
+    foreach(PwmFan *const fan, m_fans)
+        list << qobject_cast<QObject *>(fan);
+    return list;
+}
+
+}

+ 75 - 0
lib/src/pwmfanmodel.h

@@ -0,0 +1,75 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015  Malte Veerman maldela@halloarsch.de
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef PWMFANMODEL_H
+#define PWMFANMODEL_H
+
+
+#include <QtCore/QStringListModel>
+
+
+
+namespace Fancontrol {
+
+
+class PwmFan;
+
+class PwmFanModel : public QStringListModel
+{
+    Q_OBJECT
+    Q_PROPERTY(QList<QObject *> fans READ fans NOTIFY fansChanged)
+    Q_PROPERTY(int count READ count NOTIFY fansChanged)
+
+public:
+
+    PwmFanModel(QObject *parent = Q_NULLPTR);
+    void setPwmFans(const QList<PwmFan *> &fans);
+    void addPwmFans(const QList<PwmFan *> &fans);
+    QList<QObject *> fans() const;
+    int count() const { return m_fans.size(); }
+
+
+public slots:
+
+    void updateFan(PwmFan *fan);
+
+
+private slots:
+
+    void updateFan();
+
+
+signals:
+
+    void fansChanged();
+
+
+private:
+
+    QList<PwmFan *> m_fans;
+};
+
+}
+
+
+#endif //PWMFANMODEL_H

+ 130 - 0
lib/src/tempmodel.cpp

@@ -0,0 +1,130 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015  Malte Veerman maldela@halloarsch.de
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#include "tempmodel.h"
+#include "temp.h"
+
+#include <QDebug>
+
+
+namespace Fancontrol
+{
+
+TempModel::TempModel(QObject *parent) : QStringListModel(parent),
+m_unit(0)
+{
+}
+
+QString TempModel::composeText(Temp *temp)
+{
+    QString suffix = m_unit == 0 ? "°C" : m_unit == 2 ? "°F" : "K";
+
+    return temp->name() + ": " + QString::number(temp->value()) + suffix + "   (" + temp->path() + ")";
+}
+
+
+void TempModel::setTemps(const QList<Temp *> &temps)
+{
+    m_temps = temps;
+    emit tempsChanged();
+
+    QStringList list;
+
+    foreach (Temp *const temp, temps)
+    {
+        connect(temp, SIGNAL(nameChanged()), this, SLOT(updateTemp()));
+        connect(temp, SIGNAL(valueChanged()), this, SLOT(updateTemp()));
+        list << composeText(temp);
+    }
+
+    setStringList(list);
+}
+
+void TempModel::addTemps(const QList<Temp *> &temps)
+{
+    if (!temps.isEmpty())
+    {
+        m_temps += temps;
+        emit tempsChanged();
+
+        int oldSize = rowCount();
+
+        insertRows(oldSize, temps.size());
+
+        foreach (Temp *const temp, temps)
+        {
+            connect(temp, SIGNAL(nameChanged()), this, SLOT(updateTemp()));
+            connect(temp, SIGNAL(valueChanged()), this, SLOT(updateTemp()));
+            updateTemp(temp);
+        }
+    }
+}
+
+void TempModel::updateTemp(Temp *temp)
+{
+    if (!temp)
+        return;
+
+    int i = m_temps.indexOf(temp);
+    if (i == -1)
+        return;
+
+    setData(index(i, 0), composeText(temp));
+    emit dataChanged(index(i, 0), index(i, 0));
+}
+
+void TempModel::updateTemp()
+{
+    Temp *temp = qobject_cast<Temp *>(sender());
+
+    if (!temp)
+        return;
+
+    int i = m_temps.indexOf(temp);
+    if (i == -1)
+        return;
+
+    setData(index(i, 0), composeText(temp));
+    emit dataChanged(index(i, 0), index(i, 0));
+}
+
+void TempModel::updateAll()
+{
+    for (int i=0; i<m_temps.size(); i++)
+    {
+        Temp *temp = m_temps.at(i);
+        setData(index(i, 0), composeText(temp));
+    }
+    emit dataChanged(index(0, 0), index(count(), 0));
+}
+
+QList<QObject *> TempModel::temps() const
+{
+    QList<QObject *> list;
+    foreach(Temp *const temp, m_temps)
+        list << qobject_cast<QObject *>(temp);
+    return list;
+}
+
+}
+

+ 87 - 0
lib/src/tempmodel.h

@@ -0,0 +1,87 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015  Malte Veerman maldela@halloarsch.de
+ *
+ * This program 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 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef TEMPMODEL_H
+#define TEMPMODEL_H
+
+
+#include <QtCore/QStringListModel>
+
+
+
+namespace Fancontrol {
+
+
+class Temp;
+
+class TempModel : public QStringListModel
+{
+    Q_OBJECT
+    Q_PROPERTY(QList<QObject *> temps READ temps NOTIFY tempsChanged)
+    Q_PROPERTY(int count READ count NOTIFY tempsChanged)
+
+public:
+
+    TempModel(QObject *parent = Q_NULLPTR);
+    void setTemps(const QList<Temp *> &temps);
+    void addTemps(const QList<Temp *> &temps);
+    QList<QObject *> temps() const;
+    int count() const { return m_temps.size(); }
+    void setUnit(int unit) { if (unit != m_unit) { m_unit = unit; updateAll(); } }
+
+
+protected:
+
+    QString composeText(Temp *temp);
+
+
+public slots:
+
+    void updateTemp(Temp *temp);
+
+
+protected slots:
+
+    void updateAll();
+
+
+private slots:
+
+    void updateTemp();
+
+
+signals:
+
+    void tempsChanged();
+
+
+private:
+
+    QList<Temp *> m_temps;
+    int m_unit;
+};
+
+}
+
+
+#endif //TEMPMODEL_H

+ 0 - 70
package/contents/scripts/arrayfunctions.js

@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2015  Malte Veerman <maldela@halloarsch.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-function names(array) {
-    var names = [];
-    for (var i=0; i<array.length; i++) {
-        names[i] = array[i].name;
-    }
-    return names;
-}
-
-function nameWithPath(fan) {
-    return fan.name + "  (" + fan.path + ")";
-}
-
-function namesWithPaths(array) {
-    var namesWithPaths = [];
-    for (var i=0; i<array.length; i++) {
-        namesWithPaths[i] = nameWithPath(array[i]);
-    }
-    return namesWithPaths;
-}
-
-function labels(array) {
-    var labels = [];
-    for (var i=0; i<array.length; i++) {
-        labels[i] = array[i].label;
-    }
-    return labels;
-}
-
-function labelsWithPaths(array) {
-    var labelsWithPaths = [];
-    for (var i=0; i<array.length; i++) {
-        labelsWithPaths[i] = array[i].label + "  (" + array[i].path + ")";
-    }
-    return labelsWithPaths;
-}
-
-function maxProperty(array, prop) {
-    var max = 0;
-    for (var i=0; i<array.length; i++) {
-        max = Math.max(max, array[i][prop]);
-    }
-    return max;
-}
-
-function minProperty(array, prop) {
-    var min = 0;
-    for (var i=0; i<array.length; i++) {
-        min = Math.min(min, array[i][prop]);
-    }
-    return min;
-}

+ 0 - 1
package/contents/ui/ConfigfileTab.qml

@@ -21,7 +21,6 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.2
 import QtQuick.Layouts 1.1
-import "../scripts/arrayfunctions.js" as ArrayFunctions
 
 
 ColumnLayout {

+ 0 - 1
package/contents/ui/KCM.qml

@@ -23,7 +23,6 @@ import QtQuick.Controls 1.3
 import QtQuick.Layouts 1.1
 import QtQuick.Dialogs 1.2
 import org.kde.kcm 1.0
-import "../scripts/arrayfunctions.js" as ArrayFunctions
 import "../scripts/units.js" as Units
 
 

+ 8 - 18
package/contents/ui/PwmFan.qml

@@ -21,7 +21,6 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.4
 import QtQuick.Layouts 1.1
-import "../scripts/arrayfunctions.js" as ArrayFunctions
 import "../scripts/math.js" as MoreMath
 import "../scripts/units.js" as Units
 import "../scripts/colors.js" as Colors
@@ -29,16 +28,14 @@ import "../scripts/colors.js" as Colors
 
 Rectangle {
     property QtObject fan
-    property QtObject loader
     property QtObject systemdCom
+    property QtObject tempModel
     property real minTemp: 40.0
     property real maxTemp: 90.0
     property int margin: 5
-    property int minimizeDuration: 400
     property int unit: 0
     property real convertedMinTemp: Units.fromCelsius(minTemp, unit)
     property real convertedMaxTemp: Units.fromCelsius(maxTemp, unit)
-    readonly property alias name: nameField.text
 
     id: root
     color: "transparent"
@@ -51,22 +48,14 @@ Rectangle {
         if (fan) {
             hasTempCheckBox.checked = Qt.binding(function() { return fan.hasTemp; })
             fanOffCheckBox.checked = Qt.binding(function() { return (fan.minPwm == 0); })
-            if (fan.hasTemp && loader) {
-                tempBox.currentIndex = loader.allTemps.indexOf(fan.temp);
-            }
         }
         bgCanvas.requestPaint();
     }
 
     onFanChanged: update();
-    onLoaderChanged: update()
-    onConvertedMinTempChanged: if (fan) bgCanvas.requestPaint()
-    onConvertedMaxTempChanged: if (fan) bgCanvas.requestPaint()
-
-    Connections {
-        target: loader
-        onConfigUrlChanged: update()
-    }
+    onMinTempChanged: if (fan) bgCanvas.requestPaint()
+    onMaxTempChanged: if (fan) bgCanvas.requestPaint()
+    onUnitChanged: if (fan) bgCanvas.requestRepaint()
 
     SystemPalette {
         id: palette
@@ -341,7 +330,7 @@ Rectangle {
                 onCheckedChanged: {
                     fan.hasTemp = checked;
                     if (checked) {
-                        fan.temp = loader.allTemps[tempBox.currentIndex];
+                        fan.temp = tempModel.temps[tempBox.currentIndex];
                     }
                     bgCanvas.requestPaint();
                 }
@@ -350,11 +339,12 @@ Rectangle {
                 ComboBox {
                     id: tempBox
                     Layout.fillWidth: true
-                    model: ArrayFunctions.namesWithPaths(loader.allTemps)
+                    model: tempModel
+                    textRole: "display"
                     enabled: hasTempCheckBox.checked
                     onCurrentIndexChanged: {
                         if (hasTempCheckBox.checked)
-                            fan.temp = loader.allTemps[currentIndex];
+                            fan.temp = tempModel.temps[currentIndex];
                     }
                 }
             }

+ 12 - 21
package/contents/ui/PwmFansTab.qml

@@ -21,13 +21,15 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.4
 import QtQuick.Layouts 1.2
-import "../scripts/arrayfunctions.js" as ArrayFunctions
 
 
 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 : null
 
     id: root
     anchors.fill: parent
@@ -35,7 +37,7 @@ ColumnLayout {
 
     RowLayout {
         width: parent.width
-        visible: loader && loader.allPwmFans.length > 0
+        visible: loader && pwmFanModel.count > 0
 
         Label {
             text: i18n("Fan:")
@@ -44,15 +46,8 @@ ColumnLayout {
         }
         ComboBox {
             id: fanComboBox
-            model: ListModel {
-                property var fans: loader.allPwmFans
-                id: fanList
-                Component.onCompleted: {
-                    for (var i=0; i<fans.length; i++) {
-                        fanList.append({"text": ArrayFunctions.nameWithPath(fans[i])});
-                    }
-                }
-            }
+            model: pwmFanModel
+            textRole: "display"
             Layout.fillWidth: true
             Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
         }
@@ -65,19 +60,15 @@ ColumnLayout {
     Loader {
         Layout.fillHeight: true
         Layout.fillWidth: true
-        active: !!baseObject.loader.allPwmFans[fanComboBox.currentIndex]
+        active: !!loader && !!systemdCom && !!pwmFans[fanComboBox.currentIndex]
+
         sourceComponent: PwmFan {
             unit: baseObject.unit
-            fan: loader.allPwmFans[fanComboBox.currentIndex]
-            loader: root.loader
-            systemdCom: baseObject.systemdCom
+            fan: pwmFans[fanComboBox.currentIndex]
+            tempModel: root.tempModel
+            systemdCom: root.systemdCom
             minTemp: baseObject.minTemp
             maxTemp: baseObject.maxTemp
-            onNameChanged: {
-                if (fanComboBox.currentText != ArrayFunctions.nameWithPath(fan)) {
-                    fanList.setProperty(fanComboBox.currentIndex, "text", ArrayFunctions.nameWithPath(fan));
-                }
-            }
         }
     }
 
@@ -85,7 +76,7 @@ ColumnLayout {
         id: noFansInfo
         anchors.centerIn: parent
         spacing: 20
-        visible: loader.allPwmFans.length == 0
+        visible: pwmFanModel.count == 0
 
         Label {
             Layout.alignment: Qt.AlignCenter

+ 0 - 1
package/contents/ui/SensorsTab.qml

@@ -21,7 +21,6 @@
 import QtQuick 2.4
 import QtQuick.Controls 1.2
 import QtQuick.Layouts 1.1
-import "../scripts/arrayfunctions.js" as ArrayFunctions
 
 
 RowLayout {

+ 0 - 1
package/contents/ui/SettingsTab.qml

@@ -22,7 +22,6 @@ import QtQuick 2.4
 import QtQuick.Layouts 1.1
 import QtQuick.Controls 1.2
 import QtQml 2.2
-import "../scripts/arrayfunctions.js" as ArrayFunctions
 import "../scripts/units.js" as Units
 
 

+ 1 - 8
package/contents/ui/StatusPoint.qml

@@ -29,8 +29,7 @@ Rectangle {
 
     property QtObject fan
     property Item background: parent
-    property real unsmoothedTemp: fan.temp ? fan.temp.value : minTemp
-    property real unscaledTemp: unsmoothedTemp
+    property real unscaledTemp: fan.temp ? fan.temp.value : minTemp
     property real unscaledPwm: fan.pwm
     property var locale: Qt.locale()
     readonly property real centerX: x + width / 2
@@ -38,7 +37,6 @@ Rectangle {
     readonly property point center: Qt.point(centerX, centerY)
     property int size: 10
     property int unit: 0
-    property int smoothing: 2
 
     width: size
     height: size
@@ -47,11 +45,6 @@ Rectangle {
     y: background.scaleY(unscaledPwm) - height/2
     color: "black"
 
-    onUnsmoothedTempChanged: {
-        root.unscaledTemp = (root.unscaledTemp * smoothing + root.unsmoothedTemp) / (smoothing + 1);
-        console.log(root.unscaledTemp);
-    }
-
     Behavior on unscaledTemp {
         SpringAnimation {
             epsilon: 0.1