author | zautrix <zautrix> | 2004-10-15 14:26:07 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-15 14:26:07 (UTC) |
commit | 4f276d80bd977401d656851515474cc00c661e5b (patch) (unidiff) | |
tree | 0d3a747bef0431ef791b69876f5bda554f9ca83f /libkcal/event.cpp | |
parent | c2fb960297c4b08980921c818a4d347057732390 (diff) | |
download | kdepimpi-4f276d80bd977401d656851515474cc00c661e5b.zip kdepimpi-4f276d80bd977401d656851515474cc00c661e5b.tar.gz kdepimpi-4f276d80bd977401d656851515474cc00c661e5b.tar.bz2 |
many phone and sync fixes
-rw-r--r-- | libkcal/event.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp index dfa265b..7256f05 100644 --- a/libkcal/event.cpp +++ b/libkcal/event.cpp | |||
@@ -1,177 +1,223 @@ | |||
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 <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "event.h" | 25 | #include "event.h" |
26 | 26 | ||
27 | using namespace KCal; | 27 | using namespace KCal; |
28 | 28 | ||
29 | Event::Event() : | 29 | Event::Event() : |
30 | mHasEndDate( false ), mTransparency( Opaque ) | 30 | mHasEndDate( false ), mTransparency( Opaque ) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | Event::Event(const Event &e) : Incidence(e) | 34 | Event::Event(const Event &e) : Incidence(e) |
35 | { | 35 | { |
36 | mDtEnd = e.mDtEnd; | 36 | mDtEnd = e.mDtEnd; |
37 | mHasEndDate = e.mHasEndDate; | 37 | mHasEndDate = e.mHasEndDate; |
38 | mTransparency = e.mTransparency; | 38 | mTransparency = e.mTransparency; |
39 | } | 39 | } |
40 | 40 | ||
41 | Event::~Event() | 41 | Event::~Event() |
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | Incidence *Event::clone() | 45 | Incidence *Event::clone() |
46 | { | 46 | { |
47 | return new Event(*this); | 47 | return new Event(*this); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool KCal::operator==( const Event& e1, const Event& e2 ) | 50 | bool KCal::operator==( const Event& e1, const Event& e2 ) |
51 | { | 51 | { |
52 | return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && | 52 | return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && |
53 | e1.dtEnd() == e2.dtEnd() && | 53 | e1.dtEnd() == e2.dtEnd() && |
54 | e1.hasEndDate() == e2.hasEndDate() && | 54 | e1.hasEndDate() == e2.hasEndDate() && |
55 | e1.transparency() == e2.transparency(); | 55 | e1.transparency() == e2.transparency(); |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | bool Event::contains ( Event* from ) | ||
60 | { | ||
61 | |||
62 | if ( !from->summary().isEmpty() ) | ||
63 | if ( !summary().startsWith( from->summary() )) | ||
64 | return false; | ||
65 | if ( from->dtStart().isValid() ) | ||
66 | if (dtStart() != from->dtStart() ) | ||
67 | return false; | ||
68 | if ( from->dtEnd().isValid() ) | ||
69 | if ( dtEnd() != from->dtEnd() ) | ||
70 | return false; | ||
71 | if ( !from->location().isEmpty() ) | ||
72 | if ( !location().startsWith( from->location() ) ) | ||
73 | return false; | ||
74 | if ( !from->description().isEmpty() ) | ||
75 | if ( !description().startsWith( from->description() )) | ||
76 | return false; | ||
77 | if ( from->alarms().count() ) { | ||
78 | Alarm *a = from->alarms().first(); | ||
79 | if ( a->enabled() ){ | ||
80 | if ( !alarms().count() ) | ||
81 | return false; | ||
82 | Alarm *b = alarms().first(); | ||
83 | if( ! b->enabled() ) | ||
84 | return false; | ||
85 | if ( ! (a->offset() == b->offset() )) | ||
86 | return false; | ||
87 | } | ||
88 | } | ||
89 | QStringList cat = categories(); | ||
90 | QStringList catFrom = from->categories(); | ||
91 | QString nCat; | ||
92 | int iii; | ||
93 | for ( iii = 0; iii < catFrom.count();++iii ) { | ||
94 | nCat = catFrom[iii]; | ||
95 | if ( !nCat.isEmpty() ) | ||
96 | if ( !cat.contains( nCat )) { | ||
97 | return false; | ||
98 | } | ||
99 | } | ||
100 | if ( from->doesRecur() ) | ||
101 | if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) | ||
102 | return false; | ||
103 | return true; | ||
104 | } | ||
59 | 105 | ||
60 | void Event::setDtEnd(const QDateTime &dtEnd) | 106 | void Event::setDtEnd(const QDateTime &dtEnd) |
61 | { | 107 | { |
62 | if (mReadOnly) return; | 108 | if (mReadOnly) return; |
63 | 109 | ||
64 | mDtEnd = getEvenTime( dtEnd ); | 110 | mDtEnd = getEvenTime( dtEnd ); |
65 | 111 | ||
66 | setHasEndDate(true); | 112 | setHasEndDate(true); |
67 | setHasDuration(false); | 113 | setHasDuration(false); |
68 | 114 | ||
69 | updated(); | 115 | updated(); |
70 | } | 116 | } |
71 | 117 | ||
72 | QDateTime Event::dtEnd() const | 118 | QDateTime Event::dtEnd() const |
73 | { | 119 | { |
74 | if (hasEndDate()) return mDtEnd; | 120 | if (hasEndDate()) return mDtEnd; |
75 | if (hasDuration()) return dtStart().addSecs(duration()); | 121 | if (hasDuration()) return dtStart().addSecs(duration()); |
76 | 122 | ||
77 | kdDebug(5800) << "Warning! Event '" << summary() | 123 | kdDebug(5800) << "Warning! Event '" << summary() |
78 | << "' does have neither end date nor duration." << endl; | 124 | << "' does have neither end date nor duration." << endl; |
79 | return dtStart(); | 125 | return dtStart(); |
80 | } | 126 | } |
81 | 127 | ||
82 | QString Event::dtEndTimeStr() const | 128 | QString Event::dtEndTimeStr() const |
83 | { | 129 | { |
84 | return KGlobal::locale()->formatTime(mDtEnd.time()); | 130 | return KGlobal::locale()->formatTime(mDtEnd.time()); |
85 | } | 131 | } |
86 | 132 | ||
87 | QString Event::dtEndDateStr(bool shortfmt) const | 133 | QString Event::dtEndDateStr(bool shortfmt) const |
88 | { | 134 | { |
89 | return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); | 135 | return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); |
90 | } | 136 | } |
91 | 137 | ||
92 | QString Event::dtEndStr(bool shortfmt) const | 138 | QString Event::dtEndStr(bool shortfmt) const |
93 | { | 139 | { |
94 | return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); | 140 | return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); |
95 | } | 141 | } |
96 | 142 | ||
97 | void Event::setHasEndDate(bool b) | 143 | void Event::setHasEndDate(bool b) |
98 | { | 144 | { |
99 | mHasEndDate = b; | 145 | mHasEndDate = b; |
100 | } | 146 | } |
101 | 147 | ||
102 | bool Event::hasEndDate() const | 148 | bool Event::hasEndDate() const |
103 | { | 149 | { |
104 | return mHasEndDate; | 150 | return mHasEndDate; |
105 | } | 151 | } |
106 | 152 | ||
107 | bool Event::isMultiDay() const | 153 | bool Event::isMultiDay() const |
108 | { | 154 | { |
109 | bool multi = !(dtStart().date() == dtEnd().date()); | 155 | bool multi = !(dtStart().date() == dtEnd().date()); |
110 | return multi; | 156 | return multi; |
111 | } | 157 | } |
112 | 158 | ||
113 | void Event::setTransparency(Event::Transparency transparency) | 159 | void Event::setTransparency(Event::Transparency transparency) |
114 | { | 160 | { |
115 | if (mReadOnly) return; | 161 | if (mReadOnly) return; |
116 | mTransparency = transparency; | 162 | mTransparency = transparency; |
117 | updated(); | 163 | updated(); |
118 | } | 164 | } |
119 | 165 | ||
120 | Event::Transparency Event::transparency() const | 166 | Event::Transparency Event::transparency() const |
121 | { | 167 | { |
122 | return mTransparency; | 168 | return mTransparency; |
123 | } | 169 | } |
124 | 170 | ||
125 | void Event::setDuration(int seconds) | 171 | void Event::setDuration(int seconds) |
126 | { | 172 | { |
127 | setHasEndDate(false); | 173 | setHasEndDate(false); |
128 | Incidence::setDuration(seconds); | 174 | Incidence::setDuration(seconds); |
129 | } | 175 | } |
130 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const | 176 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const |
131 | { | 177 | { |
132 | 178 | ||
133 | bool yes; | 179 | bool yes; |
134 | QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes ); | 180 | QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes ); |
135 | if ( ! yes || cancelled() ) { | 181 | if ( ! yes || cancelled() ) { |
136 | *ok = false; | 182 | *ok = false; |
137 | return QDateTime (); | 183 | return QDateTime (); |
138 | } | 184 | } |
139 | 185 | ||
140 | bool enabled = false; | 186 | bool enabled = false; |
141 | Alarm* alarm; | 187 | Alarm* alarm; |
142 | int off; | 188 | int off; |
143 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 189 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
144 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 190 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
145 | // *ok = false; | 191 | // *ok = false; |
146 | // return incidenceStart; | 192 | // return incidenceStart; |
147 | // } | 193 | // } |
148 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 194 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
149 | if (alarm->enabled()) { | 195 | if (alarm->enabled()) { |
150 | if ( alarm->hasTime () ) { | 196 | if ( alarm->hasTime () ) { |
151 | if ( alarm->time() < alarmStart ) { | 197 | if ( alarm->time() < alarmStart ) { |
152 | alarmStart = alarm->time(); | 198 | alarmStart = alarm->time(); |
153 | enabled = true; | 199 | enabled = true; |
154 | off = alarmStart.secsTo( incidenceStart ); | 200 | off = alarmStart.secsTo( incidenceStart ); |
155 | } | 201 | } |
156 | 202 | ||
157 | } else { | 203 | } else { |
158 | int secs = alarm->startOffset().asSeconds(); | 204 | int secs = alarm->startOffset().asSeconds(); |
159 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 205 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
160 | alarmStart = incidenceStart.addSecs( secs ); | 206 | alarmStart = incidenceStart.addSecs( secs ); |
161 | enabled = true; | 207 | enabled = true; |
162 | off = -secs; | 208 | off = -secs; |
163 | } | 209 | } |
164 | } | 210 | } |
165 | } | 211 | } |
166 | } | 212 | } |
167 | if ( enabled ) { | 213 | if ( enabled ) { |
168 | if ( alarmStart > QDateTime::currentDateTime() ) { | 214 | if ( alarmStart > QDateTime::currentDateTime() ) { |
169 | *ok = true; | 215 | *ok = true; |
170 | * offset = off; | 216 | * offset = off; |
171 | return alarmStart; | 217 | return alarmStart; |
172 | } | 218 | } |
173 | } | 219 | } |
174 | *ok = false; | 220 | *ok = false; |
175 | return QDateTime (); | 221 | return QDateTime (); |
176 | 222 | ||
177 | } | 223 | } |