Commit 84f7830f authored by Laurent Montel's avatar Laurent Montel

Extract code for saving rules, so I can autotest it

parent a892a27e
......@@ -18,6 +18,7 @@ set(full_source_file
../src/kdeloggingcategory.cpp
../src/loadcategoriesjob.cpp
../src/renamecategory.cpp
../src/saverulesjob.cpp
${CMAKE_BINARY_DIR}/src/kdebugsettings_debug.cpp
)
......@@ -53,3 +54,4 @@ add_unittest( categorywarningtest.cpp "../src/categorywarning.cpp")
add_unittest( loggingcategorytest.cpp "../src/loggingcategory.cpp")
add_unittest( loadcategoriesjobtest.cpp "../src/renamecategory.cpp;../src/loadcategoriesjob.cpp;../src/loggingcategory.cpp;../src/kdeloggingcategory.cpp;../src/kdebugsettings_debug.cpp;../src/kdebugsettingsutil.cpp")
add_unittest( renamecategorytest.cpp "../src/renamecategory.cpp;../src/kdebugsettingsutil.cpp;../src/kdeloggingcategory.cpp;../src/kdebugsettings_debug.cpp")
add_unittest( saverulesjobtest.cpp "../src/saverulesjob.cpp;../src/renamecategory.cpp;../src/loadcategoriesjob.cpp;../src/loggingcategory.cpp;../src/kdeloggingcategory.cpp;../src/kdebugsettings_debug.cpp;../src/kdebugsettingsutil.cpp")
/*
Copyright (c) 2017 Montel Laurent <montel@kde.org>
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.
*/
#include "saverulesjobtest.h"
#include <QTest>
QTEST_GUILESS_MAIN(SaveRulesJobTest)
SaveRulesJobTest::SaveRulesJobTest(QObject *parent)
: QObject(parent)
{
}
/*
Copyright (c) 2017 Montel Laurent <montel@kde.org>
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 SAVERULESJOBTEST_H
#define SAVERULESJOBTEST_H
#include <QObject>
class SaveRulesJobTest : public QObject
{
Q_OBJECT
public:
explicit SaveRulesJobTest(QObject *parent = nullptr);
~SaveRulesJobTest() = default;
};
#endif // SAVERULESJOBTEST_H
......@@ -17,6 +17,7 @@ set(kdebugsettings_SRCS
kdeloggingcategory.cpp
loadcategoriesjob.cpp
renamecategory.cpp
saverulesjob.cpp
)
ecm_qt_declare_logging_category(kdebugsettings_SRCS HEADER kdebugsettings_debug.h IDENTIFIER KDEBUGSETTINGS_LOG CATEGORY_NAME log_kdebugsettings)
......
......@@ -33,7 +33,7 @@ public:
~CustomDebugSettingsPage();
void fillList(const LoggingCategory::List &list);
LoggingCategory::List rules();
LoggingCategory::List rules() const;
private:
void slotRemoveRules();
void slotAddRule();
......
......@@ -25,6 +25,7 @@
#include "kdebugsettingsutil.h"
#include "categorywarning.h"
#include "loadcategoriesjob.h"
#include "saverulesjob.h"
#include <KLocalizedString>
#include <KConfigGroup>
......@@ -205,22 +206,14 @@ void KDebugSettingsDialog::readCategoriesFiles(const QString &path)
bool KDebugSettingsDialog::saveRules(const QString &path)
{
QFile qtlogging(path);
if (!qtlogging.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
SaveRulesJob job;
job.setFileName(path);
job.setListCustom(mCustomSettingsPage->rules());
job.setListKde(mKdeApplicationSettingsPage->rules());
if (!job.start()) {
KMessageBox::error(this, i18n("\'%1\' cannot be opened. Please verify it.", path));
return false;
}
//Save Rules
const LoggingCategory::List lstKde = mKdeApplicationSettingsPage->rules();
const LoggingCategory::List lstCustom = mCustomSettingsPage->rules();
QTextStream out(&qtlogging);
out << QLatin1String("[Rules]\n");
for (LoggingCategory cat : lstKde) {
out << cat.createRule() + QLatin1Char('\n');
}
for (LoggingCategory cat : lstCustom) {
out << cat.createCustomRule() + QLatin1Char('\n');
}
return true;
}
......
/*
Copyright (c) 2017 Montel Laurent <montel@kde.org>
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.
*/
#include "saverulesjob.h"
#include <QFile>
#include <QTextStream>
SaveRulesJob::SaveRulesJob()
{
}
void SaveRulesJob::setListKde(const LoggingCategory::List &listKde)
{
mListKde = listKde;
}
void SaveRulesJob::setListCustom(const LoggingCategory::List &listCustom)
{
mListCustom = listCustom;
}
void SaveRulesJob::setFileName(const QString &fileName)
{
mFileName = fileName;
}
bool SaveRulesJob::start()
{
QFile qtlogging(mFileName);
if (!qtlogging.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
return false;
}
//Save Rules
QTextStream out(&qtlogging);
out << QLatin1String("[Rules]\n");
for (LoggingCategory cat : mListKde) {
out << cat.createRule() + QLatin1Char('\n');
}
for (LoggingCategory cat : mListCustom) {
out << cat.createCustomRule() + QLatin1Char('\n');
}
return true;
}
/*
Copyright (c) 2017 Montel Laurent <montel@kde.org>
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 SAVERULESJOB_H
#define SAVERULESJOB_H
#include "loggingcategory.h"
class SaveRulesJob
{
public:
SaveRulesJob();
~SaveRulesJob() = default;
void setListKde(const LoggingCategory::List &listKde);
void setListCustom(const LoggingCategory::List &listCustom);
void setFileName(const QString &fileName);
bool start();
private:
LoggingCategory::List mListKde;
LoggingCategory::List mListCustom;
QString mFileName;
};
#endif // SAVERULESJOB_H
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