diff options
Diffstat (limited to 'src/automatictheme.cpp')
-rw-r--r-- | src/automatictheme.cpp | 85 |
1 files changed, 45 insertions, 40 deletions
diff --git a/src/automatictheme.cpp b/src/automatictheme.cpp index 3cf33c8..9b1f3e7 100644 --- a/src/automatictheme.cpp +++ b/src/automatictheme.cpp @@ -2,26 +2,27 @@ #include "ui_automatictheme.h" #include "sunclock.hpp" -#include <QMessageBox> AutomaticTheme::AutomaticTheme(QWidget *parent) : QWidget(parent), ui(new Ui::AutomaticTheme) { ui->setupUi(this); ui->refresh->setEnabled(false); - sunrise.setSecsSinceEpoch(settings.value("sunrise").toLongLong()); - sunset.setSecsSinceEpoch(settings.value("sunset").toLongLong()); + m_sunrise.setSecsSinceEpoch( + SettingsManager::instance().settings().value("sunrise").toLongLong()); + m_sunset.setSecsSinceEpoch( + SettingsManager::instance().settings().value("sunset").toLongLong()); - ui->sunrise->setTime(sunrise.time()); - ui->sunset->setTime(sunset.time()); + ui->sunrise->setTime(m_sunrise.time()); + ui->sunset->setTime(m_sunset.time()); QTimeZone zone = QTimeZone::systemTimeZone(); QDateTime dt = QDateTime::currentDateTime(); if (zone.isValid()) { - hour_offset = (double)zone.standardTimeOffset(dt) / (double)3600; + m_hourOffset = (double)zone.standardTimeOffset(dt) / (double)3600; } else { - settings.setValue("automaticTheme", false); + SettingsManager::instance().settings().setValue("automaticTheme", false); QMessageBox::critical( this, "Error", "Unable to get system TimeZone information.\n\nAutomatic theme " @@ -29,34 +30,34 @@ AutomaticTheme::AutomaticTheme(QWidget *parent) return; } - gPosInfoSrc = QGeoPositionInfoSource::createDefaultSource(this); + m_gPosInfoSrc = QGeoPositionInfoSource::createDefaultSource(this); - if (gPosInfoSrc) // sudo apt install geoclue-2.0 + if (m_gPosInfoSrc) // sudo apt install geoclue-2.0 { ui->refresh->setEnabled(true); - connect(gPosInfoSrc, &QGeoPositionInfoSource::positionUpdated, + connect(m_gPosInfoSrc, &QGeoPositionInfoSource::positionUpdated, this, [=](const QGeoPositionInfo &update) { QGeoCoordinate cor = update.coordinate(); if (cor.isValid()) { - this->lon = cor.longitude(); - this->lat = cor.latitude(); + this->m_longitude = cor.longitude(); + this->m_latitube = cor.latitude(); ui->refresh->setEnabled(true); - gPosInfoSrc->stopUpdates(); + m_gPosInfoSrc->stopUpdates(); } else { ui->refresh->setEnabled(false); } }); - connect(gPosInfoSrc, &QGeoPositionInfoSource::updateTimeout, [=]() { - if (!settings.value("sunrise").isValid() || - !settings.value("sunset").isValid()) { + connect(m_gPosInfoSrc, &QGeoPositionInfoSource::updateTimeout, this, [=]() { + if (!SettingsManager::instance().settings().value("sunrise").isValid() || + !SettingsManager::instance().settings().value("sunset").isValid()) { if (ui->refresh->isEnabled()) ui->refresh->click(); } }); - gPosInfoSrc->startUpdates(); + m_gPosInfoSrc->startUpdates(); } else { ui->refresh->setEnabled(false); - settings.setValue("automaticTheme", false); + SettingsManager::instance().settings().setValue("automaticTheme", false); QMessageBox::critical( this, "Error", "Unable to initialize QGeoPositionInfoSource.\n\nAutomatic theme " @@ -66,52 +67,56 @@ AutomaticTheme::AutomaticTheme(QWidget *parent) } AutomaticTheme::~AutomaticTheme() { - gPosInfoSrc->disconnect(); - gPosInfoSrc->deleteLater(); + m_gPosInfoSrc->disconnect(); + m_gPosInfoSrc->deleteLater(); delete ui; } void AutomaticTheme::on_refresh_clicked() { - QGeoCoordinate geoCor = QGeoCoordinate(this->lat, this->lon); + QGeoCoordinate geoCor = QGeoCoordinate(this->m_latitube, this->m_longitude); if (geoCor.isValid()) { - Sunclock sun(this->lat, this->lon, this->hour_offset); - sunrise.setSecsSinceEpoch( - sun.sunrise(QDateTime::currentDateTime().toTime_t())); - sunset.setSecsSinceEpoch( - sun.sunset(QDateTime::currentDateTime().toTime_t())); + Sunclock sun(this->m_latitube, this->m_longitude, this->m_hourOffset); + m_sunrise.setSecsSinceEpoch( + sun.sunrise(QDateTime::currentDateTimeUtc().toTime_t())); + m_sunset.setSecsSinceEpoch( + sun.sunset(QDateTime::currentDateTimeUtc().toTime_t())); - ui->sunrise->setTime(sunrise.time()); - ui->sunset->setTime(sunset.time()); + ui->sunrise->setTime(m_sunrise.time()); + ui->sunset->setTime(m_sunset.time()); } else { - settings.setValue("automaticTheme", false); + SettingsManager::instance().settings().setValue("automaticTheme", false); QMessageBox::critical(this, "Error", "Invalid Geo-Coordinates.\n\nPlease try again."); } } void AutomaticTheme::on_save_clicked() { - if (sunrise.toSecsSinceEpoch() == sunset.toSecsSinceEpoch()) { - settings.setValue("automaticTheme", false); - QMessageBox::critical(this, "Error", - "Invalid settings.\n\nSunrise and Sunset time cannot " - "have similar values.\n\nPlease try again."); + if (m_sunrise.toSecsSinceEpoch() == m_sunset.toSecsSinceEpoch()) { + SettingsManager::instance().settings().setValue("automaticTheme", false); + QMessageBox::critical( + this, "Error", + "Invalid SettingsManager::instance().settings().\n\nSunrise and Sunset " + "time cannot " + "have similar values.\n\nPlease try again."); } else { - settings.setValue("sunrise", sunrise.toSecsSinceEpoch()); - settings.setValue("sunset", sunset.toSecsSinceEpoch()); - settings.setValue("automaticTheme", true); + SettingsManager::instance().settings().setValue( + "sunrise", m_sunrise.toSecsSinceEpoch()); + SettingsManager::instance().settings().setValue( + "sunset", m_sunset.toSecsSinceEpoch()); + SettingsManager::instance().settings().setValue("automaticTheme", true); this->close(); } } void AutomaticTheme::on_cancel_clicked() { - settings.setValue("automaticTheme", false); + SettingsManager::instance().settings().setValue("automaticTheme", false); this->close(); } void AutomaticTheme::on_sunrise_timeChanged(const QTime &time) { - sunrise.setTime(QTime(time.hour(), time.minute(), 0)); + m_sunrise.setTime(QTime(time.hour(), time.minute(), 0)); } void AutomaticTheme::on_sunset_timeChanged(const QTime &time) { - sunset.setTime(QTime(time.hour(), time.minute(), 0)); + m_sunset.setTime(QTime(time.hour(), time.minute(), 0)); } |