kdebugsettingsutil.h 3.18 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
  Copyright (c) 2015-2016 Montel Laurent <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Library General Public License as published by
  the Free Software Foundation; either version 2 of the License, or (at your
  option) any later version.

  This library 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 Library General Public
  License for more details.

  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to the
  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  02110-1301, USA.

*/

#ifndef KDEBUGSETTINGSUTIL_H
#define KDEBUGSETTINGSUTIL_H

#include <QString>
Laurent Montel's avatar
Laurent Montel committed
25 26
#include <QObject>
#include <QDebug>
Laurent Montel's avatar
Laurent Montel committed
27
#include "kdeloggingcategory.h"
Laurent Montel's avatar
Laurent Montel committed
28
#include "loggingcategory.h"
Laurent Montel's avatar
Laurent Montel committed
29 30
namespace KDebugSettingsUtil
{
Laurent Montel's avatar
Laurent Montel committed
31

32 33
struct LineLoggingQtCategory {
    LineLoggingQtCategory()
Laurent Montel's avatar
Laurent Montel committed
34 35
        : enabled(true),
          type(Unknown)
Laurent Montel's avatar
Laurent Montel committed
36 37 38
    {

    }
39 40 41 42 43 44 45 46
    enum LoggingType {
        Unknown = 0,
        Info,
        Warning,
        Debug,
        Critical,
        All
    };
Laurent Montel's avatar
Laurent Montel committed
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    bool isValid() const {
        return !logName.isEmpty();
    }
    bool operator ==(const LineLoggingQtCategory &other) const
    {
        return (enabled == other.enabled) &&
               (type == other.type) &&
               (logName == other.logName);
    }
    bool enabled;
    LoggingType type;
    QString logName;
};

struct LoadLoggingCategory {
Laurent Montel's avatar
Laurent Montel committed
63 64 65 66 67
    enum Status {
        Enabled = 0,
        Disabled = 1,
        UnknownStatus = 2
    };
68

Laurent Montel's avatar
Laurent Montel committed
69
    enum LogType {
70 71 72 73 74 75 76
        Unknown = 0,
        Off,
        Info,
        Warning,
        Debug,
        Critical,
        All
Laurent Montel's avatar
Laurent Montel committed
77 78
    };

Laurent Montel's avatar
Laurent Montel committed
79 80 81 82 83 84 85 86
    LoadLoggingCategory()
    {
        for (int i = LoadLoggingCategory::Unknown; i <= LoadLoggingCategory::All; ++i) {
            loggingTypes.insert(static_cast<LoadLoggingCategory::LogType>(i), UnknownStatus);
        }
    }
    typedef QVector<LoadLoggingCategory> List;

Laurent Montel's avatar
Laurent Montel committed
87 88
    bool isValid() const
    {
Laurent Montel's avatar
Laurent Montel committed
89
        return !logName.isEmpty();
Laurent Montel's avatar
Laurent Montel committed
90 91
    }

Laurent Montel's avatar
Laurent Montel committed
92 93
    bool operator ==(const LoadLoggingCategory &other) const
    {
Laurent Montel's avatar
Debug--  
Laurent Montel committed
94
        //qDebug() << " logname " << logName << " other.logName :" << other.logName;
95
        return (logName == other.logName) &&
96
               (loggingTypes == other.loggingTypes);
Laurent Montel's avatar
Laurent Montel committed
97
    }
Laurent Montel's avatar
Laurent Montel committed
98
    QString logName;
99
    QMap<LoadLoggingCategory::LogType, LoadLoggingCategory::Status> loggingTypes;
Laurent Montel's avatar
Laurent Montel committed
100 101
};

Laurent Montel's avatar
Laurent Montel committed
102 103 104 105 106
void readLoggingCategories(const QString &filename, KdeLoggingCategory::List &categoriesList, bool checkCategoryList = false);

KdeLoggingCategory parseLineKdeLoggingCategory(QString line);
KdeLoggingCategory::List readLoggingCategoriesForInserting(const QString &filename, KdeLoggingCategory::List &categoriesList);

107 108
QList<LoadLoggingCategory> readLoggingQtCategories(const QString &filename);
KDebugSettingsUtil::LineLoggingQtCategory parseLineLoggingQtCategory(const QString &line);
Laurent Montel's avatar
Laurent Montel committed
109
}
110

Laurent Montel's avatar
Laurent Montel committed
111
Q_DECLARE_METATYPE(KDebugSettingsUtil::LoadLoggingCategory::LogType)
Laurent Montel's avatar
Laurent Montel committed
112

113 114
Q_DECLARE_METATYPE(KDebugSettingsUtil::LineLoggingQtCategory::LoggingType)

Laurent Montel's avatar
Laurent Montel committed
115
#endif // KDEBUGSETTINGSUTIL_H