Commit 967e1d7d authored by David Jarvie's avatar David Jarvie
Browse files

Make all DisplayCalendar methods static

parent 2fdf29a9
Pipeline #27834 passed with stage
in 15 minutes and 49 seconds
......@@ -42,7 +42,14 @@ namespace
const QString displayCalendarName = QStringLiteral("displaying.ics");
}
DisplayCalendar* DisplayCalendar::mInstance = nullptr;
bool DisplayCalendar::mInitialised {false};
KAEvent::List DisplayCalendar::mEventList;
QHash<QString, KAEvent*> DisplayCalendar::mEventMap;
KCalendarCore::FileStorage::Ptr DisplayCalendar::mCalendarStorage;
QString DisplayCalendar::mDisplayCalPath;
QString DisplayCalendar::mDisplayICalPath;
DisplayCalendar::CalType DisplayCalendar::mCalType;
bool DisplayCalendar::mOpen {false};
/******************************************************************************
......@@ -54,44 +61,20 @@ void DisplayCalendar::initialise()
{
QDir dir;
dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
const QString displayCal = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1Char('/') + displayCalendarName;
mInstance = new DisplayCalendar(displayCal);
mDisplayCalPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1Char('/') + displayCalendarName;
mDisplayICalPath = mDisplayCalPath;
mDisplayICalPath.replace(QStringLiteral("\\.vcs$"), QStringLiteral(".ics"));
mCalType = (mDisplayCalPath == mDisplayICalPath) ? LOCAL_ICAL : LOCAL_VCAL; // is the calendar in ICal or VCal format?
mInitialised = true;
}
/******************************************************************************
* Terminate access to the display calendar.
*/
void DisplayCalendar::terminate()
{
delete mInstance;
mInstance = nullptr;
}
/******************************************************************************
* Return the display calendar, opening it first if necessary.
*/
DisplayCalendar* DisplayCalendar::instanceOpen()
{
if (mInstance->open())
return mInstance;
qCCritical(KALARM_LOG) << "DisplayCalendar::instanceOpen: Open error";
return nullptr;
}
/******************************************************************************
* Constructor for the display calendar file.
*/
DisplayCalendar::DisplayCalendar(const QString& path)
: mDisplayCalPath(path)
, mDisplayICalPath(path)
{
mDisplayICalPath.replace(QStringLiteral("\\.vcs$"), QStringLiteral(".ics"));
mCalType = (mDisplayCalPath == mDisplayICalPath) ? LOCAL_ICAL : LOCAL_VCAL; // is the calendar in ICal or VCal format?
}
DisplayCalendar::~DisplayCalendar()
{
close();
mInitialised = false;
}
/******************************************************************************
......@@ -99,7 +82,7 @@ DisplayCalendar::~DisplayCalendar()
*/
bool DisplayCalendar::open()
{
if (isOpen())
if (mOpen)
return true;
// Open the display calendar.
......@@ -125,7 +108,7 @@ bool DisplayCalendar::open()
mCalendarStorage->calendar().clear();
mCalendarStorage.clear();
}
return isOpen();
return mOpen;
}
/******************************************************************************
......
......@@ -27,7 +27,6 @@
#include <KCalendarCore/Event>
#include <QHash>
#include <QObject>
using namespace KAlarmCal;
......@@ -36,44 +35,38 @@ using namespace KAlarmCal;
* This stores alarms currently being displayed, to enable them to be
* redisplayed if KAlarm is killed and restarted.
*/
class DisplayCalendar : public QObject
class DisplayCalendar
{
Q_OBJECT
public:
~DisplayCalendar() override;
bool save();
KCalendarCore::Event::Ptr kcalEvent(const QString& uniqueID);
KCalendarCore::Event::List kcalEvents(CalEvent::Type s = CalEvent::EMPTY);
bool addEvent(KAEvent&);
bool deleteEvent(const QString& eventID, bool save = false);
bool isOpen() const { return mOpen; }
void adjustStartOfDay();
static bool save();
static KCalendarCore::Event::Ptr kcalEvent(const QString& uniqueID);
static KCalendarCore::Event::List kcalEvents(CalEvent::Type s = CalEvent::EMPTY);
static bool addEvent(KAEvent&);
static bool deleteEvent(const QString& eventID, bool save = false);
static bool isOpen() { return mInitialised && mOpen; }
static void adjustStartOfDay();
static void initialise();
static void terminate();
static DisplayCalendar* instance() { return mInstance; }
static DisplayCalendar* instanceOpen();
static void initialise();
static bool open();
static void terminate();
private:
enum CalType { LOCAL_ICAL, LOCAL_VCAL };
explicit DisplayCalendar(const QString& file);
bool open();
int load();
void close();
bool saveCal(const QString& newFile = QString());
bool isValid() const { return mCalendarStorage; }
void updateKAEvents();
static int load();
static void close();
static bool saveCal(const QString& newFile = QString());
static bool isValid() { return mCalendarStorage; }
static void updateKAEvents();
static DisplayCalendar* mInstance; // the unique instance
KAEvent::List mEventList;
QHash<QString, KAEvent*> mEventMap; // lookup of all events by UID
KCalendarCore::FileStorage::Ptr mCalendarStorage;
QString mDisplayCalPath; // path of display calendar file
QString mDisplayICalPath; // path of display iCalendar file
CalType mCalType; // mCalendar's type (ical/vcal)
bool mOpen {false}; // true if the calendar file is open
static bool mInitialised; // whether the calendar has been initialised
static KAEvent::List mEventList;
static QHash<QString, KAEvent*> mEventMap; // lookup of all events by UID
static KCalendarCore::FileStorage::Ptr mCalendarStorage;
static QString mDisplayCalPath; // path of display calendar file
static QString mDisplayICalPath; // path of display iCalendar file
static CalType mCalType; // mCalendar's type (ical/vcal)
static bool mOpen; // true if the calendar file is open
};
#endif // DISPLAYCALENDAR_H
......
......@@ -600,9 +600,8 @@ UpdateResult deleteTemplates(const KAEvent::List& events, QWidget* msgParent)
void deleteDisplayEvent(const QString& eventID)
{
qCDebug(KALARM_LOG) << "KAlarm::deleteDisplayEvent:" << eventID;
DisplayCalendar* cal = DisplayCalendar::instanceOpen();
if (cal)
cal->deleteEvent(eventID, true); // save calendar after deleting
if (DisplayCalendar::open())
DisplayCalendar::deleteEvent(eventID, true); // save calendar after deleting
}
/******************************************************************************
......
......@@ -1222,7 +1222,7 @@ void KAlarmApp::changeStartOfDay()
DateTime::setStartOfDay(Preferences::startOfDay());
KAEvent::setStartOfDay(Preferences::startOfDay());
Resources::adjustStartOfDay();
DisplayCalendar::instance()->adjustStartOfDay();
DisplayCalendar::adjustStartOfDay();
}
/******************************************************************************
......@@ -2640,7 +2640,7 @@ bool KAlarmApp::initCheck(bool calendarOnly)
* MessageWin::redisplayAlarms() is executing open() (but before open()
* completes), which causes problems!!
*/
DisplayCalendar::instanceOpen();
DisplayCalendar::open();
}
if (firstTime)
{
......
......@@ -1100,12 +1100,11 @@ void MessageWin::redisplayAlarms()
return;
qCDebug(KALARM_LOG) << "MessageWin::redisplayAlarms";
mRedisplayed = true;
DisplayCalendar* cal = DisplayCalendar::instance();
if (cal && cal->isOpen())
if (DisplayCalendar::isOpen())
{
KAEvent event;
Resource resource;
const Event::List events = cal->kcalEvents();
const Event::List events = DisplayCalendar::kcalEvents();
for (int i = 0, end = events.count(); i < end; ++i)
{
bool showDefer, showEdit;
......@@ -1144,7 +1143,7 @@ void MessageWin::redisplayAlarms()
*/
bool MessageWin::retrieveEvent(KAEvent& event, Resource& resource, bool& showEdit, bool& showDefer)
{
const Event::Ptr kcalEvent = DisplayCalendar::instance()->kcalEvent(CalEvent::uid(mEventId.eventId(), CalEvent::DISPLAYING));
const Event::Ptr kcalEvent = DisplayCalendar::kcalEvent(CalEvent::uid(mEventId.eventId(), CalEvent::DISPLAYING));
if (!reinstateFromDisplaying(kcalEvent, event, resource, showEdit, showDefer))
{
// The event isn't in the displaying calendar.
......@@ -1207,12 +1206,11 @@ bool MessageWin::alarmShowing(KAEvent& event)
const ResourceId id = Resources::resourceForEvent(event.id()).id();
dispEvent.setDisplaying(event, mAlarmType, id,
mDateTime.effectiveKDateTime(), mShowEdit, !mNoDefer);
DisplayCalendar* cal = DisplayCalendar::instanceOpen();
if (cal)
if (DisplayCalendar::open())
{
cal->deleteEvent(dispEvent.id()); // in case it already exists
cal->addEvent(dispEvent);
cal->save();
DisplayCalendar::deleteEvent(dispEvent.id()); // in case it already exists
DisplayCalendar::addEvent(dispEvent);
DisplayCalendar::save();
}
}
theApp()->rescheduleAlarm(event, alarm);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment