libkcal
event.cpp
00001 /* 00002 This file is part of libkcal. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include <kglobal.h> 00023 #include <klocale.h> 00024 #include <kdebug.h> 00025 00026 #include "event.h" 00027 00028 using namespace KCal; 00029 00030 Event::Event() : 00031 mHasEndDate( false ), mTransparency( Opaque ) 00032 { 00033 } 00034 00035 Event::Event(const Event &e) : Incidence(e) 00036 { 00037 mDtEnd = e.mDtEnd; 00038 mHasEndDate = e.mHasEndDate; 00039 mTransparency = e.mTransparency; 00040 } 00041 00042 Event::~Event() 00043 { 00044 // kdDebug(5800) << "~Event() " << int( this ) << endl; 00045 } 00046 00047 Event *Event::clone() 00048 { 00049 // kdDebug(5800) << "Event::clone()" << endl; 00050 return new Event(*this); 00051 } 00052 00053 bool Event::operator==( const Event& e2 ) const 00054 { 00055 return 00056 static_cast<const Incidence&>(*this) == static_cast<const Incidence&>(e2) && 00057 dtEnd() == e2.dtEnd() && 00058 hasEndDate() == e2.hasEndDate() && 00059 transparency() == e2.transparency(); 00060 } 00061 00062 00063 00064 void Event::setDtEnd(const QDateTime &dtEnd) 00065 { 00066 if (mReadOnly) return; 00067 00068 mDtEnd = dtEnd; 00069 00070 setHasEndDate(true); 00071 setHasDuration(false); 00072 00073 updated(); 00074 } 00075 00076 QDateTime Event::dtEnd() const 00077 { 00078 if (hasEndDate()) return mDtEnd; 00079 if (hasDuration()) return dtStart().addSecs(duration()); 00080 00081 kdDebug(5800) << "Warning! Event '" << summary() 00082 << "' has neither end date nor duration." << endl; 00083 return dtStart(); 00084 } 00085 00086 QDate Event::dateEnd() const 00087 { 00088 if ( doesFloat() ) return dtEnd().date(); 00089 else return dtEnd().addSecs(-1).date(); 00090 } 00091 00092 QString Event::dtEndTimeStr() const 00093 { 00094 return KGlobal::locale()->formatTime(dtEnd().time()); 00095 } 00096 00097 QString Event::dtEndDateStr(bool shortfmt) const 00098 { 00099 return KGlobal::locale()->formatDate(dtEnd().date(),shortfmt); 00100 } 00101 00102 QString Event::dtEndStr() const 00103 { 00104 return KGlobal::locale()->formatDateTime(dtEnd()); 00105 } 00106 00107 void Event::setHasEndDate(bool b) 00108 { 00109 mHasEndDate = b; 00110 } 00111 00112 bool Event::hasEndDate() const 00113 { 00114 return mHasEndDate; 00115 } 00116 00117 bool Event::isMultiDay() const 00118 { 00119 // End date is non inclusive, so subtract 1 second... 00120 QDateTime start( dtStart() ); 00121 QDateTime end( dtEnd() ); 00122 if ( ! doesFloat() ) { 00123 end = end.addSecs(-1); 00124 } 00125 bool multi = ( start.date() != end.date() && start <= end ); 00126 return multi; 00127 } 00128 00129 void Event::setTransparency(Event::Transparency transparency) 00130 { 00131 if (mReadOnly) return; 00132 mTransparency = transparency; 00133 updated(); 00134 } 00135 00136 Event::Transparency Event::transparency() const 00137 { 00138 return mTransparency; 00139 } 00140 00141 void Event::setDuration(int seconds) 00142 { 00143 setHasEndDate(false); 00144 Incidence::setDuration(seconds); 00145 }