aboutsummaryrefslogtreecommitdiff
path: root/src/automatictheme.cpp
diff options
context:
space:
mode:
authorLibravatar Keshav Bhatt <keshavnrj@gmail.com>2022-02-28 18:08:28 +0530
committerLibravatar Keshav Bhatt <keshavnrj@gmail.com>2022-02-28 18:08:28 +0530
commit9867a6b6279229d53fe59854a511c9eea9888427 (patch)
treecefdf3aa78e35741100a554f0fc25d75c4ef3065 /src/automatictheme.cpp
parent020ac6daeac226da90bc0c884a9b22a7da9baa99 (diff)
downloadwhatsie-9867a6b6279229d53fe59854a511c9eea9888427.tar.gz
whatsie-9867a6b6279229d53fe59854a511c9eea9888427.zip
build: migrate to qt 5.15
Diffstat (limited to 'src/automatictheme.cpp')
-rw-r--r--src/automatictheme.cpp171
1 files changed, 86 insertions, 85 deletions
diff --git a/src/automatictheme.cpp b/src/automatictheme.cpp
index b538244..6e14623 100644
--- a/src/automatictheme.cpp
+++ b/src/automatictheme.cpp
@@ -4,113 +4,114 @@
#include "SunClock.hpp"
#include <QMessageBox>
-AutomaticTheme::AutomaticTheme(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::AutomaticTheme)
-{
- ui->setupUi(this);
- ui->refresh->setEnabled(false);
+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());
+ sunrise.setSecsSinceEpoch(settings.value("sunrise").toLongLong());
+ sunset.setSecsSinceEpoch(settings.value("sunset").toLongLong());
- ui->sunrise->setTime(sunrise.time());
- ui->sunset->setTime(sunset.time());
+ ui->sunrise->setTime(sunrise.time());
+ ui->sunset->setTime(sunset.time());
- QTimeZone zone = QTimeZone::systemTimeZone();
- QDateTime dt = QDateTime::currentDateTime();
+ QTimeZone zone = QTimeZone::systemTimeZone();
+ QDateTime dt = QDateTime::currentDateTime();
- if(zone.isValid()){
- hour_offset = (double)zone.standardTimeOffset(dt)/(double)3600;
- }else{
- settings.setValue("automaticTheme",false);
- QMessageBox::critical(this,"Error","Unable to get system TimeZone information.\n\nAutomatic theme switcher will not work.");
- return;
- }
+ if (zone.isValid()) {
+ hour_offset = (double)zone.standardTimeOffset(dt) / (double)3600;
+ } else {
+ settings.setValue("automaticTheme", false);
+ QMessageBox::critical(
+ this, "Error",
+ "Unable to get system TimeZone information.\n\nAutomatic theme "
+ "switcher will not work.");
+ return;
+ }
- gPosInfoSrc = QGeoPositionInfoSource::createDefaultSource(this);
+ gPosInfoSrc = QGeoPositionInfoSource::createDefaultSource(this);
- if (gPosInfoSrc) // sudo apt install geoclue-2.0
- {
- ui->refresh->setEnabled(true);
- connect(gPosInfoSrc,&QGeoPositionInfoSource::positionUpdated,[=](const QGeoPositionInfo &update){
- QGeoCoordinate cor = update.coordinate();
- if(cor.isValid())
- {
+ if (gPosInfoSrc) // sudo apt install geoclue-2.0
+ {
+ ui->refresh->setEnabled(true);
+ connect(gPosInfoSrc, &QGeoPositionInfoSource::positionUpdated,
+ [=](const QGeoPositionInfo &update) {
+ QGeoCoordinate cor = update.coordinate();
+ if (cor.isValid()) {
this->lon = cor.longitude();
this->lat = cor.latitude();
ui->refresh->setEnabled(true);
gPosInfoSrc->stopUpdates();
- }else{
+ } else {
ui->refresh->setEnabled(false);
- }
- });
- connect(gPosInfoSrc,&QGeoPositionInfoSource::updateTimeout,[=](){
- if(!settings.value("sunrise").isValid() || !settings.value("sunset").isValid())
- {
- if(ui->refresh->isEnabled())
- ui->refresh->click();
- }
- });
- gPosInfoSrc->startUpdates();
- }else{
- ui->refresh->setEnabled(false);
- settings.setValue("automaticTheme",false);
- QMessageBox::critical(this,"Error","Unable to initialize QGeoPositionInfoSource.\n\nAutomatic theme switcher will not work."
- "\n\nPlease fill the sunset and sunrise time manually.");
- }
+ }
+ });
+ connect(gPosInfoSrc, &QGeoPositionInfoSource::updateTimeout, [=]() {
+ if (!settings.value("sunrise").isValid() ||
+ !settings.value("sunset").isValid()) {
+ if (ui->refresh->isEnabled())
+ ui->refresh->click();
+ }
+ });
+ gPosInfoSrc->startUpdates();
+ } else {
+ ui->refresh->setEnabled(false);
+ settings.setValue("automaticTheme", false);
+ QMessageBox::critical(
+ this, "Error",
+ "Unable to initialize QGeoPositionInfoSource.\n\nAutomatic theme "
+ "switcher will not work."
+ "\n\nPlease fill the sunset and sunrise time manually.");
+ }
}
-AutomaticTheme::~AutomaticTheme()
-{
- gPosInfoSrc->disconnect();
- gPosInfoSrc->deleteLater();
- delete ui;
+AutomaticTheme::~AutomaticTheme() {
+ gPosInfoSrc->disconnect();
+ gPosInfoSrc->deleteLater();
+ delete ui;
}
-void AutomaticTheme::on_refresh_clicked()
-{
- QGeoCoordinate geoCor = QGeoCoordinate(this->lat,this->lon);
- 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()));
+void AutomaticTheme::on_refresh_clicked() {
+ QGeoCoordinate geoCor = QGeoCoordinate(this->lat, this->lon);
+ 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()));
- ui->sunrise->setTime(sunrise.time());
- ui->sunset->setTime(sunset.time());
- }else{
- settings.setValue("automaticTheme",false);
- QMessageBox::critical(this,"Error","Invalid Geo-Coordinates.\n\nPlease try again.");
- }
+ ui->sunrise->setTime(sunrise.time());
+ ui->sunset->setTime(sunset.time());
+ } else {
+ 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.");
- //this->close();
- }else{
- settings.setValue("sunrise",sunrise.toSecsSinceEpoch());
- settings.setValue("sunset",sunset.toSecsSinceEpoch());
- settings.setValue("automaticTheme",true);
- this->close();
- }
+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.");
+ } else {
+ settings.setValue("sunrise", sunrise.toSecsSinceEpoch());
+ settings.setValue("sunset", sunset.toSecsSinceEpoch());
+ settings.setValue("automaticTheme", true);
+ this->close();
+ }
}
-void AutomaticTheme::on_cancel_clicked()
-{
- settings.setValue("automaticTheme",false);
- this->close();
+void AutomaticTheme::on_cancel_clicked() {
+ settings.setValue("automaticTheme", false);
+ this->close();
}
-void AutomaticTheme::on_sunrise_timeChanged(const QTime &time)
-{
- sunrise.setTime(QTime(time.hour(),time.minute(),0));
+void AutomaticTheme::on_sunrise_timeChanged(const QTime &time) {
+ sunrise.setTime(QTime(time.hour(), time.minute(), 0));
}
-void AutomaticTheme::on_sunset_timeChanged(const QTime &time)
-{
- sunset.setTime(QTime(time.hour(),time.minute(),0));
+void AutomaticTheme::on_sunset_timeChanged(const QTime &time) {
+ sunset.setTime(QTime(time.hour(), time.minute(), 0));
}