/* * Copyright (C) 2015 Malte Veerman * * 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. * */ #ifndef LOADER_H #define LOADER_H #include #include #include #include #include class QTimer; class KJob; class QProcess; namespace Fancontrol { class Hwmon; class PwmFan; class Temp; class GUIBase; class Loader : public QObject { Q_OBJECT Q_PROPERTY(QUrl configUrl READ configUrl NOTIFY configUrlChanged) Q_PROPERTY(QString configFile READ configFile NOTIFY configFileChanged) Q_PROPERTY(QList hwmons READ hwmonsAsObjects NOTIFY hwmonsChanged) Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged) Q_PROPERTY(bool sensorsDetected READ sensorsDetected NOTIFY sensorsDetectedChanged) Q_PROPERTY(bool restartServiceAfterTesting READ restartServiceAfterTesting WRITE setRestartServiceAfterTesting NOTIFY restartServiceAfterTestingChanged) public: explicit Loader(GUIBase *parent = Q_NULLPTR); Q_INVOKABLE void parseHwmons(); Q_INVOKABLE bool load(const QUrl & = QUrl()); Q_INVOKABLE bool save(const QUrl & = QUrl()); Q_INVOKABLE void testFans(); Q_INVOKABLE void abortTestingFans(); Q_INVOKABLE void detectSensors(); QUrl configUrl() const { return m_configUrl; } QString configFile() const { return m_configFile; } QList hwmons() const { return m_hwmons; } bool sensorsDetected() const { return m_sensorsDetected; } bool restartServiceAfterTesting() const { return m_reactivateAfterTesting; } void setRestartServiceAfterTesting(bool restart); QList hwmonsAsObjects() const; int interval() const { return m_interval; } void setInterval(int interval, bool writeNewConfig = true); public slots: void updateSensors() { emit sensorsUpdateNeeded(); } void updateConfig(); void emitAllPwmFansChanged() { emit allPwmFansChanged(); } void emitAllTempsChanged() { emit allTempsChanged(); } void handleDetectSensorsResult(KJob *job); void handleDetectSensorsResult(int exitCode); void handleTestStatusChanged(); private: void parseConfigLine(const QString &line, void (PwmFan::*memberSetFunction)(int value)); QPair getEntryNumbers(const QString &entry); QString createConfig() const; PwmFan *getPwmFan(const QPair &indexPair) const; Temp *getTemp(const QPair &indexPair) const; bool m_reactivateAfterTesting; int m_interval; QList m_hwmons; QUrl m_configUrl; QString m_configFile; QTimer *m_timer; bool m_sensorsDetected; signals: void configUrlChanged(); void configFileChanged(); void hwmonsChanged(); void intervalChanged(); void error(QString, bool = false); void sensorsUpdateNeeded(); void allPwmFansChanged(); void allTempsChanged(); void invalidConfigUrl(); void sensorsDetectedChanged(); void restartServiceAfterTestingChanged(); void requestSetServiceActive(bool); }; } #endif // LOADER_H