forked from FelixdelasPozas/TrayWeather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrayWeather.h
148 lines (121 loc) · 4.14 KB
/
TrayWeather.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
File: TrayWeather.h
Created on: 13/11/2016
Author: Felix de las Pozas Alvarez
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 3 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 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/>.
*/
#ifndef TRAYWEATHER_H_
#define TRAYWEATHER_H_
// Project
#include <ConfigurationDialog.h>
#include <Utils.h>
#include <WeatherDialog.h>
// Qt
#include <QSystemTrayIcon>
#include <QTimer>
class QNetworkReply;
class QNetworkAccessManager;
class AboutDialog;
/** \class TrayWeather
* \brief Implements the tray icon and application logic.
*
*/
class TrayWeather
: public QSystemTrayIcon
{
Q_OBJECT
public:
/** \brief TrayWeather class constructor.
* \param[in] configuration application configuration values, assumed to be valid.
* \param[in] parent pointer to the object parent of this one.
*
*/
TrayWeather(Configuration &configuration, QObject *parent = nullptr);
/** \brief TrayWeather class virtual destructor.
*
*/
virtual ~TrayWeather();
private slots:
/** \brief Handles network replies.
* \param[in] reply network reply object pointer.
*
*/
void replyFinished(QNetworkReply *reply);
/** \brief Exits the application.
*
*/
void exitApplication();
/** \brief Shows the "About" dialog.
*
*/
void showAboutDialog();
/** \brief Shows the weather forecast.
*
*/
void showForecast();
/** \brief Shows the configuration dialog.
*
*/
void showConfiguration();
/** \brief Handles icon activation.
* \param[in] reason activation reason.
*
*/
void onActivation(QSystemTrayIcon::ActivationReason reason);
/** \brief Makes a network request for weather forecast data or geolocation.
*
*/
void requestData();
private:
/** \brief Updates the tray icon tooltip.
*
*/
void updateTooltip();
/** \brief Helper method to connect all the signals and slots.
*
*/
void connectSignals();
/** \brief Helper method to disconnect all the signals and slots.
*
*/
void disconnectSignals();
/** \brief Creates the tray icon menu.
*
*/
void createMenuEntries();
/** \brief Returns true if the data is valid.
*
*/
bool validData() const;
/** \brief Invalidates all weather data.
*
*/
void invalidateData();
/** \brief Request geolocation information, can ask for DNS IP first if enabled on configuration.
*
*/
void requestGeolocation();
/** \brief Request weather data from network.
*
*/
void requestForecastData();
Configuration &m_configuration; /** application configuration. */
std::shared_ptr<QNetworkAccessManager> m_netManager; /** network manager. */
Forecast m_data; /** list of forecast data. */
ForecastData m_current; /** weather conditions now. */
QTimer m_timer; /** timer for updates and retries. */
WeatherDialog *m_weatherDialog; /** dialog to show weather and forecast data. */
AboutDialog *m_aboutDialog; /** pointer to current (if any) about dialog. */
ConfigurationDialog *m_configDialog; /** pointer to current (if any) configuration dialog. */
QString m_DNSIP; /** DNS IP used for geolocation. */
};
#endif // TRAYWEATHER_H_