Moved presence functionality from mainWindow into plugin
This commit is contained in:
@@ -7,8 +7,3 @@ LunchMealPlugin::LunchMealPlugin(QObject *parent) :
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LunchMealPlugin::initialize()
|
||||
{
|
||||
qDebug() << "called";
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ public:
|
||||
explicit LunchMealPlugin(QObject *parent = 0);
|
||||
|
||||
// ZeiterfassungPlugin interface
|
||||
void initialize() Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // LUNCHMEALPLUGIN_H
|
||||
|
@@ -2,13 +2,16 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "presencewidget.h"
|
||||
|
||||
PresencePlugin::PresencePlugin(QObject *parent) :
|
||||
ZeiterfassungPlugin(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PresencePlugin::initialize()
|
||||
{
|
||||
qDebug() << "called";
|
||||
}
|
||||
|
||||
void PresencePlugin::attachTo(MainWindow &mainWindow)
|
||||
{
|
||||
new PresenceWidget(mainWindow);
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "zeiterfassungplugin.h"
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class Q_DECL_EXPORT PresencePlugin : public ZeiterfassungPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -15,7 +17,7 @@ public:
|
||||
explicit PresencePlugin(QObject *parent = 0);
|
||||
|
||||
// ZeiterfassungPlugin interface
|
||||
void initialize() Q_DECL_OVERRIDE;
|
||||
void attachTo(MainWindow &mainWindow);
|
||||
};
|
||||
|
||||
#endif // PRESENCEPLUGIN_H
|
||||
|
@@ -14,8 +14,10 @@ DEPENDPATH += $$PWD/../../zeiterfassunglib
|
||||
|
||||
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
|
||||
|
||||
HEADERS += presenceplugin.h
|
||||
HEADERS += presenceplugin.h \
|
||||
presencewidget.h
|
||||
|
||||
SOURCES += presenceplugin.cpp
|
||||
SOURCES += presenceplugin.cpp \
|
||||
presencewidget.cpp
|
||||
|
||||
OTHER_FILES += presenceplugin.json
|
||||
|
77
plugins/presenceplugin/presencewidget.cpp
Normal file
77
plugins/presenceplugin/presencewidget.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "presencewidget.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QStatusBar>
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include <QStringBuilder>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
PresenceWidget::PresenceWidget(MainWindow &mainWindow) :
|
||||
QWidget(&mainWindow),
|
||||
m_mainWindow(mainWindow)
|
||||
{
|
||||
m_labelAvailable = new QLabel(this);
|
||||
m_labelAvailable->setFrameShape(QFrame::Panel);
|
||||
m_labelAvailable->setFrameShadow(QFrame::Sunken);
|
||||
m_mainWindow.statusBar()->addWidget(m_labelAvailable);
|
||||
|
||||
m_labelNotAvailable = new QLabel(this);
|
||||
m_labelNotAvailable->setFrameShape(QFrame::Panel);
|
||||
m_labelNotAvailable->setFrameShadow(QFrame::Sunken);
|
||||
m_mainWindow.statusBar()->addWidget(m_labelNotAvailable);
|
||||
|
||||
auto timer = new QTimer(this);
|
||||
timer->setInterval(60000);
|
||||
connect(timer, &QTimer::timeout, this, &PresenceWidget::timeout);
|
||||
timer->start();
|
||||
|
||||
timeout();
|
||||
}
|
||||
|
||||
void PresenceWidget::timeout()
|
||||
{
|
||||
if(m_reply)
|
||||
{
|
||||
qWarning() << "last request not finished yet!";
|
||||
return;
|
||||
}
|
||||
|
||||
m_labelAvailable->setText(tr("%0: %1").arg(tr("Available")).arg(tr("???")));
|
||||
m_labelNotAvailable->setText(tr("%0: %1").arg(tr("Not available")).arg(tr("???")));
|
||||
|
||||
m_reply = m_mainWindow.erfassung().doGetPresenceStatus();
|
||||
connect(m_reply.get(), &ZeiterfassungReply::finished, this, &PresenceWidget::finished);
|
||||
}
|
||||
|
||||
void PresenceWidget::finished()
|
||||
{
|
||||
if(!m_reply->success())
|
||||
{
|
||||
QMessageBox::warning(&m_mainWindow, tr("Could not get presence status!"),
|
||||
tr("Could not get presence status!") % "\n\n" % m_reply->message());
|
||||
goto after;
|
||||
}
|
||||
|
||||
{
|
||||
int available = 0,
|
||||
notAvailable = 0;
|
||||
for(const auto &status : m_reply->presenceStatuses())
|
||||
{
|
||||
if(status.presence == QStringLiteral("J"))
|
||||
available++;
|
||||
else if(status.presence == QStringLiteral("N"))
|
||||
notAvailable++;
|
||||
else
|
||||
qWarning() << "unknown presence" << status.firstName << status.lastName << status.presence;
|
||||
}
|
||||
|
||||
m_labelAvailable->setText(tr("%0: %1").arg(tr("Available")).arg(available));
|
||||
m_labelNotAvailable->setText(tr("%0: %1").arg(tr("Not available")).arg(notAvailable));
|
||||
}
|
||||
|
||||
after:
|
||||
m_reply = Q_NULLPTR;
|
||||
}
|
31
plugins/presenceplugin/presencewidget.h
Normal file
31
plugins/presenceplugin/presencewidget.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef PRESENCEWIDGET_H
|
||||
#define PRESENCEWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "replies/getpresencestatusreply.h"
|
||||
|
||||
class QLabel;
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class PresenceWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PresenceWidget(MainWindow &mainWindow);
|
||||
|
||||
private Q_SLOTS:
|
||||
void timeout();
|
||||
void finished();
|
||||
|
||||
private:
|
||||
MainWindow &m_mainWindow;
|
||||
|
||||
QLabel *m_labelAvailable;
|
||||
QLabel *m_labelNotAvailable;
|
||||
|
||||
std::unique_ptr<GetPresenceStatusReply> m_reply;
|
||||
};
|
||||
|
||||
#endif // PRESENCEWIDGET_H
|
@@ -7,8 +7,3 @@ WeatherPlugin::WeatherPlugin(QObject *parent) :
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void WeatherPlugin::initialize()
|
||||
{
|
||||
qDebug() << "called";
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ public:
|
||||
explicit WeatherPlugin(QObject *parent = 0);
|
||||
|
||||
// ZeiterfassungPlugin interface
|
||||
void initialize() Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // WEATHERPLUGIN_H
|
||||
|
@@ -33,6 +33,8 @@ struct {
|
||||
QTranslator zeiterfassunglibTranslator;
|
||||
} translators;
|
||||
|
||||
QVector<ZeiterfassungPlugin*> plugins;
|
||||
|
||||
bool loadAndInstallTranslator(QTranslator &translator,
|
||||
const QLocale &locale,
|
||||
const QString &filename,
|
||||
@@ -315,7 +317,7 @@ bool loadPlugins(QSplashScreen &splashScreen)
|
||||
continue;
|
||||
}
|
||||
|
||||
plugin->initialize();
|
||||
plugins.append(plugin);
|
||||
}
|
||||
|
||||
return ok;
|
||||
@@ -377,6 +379,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
MainWindow mainWindow(settings, erfassung, userInfo, stripFactory);
|
||||
splashScreen.finish(&mainWindow);
|
||||
|
||||
for(auto plugin : plugins)
|
||||
plugin->attachTo(mainWindow);
|
||||
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
|
@@ -48,8 +48,7 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass
|
||||
m_getAuswertungReply(Q_NULLPTR),
|
||||
m_bookingsModel(new BookingsModel(this)),
|
||||
m_timeAssignmentsModel(new TimeAssignmentsModel(this)),
|
||||
m_currentStripWidget(Q_NULLPTR),
|
||||
m_getPresenceStatusReply(Q_NULLPTR)
|
||||
m_currentStripWidget(Q_NULLPTR)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -108,10 +107,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass
|
||||
connect(m_timeAssignmentsModel, &TimeAssignmentsModel::enabledChanged, ui->treeViewTimeAssignments, &QWidget::setEnabled);
|
||||
connect(ui->treeViewTimeAssignments, &QWidget::customContextMenuRequested, this, &MainWindow::contextMenuTimeAssignment);
|
||||
|
||||
ui->statusbar->addWidget(m_presenceLabel = new QLabel(tr("???"), ui->statusbar));
|
||||
m_presenceLabel->setFrameShape(QFrame::Panel);
|
||||
m_presenceLabel->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
ui->statusbar->addPermanentWidget(m_balanceLabel = new QLabel(ui->statusbar));
|
||||
m_balanceLabel->setFrameShape(QFrame::Panel);
|
||||
m_balanceLabel->setFrameShadow(QFrame::Sunken);
|
||||
@@ -121,15 +116,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass
|
||||
|
||||
dateChanged();
|
||||
|
||||
{
|
||||
auto timer = new QTimer(this);
|
||||
timer->setInterval(60000);
|
||||
connect(timer, &QTimer::timeout, this, &MainWindow::refreshPresence);
|
||||
timer->start();
|
||||
}
|
||||
|
||||
refreshPresence();
|
||||
|
||||
if(settings.lastUpdateCheck().isNull() || settings.lastUpdateCheck() < QDate::currentDate())
|
||||
new UpdateDialog(settings, erfassung.manager(), this);
|
||||
}
|
||||
@@ -139,6 +125,46 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QMenu *MainWindow::menuFile() const
|
||||
{
|
||||
return ui->menuFile;
|
||||
}
|
||||
|
||||
QMenu *MainWindow::menuView() const
|
||||
{
|
||||
return ui->menuView;
|
||||
}
|
||||
|
||||
QMenu *MainWindow::menuTools() const
|
||||
{
|
||||
return ui->menuTools;
|
||||
}
|
||||
|
||||
QMenu *MainWindow::menuAbout() const
|
||||
{
|
||||
return ui->menuAbout;
|
||||
}
|
||||
|
||||
ZeiterfassungSettings &MainWindow::settings() const
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
|
||||
ZeiterfassungApi &MainWindow::erfassung() const
|
||||
{
|
||||
return m_erfassung;
|
||||
}
|
||||
|
||||
const ZeiterfassungApi::UserInfo &MainWindow::userInfo() const
|
||||
{
|
||||
return m_userInfo;
|
||||
}
|
||||
|
||||
StripFactory &MainWindow::stripFactory() const
|
||||
{
|
||||
return m_stripFactory;
|
||||
}
|
||||
|
||||
void MainWindow::getProjectsFinished()
|
||||
{
|
||||
if(m_getProjectsReply->success())
|
||||
@@ -663,34 +689,6 @@ void MainWindow::openAuswertung()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::refreshPresence()
|
||||
{
|
||||
m_presenceLabel->setText(tr("???"));
|
||||
|
||||
m_getPresenceStatusReply = m_erfassung.doGetPresenceStatus();
|
||||
connect(m_getPresenceStatusReply.get(), &ZeiterfassungReply::finished, this, &MainWindow::getPresenceStatusFinished);
|
||||
}
|
||||
|
||||
void MainWindow::getPresenceStatusFinished()
|
||||
{
|
||||
if(m_getPresenceStatusReply->success())
|
||||
{
|
||||
QMap<QString, int> counts;
|
||||
for(const auto &presenceStatus : m_getPresenceStatusReply->presenceStatuses())
|
||||
counts[presenceStatus.presence]++;
|
||||
QString text;
|
||||
for(auto iter = counts.constBegin(); iter != counts.constEnd(); iter++)
|
||||
{
|
||||
if(!text.isEmpty())
|
||||
text.append(' ');
|
||||
text.append(QStringLiteral("%0: %1").arg(iter.key()).arg(iter.value()));
|
||||
}
|
||||
m_presenceLabel->setText(text);
|
||||
}
|
||||
|
||||
m_getPresenceStatusReply = Q_NULLPTR;
|
||||
}
|
||||
|
||||
void MainWindow::minimumTimeChanged()
|
||||
{
|
||||
ui->timeEditTime->setMinimumTime(m_currentStripWidget->minimumTime());
|
||||
|
@@ -31,6 +31,16 @@ public:
|
||||
StripFactory &stripFactory, QWidget *parent = Q_NULLPTR);
|
||||
~MainWindow();
|
||||
|
||||
QMenu *menuFile() const;
|
||||
QMenu *menuView() const;
|
||||
QMenu *menuTools() const;
|
||||
QMenu *menuAbout() const;
|
||||
|
||||
ZeiterfassungSettings &settings() const;
|
||||
ZeiterfassungApi &erfassung() const;
|
||||
const ZeiterfassungApi::UserInfo &userInfo() const;
|
||||
StripFactory &stripFactory() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void getProjectsFinished();
|
||||
void getAuswertungFinished();
|
||||
@@ -40,8 +50,6 @@ private Q_SLOTS:
|
||||
void pushButtonEndPressed();
|
||||
void dateChanged(bool force = false);
|
||||
void openAuswertung();
|
||||
void refreshPresence();
|
||||
void getPresenceStatusFinished();
|
||||
|
||||
void minimumTimeChanged();
|
||||
void refreshingChanged();
|
||||
@@ -69,15 +77,11 @@ private:
|
||||
QDate m_auswertungDate;
|
||||
QByteArray m_auswertung;
|
||||
|
||||
QLabel *m_presenceLabel;
|
||||
|
||||
QLabel *m_balanceLabel;
|
||||
QLabel *m_holidaysLabel;
|
||||
|
||||
std::array<StripsWidget*, 7> m_stripsWidgets;
|
||||
StripsWidget *m_currentStripWidget;
|
||||
|
||||
std::unique_ptr<GetPresenceStatusReply> m_getPresenceStatusReply;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@@ -251,7 +251,7 @@
|
||||
</property>
|
||||
<addaction name="actionQuit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_About">
|
||||
<widget class="QMenu" name="menuAbout">
|
||||
<property name="title">
|
||||
<string>&About</string>
|
||||
</property>
|
||||
@@ -262,23 +262,23 @@
|
||||
<addaction name="actionAboutzeiterfassung"/>
|
||||
<addaction name="actionAboutQt"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_View">
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
<string>&View</string>
|
||||
</property>
|
||||
<addaction name="actionToday"/>
|
||||
<addaction name="actionRefresh"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Tools">
|
||||
<widget class="QMenu" name="menuTools">
|
||||
<property name="title">
|
||||
<string>&Tools</string>
|
||||
</property>
|
||||
<addaction name="actionAuswertung"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menu_View"/>
|
||||
<addaction name="menu_Tools"/>
|
||||
<addaction name="menu_About"/>
|
||||
<addaction name="menuView"/>
|
||||
<addaction name="menuTools"/>
|
||||
<addaction name="menuAbout"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
|
@@ -5,6 +5,9 @@
|
||||
|
||||
#include "zeiterfassunglib_global.h"
|
||||
|
||||
class MainWindow;
|
||||
class StripsWidget;
|
||||
|
||||
class ZEITERFASSUNGLIBSHARED_EXPORT ZeiterfassungPlugin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -12,7 +15,8 @@ class ZEITERFASSUNGLIBSHARED_EXPORT ZeiterfassungPlugin : public QObject
|
||||
public:
|
||||
explicit ZeiterfassungPlugin(QObject *parent = 0);
|
||||
|
||||
virtual void initialize() = 0;
|
||||
virtual void attachTo(MainWindow &mainWindow) { Q_UNUSED(mainWindow) }
|
||||
virtual void attachTo(StripsWidget &stripsWidget) { Q_UNUSED(stripsWidget) }
|
||||
};
|
||||
|
||||
Q_DECLARE_INTERFACE(ZeiterfassungPlugin, "dbsoftware.zeiterfassung.plugin/1.0")
|
||||
|
Reference in New Issue
Block a user