2014-01-15 14:08:42 +04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-01-28 12:59:59 +04:00
|
|
|
#ifndef OCUPDATER_H
|
|
|
|
#define OCUPDATER_H
|
2014-01-15 14:08:42 +04:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
|
2014-01-29 13:38:12 +04:00
|
|
|
#include "updater/updateinfo.h"
|
|
|
|
#include "updater/updater.h"
|
2014-01-15 14:08:42 +04:00
|
|
|
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
2014-01-28 16:34:46 +04:00
|
|
|
class QTimer;
|
2014-01-15 14:08:42 +04:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
2014-01-28 12:59:59 +04:00
|
|
|
/** @short Class that uses an ownCloud propritary XML format to fetch update information */
|
|
|
|
class OCUpdater : public QObject, public Updater
|
2014-01-15 14:08:42 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-01-28 12:59:59 +04:00
|
|
|
enum DownloadState { Unknown = 0, UpToDate, Downloading, DownloadComplete,
|
2014-01-28 16:34:46 +04:00
|
|
|
DownloadFailed, DownloadTimedOut,
|
|
|
|
UpdateOnlyAvailableThroughSystem };
|
2014-01-28 12:59:59 +04:00
|
|
|
explicit OCUpdater(const QUrl &url, QObject *parent = 0);
|
2014-01-15 14:08:42 +04:00
|
|
|
|
2014-01-29 12:58:25 +04:00
|
|
|
bool performUpdate();
|
2014-01-15 14:08:42 +04:00
|
|
|
|
2014-07-10 01:22:28 +04:00
|
|
|
void checkForUpdate() Q_DECL_OVERRIDE;
|
|
|
|
void backgroundCheckForUpdate() Q_DECL_OVERRIDE;
|
2014-01-15 14:08:42 +04:00
|
|
|
|
|
|
|
QString statusString() const;
|
2014-01-28 12:59:59 +04:00
|
|
|
int downloadState() const;
|
2014-01-28 14:01:05 +04:00
|
|
|
void setDownloadState(DownloadState state);
|
2014-01-15 14:08:42 +04:00
|
|
|
|
|
|
|
signals:
|
2014-01-28 14:01:05 +04:00
|
|
|
void downloadStateChanged();
|
2014-01-15 14:08:42 +04:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void slotStartInstaller();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void slotOpenUpdateUrl();
|
|
|
|
void slotVersionInfoArrived();
|
2014-01-28 16:34:46 +04:00
|
|
|
void slotTimedOut();
|
2014-01-15 14:08:42 +04:00
|
|
|
|
2014-01-28 12:59:59 +04:00
|
|
|
protected:
|
|
|
|
virtual void versionInfoArrived(const UpdateInfo &info) = 0;
|
2014-01-15 14:08:42 +04:00
|
|
|
bool updateSucceeded() const;
|
2014-01-28 12:59:59 +04:00
|
|
|
QNetworkAccessManager* qnam() const { return _accessManager; }
|
2014-01-31 15:42:00 +04:00
|
|
|
UpdateInfo updateInfo() const { return _updateInfo; }
|
2014-01-28 12:59:59 +04:00
|
|
|
private:
|
2014-01-15 14:08:42 +04:00
|
|
|
QUrl _updateUrl;
|
2014-01-28 12:59:59 +04:00
|
|
|
int _state;
|
2014-01-15 14:08:42 +04:00
|
|
|
QNetworkAccessManager *_accessManager;
|
2014-01-28 16:34:46 +04:00
|
|
|
QTimer *_timer;
|
2014-01-15 14:08:42 +04:00
|
|
|
UpdateInfo _updateInfo;
|
2014-01-28 12:59:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/** 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);
|
2014-07-10 01:22:28 +04:00
|
|
|
bool handleStartup() Q_DECL_OVERRIDE;
|
2014-01-28 12:59:59 +04:00
|
|
|
private slots:
|
2014-01-31 15:42:00 +04:00
|
|
|
void slotSetSeenVersion();
|
2014-01-28 12:59:59 +04:00
|
|
|
void slotDownloadFinished();
|
|
|
|
void slotWriteFile();
|
|
|
|
private:
|
2014-01-31 17:49:10 +04:00
|
|
|
NSISUpdater::UpdateState updateStateOnStart();
|
2014-01-28 12:59:59 +04:00
|
|
|
void showDialog(const UpdateInfo &info);
|
2014-07-10 01:22:28 +04:00
|
|
|
void versionInfoArrived(const UpdateInfo &info) Q_DECL_OVERRIDE;
|
2014-01-15 14:08:42 +04:00
|
|
|
QScopedPointer<QTemporaryFile> _file;
|
2014-01-28 12:59:59 +04:00
|
|
|
QString _targetFile;
|
2014-01-15 14:08:42 +04:00
|
|
|
bool _showFallbackMessage;
|
2014-01-28 12:59:59 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/** 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);
|
2014-07-10 01:22:28 +04:00
|
|
|
bool handleStartup() Q_DECL_OVERRIDE { return false; }
|
2014-01-28 12:59:59 +04:00
|
|
|
|
|
|
|
private:
|
2014-07-10 01:22:28 +04:00
|
|
|
void versionInfoArrived(const UpdateInfo &info) Q_DECL_OVERRIDE;
|
2014-01-15 14:08:42 +04:00
|
|
|
};
|
|
|
|
|
2014-01-28 12:59:59 +04:00
|
|
|
|
|
|
|
|
2014-01-15 14:08:42 +04:00
|
|
|
}
|
|
|
|
|
2014-01-28 12:59:59 +04:00
|
|
|
#endif // OC_UPDATER
|