Moved Updater functionality into plugin
This commit is contained in:
@@ -17,7 +17,7 @@ public:
|
||||
explicit AdvancedViewPlugin(QObject *parent = Q_NULLPTR);
|
||||
|
||||
// ZeiterfassungPlugin interface
|
||||
void attachTo(MainWindow &mainWindow);
|
||||
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // ADVANCEDVIEWPLUGIN_H
|
||||
|
@@ -17,7 +17,7 @@ public:
|
||||
explicit PresencePlugin(QObject *parent = Q_NULLPTR);
|
||||
|
||||
// ZeiterfassungPlugin interface
|
||||
void attachTo(MainWindow &mainWindow);
|
||||
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // PRESENCEPLUGIN_H
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include "updatedialog.h"
|
||||
#include "ui_updatedialog.h"
|
||||
#include "updaterdialog.h"
|
||||
#include "ui_updaterdialog.h"
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
@@ -14,34 +14,48 @@
|
||||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "zeiterfassungsettings.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::UpdateDialog),
|
||||
m_settings(settings)
|
||||
UpdaterDialog::UpdaterDialog(MainWindow &mainWindow) :
|
||||
QDialog(&mainWindow),
|
||||
ui(new Ui::UpdaterDialog),
|
||||
m_mainWindow(mainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &UpdateDialog::submit);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=]() {
|
||||
if(ui->checkBoxDontShow->isChecked())
|
||||
m_mainWindow.settings().setValue(QStringLiteral("UpdaterPlugin/lastUpdateCheck"), QDate::currentDate());
|
||||
|
||||
if(!QDesktopServices::openUrl(m_url))
|
||||
QMessageBox::warning(this, tr("Could not open default webbrowser!"), tr("Could not open default webbrowser!"));
|
||||
|
||||
accept();
|
||||
});
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=](){
|
||||
if(ui->checkBoxDontShow->isChecked())
|
||||
m_settings.setLastUpdateCheck(QDate::currentDate());
|
||||
m_mainWindow.settings().setValue(QStringLiteral("UpdaterPlugin/lastUpdateCheck"), 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);
|
||||
auto url = m_mainWindow.settings().value(QStringLiteral("UpdaterPlugin/url"),
|
||||
QUrl(QStringLiteral("https://api.github.com/repos/0xFEEDC0DE64/QtZeiterfassung/releases"))).toUrl();
|
||||
m_reply = m_mainWindow.erfassung().manager()->get(QNetworkRequest(url));
|
||||
connect(m_reply, &QNetworkReply::finished, this, &UpdaterDialog::finished);
|
||||
}
|
||||
|
||||
UpdateDialog::~UpdateDialog()
|
||||
UpdaterDialog::~UpdaterDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void UpdateDialog::finished()
|
||||
void UpdaterDialog::finished()
|
||||
{
|
||||
if(m_reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
@@ -83,18 +97,7 @@ void UpdateDialog::finished()
|
||||
}
|
||||
}
|
||||
|
||||
m_settings.setLastUpdateCheck(QDate::currentDate());
|
||||
m_mainWindow.settings().setValue(QStringLiteral("UpdaterPlugin/lastUpdateCheck"), QDate::currentDate());
|
||||
|
||||
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
plugins/updaterplugin/updaterdialog.h
Normal file
33
plugins/updaterplugin/updaterdialog.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef UPDATERDIALOG_H
|
||||
#define UPDATERDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QUrl>
|
||||
|
||||
#include "zeiterfassunglib_global.h"
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
namespace Ui { class UpdaterDialog; }
|
||||
class MainWindow;
|
||||
|
||||
class ZEITERFASSUNGLIBSHARED_EXPORT UpdaterDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UpdaterDialog(MainWindow &parent);
|
||||
~UpdaterDialog();
|
||||
|
||||
private Q_SLOTS:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
Ui::UpdaterDialog *ui;
|
||||
MainWindow &m_mainWindow;
|
||||
QNetworkReply *m_reply;
|
||||
|
||||
QUrl m_url;
|
||||
};
|
||||
|
||||
#endif // UPDATERDIALOG_H
|
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>UpdateDialog</class>
|
||||
<widget class="QDialog" name="UpdateDialog">
|
||||
<class>UpdaterDialog</class>
|
||||
<widget class="QDialog" name="UpdaterDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
@@ -2,6 +2,12 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "zeiterfassungsettings.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
#include "updaterdialog.h"
|
||||
|
||||
UpdaterPlugin::UpdaterPlugin(QObject *parent) :
|
||||
ZeiterfassungPlugin(parent)
|
||||
{
|
||||
@@ -10,5 +16,9 @@ UpdaterPlugin::UpdaterPlugin(QObject *parent) :
|
||||
|
||||
void UpdaterPlugin::attachTo(MainWindow &mainWindow)
|
||||
{
|
||||
qDebug() << "called";
|
||||
|
||||
if(mainWindow.settings().value(QStringLiteral("UpdaterPlugin/lastUpdateCheck")).toDate().isNull() ||
|
||||
mainWindow.settings().value(QStringLiteral("UpdaterPlugin/lastUpdateCheck")).toDate() < QDate::currentDate())
|
||||
new UpdaterDialog(mainWindow);
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ public:
|
||||
explicit UpdaterPlugin(QObject *parent = Q_NULLPTR);
|
||||
|
||||
// ZeiterfassungPlugin interface
|
||||
void attachTo(MainWindow &mainWindow);
|
||||
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // UPDATERPLUGIN_H
|
||||
|
@@ -1,6 +1,6 @@
|
||||
QT += core network gui widgets
|
||||
|
||||
TARGET = advancedviewplugin
|
||||
TARGET = updaterplugin
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += shared c++14
|
||||
@@ -14,11 +14,13 @@ DEPENDPATH += $$PWD/../../zeiterfassunglib
|
||||
|
||||
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
|
||||
|
||||
HEADERS += updaterplugin.h
|
||||
HEADERS += updaterdialog.h \
|
||||
updaterplugin.h
|
||||
|
||||
SOURCES += updaterplugin.cpp
|
||||
SOURCES += updaterdialog.cpp \
|
||||
updaterplugin.cpp
|
||||
|
||||
FORMS +=
|
||||
FORMS += updaterdialog.ui
|
||||
|
||||
RESOURCES +=
|
||||
|
||||
|
@@ -1,35 +0,0 @@
|
||||
#ifndef UPDATEDIALOG_H
|
||||
#define UPDATEDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QUrl>
|
||||
|
||||
#include "zeiterfassunglib_global.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
|
||||
class ZeiterfassungSettings;
|
||||
namespace Ui { class UpdateDialog; }
|
||||
|
||||
class ZEITERFASSUNGLIBSHARED_EXPORT UpdateDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent = Q_NULLPTR);
|
||||
~UpdateDialog();
|
||||
|
||||
private Q_SLOTS:
|
||||
void finished();
|
||||
void submit();
|
||||
|
||||
private:
|
||||
Ui::UpdateDialog *ui;
|
||||
ZeiterfassungSettings &m_settings;
|
||||
QNetworkReply *m_reply;
|
||||
|
||||
QUrl m_url;
|
||||
};
|
||||
|
||||
#endif // UPDATEDIALOG_H
|
@@ -21,7 +21,6 @@
|
||||
#include "stripswidget.h"
|
||||
#include "dialogs/aboutmedialog.h"
|
||||
#include "dialogs/settingsdialog.h"
|
||||
#include "dialogs/updatedialog.h"
|
||||
#include "replies/getprojectsreply.h"
|
||||
#include "replies/getauswertungreply.h"
|
||||
#include "replies/createbookingreply.h"
|
||||
@@ -97,9 +96,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass
|
||||
m_holidaysLabel->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
dateChanged();
|
||||
|
||||
if(settings.lastUpdateCheck().isNull() || settings.lastUpdateCheck() < QDate::currentDate())
|
||||
new UpdateDialog(settings, erfassung.manager(), this);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@@ -21,7 +21,6 @@ SOURCES += mainwindow.cpp \
|
||||
dialogs/authenticationdialog.cpp \
|
||||
dialogs/languageselectiondialog.cpp \
|
||||
dialogs/settingsdialog.cpp \
|
||||
dialogs/updatedialog.cpp \
|
||||
replies/createbookingreply.cpp \
|
||||
replies/createtimeassignmentreply.cpp \
|
||||
replies/deletebookingreply.cpp \
|
||||
@@ -51,7 +50,6 @@ HEADERS += cpp14polyfills.h \
|
||||
dialogs/authenticationdialog.h \
|
||||
dialogs/languageselectiondialog.h \
|
||||
dialogs/settingsdialog.h \
|
||||
dialogs/updatedialog.h \
|
||||
replies/createbookingreply.h \
|
||||
replies/createtimeassignmentreply.h \
|
||||
replies/deletebookingreply.h \
|
||||
@@ -69,7 +67,6 @@ HEADERS += cpp14polyfills.h \
|
||||
replies/getuserinforeply.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
dialogs/updatedialog.ui \
|
||||
dialogs/settingsdialog.ui \
|
||||
dialogs/languageselectiondialog.ui \
|
||||
dialogs/authenticationdialog.ui \
|
||||
|
@@ -132,16 +132,6 @@ void ZeiterfassungSettings::prependText(const QString &text)
|
||||
prependItem(QStringLiteral("texte"), text);
|
||||
}
|
||||
|
||||
QDate ZeiterfassungSettings::lastUpdateCheck() const
|
||||
{
|
||||
return value(QStringLiteral("lastUpdateCheck")).toDate();
|
||||
}
|
||||
|
||||
void ZeiterfassungSettings::setLastUpdateCheck(const QDate &lastUpdateCheck)
|
||||
{
|
||||
setValue(QStringLiteral("lastUpdateCheck"), lastUpdateCheck);
|
||||
}
|
||||
|
||||
QString ZeiterfassungSettings::theme() const
|
||||
{
|
||||
return value(QStringLiteral("theme")).toString();
|
||||
|
@@ -51,9 +51,6 @@ public:
|
||||
void setTexte(const QStringList &texte);
|
||||
void prependText(const QString &text);
|
||||
|
||||
QDate lastUpdateCheck() const;
|
||||
void setLastUpdateCheck(const QDate &lastUpdateCheck);
|
||||
|
||||
QString theme() const;
|
||||
void setTheme(const QString &theme);
|
||||
|
||||
|
Reference in New Issue
Block a user