-rw-r--r-- | libkcal/calendarlocal.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 8ff8b14..3c572f0 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -35,128 +35,159 @@ | |||
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | mEventList.setAutoDelete( true ); | 85 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 86 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 87 | mJournalList.setAutoDelete( false ); |
88 | 88 | ||
89 | mEventList.clear(); | 89 | mEventList.clear(); |
90 | mTodoList.clear(); | 90 | mTodoList.clear(); |
91 | mJournalList.clear(); | 91 | mJournalList.clear(); |
92 | 92 | ||
93 | mEventList.setAutoDelete( false ); | 93 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 94 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 95 | mJournalList.setAutoDelete( false ); |
96 | 96 | ||
97 | setModified( false ); | 97 | setModified( false ); |
98 | } | 98 | } |
99 | |||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | ||
101 | { | ||
102 | QString cat; | ||
103 | bool isBirthday = true; | ||
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | ||
105 | isBirthday = false; | ||
106 | cat = i18n( "Anniversary" ); | ||
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | ||
108 | isBirthday = true; | ||
109 | cat = i18n( "Birthday" ); | ||
110 | } else { | ||
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | ||
112 | return false; | ||
113 | } | ||
114 | Event * eve; | ||
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | ||
116 | if ( !(eve->categories().contains( cat ) )) | ||
117 | continue; | ||
118 | // now we have an event with fitting category | ||
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | ||
120 | continue; | ||
121 | // now we have an event with fitting category+date | ||
122 | if ( eve->summary() != event->summary() ) | ||
123 | continue; | ||
124 | // now we have an event with fitting category+date+summary | ||
125 | return false; | ||
126 | } | ||
127 | return addEvent( event ); | ||
128 | |||
129 | } | ||
99 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
100 | { | 131 | { |
101 | Event * eve; | 132 | Event * eve; |
102 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
103 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
104 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
105 | return false; | 136 | return false; |
106 | } | 137 | } |
107 | } | 138 | } |
108 | return addEvent( event ); | 139 | return addEvent( event ); |
109 | } | 140 | } |
110 | 141 | ||
111 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
112 | { | 143 | { |
113 | insertEvent( event ); | 144 | insertEvent( event ); |
114 | 145 | ||
115 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
116 | 147 | ||
117 | setModified( true ); | 148 | setModified( true ); |
118 | 149 | ||
119 | return true; | 150 | return true; |
120 | } | 151 | } |
121 | 152 | ||
122 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
123 | { | 154 | { |
124 | 155 | ||
125 | 156 | ||
126 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
127 | setModified( true ); | 158 | setModified( true ); |
128 | } | 159 | } |
129 | } | 160 | } |
130 | 161 | ||
131 | 162 | ||
132 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
133 | { | 164 | { |
134 | 165 | ||
135 | Event *event; | 166 | Event *event; |
136 | 167 | ||
137 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
138 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
139 | return event; | 170 | return event; |
140 | } | 171 | } |
141 | } | 172 | } |
142 | 173 | ||
143 | return 0; | 174 | return 0; |
144 | } | 175 | } |
145 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
146 | { | 177 | { |
147 | Todo * eve; | 178 | Todo * eve; |
148 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
149 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
150 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
151 | return false; | 182 | return false; |
152 | } | 183 | } |
153 | } | 184 | } |
154 | return addTodo( todo ); | 185 | return addTodo( todo ); |
155 | } | 186 | } |
156 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
157 | { | 188 | { |
158 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
159 | 190 | ||
160 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
161 | 192 | ||
162 | // Set up subtask relations | 193 | // Set up subtask relations |