Updater plugin #30

Merged
0xFEEDC0DE64 merged 2 commits from updater-plugin into devel 2017-12-18 22:40:01 +01:00
21 changed files with 156 additions and 90 deletions

View File

@@ -1,5 +1,6 @@
#include "advancedviewplugin.h"
#include <QDebug>
#include <QBoxLayout>
#include "mainwindow.h"
@@ -9,6 +10,7 @@
AdvancedViewPlugin::AdvancedViewPlugin(QObject *parent) :
ZeiterfassungPlugin(parent)
{
qDebug() << "called";
Q_INIT_RESOURCE(advancedviewplugin_resources);
}

View File

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

View File

@@ -5,5 +5,5 @@
LunchMealPlugin::LunchMealPlugin(QObject *parent) :
ZeiterfassungPlugin(parent)
{
qDebug() << "called";
}

View File

@@ -3,4 +3,5 @@ TEMPLATE = subdirs
SUBDIRS += advancedviewplugin \
lunchmealplugin \
presenceplugin \
updaterplugin \
weatherplugin

View File

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

View File

@@ -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();
}

View 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

View File

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

View File

@@ -0,0 +1,24 @@
#include "updaterplugin.h"
#include <QDebug>
#include "mainwindow.h"
#include "zeiterfassungsettings.h"
#include "zeiterfassungapi.h"
#include "updaterdialog.h"
UpdaterPlugin::UpdaterPlugin(QObject *parent) :
ZeiterfassungPlugin(parent)
{
qDebug() << "called";
}
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);
}

View File

@@ -0,0 +1,23 @@
#ifndef UPDATERPLUGIN_H
#define UPDATERPLUGIN_H
#include <QObject>
#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;
};
#endif // UPDATERPLUGIN_H

View File

View File

@@ -0,0 +1,29 @@
QT += core network gui widgets
TARGET = updaterplugin
TEMPLATE = lib
CONFIG += shared c++14
DESTDIR = $${OUT_PWD}/../../bin/plugins/zeiterfassung
LIBS += -L$$OUT_PWD/../../lib -lzeiterfassunglib
INCLUDEPATH += $$PWD/../../zeiterfassunglib
DEPENDPATH += $$PWD/../../zeiterfassunglib
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
HEADERS += updaterdialog.h \
updaterplugin.h
SOURCES += updaterdialog.cpp \
updaterplugin.cpp
FORMS += updaterdialog.ui
RESOURCES +=
TRANSLATIONS +=
OTHER_FILES += updaterplugin.json

View File

@@ -5,5 +5,5 @@
WeatherPlugin::WeatherPlugin(QObject *parent) :
ZeiterfassungPlugin(parent)
{
qDebug() << "called";
}

View File

@@ -278,10 +278,18 @@ bool loadPlugins(QSplashScreen &splashScreen)
for(const auto &fileInfo : dir.entryInfoList(QDir::Files))
{
if(fileInfo.isSymLink())
{
qWarning() << "skipping" << fileInfo.fileName() << "because symlink";
continue; // to skip unix so symlinks
}
if(!QLibrary::isLibrary(fileInfo.filePath()))
{
qWarning() << "skipping" << fileInfo.fileName() << "because no QLibrary";
continue; // to skip windows junk files
}
qDebug() << "loading" << fileInfo.fileName();
QPluginLoader loader(fileInfo.filePath());
if(!loader.load())

View File

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

View File

@@ -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()

View File

@@ -23,8 +23,8 @@ StripsWidget::StripsWidget(MainWindow &mainWindow, QWidget *parent) :
{
auto layout = new QVBoxLayout(this);
m_headerLayout = new QHBoxLayout(this);
m_label = new QLabel(this);
m_headerLayout = new QHBoxLayout;
m_label = new QLabel;
{
auto font = m_label->font();
font.setBold(true);
@@ -33,7 +33,7 @@ StripsWidget::StripsWidget(MainWindow &mainWindow, QWidget *parent) :
m_headerLayout->addWidget(m_label, 1);
layout->addLayout(m_headerLayout);
m_stripsLayout = new QVBoxLayout(this);
m_stripsLayout = new QVBoxLayout;
layout->addLayout(m_stripsLayout);
layout->addStretch(1);

View File

@@ -55,8 +55,6 @@ std::unique_ptr<LoginPageReply> ZeiterfassungApi::doLoginPage()
auto reply = std::unique_ptr<QNetworkReply>(m_manager->get(request));
qDebug() << reply->parent();
return std::make_unique<LoginPageReply>(std::move(reply), this);
}

View File

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

View File

@@ -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();

View File

@@ -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);