2012-06-05 17:11:29 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "logbrowser.h"
|
|
|
|
|
2020-08-13 14:00:56 +03:00
|
|
|
#include <cstdio>
|
2012-06-05 17:11:29 +04:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QCoreApplication>
|
2013-11-15 18:45:21 +04:00
|
|
|
#include <QSettings>
|
2013-08-14 19:46:58 +04:00
|
|
|
#include <QAction>
|
2019-03-15 14:12:13 +03:00
|
|
|
#include <QDesktopServices>
|
2012-06-05 17:11:29 +04:00
|
|
|
|
2014-11-10 01:25:57 +03:00
|
|
|
#include "configfile.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "logger.h"
|
2012-06-05 17:11:29 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2012-06-05 17:11:29 +04:00
|
|
|
|
|
|
|
// ==============================================================================
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
LogBrowser::LogBrowser(QWidget *parent)
|
|
|
|
: QDialog(parent)
|
2012-06-05 17:11:29 +04:00
|
|
|
{
|
2013-11-13 23:12:56 +04:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2013-07-22 14:28:43 +04:00
|
|
|
setObjectName("LogBrowser"); // for save/restoreGeometry()
|
2012-06-05 17:11:29 +04:00
|
|
|
setWindowTitle(tr("Log Output"));
|
|
|
|
setMinimumWidth(600);
|
|
|
|
|
2019-03-15 14:12:13 +03:00
|
|
|
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);
|
2012-06-05 17:11:29 +04:00
|
|
|
|
2019-03-15 14:12:13 +03:00
|
|
|
// 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, []() {
|
2019-05-23 13:50:04 +03:00
|
|
|
QString path = Logger::instance()->temporaryFolderLogDirPath();
|
|
|
|
QDir().mkpath(path);
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
2019-03-15 14:12:13 +03:00
|
|
|
});
|
|
|
|
mainLayout->addWidget(openFolderButton);
|
2017-05-09 18:04:04 +03:00
|
|
|
|
2020-05-18 21:54:23 +03:00
|
|
|
auto *btnbox = new QDialogButtonBox;
|
2017-05-17 11:55:42 +03:00
|
|
|
QPushButton *closeBtn = btnbox->addButton(QDialogButtonBox::Close);
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(closeBtn, &QAbstractButton::clicked, this, &QWidget::close);
|
2012-06-05 17:11:29 +04:00
|
|
|
|
2019-03-15 14:12:13 +03:00
|
|
|
mainLayout->addStretch();
|
2017-05-17 11:55:42 +03:00
|
|
|
mainLayout->addWidget(btnbox);
|
2012-06-05 17:11:29 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
setLayout(mainLayout);
|
2012-06-05 17:11:29 +04:00
|
|
|
|
|
|
|
setModal(false);
|
|
|
|
|
2019-03-15 14:12:13 +03:00
|
|
|
auto showLogWindow = new QAction(this);
|
2013-08-14 19:46:58 +04:00
|
|
|
showLogWindow->setShortcut(QKeySequence("F12"));
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(showLogWindow, &QAction::triggered, this, &QWidget::close);
|
2013-08-14 19:46:58 +04:00
|
|
|
addAction(showLogWindow);
|
|
|
|
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfg;
|
2013-07-22 14:28:43 +04:00
|
|
|
cfg.restoreGeometry(this);
|
2012-06-05 17:11:29 +04:00
|
|
|
}
|
|
|
|
|
2020-05-25 22:33:24 +03:00
|
|
|
LogBrowser::~LogBrowser() = default;
|
2013-09-20 16:18:28 +04:00
|
|
|
|
|
|
|
void LogBrowser::closeEvent(QCloseEvent *)
|
2012-06-15 15:04:23 +04:00
|
|
|
{
|
2014-11-10 00:30:29 +03:00
|
|
|
ConfigFile cfg;
|
2013-08-23 14:41:29 +04:00
|
|
|
cfg.saveGeometry(this);
|
2012-06-15 15:04:23 +04:00
|
|
|
}
|
|
|
|
|
2018-04-10 14:07:20 +03:00
|
|
|
void LogBrowser::togglePermanentLogging(bool enabled)
|
|
|
|
{
|
|
|
|
ConfigFile().setAutomaticLogDir(enabled);
|
|
|
|
|
|
|
|
auto logger = Logger::instance();
|
|
|
|
if (enabled) {
|
|
|
|
if (!logger->isLoggingToFile()) {
|
|
|
|
logger->setupTemporaryFolderLogDir();
|
2019-04-16 10:18:19 +03:00
|
|
|
logger->enterNextLogFile();
|
2018-04-10 14:07:20 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger->disableTemporaryFolderLogDir();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:11:29 +04:00
|
|
|
} // namespace
|