File indexing completed on 2024-06-02 05:19:19

0001 /*
0002  *  calendarupdater.h  -  base class to update a calendar to current KAlarm format
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2020 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include "resource.h"
0012 
0013 
0014 // Updates the backend calendar format of a single alarm calendar
0015 class CalendarUpdater : public QObject
0016 {
0017     Q_OBJECT
0018 public:
0019     CalendarUpdater(ResourceId, bool ignoreKeepFormat, QObject* parent, QWidget* promptParent = nullptr);
0020     ~CalendarUpdater() override;
0021 
0022     /** Check whether any instance is for the given resource ID. */
0023     static bool containsResource(ResourceId);
0024 
0025     /** Return whether another instance is already updating this collection. */
0026     bool isDuplicate() const   { return mDuplicate; }
0027 
0028     /** Return whether this instance has completed, and its deletion is pending. */
0029     bool isComplete() const     { return mCompleted; }
0030 
0031     static bool pending()   { return !mInstances.isEmpty(); }
0032 
0033     /** Wait until all completed instances have completed and been deleted. */
0034     static void waitForCompletion();
0035 
0036 #if 0
0037     /** If an existing resource calendar can be converted to the current KAlarm
0038      *  format, prompt the user whether to convert it, and if yes, tell the resource
0039      *  to update the backend storage to the current format.
0040      *  The resource's KeepFormat property will be updated if the user chooses not to
0041      *  update the calendar.
0042      *  This method should call update() on a single shot timer to prompt the
0043      *  user and convert the calendar.
0044      *  @param  parent  Parent object. If possible, this should be a QWidget.
0045      */
0046     static void updateToCurrentFormat(Resource&, bool ignoreKeepFormat, QObject* parent);
0047 #endif
0048 
0049 public Q_SLOTS:
0050     /** If the calendar is not in the current KAlarm format, prompt the user
0051      *  whether to convert to the current format, and then perform the conversion.
0052      *  This method must call deleteLater() on completion.
0053      *  @return  false if the calendar is not in current format and the user
0054      *           chose not to update it; true otherwise.
0055      */
0056     virtual bool update() = 0;
0057 
0058 protected:
0059     /** Mark the instance as completed, and schedule its deletion. */
0060     void setCompleted();
0061 
0062     static QString conversionPrompt(const QString& calendarName, const QString& calendarVersion, bool whole);
0063 
0064     static QList<CalendarUpdater*> mInstances;
0065     ResourceId mResourceId;
0066     QObject*   mParent;
0067     QWidget*   mPromptParent;
0068     const bool mIgnoreKeepFormat;
0069     const bool mDuplicate;          // another instance is already updating this resource
0070     bool       mCompleted {false};  // completed, and deleteLater() called
0071 };
0072 
0073 // vim: et sw=4: