Changeset View
Changeset View
Standalone View
Standalone View
agents/mailfilteragent/filtermanager.cpp
Show All 31 Lines | |||||
32 | #include <AkonadiCore/EntityMimeTypeFilterModel> | 32 | #include <AkonadiCore/EntityMimeTypeFilterModel> | ||
33 | #include <Akonadi/KMime/MessageParts> | 33 | #include <Akonadi/KMime/MessageParts> | ||
34 | #include <kconfig.h> | 34 | #include <kconfig.h> | ||
35 | #include <kconfiggroup.h> | 35 | #include <kconfiggroup.h> | ||
36 | #include "mailfilteragent_debug.h" | 36 | #include "mailfilteragent_debug.h" | ||
37 | #include <KLocalizedString> | 37 | #include <KLocalizedString> | ||
38 | #include <KNotification> | 38 | #include <KNotification> | ||
39 | #include <QIcon> | 39 | #include <QIcon> | ||
40 | #include <KIconLoader> | | |||
41 | #include <kmime/kmime_message.h> | 40 | #include <kmime/kmime_message.h> | ||
42 | #include <MailCommon/FilterImporterExporter> | 41 | #include <MailCommon/FilterImporterExporter> | ||
43 | #include <MailCommon/FilterLog> | 42 | #include <MailCommon/FilterLog> | ||
44 | #include <MailCommon/MailFilter> | 43 | #include <MailCommon/MailFilter> | ||
45 | #include <MailCommon/MailKernel> | 44 | #include <MailCommon/MailKernel> | ||
46 | 45 | | |||
47 | // other headers | 46 | // other headers | ||
48 | #include <algorithm> | 47 | #include <algorithm> | ||
49 | #include <errno.h> | 48 | #include <errno.h> | ||
50 | #include <KSharedConfig> | 49 | #include <KSharedConfig> | ||
51 | #include <QLocale> | 50 | #include <QLocale> | ||
52 | 51 | | |||
53 | using namespace MailCommon; | 52 | using namespace MailCommon; | ||
54 | 53 | | |||
55 | class FilterManager::Private | 54 | class FilterManager::Private | ||
56 | { | 55 | { | ||
57 | public: | 56 | public: | ||
58 | Private(FilterManager *qq) | 57 | Private(FilterManager *qq) | ||
59 | : q(qq) | 58 | : q(qq) | ||
60 | , mRequiredPartsBasedOnAll(SearchRule::Envelope) | 59 | , mRequiredPartsBasedOnAll(SearchRule::Envelope) | ||
61 | , mTotalProgressCount(0) | 60 | , mTotalProgressCount(0) | ||
62 | , mCurrentProgressCount(0) | 61 | , mCurrentProgressCount(0) | ||
63 | , mInboundFiltersExist(false) | 62 | , mInboundFiltersExist(false) | ||
64 | { | 63 | { | ||
65 | pixmapNotification = QIcon::fromTheme(QStringLiteral("view-filter")).pixmap(KIconLoader::SizeSmall, KIconLoader::SizeSmall); | | |||
66 | } | 64 | } | ||
67 | 65 | | |||
68 | void itemsFetchJobForFilterDone(KJob *job); | 66 | void itemsFetchJobForFilterDone(KJob *job); | ||
69 | void itemFetchJobForFilterDone(KJob *job); | 67 | void itemFetchJobForFilterDone(KJob *job); | ||
70 | void moveJobResult(KJob *); | 68 | void moveJobResult(KJob *); | ||
71 | void modifyJobResult(KJob *); | 69 | void modifyJobResult(KJob *); | ||
72 | void deleteJobResult(KJob *); | 70 | void deleteJobResult(KJob *); | ||
73 | void slotItemsFetchedForFilter(const Akonadi::Item::List &items); | 71 | void slotItemsFetchedForFilter(const Akonadi::Item::List &items); | ||
74 | void showNotification(const QString &errorMsg, const QString &jobErrorString); | 72 | void showNotification(const QString &errorMsg, const QString &jobErrorString); | ||
75 | 73 | | |||
76 | bool isMatching(const Akonadi::Item &item, const MailCommon::MailFilter *filter); | 74 | bool isMatching(const Akonadi::Item &item, const MailCommon::MailFilter *filter); | ||
77 | void beginFiltering(const Akonadi::Item &item) const; | 75 | void beginFiltering(const Akonadi::Item &item) const; | ||
78 | void endFiltering(const Akonadi::Item &item) const; | 76 | void endFiltering(const Akonadi::Item &item) const; | ||
79 | bool atLeastOneFilterAppliesTo(const QString &accountId) const; | 77 | bool atLeastOneFilterAppliesTo(const QString &accountId) const; | ||
80 | bool atLeastOneIncomingFilterAppliesTo(const QString &accountId) const; | 78 | bool atLeastOneIncomingFilterAppliesTo(const QString &accountId) const; | ||
81 | FilterManager *q; | 79 | FilterManager *q; | ||
82 | QVector<MailCommon::MailFilter *> mFilters; | 80 | QVector<MailCommon::MailFilter *> mFilters; | ||
83 | QMap<QString, SearchRule::RequiredPart> mRequiredParts; | 81 | QMap<QString, SearchRule::RequiredPart> mRequiredParts; | ||
84 | QPixmap pixmapNotification; | | |||
85 | SearchRule::RequiredPart mRequiredPartsBasedOnAll; | 82 | SearchRule::RequiredPart mRequiredPartsBasedOnAll; | ||
86 | int mTotalProgressCount = 0; | 83 | int mTotalProgressCount = 0; | ||
87 | int mCurrentProgressCount = 0; | 84 | int mCurrentProgressCount = 0; | ||
88 | bool mInboundFiltersExist = false; | 85 | bool mInboundFiltersExist = false; | ||
89 | bool mAllFoldersFiltersExist = false; | 86 | bool mAllFoldersFiltersExist = false; | ||
90 | }; | 87 | }; | ||
91 | 88 | | |||
92 | void FilterManager::Private::slotItemsFetchedForFilter(const Akonadi::Item::List &items) | 89 | void FilterManager::Private::slotItemsFetchedForFilter(const Akonadi::Item::List &items) | ||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | 222 | if (job->error()) { | |||
227 | showNotification(i18n("Error applying mail filter modifications"), job->errorString()); | 224 | showNotification(i18n("Error applying mail filter modifications"), job->errorString()); | ||
228 | } | 225 | } | ||
229 | } | 226 | } | ||
230 | 227 | | |||
231 | void FilterManager::Private::showNotification(const QString &errorMsg, const QString &jobErrorString) | 228 | void FilterManager::Private::showNotification(const QString &errorMsg, const QString &jobErrorString) | ||
232 | { | 229 | { | ||
233 | KNotification *notify = new KNotification(QStringLiteral("mailfilterjoberror")); | 230 | KNotification *notify = new KNotification(QStringLiteral("mailfilterjoberror")); | ||
234 | notify->setComponentName(QStringLiteral("akonadi_mailfilter_agent")); | 231 | notify->setComponentName(QStringLiteral("akonadi_mailfilter_agent")); | ||
235 | notify->setPixmap(pixmapNotification); | 232 | notify->setIconName(QStringLiteral("view-filter")); | ||
236 | notify->setText(errorMsg + QLatin1Char('\n') + jobErrorString); | 233 | notify->setText(errorMsg + QLatin1Char('\n') + jobErrorString); | ||
237 | notify->sendEvent(); | 234 | notify->sendEvent(); | ||
238 | } | 235 | } | ||
239 | 236 | | |||
240 | bool FilterManager::Private::isMatching(const Akonadi::Item &item, const MailCommon::MailFilter *filter) | 237 | bool FilterManager::Private::isMatching(const Akonadi::Item &item, const MailCommon::MailFilter *filter) | ||
241 | { | 238 | { | ||
242 | bool result = false; | 239 | bool result = false; | ||
243 | if (FilterLog::instance()->isLogging()) { | 240 | if (FilterLog::instance()->isLogging()) { | ||
▲ Show 20 Lines • Show All 423 Lines • Show Last 20 Lines |