kalarm

reminder.cpp
1 /*
2  * reminder.cpp - reminder setting widget
3  * Program: kalarm
4  * Copyright (C) 2003 - 2005 by David Jarvie <software@astrojar.org.uk>
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 <tqlayout.h>
24 #include <tqwhatsthis.h>
25 
26 #include <tdeglobal.h>
27 #include <tdelocale.h>
28 #include <kdialog.h>
29 #include <kdebug.h>
30 
31 #include "preferences.h"
32 #include "checkbox.h"
33 #include "timeselector.h"
34 #include "reminder.moc"
35 
36 
37 // Collect these widget labels together to ensure consistent wording and
38 // translations across different modules.
39 TQString Reminder::i18n_first_recurrence_only() { return i18n("Reminder for first recurrence only"); }
40 TQString Reminder::i18n_u_first_recurrence_only() { return i18n("Reminder for first rec&urrence only"); }
41 
42 
43 Reminder::Reminder(const TQString& caption, const TQString& reminderWhatsThis, const TQString& valueWhatsThis,
44  bool allowHourMinute, bool showOnceOnly, TQWidget* parent, const char* name)
45  : TQFrame(parent, name),
46  mReadOnly(false),
47  mOnceOnlyEnabled(showOnceOnly)
48 {
49  setFrameStyle(TQFrame::NoFrame);
50  TQVBoxLayout* topLayout = new TQVBoxLayout(this, 0, KDialog::spacingHint());
51 
52  mTime = new TimeSelector(caption, i18n("in advance"), reminderWhatsThis,
53  valueWhatsThis, allowHourMinute, this, "timeOption");
54  mTime->setFixedSize(mTime->sizeHint());
55  connect(mTime, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotReminderToggled(bool)));
56  topLayout->addWidget(mTime);
57 
58  if (showOnceOnly)
59  {
60  TQBoxLayout* layout = new TQHBoxLayout(topLayout, KDialog::spacingHint());
61  layout->addSpacing(3*KDialog::spacingHint());
62  mOnceOnly = new CheckBox(i18n_u_first_recurrence_only(), this);
63  mOnceOnly->setFixedSize(mOnceOnly->sizeHint());
64  TQWhatsThis::add(mOnceOnly, i18n("Display the reminder only before the first time the alarm is scheduled"));
65  layout->addWidget(mOnceOnly);
66  layout->addStretch();
67  }
68  else
69  mOnceOnly = 0;
70 }
71 
72 /******************************************************************************
73 * Set the read-only status.
74 */
75 void Reminder::setReadOnly(bool ro)
76 {
77  if ((int)ro != (int)mReadOnly)
78  {
79  mReadOnly = ro;
80  mTime->setReadOnly(mReadOnly);
81  if (mOnceOnly)
82  mOnceOnly->setReadOnly(mReadOnly);
83  }
84 }
85 
86 bool Reminder::isReminder() const
87 {
88  return mTime->isChecked();
89 }
90 
91 bool Reminder::isOnceOnly() const
92 {
93  return mOnceOnly && mOnceOnly->isEnabled() && mOnceOnly->isChecked();
94 }
95 
96 void Reminder::setOnceOnly(bool onceOnly)
97 {
98  if (mOnceOnly)
99  mOnceOnly->setChecked(onceOnly);
100 }
101 
102 /******************************************************************************
103 * Specify whether the once-only checkbox is allowed to be enabled.
104 */
105 void Reminder::enableOnceOnly(bool enable)
106 {
107  if (mOnceOnly)
108  {
109  mOnceOnlyEnabled = enable;
110  mOnceOnly->setEnabled(enable && mTime->isChecked());
111  }
112 }
113 
114 void Reminder::setMaximum(int hourmin, int days)
115 {
116  mTime->setMaximum(hourmin, days);
117 }
118 
119 /******************************************************************************
120  * Get the specified number of minutes in advance of the main alarm the
121  * reminder is to be.
122  */
123 int Reminder::minutes() const
124 {
125  return mTime->minutes();
126 }
127 
128 /******************************************************************************
129 * Initialise the controls with a specified reminder time.
130 */
131 void Reminder::setMinutes(int minutes, bool dateOnly)
132 {
133  mTime->setMinutes(minutes, dateOnly, Preferences::defaultReminderUnits());
134 }
135 
136 /******************************************************************************
137 * Set the advance reminder units to days if "Any time" is checked.
138 */
139 void Reminder::setDateOnly(bool dateOnly)
140 {
141  mTime->setDateOnly(dateOnly);
142 }
143 
144 /******************************************************************************
145 * Set the input focus on the count field.
146 */
147 void Reminder::setFocusOnCount()
148 {
149  mTime->setFocusOnCount();
150 }
151 
152 /******************************************************************************
153 * Called when the Reminder checkbox is toggled.
154 */
155 void Reminder::slotReminderToggled(bool on)
156 {
157  if (mOnceOnly)
158  mOnceOnly->setEnabled(on && mOnceOnlyEnabled);
159 }