Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No-Gui version #19

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
10 changes: 7 additions & 3 deletions QSimpleUpdater.pri
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ QT += widgets
INCLUDEPATH += $$PWD/include

SOURCES += \
$$PWD/src/DownloaderLite.cpp \
$$PWD/src/DownloaderGUI.cpp \
$$PWD/src/IDownloader.cpp \
$$PWD/src/Updater.cpp \
$$PWD/src/Downloader.cpp \
$$PWD/src/QSimpleUpdater.cpp

HEADERS += \
$$PWD/include/DownloaderGUI.h \
$$PWD/include/IDownloader.h \
$$PWD/include/QSimpleUpdater.h \
$$PWD/src/Updater.h \
$$PWD/src/Downloader.h
$$PWD/include/Updater.h \
$$PWD/include/DownloaderLite.h

FORMS += $$PWD/src/Downloader.ui
RESOURCES += $$PWD/etc/resources/qsimpleupdater.qrc
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ After downloading this file, the library analyzes the local version and the remo

An example update definition file can be found [here](https://github.com/alex-spataru/QSimpleUpdater/blob/master/tutorial/definitions/updates.json).

Is it possible to enable a no-gui version of the updater calling QSimpleUpdater::setUseGui(bool); in no-gui mode, it automatically downloads and install the updates found.


### 2. Can I customize the update notifications shown to the user?

Yes! You can "toggle" which notifications to show using the library's functions or re-implement by yourself the notifications by "reacting" to the signals emitted by the QSimpleUpdater.
Expand Down
86 changes: 86 additions & 0 deletions include/DownloaderGUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2014-2016 Alex Spataru <[email protected]>
* Copyright (c) 2017 Gilmanov Ildar <https://github.com/gilmanov-ildar>
*
* This file is part of the QSimpleUpdater library, which is released under
* the DBAD license, you can read a copy of it below:
*
* DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING,
* DISTRIBUTION AND MODIFICATION:
*
* Do whatever you like with the original work, just don't be a dick.
* Being a dick includes - but is not limited to - the following instances:
*
* 1a. Outright copyright infringement - Don't just copy this and change the
* name.
* 1b. Selling the unmodified original with no work done what-so-ever, that's
* REALLY being a dick.
* 1c. Modifying the original work to contain hidden harmful content.
* That would make you a PROPER dick.
*
* If you become rich through modifications, related works/services, or
* supporting the original work, share the love.
* Only a dick would make loads off this work and not buy the original works
* creator(s) a pint.
*
* Code is provided with no warranty. Using somebody else's code and bitching
* when it goes wrong makes you a DONKEY dick.
* Fix the problem yourself. A non-dick would submit the fix back.
*/

#ifndef DOWNLOAD_DIALOG_H
#define DOWNLOAD_DIALOG_H

#include <QDir>
#include <QDialog>
#include <ui_Downloader.h>
#include "IDownloader.h"

namespace Ui {
class Downloader;
}

class QNetworkReply;
class QNetworkAccessManager;

/**
* \brief Implements an integrated file downloader with a nice UI
*/
class DownloaderGUI : public QWidget, public IDownloader
{
Q_OBJECT
Q_INTERFACES(IDownloader)

public:
explicit DownloaderGUI (QWidget* parent = nullptr);
virtual ~DownloaderGUI();

signals:
void downloadFinished (const QString& url, const QString& filepath) override;

public slots:
virtual void startDownload (const QUrl& url) override;

protected slots:
virtual void finished() override;
virtual void cancelDownload() override;
virtual void installUpdate() override;
virtual void openDownload() override;
virtual void saveFile(qint64 received, qint64 total) override {IDownloader::saveFile(received,total);}
virtual void updateProgress (qint64 received, qint64 total) override;

protected:
virtual const QObject* getThisQObj() override {return this;}

private slots:
void calculateSizes (qint64 received, qint64 total);
void calculateTimeRemaining (qint64 received, qint64 total);

private:
qreal round (const qreal& input);

private:
Ui::Downloader* m_ui;
};

#endif
64 changes: 64 additions & 0 deletions include/DownloaderLite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2014-2016 Alex Spataru <[email protected]>
* Copyright (c) 2017 Gilmanov Ildar <https://github.com/gilmanov-ildar>
*
* This file is part of the QSimpleUpdater library, which is released under
* the DBAD license, you can read a copy of it below:
*
* DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING,
* DISTRIBUTION AND MODIFICATION:
*
* Do whatever you like with the original work, just don't be a dick.
* Being a dick includes - but is not limited to - the following instances:
*
* 1a. Outright copyright infringement - Don't just copy this and change the
* name.
* 1b. Selling the unmodified original with no work done what-so-ever, that's
* REALLY being a dick.
* 1c. Modifying the original work to contain hidden harmful content.
* That would make you a PROPER dick.
*
* If you become rich through modifications, related works/services, or
* supporting the original work, share the love.
* Only a dick would make loads off this work and not buy the original works
* creator(s) a pint.
*
* Code is provided with no warranty. Using somebody else's code and bitching
* when it goes wrong makes you a DONKEY dick.
* Fix the problem yourself. A non-dick would submit the fix back.
*/

#ifndef DOWNLOADERLITE_H
#define DOWNLOADERLITE_H

#include <QObject>
#include "IDownloader.h"

class DownloaderLite : public QObject, public IDownloader
{
Q_OBJECT
Q_INTERFACES(IDownloader)

public:
explicit DownloaderLite(QObject *parent = nullptr) : QObject(parent){}
virtual ~DownloaderLite() {}

signals:
void downloadFinished (const QString& url, const QString& filepath) override;

public slots:
virtual void startDownload (const QUrl& url) override {IDownloader::startDownload(url);}

protected slots:
virtual void finished() override {IDownloader::finished();}
virtual void cancelDownload() override{IDownloader::cancelDownload();}
virtual void installUpdate() override{IDownloader::installUpdate();}
virtual void openDownload() override{IDownloader::openDownload();}
virtual void saveFile(qint64 received, qint64 total) override{IDownloader::saveFile(received,total);}
virtual void updateProgress(qint64 received, qint64 total) override{IDownloader::updateProgress(received,total);}

protected:
virtual const QObject* getThisQObj() override {return this;}
};

#endif // DOWNLOADERLITE_H
191 changes: 91 additions & 100 deletions src/Downloader.h → include/IDownloader.h
Original file line number Diff line number Diff line change
@@ -1,100 +1,91 @@
/*
* Copyright (c) 2014-2016 Alex Spataru <[email protected]>
* Copyright (c) 2017 Gilmanov Ildar <https://github.com/gilmanov-ildar>
*
* This file is part of the QSimpleUpdater library, which is released under
* the DBAD license, you can read a copy of it below:
*
* DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING,
* DISTRIBUTION AND MODIFICATION:
*
* Do whatever you like with the original work, just don't be a dick.
* Being a dick includes - but is not limited to - the following instances:
*
* 1a. Outright copyright infringement - Don't just copy this and change the
* name.
* 1b. Selling the unmodified original with no work done what-so-ever, that's
* REALLY being a dick.
* 1c. Modifying the original work to contain hidden harmful content.
* That would make you a PROPER dick.
*
* If you become rich through modifications, related works/services, or
* supporting the original work, share the love.
* Only a dick would make loads off this work and not buy the original works
* creator(s) a pint.
*
* Code is provided with no warranty. Using somebody else's code and bitching
* when it goes wrong makes you a DONKEY dick.
* Fix the problem yourself. A non-dick would submit the fix back.
*/

#ifndef DOWNLOAD_DIALOG_H
#define DOWNLOAD_DIALOG_H

#include <QDir>
#include <QDialog>
#include <ui_Downloader.h>

namespace Ui {
class Downloader;
}

class QNetworkReply;
class QNetworkAccessManager;

/**
* \brief Implements an integrated file downloader with a nice UI
*/
class Downloader : public QWidget
{
Q_OBJECT

signals:
void downloadFinished (const QString& url, const QString& filepath);

public:
explicit Downloader (QWidget* parent = 0);
~Downloader();

bool useCustomInstallProcedures() const;

QString downloadDir() const;
void setDownloadDir (const QString& downloadDir);

public slots:
void setUrlId (const QString& url);
void startDownload (const QUrl& url);
void setFileName (const QString& file);
void setUserAgentString (const QString& agent);
void setUseCustomInstallProcedures (const bool custom);
void setMandatoryUpdate (const bool mandatory_update);

private slots:
void finished();
void openDownload();
void installUpdate();
void cancelDownload();
void saveFile (qint64 received, qint64 total);
void calculateSizes (qint64 received, qint64 total);
void updateProgress (qint64 received, qint64 total);
void calculateTimeRemaining (qint64 received, qint64 total);

private:
qreal round (const qreal& input);

private:
QString m_url;
uint m_startTime;
QDir m_downloadDir;
QString m_fileName;
Ui::Downloader* m_ui;
QNetworkReply* m_reply;
QString m_userAgentString;

bool m_useCustomProcedures;
bool m_mandatoryUpdate;

QNetworkAccessManager* m_manager;
};

#endif
/*
* Copyright (c) 2014-2016 Alex Spataru <[email protected]>
* Copyright (c) 2017 Gilmanov Ildar <https://github.com/gilmanov-ildar>
*
* This file is part of the QSimpleUpdater library, which is released under
* the DBAD license, you can read a copy of it below:
*
* DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING,
* DISTRIBUTION AND MODIFICATION:
*
* Do whatever you like with the original work, just don't be a dick.
* Being a dick includes - but is not limited to - the following instances:
*
* 1a. Outright copyright infringement - Don't just copy this and change the
* name.
* 1b. Selling the unmodified original with no work done what-so-ever, that's
* REALLY being a dick.
* 1c. Modifying the original work to contain hidden harmful content.
* That would make you a PROPER dick.
*
* If you become rich through modifications, related works/services, or
* supporting the original work, share the love.
* Only a dick would make loads off this work and not buy the original works
* creator(s) a pint.
*
* Code is provided with no warranty. Using somebody else's code and bitching
* when it goes wrong makes you a DONKEY dick.
* Fix the problem yourself. A non-dick would submit the fix back.
*/

#ifndef DOWNLOADERINTERFACE_H
#define DOWNLOADERINTERFACE_H

#include <QString>
#include <QDir>

class QNetworkReply;
class QNetworkAccessManager;

class IDownloader
{
public:
IDownloader();
virtual ~IDownloader();

bool useCustomInstallProcedures() const;

QString downloadDir() const;
void setDownloadDir (const QString& downloadDir);

signals:
virtual void downloadFinished (const QString& url, const QString& filepath) = 0;

public slots:
void setUrlId (const QString& url);
void setFileName (const QString& file);
void setUserAgentString (const QString& agent);
void setUseCustomInstallProcedures (const bool custom);
void setMandatoryUpdate (const bool mandatory_update);

virtual void startDownload (const QUrl& url) = 0;

protected slots:
virtual void finished() = 0;
virtual void cancelDownload() = 0;
virtual void installUpdate() = 0;
virtual void updateProgress (qint64 received, qint64 total) = 0;
virtual void openDownload() = 0;
virtual void saveFile(qint64 received, qint64 total) = 0;

protected:
virtual const QObject* getThisQObj() = 0;

QString m_url;
uint m_startTime;
QDir m_downloadDir;
QString m_fileName;
QNetworkReply* m_reply;
QString m_userAgentString;

bool m_useCustomProcedures;
bool m_mandatoryUpdate;

QNetworkAccessManager* m_manager;

static const QString PARTIAL_DOWN;
};

Q_DECLARE_INTERFACE(IDownloader, "IDownloader")

#endif // DOWNLOADERINTERFACE_H
Loading