Commit c6fe054d authored by David Jarvie's avatar David Jarvie

Convert tabs to spaces, indent 4 spaces.

Update copyright email address.
Order #include statements consistently.
parent d3a2ee0d
KAlarm author:
David Jarvie <software@astrojar.org.uk>
Alarm daemon author:
David Jarvie <software@astrojar.org.uk>
Original KOrganizer alarm daemon author:
Preston Brown <pbrown@kde.org>
KOrganizer alarm daemon maintainer:
Cornelius Schumacher <schumacher@kde.org>
\ No newline at end of file
David Jarvie <djarvie@kde.org>
This diff is collapsed.
......@@ -38,8 +38,8 @@
#ifndef USE_AKONADI
namespace KCal {
class Calendar;
class CalendarLocal;
class Calendar;
class CalendarLocal;
}
class AlarmResource;
class ProgressDialog;
......@@ -52,171 +52,173 @@ class ProgressDialog;
*/
class AlarmCalendar : public QObject
{
Q_OBJECT
public:
virtual ~AlarmCalendar();
bool valid() const { return (mCalType == RESOURCES) || mUrl.isValid(); }
KAlarm::CalEvent::Type type() const { return (mCalType == RESOURCES) ? KAlarm::CalEvent::EMPTY : mEventType; }
bool open();
int load();
bool reload();
Q_OBJECT
public:
virtual ~AlarmCalendar();
bool valid() const { return (mCalType == RESOURCES) || mUrl.isValid(); }
KAlarm::CalEvent::Type type() const { return (mCalType == RESOURCES) ? KAlarm::CalEvent::EMPTY : mEventType; }
bool open();
int load();
bool reload();
#ifndef USE_AKONADI
void loadResource(AlarmResource*, QWidget* parent);
void reloadFromCache(const QString& resourceID);
void loadResource(AlarmResource*, QWidget* parent);
void reloadFromCache(const QString& resourceID);
#endif
bool save();
void close();
void startUpdate();
bool endUpdate();
KAEvent* earliestAlarm() const;
void setAlarmPending(KAEvent*, bool pending = true);
bool haveDisabledAlarms() const { return mHaveDisabledAlarms; }
void disabledChanged(const KAEvent*);
KAEvent::List atLoginAlarms() const;
bool save();
void close();
void startUpdate();
bool endUpdate();
KAEvent* earliestAlarm() const;
void setAlarmPending(KAEvent*, bool pending = true);
bool haveDisabledAlarms() const { return mHaveDisabledAlarms; }
void disabledChanged(const KAEvent*);
KAEvent::List atLoginAlarms() const;
#ifdef USE_AKONADI
KCalCore::Event::Ptr kcalEvent(const QString& uniqueID); // if Akonadi, display calendar only
KCalCore::Event::Ptr kcalEvent(const QString& uniqueID); // if Akonadi, display calendar only
#else
KCal::Event* createKCalEvent(const KAEvent* e) const
{ return createKCalEvent(e, QString()); }
KCal::Event* kcalEvent(const QString& uniqueID); // if Akonadi, display calendar only
KCal::Event* createKCalEvent(const KAEvent* e) const
{ return createKCalEvent(e, QString()); }
KCal::Event* kcalEvent(const QString& uniqueID); // if Akonadi, display calendar only
#endif
KAEvent* event(const QString& uniqueID);
KAEvent* templateEvent(const QString& templateName);
KAEvent* event(const QString& uniqueID);
KAEvent* templateEvent(const QString& templateName);
#ifdef USE_AKONADI
KAEvent::List events(KAlarm::CalEvent::Types s = KAlarm::CalEvent::EMPTY) { return events(Akonadi::Collection(), s); }
KAEvent::List events(const Akonadi::Collection&, KAlarm::CalEvent::Types = KAlarm::CalEvent::EMPTY);
KAEvent::List events(KAlarm::CalEvent::Types s = KAlarm::CalEvent::EMPTY) { return events(Akonadi::Collection(), s); }
KAEvent::List events(const Akonadi::Collection&, KAlarm::CalEvent::Types = KAlarm::CalEvent::EMPTY);
#else
KAEvent::List events(KAlarm::CalEvent::Types s = KAlarm::CalEvent::EMPTY) { return events(0, s); }
KAEvent::List events(AlarmResource*, KAlarm::CalEvent::Types = KAlarm::CalEvent::EMPTY);
KAEvent::List events(const KDateTime& from, const KDateTime& to, KAlarm::CalEvent::Types);
KAEvent::List events(KAlarm::CalEvent::Types s = KAlarm::CalEvent::EMPTY) { return events(0, s); }
KAEvent::List events(AlarmResource*, KAlarm::CalEvent::Types = KAlarm::CalEvent::EMPTY);
KAEvent::List events(const KDateTime& from, const KDateTime& to, KAlarm::CalEvent::Types);
#endif
#ifdef USE_AKONADI
KCalCore::Event::List kcalEvents(KAlarm::CalEvent::Type s = KAlarm::CalEvent::EMPTY); // display calendar only
bool eventReadOnly(Akonadi::Item::Id) const;
KCalCore::Event::List kcalEvents(KAlarm::CalEvent::Type s = KAlarm::CalEvent::EMPTY); // display calendar only
bool eventReadOnly(Akonadi::Item::Id) const;
Akonadi::Collection collectionForEvent(Akonadi::Item::Id) const;
bool addEvent(KAEvent&, QWidget* promptParent = 0, bool useEventID = false, Akonadi::Collection* = 0, bool noPrompt = false, bool* cancelled = 0);
bool addEvent(KAEvent&, QWidget* promptParent = 0, bool useEventID = false, Akonadi::Collection* = 0, bool noPrompt = false, bool* cancelled = 0);
#else
KCal::Event::List kcalEvents(KAlarm::CalEvent::Type s = KAlarm::CalEvent::EMPTY) { return kcalEvents(0, s); }
KCal::Event::List kcalEvents(AlarmResource*, KAlarm::CalEvent::Type = KAlarm::CalEvent::EMPTY);
bool eventReadOnly(const QString& uniqueID) const;
AlarmResource* resourceForEvent(const QString& eventID) const;
bool addEvent(KAEvent*, QWidget* promptParent = 0, bool useEventID = false, AlarmResource* = 0, bool noPrompt = false, bool* cancelled = 0);
KCal::Event::List kcalEvents(KAlarm::CalEvent::Type s = KAlarm::CalEvent::EMPTY) { return kcalEvents(0, s); }
KCal::Event::List kcalEvents(AlarmResource*, KAlarm::CalEvent::Type = KAlarm::CalEvent::EMPTY);
bool eventReadOnly(const QString& uniqueID) const;
AlarmResource* resourceForEvent(const QString& eventID) const;
bool addEvent(KAEvent*, QWidget* promptParent = 0, bool useEventID = false, AlarmResource* = 0, bool noPrompt = false, bool* cancelled = 0);
#endif
bool modifyEvent(const QString& oldEventId, KAEvent* newEvent);
KAEvent* updateEvent(const KAEvent&);
KAEvent* updateEvent(const KAEvent*);
bool modifyEvent(const QString& oldEventId, KAEvent* newEvent);
KAEvent* updateEvent(const KAEvent&);
KAEvent* updateEvent(const KAEvent*);
#ifdef USE_AKONADI
bool deleteEvent(const KAEvent&, bool save = false);
bool deleteDisplayEvent(const QString& eventID, bool save = false);
bool deleteEvent(const KAEvent&, bool save = false);
bool deleteDisplayEvent(const QString& eventID, bool save = false);
#else
bool deleteEvent(const QString& eventID, bool save = false);
bool deleteEvent(const QString& eventID, bool save = false);
#endif
void purgeEvents(const KAEvent::List&);
bool isOpen() const { return mOpen; }
QString path() const { return (mCalType == RESOURCES) ? QString() : mUrl.prettyUrl(); }
QString urlString() const { return (mCalType == RESOURCES) ? QString() : mUrl.url(); }
void adjustStartOfDay();
static bool initialiseCalendars();
static void terminateCalendars();
static AlarmCalendar* resources() { return mResourcesCalendar; }
static AlarmCalendar* displayCalendar() { return mDisplayCalendar; }
static AlarmCalendar* displayCalendarOpen();
void purgeEvents(const KAEvent::List&);
bool isOpen() const { return mOpen; }
QString path() const { return (mCalType == RESOURCES) ? QString() : mUrl.prettyUrl(); }
QString urlString() const { return (mCalType == RESOURCES) ? QString() : mUrl.url(); }
void adjustStartOfDay();
static bool initialiseCalendars();
static void terminateCalendars();
static AlarmCalendar* resources() { return mResourcesCalendar; }
static AlarmCalendar* displayCalendar() { return mDisplayCalendar; }
static AlarmCalendar* displayCalendarOpen();
#ifdef USE_AKONADI
static bool importAlarms(QWidget*, Akonadi::Collection* = 0);
static bool importAlarms(QWidget*, Akonadi::Collection* = 0);
#else
static bool importAlarms(QWidget*, AlarmResource* = 0);
static bool importAlarms(QWidget*, AlarmResource* = 0);
#endif
static bool exportAlarms(const KAEvent::List&, QWidget* parent);
static KAEvent* getEvent(const QString& uniqueID);
static bool exportAlarms(const KAEvent::List&, QWidget* parent);
static KAEvent* getEvent(const QString& uniqueID);
signals:
void earliestAlarmChanged();
void haveDisabledAlarmsChanged(bool haveDisabled);
void calendarSaved(AlarmCalendar*);
signals:
void earliestAlarmChanged();
void haveDisabledAlarmsChanged(bool haveDisabled);
void calendarSaved(AlarmCalendar*);
private slots:
void setAskResource(bool ask);
private slots:
void setAskResource(bool ask);
#ifdef USE_AKONADI
void slotCollectionStatusChanged(const Akonadi::Collection&, AkonadiModel::Change, bool value);
void slotEventsAdded(const AkonadiModel::EventList&);
void slotEventsToBeRemoved(const AkonadiModel::EventList&);
void slotEventChanged(const AkonadiModel::Event&);
void slotCollectionStatusChanged(const Akonadi::Collection&, AkonadiModel::Change, bool value);
void slotEventsAdded(const AkonadiModel::EventList&);
void slotEventsToBeRemoved(const AkonadiModel::EventList&);
void slotEventChanged(const AkonadiModel::Event&);
#else
void slotCacheDownloaded(AlarmResource*);
void slotResourceLoaded(AlarmResource*, bool success);
void slotResourceChange(AlarmResource*, AlarmResources::Change);
void slotCacheDownloaded(AlarmResource*);
void slotResourceLoaded(AlarmResource*, bool success);
void slotResourceChange(AlarmResource*, AlarmResources::Change);
#endif
private:
enum CalType { RESOURCES, LOCAL_ICAL, LOCAL_VCAL };
private:
enum CalType { RESOURCES, LOCAL_ICAL, LOCAL_VCAL };
#ifdef USE_AKONADI
typedef QMap<Akonadi::Collection::Id, KAEvent::List> ResourceMap; // id = invalid for display calendar
typedef QMap<Akonadi::Collection::Id, KAEvent*> EarliestMap;
typedef QMap<Akonadi::Collection::Id, KAEvent::List> ResourceMap; // id = invalid for display calendar
typedef QMap<Akonadi::Collection::Id, KAEvent*> EarliestMap;
#else
typedef QMap<AlarmResource*, KAEvent::List> ResourceMap; // resource = null for display calendar
typedef QMap<AlarmResource*, KAEvent*> EarliestMap;
typedef QMap<AlarmResource*, KAEvent::List> ResourceMap; // resource = null for display calendar
typedef QMap<AlarmResource*, KAEvent*> EarliestMap;
#endif
typedef QMap<QString, KAEvent*> KAEventMap; // indexed by event UID
typedef QMap<QString, KAEvent*> KAEventMap; // indexed by event UID
AlarmCalendar();
AlarmCalendar(const QString& file, KAlarm::CalEvent::Type);
bool saveCal(const QString& newFile = QString());
AlarmCalendar();
AlarmCalendar(const QString& file, KAlarm::CalEvent::Type);
bool saveCal(const QString& newFile = QString());
#ifdef USE_AKONADI
bool isValid() const { return mCalType == RESOURCES || mCalendarStorage; }
bool addEvent(const Akonadi::Collection&, KAEvent*);
void addNewEvent(const Akonadi::Collection&, KAEvent*, bool replace = false);
void updateEventInternal(const KAEvent&, const Akonadi::Collection&);
KAlarm::CalEvent::Type deleteEventInternal(const KAEvent&, const Akonadi::Collection& = Akonadi::Collection());
KAlarm::CalEvent::Type deleteEventInternal(const QString& eventID, const KAEvent& = KAEvent(), const Akonadi::Collection& = Akonadi::Collection());
void updateKAEvents(const Akonadi::Collection&);
void removeKAEvents(Akonadi::Collection::Id, bool closing = false);
void findEarliestAlarm(const Akonadi::Collection&);
void findEarliestAlarm(Akonadi::Collection::Id); //deprecated
bool isValid() const { return mCalType == RESOURCES || mCalendarStorage; }
bool addEvent(const Akonadi::Collection&, KAEvent*);
void addNewEvent(const Akonadi::Collection&, KAEvent*, bool replace = false);
void updateEventInternal(const KAEvent&, const Akonadi::Collection&);
KAlarm::CalEvent::Type deleteEventInternal(const KAEvent&, const Akonadi::Collection& = Akonadi::Collection());
KAlarm::CalEvent::Type deleteEventInternal(const QString& eventID, const KAEvent& = KAEvent(), const Akonadi::Collection& = Akonadi::Collection());
void updateKAEvents(const Akonadi::Collection&);
void removeKAEvents(Akonadi::Collection::Id, bool closing = false);
void findEarliestAlarm(const Akonadi::Collection&);
void findEarliestAlarm(Akonadi::Collection::Id); //deprecated
#else
bool isValid() const { return mCalendar; }
bool addEvent(AlarmResource*, KAEvent*);
KAEvent* addEvent(AlarmResource*, const KCal::Event*);
void addNewEvent(AlarmResource*, KAEvent*);
KAlarm::CalEvent::Type deleteEventInternal(const QString& eventID);
void updateKAEvents(AlarmResource*, KCal::CalendarLocal*);
static void updateResourceKAEvents(AlarmResource*, KCal::CalendarLocal*);
void removeKAEvents(AlarmResource*, bool closing = false);
void findEarliestAlarm(AlarmResource*);
KCal::Event* createKCalEvent(const KAEvent*, const QString& baseID) const;
bool isValid() const { return mCalendar; }
bool addEvent(AlarmResource*, KAEvent*);
KAEvent* addEvent(AlarmResource*, const KCal::Event*);
void addNewEvent(AlarmResource*, KAEvent*);
KAlarm::CalEvent::Type deleteEventInternal(const QString& eventID);
void updateKAEvents(AlarmResource*, KCal::CalendarLocal*);
static void updateResourceKAEvents(AlarmResource*, KCal::CalendarLocal*);
void removeKAEvents(AlarmResource*, bool closing = false);
void findEarliestAlarm(AlarmResource*);
KCal::Event* createKCalEvent(const KAEvent*, const QString& baseID) const;
#endif
void checkForDisabledAlarms();
void checkForDisabledAlarms(bool oldEnabled, bool newEnabled);
void checkForDisabledAlarms();
void checkForDisabledAlarms(bool oldEnabled, bool newEnabled);
static AlarmCalendar* mResourcesCalendar; // the calendar resources
static AlarmCalendar* mDisplayCalendar; // the display calendar
static AlarmCalendar* mResourcesCalendar; // the calendar resources
static AlarmCalendar* mDisplayCalendar; // the display calendar
#ifdef USE_AKONADI
KCalCore::FileStorage::Ptr mCalendarStorage; // null pointer for Akonadi
KCalCore::FileStorage::Ptr mCalendarStorage; // null pointer for Akonadi
#else
KCal::Calendar* mCalendar; // AlarmResources or CalendarLocal, null for Akonadi
KCal::Calendar* mCalendar; // AlarmResources or CalendarLocal, null for Akonadi
#endif
ResourceMap mResourceMap;
KAEventMap mEventMap; // lookup of all events by UID
EarliestMap mEarliestAlarm; // alarm with earliest trigger time, by resource
QList<QString> mPendingAlarms; // IDs of alarms which are currently being processed after triggering
KUrl mUrl; // URL of current calendar file
KUrl mICalUrl; // URL of iCalendar file
ResourceMap mResourceMap;
KAEventMap mEventMap; // lookup of all events by UID
EarliestMap mEarliestAlarm; // alarm with earliest trigger time, by resource
QList<QString> mPendingAlarms; // IDs of alarms which are currently being processed after triggering
KUrl mUrl; // URL of current calendar file
KUrl mICalUrl; // URL of iCalendar file
#ifndef USE_AKONADI
typedef QMap<AlarmResource*, ProgressDialog*> ProgressDlgMap;
typedef QMap<AlarmResource*, QWidget*> ResourceWidgetMap;
ProgressDlgMap mProgressDlgs; // download progress dialogues
ResourceWidgetMap mProgressParents; // parent widgets for download progress dialogues
typedef QMap<AlarmResource*, ProgressDialog*> ProgressDlgMap;
typedef QMap<AlarmResource*, QWidget*> ResourceWidgetMap;
ProgressDlgMap mProgressDlgs; // download progress dialogues
ResourceWidgetMap mProgressParents; // parent widgets for download progress dialogues
#endif
QString mLocalFile; // calendar file, or local copy if it's a remote file
CalType mCalType; // what type of calendar mCalendar is (resources/ical/vcal)
KAlarm::CalEvent::Type mEventType; // what type of events the calendar file is for
bool mOpen; // true if the calendar file is open
int mUpdateCount; // nesting level of group of calendar update calls
bool mUpdateSave; // save() was called while mUpdateCount > 0
bool mHaveDisabledAlarms; // there is at least one individually disabled alarm
using QObject::event; // prevent "hidden" warning
QString mLocalFile; // calendar file, or local copy if it's a remote file
CalType mCalType; // what type of calendar mCalendar is (resources/ical/vcal)
KAlarm::CalEvent::Type mEventType; // what type of events the calendar file is for
bool mOpen; // true if the calendar file is open
int mUpdateCount; // nesting level of group of calendar update calls
bool mUpdateSave; // save() was called while mUpdateCount > 0
bool mHaveDisabledAlarms; // there is at least one individually disabled alarm
using QObject::event; // prevent "hidden" warning
};
#endif // ALARMCALENDAR_H
// vim: et sw=4:
......@@ -41,105 +41,107 @@
void AlarmListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItem opt = option;
if (index.isValid())
{
if (opt.state & QStyle::State_Selected
QStyleOptionViewItem opt = option;
if (index.isValid())
{
if (opt.state & QStyle::State_Selected
#ifdef USE_AKONADI
&& !index.data(AkonadiModel::EnabledRole).toBool())
&& !index.data(AkonadiModel::EnabledRole).toBool())
#else
&& !index.data(EventListModel::EnabledRole).toBool())
&& !index.data(EventListModel::EnabledRole).toBool())
#endif
{
// Make the text colour for selected disabled alarms
// distinguishable from enabled alarms.
KColorScheme::adjustForeground(opt.palette, KColorScheme::InactiveText, QPalette::HighlightedText, KColorScheme::Selection);
}
switch (index.column())
{
case ITEM_LIST_MODEL::TimeColumn:
{
QString str = index.data(Qt::DisplayRole).toString();
// Need to pad out spacing to align times without leading zeroes
int i = str.indexOf(" ~"); // look for indicator that leading zeroes are omitted
if (i >= 0)
{
QVariant value;
value = index.data(Qt::ForegroundRole);
if (value.isValid())
opt.palette.setColor(QPalette::Text, value.value<QColor>());
int digitWidth = opt.fontMetrics.width("0");
QString date = str.left(i + 1);
int w = opt.fontMetrics.width(date) + digitWidth;
drawDisplay(painter, opt, opt.rect, date);
QRect rect(opt.rect);
rect.setLeft(rect.left() + w);
drawDisplay(painter, opt, rect, str.mid(i + 2));
return;
}
break;
}
case ITEM_LIST_MODEL::ColourColumn:
{
{
// Make the text colour for selected disabled alarms
// distinguishable from enabled alarms.
KColorScheme::adjustForeground(opt.palette, KColorScheme::InactiveText, QPalette::HighlightedText, KColorScheme::Selection);
}
switch (index.column())
{
case ITEM_LIST_MODEL::TimeColumn:
{
QString str = index.data(Qt::DisplayRole).toString();
// Need to pad out spacing to align times without leading zeroes
int i = str.indexOf(" ~"); // look for indicator that leading zeroes are omitted
if (i >= 0)
{
QVariant value;
value = index.data(Qt::ForegroundRole);
if (value.isValid())
opt.palette.setColor(QPalette::Text, value.value<QColor>());
int digitWidth = opt.fontMetrics.width("0");
QString date = str.left(i + 1);
int w = opt.fontMetrics.width(date) + digitWidth;
drawDisplay(painter, opt, opt.rect, date);
QRect rect(opt.rect);
rect.setLeft(rect.left() + w);
drawDisplay(painter, opt, rect, str.mid(i + 2));
return;
}
break;
}
case ITEM_LIST_MODEL::ColourColumn:
{
#ifdef USE_AKONADI
#ifdef __GNUC__
#warning Check this
#endif
const KAEvent event = static_cast<const ItemListModel*>(index.model())->event(index);
if (event.isValid() && event.commandError() != KAEvent::CMD_NO_ERROR)
const KAEvent event = static_cast<const ItemListModel*>(index.model())->event(index);
if (event.isValid() && event.commandError() != KAEvent::CMD_NO_ERROR)
#else
const KAEvent* event = static_cast<const EventListFilterModel*>(index.model())->event(index);
if (event && event->commandError() != KAEvent::CMD_NO_ERROR)
const KAEvent* event = static_cast<const EventListFilterModel*>(index.model())->event(index);
if (event && event->commandError() != KAEvent::CMD_NO_ERROR)
#endif
{
opt.font.setBold(true);
opt.font.setStyleHint(QFont::Serif);
opt.font.setPixelSize(opt.rect.height() - 2);
}
break;
}
default:
break;
}
}
QItemDelegate::paint(painter, opt, index);
{
opt.font.setBold(true);
opt.font.setStyleHint(QFont::Serif);
opt.font.setPixelSize(opt.rect.height() - 2);
}
break;
}
default:
break;
}
}
QItemDelegate::paint(painter, opt, index);
}
QSize AlarmListDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if (index.isValid())
{
switch (index.column())
{
case ITEM_LIST_MODEL::TimeColumn:
{
int h = option.fontMetrics.lineSpacing();
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
int w = 2 * textMargin;
QString str = index.data(Qt::DisplayRole).toString();
// Need to pad out spacing to align times without leading zeroes
int i = str.indexOf(" ~"); // look for indicator that leading zeroes are omitted
if (i >= 0)
{
int digitWidth = option.fontMetrics.width("0");
QString date = str.left(i + 1);
w += option.fontMetrics.width(date) + digitWidth + option.fontMetrics.width(str.mid(i + 2));;
}
else
w += option.fontMetrics.width(str);
return QSize(w, h);
}
case ITEM_LIST_MODEL::ColourColumn:
{
int h = option.fontMetrics.lineSpacing();
return QSize(h * 3 / 4, h);
}
}
}
return QItemDelegate::sizeHint(option, index);
if (index.isValid())
{
switch (index.column())
{
case ITEM_LIST_MODEL::TimeColumn:
{
int h = option.fontMetrics.lineSpacing();
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
int w = 2 * textMargin;
QString str = index.data(Qt::DisplayRole).toString();
// Need to pad out spacing to align times without leading zeroes
int i = str.indexOf(" ~"); // look for indicator that leading zeroes are omitted
if (i >= 0)
{
int digitWidth = option.fontMetrics.width("0");
QString date = str.left(i + 1);
w += option.fontMetrics.width(date) + digitWidth + option.fontMetrics.width(str.mid(i + 2));;
}
else
w += option.fontMetrics.width(str);
return QSize(w, h);
}
case ITEM_LIST_MODEL::ColourColumn:
{
int h = option.fontMetrics.lineSpacing();
return QSize(h * 3 / 4, h);
}
}
}
return QItemDelegate::sizeHint(option, index);
}
void AlarmListDelegate::edit(KAEvent* event, EventListView* view)
{