summaryrefslogtreecommitdiffabout
path: root/libkcal/event.cpp
Unidiff
Diffstat (limited to 'libkcal/event.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/event.cpp1
1 files changed, 0 insertions, 1 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index dd67252..dfa265b 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -1,178 +1,177 @@
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
27using namespace KCal; 27using namespace KCal;
28 28
29Event::Event() : 29Event::Event() :
30 mHasEndDate( false ), mTransparency( Opaque ) 30 mHasEndDate( false ), mTransparency( Opaque )
31{ 31{
32} 32}
33 33
34Event::Event(const Event &e) : Incidence(e) 34Event::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
41Event::~Event() 41Event::~Event()
42{ 42{
43} 43}
44 44
45Incidence *Event::clone() 45Incidence *Event::clone()
46{ 46{
47 kdDebug(5800) << "Event::clone()" << endl;
48 return new Event(*this); 47 return new Event(*this);
49} 48}
50 49
51bool KCal::operator==( const Event& e1, const Event& e2 ) 50bool KCal::operator==( const Event& e1, const Event& e2 )
52{ 51{
53 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && 52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) &&
54 e1.dtEnd() == e2.dtEnd() && 53 e1.dtEnd() == e2.dtEnd() &&
55 e1.hasEndDate() == e2.hasEndDate() && 54 e1.hasEndDate() == e2.hasEndDate() &&
56 e1.transparency() == e2.transparency(); 55 e1.transparency() == e2.transparency();
57} 56}
58 57
59 58
60 59
61void Event::setDtEnd(const QDateTime &dtEnd) 60void Event::setDtEnd(const QDateTime &dtEnd)
62{ 61{
63 if (mReadOnly) return; 62 if (mReadOnly) return;
64 63
65 mDtEnd = getEvenTime( dtEnd ); 64 mDtEnd = getEvenTime( dtEnd );
66 65
67 setHasEndDate(true); 66 setHasEndDate(true);
68 setHasDuration(false); 67 setHasDuration(false);
69 68
70 updated(); 69 updated();
71} 70}
72 71
73QDateTime Event::dtEnd() const 72QDateTime Event::dtEnd() const
74{ 73{
75 if (hasEndDate()) return mDtEnd; 74 if (hasEndDate()) return mDtEnd;
76 if (hasDuration()) return dtStart().addSecs(duration()); 75 if (hasDuration()) return dtStart().addSecs(duration());
77 76
78 kdDebug(5800) << "Warning! Event '" << summary() 77 kdDebug(5800) << "Warning! Event '" << summary()
79 << "' does have neither end date nor duration." << endl; 78 << "' does have neither end date nor duration." << endl;
80 return dtStart(); 79 return dtStart();
81} 80}
82 81
83QString Event::dtEndTimeStr() const 82QString Event::dtEndTimeStr() const
84{ 83{
85 return KGlobal::locale()->formatTime(mDtEnd.time()); 84 return KGlobal::locale()->formatTime(mDtEnd.time());
86} 85}
87 86
88QString Event::dtEndDateStr(bool shortfmt) const 87QString Event::dtEndDateStr(bool shortfmt) const
89{ 88{
90 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); 89 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt);
91} 90}
92 91
93QString Event::dtEndStr(bool shortfmt) const 92QString Event::dtEndStr(bool shortfmt) const
94{ 93{
95 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); 94 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt);
96} 95}
97 96
98void Event::setHasEndDate(bool b) 97void Event::setHasEndDate(bool b)
99{ 98{
100 mHasEndDate = b; 99 mHasEndDate = b;
101} 100}
102 101
103bool Event::hasEndDate() const 102bool Event::hasEndDate() const
104{ 103{
105 return mHasEndDate; 104 return mHasEndDate;
106} 105}
107 106
108bool Event::isMultiDay() const 107bool Event::isMultiDay() const
109{ 108{
110 bool multi = !(dtStart().date() == dtEnd().date()); 109 bool multi = !(dtStart().date() == dtEnd().date());
111 return multi; 110 return multi;
112} 111}
113 112
114void Event::setTransparency(Event::Transparency transparency) 113void Event::setTransparency(Event::Transparency transparency)
115{ 114{
116 if (mReadOnly) return; 115 if (mReadOnly) return;
117 mTransparency = transparency; 116 mTransparency = transparency;
118 updated(); 117 updated();
119} 118}
120 119
121Event::Transparency Event::transparency() const 120Event::Transparency Event::transparency() const
122{ 121{
123 return mTransparency; 122 return mTransparency;
124} 123}
125 124
126void Event::setDuration(int seconds) 125void Event::setDuration(int seconds)
127{ 126{
128 setHasEndDate(false); 127 setHasEndDate(false);
129 Incidence::setDuration(seconds); 128 Incidence::setDuration(seconds);
130} 129}
131QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const 130QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const
132{ 131{
133 132
134 bool yes; 133 bool yes;
135 QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes ); 134 QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes );
136 if ( ! yes || cancelled() ) { 135 if ( ! yes || cancelled() ) {
137 *ok = false; 136 *ok = false;
138 return QDateTime (); 137 return QDateTime ();
139 } 138 }
140 139
141 bool enabled = false; 140 bool enabled = false;
142 Alarm* alarm; 141 Alarm* alarm;
143 int off; 142 int off;
144 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 143 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
145 // if ( QDateTime::currentDateTime() > incidenceStart ){ 144 // if ( QDateTime::currentDateTime() > incidenceStart ){
146// *ok = false; 145// *ok = false;
147// return incidenceStart; 146// return incidenceStart;
148// } 147// }
149 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 148 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
150 if (alarm->enabled()) { 149 if (alarm->enabled()) {
151 if ( alarm->hasTime () ) { 150 if ( alarm->hasTime () ) {
152 if ( alarm->time() < alarmStart ) { 151 if ( alarm->time() < alarmStart ) {
153 alarmStart = alarm->time(); 152 alarmStart = alarm->time();
154 enabled = true; 153 enabled = true;
155 off = alarmStart.secsTo( incidenceStart ); 154 off = alarmStart.secsTo( incidenceStart );
156 } 155 }
157 156
158 } else { 157 } else {
159 int secs = alarm->startOffset().asSeconds(); 158 int secs = alarm->startOffset().asSeconds();
160 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 159 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
161 alarmStart = incidenceStart.addSecs( secs ); 160 alarmStart = incidenceStart.addSecs( secs );
162 enabled = true; 161 enabled = true;
163 off = -secs; 162 off = -secs;
164 } 163 }
165 } 164 }
166 } 165 }
167 } 166 }
168 if ( enabled ) { 167 if ( enabled ) {
169 if ( alarmStart > QDateTime::currentDateTime() ) { 168 if ( alarmStart > QDateTime::currentDateTime() ) {
170 *ok = true; 169 *ok = true;
171 * offset = off; 170 * offset = off;
172 return alarmStart; 171 return alarmStart;
173 } 172 }
174 } 173 }
175 *ok = false; 174 *ok = false;
176 return QDateTime (); 175 return QDateTime ();
177 176
178} 177}