Don't duplicate code for showing log entries
This commit is contained in:
parent
5046cb3eed
commit
bae7f7c4c8
|
@ -236,12 +236,11 @@ void TrayWidget::showLog()
|
||||||
|
|
||||||
void TrayWidget::showNotifications()
|
void TrayWidget::showNotifications()
|
||||||
{
|
{
|
||||||
auto *dlg = new TextViewDialog(tr("New notifications"), this);
|
auto *const dlg = TextViewDialog::forLogEntries(m_notifications, tr("New notifications"));
|
||||||
for (const SyncthingLogEntry &entry : m_notifications) {
|
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
dlg->browser()->append(entry.when % QChar(':') % QChar(' ') % QChar('\n') % entry.message % QChar('\n'));
|
centerWidget(dlg);
|
||||||
}
|
|
||||||
m_notifications.clear();
|
|
||||||
showDialog(dlg);
|
showDialog(dlg);
|
||||||
|
m_notifications.clear();
|
||||||
dismissNotifications();
|
dismissNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,11 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace std::placeholders;
|
||||||
using namespace Dialogs;
|
using namespace Dialogs;
|
||||||
using namespace Data;
|
using namespace Data;
|
||||||
|
|
||||||
|
@ -131,19 +133,20 @@ TextViewDialog *TextViewDialog::forLogEntries(SyncthingConnection &connection)
|
||||||
auto *const dlg = new TextViewDialog(tr("Log"));
|
auto *const dlg = new TextViewDialog(tr("Log"));
|
||||||
const auto loadLog = [dlg, &connection] {
|
const auto loadLog = [dlg, &connection] {
|
||||||
connect(dlg, &QWidget::destroyed, bind(static_cast<bool (*)(const QMetaObject::Connection &)>(&QObject::disconnect),
|
connect(dlg, &QWidget::destroyed, bind(static_cast<bool (*)(const QMetaObject::Connection &)>(&QObject::disconnect),
|
||||||
connection.requestLog([dlg](const std::vector<SyncthingLogEntry> &entries) {
|
connection.requestLog(bind(&TextViewDialog::showLogEntries, dlg, _1))));
|
||||||
dlg->browser()->clear();
|
|
||||||
for (const SyncthingLogEntry &entry : entries) {
|
|
||||||
dlg->browser()->append(
|
|
||||||
entry.when % QChar(':') % QChar(' ') % QChar('\n') % entry.message % QChar('\n'));
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
};
|
};
|
||||||
connect(dlg, &TextViewDialog::reload, loadLog);
|
connect(dlg, &TextViewDialog::reload, loadLog);
|
||||||
loadLog();
|
loadLog();
|
||||||
return dlg;
|
return dlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextViewDialog *TextViewDialog::forLogEntries(const std::vector<SyncthingLogEntry> &logEntries, const QString &title)
|
||||||
|
{
|
||||||
|
auto *const dlg = new TextViewDialog(title.isEmpty() ? tr("Log") : title);
|
||||||
|
dlg->showLogEntries(logEntries);
|
||||||
|
return dlg;
|
||||||
|
}
|
||||||
|
|
||||||
void TextViewDialog::keyPressEvent(QKeyEvent *event)
|
void TextViewDialog::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
switch (event->key()) {
|
switch (event->key()) {
|
||||||
|
@ -156,4 +159,12 @@ void TextViewDialog::keyPressEvent(QKeyEvent *event)
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextViewDialog::showLogEntries(const std::vector<SyncthingLogEntry> &logEntries)
|
||||||
|
{
|
||||||
|
browser()->clear();
|
||||||
|
for (const SyncthingLogEntry &entry : logEntries) {
|
||||||
|
browser()->append(entry.when % QChar(':') % QChar(' ') % QChar('\n') % entry.message % QChar('\n'));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ QT_FORWARD_DECLARE_CLASS(QTextBrowser)
|
||||||
namespace Data {
|
namespace Data {
|
||||||
class SyncthingConnection;
|
class SyncthingConnection;
|
||||||
struct SyncthingDir;
|
struct SyncthingDir;
|
||||||
|
struct SyncthingLogEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace QtGui {
|
namespace QtGui {
|
||||||
|
@ -22,6 +23,7 @@ public:
|
||||||
QTextBrowser *browser();
|
QTextBrowser *browser();
|
||||||
static TextViewDialog *forDirectoryErrors(const Data::SyncthingDir &dir);
|
static TextViewDialog *forDirectoryErrors(const Data::SyncthingDir &dir);
|
||||||
static TextViewDialog *forLogEntries(Data::SyncthingConnection &connection);
|
static TextViewDialog *forLogEntries(Data::SyncthingConnection &connection);
|
||||||
|
static TextViewDialog *forLogEntries(const std::vector<Data::SyncthingLogEntry> &logEntries, const QString &title = QString());
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void reload();
|
void reload();
|
||||||
|
@ -30,6 +32,8 @@ protected:
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void showLogEntries(const std::vector<Data::SyncthingLogEntry> &logEntries);
|
||||||
|
|
||||||
QTextBrowser *m_browser;
|
QTextBrowser *m_browser;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue