summaryrefslogtreecommitdiffabout
path: root/libkcal/event.cpp
Unidiff
Diffstat (limited to 'libkcal/event.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/event.cpp46
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,122 +1,168 @@
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 return new Event(*this); 47 return new Event(*this);
48} 48}
49 49
50bool KCal::operator==( const Event& e1, const Event& e2 ) 50bool 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
59bool 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
60void Event::setDtEnd(const QDateTime &dtEnd) 106void 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
72QDateTime Event::dtEnd() const 118QDateTime 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
82QString Event::dtEndTimeStr() const 128QString Event::dtEndTimeStr() const
83{ 129{
84 return KGlobal::locale()->formatTime(mDtEnd.time()); 130 return KGlobal::locale()->formatTime(mDtEnd.time());
85} 131}
86 132
87QString Event::dtEndDateStr(bool shortfmt) const 133QString 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
92QString Event::dtEndStr(bool shortfmt) const 138QString 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
97void Event::setHasEndDate(bool b) 143void Event::setHasEndDate(bool b)
98{ 144{
99 mHasEndDate = b; 145 mHasEndDate = b;
100} 146}
101 147
102bool Event::hasEndDate() const 148bool Event::hasEndDate() const
103{ 149{
104 return mHasEndDate; 150 return mHasEndDate;
105} 151}
106 152
107bool Event::isMultiDay() const 153bool 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
113void Event::setTransparency(Event::Transparency transparency) 159void 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
120Event::Transparency Event::transparency() const 166Event::Transparency Event::transparency() const
121{ 167{
122 return mTransparency; 168 return mTransparency;