Imported existing sources
This commit is contained in:
28
translations/updaterplugin_de.ts
Normal file
28
translations/updaterplugin_de.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="de_DE">
|
||||
<context>
|
||||
<name>UpdaterDialog</name>
|
||||
<message>
|
||||
<location filename="../updaterdialog.ui" line="14"/>
|
||||
<location filename="../updaterdialog.ui" line="25"/>
|
||||
<source>New update available!</source>
|
||||
<translation>Neues Update verfügbar!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../updaterdialog.ui" line="32"/>
|
||||
<source>There is a new release available to download!</source>
|
||||
<translation>Ein neues Release steht zum Download bereit!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../updaterdialog.ui" line="70"/>
|
||||
<source>Dont show today anymore</source>
|
||||
<translation>Heute nicht mehr anzeigen</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../updaterdialog.cpp" line="50"/>
|
||||
<source>Could not open default webbrowser!</source>
|
||||
<translation>Konnte Standard-Browser nicht öffnen!</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
28
translations/updaterplugin_en.ts
Normal file
28
translations/updaterplugin_en.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="en_US">
|
||||
<context>
|
||||
<name>UpdaterDialog</name>
|
||||
<message>
|
||||
<location filename="../updaterdialog.ui" line="14"/>
|
||||
<location filename="../updaterdialog.ui" line="25"/>
|
||||
<source>New update available!</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../updaterdialog.ui" line="32"/>
|
||||
<source>There is a new release available to download!</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../updaterdialog.ui" line="70"/>
|
||||
<source>Dont show today anymore</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../updaterdialog.cpp" line="50"/>
|
||||
<source>Could not open default webbrowser!</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
108
updaterdialog.cpp
Normal file
108
updaterdialog.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#include "updaterdialog.h"
|
||||
#include "ui_updaterdialog.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 "mainwindow.h"
|
||||
#include "zeiterfassungsettings.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
#include "updatersettings.h"
|
||||
|
||||
UpdaterDialog::UpdaterDialog(MainWindow &mainWindow) :
|
||||
ZeiterfassungDialog(&mainWindow),
|
||||
ui(new Ui::UpdaterDialog),
|
||||
m_mainWindow(mainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &UpdaterDialog::acceptedSlot);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &UpdaterDialog::rejectedSlot);
|
||||
|
||||
m_reply = m_mainWindow.erfassung().manager()->get(QNetworkRequest(UpdaterSettings(mainWindow.settings()).url()));
|
||||
connect(m_reply, &QNetworkReply::finished, this, &UpdaterDialog::finished);
|
||||
}
|
||||
|
||||
UpdaterDialog::~UpdaterDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void UpdaterDialog::acceptedSlot()
|
||||
{
|
||||
if(ui->checkBoxDontShow->isChecked())
|
||||
UpdaterSettings(m_mainWindow.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();
|
||||
}
|
||||
|
||||
void UpdaterDialog::rejectedSlot()
|
||||
{
|
||||
if(ui->checkBoxDontShow->isChecked())
|
||||
UpdaterSettings(m_mainWindow.settings()).setLastUpdateCheck(QDate::currentDate());
|
||||
|
||||
reject();
|
||||
}
|
||||
|
||||
void UpdaterDialog::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(QStringLiteral("tag_name")).toString());
|
||||
|
||||
if(appVersion < version)
|
||||
{
|
||||
m_url = QUrl(releaseObj.value(QStringLiteral("html_url")).toString());
|
||||
ui->labelDescription->setText(releaseObj.value(QStringLiteral("body")).toString());
|
||||
|
||||
show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
UpdaterSettings(m_mainWindow.settings()).setLastUpdateCheck(QDate::currentDate());
|
||||
|
||||
deleteLater();
|
||||
}
|
31
updaterdialog.h
Normal file
31
updaterdialog.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include "zeiterfassungdialog.h"
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
namespace Ui { class UpdaterDialog; }
|
||||
class MainWindow;
|
||||
|
||||
class UpdaterDialog : public ZeiterfassungDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UpdaterDialog(MainWindow &parent);
|
||||
~UpdaterDialog();
|
||||
|
||||
private Q_SLOTS:
|
||||
void acceptedSlot();
|
||||
void rejectedSlot();
|
||||
void finished();
|
||||
|
||||
private:
|
||||
Ui::UpdaterDialog *ui;
|
||||
MainWindow &m_mainWindow;
|
||||
QNetworkReply *m_reply;
|
||||
|
||||
QUrl m_url;
|
||||
};
|
90
updaterdialog.ui
Normal file
90
updaterdialog.ui
Normal file
@@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>UpdaterDialog</class>
|
||||
<widget class="QDialog" name="UpdaterDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>447</width>
|
||||
<height>280</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>New update available!</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>
|
46
updaterplugin.cpp
Normal file
46
updaterplugin.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "updaterplugin.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
#include <QLocale>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "zeiterfassungsettings.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
#include "updatersettings.h"
|
||||
#include "updaterdialog.h"
|
||||
#include "updatersettingswidget.h"
|
||||
|
||||
UpdaterPlugin::UpdaterPlugin(QObject *parent) :
|
||||
ZeiterfassungPlugin(parent)
|
||||
{
|
||||
qDebug() << "called";
|
||||
|
||||
static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations"));
|
||||
|
||||
if(m_translator.load(QLocale(), QStringLiteral("updaterplugin"), QStringLiteral("_"), dir))
|
||||
{
|
||||
if(!QCoreApplication::installTranslator(&m_translator))
|
||||
{
|
||||
qWarning() << "could not install translation updaterplugin";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "could not load translation updaterplugin";
|
||||
}
|
||||
}
|
||||
|
||||
void UpdaterPlugin::attachTo(MainWindow &mainWindow)
|
||||
{
|
||||
auto lastUpdateCheck = UpdaterSettings(mainWindow.settings()).lastUpdateCheck();
|
||||
if(lastUpdateCheck.isNull() || lastUpdateCheck < QDate::currentDate())
|
||||
new UpdaterDialog(mainWindow);
|
||||
}
|
||||
|
||||
SettingsWidget *UpdaterPlugin::settingsWidget(ZeiterfassungSettings &settings, QWidget *parent) const
|
||||
{
|
||||
return new UpdaterSettingsWidget(settings, parent);
|
||||
}
|
26
updaterplugin.h
Normal file
26
updaterplugin.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QTranslator>
|
||||
|
||||
#include "zeiterfassungplugin.h"
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class Q_DECL_EXPORT UpdaterPlugin : public ZeiterfassungPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "dbsoftware.zeiterfassung.plugin/1.0" FILE "updaterplugin.json")
|
||||
Q_INTERFACES(ZeiterfassungPlugin)
|
||||
|
||||
public:
|
||||
explicit UpdaterPlugin(QObject *parent = Q_NULLPTR);
|
||||
|
||||
// ZeiterfassungPlugin interface
|
||||
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
||||
|
||||
virtual SettingsWidget *settingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR) const Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QTranslator m_translator;
|
||||
};
|
0
updaterplugin.json
Normal file
0
updaterplugin.json
Normal file
26
updaterplugin.pro
Normal file
26
updaterplugin.pro
Normal file
@@ -0,0 +1,26 @@
|
||||
QT += core network gui widgets
|
||||
|
||||
DBLIBS += zeiterfassungcore zeiterfassunggui
|
||||
|
||||
TARGET = updaterplugin
|
||||
|
||||
HEADERS += updaterdialog.h \
|
||||
updaterplugin.h \
|
||||
updatersettings.h \
|
||||
updatersettingswidget.h
|
||||
|
||||
SOURCES += updaterdialog.cpp \
|
||||
updaterplugin.cpp \
|
||||
updatersettings.cpp \
|
||||
updatersettingswidget.cpp
|
||||
|
||||
FORMS += updaterdialog.ui
|
||||
|
||||
RESOURCES +=
|
||||
|
||||
TRANSLATIONS += translations/updaterplugin_en.ts \
|
||||
translations/updaterplugin_de.ts
|
||||
|
||||
OTHER_FILES += updaterplugin.json
|
||||
|
||||
include(../plugin.pri)
|
72
updatersettings.cpp
Normal file
72
updatersettings.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "updatersettings.h"
|
||||
|
||||
#include "zeiterfassungsettings.h"
|
||||
|
||||
const QString UpdaterSettings::m_url("UpdaterPlugin/url");
|
||||
const QString UpdaterSettings::m_lastUpdateCheck("UpdaterPlugin/lastUpdateCheck");
|
||||
const QUrl UpdaterSettings::m_defaultUrl(QStringLiteral("https://api.github.com/repos/0xFEEDC0DE64/QtZeiterfassung/releases"));
|
||||
|
||||
UpdaterSettings::UpdaterSettings(ZeiterfassungSettings &settings, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_settings(settings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QUrl UpdaterSettings::url() const
|
||||
{
|
||||
return m_settings.value(m_url, m_defaultUrl).toUrl();
|
||||
}
|
||||
|
||||
bool UpdaterSettings::setUrl(const QUrl &url)
|
||||
{
|
||||
if(this->url() == url)
|
||||
return true;
|
||||
|
||||
if(url == m_defaultUrl)
|
||||
m_settings.remove(m_url);
|
||||
else
|
||||
m_settings.setValue(m_url, url);
|
||||
|
||||
m_settings.sync();
|
||||
|
||||
const auto success = m_settings.status() == QSettings::NoError;
|
||||
if(success)
|
||||
Q_EMIT urlChanged(url);
|
||||
else
|
||||
{
|
||||
Q_EMIT m_settings.saveErrorOccured();
|
||||
Q_EMIT saveErrorOccured();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
QDate UpdaterSettings::lastUpdateCheck() const
|
||||
{
|
||||
return m_settings.value(m_lastUpdateCheck).toDate();
|
||||
}
|
||||
|
||||
bool UpdaterSettings::setLastUpdateCheck(const QDate &lastUpdateCheck)
|
||||
{
|
||||
if(this->lastUpdateCheck() == lastUpdateCheck)
|
||||
return true;
|
||||
|
||||
if(!lastUpdateCheck.isValid())
|
||||
m_settings.remove(m_lastUpdateCheck);
|
||||
else
|
||||
m_settings.setValue(m_lastUpdateCheck, lastUpdateCheck);
|
||||
|
||||
m_settings.sync();
|
||||
|
||||
const auto success = m_settings.status() == QSettings::NoError;
|
||||
if(success)
|
||||
Q_EMIT lastUpdateCheckChanged(lastUpdateCheck);
|
||||
else
|
||||
{
|
||||
Q_EMIT m_settings.saveErrorOccured();
|
||||
Q_EMIT saveErrorOccured();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
36
updatersettings.h
Normal file
36
updatersettings.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QDate>
|
||||
|
||||
class ZeiterfassungSettings;
|
||||
|
||||
class UpdaterSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
|
||||
Q_PROPERTY(QDate lastUpdateCheck READ lastUpdateCheck WRITE setLastUpdateCheck NOTIFY lastUpdateCheckChanged)
|
||||
|
||||
public:
|
||||
explicit UpdaterSettings(ZeiterfassungSettings &settings, QObject *parent = Q_NULLPTR);
|
||||
|
||||
QUrl url() const;
|
||||
bool setUrl(const QUrl &url);
|
||||
|
||||
QDate lastUpdateCheck() const;
|
||||
bool setLastUpdateCheck(const QDate &lastUpdateCheck);
|
||||
|
||||
Q_SIGNALS:
|
||||
void saveErrorOccured();
|
||||
|
||||
void urlChanged(const QUrl &url);
|
||||
void lastUpdateCheckChanged(const QDate &lastUpdateCheck);
|
||||
|
||||
private:
|
||||
ZeiterfassungSettings &m_settings;
|
||||
|
||||
static const QString m_url;
|
||||
static const QString m_lastUpdateCheck;
|
||||
static const QUrl m_defaultUrl;
|
||||
};
|
32
updatersettingswidget.cpp
Normal file
32
updatersettingswidget.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "updatersettingswidget.h"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
|
||||
UpdaterSettingsWidget::UpdaterSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent) :
|
||||
SettingsWidget(parent),
|
||||
m_settings(settings)
|
||||
{
|
||||
auto layout = new QFormLayout(this);
|
||||
layout->setMargin(0);
|
||||
|
||||
m_lineEdit = new QLineEdit(m_settings.url().toString(), this);
|
||||
layout->addRow(tr("Updater url:"), m_lineEdit);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
bool UpdaterSettingsWidget::isValid(QString &message) const
|
||||
{
|
||||
auto valid = QUrl::fromUserInput(m_lineEdit->text()).isValid();
|
||||
|
||||
if(!valid)
|
||||
message = tr("The updater url is invalid!");
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
bool UpdaterSettingsWidget::apply()
|
||||
{
|
||||
return m_settings.setUrl(QUrl(m_lineEdit->text()));
|
||||
}
|
25
updatersettingswidget.h
Normal file
25
updatersettingswidget.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "settingswidget.h"
|
||||
|
||||
#include "updatersettings.h"
|
||||
|
||||
class QLineEdit;
|
||||
|
||||
class UpdaterSettingsWidget : public SettingsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UpdaterSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR);
|
||||
|
||||
virtual bool isValid(QString &message) const Q_DECL_OVERRIDE;
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual bool apply() Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
UpdaterSettings m_settings;
|
||||
|
||||
QLineEdit *m_lineEdit;
|
||||
};
|
Reference in New Issue
Block a user