loader.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <QUrl>
  23. #include <QTimer>
  24. #include "hwmon.h"
  25. #include "fancontrol_gui_lib_export.h"
  26. class Hwmon;
  27. class FANCONTROL_GUI_LIB_EXPORT Loader : public QObject
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY(QUrl configUrl READ configUrl NOTIFY configUrlChanged)
  31. Q_PROPERTY(QString configFile READ configFile NOTIFY configFileChanged)
  32. Q_PROPERTY(QList<QObject *> hwmons READ hwmons NOTIFY hwmonsChanged)
  33. Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
  34. Q_PROPERTY(QString error READ error NOTIFY errorChanged)
  35. public:
  36. explicit Loader(QObject *parent = 0);
  37. Q_INVOKABLE void parseHwmons();
  38. Q_INVOKABLE void load(const QUrl & = QUrl());
  39. Q_INVOKABLE void save(const QUrl & = QUrl());
  40. Q_INVOKABLE void testFans();
  41. QUrl configUrl() const { return m_configUrl; }
  42. QString configFile() const { return m_configFile; }
  43. QList<QObject *> hwmons() const;
  44. int interval() { return m_interval; }
  45. void setInterval(int interval) { if (interval != m_interval) { m_interval = interval; emit intervalChanged(m_interval*1000); createConfigFile(); } }
  46. Hwmon * hwmon(int i) { return m_hwmons.value(i, Q_NULLPTR); }
  47. QString error() const { return m_error; }
  48. static int getHwmonNumber(const QString &str) { return str.split('/').value(0).remove("hwmon").toInt(); }
  49. static int getSensorNumber(const QString &str) { return str.split('/').value(1).remove(QRegExp("pwm|fan|temp|_input")).toInt() - 1; }
  50. public slots:
  51. void updateSensors() { emit sensorsUpdateNeeded(); }
  52. protected slots:
  53. void createConfigFile();
  54. protected:
  55. bool m_parsed;
  56. int m_interval;
  57. QList<Hwmon *> m_hwmons;
  58. QUrl m_configUrl;
  59. QString m_configFile;
  60. QString m_error;
  61. QTimer m_timer;
  62. signals:
  63. void configUrlChanged();
  64. void configFileChanged();
  65. void hwmonsChanged();
  66. void intervalChanged(int);
  67. void errorChanged();
  68. void sensorsUpdateNeeded();
  69. };
  70. #endif // LOADER_H