libkcal

event.cpp
1 /*
2  This file is part of libkcal.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include <tdeglobal.h>
23 #include <tdelocale.h>
24 #include <kdebug.h>
25 
26 #include "event.h"
27 
28 using namespace KCal;
29 
30 Event::Event() :
31  mHasEndDate( false ), mTransparency( Opaque )
32 {
33 }
34 
35 Event::Event(const Event &e) : Incidence(e)
36 {
37  mDtEnd = e.mDtEnd;
38  mHasEndDate = e.mHasEndDate;
39  mTransparency = e.mTransparency;
40 }
41 
42 Event::~Event()
43 {
44 // kdDebug(5800) << "~Event() " << int( this ) << endl;
45 }
46 
48 {
49 // kdDebug(5800) << "Event::clone()" << endl;
50  return new Event(*this);
51 }
52 
53 Event& Event::operator=( const Event &e )
54 {
55  Incidence::operator=( e );
56  mDtEnd = e.mDtEnd;
57  mHasEndDate = e.mHasEndDate;
58  mTransparency = e.mTransparency;
59  return *this;
60 }
61 
62 bool Event::operator==( const Event& e2 ) const
63 {
64  return
65  static_cast<const Incidence&>(*this) == static_cast<const Incidence&>(e2) &&
66  dtEnd() == e2.dtEnd() &&
67  hasEndDate() == e2.hasEndDate() &&
68  transparency() == e2.transparency();
69 }
70 
71 
72 
73 void Event::setDtEnd(const TQDateTime &dtEnd)
74 {
75  if (mReadOnly) return;
76 
77  mDtEnd = dtEnd;
78 
79  setHasEndDate(true);
80  setHasDuration(false);
81 
82  updated();
83 }
84 
85 TQDateTime Event::dtEnd() const
86 {
87  if (hasEndDate()) return mDtEnd;
88  if (hasDuration()) return dtStart().addSecs(duration());
89 
90  // It is valid for a VEVENT to be without a DTEND. See RFC2445, Sect4.6.1.
91  // Be careful to use Event::dateEnd() as appropriate due to this possibility.
92  return dtStart();
93 }
94 
95 TQDate Event::dateEnd() const
96 {
97  if ( doesFloat() ) return dtEnd().date();
98  else return dtEnd().addSecs(-1).date();
99 }
100 
101 TQString Event::dtEndTimeStr() const
102 {
103  return TDEGlobal::locale()->formatTime(dtEnd().time());
104 }
105 
106 TQString Event::dtEndDateStr(bool shortfmt) const
107 {
108  return TDEGlobal::locale()->formatDate(dtEnd().date(),shortfmt);
109 }
110 
111 TQString Event::dtEndStr() const
112 {
113  return TDEGlobal::locale()->formatDateTime(dtEnd());
114 }
115 
117 {
118  mHasEndDate = b;
119 }
120 
121 bool Event::hasEndDate() const
122 {
123  return mHasEndDate;
124 }
125 
126 bool Event::isMultiDay() const
127 {
128  // End date is non inclusive, so subtract 1 second...
129  TQDateTime start( dtStart() );
130  TQDateTime end( dtEnd() );
131  if ( ! doesFloat() ) {
132  end = end.addSecs(-1);
133  }
134  bool multi = ( start.date() != end.date() && start <= end );
135  return multi;
136 }
137 
139 {
140  if (mReadOnly) return;
141  mTransparency = transparency;
142  updated();
143 }
144 
146 {
147  return mTransparency;
148 }
149 
150 void Event::setDuration(int seconds)
151 {
152  setHasEndDate(false);
153  Incidence::setDuration(seconds);
154 }
This class provides an Event in the sense of RFC2445.
Definition: event.h:33
TQString TDE_DEPRECATED dtEndStr() const
Return end date and time as string formatted according to the users locale settings.
Definition: event.cpp:111
void setHasEndDate(bool)
Set whether the event has an end date/time.
Definition: event.cpp:116
TQString TDE_DEPRECATED dtEndDateStr(bool shortfmt=true) const
Return end date as string formatted according to the users locale settings.
Definition: event.cpp:106
void setTransparency(Transparency transparency)
Set the event's time transparency level.
Definition: event.cpp:138
virtual TQDateTime dtEnd() const
Return end date and time.
Definition: event.cpp:85
void setDtEnd(const TQDateTime &dtEnd)
Set end date and time.
Definition: event.cpp:73
bool isMultiDay() const
Return true if the event spans multiple days, otherwise return false.
Definition: event.cpp:126
Transparency transparency() const
Return the event's time transparency level.
Definition: event.cpp:145
Transparency
Transparency of event.
Definition: event.h:41
Event * clone()
Return copy of this Event.
Definition: event.cpp:47
TQString TDE_DEPRECATED dtEndTimeStr() const
Return end time as string formatted according to the users locale settings.
Definition: event.cpp:101
void setDuration(int seconds)
Set duration of this event.
Definition: event.cpp:150
bool hasEndDate() const
Return whether the event has an end date/time.
Definition: event.cpp:121
TQDate dateEnd() const
Returns the day when the event ends.
Definition: event.cpp:95
void updated()
Call this to notify the observers after the IncidenceBas object has changed.
bool doesFloat() const
Return true or false depending on whether the incidence "floats," i.e.
virtual TQDateTime dtStart() const
returns an event's starting date/time as a TQDateTime.
This class provides the base class common to all calendar components.
Definition: incidence.h:48
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38