Warning, file /utilities/kdebugsettings/src/saverulesjob.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2017-2022 Laurent Montel <montel@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include "saverulesjob.h"
0009 
0010 #include <QFile>
0011 #include <QTextStream>
0012 
0013 SaveRulesJob::SaveRulesJob() = default;
0014 
0015 void SaveRulesJob::setListKde(const LoggingCategory::List &listKde)
0016 {
0017     mListKde = listKde;
0018 }
0019 
0020 void SaveRulesJob::setListCustom(const LoggingCategory::List &listCustom)
0021 {
0022     mListCustom = listCustom;
0023 }
0024 
0025 void SaveRulesJob::setFileName(const QString &fileName)
0026 {
0027     mFileName = fileName;
0028 }
0029 
0030 bool SaveRulesJob::start()
0031 {
0032     QFile qtlogging(mFileName);
0033     if (!qtlogging.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
0034         return false;
0035     }
0036     // Save Rules
0037     QTextStream out(&qtlogging);
0038     out << QLatin1String("[Rules]\n");
0039     for (const LoggingCategory &cat : std::as_const(mListKde)) {
0040         out << cat.createRule() + QLatin1Char('\n');
0041     }
0042     for (const LoggingCategory &cat : std::as_const(mListCustom)) {
0043         out << cat.createCustomRule() + QLatin1Char('\n');
0044     }
0045     return true;
0046 }
0047 
0048 QString SaveRulesJob::fileName() const
0049 {
0050     return mFileName;
0051 }