File: UpdateChecker.h

package info (click to toggle)
flightcrew 0.9.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 6,748 kB
  • sloc: cpp: 53,736; xml: 2,006; ansic: 275; python: 215; sh: 112; makefile: 8; exp: 8
file content (118 lines) | stat: -rw-r--r-- 3,575 bytes parent folder | download | duplicates (3)
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
/************************************************************************
**
**  Copyright (C) 2010  Strahinja Markovic
**
**  This file is part of FlightCrew.
**
**  FlightCrew is free software: you can redistribute it and/or modify
**  it under the terms of the GNU Lesser General Public License as published
**  by the Free Software Foundation, either version 3 of the License, or
**  (at your option) any later version.
**
**  FlightCrew 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 Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public License
**  along with FlightCrew.  If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/

#pragma once
#ifndef UPDATECHECKER_H
#define UPDATECHECKER_H

#include <QObject>

class QNetworkAccessManager;
class QNetworkReply;

/**
 * Responsible for checking the current online version of
 * FlightCrew against the running one. If a newer version
 * exists, then a dialog is displayed informing the user
 * about it.
 *
 * Objects of this class should ALWAYS be created on the heap
 * and never explicitly deleted. The reason is that these objects
 * receive replies asynchronously from the web and need to persist.
 * Upon receiving and processing the network reply, the object
 * schedules its own deletion.
 */
class UpdateChecker : QObject
{
    Q_OBJECT

public:

    /**
     * Constructor.
     *
     * @param parent The object's parent.
     */
    UpdateChecker( QObject *parent );

    /**
     * Sends a request for the online version
     * if the last check was performed
     * a SECONDS_BETWEEN_CHECKS amount of time ago.
     */
    void CheckForUpdate();

private slots:

    /**
     * Gets called when the request posted by CheckForUpdate() 
     * gets a reply from the server.
     *
     * @param reply The network reply.
     */
    void ReplyRecieved( QNetworkReply* reply );

private:

    /**
     * Extracts the full text present in the network reply.
     *
     * @param reply The reply from which text should be extracted.
     * @return The full text content.
     */
    QString TextInReply( QNetworkReply* reply ) const;

    /**
     * Returns the version string present 
     * in the specified XML file, or an empty QString
     * if the required element is not present.
     *
     * @param online_version_xml The xml content from the reply.
     * @return The version string.
     */
    QString ReadOnlineVersion( const QString &online_version_xml ) const;

    /**
     * Compares the two provided version strings.
     *
     * @param current_version_string The version of the running program.
     * @param online_version_string The newest version.
     * @return \c true if the online string specifies
     *         that the online version is newer.
     */
    bool IsOnlineVersionNewer( const QString &current_version_string, 
                               const QString &online_version_string ) const;


    ///////////////////////////////
    // PRIVATE MEMBER VARIABLES
    ///////////////////////////////

    /**
     * The network manager used to post 
     * network requests and receive replies.
     */ 
    QNetworkAccessManager *m_NetworkManager;

};

#endif // UPDATECHECKER_H