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

KAlarm Library

  • kalarmcal
repetition.cpp
1 /*
2  * repetition.cpp - represents a sub-repetition: interval and count
3  * This file is part of kalarmcal library, which provides access to KAlarm
4  * calendar data.
5  * Copyright © 2009-2012 by David Jarvie <djarvie@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Library General Public License as published
9  * by the Free Software Foundation; either version 2 of the License, or (at
10  * your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  * License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  */
22 
23 #include "repetition.h"
24 #include <kdatetime.h>
25 
26 #ifndef KALARMCAL_USE_KRESOURCES
27 using namespace KCalCore;
28 #else
29 using namespace KCal;
30 #endif
31 
32 namespace KAlarmCal
33 {
34 
35 class Repetition::Private
36 {
37  public:
38  Private() : mInterval(0), mCount(0) {}
39  Private(const Duration& interval, int count)
40  : mInterval(interval), mCount(count)
41  {
42  if ((!count && interval) || (count && !interval))
43  {
44  mCount = 0;
45  mInterval = 0;
46  }
47  }
48 
49  Duration mInterval; // sub-repetition interval
50  int mCount; // sub-repetition count (excluding the first time)
51 };
52 
53 
54 Repetition::Repetition()
55  : d(new Private)
56 {
57 }
58 
59 Repetition::Repetition(const Duration& interval, int count)
60  : d(new Private(interval, count))
61 {
62 }
63 
64 Repetition::Repetition(const Repetition& other)
65  : d(new Private(*other.d))
66 {
67 }
68 
69 Repetition::~Repetition()
70 {
71  delete d;
72 }
73 
74 Repetition& Repetition::operator=(const Repetition& other)
75 {
76  if (&other != this)
77  *d = *other.d;
78  return *this;
79 }
80 
81 void Repetition::set(const Duration& interval, int count)
82 {
83  if (!count || !interval)
84  {
85  d->mCount = 0;
86  d->mInterval = 0;
87  }
88  else
89  {
90  d->mCount = count;
91  d->mInterval = interval;
92  }
93 }
94 
95 void Repetition::set(const Duration& interval)
96 {
97  if (d->mCount)
98  {
99  d->mInterval = interval;
100  if (!interval)
101  d->mCount = 0;
102  }
103 }
104 
105 Repetition::operator bool() const
106 {
107  return d->mCount;
108 }
109 
110 bool Repetition::operator==(const Repetition& r) const
111 {
112  return d->mInterval == r.d->mInterval && d->mCount == r.d->mCount;
113 }
114 
115 int Repetition::count() const
116 {
117  return d->mCount;
118 }
119 
120 Duration Repetition::interval() const
121 {
122  return d->mInterval;
123 }
124 
125 Duration Repetition::duration() const
126 {
127  return d->mInterval * d->mCount;
128 }
129 
130 Duration Repetition::duration(int count) const
131 {
132  return d->mInterval * count;
133 }
134 
135 bool Repetition::isDaily() const
136 {
137  return d->mInterval.isDaily();
138 }
139 
140 int Repetition::intervalDays() const
141 {
142  return d->mInterval.asDays();
143 }
144 
145 int Repetition::intervalMinutes() const
146 {
147  return d->mInterval.asSeconds() / 60;
148 }
149 
150 int Repetition::intervalSeconds() const
151 {
152  return d->mInterval.asSeconds();
153 }
154 
155 int Repetition::nextRepeatCount(const KDateTime& from, const KDateTime& preDateTime) const
156 {
157  return d->mInterval.isDaily()
158  ? from.daysTo(preDateTime) / d->mInterval.asDays() + 1
159  : static_cast<int>(from.secsTo_long(preDateTime) / d->mInterval.asSeconds()) + 1;
160 }
161 
162 int Repetition::previousRepeatCount(const KDateTime& from, const KDateTime& afterDateTime) const
163 {
164  return d->mInterval.isDaily()
165  ? from.daysTo(afterDateTime.addSecs(-1)) / d->mInterval.asDays()
166  : static_cast<int>((from.secsTo_long(afterDateTime) - 1) / d->mInterval.asSeconds());
167 }
168 
169 } // namespace KAlarmCal
170 
171 // vim: et sw=4:
KAlarmCal::Repetition::interval
KCalCore::Duration interval() const
Return the interval between repetitions.
Definition: repetition.cpp:120
KCalCore::Duration
KAlarmCal::Repetition::previousRepeatCount
int previousRepeatCount(const KDateTime &from, const KDateTime &afterDateTime) const
Find the repetition count for the last repetition before a specified time.
Definition: repetition.cpp:162
KAlarmCal::Repetition::intervalSeconds
int intervalSeconds() const
Return the repetition interval in terms of seconds.
Definition: repetition.cpp:150
KAlarmCal::Repetition
Represents a sub-repetition, defined by interval and repeat count.
Definition: repetition.h:47
KAlarmCal::Repetition::Repetition
Repetition()
Default constructor.
Definition: repetition.cpp:54
KAlarmCal::Repetition::duration
KCalCore::Duration duration() const
Return the overall duration of the repetition.
Definition: repetition.cpp:125
KAlarmCal::Repetition::intervalMinutes
int intervalMinutes() const
Return the repetition interval in terms of minutes.
Definition: repetition.cpp:145
KAlarmCal::Repetition::nextRepeatCount
int nextRepeatCount(const KDateTime &from, const KDateTime &preDateTime) const
Find the repetition count for the next repetition after a specified time.
Definition: repetition.cpp:155
KAlarmCal::Repetition::count
int count() const
Return the number of repetitions.
Definition: repetition.cpp:115
KAlarmCal::Repetition::isDaily
bool isDaily() const
Check whether the repetition interval is in terms of days (as opposed to minutes).
Definition: repetition.cpp:135
KAlarmCal::Repetition::set
void set(const KCalCore::Duration &interval, int count)
Initialises the instance with the specified interval and count.
Definition: repetition.cpp:81
KAlarmCal::Repetition::intervalDays
int intervalDays() const
Return the repetition interval in terms of days.
Definition: repetition.cpp:140
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:04:31 by doxygen 1.8.5 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.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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