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()
|
||||
{
|
||||
auto *dlg = new TextViewDialog(tr("Log"), this);
|
||||
auto loadLog = [dlg, this] {
|
||||
connect(dlg, &QWidget::destroyed, bind(static_cast<bool (*)(const QMetaObject::Connection &)>(&QObject::disconnect),
|
||||
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();
|
||||
auto *const dlg = TextViewDialog::forLogEntries(m_connection);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
centerWidget(dlg);
|
||||
showDialog(dlg);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "./textviewdialog.h"
|
||||
|
||||
#include "../../connector/syncthingconnection.h"
|
||||
#include "../../connector/syncthingdir.h"
|
||||
|
||||
// use meta-data of syncthingtray application here
|
||||
|
@ -125,6 +126,24 @@ TextViewDialog *TextViewDialog::forDirectoryErrors(const Data::SyncthingDir &dir
|
|||
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)
|
||||
{
|
||||
switch (event->key()) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
QT_FORWARD_DECLARE_CLASS(QTextBrowser)
|
||||
|
||||
namespace Data {
|
||||
class SyncthingConnection;
|
||||
struct SyncthingDir;
|
||||
}
|
||||
|
||||
|
@ -20,6 +21,7 @@ public:
|
|||
|
||||
QTextBrowser *browser();
|
||||
static TextViewDialog *forDirectoryErrors(const Data::SyncthingDir &dir);
|
||||
static TextViewDialog *forLogEntries(Data::SyncthingConnection &connection);
|
||||
|
||||
Q_SIGNALS:
|
||||
void reload();
|
||||
|
|
Loading…
Reference in New Issue