[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/kalarm
From:       David Jarvie <djarvie () kde ! org>
Date:       2010-11-15 17:19:02
Message-ID: 20101115171902.A6CA6AC8A2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1197403 by djarvie:

Fix working-time-only alarms not triggering if KAlarm is started up outside
working hours, after the last trigger time during working hours was missed.


 M  +33 -7     kalarmapp.cpp  
 M  +1 -1      kalarmapp.h  


--- trunk/KDE/kdepim/kalarm/kalarmapp.cpp #1197402:1197403
@@ -1191,6 +1191,7 @@
 					}
 				}
 				bool reschedule = false;
+				bool rescheduleWork = false;
 				if ((event->workTimeOnly() || event->holidaysExcluded())  &&  !alarm.deferred())
 				{
 					// The alarm is restricted to working hours and/or non-holidays
@@ -1204,7 +1205,9 @@
 					}
 					else
 						reschedule = !event->isWorkingTime(nextDT);
-					if (reschedule) { kDebug() << "Alarm" << alarm.type() << "at" << \
nextDT.dateTime() << ": not during working hours"; } +					rescheduleWork = \
reschedule; +					if (reschedule)
+						kDebug() << "Alarm" << alarm.type() << "at" << nextDT.dateTime() << ": not \
during working hours";  }
 				if (!reschedule  &&  alarm.repeatAtLogin())
 				{
@@ -1303,7 +1306,7 @@
 				if (reschedule)
 				{
 					// The latest repetition was too long ago, so schedule the next one
-					rescheduleAlarm(*event, alarm, false);
+					rescheduleAlarm(*event, alarm, false, (rescheduleWork ? nextDT : KDateTime()));
 					updateCalAndDisplay = true;
 					continue;
 				}
@@ -1361,11 +1364,14 @@
 }
 
 /******************************************************************************
-* Reschedule the alarm for its next recurrence. If none remain, delete it.
-* If the alarm is deleted and it is the last alarm for its event, the event is
-* removed from the calendar file and from every main window instance.
+* Reschedule the alarm for its next recurrence after now. If none remain,
+* delete it.  If the alarm is deleted and it is the last alarm for its event,
+* the event is removed from the calendar file and from every main window
+* instance.
+* If 'nextDt' is valid, the event is rescheduled for the next non-working
+* time occurrence after that.
 */
-void KAlarmApp::rescheduleAlarm(KAEvent& event, const KAAlarm& alarm, bool \
updateCalAndDisplay) +void KAlarmApp::rescheduleAlarm(KAEvent& event, const KAAlarm& \
alarm, bool updateCalAndDisplay, const KDateTime& nextDt)  {
 	kDebug();
 	bool update = false;
@@ -1385,7 +1391,12 @@
 	else
 	{
 		// Reschedule the alarm for its next occurrence.
-		KAEvent::OccurType type = \
event.setNextOccurrence(KDateTime::currentUtcDateTime()); +		bool next = \
nextDt.isValid(); +		KDateTime next_dt = nextDt;
+		KDateTime now = KDateTime::currentUtcDateTime();
+		do
+		{
+			KAEvent::OccurType type = event.setNextOccurrence(next ? next_dt : now);
 		switch (type)
 		{
 			case KAEvent::NO_OCCURRENCE:
@@ -1414,7 +1425,22 @@
 			event.removeExpiredAlarm(KAAlarm::DEFERRED_ALARM);
 			update = true;
 		}
+			if (next)
+			{
+				// The alarm is restricted to working hours and/or non-holidays.
+				// Check if the calculated next time is valid.
+				next_dt = event.mainDateTime(true).effectiveKDateTime();
+				if (event.mainDateTime(false).isDateOnly())
+				{
+					KDateTime dt(next_dt);
+					dt.setDateOnly(true);
+					next = !event.isWorkingTime(dt);
 	}
+				else
+					next = !event.isWorkingTime(next_dt);
+			}
+		} while (next && next_dt <= now);
+	}
 	event.endChanges();
 	if (update)
 		KAlarm::updateEvent(event);     // update the window lists and calendar file
--- trunk/KDE/kdepim/kalarm/kalarmapp.h #1197402:1197403
@@ -163,7 +163,7 @@
 		void               queueAlarmId(const QString& id);
 		bool               dbusHandleEvent(const QString& eventID, EventFunc);
 		bool               handleEvent(const QString& eventID, EventFunc);
-		void               rescheduleAlarm(KAEvent&, const KAAlarm&, bool \
updateCalAndDisplay); +		void               rescheduleAlarm(KAEvent&, const KAAlarm&, \
bool updateCalAndDisplay, const KDateTime& nextDt = KDateTime());  bool               \
cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);  ShellProcess*      \
doShellCommand(const QString& command, const KAEvent&, const KAAlarm*, int flags = 0, \
const QObject* receiver = 0, const char* slot = 0);  QString            \
composeXTermCommand(const QString& command, const KAEvent&, const KAAlarm*, int \
flags, QString& tempScriptFile) const;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic