author | zecke <zecke> | 2003-05-07 16:02:41 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-05-07 16:02:41 (UTC) |
commit | accd04a63230ac46978f77deae1b0d1419618730 (patch) (unidiff) | |
tree | 6a54ce4cdda8d86a781838b7b990939e2962d461 /libopie/pim | |
parent | ef9b40f99443fabed972d29ce47c2ccb29e77210 (diff) | |
download | opie-accd04a63230ac46978f77deae1b0d1419618730.zip opie-accd04a63230ac46978f77deae1b0d1419618730.tar.gz opie-accd04a63230ac46978f77deae1b0d1419618730.tar.bz2 |
try to use less memory and only create objects like
ORecur, OPimState, OPimNotifyManager and OPimMaintainer if necessary
-rw-r--r-- | libopie/pim/otodo.cpp | 81 | ||||
-rw-r--r-- | libopie/pim/otodo.h | 16 |
2 files changed, 82 insertions, 15 deletions
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index ea66d39..f3df119 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp | |||
@@ -23,6 +23,10 @@ | |||
23 | 23 | ||
24 | struct OTodo::OTodoData : public QShared { | 24 | struct OTodo::OTodoData : public QShared { |
25 | OTodoData() : QShared() { | 25 | OTodoData() : QShared() { |
26 | recur = 0; | ||
27 | state = 0; | ||
28 | maintainer = 0; | ||
29 | notifiers = 0; | ||
26 | }; | 30 | }; |
27 | 31 | ||
28 | QDate date; | 32 | QDate date; |
@@ -33,12 +37,12 @@ struct OTodo::OTodoData : public QShared { | |||
33 | QString sum; | 37 | QString sum; |
34 | QMap<QString, QString> extra; | 38 | QMap<QString, QString> extra; |
35 | ushort prog; | 39 | ushort prog; |
36 | OPimState state; | 40 | OPimState *state; |
37 | ORecur recur; | 41 | ORecur *recur; |
38 | OPimMaintainer maintainer; | 42 | OPimMaintainer *maintainer; |
39 | QDate start; | 43 | QDate start; |
40 | QDate completed; | 44 | QDate completed; |
41 | OPimNotifyManager notifiers; | 45 | OPimNotifyManager *notifiers; |
42 | }; | 46 | }; |
43 | 47 | ||
44 | OTodo::OTodo(const OTodo &event ) | 48 | OTodo::OTodo(const OTodo &event ) |
@@ -151,14 +155,36 @@ QString OTodo::description()const | |||
151 | { | 155 | { |
152 | return data->desc; | 156 | return data->desc; |
153 | } | 157 | } |
158 | bool OTodo::hasState() const{ | ||
159 | if (!data->state ) return false; | ||
160 | return ( data->state->state() != OPimState::Undefined ); | ||
161 | } | ||
154 | OPimState OTodo::state()const { | 162 | OPimState OTodo::state()const { |
155 | return data->state; | 163 | if (!data->state ) { |
164 | OPimState state; | ||
165 | return state; | ||
166 | } | ||
167 | |||
168 | return (*data->state); | ||
169 | } | ||
170 | bool OTodo::hasRecurrence()const { | ||
171 | if (!data->recur) return false; | ||
172 | return data->recur->doesRecur(); | ||
156 | } | 173 | } |
157 | ORecur OTodo::recurrence()const { | 174 | ORecur OTodo::recurrence()const { |
158 | return data->recur; | 175 | if (!data->recur) return ORecur(); |
176 | |||
177 | return (*data->recur); | ||
178 | } | ||
179 | bool OTodo::hasMaintainer()const { | ||
180 | if (!data->maintainer) return false; | ||
181 | |||
182 | return (data->maintainer->mode() != OPimMaintainer::Undefined ); | ||
159 | } | 183 | } |
160 | OPimMaintainer OTodo::maintainer()const { | 184 | OPimMaintainer OTodo::maintainer()const { |
161 | return data->maintainer; | 185 | if (!data->maintainer) return OPimMaintainer(); |
186 | |||
187 | return (*data->maintainer); | ||
162 | } | 188 | } |
163 | void OTodo::setCompleted( bool completed ) | 189 | void OTodo::setCompleted( bool completed ) |
164 | { | 190 | { |
@@ -201,15 +227,25 @@ void OTodo::setCompletedDate( const QDate& date ) { | |||
201 | } | 227 | } |
202 | void OTodo::setState( const OPimState& state ) { | 228 | void OTodo::setState( const OPimState& state ) { |
203 | changeOrModify(); | 229 | changeOrModify(); |
204 | data->state = state; | 230 | if (data->state ) |
231 | (*data->state) = state; | ||
232 | else | ||
233 | data->state = new OPimState( state ); | ||
205 | } | 234 | } |
206 | void OTodo::setRecurrence( const ORecur& rec) { | 235 | void OTodo::setRecurrence( const ORecur& rec) { |
207 | changeOrModify(); | 236 | changeOrModify(); |
208 | data->recur = rec; | 237 | if (data->recur ) |
238 | (*data->recur) = rec; | ||
239 | else | ||
240 | data->recur = new ORecur( rec ); | ||
209 | } | 241 | } |
210 | void OTodo::setMaintainer( const OPimMaintainer& pim ) { | 242 | void OTodo::setMaintainer( const OPimMaintainer& pim ) { |
211 | changeOrModify(); | 243 | changeOrModify(); |
212 | data->maintainer = pim; | 244 | |
245 | if (data->maintainer ) | ||
246 | (*data->maintainer) = pim; | ||
247 | else | ||
248 | data->maintainer = new OPimMaintainer( pim ); | ||
213 | } | 249 | } |
214 | bool OTodo::isOverdue( ) | 250 | bool OTodo::isOverdue( ) |
215 | { | 251 | { |
@@ -260,8 +296,14 @@ QString OTodo::toRichText() const | |||
260 | 296 | ||
261 | return text; | 297 | return text; |
262 | } | 298 | } |
299 | bool OTodo::hasNotifiers()const { | ||
300 | if (!data->notifiers) return false; | ||
301 | return data->notifiers->isEmpty(); | ||
302 | } | ||
263 | OPimNotifyManager& OTodo::notifiers() { | 303 | OPimNotifyManager& OTodo::notifiers() { |
264 | return data->notifiers; | 304 | if (!data->notifiers ) |
305 | data->notifiers = new OPimNotifyManager; | ||
306 | return (*data->notifiers); | ||
265 | } | 307 | } |
266 | 308 | ||
267 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 309 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
@@ -405,12 +447,21 @@ void OTodo::copy( OTodoData* src, OTodoData* dest ) { | |||
405 | dest->sum = src->sum; | 447 | dest->sum = src->sum; |
406 | dest->extra = src->extra; | 448 | dest->extra = src->extra; |
407 | dest->prog = src->prog; | 449 | dest->prog = src->prog; |
408 | dest->state = src->state; | 450 | |
409 | dest->recur = src->recur; | 451 | if (src->state ) |
410 | dest->maintainer = src->maintainer; | 452 | dest->state = new OPimState( *src->state ); |
453 | |||
454 | if (src->recur ) | ||
455 | dest->recur = new ORecur( *src->recur ); | ||
456 | |||
457 | if (src->maintainer ) | ||
458 | dest->maintainer = new OPimMaintainer( *src->maintainer ) | ||
459 | ; | ||
411 | dest->start = src->start; | 460 | dest->start = src->start; |
412 | dest->completed = src->completed; | 461 | dest->completed = src->completed; |
413 | dest->notifiers = src->notifiers; | 462 | |
463 | if (src->notifiers ) | ||
464 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); | ||
414 | } | 465 | } |
415 | QString OTodo::type() const { | 466 | QString OTodo::type() const { |
416 | return QString::fromLatin1("OTodo"); | 467 | return QString::fromLatin1("OTodo"); |
diff --git a/libopie/pim/otodo.h b/libopie/pim/otodo.h index 2f66f55..a58d9aa 100644 --- a/libopie/pim/otodo.h +++ b/libopie/pim/otodo.h | |||
@@ -128,16 +128,31 @@ public: | |||
128 | QDate completedDate()const; | 128 | QDate completedDate()const; |
129 | 129 | ||
130 | /** | 130 | /** |
131 | * does it have a state? | ||
132 | */ | ||
133 | bool hasState()const; | ||
134 | |||
135 | /** | ||
131 | * What is the state of this OTodo? | 136 | * What is the state of this OTodo? |
132 | */ | 137 | */ |
133 | OPimState state()const; | 138 | OPimState state()const; |
134 | 139 | ||
135 | /** | 140 | /** |
141 | * has recurrence? | ||
142 | */ | ||
143 | bool hasRecurrence()const; | ||
144 | |||
145 | /** | ||
136 | * the recurrance of this | 146 | * the recurrance of this |
137 | */ | 147 | */ |
138 | ORecur recurrence()const; | 148 | ORecur recurrence()const; |
139 | 149 | ||
140 | /** | 150 | /** |
151 | * does this OTodo have a maintainer? | ||
152 | */ | ||
153 | bool hasMaintainer()const; | ||
154 | |||
155 | /** | ||
141 | * the Maintainer of this OTodo | 156 | * the Maintainer of this OTodo |
142 | */ | 157 | */ |
143 | OPimMaintainer maintainer()const; | 158 | OPimMaintainer maintainer()const; |
@@ -158,6 +173,7 @@ public: | |||
158 | */ | 173 | */ |
159 | QString toRichText() const; | 174 | QString toRichText() const; |
160 | 175 | ||
176 | bool hasNotifiers()const; | ||
161 | /* | 177 | /* |
162 | * check if the sharing is still fine!! -zecke | 178 | * check if the sharing is still fine!! -zecke |
163 | */ | 179 | */ |