author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libkcal/event.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
-rw-r--r-- | libkcal/event.cpp | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp new file mode 100644 index 0000000..dd67252 --- a/dev/null +++ b/libkcal/event.cpp | |||
@@ -0,0 +1,178 @@ | |||
1 | /* | ||
2 | This file is part of libkcal. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | #include <kglobal.h> | ||
22 | #include <klocale.h> | ||
23 | #include <kdebug.h> | ||
24 | |||
25 | #include "event.h" | ||
26 | |||
27 | using namespace KCal; | ||
28 | |||
29 | Event::Event() : | ||
30 | mHasEndDate( false ), mTransparency( Opaque ) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | Event::Event(const Event &e) : Incidence(e) | ||
35 | { | ||
36 | mDtEnd = e.mDtEnd; | ||
37 | mHasEndDate = e.mHasEndDate; | ||
38 | mTransparency = e.mTransparency; | ||
39 | } | ||
40 | |||
41 | Event::~Event() | ||
42 | { | ||
43 | } | ||
44 | |||
45 | Incidence *Event::clone() | ||
46 | { | ||
47 | kdDebug(5800) << "Event::clone()" << endl; | ||
48 | return new Event(*this); | ||
49 | } | ||
50 | |||
51 | bool KCal::operator==( const Event& e1, const Event& e2 ) | ||
52 | { | ||
53 | return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && | ||
54 | e1.dtEnd() == e2.dtEnd() && | ||
55 | e1.hasEndDate() == e2.hasEndDate() && | ||
56 | e1.transparency() == e2.transparency(); | ||
57 | } | ||
58 | |||
59 | |||
60 | |||
61 | void Event::setDtEnd(const QDateTime &dtEnd) | ||
62 | { | ||
63 | if (mReadOnly) return; | ||
64 | |||
65 | mDtEnd = getEvenTime( dtEnd ); | ||
66 | |||
67 | setHasEndDate(true); | ||
68 | setHasDuration(false); | ||
69 | |||
70 | updated(); | ||
71 | } | ||
72 | |||
73 | QDateTime Event::dtEnd() const | ||
74 | { | ||
75 | if (hasEndDate()) return mDtEnd; | ||
76 | if (hasDuration()) return dtStart().addSecs(duration()); | ||
77 | |||
78 | kdDebug(5800) << "Warning! Event '" << summary() | ||
79 | << "' does have neither end date nor duration." << endl; | ||
80 | return dtStart(); | ||
81 | } | ||
82 | |||
83 | QString Event::dtEndTimeStr() const | ||
84 | { | ||
85 | return KGlobal::locale()->formatTime(mDtEnd.time()); | ||
86 | } | ||
87 | |||
88 | QString Event::dtEndDateStr(bool shortfmt) const | ||
89 | { | ||
90 | return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); | ||
91 | } | ||
92 | |||
93 | QString Event::dtEndStr(bool shortfmt) const | ||
94 | { | ||
95 | return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); | ||
96 | } | ||
97 | |||
98 | void Event::setHasEndDate(bool b) | ||
99 | { | ||
100 | mHasEndDate = b; | ||
101 | } | ||
102 | |||
103 | bool Event::hasEndDate() const | ||
104 | { | ||
105 | return mHasEndDate; | ||
106 | } | ||
107 | |||
108 | bool Event::isMultiDay() const | ||
109 | { | ||
110 | bool multi = !(dtStart().date() == dtEnd().date()); | ||
111 | return multi; | ||
112 | } | ||
113 | |||
114 | void Event::setTransparency(Event::Transparency transparency) | ||
115 | { | ||
116 | if (mReadOnly) return; | ||
117 | mTransparency = transparency; | ||
118 | updated(); | ||
119 | } | ||
120 | |||
121 | Event::Transparency Event::transparency() const | ||
122 | { | ||
123 | return mTransparency; | ||
124 | } | ||
125 | |||
126 | void Event::setDuration(int seconds) | ||
127 | { | ||
128 | setHasEndDate(false); | ||
129 | Incidence::setDuration(seconds); | ||
130 | } | ||
131 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset ) const | ||
132 | { | ||
133 | |||
134 | bool yes; | ||
135 | QDateTime incidenceStart = getNextOccurence( QDateTime::currentDateTime(), &yes ); | ||
136 | if ( ! yes || cancelled() ) { | ||
137 | *ok = false; | ||
138 | return QDateTime (); | ||
139 | } | ||
140 | |||
141 | bool enabled = false; | ||
142 | Alarm* alarm; | ||
143 | int off; | ||
144 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | ||
145 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | ||
146 | // *ok = false; | ||
147 | // return incidenceStart; | ||
148 | // } | ||
149 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | ||
150 | if (alarm->enabled()) { | ||
151 | if ( alarm->hasTime () ) { | ||
152 | if ( alarm->time() < alarmStart ) { | ||
153 | alarmStart = alarm->time(); | ||
154 | enabled = true; | ||
155 | off = alarmStart.secsTo( incidenceStart ); | ||
156 | } | ||
157 | |||
158 | } else { | ||
159 | int secs = alarm->startOffset().asSeconds(); | ||
160 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | ||
161 | alarmStart = incidenceStart.addSecs( secs ); | ||
162 | enabled = true; | ||
163 | off = -secs; | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | if ( enabled ) { | ||
169 | if ( alarmStart > QDateTime::currentDateTime() ) { | ||
170 | *ok = true; | ||
171 | * offset = off; | ||
172 | return alarmStart; | ||
173 | } | ||
174 | } | ||
175 | *ok = false; | ||
176 | return QDateTime (); | ||
177 | |||
178 | } | ||