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 <QJsonArray>
#include <QJsonValue> #include <QJsonValue>
#include <QJsonObject> #include <QJsonObject>
#include <QDesktopServices>
#include <QMessageBox>
#include "zeiterfassungsettings.h"
UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent) : UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent) :
QDialog(parent), QDialog(parent),
@@ -19,6 +23,15 @@ UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManage
{ {
ui->setupUi(this); 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")))); m_reply = manager->get(QNetworkRequest(QUrl(QStringLiteral("https://api.github.com/repos/0xFEEDC0DE64/QtZeiterfassung/releases"))));
connect(m_reply, &QNetworkReply::finished, this, &UpdateDialog::finished); connect(m_reply, &QNetworkReply::finished, this, &UpdateDialog::finished);
} }
@@ -60,6 +73,26 @@ void UpdateDialog::finished()
auto releaseObj = releaseVal.toObject(); auto releaseObj = releaseVal.toObject();
auto version = QVersionNumber::fromString(releaseObj.value("tag_name").toString()); 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 #define UPDATEDIALOG_H
#include <QDialog> #include <QDialog>
#include <QUrl>
class QNetworkAccessManager; class QNetworkAccessManager;
class QNetworkReply; class QNetworkReply;
@@ -19,11 +20,14 @@ public:
private Q_SLOTS: private Q_SLOTS:
void finished(); void finished();
void submit();
private: private:
Ui::UpdateDialog *ui; Ui::UpdateDialog *ui;
ZeiterfassungSettings &m_settings; ZeiterfassungSettings &m_settings;
QNetworkReply *m_reply; QNetworkReply *m_reply;
QUrl m_url;
}; };
#endif // UPDATEDIALOG_H #endif // UPDATEDIALOG_H

View File

@@ -1,71 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>UpdateDialog</class> <class>UpdateDialog</class>
<widget class="QDialog" name="UpdateDialog"> <widget class="QDialog" name="UpdateDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>447</width>
<height>300</height> <height>280</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<widget class="QDialogButtonBox" name="buttonBox"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0,0">
<property name="geometry"> <item>
<rect> <widget class="QLabel" name="labelTitle">
<x>30</x> <property name="font">
<y>240</y> <font>
<width>341</width> <pointsize>20</pointsize>
<height>32</height> </font>
</rect> </property>
</property> <property name="text">
<property name="orientation"> <string>New update available!</string>
<enum>Qt::Horizontal</enum> </property>
</property> </widget>
<property name="standardButtons"> </item>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <item>
</property> <widget class="QLabel" name="label">
</widget> <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> </widget>
<pixmapfunction/>
<resources/> <resources/>
<connections> <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>
</ui> </ui>

View File

@@ -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">