From: Christian Kamm Date: Fri, 15 Mar 2019 11:12:13 +0000 (+0100) Subject: LogWindow: Remove output, add "go to log folder" button #6475 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~256 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=22234e0e73bac08353e84ef5a3e43e360b4057c0;p=nextcloud-desktop.git LogWindow: Remove output, add "go to log folder" button #6475 --- diff --git a/src/gui/logbrowser.cpp b/src/gui/logbrowser.cpp index 34dc8891c..8ad0410e8 100644 --- a/src/gui/logbrowser.cpp +++ b/src/gui/logbrowser.cpp @@ -18,17 +18,16 @@ #include #include -#include #include #include #include -#include #include #include #include #include #include #include +#include #include "configfile.h" #include "logger.h" @@ -37,197 +36,78 @@ namespace OCC { // ============================================================================== -LogWidget::LogWidget(QWidget *parent) - : QPlainTextEdit(parent) -{ - setReadOnly(true); - QFont font; - font.setFamily(QLatin1String("Courier New")); - font.setFixedPitch(true); - document()->setDefaultFont(font); -} - -// ============================================================================== - LogBrowser::LogBrowser(QWidget *parent) : QDialog(parent) - , _logWidget(new LogWidget(parent)) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setObjectName("LogBrowser"); // for save/restoreGeometry() setWindowTitle(tr("Log Output")); setMinimumWidth(600); - auto *mainLayout = new QVBoxLayout; - // mainLayout->setMargin(0); - - mainLayout->addWidget(_logWidget); - - auto *toolLayout = new QHBoxLayout; - mainLayout->addLayout(toolLayout); + auto mainLayout = new QVBoxLayout; + + auto label = new QLabel( + tr("The client can write debug logs to a temporary folder. " + "These logs are very helpful for diagnosing problems.\n" + "Since log files can get large, the client will start a new one for each sync " + "run and compress older ones. It will also delete log files after a couple " + "of hours to avoid consuming too much disk space.\n" + "If enabled, logs will be written to %1") + .arg(Logger::instance()->temporaryFolderLogDirPath())); + label->setWordWrap(true); + label->setTextInteractionFlags(Qt::TextSelectableByMouse); + label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding); + mainLayout->addWidget(label); - // Search input field - auto *lab = new QLabel(tr("&Search:") + " "); - _findTermEdit = new QLineEdit; - lab->setBuddy(_findTermEdit); - toolLayout->addWidget(lab); - toolLayout->addWidget(_findTermEdit); - - // find button - auto *findBtn = new QPushButton; - findBtn->setText(tr("&Find")); - connect(findBtn, &QAbstractButton::clicked, this, &LogBrowser::slotFind); - toolLayout->addWidget(findBtn); - - // stretch - toolLayout->addStretch(1); - _statusLabel = new QLabel; - toolLayout->addWidget(_statusLabel); - toolLayout->addStretch(5); - - // Debug logging - _logDebugCheckBox = new QCheckBox(tr("&Capture debug messages") + " "); - connect(_logDebugCheckBox, &QCheckBox::stateChanged, this, &LogBrowser::slotDebugCheckStateChanged); - toolLayout->addWidget(_logDebugCheckBox); + // button to permanently save logs + auto enableLoggingButton = new QCheckBox; + enableLoggingButton->setText(tr("Enable logging to temporary folder")); + enableLoggingButton->setChecked(ConfigFile().automaticLogDir()); + connect(enableLoggingButton, &QCheckBox::toggled, this, &LogBrowser::togglePermanentLogging); + mainLayout->addWidget(enableLoggingButton); + + label = new QLabel( + tr("This setting persists across client restarts.\n" + "Note that using any logging command line options will override this setting.")); + label->setWordWrap(true); + label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding); + mainLayout->addWidget(label); + + auto openFolderButton = new QPushButton; + openFolderButton->setText(tr("Open folder")); + connect(openFolderButton, &QPushButton::clicked, this, []() { + QDesktopServices::openUrl(Logger::instance()->temporaryFolderLogDirPath()); + }); + mainLayout->addWidget(openFolderButton); auto *btnbox = new QDialogButtonBox; QPushButton *closeBtn = btnbox->addButton(QDialogButtonBox::Close); connect(closeBtn, &QAbstractButton::clicked, this, &QWidget::close); + mainLayout->addStretch(); mainLayout->addWidget(btnbox); - // button to permanently save logs - _permanentLogging = new QCheckBox; - _permanentLogging->setText(tr("Permanently save logs")); - _permanentLogging->setToolTip( - tr("When this option is enabled and no other logging is configured, " - "logs will be written to a temporary folder and expire after a few hours. " - "This setting persists across client restarts.\n" - "\n" - "Logs will be written to %1") - .arg(Logger::instance()->temporaryFolderLogDirPath())); - _permanentLogging->setChecked(ConfigFile().automaticLogDir()); - btnbox->addButton(_permanentLogging, QDialogButtonBox::ActionRole); - connect(_permanentLogging, &QCheckBox::toggled, this, &LogBrowser::togglePermanentLogging); - - // clear button - _clearBtn = new QPushButton; - _clearBtn->setText(tr("Clear")); - _clearBtn->setToolTip(tr("Clear the log display.")); - btnbox->addButton(_clearBtn, QDialogButtonBox::ActionRole); - connect(_clearBtn, &QAbstractButton::clicked, this, &LogBrowser::slotClearLog); - - // save Button - _saveBtn = new QPushButton; - _saveBtn->setText(tr("S&ave")); - _saveBtn->setToolTip(tr("Save the log file to a file on disk for debugging.")); - btnbox->addButton(_saveBtn, QDialogButtonBox::ActionRole); - connect(_saveBtn, &QAbstractButton::clicked, this, &LogBrowser::slotSave); - setLayout(mainLayout); setModal(false); - Logger::instance()->setLogWindowActivated(true); - // Direct connection for log coming from this thread, and queued for the one in a different thread - connect(Logger::instance(), &Logger::logWindowLog, this, &LogBrowser::slotNewLog, Qt::AutoConnection); - - auto *showLogWindow = new QAction(this); + auto showLogWindow = new QAction(this); showLogWindow->setShortcut(QKeySequence("F12")); connect(showLogWindow, &QAction::triggered, this, &QWidget::close); addAction(showLogWindow); ConfigFile cfg; cfg.restoreGeometry(this); - int lines = cfg.maxLogLines(); - _logWidget->document()->setMaximumBlockCount(lines); } LogBrowser::~LogBrowser() = default; -void LogBrowser::showEvent(QShowEvent *) -{ - // This could have been changed through the --logdebug argument passed through the single application. - _logDebugCheckBox->setCheckState(Logger::instance()->logDebug() ? Qt::Checked : Qt::Unchecked); -} - void LogBrowser::closeEvent(QCloseEvent *) { ConfigFile cfg; cfg.saveGeometry(this); } - -void LogBrowser::slotNewLog(const QString &msg) -{ - if (_logWidget->isVisible()) { - _logWidget->appendPlainText(msg); - } -} - - -void LogBrowser::slotFind() -{ - QString searchText = _findTermEdit->text(); - - if (searchText.isEmpty()) - return; - - search(searchText); -} - -void LogBrowser::slotDebugCheckStateChanged(int checkState) -{ - Logger::instance()->setLogDebug(checkState == Qt::Checked); -} - -void LogBrowser::search(const QString &str) -{ - QList extraSelections; - - _logWidget->moveCursor(QTextCursor::Start); - QColor color = QColor(Qt::gray).lighter(130); - _statusLabel->clear(); - - while (_logWidget->find(str)) { - QTextEdit::ExtraSelection extra; - extra.format.setBackground(color); - - extra.cursor = _logWidget->textCursor(); - extraSelections.append(extra); - } - - QString stat = QString::fromLatin1("Search term %1 with %2 search results.").arg(str).arg(extraSelections.count()); - _statusLabel->setText(stat); - - _logWidget->setExtraSelections(extraSelections); -} - -void LogBrowser::slotSave() -{ - _saveBtn->setEnabled(false); - - QString saveFile = QFileDialog::getSaveFileName(this, tr("Save log file"), QDir::homePath()); - - if (!saveFile.isEmpty()) { - QFile file(saveFile); - - if (file.open(QIODevice::WriteOnly)) { - QTextStream stream(&file); - stream << _logWidget->toPlainText(); - file.close(); - } else { - QMessageBox::critical(this, tr("Error"), tr("Could not write to log file %1").arg(saveFile)); - } - } - _saveBtn->setEnabled(true); -} - -void LogBrowser::slotClearLog() -{ - _logWidget->clear(); -} - void LogBrowser::togglePermanentLogging(bool enabled) { ConfigFile().setAutomaticLogDir(enabled); diff --git a/src/gui/logbrowser.h b/src/gui/logbrowser.h index 7694b6311..c49e26b73 100644 --- a/src/gui/logbrowser.h +++ b/src/gui/logbrowser.h @@ -29,19 +29,6 @@ namespace OCC { -/** - * @brief The LogWidget class - * @ingroup gui - */ -class LogWidget : public QPlainTextEdit -{ - Q_OBJECT -public: - explicit LogWidget(QWidget *parent = nullptr); - -signals: -}; - /** * @brief The LogBrowser class * @ingroup gui @@ -53,29 +40,11 @@ public: explicit LogBrowser(QWidget *parent = nullptr); ~LogBrowser(); - void setLogFile(const QString &, bool); - protected: - void showEvent(QShowEvent *) override; void closeEvent(QCloseEvent *) override; protected slots: - void slotNewLog(const QString &msg); - void slotFind(); - void slotDebugCheckStateChanged(int); - void search(const QString &); - void slotSave(); - void slotClearLog(); void togglePermanentLogging(bool enabled); - -private: - LogWidget *_logWidget; - QLineEdit *_findTermEdit; - QCheckBox *_logDebugCheckBox; - QCheckBox *_permanentLogging; - QPushButton *_saveBtn; - QPushButton *_clearBtn; - QLabel *_statusLabel; }; } // namespace diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index a9df83a63..1b7b8791a 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -121,7 +121,7 @@ void Logger::log(Log log) bool Logger::isNoop() const { QMutexLocker lock(&_mutex); - return !_logstream && !_logWindowActivated; + return !_logstream; } bool Logger::isLoggingToFile() const @@ -163,12 +163,6 @@ void Logger::mirallLog(const QString &message) Logger::instance()->log(log_); } -void Logger::setLogWindowActivated(bool activated) -{ - QMutexLocker locker(&_mutex); - _logWindowActivated = activated; -} - QString Logger::logFile() const { return _logFile.fileName(); diff --git a/src/libsync/logger.h b/src/libsync/logger.h index c8ff3bce8..4963e40fc 100644 --- a/src/libsync/logger.h +++ b/src/libsync/logger.h @@ -58,8 +58,6 @@ public: void postOptionalGuiLog(const QString &title, const QString &message); void postGuiMessage(const QString &title, const QString &message); - void setLogWindowActivated(bool activated); - QString logFile() const; void setLogFile(const QString &name); @@ -104,7 +102,6 @@ private: ~Logger(); QList _logs; bool _showTime = true; - bool _logWindowActivated = false; QFile _logFile; bool _doFileFlush = false; int _logExpire = 0;