Move showLog() entirely to TextViewDialog
So Plasmoid can use it as well
This commit is contained in:
parent
9fa45c6dc9
commit
e797d8e76c
|
@ -255,19 +255,9 @@ void TrayWidget::showOwnDeviceId()
|
||||||
|
|
||||||
void TrayWidget::showLog()
|
void TrayWidget::showLog()
|
||||||
{
|
{
|
||||||
auto *dlg = new TextViewDialog(tr("Log"), this);
|
auto *const dlg = TextViewDialog::forLogEntries(m_connection);
|
||||||
auto loadLog = [dlg, this] {
|
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
connect(dlg, &QWidget::destroyed, bind(static_cast<bool (*)(const QMetaObject::Connection &)>(&QObject::disconnect),
|
centerWidget(dlg);
|
||||||
m_connection.requestLog([dlg, this](const std::vector<SyncthingLogEntry> &entries) {
|
|
||||||
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);
|
|
||||||
loadLog();
|
|
||||||
showDialog(dlg);
|
showDialog(dlg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "./textviewdialog.h"
|
#include "./textviewdialog.h"
|
||||||
|
|
||||||
|
#include "../../connector/syncthingconnection.h"
|
||||||
#include "../../connector/syncthingdir.h"
|
#include "../../connector/syncthingdir.h"
|
||||||
|
|
||||||
// use meta-data of syncthingtray application here
|
// use meta-data of syncthingtray application here
|
||||||
|
@ -125,6 +126,24 @@ TextViewDialog *TextViewDialog::forDirectoryErrors(const Data::SyncthingDir &dir
|
||||||
return textViewDlg;
|
return textViewDlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextViewDialog *TextViewDialog::forLogEntries(SyncthingConnection &connection)
|
||||||
|
{
|
||||||
|
auto *const dlg = new TextViewDialog(tr("Log"));
|
||||||
|
const auto loadLog = [dlg, &connection] {
|
||||||
|
connect(dlg, &QWidget::destroyed, bind(static_cast<bool (*)(const QMetaObject::Connection &)>(&QObject::disconnect),
|
||||||
|
connection.requestLog([dlg](const std::vector<SyncthingLogEntry> &entries) {
|
||||||
|
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);
|
||||||
|
loadLog();
|
||||||
|
return dlg;
|
||||||
|
}
|
||||||
|
|
||||||
void TextViewDialog::keyPressEvent(QKeyEvent *event)
|
void TextViewDialog::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
switch (event->key()) {
|
switch (event->key()) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
QT_FORWARD_DECLARE_CLASS(QTextBrowser)
|
QT_FORWARD_DECLARE_CLASS(QTextBrowser)
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
class SyncthingConnection;
|
||||||
struct SyncthingDir;
|
struct SyncthingDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +21,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);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void reload();
|
void reload();
|
||||||
|
|
Loading…
Reference in New Issue