• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KCal Library

event.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of the kcal library.
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 */
00032 #include "event.h"
00033 
00034 #include <kglobal.h>
00035 #include <klocale.h>
00036 #include <kdebug.h>
00037 #include <ksystemtimezone.h>
00038 
00039 using namespace KCal;
00040 
00045 //@cond PRIVATE
00046 class KCal::Event::Private
00047 {
00048   public:
00049     Private()
00050       : mHasEndDate( false ),
00051         mTransparency( Opaque )
00052     {}
00053     Private( const KCal::Event::Private &other )
00054       : mDtEnd( other.mDtEnd ),
00055         mHasEndDate( other.mHasEndDate ),
00056         mTransparency( other.mTransparency )
00057     {}
00058 
00059     KDateTime mDtEnd;
00060     bool mHasEndDate;
00061     Transparency mTransparency;
00062 };
00063 //@endcond
00064 
00065 Event::Event()
00066   : d( new KCal::Event::Private )
00067 {
00068 }
00069 
00070 Event::Event( const Event &other )
00071   : Incidence( other ), d( new KCal::Event::Private( *other.d ) )
00072 {
00073 }
00074 
00075 Event::~Event()
00076 {
00077   delete d;
00078 }
00079 
00080 Event *Event::clone()
00081 {
00082   return new Event( *this );
00083 }
00084 
00085 Event &Event::operator=( const Event &other )
00086 {
00087   Incidence::operator=( other );
00088   *d = *other.d;
00089   return *this;
00090 }
00091 
00092 bool Event::operator==( const Event &event ) const
00093 {
00094   return
00095     static_cast<const Incidence &>( *this ) == static_cast<const Incidence &>( event ) &&
00096     dtEnd() == event.dtEnd() &&
00097     hasEndDate() == event.hasEndDate() &&
00098     transparency() == event.transparency();
00099 }
00100 
00101 QByteArray Event::type() const
00102 {
00103   return "Event";
00104 }
00105 
00106 void Event::setDtEnd( const KDateTime &dtEnd )
00107 {
00108   if ( mReadOnly ) {
00109     return;
00110   }
00111 
00112   d->mDtEnd = dtEnd;
00113   setHasEndDate( true );
00114   setHasDuration( false );
00115 
00116   updated();
00117 }
00118 
00119 KDateTime Event::dtEnd() const
00120 {
00121   if ( hasEndDate() ) {
00122     return d->mDtEnd;
00123   }
00124   if ( hasDuration() ) {
00125     return duration().end( dtStart() );
00126   }
00127 
00128   kDebug() << "Warning! Event '" << summary()
00129            << "' has neither end date nor duration.";
00130   return dtStart();
00131 }
00132 
00133 QDate Event::dateEnd() const
00134 {
00135   KDateTime end = dtEnd().toTimeSpec( dtStart() );
00136   if ( allDay() ) {
00137     return end.date();
00138   } else {
00139     return end.addSecs(-1).date();
00140   }
00141 }
00142 
00143 QString Event::dtEndTimeStr( bool shortfmt, const KDateTime::Spec &spec ) const
00144 {
00145   if ( spec.isValid() ) {
00146 
00147     QString timeZone;
00148     if ( spec.timeZone() != KSystemTimeZones::local() ) {
00149       timeZone = ' ' + spec.timeZone().name();
00150     }
00151 
00152     return KGlobal::locale()->formatTime( dtEnd().toTimeSpec( spec ).time(), shortfmt )
00153       + timeZone;
00154   } else {
00155     return KGlobal::locale()->formatTime( dtEnd().time(), shortfmt );
00156   }
00157 }
00158 
00159 QString Event::dtEndDateStr( bool shortfmt, const KDateTime::Spec &spec ) const
00160 {
00161   if ( spec.isValid() ) {
00162 
00163     QString timeZone;
00164     if ( spec.timeZone() != KSystemTimeZones::local() ) {
00165       timeZone = ' ' + spec.timeZone().name();
00166     }
00167 
00168     return KGlobal::locale()->formatDate(
00169       dtEnd().toTimeSpec( spec ).date(),
00170       ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) )
00171       + timeZone;
00172   } else {
00173     return KGlobal::locale()->formatDate(
00174       dtEnd().date(),
00175       ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00176   }
00177 }
00178 
00179 QString Event::dtEndStr( bool shortfmt, const KDateTime::Spec &spec ) const
00180 {
00181   if ( allDay() ) {
00182     return dtEndDateStr( shortfmt, spec );
00183   }
00184 
00185   if ( spec.isValid() ) {
00186 
00187     QString timeZone;
00188     if ( spec.timeZone() != KSystemTimeZones::local() ) {
00189       timeZone = ' ' + spec.timeZone().name();
00190     }
00191 
00192     return KGlobal::locale()->formatDateTime(
00193       dtEnd().toTimeSpec( spec ).dateTime(),
00194       ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) )
00195       + timeZone;
00196   } else {
00197     return KGlobal::locale()->formatDateTime(
00198       dtEnd().dateTime(),
00199       ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00200   }
00201 }
00202 
00203 void Event::setHasEndDate( bool b )
00204 {
00205   d->mHasEndDate = b;
00206 }
00207 
00208 bool Event::hasEndDate() const
00209 {
00210   return d->mHasEndDate;
00211 }
00212 
00213 bool Event::isMultiDay( const KDateTime::Spec &spec ) const
00214 {
00215   // End date is non inclusive, so subtract 1 second...
00216   KDateTime start, end;
00217   if ( spec.isValid() ) {
00218     start = dtStart().toTimeSpec( spec );
00219     end = dtEnd().toTimeSpec( spec );
00220   } else {
00221     start = dtStart();
00222     end = dtEnd();
00223   }
00224 
00225   if ( !allDay() ) {
00226     end = end.addSecs( -1 );
00227   }
00228 
00229   bool multi = ( start.date() != end.date() && start <= end );
00230   return multi;
00231 }
00232 
00233 void Event::shiftTimes( const KDateTime::Spec &oldSpec,
00234                         const KDateTime::Spec &newSpec )
00235 {
00236   Incidence::shiftTimes( oldSpec, newSpec );
00237   if ( hasEndDate() ) {
00238     d->mDtEnd = d->mDtEnd.toTimeSpec( oldSpec );
00239     d->mDtEnd.setTimeSpec( newSpec );
00240   }
00241 }
00242 
00243 void Event::setTransparency( Event::Transparency transparency )
00244 {
00245   if ( mReadOnly ) {
00246     return;
00247   }
00248   d->mTransparency = transparency;
00249   updated();
00250 }
00251 
00252 Event::Transparency Event::transparency() const
00253 {
00254   return d->mTransparency;
00255 }
00256 
00257 void Event::setDuration( const Duration &duration )
00258 {
00259   setHasEndDate( false );
00260   Incidence::setDuration( duration );
00261 }
00262 
00263 KDateTime Event::endDateRecurrenceBase() const
00264 {
00265   return dtEnd();
00266 }

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal