loader.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #ifndef LOADER_H
  20. #define LOADER_H
  21. #include <QObject>
  22. #include <QStringList>
  23. #include <QUrl>
  24. #include <QTimer>
  25. #include "hwmon.h"
  26. #include "export.h"
  27. class Hwmon;
  28. class FANCONTROL_GUI_EXPORT Loader : public QObject
  29. {
  30. Q_OBJECT
  31. Q_PROPERTY(QUrl configUrl READ configUrl WRITE setConfigUrl NOTIFY configUrlChanged)
  32. Q_PROPERTY(QString configFile READ configFile NOTIFY configFileChanged)
  33. Q_PROPERTY(QList<QObject *> hwmons READ hwmons NOTIFY hwmonsChanged)
  34. Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
  35. Q_PROPERTY(QString error READ error NOTIFY errorChanged)
  36. public:
  37. explicit Loader(QObject *parent = 0);
  38. Q_INVOKABLE void parseHwmons();
  39. Q_INVOKABLE void open(const QUrl & = QUrl());
  40. Q_INVOKABLE void save(const QUrl & = QUrl());
  41. Q_INVOKABLE void testFans();
  42. QUrl configUrl() const { return m_configUrl; }
  43. void setConfigUrl(const QUrl &url) { open(url); if (m_configUrl != url) { m_configUrl = url; emit configUrlChanged(); } }
  44. QString configFile() const { return m_configFile; }
  45. QList<QObject *> hwmons() const;
  46. int interval() { return m_interval; }
  47. void setInterval(int interval) { if (interval != m_interval) { m_interval = interval; emit intervalChanged(m_interval*1000); createConfigFile(); } }
  48. Hwmon * hwmon(int i) { return m_hwmons.value(i, nullptr); }
  49. QString error() const { return m_error; }
  50. static int getHwmonNumber(const QString &str) { return str.split('/').value(0).remove("hwmon").toInt(); }
  51. static int getSensorNumber(const QString &str) { return str.split('/').value(1).remove(QRegExp("pwm|fan|temp|_input")).toInt() - 1; }
  52. public slots:
  53. void updateSensors() { emit sensorsUpdateNeeded(); }
  54. protected slots:
  55. void createConfigFile();
  56. protected:
  57. bool m_parsed;
  58. int m_interval;
  59. QList<Hwmon *> m_hwmons;
  60. QUrl m_configUrl;
  61. QString m_configFile;
  62. QString m_error;
  63. QTimer m_timer;
  64. signals:
  65. void configUrlChanged();
  66. void configFileChanged();
  67. void hwmonsChanged();
  68. void intervalChanged(int);
  69. void errorChanged();
  70. void sensorsUpdateNeeded();
  71. };
  72. #endif // LOADER_H