libkcal
event.cpp
Go to the documentation of this file.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 Event& Event::operator=( const Event &e ) 00054 { 00055 Incidence::operator=( e ); 00056 mDtEnd = e.mDtEnd; 00057 mHasEndDate = e.mHasEndDate; 00058 mTransparency = e.mTransparency; 00059 return *this; 00060 } 00061 00062 bool Event::operator==( const Event& e2 ) const 00063 { 00064 return 00065 static_cast<const Incidence&>(*this) == static_cast<const Incidence&>(e2) && 00066 dtEnd() == e2.dtEnd() && 00067 hasEndDate() == e2.hasEndDate() && 00068 transparency() == e2.transparency(); 00069 } 00070 00071 00072 00073 void Event::setDtEnd(const QDateTime &dtEnd) 00074 { 00075 if (mReadOnly) return; 00076 00077 mDtEnd = dtEnd; 00078 00079 setHasEndDate(true); 00080 setHasDuration(false); 00081 00082 updated(); 00083 } 00084 00085 QDateTime Event::dtEnd() const 00086 { 00087 if (hasEndDate()) return mDtEnd; 00088 if (hasDuration()) return dtStart().addSecs(duration()); 00089 00090 kdDebug(5800) << "Warning! Event '" << summary() 00091 << "' has neither end date nor duration." << endl; 00092 return dtStart(); 00093 } 00094 00095 QDate Event::dateEnd() const 00096 { 00097 if ( doesFloat() ) return dtEnd().date(); 00098 else return dtEnd().addSecs(-1).date(); 00099 } 00100 00101 QString Event::dtEndTimeStr() const 00102 { 00103 return KGlobal::locale()->formatTime(dtEnd().time()); 00104 } 00105 00106 QString Event::dtEndDateStr(bool shortfmt) const 00107 { 00108 return KGlobal::locale()->formatDate(dtEnd().date(),shortfmt); 00109 } 00110 00111 QString Event::dtEndStr() const 00112 { 00113 return KGlobal::locale()->formatDateTime(dtEnd()); 00114 } 00115 00116 void Event::setHasEndDate(bool b) 00117 { 00118 mHasEndDate = b; 00119 } 00120 00121 bool Event::hasEndDate() const 00122 { 00123 return mHasEndDate; 00124 } 00125 00126 bool Event::isMultiDay() const 00127 { 00128 // End date is non inclusive, so subtract 1 second... 00129 QDateTime start( dtStart() ); 00130 QDateTime end( dtEnd() ); 00131 if ( ! doesFloat() ) { 00132 end = end.addSecs(-1); 00133 } 00134 bool multi = ( start.date() != end.date() && start <= end ); 00135 return multi; 00136 } 00137 00138 void Event::setTransparency(Event::Transparency transparency) 00139 { 00140 if (mReadOnly) return; 00141 mTransparency = transparency; 00142 updated(); 00143 } 00144 00145 Event::Transparency Event::transparency() const 00146 { 00147 return mTransparency; 00148 } 00149 00150 void Event::setDuration(int seconds) 00151 { 00152 setHasEndDate(false); 00153 Incidence::setDuration(seconds); 00154 }