-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
58 lines (48 loc) · 1.68 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <thread>
#include <chrono>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Configure weather forecast stuff
auto url = QUrl("https://www.yr.no/stad/Noreg/Vestland/Bergen/Nesttun/varsel.xml");
this->forecast = new YrForecast(url, &this->networkmanager, this);
connect(this->forecast, &YrForecast::forecastUpdated,
this, &MainWindow::updateForecast);
connect(this->forecast, &YrForecast::symbolUpdated,
this, &MainWindow::updateForecastSymbol);
this->forecast->startTimer();
// Configure sensor API
QString secretsFile("/home/endre/Programmering/Qt/DTKiosk/auth.json");
this->dtAuth = new DTAuth(secretsFile, &this->networkmanager, this);
this->sensor = new DTSensor("bdoktet7rihjbm0413a0", "bfn87ac77eqnkh13caf0",
this->dtAuth, &this->networkmanager, this);
connect(this->dtAuth, &DTAuth::authenticated,
this->sensor, &DTSensor::downloadData);
ui->indoor->setText("24.3°C");
ui->outdoor->setText("11.4°C");
// Configure power consumption stuff
ui->power->setText("5600 W");
this->dtAuth->authenticate();
}
MainWindow::~MainWindow()
{
delete ui;
delete forecast;
}
void MainWindow::updateForecast(QString temp, QString precip, QString time)
{
ui->forecastTemp->setText(temp);
ui->forecastPrecip->setText(precip);
ui->forecastTime->setText(time);
}
void MainWindow::updateForecastSymbol(QByteArray data)
{
auto pix = QPixmap();
pix.loadFromData(data, "PNG");
ui->forecastSymbol->setPixmap(pix);
}