123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /*
- * <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 "guibase.h"
- #include "config.h"
- #include "hwmon.h"
- #include <QtQml/qqml.h>
- #include <QtCore/QLocale>
- namespace Fancontrol
- {
- GUIBase::GUIBase(QObject *parent) : QObject(parent),
- m_config(Config::instance()),
- #ifndef NO_SYSTEMD
- m_com(new SystemdCommunicator(this)),
- #endif
- m_loader(new Loader(this)),
- m_configValid(false),
- m_pwmFanModel(new PwmFanModel(this)),
- m_tempModel(new TempModel(this))
- {
- connect(m_config, &Config::configChanged, this, &GUIBase::emitConfigChanged);
- QLocale locale = QLocale::system();
- QLocale::MeasurementSystem system = locale.measurementSystem();
- m_unit = (system == QLocale::MetricSystem) ? 0 : 2;
- qmlRegisterType<Loader>();
- qmlRegisterType<Hwmon>();
- qmlRegisterType<Fan>();
- qmlRegisterType<PwmFan>();
- qmlRegisterType<Temp>();
- #ifndef NO_SYSTEMD
- 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()
- {
- m_config->load();
- m_configValid = m_loader->load(configUrl());
- #ifndef NO_SYSTEMD
- m_com->setServiceName(serviceName());
- #endif
- emitConfigChanged();
- }
- void GUIBase::save(bool saveLoader, const QUrl &url)
- {
- m_config->save();
- if (saveLoader)
- m_loader->save(url);
- }
- qreal GUIBase::maxTemp() const
- {
- return m_config->findItem(QStringLiteral("MaxTemp"))->property().toReal();
- }
- qreal GUIBase::minTemp() const
- {
- return m_config->findItem(QStringLiteral("MinTemp"))->property().toReal();
- }
- QString GUIBase::serviceName() const
- {
- return m_config->findItem(QStringLiteral("ServiceName"))->property().toString();
- }
- QUrl GUIBase::configUrl() const
- {
- return QUrl(m_config->findItem(QStringLiteral("ConfigUrl"))->property().toString());
- }
- void GUIBase::setMaxTemp(qreal temp)
- {
- if (temp != maxTemp())
- {
- m_config->findItem(QStringLiteral("MaxTemp"))->setProperty(temp);
- emit maxTempChanged();
- }
- }
- void GUIBase::setMinTemp(qreal temp)
- {
- if (temp != minTemp())
- {
- m_config->findItem(QStringLiteral("MinTemp"))->setProperty(temp);
- emit minTempChanged();
- }
- }
- void GUIBase::setServiceName(const QString& name)
- {
- if(name != serviceName())
- {
- m_config->findItem(QStringLiteral("ServiceName"))->setProperty(name);
- #ifndef NO_SYSTEMD
- m_com->setServiceName(name);
- #endif
- emit serviceNameChanged();
- }
- }
- void GUIBase::setConfigUrl(const QUrl &url)
- {
- if (url != configUrl())
- {
- m_config->findItem(QStringLiteral("ConfigUrl"))->setProperty(url.toString(QUrl::PreferLocalFile));
- m_configValid = m_loader->load(url);
- emit configUrlChanged();
- }
- }
- void GUIBase::emitConfigChanged()
- {
- emit serviceNameChanged();
- emit minTempChanged();
- emit maxTempChanged();
- emit configUrlChanged();
- }
- }
|