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

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
reminder.cpp
Go to the documentation of this file.
1 /*
2  * reminder.cpp - reminder setting widget
3  * Program: kalarm
4  * Copyright © 2003-2005,2007-2011 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 
23 #include "preferences.h"
24 #include "checkbox.h"
25 #include "combobox.h"
26 #include "timeselector.h"
27 #include "reminder.h"
28 
29 #ifdef USE_AKONADI
30 #include <kcalcore/duration.h>
31 using namespace KCalCore;
32 #else
33 #include <kcal/duration.h>
34 using namespace KCal;
35 #endif
36 
37 #include <kglobal.h>
38 #include <klocale.h>
39 #include <kdialog.h>
40 #include <kdatetime.h>
41 #include <kdebug.h>
42 
43 #include <QVBoxLayout>
44 #include <QHBoxLayout>
45 
46 
47 // Collect these widget labels together to ensure consistent wording and
48 // translations across different modules.
49 QString Reminder::i18n_chk_FirstRecurrenceOnly() { return i18nc("@option:check", "Reminder for first recurrence only"); }
50 
51 #define i18n_in_advance i18nc("@item:inlistbox", "in advance")
52 
53 
54 Reminder::Reminder(const QString& reminderWhatsThis, const QString& valueWhatsThis,
55  const QString& beforeAfterWhatsThis, bool allowHourMinute,
56  bool showOnceOnly, QWidget* parent)
57  : QFrame(parent),
58  mReadOnly(false),
59  mOnceOnlyEnabled(showOnceOnly)
60 {
61  QVBoxLayout* topLayout = new QVBoxLayout(this);
62  topLayout->setMargin(0);
63  topLayout->setSpacing(KDialog::spacingHint());
64 
65  mTime = new TimeSelector(i18nc("@option:check", "Reminder:"), reminderWhatsThis,
66  valueWhatsThis, allowHourMinute, this);
67  mTimeSignCombo = mTime->createSignCombo();
68  mTimeSignCombo->addItem(i18n_in_advance);
69  mTimeSignCombo->addItem(i18nc("@item:inlistbox", "afterwards"));
70  mTimeSignCombo->setWhatsThis(beforeAfterWhatsThis);
71  mTimeSignCombo->setCurrentIndex(0); // default to "in advance"
72  mTime->setFixedSize(mTime->sizeHint());
73  connect(mTime, SIGNAL(toggled(bool)), SLOT(slotReminderToggled(bool)));
74 #ifdef USE_AKONADI
75  connect(mTime, SIGNAL(valueChanged(KCalCore::Duration)), SIGNAL(changed()));
76 #else
77  connect(mTime, SIGNAL(valueChanged(KCal::Duration)), SIGNAL(changed()));
78 #endif
79  connect(mTimeSignCombo, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()));
80  topLayout->addWidget(mTime, 0, Qt::AlignLeft);
81 
82  if (showOnceOnly)
83  {
84  QHBoxLayout* layout = new QHBoxLayout();
85  layout->setMargin(0);
86  layout->addSpacing(3*KDialog::spacingHint());
87  topLayout->addLayout(layout);
88  mOnceOnly = new CheckBox(i18n_chk_FirstRecurrenceOnly(), this);
89  mOnceOnly->setFixedSize(mOnceOnly->sizeHint());
90  connect(mOnceOnly, SIGNAL(toggled(bool)), SIGNAL(changed()));
91  mOnceOnly->setWhatsThis(i18nc("@info:whatsthis", "Display the reminder only for the first time the alarm is scheduled"));
92  layout->addWidget(mOnceOnly);
93  layout->addStretch();
94  }
95  else
96  mOnceOnly = 0;
97 }
98 
99 /******************************************************************************
100 * Allow or disallow advance reminder selection.
101 */
102 void Reminder::setAfterOnly(bool afterOnly)
103 {
104  if (afterOnly && mTimeSignCombo->count() == 2)
105  mTimeSignCombo->removeItem(0);
106  else if (!afterOnly && mTimeSignCombo->count() == 1)
107  mTimeSignCombo->insertItem(0, i18n_in_advance);
108 }
109 
110 /******************************************************************************
111 * Set the read-only status.
112 */
113 void Reminder::setReadOnly(bool ro)
114 {
115  if ((int)ro != (int)mReadOnly)
116  {
117  mReadOnly = ro;
118  mTime->setReadOnly(mReadOnly);
119  if (mOnceOnly)
120  mOnceOnly->setReadOnly(mReadOnly);
121  }
122 }
123 
124 bool Reminder::isReminder() const
125 {
126  return mTime->isChecked();
127 }
128 
129 bool Reminder::isOnceOnly() const
130 {
131  return mOnceOnly && mOnceOnly->isEnabled() && mOnceOnly->isChecked();
132 }
133 
134 void Reminder::setOnceOnly(bool onceOnly)
135 {
136  if (mOnceOnly)
137  mOnceOnly->setChecked(onceOnly);
138 }
139 
140 /******************************************************************************
141 * Specify whether the once-only checkbox is allowed to be enabled.
142 */
143 void Reminder::enableOnceOnly(bool enable)
144 {
145  if (mOnceOnly)
146  {
147  mOnceOnlyEnabled = enable;
148  mOnceOnly->setEnabled(enable && mTime->isChecked());
149  }
150 }
151 
152 void Reminder::setMaximum(int hourmin, int days)
153 {
154  mTime->setMaximum(hourmin, days);
155 }
156 
157 /******************************************************************************
158 * Get the specified number of minutes in advance of the main alarm the
159 * reminder is to be.
160 * Reply > 0 if advance reminder
161 * < 0 if reminder after main alarm
162 * = 0 if no reminder.
163 */
164 int Reminder::minutes() const
165 {
166  int index = mTimeSignCombo->currentIndex();
167  if (mTimeSignCombo->count() == 1)
168  ++index; // "in advance" is not available
169  int sign = index ? -1 : 1;
170  return mTime->period().asSeconds() * sign / 60;
171 }
172 
173 /******************************************************************************
174 * Initialise the controls with a specified reminder time.
175 */
176 void Reminder::setMinutes(int minutes, bool dateOnly)
177 {
178  bool neg = (minutes < 0);
179  minutes = abs(minutes);
180  Duration period;
181  if (minutes % (24*60))
182  period = Duration(minutes * 60, Duration::Seconds);
183  else
184  period = Duration(minutes / (24*60), Duration::Days);
185  mTime->setPeriod(period, dateOnly, Preferences::defaultReminderUnits());
186  mTimeSignCombo->setCurrentIndex(neg ? 1 : 0);
187 }
188 
189 /******************************************************************************
190 * Set the reminder units to days if "Any time" is checked.
191 */
192 void Reminder::setDateOnly(bool dateOnly)
193 {
194  mTime->setDateOnly(dateOnly);
195 }
196 
197 /******************************************************************************
198 * Set the input focus on the count field.
199 */
200 void Reminder::setFocusOnCount()
201 {
202  mTime->setFocusOnCount();
203 }
204 
205 /******************************************************************************
206 * Called when the Reminder checkbox is toggled.
207 */
208 void Reminder::slotReminderToggled(bool on)
209 {
210  if (mOnceOnly)
211  mOnceOnly->setEnabled(on && mOnceOnlyEnabled);
212 }
213 
214 /******************************************************************************
215 * Called when the start time relating to the reminder has changed.
216 * Sets the default reminder time units appropriately, if no reminder time is
217 * currently set.
218 */
219 void Reminder::setDefaultUnits(const KDateTime& dt)
220 {
221  if (mTime->isChecked())
222  return; // don't change units if reminder is already set
223  TimePeriod::Units units;
224  TimePeriod::Units currentUnits = mTime->units();
225  if (KDateTime::currentDateTime(dt.timeSpec()).daysTo(dt) < 7)
226  {
227  if (currentUnits == TimePeriod::Minutes || currentUnits == TimePeriod::HoursMinutes)
228  return;
229  units = (Preferences::defaultReminderUnits() == TimePeriod::Minutes)
230  ? TimePeriod::Minutes : TimePeriod::HoursMinutes;
231  }
232  else
233  {
234  if (currentUnits == TimePeriod::Days || currentUnits == TimePeriod::Weeks)
235  return;
236  units = TimePeriod::Days;
237  }
238  mTime->setUnits(units);
239 }
240 #include "moc_reminder.cpp"
241 // vim: et sw=4:
QWidget::layout
QLayout * layout() const
CheckBox::setReadOnly
virtual void setReadOnly(bool readOnly)
QWidget
TimePeriod::Days
TimeSelector::setMaximum
void setMaximum(int hourmin, int days)
Definition: timeselector.cpp:115
Reminder::setAfterOnly
void setAfterOnly(bool after)
Definition: reminder.cpp:102
TimeSelector::isChecked
bool isChecked() const
Definition: timeselector.cpp:101
TimePeriod::Units
Units
TimeSelector::setUnits
void setUnits(TimePeriod::Units units)
Definition: timeselector.h:48
TimeSelector::units
TimePeriod::Units units() const
Definition: timeselector.h:47
Reminder::i18n_chk_FirstRecurrenceOnly
static QString i18n_chk_FirstRecurrenceOnly()
Definition: reminder.cpp:49
TimeSelector::setReadOnly
void setReadOnly(bool)
Definition: timeselector.cpp:89
TimePeriod::HoursMinutes
QCheckBox::sizeHint
virtual QSize sizeHint() const
QHBoxLayout
QBoxLayout::addSpacing
void addSpacing(int size)
checkbox.h
QFrame::sizeHint
virtual QSize sizeHint() const
Reminder::setDateOnly
void setDateOnly(bool dateOnly)
Definition: reminder.cpp:192
Reminder::setMinutes
void setMinutes(int minutes, bool dateOnly)
Definition: reminder.cpp:176
QWidget::isEnabled
bool isEnabled() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
Reminder::setFocusOnCount
void setFocusOnCount()
Definition: reminder.cpp:200
TimeSelector::setFocusOnCount
void setFocusOnCount()
Definition: timeselector.cpp:152
CheckBox
i18n_in_advance
#define i18n_in_advance
Definition: reminder.cpp:51
Reminder::setDefaultUnits
void setDefaultUnits(const KDateTime &)
Definition: reminder.cpp:219
QVBoxLayout
QString
QLayout::setMargin
void setMargin(int margin)
Reminder::isReminder
bool isReminder() const
Definition: reminder.cpp:124
reminder.h
QWidget::setFixedSize
void setFixedSize(const QSize &s)
preferences.h
QFrame
Reminder::changed
void changed()
QAbstractButton::isChecked
bool isChecked() const
Reminder::setReadOnly
void setReadOnly(bool)
Definition: reminder.cpp:113
QWidget::setWhatsThis
void setWhatsThis(const QString &)
TimeSelector::setDateOnly
void setDateOnly(bool dateOnly=true)
Definition: timeselector.cpp:120
QBoxLayout::addStretch
void addStretch(int stretch)
Reminder::isOnceOnly
bool isOnceOnly() const
Definition: reminder.cpp:129
kalarm.h
combobox.h
TimeSelector
Definition: timeselector.h:31
TimeSelector::setPeriod
void setPeriod(const KCal::Duration &, bool dateOnly, TimePeriod::Units defaultUnits)
Definition: timeselector.cpp:140
timeselector.h
Reminder::minutes
int minutes() const
Definition: reminder.cpp:164
Reminder::setMaximum
void setMaximum(int hourmin, int days)
Definition: reminder.cpp:152
TimePeriod::Weeks
Reminder::enableOnceOnly
void enableOnceOnly(bool enable)
Definition: reminder.cpp:143
TimeSelector::createSignCombo
ComboBox * createSignCombo()
Definition: timeselector.cpp:78
TimePeriod::Minutes
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QBoxLayout::setSpacing
void setSpacing(int spacing)
Reminder::Reminder
Reminder(const QString &reminderWhatsThis, const QString &valueWhatsThis, const QString &beforeAfterWhatsThis, bool allowHourMinute, bool showOnceOnly, QWidget *parent)
Definition: reminder.cpp:54
Reminder::setOnceOnly
void setOnceOnly(bool)
Definition: reminder.cpp:134
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
TimeSelector::period
KCal::Duration period() const
Definition: timeselector.cpp:129
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

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