summaryrefslogtreecommitdiffabout
path: root/libkcal/freebusy.cpp
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /libkcal/freebusy.cpp
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-p1.zip
kdepimpi-p1.tar.gz
kdepimpi-p1.tar.bz2
initial public commit of qt4 portp1
Diffstat (limited to 'libkcal/freebusy.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/freebusy.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/libkcal/freebusy.cpp b/libkcal/freebusy.cpp
index ba15d6d..e4e9ec9 100644
--- a/libkcal/freebusy.cpp
+++ b/libkcal/freebusy.cpp
@@ -1,184 +1,187 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kdebug.h> 21#include <kdebug.h>
22 22
23#include "freebusy.h" 23#include "freebusy.h"
24//Added by qt3to4:
25#include <Q3ValueList>
26#include <Q3PtrList>
24 27
25using namespace KCal; 28using namespace KCal;
26 29
27FreeBusy::FreeBusy() 30FreeBusy::FreeBusy()
28{ 31{
29} 32}
30 33
31FreeBusy::FreeBusy(const QDateTime &start, const QDateTime &end) 34FreeBusy::FreeBusy(const QDateTime &start, const QDateTime &end)
32{ 35{
33 setDtStart(start); 36 setDtStart(start);
34 setDtEnd(end); 37 setDtEnd(end);
35} 38}
36 39
37FreeBusy::FreeBusy( Calendar *calendar, const QDateTime &start, const QDateTime &end ) 40FreeBusy::FreeBusy( Calendar *calendar, const QDateTime &start, const QDateTime &end )
38{ 41{
39 kdDebug() << "FreeBusy::FreeBusy" << endl; 42 kdDebug() << "FreeBusy::FreeBusy" << endl;
40 mCalendar = calendar; 43 mCalendar = calendar;
41 44
42 setDtStart(start); 45 setDtStart(start);
43 setDtEnd(end); 46 setDtEnd(end);
44 47
45 //Gets all the events in the calendar 48 //Gets all the events in the calendar
46 QPtrList<Event> eventList = mCalendar->events(); 49 Q3PtrList<Event> eventList = mCalendar->events();
47 Event *event; 50 Event *event;
48 51
49 int extraDays, i, x, duration; 52 int extraDays, i, x, duration;
50 duration = start.daysTo(end); 53 duration = start.daysTo(end);
51 QDate day; 54 QDate day;
52 QDateTime tmpStart; 55 QDateTime tmpStart;
53 QDateTime tmpEnd; 56 QDateTime tmpEnd;
54 //Loops through every event in the calendar 57 //Loops through every event in the calendar
55 for( event = eventList.first(); event; event = eventList.next() ) { 58 for( event = eventList.first(); event; event = eventList.next() ) {
56 //This whole for loop is for recurring events, it loops through 59 //This whole for loop is for recurring events, it loops through
57 //each of the days of the freebusy request 60 //each of the days of the freebusy request
58 61
59 //First check if this is transparent. If it is, it shouldn't be in the 62 //First check if this is transparent. If it is, it shouldn't be in the
60 //freebusy list 63 //freebusy list
61 if ( event->transparency() == Event::Transparent ) 64 if ( event->transparency() == Event::Transparent )
62 // Transparent 65 // Transparent
63 continue; 66 continue;
64 67
65 for(i=0; i<=duration; i++) { 68 for(i=0; i<=duration; i++) {
66 day=(start.addDays(i).date()); 69 day=(start.addDays(i).date());
67 tmpStart.setDate(day); 70 tmpStart.setDate(day);
68 tmpEnd.setDate(day); 71 tmpEnd.setDate(day);
69 72
70 if( (*(event->recurrence())).doesRecur() ) { 73 if( (*(event->recurrence())).doesRecur() ) {
71 if ( event->isMultiDay() ) { 74 if ( event->isMultiDay() ) {
72 extraDays = event->dtStart().date().daysTo(event->dtEnd().date()); 75 extraDays = event->dtStart().date().daysTo(event->dtEnd().date());
73 for (x=0; x<=extraDays; x++) { 76 for (x=0; x<=extraDays; x++) {
74 if ( event->recursOn(day.addDays(-x))) { 77 if ( event->recursOn(day.addDays(-x))) {
75 tmpStart.setDate(day.addDays(-x)); 78 tmpStart.setDate(day.addDays(-x));
76 tmpStart.setTime(event->dtStart().time()); 79 tmpStart.setTime(event->dtStart().time());
77 tmpEnd=tmpStart.addSecs( (event->duration()) ); 80 tmpEnd=tmpStart.addSecs( (event->duration()) );
78 81
79 addLocalPeriod( tmpStart, tmpEnd ); 82 addLocalPeriod( tmpStart, tmpEnd );
80 break; 83 break;
81 } 84 }
82 } 85 }
83 } else { 86 } else {
84 if (event->recursOn(day)) { 87 if (event->recursOn(day)) {
85 tmpStart.setTime(event->dtStart().time()); 88 tmpStart.setTime(event->dtStart().time());
86 tmpEnd.setTime(event->dtEnd().time()); 89 tmpEnd.setTime(event->dtEnd().time());
87 90
88 addLocalPeriod (tmpStart, tmpEnd); 91 addLocalPeriod (tmpStart, tmpEnd);
89 } 92 }
90 } 93 }
91 } 94 }
92 95
93 } 96 }
94 //Non-reocurring events 97 //Non-reocurring events
95 addLocalPeriod(event->dtStart(), event->dtEnd()); 98 addLocalPeriod(event->dtStart(), event->dtEnd());
96 } 99 }
97 100
98 sortList(); 101 sortList();
99} 102}
100 103
101FreeBusy::~FreeBusy() 104FreeBusy::~FreeBusy()
102{ 105{
103} 106}
104 107
105bool FreeBusy::setDtEnd( const QDateTime &end ) 108bool FreeBusy::setDtEnd( const QDateTime &end )
106{ 109{
107 mDtEnd = end; 110 mDtEnd = end;
108 return true; 111 return true;
109} 112}
110 113
111QDateTime FreeBusy::dtEnd() const 114QDateTime FreeBusy::dtEnd() const
112{ 115{
113 return mDtEnd; 116 return mDtEnd;
114} 117}
115 118
116QValueList<Period> FreeBusy::busyPeriods() const 119Q3ValueList<Period> FreeBusy::busyPeriods() const
117{ 120{
118 return mBusyPeriods; 121 return mBusyPeriods;
119} 122}
120 123
121bool FreeBusy::addLocalPeriod(const QDateTime &eventStart, const QDateTime &eventEnd ) { 124bool FreeBusy::addLocalPeriod(const QDateTime &eventStart, const QDateTime &eventEnd ) {
122 QDateTime tmpStart; 125 QDateTime tmpStart;
123 QDateTime tmpEnd; 126 QDateTime tmpEnd;
124 127
125 //Check to see if the start *or* end of the event is 128 //Check to see if the start *or* end of the event is
126 //between the start and end of the freebusy dates. 129 //between the start and end of the freebusy dates.
127 if (!((((this->dtStart()).secsTo(eventStart)>=0)&&(eventStart.secsTo(this->dtEnd())>=0)) 130 if (!((((this->dtStart()).secsTo(eventStart)>=0)&&(eventStart.secsTo(this->dtEnd())>=0))
128 ||(((this->dtStart()).secsTo(eventEnd) >= 0)&&(eventEnd.secsTo(this->dtEnd()) >= 0)))) 131 ||(((this->dtStart()).secsTo(eventEnd) >= 0)&&(eventEnd.secsTo(this->dtEnd()) >= 0))))
129 return false; 132 return false;
130 133
131 if ( eventStart.secsTo(this->dtStart())>=0) { 134 if ( eventStart.secsTo(this->dtStart())>=0) {
132 tmpStart = this->dtStart(); 135 tmpStart = this->dtStart();
133 } else { 136 } else {
134 tmpStart = eventStart; 137 tmpStart = eventStart;
135 } 138 }
136 139
137 if ( eventEnd.secsTo(this->dtEnd())<=0 ) { 140 if ( eventEnd.secsTo(this->dtEnd())<=0 ) {
138 tmpEnd = this->dtEnd(); 141 tmpEnd = this->dtEnd();
139 } else { 142 } else {
140 tmpEnd = eventEnd; 143 tmpEnd = eventEnd;
141 } 144 }
142 145
143 Period p(tmpStart, tmpEnd); 146 Period p(tmpStart, tmpEnd);
144 mBusyPeriods.append( p ); 147 mBusyPeriods.append( p );
145 148
146 return true; 149 return true;
147} 150}
148 151
149FreeBusy::FreeBusy(QValueList<Period> busyPeriods) 152FreeBusy::FreeBusy(Q3ValueList<Period> busyPeriods)
150{ 153{
151 mBusyPeriods = busyPeriods; 154 mBusyPeriods = busyPeriods;
152} 155}
153 156
154void FreeBusy::sortList() 157void FreeBusy::sortList()
155{ 158{
156 typedef QValueList<Period> PeriodList; 159 typedef Q3ValueList<Period> PeriodList;
157 160
158 PeriodList::Iterator tmpPeriod, earlyPeriod; 161 PeriodList::Iterator tmpPeriod, earlyPeriod;
159 PeriodList sortedList; 162 PeriodList sortedList;
160 QDateTime earlyTime; 163 QDateTime earlyTime;
161 164
162 while( mBusyPeriods.count() > 0 ) { 165 while( mBusyPeriods.count() > 0 ) {
163 earlyTime=(*mBusyPeriods.begin()).start(); 166 earlyTime=(*mBusyPeriods.begin()).start();
164 for (tmpPeriod=mBusyPeriods.begin(); tmpPeriod!=mBusyPeriods.end(); tmpPeriod++) { 167 for (tmpPeriod=mBusyPeriods.begin(); tmpPeriod!=mBusyPeriods.end(); tmpPeriod++) {
165 if (earlyTime.secsTo((*tmpPeriod).start()) <= 0) { 168 if (earlyTime.secsTo((*tmpPeriod).start()) <= 0) {
166 earlyTime=(*tmpPeriod).start(); 169 earlyTime=(*tmpPeriod).start();
167 earlyPeriod=tmpPeriod; 170 earlyPeriod=tmpPeriod;
168 } 171 }
169 } 172 }
170 //Move tmpPeriod to sortedList 173 //Move tmpPeriod to sortedList
171 Period tmpPeriod( (*earlyPeriod).start(), (*earlyPeriod).end() ); 174 Period tmpPeriod( (*earlyPeriod).start(), (*earlyPeriod).end() );
172 sortedList.append( tmpPeriod ); 175 sortedList.append( tmpPeriod );
173 mBusyPeriods.remove( earlyPeriod ); 176 mBusyPeriods.remove( earlyPeriod );
174 } 177 }
175 mBusyPeriods=sortedList; 178 mBusyPeriods=sortedList;
176} 179}
177 180
178void FreeBusy::addPeriod(const QDateTime &start, const QDateTime &end) 181void FreeBusy::addPeriod(const QDateTime &start, const QDateTime &end)
179{ 182{
180 Period p(start, end); 183 Period p(start, end);
181 mBusyPeriods.append( p ); 184 mBusyPeriods.append( p );
182 185
183 sortList(); 186 sortList();
184} 187}