File indexing completed on 2024-05-19 04:58:23

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2010-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #include "filter.h"
0010 
0011 #include <KConfigGroup>
0012 #include <KSharedConfig>
0013 
0014 class Filter::Private
0015 {
0016 public:
0017     Private(const QString &text, Filter::FilterField field, Filter::FilterType type,
0018             Filter::FilterAction action, bool dontHide)
0019         : filterField(field), filterText(text), filterType(type)
0020         , filterAction(action), dontHideReplies(dontHide)
0021     {
0022         config = new KConfigGroup(KSharedConfig::openConfig(),
0023                                   QStringLiteral("Filter_%1%2%3%4").arg(text)
0024                                   .arg(field)
0025                                   .arg(type)
0026                                   .arg(action));
0027     }
0028 
0029     Private(const KConfigGroup &configGroup)
0030         : config(new KConfigGroup(configGroup))
0031     {
0032         filterText = config->readEntry("Text", QString());
0033         filterField = (FilterField) config->readEntry("Field", 0);
0034         filterType = (FilterType) config->readEntry("Type", 0);
0035         filterAction = (FilterAction) config->readEntry<int>("Action", Filter::Remove);
0036         dontHideReplies = config->readEntry("DontHideReplies", false);
0037     }
0038 
0039     FilterField filterField;
0040     QString filterText;
0041     FilterType filterType;
0042     FilterAction filterAction;
0043     bool dontHideReplies;
0044     KConfigGroup *config;
0045 };
0046 
0047 Filter::Filter(const QString &filterText, Filter::FilterField field, Filter::FilterType type,
0048                Filter::FilterAction action, bool dontHide, QObject *parent)
0049     : QObject(parent), d(new Private(filterText, field, type, action, dontHide))
0050 {}
0051 
0052 Filter::Filter(const KConfigGroup &config, QObject *parent)
0053     : QObject(parent), d(new Private(config))
0054 {
0055 }
0056 
0057 Filter::~Filter()
0058 {
0059 }
0060 
0061 Filter::FilterField Filter::filterField() const
0062 {
0063     return d->filterField;
0064 }
0065 
0066 void Filter::setFilterField(Filter::FilterField field)
0067 {
0068     d->filterField = field;
0069 }
0070 
0071 QString Filter::filterText() const
0072 {
0073     return d->filterText;
0074 }
0075 
0076 void Filter::setFilterText(const QString &text)
0077 {
0078     d->filterText = text;
0079 }
0080 
0081 Filter::FilterType Filter::filterType() const
0082 {
0083     return d->filterType;
0084 }
0085 
0086 void Filter::setFilterType(Filter::FilterType type)
0087 {
0088     d->filterType = type;
0089 }
0090 
0091 Filter::FilterAction Filter::filterAction() const
0092 {
0093     return d->filterAction;
0094 }
0095 
0096 void Filter::setFilterAction(Filter::FilterAction action)
0097 {
0098     d->filterAction = action;
0099 }
0100 
0101 bool Filter::dontHideReplies() const
0102 {
0103     return d->dontHideReplies;
0104 }
0105 
0106 void Filter::setDontHideReplies(bool dontHide)
0107 {
0108     d->dontHideReplies = dontHide;
0109 }
0110 
0111 void Filter::writeConfig()
0112 {
0113     d->config->writeEntry("Text", filterText());
0114     d->config->writeEntry("Field", (int)filterField());
0115     d->config->writeEntry("Type", (int)filterType());
0116     d->config->writeEntry("Action", (int)filterAction());
0117     d->config->writeEntry("DontHideReplies", dontHideReplies());
0118     d->config->sync();
0119 }
0120 
0121 #include "moc_filter.cpp"