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>
|
|
|
|
|
|
|
|
#include "mirall/updateinfo.h"
|
|
|
|
#include "mirall/updater.h"
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
void performUpdate();
|
|
|
|
|
|
|
|
void checkForUpdate();
|
|
|
|
void backgroundCheckForUpdate();
|
|
|
|
|
|
|
|
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 slotSetVersionSeen();
|
|
|
|
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;
|
|
|
|
QString clientVersion() const;
|
|
|
|
QString getSystemInfo();
|
2014-01-28 12:59:59 +04:00
|
|
|
QNetworkAccessManager* qnam() const { return _accessManager; }
|
2014-01-15 14:08:42 +04:00
|
|
|
|
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);
|
|
|
|
bool handleStartup();
|
|
|
|
private slots:
|
|
|
|
void slotDownloadFinished();
|
|
|
|
void slotWriteFile();
|
|
|
|
private:
|
|
|
|
NSISUpdater::UpdateState updateState() const;
|
|
|
|
void showDialog(const UpdateInfo &info);
|
|
|
|
void showFallbackMessage();
|
|
|
|
void versionInfoArrived(const UpdateInfo &info);
|
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);
|
|
|
|
bool handleStartup() { return false; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void versionInfoArrived(const UpdateInfo &info);
|
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
|