Auto updater #4
98
dialogs/updatedialog.cpp
Normal file
98
dialogs/updatedialog.cpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include "updatedialog.h"
|
||||||
|
#include "ui_updatedialog.h"
|
||||||
|
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "zeiterfassungsettings.h"
|
||||||
|
|
||||||
|
UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::UpdateDialog),
|
||||||
|
m_settings(settings)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &UpdateDialog::submit);
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=](){
|
||||||
|
if(ui->checkBoxDontShow->isChecked())
|
||||||
|
m_settings.setLastUpdateCheck(QDate::currentDate());
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
|
||||||
|
m_reply = manager->get(QNetworkRequest(QUrl(QStringLiteral("https://api.github.com/repos/0xFEEDC0DE64/QtZeiterfassung/releases"))));
|
||||||
|
connect(m_reply, &QNetworkReply::finished, this, &UpdateDialog::finished);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateDialog::~UpdateDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateDialog::finished()
|
||||||
|
{
|
||||||
|
if(m_reply->error() != QNetworkReply::NoError)
|
||||||
|
{
|
||||||
|
qWarning() << "request error" << m_reply->error() << m_reply->errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonParseError error;
|
||||||
|
auto document = QJsonDocument::fromJson(m_reply->readAll(), &error);
|
||||||
|
|
||||||
|
if(error.error != QJsonParseError::NoError)
|
||||||
|
{
|
||||||
|
qWarning() << "parse error" << error.error << error.errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!document.isArray())
|
||||||
|
{
|
||||||
|
qWarning() << "document is not an array!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto appVersion = QVersionNumber::fromString(QCoreApplication::applicationVersion());
|
||||||
|
|
||||||
|
auto array = document.array();
|
||||||
|
|
||||||
|
for(const auto &releaseVal : array)
|
||||||
|
{
|
||||||
|
auto releaseObj = releaseVal.toObject();
|
||||||
|
auto version = QVersionNumber::fromString(releaseObj.value("tag_name").toString());
|
||||||
|
|
||||||
|
if(appVersion < version)
|
||||||
|
{
|
||||||
|
m_url = QUrl(releaseObj.value("html_url").toString());
|
||||||
|
ui->labelDescription->setText(releaseObj.value("body").toString());
|
||||||
|
|
||||||
|
show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateDialog::submit()
|
||||||
|
{
|
||||||
|
if(ui->checkBoxDontShow->isChecked())
|
||||||
|
m_settings.setLastUpdateCheck(QDate::currentDate());
|
||||||
|
|
||||||
|
if(!QDesktopServices::openUrl(m_url))
|
||||||
|
QMessageBox::warning(this, tr("Could not open default webbrowser!"), tr("Could not open default webbrowser!"));
|
||||||
|
|
||||||
|
accept();
|
||||||
|
}
|
33
dialogs/updatedialog.h
Normal file
33
dialogs/updatedialog.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef UPDATEDIALOG_H
|
||||||
|
#define UPDATEDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
class QNetworkAccessManager;
|
||||||
|
class QNetworkReply;
|
||||||
|
|
||||||
|
class ZeiterfassungSettings;
|
||||||
|
namespace Ui { class UpdateDialog; }
|
||||||
|
|
||||||
|
class UpdateDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent = 0);
|
||||||
|
~UpdateDialog();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void finished();
|
||||||
|
void submit();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::UpdateDialog *ui;
|
||||||
|
ZeiterfassungSettings &m_settings;
|
||||||
|
QNetworkReply *m_reply;
|
||||||
|
|
||||||
|
QUrl m_url;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UPDATEDIALOG_H
|
90
dialogs/updatedialog.ui
Normal file
90
dialogs/updatedialog.ui
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>UpdateDialog</class>
|
||||||
|
<widget class="QDialog" name="UpdateDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>447</width>
|
||||||
|
<height>280</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0,0">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelTitle">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>20</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>New update available!</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>There is a new release available to download!</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelDescription">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::WinPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Sunken</enum>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">TextLabel</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkBoxDontShow">
|
||||||
|
<property name="text">
|
||||||
|
<string>Dont show today anymore</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@@ -20,6 +20,7 @@
|
|||||||
#include "dialogs/bookingdialog.h"
|
#include "dialogs/bookingdialog.h"
|
||||||
#include "dialogs/timeassignmentdialog.h"
|
#include "dialogs/timeassignmentdialog.h"
|
||||||
#include "dialogs/settingsdialog.h"
|
#include "dialogs/settingsdialog.h"
|
||||||
|
#include "dialogs/updatedialog.h"
|
||||||
#include "strips/bookingstrip.h"
|
#include "strips/bookingstrip.h"
|
||||||
#include "strips/timeassignmentstrip.h"
|
#include "strips/timeassignmentstrip.h"
|
||||||
#include "models/bookingsmodel.h"
|
#include "models/bookingsmodel.h"
|
||||||
@@ -112,6 +113,9 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, Zeiterfassung &erfassung
|
|||||||
m_holidaysLabel->setFrameShadow(QFrame::Sunken);
|
m_holidaysLabel->setFrameShadow(QFrame::Sunken);
|
||||||
|
|
||||||
refresh(true);
|
refresh(true);
|
||||||
|
|
||||||
|
if(settings.lastUpdateCheck().isNull() || settings.lastUpdateCheck() < QDate::currentDate())
|
||||||
|
new UpdateDialog(settings, erfassung.manager(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@@ -196,7 +196,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1220</width>
|
<width>1220</width>
|
||||||
<height>438</height>
|
<height>454</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout2">
|
<layout class="QVBoxLayout" name="verticalLayout2">
|
||||||
@@ -258,7 +258,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1242</width>
|
<width>1242</width>
|
||||||
<height>26</height>
|
<height>22</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
@@ -33,6 +33,11 @@ void Zeiterfassung::setUrl(const QString &url)
|
|||||||
Q_EMIT urlChanged(m_url = url);
|
Q_EMIT urlChanged(m_url = url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QNetworkAccessManager *Zeiterfassung::manager() const
|
||||||
|
{
|
||||||
|
return m_manager;
|
||||||
|
}
|
||||||
|
|
||||||
bool Zeiterfassung::doLoginPage()
|
bool Zeiterfassung::doLoginPage()
|
||||||
{
|
{
|
||||||
if(m_replies.login)
|
if(m_replies.login)
|
||||||
|
@@ -21,6 +21,8 @@ public:
|
|||||||
const QString &url() const;
|
const QString &url() const;
|
||||||
void setUrl(const QString &url);
|
void setUrl(const QString &url);
|
||||||
|
|
||||||
|
QNetworkAccessManager *manager() const;
|
||||||
|
|
||||||
struct UserInfo
|
struct UserInfo
|
||||||
{
|
{
|
||||||
int userId;
|
int userId;
|
||||||
|
@@ -30,7 +30,8 @@ SOURCES += main.cpp \
|
|||||||
strips/timeassignmentstrip.cpp \
|
strips/timeassignmentstrip.cpp \
|
||||||
dialogs/bookingdialog.cpp \
|
dialogs/bookingdialog.cpp \
|
||||||
models/bookingsmodel.cpp \
|
models/bookingsmodel.cpp \
|
||||||
strips/bookingstrip.cpp
|
strips/bookingstrip.cpp \
|
||||||
|
dialogs/updatedialog.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
zeiterfassung.h \
|
zeiterfassung.h \
|
||||||
@@ -46,7 +47,8 @@ HEADERS += \
|
|||||||
strips/timeassignmentstrip.h \
|
strips/timeassignmentstrip.h \
|
||||||
dialogs/bookingdialog.h \
|
dialogs/bookingdialog.h \
|
||||||
models/bookingsmodel.h \
|
models/bookingsmodel.h \
|
||||||
strips/bookingstrip.h
|
strips/bookingstrip.h \
|
||||||
|
dialogs/updatedialog.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
mainwindow.ui \
|
mainwindow.ui \
|
||||||
@@ -57,7 +59,8 @@ FORMS += \
|
|||||||
dialogs/timeassignmentdialog.ui \
|
dialogs/timeassignmentdialog.ui \
|
||||||
strips/timeassignmentstrip.ui \
|
strips/timeassignmentstrip.ui \
|
||||||
dialogs/bookingdialog.ui \
|
dialogs/bookingdialog.ui \
|
||||||
strips/bookingstrip.ui
|
strips/bookingstrip.ui \
|
||||||
|
dialogs/updatedialog.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
@@ -172,6 +172,16 @@ void ZeiterfassungSettings::setTimeAssignmentBackgroundColor(const QString timeA
|
|||||||
setValue("timeAssignmentBackgroundColor", timeAssignmentBackgroundColor);
|
setValue("timeAssignmentBackgroundColor", timeAssignmentBackgroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDate ZeiterfassungSettings::lastUpdateCheck() const
|
||||||
|
{
|
||||||
|
return value("lastUpdateCheck").toDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZeiterfassungSettings::setLastUpdateCheck(const QDate &lastUpdateCheck)
|
||||||
|
{
|
||||||
|
setValue("lastUpdateCheck", lastUpdateCheck);
|
||||||
|
}
|
||||||
|
|
||||||
void ZeiterfassungSettings::prepentItem(const QString &name, const QString &item)
|
void ZeiterfassungSettings::prepentItem(const QString &name, const QString &item)
|
||||||
{
|
{
|
||||||
if(item.trimmed().isEmpty())
|
if(item.trimmed().isEmpty())
|
||||||
|
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
class ZeiterfassungSettings : public QSettings
|
class ZeiterfassungSettings : public QSettings
|
||||||
{
|
{
|
||||||
@@ -58,6 +61,9 @@ public:
|
|||||||
QString timeAssignmentBackgroundColor() const;
|
QString timeAssignmentBackgroundColor() const;
|
||||||
void setTimeAssignmentBackgroundColor(const QString timeAssignmentBackgroundColor);
|
void setTimeAssignmentBackgroundColor(const QString timeAssignmentBackgroundColor);
|
||||||
|
|
||||||
|
QDate lastUpdateCheck() const;
|
||||||
|
void setLastUpdateCheck(const QDate &lastUpdateCheck);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void prepentItem(const QString &name, const QString &item);
|
void prepentItem(const QString &name, const QString &item);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user