File indexing completed on 2022-09-27 16:31:46

0001 /*
0002     SPDX-FileCopyrightText: 2015-2022 Laurent Montel <montel@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #pragma once
0009 
0010 #include "kdeloggingcategory.h"
0011 #include "libkdebugsettings_export.h"
0012 #include "loggingcategory.h"
0013 #include "renamecategory.h"
0014 #include <QDebug>
0015 #include <QString>
0016 
0017 namespace KDebugSettingsUtil
0018 {
0019 struct LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT LineLoggingQtCategory {
0020     LineLoggingQtCategory() = default;
0021 
0022     enum LoggingType { Unknown = 0, Info, Warning, Debug, Critical, All };
0023 
0024     Q_REQUIRED_RESULT bool isValid() const
0025     {
0026         return !logName.isEmpty();
0027     }
0028 
0029     Q_REQUIRED_RESULT bool operator==(const LineLoggingQtCategory &other) const
0030     {
0031         return (enabled == other.enabled) && (type == other.type) && (logName == other.logName);
0032     }
0033 
0034     bool enabled = true;
0035     LoggingType type = Unknown;
0036     QString logName;
0037 };
0038 
0039 struct LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT LoadLoggingCategory {
0040     enum Status { Enabled = 0, Disabled = 1, UnknownStatus = 2 };
0041 
0042     enum LogType { Unknown = 0, Off, Info, Warning, Debug, Critical, All };
0043 
0044     LoadLoggingCategory()
0045     {
0046         for (int i = LoadLoggingCategory::Unknown; i <= LoadLoggingCategory::All; ++i) {
0047             loggingTypes.insert(static_cast<LoadLoggingCategory::LogType>(i), UnknownStatus);
0048         }
0049     }
0050 
0051     using List = QVector<LoadLoggingCategory>;
0052 
0053     bool isValid() const
0054     {
0055         return !logName.isEmpty();
0056     }
0057 
0058     Q_REQUIRED_RESULT bool operator==(const LoadLoggingCategory &other) const
0059     {
0060         // qDebug() << " logname " << logName << " other.logName :" << other.logName;
0061         return (logName == other.logName) && (loggingTypes == other.loggingTypes);
0062     }
0063 
0064     QString logName;
0065     QMap<LoadLoggingCategory::LogType, LoadLoggingCategory::Status> loggingTypes;
0066 };
0067 
0068 LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT void
0069 readLoggingCategories(const QString &filename, KdeLoggingCategory::List &categoriesList, bool checkCategoryList = false);
0070 
0071 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT KdeLoggingCategory parseLineKdeLoggingCategory(QString line, const QString &filename);
0072 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT KdeLoggingCategory::List readLoggingCategoriesForInserting(const QString &filename,
0073                                                                                                       KdeLoggingCategory::List &categoriesList);
0074 
0075 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT QList<LoadLoggingCategory> readLoggingQtCategories(const QString &filename);
0076 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT KDebugSettingsUtil::LineLoggingQtCategory parseLineLoggingQtCategory(const QString &line);
0077 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT RenameCategory parseRenameCategory(QString line, const QString &filename);
0078 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT RenameCategory::List readRenameCategories(const QString &filename);
0079 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT LoggingCategory::LoggingType convertCategoryTypeFromString(const QString &str);
0080 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT QString convertCategoryTypeToString(LoggingCategory::LoggingType type);
0081 Q_REQUIRED_RESULT LIBKDEBUGSETTINGS_EXPORT QString qtFileName();
0082 }
0083 
0084 Q_DECLARE_METATYPE(KDebugSettingsUtil::LoadLoggingCategory::LogType)
0085 
0086 Q_DECLARE_METATYPE(KDebugSettingsUtil::LineLoggingQtCategory::LoggingType)