MailImporter

filters.cpp
1/*
2 SPDX-FileCopyrightText: 2000 Hans Dijkema <kmailcvt@hum.org>
3 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8// Local Includes
9
10// KDE Includes
11#include "filters.h"
12#include "mailimporter_debug.h"
13//////////////////////////////////////////////////////////////////////////////////
14//
15// The generic filter class
16//
17//////////////////////////////////////////////////////////////////////////////////
18
19using namespace MailImporter;
20
21class Q_DECL_HIDDEN Filter::FilterPrivate
22{
23public:
24 FilterPrivate(const QString &_name, const QString &_author, const QString &_info)
25 : name(_name)
26 , author(_author)
27 , info(_info)
28 {
29 }
30
31 ~FilterPrivate()
32 {
33 }
34
36 QString author;
37 QString info;
38 QString mailDir;
39 MailImporter::FilterImporterBase *filterImporter = nullptr;
40 MailImporter::FilterInfo *filterInfo = nullptr;
41};
42
43Filter::Filter(const QString &name, const QString &author, const QString &info)
44 : d(new FilterPrivate(name, author, info))
45{
46}
47
48Filter::~Filter() = default;
49
50void Filter::clear()
51{
52 filterImporter()->clear();
53 d->mailDir.clear();
54}
55
56void Filter::setMailDir(const QString &mailDir)
57{
58 d->mailDir = mailDir;
59}
60
61QString Filter::mailDir() const
62{
63 return d->mailDir;
64}
65
66void Filter::setFilterInfo(FilterInfo *info)
67{
68 d->filterInfo = info;
69 clear();
70}
71
72MailImporter::FilterInfo *Filter::filterInfo() const
73{
74 if (!d->filterInfo) {
75 Q_ASSERT_X(d->filterInfo != nullptr, "Filter::filterInfo", "filterInfo was not settings. It's a bug in application.");
76 qCDebug(MAILIMPORTER_LOG) << " filterInfo must never be null. You forgot to create a filterinfo";
77 }
78 return d->filterInfo;
79}
80
81void Filter::setFilterImporter(FilterImporterBase *importer)
82{
83 d->filterImporter = importer;
84}
85
86FilterImporterBase *Filter::filterImporter() const
87{
88 Q_ASSERT_X(d->filterImporter != nullptr, "Filter::filterImporter", "filterImporter was not settings. It's a bug in application.");
89 return d->filterImporter;
90}
91
92void Filter::clearCountDuplicate()
93{
94 filterImporter()->clearCountDuplicate();
95}
96
97int Filter::countDuplicates() const
98{
99 return filterImporter()->countDuplicates();
100}
101
102QString Filter::author() const
103{
104 return d->author;
105}
106
107QString Filter::name() const
108{
109 return d->name;
110}
111
112QString Filter::info() const
113{
114 return d->info;
115}
116
117void Filter::setAuthor(const QString &_author)
118{
119 d->author = _author;
120}
121
122void Filter::setName(const QString &_name)
123{
124 d->name = _name;
125}
126
127void Filter::setInfo(const QString &_info)
128{
129 d->info = _info;
130}
131
132bool Filter::importMessage(const QString &folderName, const QString &msgPath, bool duplicateCheck, const MailImporter::MessageStatus &status)
133{
134 return filterImporter()->importMessage(folderName, msgPath, duplicateCheck, status);
135}
136
137int Filter::countDirectory(const QDir &dir, bool searchHiddenDirectory)
138{
139 int countDir = 0;
140 QStringList subDirs;
141 if (searchHiddenDirectory) {
142 subDirs = dir.entryList(QStringList(QStringLiteral("*")), QDir::Dirs | QDir::Hidden, QDir::Name);
143 } else {
144 subDirs = dir.entryList(QStringList(QStringLiteral("[^\\.]*")), QDir::Dirs, QDir::Name); // Removal of . and ..
145 }
146
148 for (QStringList::ConstIterator filename = subDirs.constBegin(); filename != end; ++filename) {
149 if (!(*filename == QLatin1Char('.') || *filename == QLatin1StringView(".."))) {
150 countDir += countDirectory(QDir(dir.filePath(*filename)), searchHiddenDirectory) + 1;
151 }
152 }
153 return countDir;
154}
QString name() const
Definition filters.cpp:107
void setName(const QString &name)
Definition filters.cpp:122
The FilterImporterBase class.
The FilterInfo class.
Definition filterinfo.h:21
The MessageStatus class.
Q_SCRIPTABLE CaptureState status()
KIOCORE_EXPORT QString dir(const QString &fileClass)
QString name(StandardAction id)
const QList< QKeySequence > & end()
const_iterator constBegin() const const
const_iterator constEnd() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.