Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ocupdater.h « updater « src - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3201e7c812b37d6b95387981abaa7a344ce377bb (plain)
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
/*
 * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
 *
 * 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 2 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.
 */

#ifndef OCUPDATER_H
#define OCUPDATER_H

#include <QObject>
#include <QUrl>
#include <QTemporaryFile>

#include "updater/updateinfo.h"
#include "updater/updater.h"

class QNetworkAccessManager;
class QNetworkReply;
class QTimer;

namespace Mirall {

/** @short Class that uses an ownCloud propritary XML format to fetch update information */
class OCUpdater : public QObject, public Updater
{
    Q_OBJECT
public:
    enum DownloadState { Unknown = 0, CheckingServer, UpToDate,
                         Downloading, DownloadComplete,
                         DownloadFailed, DownloadTimedOut,
                         UpdateOnlyAvailableThroughSystem };
    explicit OCUpdater(const QUrl &url, QObject *parent = 0);

    bool performUpdate();

    void checkForUpdate() Q_DECL_OVERRIDE;
    void backgroundCheckForUpdate() Q_DECL_OVERRIDE;

    QString statusString() const;
    int downloadState() const;
    void setDownloadState(DownloadState state);

signals:
    void downloadStateChanged();

public slots:
    void slotStartInstaller();

private slots:
    void slotOpenUpdateUrl();
    void slotVersionInfoArrived();
    void slotTimedOut();

protected:
    virtual void versionInfoArrived(const UpdateInfo &info) = 0;
    bool updateSucceeded() const;
    QNetworkAccessManager* qnam() const { return _accessManager; }
    UpdateInfo updateInfo() const { return _updateInfo; }
private:
    QUrl _updateUrl;
    int _state;
    QNetworkAccessManager *_accessManager;
    QTimer *_timer;
    UpdateInfo _updateInfo;
};

/** Windows Updater Using NSIS */
class NSISUpdater : public OCUpdater {
    Q_OBJECT
public:
    enum UpdateState { NoUpdate = 0, UpdateAvailable, UpdateFailed };
    explicit NSISUpdater(const QUrl &url, QObject *parent = 0);
    bool handleStartup() Q_DECL_OVERRIDE;
private slots:
    void slotSetSeenVersion();
    void slotDownloadFinished();
    void slotWriteFile();
private:
    NSISUpdater::UpdateState updateStateOnStart();
    void showDialog(const UpdateInfo &info);
    void versionInfoArrived(const UpdateInfo &info) Q_DECL_OVERRIDE;
    QScopedPointer<QTemporaryFile> _file;
    QString _targetFile;
    bool _showFallbackMessage;

};

/** Passive updater: Only implements notification for use in settings.
    Does not do popups */
class PassiveUpdateNotifier : public OCUpdater {
    Q_OBJECT
public:
    explicit PassiveUpdateNotifier(const QUrl &url, QObject *parent = 0);
    bool handleStartup() Q_DECL_OVERRIDE { return false; }

private:
    void versionInfoArrived(const UpdateInfo &info) Q_DECL_OVERRIDE;
};



}

#endif // OC_UPDATER