File indexing completed on 2024-05-12 05:13:14

0001 /*
0002   SPDX-FileCopyrightText: 2000, 2001 Cornelius Schumacher <schumacher@kde.org>
0003   SPDX-FileCopyrightText: 2004 David Faure <faure@kde.org>
0004   SPDX-FileCopyrightText: 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
0005 
0006   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0007 */
0008 
0009 #pragma once
0010 
0011 #include "calendarsupport_export.h"
0012 
0013 #include <Akonadi/ETMCalendar>
0014 #include <Akonadi/Item>
0015 #include <KCalendarCore/Event>
0016 #include <KCalendarCore/Todo>
0017 
0018 #include <QObject>
0019 
0020 class QDate;
0021 
0022 namespace Akonadi
0023 {
0024 class IncidenceChanger;
0025 }
0026 
0027 namespace CalendarSupport
0028 {
0029 /**
0030  * This class handles expiring and archiving of events.
0031  * It is used directly by the archivedialog, and it is also
0032  * triggered by actionmanager's timer for auto-archiving.
0033  *
0034  * The settings are not held in this class, but directly in KOPrefs (from korganizer.kcfg)
0035  * Be sure to set mArchiveAction and mArchiveFile before a manual archiving
0036  * mAutoArchive is used for auto archiving.
0037  */
0038 class CALENDARSUPPORT_EXPORT EventArchiver : public QObject
0039 {
0040     Q_OBJECT
0041 public:
0042     explicit EventArchiver(QObject *parent = nullptr);
0043     ~EventArchiver() override;
0044 
0045     /**
0046      * Delete or archive events once
0047      * @param calendar the calendar to archive
0048      * @param limitDate all events *before* the limitDate (not included) will be deleted/archived.
0049      * @param widget parent widget for message boxes
0050      * Confirmation and "no events to process" dialogs will be shown
0051      */
0052     void runOnce(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QDate limitDate, QWidget *widget);
0053 
0054     /**
0055      * Delete or archive events. This is called regularly, when auto-archiving
0056      * is enabled
0057      * @param calendar the calendar to archive
0058      * @param widget parent widget for message boxes
0059      * @param withGUI whether this is called from the dialog, so message boxes should be shown.
0060      * Note that error dialogs like "cannot save" are shown even if from this method, so widget
0061      * should be set in all cases.
0062      */
0063     void runAuto(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QWidget *widget, bool withGUI);
0064 
0065 Q_SIGNALS:
0066     void eventsDeleted();
0067 
0068 private:
0069     CALENDARSUPPORT_NO_EXPORT void
0070     run(const Akonadi::ETMCalendar::Ptr &calendar, Akonadi::IncidenceChanger *changer, QDate limitDate, QWidget *widget, bool withGUI, bool errorIfNone);
0071 
0072     CALENDARSUPPORT_NO_EXPORT void
0073     deleteIncidences(Akonadi::IncidenceChanger *changer, QDate limitDate, QWidget *widget, const Akonadi::Item::List &items, bool withGUI);
0074 
0075     CALENDARSUPPORT_NO_EXPORT void archiveIncidences(const Akonadi::ETMCalendar::Ptr &calendar,
0076                                                      Akonadi::IncidenceChanger *changer,
0077                                                      QDate limitDate,
0078                                                      QWidget *widget,
0079                                                      const KCalendarCore::Incidence::List &incidences,
0080                                                      bool withGUI);
0081 
0082     /**
0083      * Checks if all to-dos under @p todo and including @p todo were completed before @p limitDate.
0084      * If not, we can't archive this to-do.
0085      * @param todo root of the sub-tree we are checking
0086      * @param limitDate
0087      * @param checkedUids used internally to prevent infinite recursion due to invalid calendar files
0088      */
0089     CALENDARSUPPORT_NO_EXPORT bool isSubTreeComplete(const Akonadi::ETMCalendar::Ptr &calendar,
0090                                                      const KCalendarCore::Todo::Ptr &todo,
0091                                                      QDate limitDate,
0092                                                      QStringList checkedUids = QStringList()) const;
0093 };
0094 }