summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Montel <[email protected]>2018-02-21 13:24:20 +0100
committerLaurent Montel <[email protected]>2018-02-21 13:24:20 +0100
commit7aff08c1fc1f4605ed37659b4b13e91177e16fd3 (patch)
tree5185a0f5d36bb25c4329f7bc4ab471b82b552601
parent85cbc3304c6f145c5d19965514018d4cc9adc42d (diff)
Fix Bug 390752 - Kdebugsettings overwrites default debug level for all log categories
FIXED-IN: 18.04.0 BUG: 390752
-rw-r--r--autotests/categorytypecomboboxtest.cpp14
-rw-r--r--autotests/categorytypecomboboxtest.h2
-rw-r--r--autotests/kdebugsettingutiltest.cpp38
-rw-r--r--autotests/kdebugsettingutiltest.h4
-rw-r--r--data/kde.categories2
-rw-r--r--src/categorytypecombobox.cpp10
-rw-r--r--src/categorytypecombobox.h2
-rw-r--r--src/kdeapplicationtreelistwidget.cpp9
-rw-r--r--src/kdeapplicationtreelistwidget.h1
-rw-r--r--src/kdebugsettingsdialog.cpp1
-rw-r--r--src/kdebugsettingsutil.cpp20
-rw-r--r--src/kdebugsettingsutil.h1
-rw-r--r--src/loadcategoriesjob.cpp7
-rw-r--r--src/loggingcategory.cpp6
-rw-r--r--src/loggingcategory.h5
15 files changed, 108 insertions, 14 deletions
diff --git a/autotests/categorytypecomboboxtest.cpp b/autotests/categorytypecomboboxtest.cpp
index 035fa57..8145f18 100644
--- a/autotests/categorytypecomboboxtest.cpp
+++ b/autotests/categorytypecomboboxtest.cpp
@@ -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)
diff --git a/autotests/categorytypecomboboxtest.h b/autotests/categorytypecomboboxtest.h
index 748eab5..3854820 100644
--- a/autotests/categorytypecomboboxtest.h
+++ b/autotests/categorytypecomboboxtest.h
@@ -36,6 +36,8 @@ private Q_SLOTS:
void shouldVerifyItNotDefault();
void shouldChangeDefaultCategory();
+
+ void shouldVerifyThatDefaultCategoryIsCorrect();
};
#endif // CATEGORYTYPECOMBOBOXTEST_H
diff --git a/autotests/kdebugsettingutiltest.cpp b/autotests/kdebugsettingutiltest.cpp
index c2a7a72..5f9fe66 100644
--- a/autotests/kdebugsettingutiltest.cpp
+++ b/autotests/kdebugsettingutiltest.cpp
@@ -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)
diff --git a/autotests/kdebugsettingutiltest.h b/autotests/kdebugsettingutiltest.h
index 97ec994..cca5930 100644
--- a/autotests/kdebugsettingutiltest.h
+++ b/autotests/kdebugsettingutiltest.h
@@ -41,6 +41,10 @@ private Q_SLOTS:
void shouldReadRenameCategories_data();
void shouldReadRenameCategories();
+
+ void shouldConvertCategoryTypeFromString_data();
+ void shouldConvertCategoryTypeFromString();
+
};
#endif // KDEBUGSETTINGUTILTEST_H
diff --git a/data/kde.categories b/data/kde.categories
index 34e4ee2..4319229 100644
--- a/data/kde.categories
+++ b/data/kde.categories
@@ -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)
diff --git a/src/categorytypecombobox.cpp b/src/categorytypecombobox.cpp
index 63124ad..69a91c6 100644
--- a/src/categorytypecombobox.cpp
+++ b/src/categorytypecombobox.cpp
@@ -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;
+}
diff --git a/src/categorytypecombobox.h b/src/categorytypecombobox.h
index d5a43ea..217cdd6 100644
--- a/src/categorytypecombobox.h
+++ b/src/categorytypecombobox.h
@@ -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;
};
diff --git a/src/kdeapplicationtreelistwidget.cpp b/src/kdeapplicationtreelistwidget.cpp
index cddc617..12e232c 100644
--- a/src/kdeapplicationtreelistwidget.cpp
+++ b/src/kdeapplicationtreelistwidget.cpp
@@ -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();
}
}
diff --git a/src/kdeapplicationtreelistwidget.h b/src/kdeapplicationtreelistwidget.h
index 1a68f1d..b9c4150 100644
--- a/src/kdeapplicationtreelistwidget.h
+++ b/src/kdeapplicationtreelistwidget.h
@@ -41,6 +41,7 @@ public:
void setDefaultCategory(LoggingCategory::LoggingType type);
LoggingCategory rule() const;
+ void restoreToDefault();
private:
QString mCategory;
CategoryTypeComboBox *mCategoryTypeCombobox = nullptr;
diff --git a/src/kdebugsettingsdialog.cpp b/src/kdebugsettingsdialog.cpp
index dc51e4a..691a3b4 100644
--- a/src/kdebugsettingsdialog.cpp
+++ b/src/kdebugsettingsdialog.cpp
@@ -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);
}
diff --git a/src/kdebugsettingsutil.cpp b/src/kdebugsettingsutil.cpp
index 1094bc4..7c3b21a 100644
--- a/src/kdebugsettingsutil.cpp
+++ b/src/kdebugsettingsutil.cpp
@@ -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;
+}
diff --git a/src/kdebugsettingsutil.h b/src/kdebugsettingsutil.h
index 8a6233d..845e3ac 100644
--- a/src/kdebugsettingsutil.h
+++ b/src/kdebugsettingsutil.h
@@ -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)
diff --git a/src/loadcategoriesjob.cpp b/src/loadcategoriesjob.cpp
index cdde22d..7cfa933 100644
--- a/src/loadcategoriesjob.cpp
+++ b/src/loadcategoriesjob.cpp
@@ -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);
}
}
diff --git a/src/loggingcategory.cpp b/src/loggingcategory.cpp
index b7629ac..4a352ee 100644
--- a/src/loggingcategory.cpp
+++ b/src/loggingcategory.cpp
@@ -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;
}
diff --git a/src/loggingcategory.h b/src/loggingcategory.h
index 8264d5a..6a44cb9 100644
--- a/src/loggingcategory.h
+++ b/src/loggingcategory.h
@@ -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);