summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimtemplatebase.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimtemplatebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimtemplatebase.cpp b/libopie2/opiepim/core/opimtemplatebase.cpp
new file mode 100644
index 0000000..0a07320
--- a/dev/null
+++ b/libopie2/opiepim/core/opimtemplatebase.cpp
@@ -0,0 +1,112 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 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 "opimtemplatebase.h"
31
32#include <opie2/opimoccurrence.h>
33#include <opie2/private/opimoccurrence_p.h>
34
35namespace Opie {
36
37static void setPeriod( OPimOccurrence& oc, bool period, const QDate& d,
38 const QTime& s, const QTime& t ) {
39 if ( period )
40 oc.setPeriod( d );
41 else
42 oc.setPeriod( d, s, t );
43}
44
45// namespace Opie {
46OPimBase::OPimBase() {}
47OPimBase::~OPimBase() {}
48
49/**
50 * @internal Convert internal Occurrence representation
51 * to the external
52 */
53OPimOccurrence::List OPimBase::convertOccurrenceFromBackend( const OPimBackendOccurrence::List& lst )const {
54 OPimOccurrence::List oc_lst;
55
56 /*
57 * Split multiday events up. Create the internal data structure
58 * and then iterate over the days and create the OPimOccurrecne.
59 */
60 for ( OPimBackendOccurrence::List::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
61 OPimBackendOccurrence boc = *it;
62
63 /*
64 * Create the Shared Data Structure
65 */
66 OPimOccurrence::Data *data = new OPimOccurrence::Data();
67 data->summary = boc.summary();
68 data->location = boc.location();
69 data->note = boc.note();
70 data->uid = boc.uid();
71 data->backend = const_cast<OPimBase*>(this);
72
73 QDateTime start = boc.startDateTime();
74 QDateTime end = boc.endDateTime();
75
76 /*
77 * Start and End are on the same day
78 * Start and End are on two different ways.
79 * - Add Start and End and the days inbetween
80 */
81 int dto = start.daysTo( end );
82 bool allDay = boc.isAllDay();
83
84 if ( dto == 0 ) {
85 OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::StartEnd );
86 setPeriod( oc, allDay, start.date(), start.time(), end.time() );
87 oc_lst.append( oc );
88 }else {
89
90 OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::Start );
91 setPeriod( oc, allDay, start.date(), start.time(), QTime(23,59,59));
92 oc_lst.append( oc );
93
94 QDate next = start.addDays( 1 ).date();
95 while ( next != end.date() ) {
96 oc = OPimOccurrence( data, OPimOccurrence::MidWay );
97 setPeriod( oc, allDay, next, QTime(0, 0, 0), QTime(23, 59, 59));
98 oc_lst.append( oc );
99 next = next.addDays( 1 );
100 }
101
102 oc = OPimOccurrence( data, OPimOccurrence::End );
103 setPeriod( oc, allDay, end.date(), QTime(0, 0, 0 ), end.time() );
104 oc_lst.append( oc );
105 }
106 }
107
108 return oc_lst;
109}
110// }
111
112}