Commit 08e72349 authored by David Jarvie's avatar David Jarvie

Bugfixes

svn path=/trunk/kdepim/; revision=125004
parent 83728f14
......@@ -277,10 +277,10 @@ int KAlarmApp::newInstance()
*/
void KAlarmApp::addWindow(KAlarmMainWindow* win)
{
for (vector<KAlarmMainWindow*>::iterator it = mainWindowList.begin(); it != mainWindowList.end(); ++it)
if (*it == win)
for (KAlarmMainWindow* w = mainWindowList.first(); w; w = mainWindowList.next())
if (w == win)
return;
mainWindowList.push_back(win);
mainWindowList.append(win);
}
......@@ -289,10 +289,10 @@ void KAlarmApp::addWindow(KAlarmMainWindow* win)
*/
void KAlarmApp::deleteWindow(KAlarmMainWindow* win)
{
for (vector<KAlarmMainWindow*>::iterator it = mainWindowList.begin(); it != mainWindowList.end(); ++it)
if (*it == win)
for (QPtrListIterator<KAlarmMainWindow> it(mainWindowList); it.current(); ++it)
if (it.current() == win)
{
mainWindowList.erase(it);
mainWindowList.remove();
break;
}
}
......@@ -383,6 +383,8 @@ bool KAlarmApp::handleMessage(const QString& eventID, EventFunc function)
QDateTime now = QDateTime::currentDateTime();
bool updateCalAndDisplay = false;
KAlarmAlarm displayAlarm;
// Check all the alarms in turn.
// Note that the main alarm is fetched before any other alarms.
for (KAlarmAlarm alarm = event.firstAlarm(); alarm.valid(); alarm = event.nextAlarm(alarm))
{
// Check whether this alarm is due yet
......@@ -398,10 +400,9 @@ bool KAlarmApp::handleMessage(const QString& eventID, EventFunc function)
if (secs < MAX_LATENESS + 30)
continue;
// Check if the main alarm is due yet; if so, display it instead.
// Check if the main alarm is already being displayed.
// (We don't want to display both at the same time.)
KAlarmAlarm al = event.alarm(alarm.sequence() - KAlarmEvent::REPEAT_AT_LOGIN_OFFSET);
if (al.valid() && al.dateTime().secsTo(now) >= 0)
if (displayAlarm.valid())
continue;
}
if (alarm.lateCancel())
......@@ -446,21 +447,21 @@ bool KAlarmApp::handleMessage(const QString& eventID, EventFunc function)
}
/******************************************************************************
* Reschedule the specified alarm for its next repetition. If no repetitions
* remain, cancel it.
* Called when an alarm is displayed to reschedule it for its next repetition.
* If no repetitions remain, cancel it.
*/
void KAlarmApp::rescheduleAlarm(const QString& eventID, int alarmID)
void KAlarmApp::rescheduleAlarm(KAlarmEvent& event, int alarmID)
{
kdDebug() << "KAlarmApp::rescheduleAlarm(): " << eventID << ":" << alarmID << endl;
Event* kcalEvent = calendar.getEvent(eventID);
kdDebug() << "KAlarmApp::rescheduleAlarm(): " << event.id() << ":" << alarmID << endl;
Event* kcalEvent = calendar.getEvent(event.id());
if (!kcalEvent)
kdError() << "KAlarmApp::rescheduleAlarm(): event ID not found: " << eventID << endl;
kdError() << "KAlarmApp::rescheduleAlarm(): event ID not found: " << event.id() << endl;
else
{
KAlarmEvent event(*kcalEvent);
// KAlarmEvent event(*kcalEvent);
KAlarmAlarm alarm = event.alarm(alarmID);
if (!alarm.valid())
kdError() << "KAlarmApp::rescheduleAlarm(): alarm sequence not found: " << eventID << ":" << alarmID << endl;
kdError() << "KAlarmApp::rescheduleAlarm(): alarm sequence not found: " << event.id() << ":" << alarmID << endl;
handleAlarm(event, alarm, ALARM_RESCHEDULE, true);
}
}
......@@ -503,6 +504,8 @@ void KAlarmApp::handleAlarm(KAlarmEvent& event, KAlarmAlarm& alarm, AlarmFunc fu
if (updateCalAndDisplay)
updateMessage(event, 0L); // update the window lists and calendar file
else
event.setUpdated(); // note that the calendar file needs to be updated
break;
}
}
......@@ -510,6 +513,8 @@ void KAlarmApp::handleAlarm(KAlarmEvent& event, KAlarmAlarm& alarm, AlarmFunc fu
break;
}
}
else if (updateCalAndDisplay && event.updated())
updateMessage(event, 0L); // update the window lists and calendar file
break;
case ALARM_CANCEL:
......@@ -545,9 +550,9 @@ void KAlarmApp::addMessage(const KAlarmEvent& event, KAlarmMainWindow* win)
reloadDaemon();
// Update the window lists
for (vector<KAlarmMainWindow*>::iterator it = mainWindowList.begin(); it != mainWindowList.end(); ++it)
if (*it != win)
(*it)->addMessage(event);
for (KAlarmMainWindow* w = mainWindowList.first(); w; w = mainWindowList.next())
if (w != win)
w->addMessage(event);
}
/******************************************************************************
......@@ -569,9 +574,9 @@ void KAlarmApp::modifyMessage(const QString& oldEventID, const KAlarmEvent& newE
reloadDaemon();
// Update the window lists
for (vector<KAlarmMainWindow*>::iterator it = mainWindowList.begin(); it != mainWindowList.end(); ++it)
if (*it != win)
(*it)->modifyMessage(oldEventID, newEvent);
for (KAlarmMainWindow* w = mainWindowList.first(); w; w = mainWindowList.next())
if (w != win)
w->modifyMessage(oldEventID, newEvent);
}
/******************************************************************************
......@@ -593,9 +598,9 @@ void KAlarmApp::updateMessage(const KAlarmEvent& event, KAlarmMainWindow* win)
reloadDaemon();
// Update the window lists
for (vector<KAlarmMainWindow*>::iterator it = mainWindowList.begin(); it != mainWindowList.end(); ++it)
if (*it != win)
(*it)->modifyMessage(event);
for (KAlarmMainWindow* w = mainWindowList.first(); w; w = mainWindowList.next())
if (w != win)
w->modifyMessage(event);
}
/******************************************************************************
......@@ -608,9 +613,9 @@ void KAlarmApp::deleteMessage(KAlarmEvent& event, KAlarmMainWindow* win, bool te
kdDebug() << "KAlarmApp::deleteMessage(): " << event.id() << endl;
// Update the window lists
for (vector<KAlarmMainWindow*>::iterator it = mainWindowList.begin(); it != mainWindowList.end(); ++it)
if (*it != win)
(*it)->deleteMessage(event);
for (KAlarmMainWindow* w = mainWindowList.first(); w; w = mainWindowList.next())
if (w != win)
w->deleteMessage(event);
// Delete the event from the calendar file
calendar.deleteEvent(event.id());
......
......@@ -13,8 +13,6 @@
#ifndef KALARMAPP_H
#define KALARMAPP_H
#include <vector>
#include <kuniqueapp.h>
#include <kurl.h>
......@@ -84,7 +82,7 @@ class KAlarmApp : public KUniqueApplication
void modifyMessage(const QString& oldEventID, const KAlarmEvent& newEvent, KAlarmMainWindow*);
void updateMessage(const KAlarmEvent&, KAlarmMainWindow*);
void deleteMessage(KAlarmEvent&, KAlarmMainWindow*, bool tellDaemon = true);
void rescheduleAlarm(const QString& eventID, int alarmID);
void rescheduleAlarm(KAlarmEvent&, int alarmID);
void displayMessage(const QString& eventID) { handleMessage(eventID, EVENT_DISPLAY); }
void deleteMessage(const QString& eventID) { handleMessage(eventID, EVENT_CANCEL); }
QSize readConfigWindowSize(const char* window, const QSize& defaultSize);
......@@ -110,12 +108,12 @@ class KAlarmApp : public KUniqueApplication
void handleAlarm(KAlarmEvent&, KAlarmAlarm&, AlarmFunc, bool updateCalAndDisplay);
static bool convWakeTime(const QCString timeParam, QDateTime&);
static KAlarmApp* theInstance;
MainWidget* mainWidget; // the parent of the DCOP receiver object
vector<KAlarmMainWindow*> mainWindowList; // active main windows
AlarmCalendar calendar;
bool daemonRegistered; // true if we've registered with alarm daemon
GeneralSettings* m_generalSettings; // general program preferences
static KAlarmApp* theInstance;
MainWidget* mainWidget; // the parent of the DCOP receiver object
QPtrList<KAlarmMainWindow> mainWindowList; // active main windows
AlarmCalendar calendar;
bool daemonRegistered; // true if we've registered with alarm daemon
GeneralSettings* m_generalSettings; // general program preferences
};
inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
......
......@@ -12,6 +12,8 @@
#include "kalarm.h"
#include <stdlib.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
......
......@@ -43,17 +43,21 @@ static const int MAX_LINE_LENGTH = 80; // maximum width (in characters) to tr
/******************************************************************************
* Construct the message window.
* Construct the message window for the specified alarm.
* Other alarms in the supplied event may have been updated by the caller, so
* the whole event needs to be stored for updating the calendar file when it is
* displayed.
*/
MessageWin::MessageWin(const KAlarmEvent& event, const KAlarmAlarm& alarm, bool reschedule_event)
MessageWin::MessageWin(const KAlarmEvent& evnt, const KAlarmAlarm& alarm, bool reschedule_event)
: KMainWindow(0L, "MessageWin", WStyle_StaysOnTop | WDestructiveClose | WGroupLeader),
event(evnt),
message(alarm.messageIsFileName() ? alarm.fileName() : alarm.message()),
font(theApp()->generalSettings()->messageFont()),
colour(alarm.colour()),
dateTime(alarm.repeatAtLogin() ? event.firstAlarm().dateTime() : alarm.dateTime()),
eventID(event.id()),
dateTime(alarm.repeatAtLogin() ? evnt.firstAlarm().dateTime() : alarm.dateTime()),
eventID(evnt.id()),
// audioFile(alarm.audioFile()),
alarmSeq(alarm.id()),
alarmID(alarm.id()),
flags(alarm.flags()),
beep(alarm.beep()),
file(alarm.messageIsFileName()),
......@@ -79,6 +83,7 @@ MessageWin::MessageWin(const KAlarmEvent& event, const KAlarmAlarm& alarm, bool
MessageWin::MessageWin()
: KMainWindow(0L, "MessageWin", WStyle_StaysOnTop | WDestructiveClose),
deferHeight(0),
rescheduleEvent(false),
shown(true)
{
kdDebug() << "MessageWin::MessageWin()" << endl;
......@@ -245,16 +250,21 @@ QSize MessageWin::initView()
*/
void MessageWin::saveProperties(KConfig* config)
{
config->writeEntry(QString::fromLatin1("EventID"), eventID);
config->writeEntry(QString::fromLatin1("AlarmID"), alarmSeq);
config->writeEntry(QString::fromLatin1("Message"), message);
config->writeEntry(QString::fromLatin1("File"), file);
config->writeEntry(QString::fromLatin1("Font"), font);
config->writeEntry(QString::fromLatin1("Colour"), colour);
if (dateTime.isValid())
config->writeEntry(QString::fromLatin1("Time"), dateTime);
config->writeEntry(QString::fromLatin1("Height"), height() - deferHeight);
config->writeEntry(QString::fromLatin1("NoDefer"), noDefer);
if (shown)
{
config->writeEntry(QString::fromLatin1("EventID"), eventID);
config->writeEntry(QString::fromLatin1("AlarmID"), alarmID);
config->writeEntry(QString::fromLatin1("Message"), message);
config->writeEntry(QString::fromLatin1("File"), file);
config->writeEntry(QString::fromLatin1("Font"), font);
config->writeEntry(QString::fromLatin1("Colour"), colour);
if (dateTime.isValid())
config->writeEntry(QString::fromLatin1("Time"), dateTime);
config->writeEntry(QString::fromLatin1("Height"), height() - deferHeight);
config->writeEntry(QString::fromLatin1("NoDefer"), noDefer);
}
else
config->writeEntry(QString::fromLatin1("AlarmID"), -1);
}
/******************************************************************************
......@@ -265,7 +275,7 @@ void MessageWin::saveProperties(KConfig* config)
void MessageWin::readProperties(KConfig* config)
{
eventID = config->readEntry(QString::fromLatin1("EventID"));
alarmSeq = config->readNumEntry(QString::fromLatin1("AlarmID"));
alarmID = config->readNumEntry(QString::fromLatin1("AlarmID"));
message = config->readEntry(QString::fromLatin1("Message"));
file = config->readBoolEntry(QString::fromLatin1("File"));
font = config->readFontEntry(QString::fromLatin1("Font"));
......@@ -274,7 +284,8 @@ void MessageWin::readProperties(KConfig* config)
dateTime = config->readDateTimeEntry(QString::fromLatin1("Time"), &invalidDateTime);
restoreHeight = config->readNumEntry(QString::fromLatin1("Height"));
noDefer = config->readBoolEntry(QString::fromLatin1("NoDefer"));
initView();
if (alarmID > 0)
initView();
}
/******************************************************************************
......@@ -296,7 +307,7 @@ void MessageWin::showEvent(QShowEvent* se)
if (!audioFile.isEmpty())
KAudioPlayer::play(audioFile.latin1());
if (rescheduleEvent)
theApp()->rescheduleAlarm(eventID, alarmSeq);
theApp()->rescheduleAlarm(event, alarmID);
shown = true;
}
}
......
......@@ -46,13 +46,14 @@ class MessageWin : public KMainWindow
private:
QSize initView();
// KAlarmEvent properties
KAlarmEvent event; // the whole event, for updating the calendar file
QString message;
QFont font;
QColor colour;
QDateTime dateTime;
QString eventID;
QString audioFile;
int alarmSeq;
int alarmID;
int flags;
bool beep;
bool file;
......
......@@ -136,8 +136,9 @@ void KAlarmEvent::set(const Event& event)
// Incorporate the alarms' details into the overall event
AlarmMap::ConstIterator it = alarmMap.begin();
mAlarmSeq = it.key();
mMainAlarmID = -1; // initialise as invalid
mAlarmCount = 0;
bool set = false;
for ( ; it != alarmMap.end(); ++it)
{
const AlarmData& data = it.data();
......@@ -145,8 +146,14 @@ void KAlarmEvent::set(const Event& event)
{
mRepeatAtLogin = true;
mRepeatAtLoginDateTime = data.dateTime;
mRepeatAtLoginAlarmID = it.key();
}
else
mMainAlarmID = it.key();
// Ensure that the basic fields are set up even if the repeat-at-login
// alarm is the only alarm in the event (which shouldn't happen!)
if (!data.repeatAtLogin || !set)
{
mMessageOrFile = data.messageOrFile;
mFile = data.file;
......@@ -154,9 +161,11 @@ void KAlarmEvent::set(const Event& event)
mRepeatCount = data.repeatCount;
mRepeatMinutes = data.repeatMinutes;
mLateCancel = data.lateCancel;
set = true;
}
++mAlarmCount;
}
mUpdated = false;
}
void KAlarmEvent::set(const QDateTime& dateTime, const QString& text, const QColor& colour, bool file, int flags, int repeatCount, int repeatInterval)
......@@ -168,6 +177,7 @@ void KAlarmEvent::set(const QDateTime& dateTime, const QString& text, const QCol
mRepeatCount = repeatCount;
mRepeatMinutes = repeatInterval;
set(flags);
mUpdated = false;
}
void KAlarmEvent::set(int flags)
......@@ -179,17 +189,18 @@ void KAlarmEvent::set(int flags)
bool KAlarmEvent::operator==(const KAlarmEvent& event)
{
return mMessageOrFile == event.mMessageOrFile
&& mDateTime == event.mDateTime
&& mColour == event.mColour
&& mRevision == event.mRevision
&& mAlarmSeq == event.mAlarmSeq
&& mRepeatCount == event.mRepeatCount
&& mRepeatMinutes == event.mRepeatMinutes
&& mBeep == event.mBeep
&& mFile == event.mFile
&& mRepeatAtLogin == event.mRepeatAtLogin
&& mLateCancel == event.mLateCancel;
return mMessageOrFile == event.mMessageOrFile
&& mDateTime == event.mDateTime
&& mColour == event.mColour
&& mRevision == event.mRevision
&& mMainAlarmID == event.mMainAlarmID
&& mRepeatAtLoginAlarmID == event.mRepeatAtLoginAlarmID
&& mRepeatCount == event.mRepeatCount
&& mRepeatMinutes == event.mRepeatMinutes
&& mBeep == event.mBeep
&& mFile == event.mFile
&& mRepeatAtLogin == event.mRepeatAtLogin
&& mLateCancel == event.mLateCancel;
}
int KAlarmEvent::flags() const
......@@ -264,17 +275,17 @@ KAlarmAlarm KAlarmEvent::alarm(int alarmID) const
al.mFile = mFile;
al.mColour = mColour;
al.mBeep = mBeep;
if (alarmID == mAlarmSeq)
if (alarmID == mMainAlarmID)
{
al.mAlarmSeq = mAlarmSeq;
al.mAlarmSeq = mMainAlarmID;
al.mDateTime = mDateTime;
al.mRepeatCount = mRepeatCount;
al.mRepeatMinutes = mRepeatMinutes;
al.mLateCancel = mLateCancel;
}
else if (alarmID == mAlarmSeq + REPEAT_AT_LOGIN_OFFSET && mRepeatAtLogin)
else if (alarmID == mRepeatAtLoginAlarmID && mRepeatAtLogin)
{
al.mAlarmSeq = mAlarmSeq + REPEAT_AT_LOGIN_OFFSET;
al.mAlarmSeq = mRepeatAtLoginAlarmID;
al.mDateTime = mRepeatAtLoginDateTime;
// al.mDateTime = QDateTime::currentDateTime().addSecs(-KAlarmApp::MAX_LATENESS - 1);
al.mRepeatAtLogin = true;
......@@ -282,18 +293,27 @@ KAlarmAlarm KAlarmEvent::alarm(int alarmID) const
return al;
}
KAlarmAlarm KAlarmEvent::firstAlarm() const
{
if (mMainAlarmID > 0)
return alarm(mMainAlarmID);
if (mRepeatAtLogin)
return alarm(mRepeatAtLoginAlarmID);
return KAlarmAlarm();
}
KAlarmAlarm KAlarmEvent::nextAlarm(const KAlarmAlarm& alrm) const
{
if (alrm.id() != mAlarmSeq || !mRepeatAtLogin)
if (alrm.id() != mMainAlarmID || !mRepeatAtLogin)
return KAlarmAlarm();
return alarm(alrm.id() + REPEAT_AT_LOGIN_OFFSET);
return alarm(mRepeatAtLoginAlarmID);
}
void KAlarmEvent::removeAlarm(int alarmID)
{
if (alarmID == mAlarmSeq)
if (alarmID == mMainAlarmID)
mAlarmCount = 0; // removing main alarm - also remove subsidiary alarms
else if (alarmID == mAlarmSeq + REPEAT_AT_LOGIN_OFFSET)
else if (alarmID == mRepeatAtLoginAlarmID)
{
mRepeatAtLogin = false;
--mAlarmCount;
......
......@@ -31,7 +31,6 @@
* colour - stored as a hex string prefixed by #, as the first category (event CATEGORIES field)
* elapsed repeat count - stored as the revision number (event SEQUENCE field)
* beep - stored as a "BEEP" category (event CATEGORIES field)
* highest used alarm sequence number - stored as a "SEQnnn" category (event CATEGORIES field)
*/
// KAlarmAlarm corresponds to a single KCal::Alarm instance
......@@ -84,7 +83,7 @@ class KAlarmEvent
BEEP = 0x02,
REPEAT_AT_LOGIN = 0x04
};
KAlarmEvent() : mRevision(0), mAlarmSeq(1), mRepeatCount(0) { }
KAlarmEvent() : mRevision(0), mMainAlarmID(1), mRepeatCount(0) { }
KAlarmEvent(const QDateTime& dt, const QString& message, const QColor& c, bool file, int flags, int repeatCount = 0, int repeatMinutes = 0)
{ set(dt, message, c, file, flags, repeatCount, repeatMinutes); }
explicit KAlarmEvent(const KCal::Event& e) { set(e); }
......@@ -103,16 +102,17 @@ class KAlarmEvent
void set(int flags);
KCal::Event* event() const; // convert to new Event
KAlarmAlarm alarm(int alarmID) const;
KAlarmAlarm firstAlarm() const { return alarm(mAlarmSeq); }
KAlarmAlarm firstAlarm() const;
KAlarmAlarm nextAlarm(const KAlarmAlarm&) const;
bool updateEvent(KCal::Event&) const;
void removeAlarm(int alarmID);
void incrementRevision() { ++mRevision; }
void setUpdated() { mUpdated = true; }
bool updated() const { return mUpdated; }
bool operator==(const KAlarmEvent&);
bool operator!=(const KAlarmEvent& e) { return !operator==(e); }
const QString& id() const { return mEventID; }
int alarmSequence() const { return mAlarmSeq; }
int alarmCount() const { return mAlarmCount; }
const QDateTime& dateTime() const { return mDateTime; }
QDate date() const { return mDateTime.date(); }
......@@ -139,7 +139,8 @@ class KAlarmEvent
QDateTime mRepeatAtLoginDateTime; // repeat at login time
QColor mColour; // background colour of alarm message
int mRevision; // revision number of the original alarm, or 0
int mAlarmSeq; // sequence number of main alarm
int mMainAlarmID; // sequence number of main alarm
int mRepeatAtLoginAlarmID; // sequence number of repeat-at-login alarm
int mAlarmCount; // number of alarms
int mRepeatCount; // number of times to repeat the alarm
int mRepeatMinutes; // interval (minutes) between repeated alarms
......@@ -147,6 +148,7 @@ class KAlarmEvent
bool mFile; // mMessageOrFile is a file URL
bool mRepeatAtLogin; // whether to repeat the alarm at every login
bool mLateCancel; // whether to cancel the alarm if it can't be displayed on time
bool mUpdated; // event has been updated but not written to calendar file
};
#endif // KALARMEVENT_H
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