Commit e1e5fd37 authored by David Jarvie's avatar David Jarvie
Browse files

Remove unused #includes and unnecessary methods

parent 10a8886f
Pipeline #23120 passed with stage
in 18 minutes and 26 seconds
......@@ -20,13 +20,8 @@
#include "displaycalendar.h"
//#include "kalarm.h"
//#include "functions.h"
//#include "kalarmapp.h"
#include "mainwindow.h"
#include "preferences.h"
//#include "resources/datamodel.h"
//#include "resources/resources.h"
#include "lib/messagebox.h"
#include "kalarm_debug.h"
......@@ -34,10 +29,6 @@
#include <KCalendarCore/ICalFormat>
#include <KLocalizedString>
//#include <KIO/StatJob>
//#include <KIO/StoredTransferJob>
//#include <KSharedConfig>
//#include <kio_version.h>
#include <QStandardPaths>
#include <QDir>
......@@ -46,8 +37,10 @@ using namespace KCalendarCore;
using namespace KAlarmCal;
static const QString displayCalendarName = QStringLiteral("displaying.ics");
static const ResourceId DISPLAY_RES_ID = -1; // resource ID used for displaying calendar
namespace
{
const QString displayCalendarName = QStringLiteral("displaying.ics");
}
DisplayCalendar* DisplayCalendar::mInstance = nullptr;
......@@ -272,7 +265,6 @@ void DisplayCalendar::updateKAEvents()
delete event;
continue; // ignore events without usable alarms
}
event->setResourceId(DISPLAY_RES_ID);
mEventList += event;
mEventMap[kcalevent->uid()] = event;
}
......@@ -307,7 +299,6 @@ bool DisplayCalendar::addEvent(KAEvent& evnt)
bool remove = false;
if (!mEventMap.contains(event->id()))
{
event->setResourceId(DISPLAY_RES_ID);
mEventList += event;
mEventMap[event->id()] = event;
ok = mCalendarStorage->calendar()->addEvent(kcalEvent);
......@@ -348,7 +339,7 @@ bool DisplayCalendar::deleteEvent(const QString& eventID, bool saveit)
// destructed when the event is deleted below.
const QString id = eventID;
KAEventMap::Iterator it = mEventMap.find(id);
auto it = mEventMap.find(id);
if (it != mEventMap.end())
{
KAEvent* ev = it.value();
......
......@@ -21,9 +21,6 @@
#ifndef DISPLAYCALENDAR_H
#define DISPLAYCALENDAR_H
#include "eventid.h"
#include "resources/resource.h"
#include <KAlarmCal/KAEvent>
#include <KCalendarCore/FileStorage>
......@@ -36,46 +33,47 @@ using namespace KAlarmCal;
/** Provides read and write access to the display calendar.
* This stores alarms currently being displayed, to enable them to be
* redisplayed if KAlarm is killed and restarted.
*/
class DisplayCalendar : public QObject
{
Q_OBJECT
public:
~DisplayCalendar() override;
bool save();
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();
bool addEvent(KAEvent&);
bool deleteEvent(const QString& eventID, bool save = false);
bool isOpen() const { return mOpen; }
void adjustStartOfDay();
static void initialise();
static void terminate();
static DisplayCalendar* instance() { return mInstance; }
static DisplayCalendar* instanceOpen();
static void initialise();
static void terminate();
static DisplayCalendar* instance() { return mInstance; }
static DisplayCalendar* instanceOpen();
private:
enum CalType { LOCAL_ICAL, LOCAL_VCAL };
typedef QHash<QString, KAEvent*> KAEventMap; // indexed by event UID
explicit DisplayCalendar(const QString& file);
bool open();
int load();
void close();
bool saveCal(const QString& newFile = QString());
bool isValid() const { return mCalendarStorage; }
void updateKAEvents();
bool open();
int load();
void close();
bool saveCal(const QString& newFile = QString());
bool isValid() const { return mCalendarStorage; }
void updateKAEvents();
static DisplayCalendar* mInstance; // the unique instance
static DisplayCalendar* mInstance; // the unique instance
KAEvent::List mEventList;
KAEventMap mEventMap; // lookup of all events by UID
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; // what type of calendar mCalendar is (ical/vcal)
bool mOpen {false}; // true if the calendar file is open
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
};
#endif // DISPLAYCALENDAR_H
......
......@@ -255,7 +255,7 @@ UpdateResult addEvent(KAEvent& event, Resource& resource, QWidget* msgParent, in
}
else
{
if (!cal->save(resource, &status.status.message))
if (!resource.save(&status.status.message))
{
resource.reload(true); // discard the new event
status.status.status = SAVE_FAILED;
......@@ -319,7 +319,7 @@ UpdateResult addEvents(QVector<KAEvent>& events, Resource& resource, QWidget* ms
}
if (status.failedCount() == events.count())
status.status = UPDATE_FAILED;
else if (!cal->save(resource, &status.status.message))
else if (!resource.save(&status.status.message))
{
resource.reload(true); // discard the new events
status.updateError(SAVE_FAILED, events.count()); // everything failed
......@@ -378,7 +378,7 @@ UpdateResult addTemplate(KAEvent& event, Resource& resource, QWidget* msgParent)
else
{
event = newev; // update event ID etc.
if (!cal->save(resource, &status.status.message))
if (!resource.save(&status.status.message))
{
resource.reload(true); // discard the new template
status.status.status = SAVE_FAILED;
......@@ -423,7 +423,7 @@ UpdateResult modifyEvent(KAEvent& oldEvent, KAEvent& newEvent, QWidget* msgParen
status.status = UPDATE_FAILED;
else
{
if (!cal->save(resource, &status.status.message))
if (!resource.save(&status.status.message))
{
resource.reload(true); // retrieve the pre-update version of the event
status.status.status = SAVE_FAILED;
......@@ -542,7 +542,7 @@ UpdateResult deleteEvents(QVector<KAEvent>& events, Resource& resource, bool arc
{
QString msg;
for (Resource res : resources)
if (!cal->save(res, &msg))
if (!res.save(&msg))
{
res.reload(true); // retrieve the events which couldn't be deleted
status.setError(SAVE_FAILED, status.failedCount(), msg);
......@@ -588,7 +588,7 @@ UpdateResult deleteTemplates(const KAEvent::List& events, QWidget* msgParent)
{
QString msg;
for (Resource res : resources)
if (!cal->save(res, &msg))
if (!res.save(&msg))
{
res.reload(true); // retrieve the templates which couldn't be deleted
status.status.message = msg;
......@@ -688,7 +688,7 @@ UpdateResult reactivateEvents(QVector<KAEvent>& events, QVector<int>& ineligible
status.setError(status.failedCount() == events.count() ? UPDATE_FAILED : UPDATE_ERROR, status.failedCount());
if (status.failedCount() < events.count())
{
if (!cal->save(resource, &status.status.message))
if (!resource.save(&status.status.message))
{
resource.reload(true);
status.updateError(SAVE_FAILED, count);
......@@ -767,7 +767,7 @@ UpdateResult enableEvents(QVector<KAEvent>& events, bool enable, QWidget* msgPar
for (ResourceId id : resourceIds)
{
Resource res = Resources::resource(id);
if (!cal->save(res, &msg))
if (!res.save(&msg))
{
// Don't reload resource after failed save. It's better to
// keep the new enabled status of the alarms at least until
......@@ -1334,7 +1334,7 @@ KAlarm::UpdateResult updateEvent(KAEvent& event, KAlarm::UpdateError err, QWidge
else
{
Resource resource = Resources::resource(event.resourceId());
if (!cal->save(resource, &status.status.message))
if (!resource.save(&status.status.message))
{
resource.reload(true); // retrieve the pre-update version of the event
status.status.status = KAlarm::SAVE_FAILED;
......@@ -1616,7 +1616,9 @@ void refreshAlarmsIfQueued()
if (refreshAlarmsQueued)
{
qCDebug(KALARM_LOG) << "KAlarm::refreshAlarmsIfQueued";
ResourcesCalendar::instance()->reload();
QVector<Resource> resources = Resources::enabledResources();
for (Resource& resource : resources)
resource.reload();
// Close any message windows for alarms which are now disabled
const KAEvent::List events = ResourcesCalendar::instance()->events(CalEvent::ACTIVE);
......
......@@ -21,34 +21,14 @@
#include "resourcescalendar.h"
#include "kalarm.h"
#include "functions.h"
#include "kalarmapp.h"
#include "mainwindow.h"
#include "preferences.h"
#include "resources/datamodel.h"
#include "resources/resources.h"
#include "lib/messagebox.h"
#include "kalarm_debug.h"
#include <KCalendarCore/MemoryCalendar>
#include <KCalendarCore/ICalFormat>
#include <KLocalizedString>
#include <KIO/StatJob>
#include <KIO/StoredTransferJob>
#include <KSharedConfig>
#include <kio_version.h>
#include <QStandardPaths>
#include <QDir>
using namespace KCalendarCore;
using namespace KAlarmCal;
static const QString displayCalendarName = QStringLiteral("displaying.ics");
static const ResourceId DISPLAY_RES_ID = -1; // resource ID used for displaying calendar
ResourcesCalendar* ResourcesCalendar::mInstance = nullptr;
......@@ -60,7 +40,7 @@ ResourcesCalendar* ResourcesCalendar::mInstance = nullptr;
void ResourcesCalendar::initialise()
{
KACalendar::setProductId(KALARM_NAME, KALARM_VERSION);
CalFormat::setApplication(QStringLiteral(KALARM_NAME), QString::fromLatin1(KACalendar::icalProductId()));
KCalendarCore::CalFormat::setApplication(QStringLiteral(KALARM_NAME), QString::fromLatin1(KACalendar::icalProductId()));
mInstance = new ResourcesCalendar();
}
......@@ -104,50 +84,6 @@ ResourcesCalendar::ResourcesCalendar()
}
ResourcesCalendar::~ResourcesCalendar()
{
close();
}
/******************************************************************************
* Reload the calendar resources into memory.
*/
bool ResourcesCalendar::reload()
{
qCDebug(KALARM_LOG) << "ResourcesCalendar::reload";
bool ok = true;
QVector<Resource> resources = Resources::enabledResources();
for (Resource& resource : resources)
ok = ok && resource.reload();
return ok;
}
/******************************************************************************
* Save the calendar.
*/
bool ResourcesCalendar::save()
{
bool ok = true;
// Get all enabled, writable resources.
QVector<Resource> resources = Resources::enabledResources(CalEvent::EMPTY, true);
for (Resource& res : resources)
ok = ok && res.save();
return ok;
}
/******************************************************************************
* Save a resource in the calendar.
* If errorMessage is non-null, it will receive the error message in case of
* error, and the resource will not display the error message.
*/
bool ResourcesCalendar::save(Resource& resource, QString* errorMessage)
{
return resource.save(errorMessage);
}
/******************************************************************************
* Close display calendar file at program exit.
*/
void ResourcesCalendar::close()
{
// Resource map should be empty, but just in case...
while (!mResourceMap.isEmpty())
......@@ -173,10 +109,7 @@ bool ResourcesCalendar::removeKAEvents(ResourceId key, bool closing, CalEvent::T
KAEvent* event = events[i];
bool remove = (event->resourceId() != key);
if (remove)
{
if (key != DISPLAY_RES_ID)
qCCritical(KALARM_LOG) << "ResourcesCalendar::removeKAEvents: Event" << event->id() << ", resource" << event->resourceId() << "Indexed under resource" << key;
}
qCCritical(KALARM_LOG) << "ResourcesCalendar::removeKAEvents: Event" << event->id() << ", resource" << event->resourceId() << "Indexed under resource" << key;
else
remove = event->category() & types;
if (remove)
......@@ -375,7 +308,7 @@ bool ResourcesCalendar::addEvent(KAEvent& evnt, Resource& resource, QWidget* pro
else
useEventID = true;
if (id.isEmpty())
id = CalFormat::createUniqueId();
id = KCalendarCore::CalFormat::createUniqueId();
if (useEventID)
id = CalEvent::uid(id, type); // include the alarm type tag in the ID
event->setEventId(id);
......@@ -484,7 +417,7 @@ bool ResourcesCalendar::modifyEvent(const EventId& oldEventId, KAEvent& newEvent
return false;
}
if (noNewId)
newEvent.setEventId(CalFormat::createUniqueId());
newEvent.setEventId(KCalendarCore::CalFormat::createUniqueId());
Resource resource = Resources::resource(oldEventId.resourceId());
if (!resource.isValid())
return false;
......
......@@ -41,10 +41,6 @@ class ResourcesCalendar : public QObject
Q_OBJECT
public:
~ResourcesCalendar() override;
bool reload();
bool save();
bool save(Resource&, QString* errorMessage = nullptr);
void close();
KAEvent* earliestAlarm() const;
void setAlarmPending(KAEvent*, bool pending = true);
bool haveDisabledAlarms() const { return mHaveDisabledAlarms; }
......
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