summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimoccurrence.cpp
authorzecke <zecke>2004-11-18 21:45:49 (UTC)
committer zecke <zecke>2004-11-18 21:45:49 (UTC)
commit7484344ff5be1f7c54e51715776d0e3cadeb1ed0 (patch) (unidiff)
tree96f427f7a1fb1c8ca0a6efbd72b51e916cb1651d /libopie2/opiepim/core/opimoccurrence.cpp
parent3302eb30390e6053637929316670da3e8fbe279e (diff)
downloadopie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.zip
opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.tar.gz
opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.tar.bz2
Big PIM API Update Core Part (1/2 of what should be implemented):
OPimRecords: -Add a so called safeCast using the rtti value OPimTodo: -Fix memleak with OPimState OPimOccurrence: -New class. Every 'Access' can give occurrences for a period of time Move Documentation
Diffstat (limited to 'libopie2/opiepim/core/opimoccurrence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimoccurrence.cpp319
1 files changed, 319 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimoccurrence.cpp b/libopie2/opiepim/core/opimoccurrence.cpp
new file mode 100644
index 0000000..14ab5cf
--- a/dev/null
+++ b/libopie2/opiepim/core/opimoccurrence.cpp
@@ -0,0 +1,319 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2003, 2004 Holger Freyther <zecke@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimoccurrence.h"
31#include <opie2/opimtemplatebase.h>
32#include <opie2/private/opimoccurrence_p.h>
33
34
35/* QT */
36#include <qshared.h>
37
38
39namespace Opie {
40
41OPimOccurrence::OPimOccurrence( OPimOccurrence::Data* _data,
42 enum OPimOccurrence::Position pos )
43 : m_pos( pos ), data( _data )
44{}
45
46/**
47 * \brief Copy constructor
48 */
49OPimOccurrence::OPimOccurrence( const OPimOccurrence& oc )
50 : data( oc.data )
51{
52 /*
53 * Increment the reference count
54 */
55 data->ref();
56
57 /*
58 * copy the other information
59 */
60 m_start = oc.m_start;
61 m_end = oc.m_end;
62 m_occurrence = oc.m_occurrence;
63 m_isAllDay = oc.m_isAllDay;
64 m_pos = oc.m_pos;
65}
66
67OPimOccurrence::OPimOccurrence()
68 : m_isAllDay( false ), m_pos( StartEnd )
69{
70 /* simple convient c'tor */
71 data = new OPimOccurrence::Data();
72}
73
74OPimOccurrence::~OPimOccurrence() {
75 deref();
76}
77
78/**
79 * \brief Copy Operator
80 */
81OPimOccurrence& OPimOccurrence::operator=( const OPimOccurrence& oc ) {
82 /* guard against self assignment */
83 if ( this == &oc ) return *this;
84
85 oc.data->ref();
86 deref();
87 data = oc.data;
88
89
90 /*
91 * copy the other information
92 */
93 m_start = oc.m_start;
94 m_end = oc.m_end;
95 m_occurrence = oc.m_occurrence;
96 m_isAllDay = oc.m_isAllDay;
97 m_pos = oc.m_pos;
98
99 return *this;
100}
101
102
103/**
104 * @internal
105 */
106void OPimOccurrence::deref() {
107 if ( data->deref() ) {
108 delete data;
109 data = 0;
110 }
111}
112
113/**
114 * \brief Set the Occurrence to be All Day on a specified QDate
115 *
116 * If no QTime is associated to a OPimOccurrence use this Method
117 * to set the Period of this Occurrence. When using this Method
118 * later calls to \sa isAllDay() will return true.
119 * The Occurrence will be set to occurr on \par from.
120 *
121 * @param from The Day this OPimOccurrence occurs
122 *
123 */
124void OPimOccurrence::setPeriod( const QDate& from ) {
125 m_occurrence = from;
126 m_start = m_end = QTime(); // assign invalid value just in case
127 m_isAllDay = true;
128}
129
130/**
131 * \brief Set the period of this Occurrence with a QTime associated (overloaded)
132 *
133 * Set the period of time for this Occurrence. Each Ocurrence is limited
134 * to one day. Using this Method will make \sa isAllDay() return false.
135 * If \par from and \par to are on two different days the QDate of the
136 * \par from QDateTime will be used.
137 *
138 * @param from The Start Date Time of the Occurrence
139 * @param to The End Date Time of the Occurrence
140 */
141void OPimOccurrence::setPeriod( const QDateTime& from, const QDateTime& to ) {
142 m_occurrence = from.date();
143 m_start = from.time();
144 m_end = to.time();
145 m_isAllDay = false;
146}
147
148/**
149 * \brief Set the period of this Occurrence with a QTime associated
150 *
151 * @param from The QDate of the Occurrence
152 * @param start The Start QTime of the Occurrence
153 * @param end The End QTime of the Occurrence
154 */
155void OPimOccurrence::setPeriod( const QDate& from, const QTime& start,
156 const QTime& end ) {
157 m_occurrence = from;
158 m_start = start;
159 m_end = end;
160 m_isAllDay = false;
161}
162
163
164/**
165 * \brief Is a QTime associated to the OPimOccurrence
166 *
167 * @return Return true if no QTime is associated
168 */
169bool OPimOccurrence::isAllDay()const {
170 return m_isAllDay;
171}
172
173
174/**
175 * \brief Return the QDate where this OPimOccurrence takes place
176 * @return the QDate where this OPimOccurrence occurrs.
177 */
178QDate OPimOccurrence::date()const {
179 return m_occurrence;
180}
181
182
183/**
184 * \brief Return the start time of the OPimOccurrence
185 *
186 * @return Return the Start Time of the OPimOccurrence. It is
187 * invalid if \sa isAllDay() returns true.
188 */
189QTime OPimOccurrence::startTime()const {
190 return m_start;
191}
192
193QTime OPimOccurrence::endTime()const {
194 return m_end;
195}
196
197QDateTime OPimOccurrence::startDateTime()const {
198 return QDateTime( m_occurrence, m_start );
199}
200
201QDateTime OPimOccurrence::endDateTime()const {
202 return QDateTime( m_occurrence, m_end );
203}
204
205
206QString OPimOccurrence::summary()const {
207 return data->summary;
208}
209
210QString OPimOccurrence::location()const {
211 return data->location;
212}
213
214QString OPimOccurrence::note()const {
215 return data->note;
216}
217
218
219/**
220 * -1 if no time is associated
221 * otherwise the length of the occurrence in hours
222 */
223int OPimOccurrence::length()const {
224 if ( m_isAllDay )
225 return -1;
226 else
227 return ( m_end.hour() * 60 - m_start.hour() * 60 )
228 + QABS( m_start.minute() - m_end.minute() );
229}
230
231enum OPimOccurrence::Position OPimOccurrence::position()const {
232 return m_pos;
233}
234
235void OPimOccurrence::setPosition( enum OPimOccurrence::Position& pos ) {
236 m_pos = pos;
237}
238
239
240Opie::Core::OSharedPointer<OPimRecord> OPimOccurrence::record()const {
241 if ( !data->record && data->backend )
242 data->record = data->backend->record( data->uid );
243 return data->record;
244}
245
246template<class Record> Record OPimOccurrence::internalToRecord()const {
247 Record target;
248
249 /* If it is not loaded, try to load it using OPimBase */
250 if ( !data->record && data->backend )
251 data->record = data->backend->record( data->uid );
252
253 Record *ta = Record::safeCast( data->record );
254 if ( ta )
255 target = *ta;
256
257
258 return target;
259}
260
261OPimEvent OPimOccurrence::toEvent()const {
262 return internalToRecord<OPimEvent>();
263}
264
265OPimTodo OPimOccurrence::toTodo()const {
266 return internalToRecord<OPimTodo>();
267}
268
269OPimContact OPimOccurrence::toContact()const {
270 return internalToRecord<OPimContact>();
271}
272
273bool OPimOccurrence::operator<( const OPimOccurrence& oc )const {
274 if ( m_occurrence < oc.m_occurrence )
275 return true;
276 if ( m_occurrence == oc.m_occurrence )
277 return m_start < oc.m_start;
278 else
279 return false;
280}
281
282bool OPimOccurrence::operator<=( const OPimOccurrence& oc )const {
283 return ( m_occurrence <= oc.m_occurrence );
284}
285
286bool OPimOccurrence::operator==( const OPimOccurrence& oc )const {
287 if ( data->uid != oc.data->uid )
288 return false;
289 if ( m_occurrence != oc.m_occurrence )
290 return false;
291 if ( m_isAllDay != oc.m_isAllDay )
292 return false;
293 if ( m_isAllDay && oc.m_isAllDay )
294 if ( m_start != oc.m_start ||
295 m_end != oc.m_end )
296 return false;
297 if ( data->summary != oc.data->summary )
298 return false;
299 if ( data->note != oc.data->note )
300 return false;
301 if ( data->location != oc.data->location )
302 return false;
303
304 return true;
305}
306
307bool OPimOccurrence::operator!=( const OPimOccurrence& oc )const {
308 return !( *this == oc );
309}
310
311bool OPimOccurrence::operator>( const OPimOccurrence& oc )const {
312 return !( *this <= oc );
313}
314
315bool OPimOccurrence::operator>=( const OPimOccurrence& oc )const {
316 return !( *this < oc );
317}
318
319}