summaryrefslogtreecommitdiff
blob: 6e75d0ca3e4e6dd25318caac2df83a98fa7090ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
From f73e082654a88617439043454b45bf950d168dfc Mon Sep 17 00:00:00 2001
From: David Jarvie <djarvie@kde.org>
Date: Thu, 29 Mar 2012 00:29:03 +0100
Subject: [PATCH 6/6] Bug 296383: during startup, check that resources
 calendar opens ok

Prevent crash in program initialisation by checking that the
resources calendar has opened successfully.

BUG:296383

Backport of 4a3204b75464406ab3b3505e2fe222937aac6750 (master)
---
 kalarm/Changelog         |    3 ++-
 kalarm/alarmcalendar.cpp |   19 ++++++++++++++++---
 kalarm/alarmcalendar.h   |    4 ++--
 kalarm/kalarmapp.cpp     |    3 ++-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/kalarm/Changelog b/kalarm/Changelog
index 7caf1dd..e2aee86 100644
--- a/kalarm/Changelog
+++ b/kalarm/Changelog
@@ -1,10 +1,11 @@
 KAlarm Change Log
 
-=== Version 2.4.12 --- 26 April 2011 ===
+=== Version 2.4.12 --- 29 March 2012 ===
 - Fix crash on some systems when New Alarm dialogue is displayed from system tray
   icon menu.
 - Fix KAlarm button in alarm window not always showing main window and not
   highlighting the alarm in the main window.
+- Fail cleanly if calendar resources fail to open.
 
 === Version 2.4.11 (KDEPIM 4.4.11) --- 16 April 2011 ===
 - Fix bad borders round left hand buttons of time spinboxes in Oxygen style.
diff --git a/kalarm/alarmcalendar.cpp b/kalarm/alarmcalendar.cpp
index 0b6eed8..281b58c 100644
--- a/kalarm/alarmcalendar.cpp
+++ b/kalarm/alarmcalendar.cpp
@@ -1,7 +1,7 @@
 /*
  *  alarmcalendar.cpp  -  KAlarm calendar file access
  *  Program:  kalarm
- *  Copyright © 2001-2009 by David Jarvie <djarvie@kde.org>
+ *  Copyright © 2001-2012 by David Jarvie <djarvie@kde.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -187,11 +187,24 @@ AlarmCalendar::~AlarmCalendar()
 }
 
 /******************************************************************************
+* Check whether the calendar is open.
+*/
+bool AlarmCalendar::isOpen()
+{
+	if (mOpen  &&  mCalType == RESOURCES  &&  !AlarmResources::instance())
+	{
+		mCalendar = 0;
+		mOpen = false;
+	}
+	return mOpen;
+}
+
+/******************************************************************************
 * Open the calendar if not already open, and load it into memory.
 */
 bool AlarmCalendar::open()
 {
-	if (mOpen)
+	if (isOpen())
 		return true;
 	if (mCalType == RESOURCES)
 	{
@@ -233,7 +246,7 @@ bool AlarmCalendar::open()
 		delete mCalendar;
 		mCalendar = 0;
 	}
-	return mOpen;
+	return isOpen();
 }
 
 /******************************************************************************
diff --git a/kalarm/alarmcalendar.h b/kalarm/alarmcalendar.h
index be4537d..1535dd0 100644
--- a/kalarm/alarmcalendar.h
+++ b/kalarm/alarmcalendar.h
@@ -1,7 +1,7 @@
 /*
  *  alarmcalendar.h  -  KAlarm calendar file access
  *  Program:  kalarm
- *  Copyright © 2001-2009 by David Jarvie <djarvie@kde.org>
+ *  Copyright © 2001-2012 by David Jarvie <djarvie@kde.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -78,7 +78,7 @@ class AlarmCalendar : public QObject
 		KAEvent*              updateEvent(const KAEvent*);
 		bool                  deleteEvent(const QString& eventID, bool save = false);
 		void                  purgeEvents(const KAEvent::List&);
-		bool                  isOpen() const         { return mOpen; }
+		bool                  isOpen();
 		QString               path() const           { return (mCalType == RESOURCES) ? QString() : mUrl.prettyUrl(); }
 		QString               urlString() const      { return (mCalType == RESOURCES) ? QString() : mUrl.url(); }
 		void                  adjustStartOfDay();
diff --git a/kalarm/kalarmapp.cpp b/kalarm/kalarmapp.cpp
index e472bac..f432860 100644
--- a/kalarm/kalarmapp.cpp
+++ b/kalarm/kalarmapp.cpp
@@ -1953,7 +1953,8 @@ bool KAlarmApp::initCheck(bool calendarOnly)
 		 */
 		AlarmCalendar::displayCalendar()->open();
 
-		AlarmCalendar::resources()->open();
+		if (!AlarmCalendar::resources()->open())
+			return false;
 		setArchivePurgeDays();
 
 		firstTime = false;
-- 
1.7.9.2