Implemented UpdateDialog

This commit is contained in:
0xFEEDC0DE64
2017-12-07 00:51:45 +01:00
parent 78da01e53e
commit d045466017
4 changed files with 115 additions and 59 deletions

View File

@@ -11,6 +11,10 @@
#include <QJsonArray>
#include <QJsonValue>
#include <QJsonObject>
#include <QDesktopServices>
#include <QMessageBox>
#include "zeiterfassungsettings.h"
UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent) :
QDialog(parent),
@@ -19,6 +23,15 @@ UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManage
{
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);
}
@@ -60,6 +73,26 @@ void UpdateDialog::finished()
auto releaseObj = releaseVal.toObject();
auto version = QVersionNumber::fromString(releaseObj.value("tag_name").toString());
qDebug() << version << (appVersion < version);
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();
}

View File

@@ -2,6 +2,7 @@
#define UPDATEDIALOG_H
#include <QDialog>
#include <QUrl>
class QNetworkAccessManager;
class QNetworkReply;
@@ -19,11 +20,14 @@ public:
private Q_SLOTS:
void finished();
void submit();
private:
Ui::UpdateDialog *ui;
ZeiterfassungSettings &m_settings;
QNetworkReply *m_reply;
QUrl m_url;
};
#endif // UPDATEDIALOG_H

View File

@@ -1,71 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>UpdateDialog</class>
<widget class="QDialog" name="UpdateDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>447</width>
<height>280</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<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>
<pixmapfunction/>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>UpdateDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>UpdateDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

View File

@@ -196,7 +196,7 @@
<x>0</x>
<y>0</y>
<width>1220</width>
<height>438</height>
<height>454</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout2">
@@ -258,7 +258,7 @@
<x>0</x>
<y>0</y>
<width>1242</width>
<height>26</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">