2 Copyright (c) 2013 Sérgio Martins <iamsergio@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 As a special exception, permission is given to link this program
19 with any edition of Qt, and distribute the resulting executable,
20 without including the source code for Qt in the source distribution.
23 #ifndef CALENDARJANITOR_H
24 #define CALENDARJANITOR_H
28 #include <KCalCore/Incidence>
30 #include <Akonadi/Calendar/IncidenceChanger>
31 #include <Akonadi/Calendar/FetchJobCalendar>
32 #include <AkonadiCore/Collection>
33 #include <AkonadiCore/Item>
38 class CollectionLoader
;
40 class CalendarJanitor
: public QObject
44 explicit CalendarJanitor(const Options
&options
, QObject
*parent
= Q_NULLPTR
);
49 void finished(bool success
);
52 void onCollectionsFetched(bool success
);
53 void onItemsFetched(bool success
, const QString
&errorMessage
);
54 void onModifyFinished(int changeId
, const Akonadi::Item
&item
,
55 Akonadi::IncidenceChanger::ResultCode resultCode
, const QString
&errorMessage
);
56 void onDeleteFinished(int changeId
, const QVector
<Akonadi::Item::Id
> &,
57 Akonadi::IncidenceChanger::ResultCode resultCode
, const QString
&errorMessage
);
59 void processNextCollection();
61 // For each collection we process, we run a bunch of tests on it.
74 void stripOldAlarms();
76 void printFound(const Akonadi::Item
&item
, const QString
&explanation
= QString());
78 void beginTest(const QString
&message
);
79 void endTest(bool print
= true, const QString
&fixExplanation
= QString(),
80 const QString
&fixExplanation2
= QString());
82 void deleteIncidence(const Akonadi::Item
&item
);
85 CollectionLoader
*m_collectionLoader
;
86 Akonadi::Collection::List m_collectionsToProcess
;
87 Akonadi::Item::List m_itemsToProcess
;
89 Akonadi::IncidenceChanger
*m_changer
;
90 Akonadi::Collection m_currentCollection
;
91 Options::SanityCheck m_currentSanityCheck
;
92 int m_pendingModifications
;
93 int m_pendingDeletions
;
94 bool m_strippingOldAlarms
;
96 QList
<Akonadi::Item::Id
> m_test1Results
;
97 QStringList m_test2Results
;
100 bool m_fixingEnabled
;
102 QString m_summary
; // to print at the end.
103 QMultiMap
<QString
, KCalCore::Incidence::Ptr
> m_incidenceMap
;
104 QMap
<KCalCore::Incidence::Ptr
, Akonadi::Item
> m_incidenceToItem
;
106 Akonadi::FetchJobCalendar::Ptr m_calendar
;
111 #endif // CALENDARJANITOR_H