1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
/***************************************************************************
showkloglogwidget.cpp - description
-------------------
begin : jan 2021
copyright : (C) 2021 by Jaime Robles
email : jaime@robles.es
***************************************************************************/
/*****************************************************************************
* This file is part of KLog. *
* *
* KLog 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 3 of the License, or *
* (at your option) any later version. *
* *
* KLog 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. *
* *
* You should have received a copy of the GNU General Public License *
* along with KLog. If not, see <https://www.gnu.org/licenses/>. *
* *
*****************************************************************************/
#include "showkloglogwidget.h"
ShowKLogLogWidget::ShowKLogLogWidget(QWidget *parent) : QWidget(parent)
{
util = new Utilities(Q_FUNC_INFO);
levelComboBox = new QComboBox;
model = new QStringListModel();
//QStringList list;
list.clear();
model->setStringList(list);
logsView = new QListView;
logsView->setModel(model);
createUI();
}
ShowKLogLogWidget::~ShowKLogLogWidget()
{
delete(util);
}
void ShowKLogLogWidget::createUI()
{
levelComboBox->clear();
levelComboBox->addItems(util->getDebugLevels());
levelComboBox->setCurrentIndex(0);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(levelComboBox);
layout->addWidget(logsView);
setLayout(layout);
connect(levelComboBox, SIGNAL(currentTextChanged (QString)), this, SLOT(slotLevelComboBoxChanged(QString) ) ) ;
}
void ShowKLogLogWidget::add(const QString &_func, QString const &_log, const DebugLogLevel _l)
{
//qDebug() << "Debugging0: " << _func << "/" << _log << "/" << util->debugLevelToString(logLevel) << "/" << util->debugLevelToString(_l);
if (logLevel >_l)
{
return;
}
QString msg;
msg = QString("%1 %2 - %3 - %4").arg(QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm:ss")).arg(util->debugLevelToString (_l)).arg(_func).arg(_log);
//qDebug() << "Debugging1: " << msg;
if(model->insertRow(0)) {
QModelIndex index = model->index(0, 0);
model->setData(index, msg);
}
return;
// FILE
debugFile = new QFile(util->getDebugLogFile());
if (!debugFile->open(QIODevice::Append | QIODevice::Text)) /* Flawfinder: ignore */
{
//qDebug() << Q_FUNC_INFO << " Can't open the file to log - EXITING";
return;
}
QTextStream out(debugFile);
out << (QDateTime::currentDateTime()).toString("yyyyMMdd-hhmmsszzz") << " - " << _func << " - " << msg;
//qDebug() << "Debugging2: " << out.string();
debugFile->close();
}
void ShowKLogLogWidget::setLogLevel(const DebugLogLevel _l)
{
//qDebug() << Q_FUNC_INFO << " - New log Level: " << util->debugLevelToString(_l);
QString logString = util->debugLevelToString(_l);
if (util->isValidLogLevel(logString))
levelComboBox->setCurrentIndex(levelComboBox->findText(logString, Qt::MatchCaseSensitive));
else
{
levelComboBox->setCurrentIndex(0);
logLevel = util->stringToDebugLevel("None");
return;
}
logLevel = _l;
}
void ShowKLogLogWidget::slotLevelComboBoxChanged(const QString &_l)
{
emit newLogLevel(util->stringToDebugLevel(_l));
}
|