2 * latecancel.cpp - widget to specify cancellation if late
4 * Copyright © 2004,2005,2007-2011 by David Jarvie <djarvie@kde.org>
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.
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.
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.
22 #include "latecancel.moc"
27 #include <kcalcore/duration.h>
28 using namespace KCalCore
;
30 #include <kcal/duration.h>
37 #include <QStackedWidget>
38 #include <QVBoxLayout>
39 #include <QHBoxLayout>
42 // Collect these widget labels together to ensure consistent wording and
43 // translations across different modules.
44 QString
LateCancelSelector::i18n_chk_CancelIfLate() { return i18nc("@option:check", "Cancel if late"); }
45 QString
LateCancelSelector::i18n_chk_AutoCloseWin() { return i18nc("@option:check", "Auto-close window after this time"); }
46 QString
LateCancelSelector::i18n_chk_AutoCloseWinLC() { return i18nc("@option:check", "Auto-close window after late-cancellation time"); }
49 LateCancelSelector::LateCancelSelector(bool allowHourMinute
, QWidget
* parent
)
53 mAutoCloseShown(false)
55 QString whatsThis
= i18nc("@info:whatsthis",
56 "<para>If checked, the alarm will be canceled if it cannot be triggered within the "
57 "specified period after its scheduled time. Possible reasons for not triggering "
58 "include your being logged off, X not running, or <application>KAlarm</application> not running.</para>"
59 "<para>If unchecked, the alarm will be triggered at the first opportunity after "
60 "its scheduled time, regardless of how late it is.</para>");
62 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
63 topLayout
->setMargin(0);
64 topLayout
->setSpacing(KDialog::spacingHint());
66 mStack
= new QStackedWidget(this);
67 topLayout
->addWidget(mStack
, 0, Qt::AlignLeft
);
68 mCheckboxFrame
= new QFrame();
69 mStack
->addWidget(mCheckboxFrame
);
70 QHBoxLayout
* hlayout
= new QHBoxLayout(mCheckboxFrame
);
71 hlayout
->setMargin(0);
72 mCheckbox
= new CheckBox(i18n_chk_CancelIfLate(), mCheckboxFrame
);
73 connect(mCheckbox
, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
74 connect(mCheckbox
, SIGNAL(toggled(bool)), SIGNAL(changed()));
75 mCheckbox
->setWhatsThis(whatsThis
);
76 hlayout
->addWidget(mCheckbox
, 0, Qt::AlignLeft
);
78 mTimeSelectorFrame
= new QFrame();
79 mStack
->addWidget(mTimeSelectorFrame
);
80 hlayout
= new QHBoxLayout(mTimeSelectorFrame
);
81 hlayout
->setMargin(0);
82 mTimeSelector
= new TimeSelector(i18nc("@option:check Cancel if late by 10 minutes", "Cancel if late by"),
83 whatsThis
, i18nc("@info:whatsthis", "Enter how late will cause the alarm to be canceled"),
84 allowHourMinute
, mTimeSelectorFrame
);
85 connect(mTimeSelector
, SIGNAL(toggled(bool)), SLOT(slotToggled(bool)));
87 connect(mTimeSelector
, SIGNAL(valueChanged(KCalCore::Duration
)), SIGNAL(changed()));
89 connect(mTimeSelector
, SIGNAL(valueChanged(KCal::Duration
)), SIGNAL(changed()));
91 hlayout
->addWidget(mTimeSelector
, 0, Qt::AlignLeft
);
93 hlayout
= new QHBoxLayout();
94 hlayout
->setMargin(0);
95 hlayout
->addSpacing(3*KDialog::spacingHint());
96 topLayout
->addLayout(hlayout
);
97 mAutoClose
= new CheckBox(i18n_chk_AutoCloseWin(), this);
98 connect(mAutoClose
, SIGNAL(toggled(bool)), SIGNAL(changed()));
99 mAutoClose
->setWhatsThis(i18nc("@info:whatsthis", "Automatically close the alarm window after the expiry of the late-cancellation period"));
100 hlayout
->addWidget(mAutoClose
);
101 hlayout
->addStretch();
104 mAutoClose
->setEnabled(false);
107 /******************************************************************************
108 * Set the read-only status.
110 void LateCancelSelector::setReadOnly(bool ro
)
112 if ((int)ro
!= (int)mReadOnly
)
115 mCheckbox
->setReadOnly(mReadOnly
);
116 mTimeSelector
->setReadOnly(mReadOnly
);
117 mAutoClose
->setReadOnly(mReadOnly
);
121 int LateCancelSelector::minutes() const
123 return mTimeSelector
->period().asSeconds() / 60;
126 void LateCancelSelector::setMinutes(int minutes
, bool dateOnly
, TimePeriod::Units defaultUnits
)
128 slotToggled(minutes
);
130 if (minutes
% (24*60))
131 period
= Duration(minutes
* 60, Duration::Seconds
);
133 period
= Duration(minutes
/ (24*60), Duration::Days
);
134 mTimeSelector
->setPeriod(period
, dateOnly
, defaultUnits
);
137 void LateCancelSelector::setDateOnly(bool dateOnly
)
139 if (dateOnly
!= mDateOnly
)
141 mDateOnly
= dateOnly
;
142 if (mTimeSelector
->isChecked()) // don't change when it's not visible
143 mTimeSelector
->setDateOnly(dateOnly
);
147 void LateCancelSelector::showAutoClose(bool show
)
153 mAutoCloseShown
= show
;
157 bool LateCancelSelector::isAutoClose() const
159 return mAutoCloseShown
&& mAutoClose
->isEnabled() && mAutoClose
->isChecked();
162 void LateCancelSelector::setAutoClose(bool autoClose
)
164 mAutoClose
->setChecked(autoClose
);
167 /******************************************************************************
168 * Called when either of the checkboxes is toggled.
170 void LateCancelSelector::slotToggled(bool on
)
172 mCheckbox
->setChecked(on
);
173 mTimeSelector
->setChecked(on
);
176 mTimeSelector
->setDateOnly(mDateOnly
);
177 mStack
->setCurrentWidget(mTimeSelectorFrame
);
180 mStack
->setCurrentWidget(mCheckboxFrame
);
181 mAutoClose
->setEnabled(on
);