]> git.donarmstrong.com Git - flightcrew.git/blob - src/FlightCrew-gui/UpdateChecker.h
update changelog, target experimental
[flightcrew.git] / src / FlightCrew-gui / UpdateChecker.h
1 /************************************************************************\r
2 **\r
3 **  Copyright (C) 2010  Strahinja Markovic\r
4 **\r
5 **  This file is part of FlightCrew.\r
6 **\r
7 **  FlightCrew is free software: you can redistribute it and/or modify\r
8 **  it under the terms of the GNU Lesser General Public License as published\r
9 **  by the Free Software Foundation, either version 3 of the License, or\r
10 **  (at your option) any later version.\r
11 **\r
12 **  FlightCrew is distributed in the hope that it will be useful,\r
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 **  GNU Lesser General Public License for more details.\r
16 **\r
17 **  You should have received a copy of the GNU Lesser General Public License\r
18 **  along with FlightCrew.  If not, see <http://www.gnu.org/licenses/>.\r
19 **\r
20 *************************************************************************/\r
21 \r
22 #pragma once\r
23 #ifndef UPDATECHECKER_H\r
24 #define UPDATECHECKER_H\r
25 \r
26 #include <QObject>\r
27 \r
28 class QNetworkAccessManager;\r
29 class QNetworkReply;\r
30 \r
31 /**\r
32  * Responsible for checking the current online version of\r
33  * FlightCrew against the running one. If a newer version\r
34  * exists, then a dialog is displayed informing the user\r
35  * about it.\r
36  *\r
37  * Objects of this class should ALWAYS be created on the heap\r
38  * and never explicitly deleted. The reason is that these objects\r
39  * receive replies asynchronously from the web and need to persist.\r
40  * Upon receiving and processing the network reply, the object\r
41  * schedules its own deletion.\r
42  */\r
43 class UpdateChecker : QObject\r
44 {\r
45     Q_OBJECT\r
46 \r
47 public:\r
48 \r
49     /**\r
50      * Constructor.\r
51      *\r
52      * @param parent The object's parent.\r
53      */\r
54     UpdateChecker( QObject *parent );\r
55 \r
56     /**\r
57      * Sends a request for the online version\r
58      * if the last check was performed\r
59      * a SECONDS_BETWEEN_CHECKS amount of time ago.\r
60      */\r
61     void CheckForUpdate();\r
62 \r
63 private slots:\r
64 \r
65     /**\r
66      * Gets called when the request posted by CheckForUpdate() \r
67      * gets a reply from the server.\r
68      *\r
69      * @param reply The network reply.\r
70      */\r
71     void ReplyRecieved( QNetworkReply* reply );\r
72 \r
73 private:\r
74 \r
75     /**\r
76      * Extracts the full text present in the network reply.\r
77      *\r
78      * @param reply The reply from which text should be extracted.\r
79      * @return The full text content.\r
80      */\r
81     QString TextInReply( QNetworkReply* reply ) const;\r
82 \r
83     /**\r
84      * Returns the version string present \r
85      * in the specified XML file, or an empty QString\r
86      * if the required element is not present.\r
87      *\r
88      * @param online_version_xml The xml content from the reply.\r
89      * @return The version string.\r
90      */\r
91     QString ReadOnlineVersion( const QString &online_version_xml ) const;\r
92 \r
93     /**\r
94      * Compares the two provided version strings.\r
95      *\r
96      * @param current_version_string The version of the running program.\r
97      * @param online_version_string The newest version.\r
98      * @return \c true if the online string specifies\r
99      *         that the online version is newer.\r
100      */\r
101     bool IsOnlineVersionNewer( const QString &current_version_string, \r
102                                const QString &online_version_string ) const;\r
103 \r
104 \r
105     ///////////////////////////////\r
106     // PRIVATE MEMBER VARIABLES\r
107     ///////////////////////////////\r
108 \r
109     /**\r
110      * The network manager used to post \r
111      * network requests and receive replies.\r
112      */ \r
113     QNetworkAccessManager *m_NetworkManager;\r
114 \r
115 };\r
116 \r
117 #endif // UPDATECHECKER_H\r
118 \r