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

KAlarm Library

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 Repetition::Repetition()
54  : d(new Private)
55 {
56 }
57 
58 Repetition::Repetition(const Duration& interval, int count)
59  : d(new Private(interval, count))
60 {
61 }
62 
63 Repetition::Repetition(const Repetition& other)
64  : d(new Private(*other.d))
65 {
66 }
67 
68 Repetition::~Repetition()
69 {
70  delete d;
71 }
72 
73 Repetition& Repetition::operator=(const Repetition& other)
74 {
75  if (&other != this)
76  *d = *other.d;
77  return *this;
78 }
79 
80 void Repetition::set(const Duration& interval, int count)
81 {
82  if (!count || !interval)
83  {
84  d->mCount = 0;
85  d->mInterval = 0;
86  }
87  else
88  {
89  d->mCount = count;
90  d->mInterval = interval;
91  }
92 }
93 
94 void Repetition::set(const Duration& interval)
95 {
96  if (d->mCount)
97  {
98  d->mInterval = interval;
99  if (!interval)
100  d->mCount = 0;
101  }
102 }
103 
104 Repetition::operator bool() const
105 {
106  return d->mCount;
107 }
108 
109 bool Repetition::operator==(const Repetition& r) const
110 {
111  return d->mInterval == r.d->mInterval && d->mCount == r.d->mCount;
112 }
113 
114 int Repetition::count() const
115 {
116  return d->mCount;
117 }
118 
119 Duration Repetition::interval() const
120 {
121  return d->mInterval;
122 }
123 
124 Duration Repetition::duration() const
125 {
126  return d->mInterval * d->mCount;
127 }
128 
129 Duration Repetition::duration(int count) const
130 {
131  return d->mInterval * count;
132 }
133 
134 bool Repetition::isDaily() const
135 {
136  return d->mInterval.isDaily();
137 }
138 
139 int Repetition::intervalDays() const
140 {
141  return d->mInterval.asDays();
142 }
143 
144 int Repetition::intervalMinutes() const
145 {
146  return d->mInterval.asSeconds() / 60;
147 }
148 
149 int Repetition::intervalSeconds() const
150 {
151  return d->mInterval.asSeconds();
152 }
153 
154 int Repetition::nextRepeatCount(const KDateTime& from, const KDateTime& preDateTime) const
155 {
156  return d->mInterval.isDaily()
157  ? from.daysTo(preDateTime) / d->mInterval.asDays() + 1
158  : static_cast<int>(from.secsTo_long(preDateTime) / d->mInterval.asSeconds()) + 1;
159 }
160 
161 int Repetition::previousRepeatCount(const KDateTime& from, const KDateTime& afterDateTime) const
162 {
163  return d->mInterval.isDaily()
164  ? from.daysTo(afterDateTime.addSecs(-1)) / d->mInterval.asDays()
165  : static_cast<int>((from.secsTo_long(afterDateTime) - 1) / d->mInterval.asSeconds());
166 }
167 
168 } // namespace KAlarmCal
169 
170 // vim: et sw=4:
KAlarmCal::Repetition::interval
KCalCore::Duration interval() const
Return the interval between repetitions.
Definition: repetition.cpp:119
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:161
KAlarmCal::Repetition::intervalSeconds
int intervalSeconds() const
Return the repetition interval in terms of seconds.
Definition: repetition.cpp:149
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:53
KAlarmCal::Repetition::duration
KCalCore::Duration duration() const
Return the overall duration of the repetition.
Definition: repetition.cpp:124
KAlarmCal::Repetition::intervalMinutes
int intervalMinutes() const
Return the repetition interval in terms of minutes.
Definition: repetition.cpp:144
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:154
KAlarmCal::Repetition::count
int count() const
Return the number of repetitions.
Definition: repetition.cpp:114
KAlarmCal::Repetition::isDaily
bool isDaily() const
Check whether the repetition interval is in terms of days (as opposed to minutes).
Definition: repetition.cpp:134
KAlarmCal::Repetition::set
void set(const KCalCore::Duration &interval, int count)
Initialises the instance with the specified interval and count.
Definition: repetition.cpp:80
KAlarmCal::Repetition::intervalDays
int intervalDays() const
Return the repetition interval in terms of days.
Definition: repetition.cpp:139
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:14 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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