Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 7aff08c1 authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 390752 - Kdebugsettings overwrites default debug level for all log categories

FIXED-IN: 18.04.0
BUG: 390752
parent 85cbc330
......@@ -95,4 +95,18 @@ void CategoryTypeComboBoxTest::shouldChangeDefaultCategory()
QVERIFY(w.loggingCategoryIsNotDefault());
}
void CategoryTypeComboBoxTest::shouldVerifyThatDefaultCategoryIsCorrect()
{
CategoryTypeComboBox w(true);
w.setDefaultCategories(LoggingCategory::All);
QCOMPARE(w.defaultCategories(), LoggingCategory::All);
w.setDefaultCategories(LoggingCategory::Critical);
QCOMPARE(w.defaultCategories(), LoggingCategory::Critical);
w.setDefaultCategories(LoggingCategory::Debug);
QCOMPARE(w.defaultCategories(), LoggingCategory::Debug);
}
QTEST_MAIN(CategoryTypeComboBoxTest)
......@@ -36,6 +36,8 @@ private Q_SLOTS:
void shouldVerifyItNotDefault();
void shouldChangeDefaultCategory();
void shouldVerifyThatDefaultCategoryIsCorrect();
};
#endif // CATEGORYTYPECOMBOBOXTEST_H
......@@ -51,10 +51,23 @@ void KDebugSettingUtilTest::shouldParseKdeLoggingLine_data()
QTest::newRow("validLineWithParenthesesAndCategories") << QStringLiteral("log linux (foo) [WARNING]") << QStringLiteral("linux (foo)") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategories") << QStringLiteral("log linux [WARNING]") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategories2") << QStringLiteral("log linux [WARNING] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategories3") << QStringLiteral("log linux [WARNING] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategoriesWarning") << QStringLiteral("log linux [WARNING]") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategoriesWarning2") << QStringLiteral("log linux [WARNING] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineCategoriesWarning3") << QStringLiteral("log linux [WARNING] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("WARNING") << true;
QTest::newRow("validLineBadCategories") << QStringLiteral("log linux [FOO] ") << QStringLiteral("linux [FOO]") << QStringLiteral("log") << QString() << true;
QTest::newRow("linewithcomment") << QStringLiteral("log linux#comment about linux") << QStringLiteral("linux") << QStringLiteral("log") << QString() << true;
QTest::newRow("validLineCategoriesInfo") << QStringLiteral("log linux [INFO]") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("INFO") << true;
QTest::newRow("validLineCategoriesInfo2") << QStringLiteral("log linux [INFO] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("INFO") << true;
QTest::newRow("validLineCategoriesInfo3") << QStringLiteral("log linux [INFO] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("INFO") << true;
QTest::newRow("validLineCategoriesDEBUG") << QStringLiteral("log linux [DEBUG]") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("DEBUG") << true;
QTest::newRow("validLineCategoriesDEBUG2") << QStringLiteral("log linux [DEBUG] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("DEBUG") << true;
QTest::newRow("validLineCategoriesDEBUG3") << QStringLiteral("log linux [DEBUG] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("DEBUG") << true;
QTest::newRow("validLineCategoriesCRITICAL") << QStringLiteral("log linux [CRITICAL]") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("CRITICAL") << true;
QTest::newRow("validLineCategoriesCRITICAL2") << QStringLiteral("log linux [CRITICAL] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("CRITICAL") << true;
QTest::newRow("validLineCategoriesCRITICAL3") << QStringLiteral("log linux [CRITICAL] ") << QStringLiteral("linux") << QStringLiteral("log") << QStringLiteral("CRITICAL") << true;
}
void KDebugSettingUtilTest::shouldParseKdeLoggingLine()
......@@ -159,4 +172,23 @@ void KDebugSettingUtilTest::shouldReadRenameCategories()
QCOMPARE(lst.count(), numberofrenamecategories);
}
void KDebugSettingUtilTest::shouldConvertCategoryTypeFromString_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<LoggingCategory::LoggingType>("loggingType");
QTest::newRow("empty") << QString() << LoggingCategory::LoggingType::Info;
QTest::newRow("WARNING") << QStringLiteral("WARNING") << LoggingCategory::LoggingType::Warning;
QTest::newRow("Info") << QStringLiteral("INFO") << LoggingCategory::LoggingType::Info;
QTest::newRow("Debug") << QStringLiteral("DEBUG") << LoggingCategory::LoggingType::Debug;
QTest::newRow("Critical") << QStringLiteral("CRITICAL") << LoggingCategory::LoggingType::Critical;
QTest::newRow("unknow") << QStringLiteral("foo") << LoggingCategory::LoggingType::Info;
}
void KDebugSettingUtilTest::shouldConvertCategoryTypeFromString()
{
QFETCH(QString, input);
QFETCH(LoggingCategory::LoggingType, loggingType);
QCOMPARE(KDebugSettingsUtil::convertCategoryTypeFromString(input), loggingType);
}
QTEST_GUILESS_MAIN(KDebugSettingUtilTest)
......@@ -41,6 +41,10 @@ private Q_SLOTS:
void shouldReadRenameCategories_data();
void shouldReadRenameCategories();
void shouldConvertCategoryTypeFromString_data();
void shouldConvertCategoryTypeFromString();
};
#endif // KDEBUGSETTINGUTILTEST_H
......@@ -18,7 +18,7 @@ kf5.kio.core.dirlister KCoreDirLister (KIO)
kf5.kio.core.copyjob KIO::CopyJob (KIO)
kf5.kio.widgets KIOWidgets (KIO)
kf5.kiod KIO Daemon (KIO)
kf5.kio.kio_http KIO HTTP slave (KIO)
kf5.kio.kio_http KIO HTTP slave (KIO) [WARNING]
kf5.kjobwidgets KJobWidgets
kf5.kio.favicons FavIcons (KIO)
kf5.kservice.sycoca KSycoca (KService)
......
......@@ -39,6 +39,11 @@ CategoryTypeComboBox::~CategoryTypeComboBox()
{
}
void CategoryTypeComboBox::restoreToDefault()
{
setType(mDefaultCategories);
}
void CategoryTypeComboBox::setType(LoggingCategory::LoggingType type)
{
const int pos = findData(QVariant::fromValue(type));
......@@ -64,3 +69,8 @@ void CategoryTypeComboBox::setDefaultCategories(const LoggingCategory::LoggingTy
{
mDefaultCategories = defaultCategories;
}
LoggingCategory::LoggingType CategoryTypeComboBox::defaultCategories() const
{
return mDefaultCategories;
}
......@@ -35,7 +35,9 @@ public:
void setType(LoggingCategory::LoggingType type);
bool loggingCategoryIsNotDefault() const;
void setDefaultCategories(const LoggingCategory::LoggingType &defaultCategories);
LoggingCategory::LoggingType defaultCategories() const;
void restoreToDefault();
private:
LoggingCategory::LoggingType mDefaultCategories = LoggingCategory::Info;
};
......
......@@ -34,6 +34,11 @@ KDEApplicationTreeListWidgetItem::~KDEApplicationTreeListWidgetItem()
{
}
void KDEApplicationTreeListWidgetItem::restoreToDefault()
{
mCategoryTypeCombobox->restoreToDefault();
}
void KDEApplicationTreeListWidgetItem::setType(LoggingCategory::LoggingType type)
{
mCategoryTypeCombobox->setType(type);
......@@ -107,7 +112,7 @@ void KDEApplicationTreeListWidget::addListItems(const LoggingCategory::List &lis
KDEApplicationTreeListWidgetItem *item = new KDEApplicationTreeListWidgetItem(cat.logName, this);
item->setText(KDEApplicationTreeListWidgetItem::Description, cat.description);
item->setType(cat.loggingType);
//item->setDefaultCategory(cat.)
item->setDefaultCategory(cat.defaultCategoryType);
}
resizeColumnToContents(KDEApplicationTreeListWidgetItem::Description);
}
......@@ -135,6 +140,6 @@ void KDEApplicationTreeListWidget::restoreToDefault()
//TODO use default value
for (int i = 0; i < topLevelItemCount(); ++i) {
KDEApplicationTreeListWidgetItem *itemWidget = static_cast<KDEApplicationTreeListWidgetItem *>(topLevelItem(i));
itemWidget->setType(LoggingCategory::Info);
itemWidget->restoreToDefault();
}
}
......@@ -41,6 +41,7 @@ public:
void setDefaultCategory(LoggingCategory::LoggingType type);
LoggingCategory rule() const;
void restoreToDefault();
private:
QString mCategory;
CategoryTypeComboBox *mCategoryTypeCombobox = nullptr;
......
......@@ -251,6 +251,7 @@ void KDebugSettingsDialog::slotInsertCategories()
LoggingCategory loggingCat;
loggingCat.description = cat.description;
loggingCat.logName = cat.logName;
loggingCat.defaultCategoryType = KDebugSettingsUtil::convertCategoryTypeFromString(cat.defaultCategory);
if (loggingCat.isValid()) {
newCategories.append(loggingCat);
}
......
......@@ -108,7 +108,8 @@ KdeLoggingCategory KDebugSettingsUtil::parseLineKdeLoggingCategory(QString line)
description = match.captured(2);
//qDebug() << " logName"<<logName<<" description " << description << " line " << line;
}
static const QRegularExpression regularExpressionDefaultCategory(QStringLiteral("^(.*)\\s+\\[(.*)\\]$"));
static const QRegularExpression regularExpressionDefaultCategory(QStringLiteral("^(.*)\\s+\\[(DEBUG|INFO|WARNING|CRITICAL)\\]$"));
QRegularExpressionMatch match2 = regularExpressionDefaultCategory.match(description);
QString defaultCategoryCaptured;
if (match.hasMatch()) {
......@@ -333,3 +334,20 @@ QList<KDebugSettingsUtil::LoadLoggingCategory> KDebugSettingsUtil::readLoggingQt
return hashLoadLoggingCategories.values();
}
LoggingCategory::LoggingType KDebugSettingsUtil::convertCategoryTypeFromString(const QString &str)
{
if (str.isEmpty()) {
return LoggingCategory::Info; //Default
} else if (str == QLatin1String("DEBUG")) {
return LoggingCategory::Debug;
} else if (str == QLatin1String("INFO")) {
return LoggingCategory::Info;
} else if (str == QLatin1String("WARNING")) {
return LoggingCategory::Warning;
} else if (str == QLatin1String("CRITICAL")) {
return LoggingCategory::Critical;
}
qCWarning(KDEBUGSETTINGS_LOG) << "Default category is unknown: " << str;
return LoggingCategory::Info;
}
......@@ -113,6 +113,7 @@ QList<LoadLoggingCategory> readLoggingQtCategories(const QString &filename);
KDebugSettingsUtil::LineLoggingQtCategory parseLineLoggingQtCategory(const QString &line);
RenameCategory parseRenameCategory(QString line);
RenameCategory::List readRenameCategories(const QString &filename);
LoggingCategory::LoggingType convertCategoryTypeFromString(const QString &str);
}
Q_DECLARE_METATYPE(KDebugSettingsUtil::LoadLoggingCategory::LogType)
......
......@@ -97,6 +97,7 @@ void LoadCategoriesJob::start()
{
mCustomCategories.clear();
mQtKdeCategories.clear();
qDebug() << " SDDDDDS";
mFoundOverrideRule = false;
const int number(mCategories.count());
const QList<KDebugSettingsUtil::LoadLoggingCategory> originalQtCategories = KDebugSettingsUtil::readLoggingQtCategories(mFileName);
......@@ -126,6 +127,7 @@ void LoadCategoriesJob::start()
}
tmp.description = kdeCat.description;
tmp.logName = kdeCat.logName;
tmp.defaultCategoryType = KDebugSettingsUtil::convertCategoryTypeFromString(kdeCat.defaultCategory);
mQtKdeCategories.append(tmp);
foundInConfigFile = true;
......@@ -140,8 +142,9 @@ void LoadCategoriesJob::start()
if (!foundInConfigFile) {
LoggingCategory tmp;
tmp.description = kdeCat.description;
tmp.logName = kdeCat.logName;
tmp.loggingType = LoggingCategory::Info;
tmp.logName = kdeCat.logName;
tmp.loggingType = KDebugSettingsUtil::convertCategoryTypeFromString(kdeCat.defaultCategory);
tmp.defaultCategoryType = KDebugSettingsUtil::convertCategoryTypeFromString(kdeCat.defaultCategory);
mQtKdeCategories.append(tmp);
}
}
......
......@@ -21,8 +21,6 @@
#include "loggingcategory.h"
LoggingCategory::LoggingCategory()
: loggingType(Info)
, enabled(true)
{
}
......@@ -31,7 +29,8 @@ bool LoggingCategory::operator ==(const LoggingCategory &other) const
return (description == other.description)
&& (logName == other.logName)
&& (enabled == other.enabled)
&& (loggingType == other.loggingType);
&& (loggingType == other.loggingType)
&& (defaultCategoryType == other.defaultCategoryType);
}
bool LoggingCategory::isValid() const
......@@ -115,5 +114,6 @@ QDebug operator<<(QDebug d, const LoggingCategory &cat)
d << "logname: " << cat.logName;
d << "enabled: " << cat.enabled;
d << "type: " << cat.loggingType;
d << "default category: " << cat.defaultCategoryType;
return d;
}
......@@ -55,8 +55,9 @@ struct LoggingCategory {
QString description;
QString logName;
LoggingType loggingType;
bool enabled;
LoggingType loggingType = Info;
LoggingType defaultCategoryType = Info;
bool enabled = true;
};
QDebug operator<<(QDebug debug, const LoggingCategory &cat);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment