• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • Contact Us
 

KAlarm Library

repetition.cpp
00001 /*
00002  *  repetition.cpp  -  represents a sub-repetition: interval and count
00003  *  This file is part of kalarmcal library, which provides access to KAlarm
00004  *  calendar data.
00005  *  Copyright © 2009-2012 by David Jarvie <djarvie@kde.org>
00006  *
00007  *  This library is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU Library General Public License as published
00009  *  by the Free Software Foundation; either version 2 of the License, or (at
00010  *  your option) any later version.
00011  *
00012  *  This library is distributed in the hope that it will be useful, but WITHOUT
00013  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015  *  License for more details.
00016  *
00017  *  You should have received a copy of the GNU Library General Public License
00018  *  along with this library; see the file COPYING.LIB.  If not, write to the
00019  *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00020  *  MA 02110-1301, USA.
00021  */
00022 
00023 #include "repetition.h"
00024 #include <kdatetime.h>
00025 
00026 #ifndef KALARMCAL_USE_KRESOURCES
00027 using namespace KCalCore;
00028 #else
00029 using namespace KCal;
00030 #endif
00031 
00032 namespace KAlarmCal
00033 {
00034 
00035 class Repetition::Private
00036 {
00037     public:
00038         Private() : mInterval(0), mCount(0) {}
00039         Private(const Duration& interval, int count)
00040             : mInterval(interval), mCount(count)
00041         {
00042             if ((!count && interval) || (count && !interval))
00043             {
00044                 mCount = 0;
00045                 mInterval = 0;
00046             }
00047         }
00048 
00049         Duration mInterval;   // sub-repetition interval
00050         int      mCount;      // sub-repetition count (excluding the first time)
00051 };
00052 
00053 
00054 Repetition::Repetition()
00055     : d(new Private)
00056 {
00057 }
00058 
00059 Repetition::Repetition(const Duration& interval, int count)
00060     : d(new Private(interval, count))
00061 {
00062 }
00063 
00064 Repetition::Repetition(const Repetition& other)
00065     : d(new Private(*other.d))
00066 {
00067 }
00068 
00069 Repetition::~Repetition()
00070 {
00071     delete d;
00072 }
00073 
00074 Repetition& Repetition::operator=(const Repetition& other)
00075 {
00076     if (&other != this)
00077         *d = *other.d;
00078     return *this;
00079 }
00080 
00081 void Repetition::set(const Duration& interval, int count)
00082 {
00083     if (!count || !interval)
00084     {
00085         d->mCount = 0;
00086         d->mInterval = 0;
00087     }
00088     else
00089     {
00090         d->mCount = count;
00091         d->mInterval = interval;
00092     }
00093 }
00094 
00095 void Repetition::set(const Duration& interval)
00096 {
00097     if (d->mCount)
00098     {
00099         d->mInterval = interval;
00100         if (!interval)
00101             d->mCount = 0;
00102     }
00103 }
00104 
00105 Repetition::operator bool() const
00106 {
00107     return d->mCount;
00108 }
00109 
00110 bool Repetition::operator==(const Repetition& r) const  
00111 {
00112     return d->mInterval == r.d->mInterval && d->mCount == r.d->mCount;
00113 }
00114 
00115 int Repetition::count() const
00116 {
00117     return d->mCount;
00118 }
00119 
00120 Duration Repetition::interval() const
00121 {
00122     return d->mInterval;
00123 }
00124 
00125 Duration Repetition::duration() const
00126 {
00127     return d->mInterval * d->mCount;
00128 }
00129 
00130 Duration Repetition::duration(int count) const
00131 {
00132     return d->mInterval * count;
00133 }
00134 
00135 bool Repetition::isDaily() const
00136 {
00137     return d->mInterval.isDaily();
00138 }
00139 
00140 int Repetition::intervalDays() const
00141 {
00142     return d->mInterval.asDays();
00143 }
00144 
00145 int Repetition::intervalMinutes() const
00146 {
00147     return d->mInterval.asSeconds() / 60;
00148 }
00149 
00150 int Repetition::intervalSeconds() const
00151 {
00152     return d->mInterval.asSeconds();
00153 }
00154 
00155 int Repetition::nextRepeatCount(const KDateTime& from, const KDateTime& preDateTime) const
00156 {
00157     return d->mInterval.isDaily()
00158          ? from.daysTo(preDateTime) / d->mInterval.asDays() + 1
00159          : static_cast<int>(from.secsTo_long(preDateTime) / d->mInterval.asSeconds()) + 1;
00160 }
00161 
00162 int Repetition::previousRepeatCount(const KDateTime& from, const KDateTime& afterDateTime) const
00163 {
00164     return d->mInterval.isDaily()
00165          ? from.daysTo(afterDateTime.addSecs(-1)) / d->mInterval.asDays()
00166          : static_cast<int>((from.secsTo_long(afterDateTime) - 1) / d->mInterval.asSeconds());
00167 }
00168 
00169 } // namespace KAlarmCal
00170 
00171 // vim: et sw=4:
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:50:08 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KAlarm Library

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

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal