Skip to content
Snippets Groups Projects
Commit 66706217 authored by akiraohgaki's avatar akiraohgaki
Browse files

Add AppImageUpdater class

parent 3dfd4d75
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ unix:!ios:!android { ...@@ -33,6 +33,7 @@ unix:!ios:!android {
QT += dbus QT += dbus
HEADERS += \ HEADERS += \
$${PWD}/src/updaters/appimageupdater.h \
$${PWD}/src/desktopthemes/kdetheme.h \ $${PWD}/src/desktopthemes/kdetheme.h \
$${PWD}/src/desktopthemes/gnometheme.h \ $${PWD}/src/desktopthemes/gnometheme.h \
$${PWD}/src/desktopthemes/xfcetheme.h \ $${PWD}/src/desktopthemes/xfcetheme.h \
...@@ -40,6 +41,7 @@ unix:!ios:!android { ...@@ -40,6 +41,7 @@ unix:!ios:!android {
$${PWD}/src/desktopthemes/matetheme.h $${PWD}/src/desktopthemes/matetheme.h
SOURCES += \ SOURCES += \
$${PWD}/src/updaters/appimageupdater.cpp \
$${PWD}/src/desktopthemes/kdetheme.cpp \ $${PWD}/src/desktopthemes/kdetheme.cpp \
$${PWD}/src/desktopthemes/gnometheme.cpp \ $${PWD}/src/desktopthemes/gnometheme.cpp \
$${PWD}/src/desktopthemes/xfcetheme.cpp \ $${PWD}/src/desktopthemes/xfcetheme.cpp \
......
#include "appimageupdater.h"
#include <QThread>
#include "appimage/update.h"
AppImageUpdater::AppImageUpdater(const QString &id, const QString &path, QObject *parent)
: QObject(parent), id_(id), path_(path)
{
isFinishedWithNoError_ = false;
errorString_ = "";
}
QString AppImageUpdater::id() const
{
return id_;
}
QString AppImageUpdater::path() const
{
return path_;
}
QString AppImageUpdater::describeAppImage() const
{
std::string description = "";
appimage::update::Updater updater(path_.toStdString());
updater.describeAppImage(description);
return QString::fromStdString(description);
}
bool AppImageUpdater::checkAppImage() const
{
bool updateAvailable = false;
appimage::update::Updater updater(path_.toStdString());
updater.checkForChanges(updateAvailable);
return updateAvailable;
}
void AppImageUpdater::updateAppImage()
{
isFinishedWithNoError_ = false;
errorString_ = "";
appimage::update::Updater updater(path_.toStdString(), false);
if (!updater.start()) {
emit finished(this);
return;
}
while (!updater.isDone()) {
QThread::msleep(100);
double progress;
if (updater.progress(progress)) {
emit updateProgress(id_, progress);
}
}
if (updater.hasError()) {
std::string message;
while (updater.nextStatusMessage(message)) {
errorString_ += QString::fromStdString(message) + "\n";
}
emit finished(this);
return;
}
isFinishedWithNoError_ = true;
emit finished(this);
}
bool AppImageUpdater::isFinishedWithNoError() const
{
return isFinishedWithNoError_;
}
QString AppImageUpdater::errorString() const
{
return errorString_;
}
#pragma once
#include <QObject>
class AppImageUpdater : public QObject
{
Q_OBJECT
public:
explicit AppImageUpdater(const QString &id, const QString &path, QObject *parent = nullptr);
QString id() const;
QString path() const;
QString describeAppImage() const;
bool checkAppImage() const;
void updateAppImage();
bool isFinishedWithNoError() const;
QString errorString() const;
signals:
void finished(AppImageUpdater *updater);
void updateProgress(QString id, double progress);
private:
QString id_;
QString path_;
bool isFinishedWithNoError_;
QString errorString_;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment