SVN_SILENT made messages (after extraction)
[kdepim.git] / kalarm / prefdlg.cpp
blob2c87d101062119cc5f876413adb5380fdd5a0a45
1 /*
2 * prefdlg.cpp - program preferences dialog
3 * Program: kalarm
4 * Copyright © 2001-2016 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.
21 #include "kalarm.h"
23 #include "alarmcalendar.h"
24 #include "collectionmodel.h"
25 #include "alarmtimewidget.h"
26 #include "buttongroup.h"
27 #include "colourbutton.h"
28 #include "editdlg.h"
29 #include "editdlgtypes.h"
30 #include "fontcolour.h"
31 #include "functions.h"
32 #include "itembox.h"
33 #include "kalarmapp.h"
34 #include "kalocale.h"
35 #include "kamail.h"
36 #include "label.h"
37 #include "latecancel.h"
38 #include "mainwindow.h"
39 #include "messagebox.h"
40 #include "preferences.h"
41 #include "radiobutton.h"
42 #include "recurrenceedit.h"
43 #include "sounddlg.h"
44 #include "soundpicker.h"
45 #include "specialactions.h"
46 #include "stackedwidgets.h"
47 #include "timeedit.h"
48 #include "timespinbox.h"
49 #include "timezonecombo.h"
50 #include "traywindow.h"
51 #include "prefdlg_p.h"
52 #include "prefdlg.h"
54 #include "config-kdepim.h"
56 #include <kalarmcal/identities.h>
58 #include <KHolidays/HolidayRegion>
59 using namespace KHolidays;
61 #include <kpimtextedit/texttospeech.h>
63 #include <kglobal.h>
64 #include <KLocalizedString>
65 #include <kshell.h>
66 #include <klineedit.h>
67 #include <KAboutData>
68 #include <kstandardguiitem.h>
69 #include <ksystemtimezone.h>
70 #include <qicon.h>
71 #if KDEPIM_HAVE_X11
72 #include <kwindowinfo.h>
73 #include <kwindowsystem.h>
74 #endif
75 #include <ktoolinvocation.h>
76 #include <KHelpClient>
78 #include <QLabel>
79 #include <QCheckBox>
80 #include <QRadioButton>
81 #include <QPushButton>
82 #include <QTabWidget>
83 #include <QSpinBox>
84 #include <QGroupBox>
85 #include <QGridLayout>
86 #include <QHBoxLayout>
87 #include <QVBoxLayout>
88 #include <QStyle>
89 #include <QResizeEvent>
90 #include <QStandardPaths>
91 #include <QComboBox>
92 #include "kalarm_debug.h"
94 using namespace KCalCore;
95 using namespace KAlarmCal;
97 static const char PREF_DIALOG_NAME[] = "PrefDialog";
99 // Command strings for executing commands in different types of terminal windows.
100 // %t = window title parameter
101 // %c = command to execute in terminal
102 // %w = command to execute in terminal, with 'sleep 86400' appended
103 // %C = temporary command file to execute in terminal
104 // %W = temporary command file to execute in terminal, with 'sleep 86400' appended
105 static QString xtermCommands[] = {
106 QStringLiteral("xterm -sb -hold -title %t -e %c"),
107 QStringLiteral("konsole --noclose -p tabtitle=%t -e ${SHELL:-sh} -c %c"),
108 QStringLiteral("gnome-terminal -t %t -e %W"),
109 QStringLiteral("eterm --pause -T %t -e %C"), // some systems use eterm...
110 QStringLiteral("Eterm --pause -T %t -e %C"), // while some use Eterm
111 QStringLiteral("rxvt -title %t -e ${SHELL:-sh} -c %w"),
112 QString() // end of list indicator - don't change!
116 /*=============================================================================
117 = Class KAlarmPrefDlg
118 =============================================================================*/
120 KAlarmPrefDlg* KAlarmPrefDlg::mInstance = Q_NULLPTR;
122 void KAlarmPrefDlg::display()
124 if (!mInstance)
126 mInstance = new KAlarmPrefDlg;
127 QSize s;
128 if (KAlarm::readConfigWindowSize(PREF_DIALOG_NAME, s))
129 mInstance->resize(s);
130 mInstance->show();
132 else
134 #if KDEPIM_HAVE_X11
135 KWindowInfo info = KWindowInfo(mInstance->winId(), NET::WMGeometry | NET::WMDesktop);
136 KWindowSystem::setCurrentDesktop(info.desktop());
137 #endif
138 mInstance->setWindowState(mInstance->windowState() & ~Qt::WindowMinimized); // un-minimize it if necessary
139 mInstance->raise();
140 mInstance->activateWindow();
144 KAlarmPrefDlg::KAlarmPrefDlg()
145 : KPageDialog(),
146 mShown(false)
148 setAttribute(Qt::WA_DeleteOnClose);
149 setObjectName(QStringLiteral("PrefDlg")); // used by LikeBack
150 setWindowTitle(i18nc("@title:window", "Configure"));
151 setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Apply);
152 button(QDialogButtonBox::Ok)->setDefault(true);
153 setFaceType(List);
154 mTabScrollGroup = new StackedScrollGroup(this, this);
156 mMiscPage = new MiscPrefTab(mTabScrollGroup);
157 mMiscPageItem = new KPageWidgetItem(mMiscPage, i18nc("@title:tab General preferences", "General"));
158 mMiscPageItem->setHeader(i18nc("@title General preferences", "General"));
159 mMiscPageItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-other")));
160 addPage(mMiscPageItem);
162 mTimePage = new TimePrefTab(mTabScrollGroup);
163 mTimePageItem = new KPageWidgetItem(mTimePage, i18nc("@title:tab", "Time & Date"));
164 mTimePageItem->setHeader(i18nc("@title", "Time and Date"));
165 mTimePageItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-time")));
166 addPage(mTimePageItem);
168 mStorePage = new StorePrefTab(mTabScrollGroup);
169 mStorePageItem = new KPageWidgetItem(mStorePage, i18nc("@title:tab", "Storage"));
170 mStorePageItem->setHeader(i18nc("@title", "Alarm Storage"));
171 mStorePageItem->setIcon(QIcon::fromTheme(QStringLiteral("system-file-manager")));
172 addPage(mStorePageItem);
174 mEmailPage = new EmailPrefTab(mTabScrollGroup);
175 mEmailPageItem = new KPageWidgetItem(mEmailPage, i18nc("@title:tab Email preferences", "Email"));
176 mEmailPageItem->setHeader(i18nc("@title", "Email Alarm Settings"));
177 mEmailPageItem->setIcon(QIcon::fromTheme(QStringLiteral("internet-mail")));
178 addPage(mEmailPageItem);
180 mViewPage = new ViewPrefTab(mTabScrollGroup);
181 mViewPageItem = new KPageWidgetItem(mViewPage, i18nc("@title:tab", "View"));
182 mViewPageItem->setHeader(i18nc("@title", "View Settings"));
183 mViewPageItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-theme")));
184 addPage(mViewPageItem);
186 mEditPage = new EditPrefTab(mTabScrollGroup);
187 mEditPageItem = new KPageWidgetItem(mEditPage, i18nc("@title:tab", "Edit"));
188 mEditPageItem->setHeader(i18nc("@title", "Default Alarm Edit Settings"));
189 mEditPageItem->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
190 addPage(mEditPageItem);
191 connect(button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotOk);
192 connect(button(QDialogButtonBox::Cancel), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotCancel);
193 connect(button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotApply);
194 connect(button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotDefault);
195 connect(button(QDialogButtonBox::Help), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotHelp);
196 restore(false);
197 adjustSize();
200 KAlarmPrefDlg::~KAlarmPrefDlg()
202 mInstance = Q_NULLPTR;
205 void KAlarmPrefDlg::slotHelp()
207 KHelpClient::invokeHelp(QStringLiteral("preferences"));
210 // Apply the preferences that are currently selected
211 void KAlarmPrefDlg::slotApply()
213 qCDebug(KALARM_LOG);
214 QString errmsg = mEmailPage->validate();
215 if (!errmsg.isEmpty())
217 setCurrentPage(mEmailPageItem);
218 if (KAMessageBox::warningYesNo(this, errmsg) != KMessageBox::Yes)
220 mValid = false;
221 return;
224 errmsg = mEditPage->validate();
225 if (!errmsg.isEmpty())
227 setCurrentPage(mEditPageItem);
228 KAMessageBox::sorry(this, errmsg);
229 mValid = false;
230 return;
232 mValid = true;
233 mEmailPage->apply(false);
234 mViewPage->apply(false);
235 mEditPage->apply(false);
236 mStorePage->apply(false);
237 mTimePage->apply(false);
238 mMiscPage->apply(false);
239 Preferences::self()->save();
242 // Apply the preferences that are currently selected
243 void KAlarmPrefDlg::slotOk()
245 qCDebug(KALARM_LOG);
246 mValid = true;
247 slotApply();
248 if (mValid)
249 QDialog::accept();
252 // Discard the current preferences and close the dialog
253 void KAlarmPrefDlg::slotCancel()
255 qCDebug(KALARM_LOG);
256 restore(false);
257 KPageDialog::reject();
260 // Reset all controls to the application defaults
261 void KAlarmPrefDlg::slotDefault()
263 switch (KAMessageBox::questionYesNoCancel(this, i18nc("@info", "Reset all tabs to their default values, or only reset the current tab?"),
264 QString(),
265 KGuiItem(i18nc("@action:button Reset ALL tabs", "&All")),
266 KGuiItem(i18nc("@action:button Reset the CURRENT tab", "C&urrent"))))
268 case KMessageBox::Yes:
269 restore(true); // restore all tabs
270 break;
271 case KMessageBox::No:
272 Preferences::self()->useDefaults(true);
273 static_cast<PrefsTabBase*>(currentPage()->widget())->restore(true, false);
274 Preferences::self()->useDefaults(false);
275 break;
276 default:
277 break;
281 // Discard the current preferences and use the present ones
282 void KAlarmPrefDlg::restore(bool defaults)
284 qCDebug(KALARM_LOG) << (defaults ? "defaults" : "");
285 if (defaults)
286 Preferences::self()->useDefaults(true);
287 mEmailPage->restore(defaults, true);
288 mViewPage->restore(defaults, true);
289 mEditPage->restore(defaults, true);
290 mStorePage->restore(defaults, true);
291 mTimePage->restore(defaults, true);
292 mMiscPage->restore(defaults, true);
293 if (defaults)
294 Preferences::self()->useDefaults(false);
297 /******************************************************************************
298 * Return the minimum size for the dialog.
299 * If the minimum size would be too high to fit the desktop, the tab contents
300 * are made scrollable.
302 QSize KAlarmPrefDlg::minimumSizeHint() const
304 if (!mTabScrollGroup->sized())
306 QSize s = mTabScrollGroup->adjustSize();
307 if (s.isValid())
309 if (mTabScrollGroup->heightReduction())
311 s = QSize(s.width(), s.height() - mTabScrollGroup->heightReduction());
312 const_cast<KAlarmPrefDlg*>(this)->resize(s);
314 return s;
317 return KPageDialog::minimumSizeHint();
320 void KAlarmPrefDlg::showEvent(QShowEvent* e)
322 KPageDialog::showEvent(e);
323 if (!mShown)
325 mTabScrollGroup->adjustSize(true);
326 mShown = true;
330 /******************************************************************************
331 * Called when the dialog's size has changed.
332 * Records the new size in the config file.
334 void KAlarmPrefDlg::resizeEvent(QResizeEvent* re)
336 if (isVisible())
337 KAlarm::writeConfigWindowSize(PREF_DIALOG_NAME, re->size());
338 KPageDialog::resizeEvent(re);
342 /*=============================================================================
343 = Class PrefsTabBase
344 =============================================================================*/
345 int PrefsTabBase::mIndentWidth = 0;
347 PrefsTabBase::PrefsTabBase(StackedScrollGroup* scrollGroup)
348 : StackedScrollWidget(scrollGroup),
349 mLabelsAligned(false)
351 QFrame *topWidget = new QFrame(this);
352 setWidget(topWidget);
353 mTopLayout = new QVBoxLayout(topWidget);
354 mTopLayout->setMargin(0);
355 mTopLayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
356 if (!mIndentWidth)
358 QRadioButton radio(this);
359 QStyleOptionButton opt;
360 opt.initFrom(&radio);
361 mIndentWidth = style()->subElementRect(QStyle::SE_RadioButtonIndicator, &opt).width();
365 void PrefsTabBase::apply(bool syncToDisc)
367 if (syncToDisc)
368 Preferences::self()->save();
371 void PrefsTabBase::addAlignedLabel(QLabel* label)
373 mLabels += label;
376 void PrefsTabBase::showEvent(QShowEvent*)
378 if (!mLabelsAligned)
380 int wid = 0;
381 int i;
382 int end = mLabels.count();
383 QList<int> xpos;
384 for (i = 0; i < end; ++i)
386 int x = mLabels[i]->mapTo(this, QPoint(0, 0)).x();
387 xpos += x;
388 int w = x + mLabels[i]->sizeHint().width();
389 if (w > wid)
390 wid = w;
392 for (i = 0; i < end; ++i)
394 mLabels[i]->setFixedWidth(wid - xpos[i]);
395 mLabels[i]->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
397 mLabelsAligned = true;
402 /*=============================================================================
403 = Class MiscPrefTab
404 =============================================================================*/
406 MiscPrefTab::MiscPrefTab(StackedScrollGroup* scrollGroup)
407 : PrefsTabBase(scrollGroup)
409 QGroupBox* group = new QGroupBox(i18nc("@title:group", "Run Mode"));
410 topLayout()->addWidget(group);
411 QVBoxLayout* vlayout = new QVBoxLayout(group);
412 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
413 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
415 // Start at login
416 mAutoStart = new QCheckBox(i18nc("@option:check", "Start at login"), group);
417 connect(mAutoStart, &QAbstractButton::clicked, this, &MiscPrefTab::slotAutostartClicked);
418 mAutoStart->setWhatsThis(xi18nc("@info:whatsthis",
419 "<para>Automatically start <application>KAlarm</application> whenever you start KDE.</para>"
420 "<para>This option should always be checked unless you intend to discontinue use of <application>KAlarm</application>.</para>"));
421 vlayout->addWidget(mAutoStart, 0, Qt::AlignLeft);
423 mQuitWarn = new QCheckBox(i18nc("@option:check", "Warn before quitting"), group);
424 mQuitWarn->setWhatsThis(xi18nc("@info:whatsthis", "Check to display a warning prompt before quitting <application>KAlarm</application>."));
425 vlayout->addWidget(mQuitWarn, 0, Qt::AlignLeft);
427 // Confirm alarm deletion?
428 group = new QGroupBox(i18nc("@title:group", "Deletion"));
429 topLayout()->addWidget(group); // this is to allow left adjustment
430 QVBoxLayout *box = new QVBoxLayout(group);
431 mConfirmAlarmDeletion = new QCheckBox(i18nc("@option:check", "Confirm alarm deletions"));
432 mConfirmAlarmDeletion->setMinimumSize(mConfirmAlarmDeletion->sizeHint());
433 mConfirmAlarmDeletion->setWhatsThis(i18nc("@info:whatsthis", "Check to be prompted for confirmation each time you delete an alarm."));
434 box->addWidget(mConfirmAlarmDeletion);
436 // Default alarm deferral time
437 QWidget *widget = new QWidget;
438 box->addWidget(widget);
439 QHBoxLayout *hbox = new QHBoxLayout(widget);
440 hbox->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
441 QLabel* label = new QLabel(i18nc("@label:spinbox", "Default defer time interval:"));
442 hbox->addWidget(label);
443 mDefaultDeferTime = new TimeSpinBox(1, 5999);
444 mDefaultDeferTime->setMinimumSize(mDefaultDeferTime->sizeHint());
445 hbox->addWidget(mDefaultDeferTime);
446 widget->setWhatsThis(i18nc("@info:whatsthis",
447 "Enter the default time interval (hours & minutes) to defer alarms, used by the Defer Alarm dialog."));
448 label->setBuddy(mDefaultDeferTime);
449 hbox->addStretch(1); // left adjust the controls
451 // Terminal window to use for command alarms
452 group = new QGroupBox(i18nc("@title:group", "Terminal for Command Alarms"));
453 group->setWhatsThis(i18nc("@info:whatsthis", "Choose which application to use when a command alarm is executed in a terminal window"));
454 topLayout()->addWidget(group);
455 QGridLayout* grid = new QGridLayout(group);
456 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
457 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
458 int row = 0;
460 mXtermType = new ButtonGroup(group);
461 int index = 0;
462 mXtermFirst = -1;
463 for (mXtermCount = 0; !xtermCommands[mXtermCount].isNull(); ++mXtermCount)
465 QString cmd = xtermCommands[mXtermCount];
466 QStringList args = KShell::splitArgs(cmd);
467 if (args.isEmpty() || QStandardPaths::findExecutable(args[0]).isEmpty())
468 continue;
469 QRadioButton* radio = new QRadioButton(args[0], group);
470 radio->setMinimumSize(radio->sizeHint());
471 mXtermType->addButton(radio, mXtermCount);
472 if (mXtermFirst < 0)
473 mXtermFirst = mXtermCount; // note the id of the first button
474 cmd.replace(QStringLiteral("%t"), KAboutData::applicationData().displayName());
475 cmd.replace(QStringLiteral("%c"), QStringLiteral("<command>"));
476 cmd.replace(QStringLiteral("%w"), QStringLiteral("<command; sleep>"));
477 cmd.replace(QStringLiteral("%C"), QStringLiteral("[command]"));
478 cmd.replace(QStringLiteral("%W"), QStringLiteral("[command; sleep]"));
479 radio->setWhatsThis(
480 xi18nc("@info:whatsthis", "Check to execute command alarms in a terminal window by <icode>%1</icode>", cmd));
481 grid->addWidget(radio, (row = index/3), index % 3, Qt::AlignLeft);
482 ++index;
485 // QHBox used here doesn't allow the QLineEdit to expand!?
486 QHBoxLayout* hlayout = new QHBoxLayout();
487 hlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
488 grid->addLayout(hlayout, row + 1, 0, 1, 3, Qt::AlignLeft);
489 QRadioButton* radio = new QRadioButton(i18nc("@option:radio Other terminal window command", "Other:"), group);
490 hlayout->addWidget(radio);
491 connect(radio, &QAbstractButton::toggled, this, &MiscPrefTab::slotOtherTerminalToggled);
492 mXtermType->addButton(radio, mXtermCount);
493 if (mXtermFirst < 0)
494 mXtermFirst = mXtermCount; // note the id of the first button
495 mXtermCommand = new QLineEdit(group);
496 mXtermCommand->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
497 hlayout->addWidget(mXtermCommand);
498 QString wt =
499 xi18nc("@info:whatsthis", "Enter the full command line needed to execute a command in your chosen terminal window. "
500 "By default the alarm's command string will be appended to what you enter here. "
501 "See the <application>KAlarm</application> Handbook for details of special codes to tailor the command line.");
502 radio->setWhatsThis(wt);
503 mXtermCommand->setWhatsThis(wt);
505 topLayout()->addStretch(); // top adjust the widgets
508 void MiscPrefTab::restore(bool defaults, bool)
510 mAutoStart->setChecked(defaults ? true : Preferences::autoStart());
511 mQuitWarn->setChecked(Preferences::quitWarn());
512 mConfirmAlarmDeletion->setChecked(Preferences::confirmAlarmDeletion());
513 mDefaultDeferTime->setValue(Preferences::defaultDeferTime());
514 QString xtermCmd = Preferences::cmdXTermCommand();
515 int id = mXtermFirst;
516 if (!xtermCmd.isEmpty())
518 for ( ; id < mXtermCount; ++id)
520 if (mXtermType->find(id) && xtermCmd == xtermCommands[id])
521 break;
524 mXtermType->setButton(id);
525 mXtermCommand->setEnabled(id == mXtermCount);
526 mXtermCommand->setText(id == mXtermCount ? xtermCmd : QString());
529 void MiscPrefTab::apply(bool syncToDisc)
531 // First validate anything entered in Other X-terminal command
532 int xtermID = mXtermType->selectedId();
533 if (xtermID >= mXtermCount)
535 QString cmd = mXtermCommand->text();
536 if (cmd.isEmpty())
537 xtermID = -1; // 'Other' is only acceptable if it's non-blank
538 else
540 QStringList args = KShell::splitArgs(cmd);
541 cmd = args.isEmpty() ? QString() : args[0];
542 if (QStandardPaths::findExecutable(cmd).isEmpty())
544 mXtermCommand->setFocus();
545 if (KAMessageBox::warningContinueCancel(topLayout()->parentWidget(), xi18nc("@info", "Command to invoke terminal window not found: <command>%1</command>", cmd))
546 != KMessageBox::Continue)
547 return;
551 if (xtermID < 0)
553 xtermID = mXtermFirst;
554 mXtermType->setButton(mXtermFirst);
557 if (mQuitWarn->isEnabled())
559 bool b = mQuitWarn->isChecked();
560 if (b != Preferences::quitWarn())
561 Preferences::setQuitWarn(b);
563 bool b = mAutoStart->isChecked();
564 if (b != Preferences::autoStart())
566 Preferences::setAutoStart(b);
567 Preferences::setAskAutoStart(true); // cancel any start-at-login prompt suppression
568 if (b)
569 Preferences::setNoAutoStart(false);
570 Preferences::setAutoStartChangedByUser(true); // prevent prompting the user on quit, about start-at-login
572 b = mConfirmAlarmDeletion->isChecked();
573 if (b != Preferences::confirmAlarmDeletion())
574 Preferences::setConfirmAlarmDeletion(b);
575 int i = mDefaultDeferTime->value();
576 if (i != Preferences::defaultDeferTime())
577 Preferences::setDefaultDeferTime(i);
578 QString text = (xtermID < mXtermCount) ? xtermCommands[xtermID] : mXtermCommand->text();
579 if (text != Preferences::cmdXTermCommand())
580 Preferences::setCmdXTermCommand(text);
581 PrefsTabBase::apply(syncToDisc);
584 void MiscPrefTab::slotAutostartClicked()
586 if (!mAutoStart->isChecked()
587 && KAMessageBox::warningYesNo(topLayout()->parentWidget(),
588 xi18nc("@info", "You should not uncheck this option unless you intend to discontinue use of <application>KAlarm</application>"),
589 QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()
590 ) != KMessageBox::Yes)
591 mAutoStart->setChecked(true);
594 void MiscPrefTab::slotOtherTerminalToggled(bool on)
596 mXtermCommand->setEnabled(on);
600 /*=============================================================================
601 = Class TimePrefTab
602 =============================================================================*/
604 TimePrefTab::TimePrefTab(StackedScrollGroup* scrollGroup)
605 : PrefsTabBase(scrollGroup)
607 // Default time zone
608 ItemBox* itemBox = new ItemBox();
609 itemBox->setMargin(0);
610 qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
612 QWidget *widget = new QWidget; // this is to control the QWhatsThis text display area
613 itemBox->addWidget(widget);
614 QHBoxLayout *box = new QHBoxLayout(widget);
615 box->setMargin(0);
616 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
617 QLabel* label = new QLabel(i18nc("@label:listbox", "Time zone:"));
618 box->addWidget(label);
619 addAlignedLabel(label);
620 #if 1
621 mTimeZone = new TimeZoneCombo(widget);
622 mTimeZone->setMaxVisibleItems(15);
623 box->addWidget(mTimeZone);
624 #else
625 mTimeZone = new KComboBox(box);
626 mTimeZone->setMaxVisibleItems(15);
627 const KTimeZones::ZoneMap zones = KSystemTimeZones::zones();
628 for (KTimeZones::ZoneMap::ConstIterator it = zones.constBegin(); it != zones.constEnd(); ++it)
629 mTimeZone->addItem(it.key());
630 #endif
631 widget->setWhatsThis(xi18nc("@info:whatsthis",
632 "Select the time zone which <application>KAlarm</application> should use "
633 "as its default for displaying and entering dates and times."));
634 label->setBuddy(mTimeZone);
635 itemBox->leftAlign();
637 // Holiday region
638 itemBox = new ItemBox();
639 itemBox->setMargin(0);
640 qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
642 widget = new QWidget; // this is to control the QWhatsThis text display area
643 itemBox->addWidget(widget);
644 box = new QHBoxLayout(widget);
645 box->setMargin(0);
646 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
647 label = new QLabel(i18nc("@label:listbox", "Holiday region:"));
648 addAlignedLabel(label);
649 box->addWidget(label);
650 mHolidays = new QComboBox();
651 mHolidays->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
652 box->addWidget(mHolidays);
653 itemBox->leftAlign();
654 label->setBuddy(mHolidays);
655 widget->setWhatsThis(i18nc("@info:whatsthis",
656 "Select which holiday region to use"));
658 QStringList regions = HolidayRegion::regionCodes();
659 QMap<QString, QString> regionsMap;
660 foreach (const QString& regionCode, regions)
662 QString name = HolidayRegion::name(regionCode);
663 QString languageName = KLocale::global()->languageCodeToName(HolidayRegion::languageCode(regionCode));
664 QString label = languageName.isEmpty() ? name : i18nc("Holiday region, region language", "%1 (%2)", name, languageName);
665 regionsMap.insert(label, regionCode);
668 mHolidays->addItem(i18nc("No holiday region", "None"), QString());
669 for (QMapIterator<QString, QString> it(regionsMap); it.hasNext(); )
671 it.next();
672 mHolidays->addItem(it.key(), it.value());
675 // Start-of-day time
676 itemBox = new ItemBox();
677 itemBox->setMargin(0);
678 qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
680 widget = new QWidget; // this is to control the QWhatsThis text display area
681 itemBox->addWidget(widget);
682 box = new QHBoxLayout(widget);
683 box->setMargin(0);
684 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
685 label = new QLabel(i18nc("@label:spinbox", "Start of day for date-only alarms:"));
686 addAlignedLabel(label);
687 box->addWidget(label);
688 mStartOfDay = new TimeEdit();
689 box->addWidget(mStartOfDay);
690 label->setBuddy(mStartOfDay);
691 widget->setWhatsThis(xi18nc("@info:whatsthis",
692 "<para>The earliest time of day at which a date-only alarm will be triggered.</para>"
693 "<para>%1</para>", TimeSpinBox::shiftWhatsThis()));
694 itemBox->leftAlign();
696 // Working hours
697 QGroupBox* group = new QGroupBox(i18nc("@title:group", "Working Hours"));
698 topLayout()->addWidget(group);
699 QBoxLayout* layout = new QVBoxLayout(group);
700 layout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
701 layout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
703 QWidget* daybox = new QWidget(group); // this is to control the QWhatsThis text display area
704 layout->addWidget(daybox);
705 QGridLayout* wgrid = new QGridLayout(daybox);
706 wgrid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
707 const KLocale* locale = KLocale::global();
708 for (int i = 0; i < 7; ++i)
710 int day = KAlarm::localeDayInWeek_to_weekDay(i);
711 mWorkDays[i] = new QCheckBox(KAlarm::weekDayName(day, locale), daybox);
712 wgrid->addWidget(mWorkDays[i], i/3, i%3, Qt::AlignLeft);
714 daybox->setWhatsThis(i18nc("@info:whatsthis", "Check the days in the week which are work days"));
716 itemBox = new ItemBox(group);
717 itemBox->setMargin(0);
718 layout->addLayout(itemBox);
720 widget = new QWidget; // this is to control the QWhatsThis text display area
721 itemBox->addWidget(widget);
722 box = new QHBoxLayout(widget);
723 box->setMargin(0);
724 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
725 label = new QLabel(i18nc("@label:spinbox", "Daily start time:"));
726 addAlignedLabel(label);
727 box->addWidget(label);
728 mWorkStart = new TimeEdit();
729 box->addWidget(mWorkStart);
730 label->setBuddy(mWorkStart);
731 widget->setWhatsThis(xi18nc("@info:whatsthis",
732 "<para>Enter the start time of the working day.</para>"
733 "<para>%1</para>", TimeSpinBox::shiftWhatsThis()));
734 itemBox->leftAlign();
736 itemBox = new ItemBox(group);
737 itemBox->setMargin(0);
738 layout->addLayout(itemBox);
740 widget = new QWidget; // this is to control the QWhatsThis text display area
741 itemBox->addWidget(widget);
742 box = new QHBoxLayout(widget);
743 box->setMargin(0);
744 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
745 label = new QLabel(i18nc("@label:spinbox", "Daily end time:"));
746 addAlignedLabel(label);
747 box->addWidget(label);
748 mWorkEnd = new TimeEdit();
749 box->addWidget(mWorkEnd);
750 label->setBuddy(mWorkEnd);
751 widget->setWhatsThis(xi18nc("@info:whatsthis",
752 "<para>Enter the end time of the working day.</para>"
753 "<para>%1</para>", TimeSpinBox::shiftWhatsThis()));
754 itemBox->leftAlign();
756 // KOrganizer event duration
757 group = new QGroupBox(i18nc("@title:group", "KOrganizer"));
758 topLayout()->addWidget(group);
759 layout = new QVBoxLayout(group);
760 layout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
761 layout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
763 widget = new QWidget; // this is to control the QWhatsThis text display area
764 layout->addWidget(widget);
765 box = new QHBoxLayout(widget);
766 box->setMargin(0);
767 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
768 label = new QLabel(i18nc("@label:spinbox", "KOrganizer event duration:"));
769 addAlignedLabel(label);
770 box->addWidget(label);
771 mKOrgEventDuration = new TimeSpinBox(0, 5999);
772 mKOrgEventDuration->setMinimumSize(mKOrgEventDuration->sizeHint());
773 box->addWidget(mKOrgEventDuration);
774 widget->setWhatsThis(xi18nc("@info:whatsthis",
775 "<para>Enter the event duration in hours and minutes, for alarms which are copied to KOrganizer.</para>"
776 "<para>%1</para>", TimeSpinBox::shiftWhatsThis()));
777 label->setBuddy(mKOrgEventDuration);
778 box->addStretch(1); // left adjust the controls
780 topLayout()->addStretch(); // top adjust the widgets
783 void TimePrefTab::restore(bool, bool)
785 #if 1
786 mTimeZone->setTimeZone(Preferences::timeZone());
787 #else
788 int tzindex = 0;
789 KTimeZone tz = Preferences::timeZone();
790 if (tz.isValid())
792 QString zone = tz.name();
793 int count = mTimeZone->count();
794 while (tzindex < count && mTimeZone->itemText(tzindex) != zone)
795 ++tzindex;
796 if (tzindex >= count)
797 tzindex = 0;
799 mTimeZone->setCurrentIndex(tzindex);
800 #endif
801 int i = Preferences::holidays().isValid() ? mHolidays->findData(Preferences::holidays().regionCode()) : 0;
802 mHolidays->setCurrentIndex(i);
803 mStartOfDay->setValue(Preferences::startOfDay());
804 mWorkStart->setValue(Preferences::workDayStart());
805 mWorkEnd->setValue(Preferences::workDayEnd());
806 QBitArray days = Preferences::workDays();
807 for (int i = 0; i < 7; ++i)
809 bool x = days.testBit(KAlarm::localeDayInWeek_to_weekDay(i) - 1);
810 mWorkDays[i]->setChecked(x);
812 mKOrgEventDuration->setValue(Preferences::kOrgEventDuration());
815 void TimePrefTab::apply(bool syncToDisc)
817 #if 1
818 KTimeZone tz = mTimeZone->timeZone();
819 if (tz.isValid())
820 Preferences::setTimeZone(tz);
821 #else
822 KTimeZone tz = KSystemTimeZones::zone(mTimeZone->currentText());
823 if (tz.isValid() && tz != Preferences::timeZone())
824 Preferences::setTimeZone(tz);
825 #endif
826 QString hol = mHolidays->itemData(mHolidays->currentIndex()).toString();
827 if (hol != Preferences::holidays().regionCode())
828 Preferences::setHolidayRegion(hol);
829 int t = mStartOfDay->value();
830 QTime sodt(t/60, t%60, 0);
831 if (sodt != Preferences::startOfDay())
832 Preferences::setStartOfDay(sodt);
833 t = mWorkStart->value();
834 Preferences::setWorkDayStart(QTime(t/60, t%60, 0));
835 t = mWorkEnd->value();
836 Preferences::setWorkDayEnd(QTime(t/60, t%60, 0));
837 QBitArray workDays(7);
838 for (int i = 0; i < 7; ++i)
839 if (mWorkDays[i]->isChecked())
840 workDays.setBit(KAlarm::localeDayInWeek_to_weekDay(i) - 1, 1);
841 Preferences::setWorkDays(workDays);
842 Preferences::setKOrgEventDuration(mKOrgEventDuration->value());
843 t = mKOrgEventDuration->value();
844 if (t != Preferences::kOrgEventDuration())
845 Preferences::setKOrgEventDuration(t);
846 PrefsTabBase::apply(syncToDisc);
850 /*=============================================================================
851 = Class StorePrefTab
852 =============================================================================*/
854 StorePrefTab::StorePrefTab(StackedScrollGroup* scrollGroup)
855 : PrefsTabBase(scrollGroup),
856 mCheckKeepChanges(false)
858 // Which resource to save to
859 QGroupBox* group = new QGroupBox(i18nc("@title:group", "New Alarms && Templates"));
860 topLayout()->addWidget(group);
861 QButtonGroup* bgroup = new QButtonGroup(group);
862 QBoxLayout* layout = new QVBoxLayout(group);
863 layout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
864 layout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
866 mDefaultResource = new QRadioButton(i18nc("@option:radio", "Store in default calendar"), group);
867 bgroup->addButton(mDefaultResource);
868 mDefaultResource->setWhatsThis(i18nc("@info:whatsthis", "Add all new alarms and alarm templates to the default calendars, without prompting."));
869 layout->addWidget(mDefaultResource, 0, Qt::AlignLeft);
870 mAskResource = new QRadioButton(i18nc("@option:radio", "Prompt for which calendar to store in"), group);
871 bgroup->addButton(mAskResource);
872 mAskResource->setWhatsThis(xi18nc("@info:whatsthis",
873 "<para>When saving a new alarm or alarm template, prompt for which calendar to store it in, if there is more than one active calendar.</para>"
874 "<para>Note that archived alarms are always stored in the default archived alarm calendar.</para>"));
875 layout->addWidget(mAskResource, 0, Qt::AlignLeft);
877 // Archived alarms
878 group = new QGroupBox(i18nc("@title:group", "Archived Alarms"));
879 topLayout()->addWidget(group);
880 QGridLayout* grid = new QGridLayout(group);
881 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
882 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
883 grid->setColumnStretch(1, 1);
884 grid->setColumnMinimumWidth(0, indentWidth());
885 mKeepArchived = new QCheckBox(i18nc("@option:check", "Keep alarms after expiry"), group);
886 connect(mKeepArchived, &QAbstractButton::toggled, this, &StorePrefTab::slotArchivedToggled);
887 mKeepArchived->setWhatsThis(
888 i18nc("@info:whatsthis", "Check to archive alarms after expiry or deletion (except deleted alarms which were never triggered)."));
889 grid->addWidget(mKeepArchived, 0, 0, 1, 2, Qt::AlignLeft);
891 QWidget *widget = new QWidget;
892 QHBoxLayout *box = new QHBoxLayout(widget);
893 box->setMargin(0);
894 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
895 mPurgeArchived = new QCheckBox(i18nc("@option:check", "Discard archived alarms after:"));
896 mPurgeArchived->setMinimumSize(mPurgeArchived->sizeHint());
897 box->addWidget(mPurgeArchived);
898 connect(mPurgeArchived, &QAbstractButton::toggled, this, &StorePrefTab::slotArchivedToggled);
899 mPurgeAfter = new SpinBox();
900 mPurgeAfter->setMinimum(1);
901 mPurgeAfter->setSingleShiftStep(10);
902 mPurgeAfter->setMinimumSize(mPurgeAfter->sizeHint());
903 box->addWidget(mPurgeAfter);
904 mPurgeAfterLabel = new QLabel(i18nc("@label Time unit for user-entered number", "days"));
905 mPurgeAfterLabel->setMinimumSize(mPurgeAfterLabel->sizeHint());
906 mPurgeAfterLabel->setBuddy(mPurgeAfter);
907 box->addWidget(mPurgeAfterLabel);
908 widget->setWhatsThis(i18nc("@info:whatsthis", "Uncheck to store archived alarms indefinitely. Check to enter how long archived alarms should be stored."));
909 grid->addWidget(widget, 1, 1, Qt::AlignLeft);
911 mClearArchived = new QPushButton(i18nc("@action:button", "Clear Archived Alarms"), group);
912 connect(mClearArchived, &QAbstractButton::clicked, this, &StorePrefTab::slotClearArchived);
913 mClearArchived->setWhatsThis((CollectionControlModel::enabledCollections(CalEvent::ARCHIVED, false).count() <= 1)
914 ? i18nc("@info:whatsthis", "Delete all existing archived alarms.")
915 : i18nc("@info:whatsthis", "Delete all existing archived alarms (from the default archived alarm calendar only)."));
916 grid->addWidget(mClearArchived, 2, 1, Qt::AlignLeft);
918 topLayout()->addStretch(); // top adjust the widgets
921 void StorePrefTab::restore(bool defaults, bool)
923 mCheckKeepChanges = defaults;
924 if (Preferences::askResource())
925 mAskResource->setChecked(true);
926 else
927 mDefaultResource->setChecked(true);
928 int keepDays = Preferences::archivedKeepDays();
929 if (!defaults)
930 mOldKeepArchived = keepDays;
931 setArchivedControls(keepDays);
932 mCheckKeepChanges = true;
935 void StorePrefTab::apply(bool syncToDisc)
937 bool b = mAskResource->isChecked();
938 if (b != Preferences::askResource())
939 Preferences::setAskResource(mAskResource->isChecked());
940 int days = !mKeepArchived->isChecked() ? 0 : mPurgeArchived->isChecked() ? mPurgeAfter->value() : -1;
941 if (days != Preferences::archivedKeepDays())
942 Preferences::setArchivedKeepDays(days);
943 PrefsTabBase::apply(syncToDisc);
946 void StorePrefTab::setArchivedControls(int purgeDays)
948 mKeepArchived->setChecked(purgeDays);
949 mPurgeArchived->setChecked(purgeDays > 0);
950 mPurgeAfter->setValue(purgeDays > 0 ? purgeDays : 0);
951 slotArchivedToggled(true);
954 void StorePrefTab::slotArchivedToggled(bool)
956 bool keep = mKeepArchived->isChecked();
957 if (keep && !mOldKeepArchived && mCheckKeepChanges
958 && !CollectionControlModel::getStandard(CalEvent::ARCHIVED).isValid())
960 KAMessageBox::sorry(topLayout()->parentWidget(),
961 xi18nc("@info", "<para>A default calendar is required in order to archive alarms, but none is currently enabled.</para>"
962 "<para>If you wish to keep expired alarms, please first use the calendars view to select a default "
963 "archived alarms calendar.</para>"));
964 mKeepArchived->setChecked(false);
965 return;
967 mOldKeepArchived = keep;
968 mPurgeArchived->setEnabled(keep);
969 mPurgeAfter->setEnabled(keep && mPurgeArchived->isChecked());
970 mPurgeAfterLabel->setEnabled(keep);
971 mClearArchived->setEnabled(keep);
974 void StorePrefTab::slotClearArchived()
976 bool single = CollectionControlModel::enabledCollections(CalEvent::ARCHIVED, false).count() <= 1;
977 if (KAMessageBox::warningContinueCancel(topLayout()->parentWidget(),
978 single ? i18nc("@info", "Do you really want to delete all archived alarms?")
979 : i18nc("@info", "Do you really want to delete all alarms in the default archived alarm calendar?"))
980 != KMessageBox::Continue)
981 return;
982 theApp()->purgeAll();
986 /*=============================================================================
987 = Class EmailPrefTab
988 =============================================================================*/
990 EmailPrefTab::EmailPrefTab(StackedScrollGroup* scrollGroup)
991 : PrefsTabBase(scrollGroup),
992 mAddressChanged(false),
993 mBccAddressChanged(false)
995 QWidget *widget = new QWidget;
996 topLayout()->addWidget(widget);
997 QHBoxLayout *box = new QHBoxLayout(widget);
998 box->setSpacing(2 * style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
999 QLabel *label = new QLabel(i18nc("@label", "Email client:"));
1000 box->addWidget(label);
1001 mEmailClient = new ButtonGroup(widget);
1002 QString kmailOption = i18nc("@option:radio", "KMail");
1003 QString sendmailOption = i18nc("@option:radio", "Sendmail");
1004 mKMailButton = new RadioButton(kmailOption);
1005 mKMailButton->setMinimumSize(mKMailButton->sizeHint());
1006 box->addWidget(mKMailButton);
1007 mEmailClient->addButton(mKMailButton, Preferences::kmail);
1008 mSendmailButton = new RadioButton(sendmailOption);
1009 mSendmailButton->setMinimumSize(mSendmailButton->sizeHint());
1010 box->addWidget(mSendmailButton);
1011 mEmailClient->addButton(mSendmailButton, Preferences::sendmail);
1012 connect(mEmailClient, &ButtonGroup::buttonSet, this, &EmailPrefTab::slotEmailClientChanged);
1013 widget->setWhatsThis(xi18nc("@info:whatsthis",
1014 "<para>Choose how to send email when an email alarm is triggered."
1015 "<list><item><interface>%1</interface>: The email is sent automatically via <application>KMail</application>. <application>KMail</application> is started first if necessary.</item>"
1016 "<item><interface>%2</interface>: The email is sent automatically. This option will only work if "
1017 "your system is configured to use <application>sendmail</application> or a sendmail compatible mail transport agent.</item></list></para>",
1018 kmailOption, sendmailOption));
1020 widget = new QWidget; // this is to allow left adjustment
1021 topLayout()->addWidget(widget);
1022 box = new QHBoxLayout(widget);
1023 mEmailCopyToKMail = new QCheckBox(xi18nc("@option:check", "Copy sent emails into <application>KMail</application>'s <resource>%1</resource> folder", KAMail::i18n_sent_mail()));
1024 mEmailCopyToKMail->setWhatsThis(xi18nc("@info:whatsthis", "After sending an email, store a copy in <application>KMail</application>'s <resource>%1</resource> folder", KAMail::i18n_sent_mail()));
1025 box->addWidget(mEmailCopyToKMail);
1026 box->setStretchFactor(new QWidget(widget), 1); // left adjust the controls
1028 widget = new QWidget; // this is to allow left adjustment
1029 topLayout()->addWidget(widget);
1030 box = new QHBoxLayout(widget);
1031 mEmailQueuedNotify = new QCheckBox(i18nc("@option:check", "Notify when remote emails are queued"));
1032 mEmailQueuedNotify->setWhatsThis(
1033 i18nc("@info:whatsthis", "Display a notification message whenever an email alarm has queued an email for sending to a remote system. "
1034 "This could be useful if, for example, you have a dial-up connection, so that you can then ensure that the email is actually transmitted."));
1035 box->addWidget(mEmailQueuedNotify);
1036 box->setStretchFactor(new QWidget(widget), 1); // left adjust the controls
1038 // Your Email Address group box
1039 QGroupBox* group = new QGroupBox(i18nc("@title:group", "Your Email Address"));
1040 topLayout()->addWidget(group);
1041 QGridLayout* grid = new QGridLayout(group);
1042 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1043 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1044 grid->setColumnStretch(2, 1);
1046 // 'From' email address controls ...
1047 label = new Label(i18nc("@label 'From' email address", "From:"), group);
1048 grid->addWidget(label, 1, 0);
1049 mFromAddressGroup = new ButtonGroup(group);
1050 connect(mFromAddressGroup, &ButtonGroup::buttonSet, this, &EmailPrefTab::slotFromAddrChanged);
1052 // Line edit to enter a 'From' email address
1053 mFromAddrButton = new RadioButton(group);
1054 mFromAddressGroup->addButton(mFromAddrButton, Preferences::MAIL_FROM_ADDR);
1055 label->setBuddy(mFromAddrButton);
1056 grid->addWidget(mFromAddrButton, 1, 1);
1057 mEmailAddress = new QLineEdit(group);
1058 connect(mEmailAddress, &QLineEdit::textChanged, this, &EmailPrefTab::slotAddressChanged);
1059 QString whatsThis = i18nc("@info:whatsthis", "Your email address, used to identify you as the sender when sending email alarms.");
1060 mFromAddrButton->setWhatsThis(whatsThis);
1061 mEmailAddress->setWhatsThis(whatsThis);
1062 mFromAddrButton->setFocusWidget(mEmailAddress);
1063 grid->addWidget(mEmailAddress, 1, 2);
1065 // 'From' email address to be taken from System Settings
1066 mFromCCentreButton = new RadioButton(i18nc("@option:radio", "Use address from System Settings"), group);
1067 mFromAddressGroup->addButton(mFromCCentreButton, Preferences::MAIL_FROM_SYS_SETTINGS);
1068 mFromCCentreButton->setWhatsThis(
1069 i18nc("@info:whatsthis", "Check to use the email address set in KDE System Settings, to identify you as the sender when sending email alarms."));
1070 grid->addWidget(mFromCCentreButton, 2, 1, 1, 2, Qt::AlignLeft);
1072 // 'From' email address to be picked from KMail's identities when the email alarm is configured
1073 mFromKMailButton = new RadioButton(xi18nc("@option:radio", "Use <application>KMail</application> identities"), group);
1074 mFromAddressGroup->addButton(mFromKMailButton, Preferences::MAIL_FROM_KMAIL);
1075 mFromKMailButton->setWhatsThis(
1076 xi18nc("@info:whatsthis", "Check to use <application>KMail</application>'s email identities to identify you as the sender when sending email alarms. "
1077 "For existing email alarms, <application>KMail</application>'s default identity will be used. "
1078 "For new email alarms, you will be able to pick which of <application>KMail</application>'s identities to use."));
1079 grid->addWidget(mFromKMailButton, 3, 1, 1, 2, Qt::AlignLeft);
1081 // 'Bcc' email address controls ...
1082 grid->setRowMinimumHeight(4, style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1083 label = new Label(i18nc("@label 'Bcc' email address", "Bcc:"), group);
1084 grid->addWidget(label, 5, 0);
1085 mBccAddressGroup = new ButtonGroup(group);
1086 connect(mBccAddressGroup, &ButtonGroup::buttonSet, this, &EmailPrefTab::slotBccAddrChanged);
1088 // Line edit to enter a 'Bcc' email address
1089 mBccAddrButton = new RadioButton(group);
1090 mBccAddressGroup->addButton(mBccAddrButton, Preferences::MAIL_FROM_ADDR);
1091 label->setBuddy(mBccAddrButton);
1092 grid->addWidget(mBccAddrButton, 5, 1);
1093 mEmailBccAddress = new QLineEdit(group);
1094 whatsThis = xi18nc("@info:whatsthis", "Your email address, used for blind copying email alarms to yourself. "
1095 "If you want blind copies to be sent to your account on the computer which <application>KAlarm</application> runs on, you can simply enter your user login name.");
1096 mBccAddrButton->setWhatsThis(whatsThis);
1097 mEmailBccAddress->setWhatsThis(whatsThis);
1098 mBccAddrButton->setFocusWidget(mEmailBccAddress);
1099 grid->addWidget(mEmailBccAddress, 5, 2);
1101 // 'Bcc' email address to be taken from System Settings
1102 mBccCCentreButton = new RadioButton(i18nc("@option:radio", "Use address from System Settings"), group);
1103 mBccAddressGroup->addButton(mBccCCentreButton, Preferences::MAIL_FROM_SYS_SETTINGS);
1104 mBccCCentreButton->setWhatsThis(
1105 i18nc("@info:whatsthis", "Check to use the email address set in KDE System Settings, for blind copying email alarms to yourself."));
1106 grid->addWidget(mBccCCentreButton, 6, 1, 1, 2, Qt::AlignLeft);
1108 topLayout()->addStretch(); // top adjust the widgets
1111 void EmailPrefTab::restore(bool defaults, bool)
1113 mEmailClient->setButton(Preferences::emailClient());
1114 mEmailCopyToKMail->setChecked(Preferences::emailCopyToKMail());
1115 setEmailAddress(Preferences::emailFrom(), Preferences::emailAddress());
1116 setEmailBccAddress((Preferences::emailBccFrom() == Preferences::MAIL_FROM_SYS_SETTINGS), Preferences::emailBccAddress());
1117 mEmailQueuedNotify->setChecked(Preferences::emailQueuedNotify());
1118 if (!defaults)
1119 mAddressChanged = mBccAddressChanged = false;
1122 void EmailPrefTab::apply(bool syncToDisc)
1124 int client = mEmailClient->selectedId();
1125 if (client >= 0 && static_cast<Preferences::MailClient>(client) != Preferences::emailClient())
1126 Preferences::setEmailClient(static_cast<Preferences::MailClient>(client));
1127 bool b = mEmailCopyToKMail->isChecked();
1128 if (b != Preferences::emailCopyToKMail())
1129 Preferences::setEmailCopyToKMail(b);
1130 int from = mFromAddressGroup->selectedId();
1131 QString text = mEmailAddress->text().trimmed();
1132 if ((from >= 0 && static_cast<Preferences::MailFrom>(from) != Preferences::emailFrom())
1133 || text != Preferences::emailAddress())
1134 Preferences::setEmailAddress(static_cast<Preferences::MailFrom>(from), text);
1135 b = (mBccAddressGroup->checkedButton() == mBccCCentreButton);
1136 Preferences::MailFrom bfrom = b ? Preferences::MAIL_FROM_SYS_SETTINGS : Preferences::MAIL_FROM_ADDR;;
1137 text = mEmailBccAddress->text().trimmed();
1138 if (bfrom != Preferences::emailBccFrom() || text != Preferences::emailBccAddress())
1139 Preferences::setEmailBccAddress(b, text);
1140 b = mEmailQueuedNotify->isChecked();
1141 if (b != Preferences::emailQueuedNotify())
1142 Preferences::setEmailQueuedNotify(mEmailQueuedNotify->isChecked());
1143 PrefsTabBase::apply(syncToDisc);
1146 void EmailPrefTab::setEmailAddress(Preferences::MailFrom from, const QString& address)
1148 mFromAddressGroup->setButton(from);
1149 mEmailAddress->setText(from == Preferences::MAIL_FROM_ADDR ? address.trimmed() : QString());
1152 void EmailPrefTab::setEmailBccAddress(bool useSystemSettings, const QString& address)
1154 mBccAddressGroup->setButton(useSystemSettings ? Preferences::MAIL_FROM_SYS_SETTINGS : Preferences::MAIL_FROM_ADDR);
1155 mEmailBccAddress->setText(useSystemSettings ? QString() : address.trimmed());
1158 void EmailPrefTab::slotEmailClientChanged(QAbstractButton* button)
1160 mEmailCopyToKMail->setEnabled(button == mSendmailButton);
1163 void EmailPrefTab::slotFromAddrChanged(QAbstractButton* button)
1165 mEmailAddress->setEnabled(button == mFromAddrButton);
1166 mAddressChanged = true;
1169 void EmailPrefTab::slotBccAddrChanged(QAbstractButton* button)
1171 mEmailBccAddress->setEnabled(button == mBccAddrButton);
1172 mBccAddressChanged = true;
1175 QString EmailPrefTab::validate()
1177 if (mAddressChanged)
1179 mAddressChanged = false;
1180 QString errmsg = validateAddr(mFromAddressGroup, mEmailAddress, KAMail::i18n_NeedFromEmailAddress());
1181 if (!errmsg.isEmpty())
1182 return errmsg;
1184 if (mBccAddressChanged)
1186 mBccAddressChanged = false;
1187 return validateAddr(mBccAddressGroup, mEmailBccAddress, i18nc("@info", "No valid 'Bcc' email address is specified."));
1189 return QString();
1192 QString EmailPrefTab::validateAddr(ButtonGroup* group, QLineEdit* addr, const QString& msg)
1194 QString errmsg = xi18nc("@info", "<para>%1</para><para>Are you sure you want to save your changes?</para>", msg);
1195 switch (group->selectedId())
1197 case Preferences::MAIL_FROM_SYS_SETTINGS:
1198 if (!KAMail::controlCentreAddress().isEmpty())
1199 return QString();
1200 errmsg = i18nc("@info", "No email address is currently set in KDE System Settings. %1", errmsg);
1201 break;
1202 case Preferences::MAIL_FROM_KMAIL:
1203 if (Identities::identitiesExist())
1204 return QString();
1205 errmsg = xi18nc("@info", "No <application>KMail</application> identities currently exist. %1", errmsg);
1206 break;
1207 case Preferences::MAIL_FROM_ADDR:
1208 if (!addr->text().trimmed().isEmpty())
1209 return QString();
1210 break;
1212 return errmsg;
1216 /*=============================================================================
1217 = Class EditPrefTab
1218 =============================================================================*/
1220 EditPrefTab::EditPrefTab(StackedScrollGroup* scrollGroup)
1221 : PrefsTabBase(scrollGroup)
1223 KLocalizedString defsetting = kxi18nc("@info:whatsthis", "The default setting for <interface>%1</interface> in the alarm edit dialog.");
1225 mTabs = new QTabWidget();
1226 topLayout()->addWidget(mTabs);
1227 StackedGroupT<QWidget>* tabgroup = new StackedGroupT<QWidget>(mTabs);
1229 StackedWidgetT<QWidget>* topGeneral = new StackedWidgetT<QWidget>(tabgroup);
1230 QVBoxLayout *tgLayout = new QVBoxLayout(topGeneral);
1231 mTabGeneral = mTabs->addTab(topGeneral, i18nc("@title:tab", "General"));
1233 StackedWidgetT<QWidget>* topTypes = new StackedWidgetT<QWidget>(tabgroup);
1234 QVBoxLayout *ttLayout = new QVBoxLayout(topTypes);
1235 mTabTypes = mTabs->addTab(topTypes, i18nc("@title:tab", "Alarm Types"));
1237 StackedWidgetT<QWidget>* topFontColour = new StackedWidgetT<QWidget>(tabgroup);
1238 QVBoxLayout *tfLayout = new QVBoxLayout(topFontColour);
1239 mTabFontColour = mTabs->addTab(topFontColour, i18nc("@title:tab", "Font && Color"));
1241 // MISCELLANEOUS
1242 // Show in KOrganizer
1243 mCopyToKOrganizer = new QCheckBox(EditAlarmDlg::i18n_chk_ShowInKOrganizer());
1244 mCopyToKOrganizer->setMinimumSize(mCopyToKOrganizer->sizeHint());
1245 mCopyToKOrganizer->setWhatsThis(defsetting.subs(EditAlarmDlg::i18n_chk_ShowInKOrganizer()).toString());
1246 tgLayout->addWidget(mCopyToKOrganizer);
1248 // Late cancellation
1249 QWidget *widget = new QWidget;
1250 tgLayout->addWidget(widget);
1251 QHBoxLayout *box = new QHBoxLayout(widget);
1252 box->setMargin(0);
1253 box->setSpacing(0);
1254 mLateCancel = new QCheckBox(LateCancelSelector::i18n_chk_CancelIfLate());
1255 mLateCancel->setMinimumSize(mLateCancel->sizeHint());
1256 mLateCancel->setWhatsThis(defsetting.subs(LateCancelSelector::i18n_chk_CancelIfLate()).toString());
1257 box->addWidget(mLateCancel);
1259 // Recurrence
1260 widget = new QWidget; // this is to control the QWhatsThis text display area
1261 tgLayout->addWidget(widget);
1262 box = new QHBoxLayout(widget);
1263 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1264 box->setMargin(0);
1265 QLabel* label = new QLabel(i18nc("@label:listbox", "Recurrence:"));
1266 box->addWidget(label);
1267 mRecurPeriod = new ComboBox();
1268 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_NoRecur());
1269 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_AtLogin());
1270 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_HourlyMinutely());
1271 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_Daily());
1272 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_Weekly());
1273 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_Monthly());
1274 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_Yearly());
1275 box->addWidget(mRecurPeriod);
1276 box->addStretch();
1277 label->setBuddy(mRecurPeriod);
1278 widget->setWhatsThis(i18nc("@info:whatsthis", "The default setting for the recurrence rule in the alarm edit dialog."));
1280 // How to handle February 29th in yearly recurrences
1281 QWidget *febBox = new QWidget; // this is to control the QWhatsThis text display area
1282 tgLayout->addWidget(febBox);
1283 QVBoxLayout *vbox = new QVBoxLayout(febBox);
1284 vbox->setMargin(0);
1285 vbox->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1286 label = new QLabel(i18nc("@label", "In non-leap years, repeat yearly February 29th alarms on:"));
1287 label->setAlignment(Qt::AlignLeft);
1288 label->setWordWrap(true);
1289 vbox->addWidget(label);
1290 box = new QHBoxLayout();
1291 vbox->addLayout(box);
1292 vbox->setMargin(0);
1293 box->setSpacing(2 * style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1294 mFeb29 = new ButtonGroup(febBox);
1295 widget = new QWidget();
1296 widget->setFixedWidth(3 * style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1297 box->addWidget(widget);
1298 QRadioButton* radio = new QRadioButton(i18nc("@option:radio", "February 2&8th"));
1299 radio->setMinimumSize(radio->sizeHint());
1300 box->addWidget(radio);
1301 mFeb29->addButton(radio, Preferences::Feb29_Feb28);
1302 radio = new QRadioButton(i18nc("@option:radio", "March &1st"));
1303 radio->setMinimumSize(radio->sizeHint());
1304 box->addWidget(radio);
1305 mFeb29->addButton(radio, Preferences::Feb29_Mar1);
1306 radio = new QRadioButton(i18nc("@option:radio", "Do not repeat"));
1307 radio->setMinimumSize(radio->sizeHint());
1308 box->addWidget(radio);
1309 mFeb29->addButton(radio, Preferences::Feb29_None);
1310 febBox->setWhatsThis(xi18nc("@info:whatsthis",
1311 "For yearly recurrences, choose what date, if any, alarms due on February 29th should occur in non-leap years."
1312 "<note>The next scheduled occurrence of existing alarms is not re-evaluated when you change this setting.</note>"));
1314 tgLayout->addStretch(); // top adjust the widgets
1316 // DISPLAY ALARMS
1317 QGroupBox* group = new QGroupBox(i18nc("@title:group", "Display Alarms"));
1318 ttLayout->addWidget(group);
1319 QVBoxLayout* vlayout = new QVBoxLayout(group);
1320 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1321 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1323 mConfirmAck = new QCheckBox(EditDisplayAlarmDlg::i18n_chk_ConfirmAck());
1324 mConfirmAck->setMinimumSize(mConfirmAck->sizeHint());
1325 mConfirmAck->setWhatsThis(defsetting.subs(EditDisplayAlarmDlg::i18n_chk_ConfirmAck()).toString());
1326 vlayout->addWidget(mConfirmAck, 0, Qt::AlignLeft);
1328 mAutoClose = new QCheckBox(LateCancelSelector::i18n_chk_AutoCloseWinLC());
1329 mAutoClose->setMinimumSize(mAutoClose->sizeHint());
1330 mAutoClose->setWhatsThis(defsetting.subs(LateCancelSelector::i18n_chk_AutoCloseWin()).toString());
1331 vlayout->addWidget(mAutoClose, 0, Qt::AlignLeft);
1333 widget = new QWidget;
1334 vlayout->addWidget(widget);
1335 box = new QHBoxLayout(widget);
1336 box->setMargin(0);
1337 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1338 label = new QLabel(i18nc("@label:listbox", "Reminder units:"));
1339 box->addWidget(label);
1340 mReminderUnits = new QComboBox();
1341 mReminderUnits->addItem(i18nc("@item:inlistbox", "Minutes"), TimePeriod::Minutes);
1342 mReminderUnits->addItem(i18nc("@item:inlistbox", "Hours/Minutes"), TimePeriod::HoursMinutes);
1343 box->addWidget(mReminderUnits);
1344 label->setBuddy(mReminderUnits);
1345 widget->setWhatsThis(i18nc("@info:whatsthis", "The default units for the reminder in the alarm edit dialog, for alarms due soon."));
1346 box->addStretch(1); // left adjust the control
1347 mSpecialActionsButton = new SpecialActionsButton(true);
1348 box->addWidget(mSpecialActionsButton);
1350 // SOUND
1351 QGroupBox* bbox = new QGroupBox(i18nc("@title:group Audio options group", "Sound"));
1352 ttLayout->addWidget(bbox);
1353 vlayout = new QVBoxLayout(bbox);
1354 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1355 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1357 QHBoxLayout *hlayout = new QHBoxLayout;
1358 hlayout->setMargin(0);
1359 vlayout->addLayout(hlayout);
1360 mSound = new QComboBox();
1361 mSound->addItem(SoundPicker::i18n_combo_None()); // index 0
1362 mSound->addItem(SoundPicker::i18n_combo_Beep()); // index 1
1363 mSound->addItem(SoundPicker::i18n_combo_File()); // index 2
1364 if (KPIMTextEdit::TextToSpeech::self()->isReady())
1365 mSound->addItem(SoundPicker::i18n_combo_Speak()); // index 3
1366 mSound->setMinimumSize(mSound->sizeHint());
1367 mSound->setWhatsThis(defsetting.subs(SoundPicker::i18n_label_Sound()).toString());
1368 hlayout->addWidget(mSound);
1369 hlayout->addStretch();
1370 mSoundRepeat = new QCheckBox(i18nc("@option:check", "Repeat sound file"));
1371 mSoundRepeat->setMinimumSize(mSoundRepeat->sizeHint());
1372 mSoundRepeat->setWhatsThis(
1373 xi18nc("@info:whatsthis sound file 'Repeat' checkbox", "The default setting for sound file <interface>%1</interface> in the alarm edit dialog.", SoundWidget::i18n_chk_Repeat()));
1374 hlayout->addWidget(mSoundRepeat);
1376 widget = new QWidget; // this is to control the QWhatsThis text display area
1377 box = new QHBoxLayout(widget);
1378 box->setMargin(0);
1379 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1380 mSoundFileLabel = new QLabel(i18nc("@label:textbox", "Sound file:"));
1381 box->addWidget(mSoundFileLabel);
1382 mSoundFile = new QLineEdit();
1383 box->addWidget(mSoundFile);
1384 mSoundFileLabel->setBuddy(mSoundFile);
1385 mSoundFileBrowse = new QPushButton();
1386 mSoundFileBrowse->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
1387 connect(mSoundFileBrowse, &QAbstractButton::clicked, this, &EditPrefTab::slotBrowseSoundFile);
1388 mSoundFileBrowse->setToolTip(i18nc("@info:tooltip", "Choose a sound file"));
1389 box->addWidget(mSoundFileBrowse);
1390 widget->setWhatsThis(i18nc("@info:whatsthis", "Enter the default sound file to use in the alarm edit dialog."));
1391 vlayout->addWidget(widget);
1393 // COMMAND ALARMS
1394 group = new QGroupBox(i18nc("@title:group", "Command Alarms"));
1395 ttLayout->addWidget(group);
1396 vlayout = new QVBoxLayout(group);
1397 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1398 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1399 hlayout = new QHBoxLayout();
1400 hlayout->setMargin(0);
1401 vlayout->addLayout(hlayout);
1403 mCmdScript = new QCheckBox(EditCommandAlarmDlg::i18n_chk_EnterScript(), group);
1404 mCmdScript->setMinimumSize(mCmdScript->sizeHint());
1405 mCmdScript->setWhatsThis(defsetting.subs(EditCommandAlarmDlg::i18n_chk_EnterScript()).toString());
1406 hlayout->addWidget(mCmdScript);
1407 hlayout->addStretch();
1409 mCmdXterm = new QCheckBox(EditCommandAlarmDlg::i18n_chk_ExecInTermWindow(), group);
1410 mCmdXterm->setMinimumSize(mCmdXterm->sizeHint());
1411 mCmdXterm->setWhatsThis(defsetting.subs(EditCommandAlarmDlg::i18n_radio_ExecInTermWindow()).toString());
1412 hlayout->addWidget(mCmdXterm);
1414 // EMAIL ALARMS
1415 group = new QGroupBox(i18nc("@title:group", "Email Alarms"));
1416 ttLayout->addWidget(group);
1417 vlayout = new QVBoxLayout(group);
1418 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1419 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1421 // BCC email to sender
1422 mEmailBcc = new QCheckBox(EditEmailAlarmDlg::i18n_chk_CopyEmailToSelf(), group);
1423 mEmailBcc->setMinimumSize(mEmailBcc->sizeHint());
1424 mEmailBcc->setWhatsThis(defsetting.subs(EditEmailAlarmDlg::i18n_chk_CopyEmailToSelf()).toString());
1425 vlayout->addWidget(mEmailBcc, 0, Qt::AlignLeft);
1427 ttLayout->addStretch();
1429 // FONT / COLOUR TAB
1430 mFontChooser = new FontColourChooser(topFontColour, QStringList(), i18nc("@title:group", "Message Font && Color"), true);
1431 tfLayout->addWidget(mFontChooser);
1434 void EditPrefTab::restore(bool, bool allTabs)
1436 int index;
1437 if (allTabs || mTabs->currentIndex() == mTabGeneral)
1439 mCopyToKOrganizer->setChecked(Preferences::defaultCopyToKOrganizer());
1440 mLateCancel->setChecked(Preferences::defaultLateCancel());
1441 switch (Preferences::defaultRecurPeriod())
1443 case Preferences::Recur_Yearly: index = 6; break;
1444 case Preferences::Recur_Monthly: index = 5; break;
1445 case Preferences::Recur_Weekly: index = 4; break;
1446 case Preferences::Recur_Daily: index = 3; break;
1447 case Preferences::Recur_SubDaily: index = 2; break;
1448 case Preferences::Recur_Login: index = 1; break;
1449 case Preferences::Recur_None:
1450 default: index = 0; break;
1452 mRecurPeriod->setCurrentIndex(index);
1453 mFeb29->setButton(Preferences::defaultFeb29Type());
1455 if (allTabs || mTabs->currentIndex() == mTabTypes)
1457 mConfirmAck->setChecked(Preferences::defaultConfirmAck());
1458 mAutoClose->setChecked(Preferences::defaultAutoClose());
1459 switch (Preferences::defaultReminderUnits())
1461 case TimePeriod::Weeks: index = 3; break;
1462 case TimePeriod::Days: index = 2; break;
1463 default:
1464 case TimePeriod::HoursMinutes: index = 1; break;
1465 case TimePeriod::Minutes: index = 0; break;
1467 mReminderUnits->setCurrentIndex(index);
1468 KAEvent::ExtraActionOptions opts(0);
1469 if (Preferences::defaultExecPreActionOnDeferral())
1470 opts |= KAEvent::ExecPreActOnDeferral;
1471 if (Preferences::defaultCancelOnPreActionError())
1472 opts |= KAEvent::CancelOnPreActError;
1473 if (Preferences::defaultDontShowPreActionError())
1474 opts |= KAEvent::DontShowPreActError;
1475 mSpecialActionsButton->setActions(Preferences::defaultPreAction(), Preferences::defaultPostAction(), opts);
1476 mSound->setCurrentIndex(soundIndex(Preferences::defaultSoundType()));
1477 mSoundFile->setText(Preferences::defaultSoundFile());
1478 mSoundRepeat->setChecked(Preferences::defaultSoundRepeat());
1479 mCmdScript->setChecked(Preferences::defaultCmdScript());
1480 mCmdXterm->setChecked(Preferences::defaultCmdLogType() == Preferences::Log_Terminal);
1481 mEmailBcc->setChecked(Preferences::defaultEmailBcc());
1483 if (allTabs || mTabs->currentIndex() == mTabFontColour)
1485 mFontChooser->setFgColour(Preferences::defaultFgColour());
1486 mFontChooser->setBgColour(Preferences::defaultBgColour());
1487 mFontChooser->setFont(Preferences::messageFont());
1491 void EditPrefTab::apply(bool syncToDisc)
1493 bool b = mAutoClose->isChecked();
1494 if (b != Preferences::defaultAutoClose())
1495 Preferences::setDefaultAutoClose(b);
1496 b = mConfirmAck->isChecked();
1497 if (b != Preferences::defaultConfirmAck())
1498 Preferences::setDefaultConfirmAck(b);
1499 TimePeriod::Units units;
1500 switch (mReminderUnits->currentIndex())
1502 case 3: units = TimePeriod::Weeks; break;
1503 case 2: units = TimePeriod::Days; break;
1504 default:
1505 case 1: units = TimePeriod::HoursMinutes; break;
1506 case 0: units = TimePeriod::Minutes; break;
1508 if (units != Preferences::defaultReminderUnits())
1509 Preferences::setDefaultReminderUnits(units);
1510 QString text = mSpecialActionsButton->preAction();
1511 if (text != Preferences::defaultPreAction())
1512 Preferences::setDefaultPreAction(text);
1513 text = mSpecialActionsButton->postAction();
1514 if (text != Preferences::defaultPostAction())
1515 Preferences::setDefaultPostAction(text);
1516 KAEvent::ExtraActionOptions opts = mSpecialActionsButton->options();
1517 b = opts & KAEvent::ExecPreActOnDeferral;
1518 if (b != Preferences::defaultExecPreActionOnDeferral())
1519 Preferences::setDefaultExecPreActionOnDeferral(b);
1520 b = opts & KAEvent::CancelOnPreActError;
1521 if (b != Preferences::defaultCancelOnPreActionError())
1522 Preferences::setDefaultCancelOnPreActionError(b);
1523 b = opts & KAEvent::DontShowPreActError;
1524 if (b != Preferences::defaultDontShowPreActionError())
1525 Preferences::setDefaultDontShowPreActionError(b);
1526 Preferences::SoundType snd;
1527 switch (mSound->currentIndex())
1529 case 3: snd = Preferences::Sound_Speak; break;
1530 case 2: snd = Preferences::Sound_File; break;
1531 case 1: snd = Preferences::Sound_Beep; break;
1532 case 0:
1533 default: snd = Preferences::Sound_None; break;
1535 if (snd != Preferences::defaultSoundType())
1536 Preferences::setDefaultSoundType(snd);
1537 text = mSoundFile->text();
1538 if (text != Preferences::defaultSoundFile())
1539 Preferences::setDefaultSoundFile(text);
1540 b = mSoundRepeat->isChecked();
1541 if (b != Preferences::defaultSoundRepeat())
1542 Preferences::setDefaultSoundRepeat(b);
1543 b = mCmdScript->isChecked();
1544 if (b != Preferences::defaultCmdScript())
1545 Preferences::setDefaultCmdScript(b);
1546 Preferences::CmdLogType log = mCmdXterm->isChecked() ? Preferences::Log_Terminal : Preferences::Log_Discard;
1547 if (log != Preferences::defaultCmdLogType())
1548 Preferences::setDefaultCmdLogType(log);
1549 b = mEmailBcc->isChecked();
1550 if (b != Preferences::defaultEmailBcc())
1551 Preferences::setDefaultEmailBcc(b);
1552 b = mCopyToKOrganizer->isChecked();
1553 if (b != Preferences::defaultCopyToKOrganizer())
1554 Preferences::setDefaultCopyToKOrganizer(b);
1555 int i = mLateCancel->isChecked() ? 1 : 0;
1556 if (i != Preferences::defaultLateCancel())
1557 Preferences::setDefaultLateCancel(i);
1558 Preferences::RecurType period;
1559 switch (mRecurPeriod->currentIndex())
1561 case 6: period = Preferences::Recur_Yearly; break;
1562 case 5: period = Preferences::Recur_Monthly; break;
1563 case 4: period = Preferences::Recur_Weekly; break;
1564 case 3: period = Preferences::Recur_Daily; break;
1565 case 2: period = Preferences::Recur_SubDaily; break;
1566 case 1: period = Preferences::Recur_Login; break;
1567 case 0:
1568 default: period = Preferences::Recur_None; break;
1570 if (period != Preferences::defaultRecurPeriod())
1571 Preferences::setDefaultRecurPeriod(period);
1572 int feb29 = mFeb29->selectedId();
1573 if (feb29 >= 0 && static_cast<Preferences::Feb29Type>(feb29) != Preferences::defaultFeb29Type())
1574 Preferences::setDefaultFeb29Type(static_cast<Preferences::Feb29Type>(feb29));
1575 QColor colour = mFontChooser->fgColour();
1576 if (colour != Preferences::defaultFgColour())
1577 Preferences::setDefaultFgColour(colour);
1578 colour = mFontChooser->bgColour();
1579 if (colour != Preferences::defaultBgColour())
1580 Preferences::setDefaultBgColour(colour);
1581 QFont font = mFontChooser->font();
1582 if (font != Preferences::messageFont())
1583 Preferences::setMessageFont(font);
1584 PrefsTabBase::apply(syncToDisc);
1587 void EditPrefTab::slotBrowseSoundFile()
1589 QString defaultDir;
1590 QString url = SoundPicker::browseFile(defaultDir, mSoundFile->text());
1591 if (!url.isEmpty())
1592 mSoundFile->setText(url);
1595 int EditPrefTab::soundIndex(Preferences::SoundType type)
1597 switch (type)
1599 case Preferences::Sound_Speak: return 3;
1600 case Preferences::Sound_File: return 2;
1601 case Preferences::Sound_Beep: return 1;
1602 case Preferences::Sound_None:
1603 default: return 0;
1607 QString EditPrefTab::validate()
1609 if (mSound->currentIndex() == soundIndex(Preferences::Sound_File) && mSoundFile->text().isEmpty())
1611 mSoundFile->setFocus();
1612 return xi18nc("@info", "You must enter a sound file when <interface>%1</interface> is selected as the default sound type", SoundPicker::i18n_combo_File());;
1614 return QString();
1618 /*=============================================================================
1619 = Class ViewPrefTab
1620 =============================================================================*/
1622 ViewPrefTab::ViewPrefTab(StackedScrollGroup* scrollGroup)
1623 : PrefsTabBase(scrollGroup)
1625 mTabs = new QTabWidget();
1626 topLayout()->addWidget(mTabs);
1628 QWidget *widget = new QWidget;
1629 QVBoxLayout *topGeneral = new QVBoxLayout(widget);
1630 topGeneral->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin) / 2);
1631 topGeneral->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1632 mTabGeneral = mTabs->addTab(widget, i18nc("@title:tab", "General"));
1634 widget = new QWidget;
1635 QVBoxLayout *topWindows = new QVBoxLayout(widget);
1636 topWindows->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin) / 2);
1637 topWindows->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1638 mTabWindows = mTabs->addTab(widget, i18nc("@title:tab", "Alarm Windows"));
1640 // Run-in-system-tray group box
1641 mShowInSystemTray = new QGroupBox(i18nc("@option:check", "Show in system tray"));
1642 mShowInSystemTray->setCheckable(true);
1643 mShowInSystemTray->setWhatsThis(
1644 xi18nc("@info:whatsthis", "<para>Check to show <application>KAlarm</application>'s icon in the system tray."
1645 " Showing it in the system tray provides easy access and a status indication.</para>"));
1646 topGeneral->addWidget(mShowInSystemTray);
1647 QGridLayout* grid = new QGridLayout(mShowInSystemTray);
1648 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1649 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1650 grid->setColumnStretch(1, 1);
1651 grid->setColumnMinimumWidth(0, indentWidth());
1653 mAutoHideSystemTray = new ButtonGroup(mShowInSystemTray);
1654 connect(mAutoHideSystemTray, &ButtonGroup::buttonSet, this, &ViewPrefTab::slotAutoHideSysTrayChanged);
1656 QRadioButton* radio = new QRadioButton(i18nc("@option:radio Always show KAlarm icon", "Always show"), mShowInSystemTray);
1657 mAutoHideSystemTray->addButton(radio, 0);
1658 radio->setWhatsThis(
1659 xi18nc("@info:whatsthis",
1660 "Check to show <application>KAlarm</application>'s icon in the system tray "
1661 "regardless of whether alarms are due."));
1662 grid->addWidget(radio, 0, 0, 1, 2, Qt::AlignLeft);
1664 radio = new QRadioButton(i18nc("@option:radio", "Automatically hide if no active alarms"), mShowInSystemTray);
1665 mAutoHideSystemTray->addButton(radio, 1);
1666 radio->setWhatsThis(
1667 xi18nc("@info:whatsthis",
1668 "Check to automatically hide <application>KAlarm</application>'s icon in "
1669 "the system tray if there are no active alarms. When hidden, the icon can "
1670 "always be made visible by use of the system tray option to show hidden icons."));
1671 grid->addWidget(radio, 1, 0, 1, 2, Qt::AlignLeft);
1673 QString text = xi18nc("@info:whatsthis",
1674 "Check to automatically hide <application>KAlarm</application>'s icon in the "
1675 "system tray if no alarms are due within the specified time period. When hidden, "
1676 "the icon can always be made visible by use of the system tray option to show hidden icons.");
1677 radio = new QRadioButton(i18nc("@option:radio", "Automatically hide if no alarm due within time period:"), mShowInSystemTray);
1678 radio->setWhatsThis(text);
1679 mAutoHideSystemTray->addButton(radio, 2);
1680 grid->addWidget(radio, 2, 0, 1, 2, Qt::AlignLeft);
1681 mAutoHideSystemTrayPeriod = new TimePeriod(true, mShowInSystemTray);
1682 mAutoHideSystemTrayPeriod->setWhatsThis(text);
1683 mAutoHideSystemTrayPeriod->setMaximumWidth(mAutoHideSystemTrayPeriod->sizeHint().width());
1684 grid->addWidget(mAutoHideSystemTrayPeriod, 3, 1, 1, 1, Qt::AlignLeft);
1685 mShowInSystemTray->setMaximumHeight(mShowInSystemTray->sizeHint().height());
1687 // System tray tooltip group box
1688 QGroupBox* group = new QGroupBox(i18nc("@title:group", "System Tray Tooltip"));
1689 topGeneral->addWidget(group);
1690 grid = new QGridLayout(group);
1691 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1692 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1693 grid->setColumnStretch(2, 1);
1694 grid->setColumnMinimumWidth(0, indentWidth());
1695 grid->setColumnMinimumWidth(1, indentWidth());
1697 mTooltipShowAlarms = new QCheckBox(i18nc("@option:check", "Show next &24 hours' alarms"), group);
1698 mTooltipShowAlarms->setMinimumSize(mTooltipShowAlarms->sizeHint());
1699 connect(mTooltipShowAlarms, &QAbstractButton::toggled, this, &ViewPrefTab::slotTooltipAlarmsToggled);
1700 mTooltipShowAlarms->setWhatsThis(
1701 i18nc("@info:whatsthis", "Specify whether to include in the system tray tooltip, a summary of alarms due in the next 24 hours."));
1702 grid->addWidget(mTooltipShowAlarms, 0, 0, 1, 3, Qt::AlignLeft);
1704 widget = new QWidget;
1705 QHBoxLayout *box = new QHBoxLayout(widget);
1706 box->setMargin(0);
1707 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1708 mTooltipMaxAlarms = new QCheckBox(i18nc("@option:check", "Maximum number of alarms to show:"));
1709 mTooltipMaxAlarms->setMinimumSize(mTooltipMaxAlarms->sizeHint());
1710 box->addWidget(mTooltipMaxAlarms);
1711 connect(mTooltipMaxAlarms, &QAbstractButton::toggled, this, &ViewPrefTab::slotTooltipMaxToggled);
1712 mTooltipMaxAlarmCount = new SpinBox(1, 99);
1713 mTooltipMaxAlarmCount->setSingleShiftStep(5);
1714 mTooltipMaxAlarmCount->setMinimumSize(mTooltipMaxAlarmCount->sizeHint());
1715 box->addWidget(mTooltipMaxAlarmCount);
1716 widget->setWhatsThis(
1717 i18nc("@info:whatsthis", "Uncheck to display all of the next 24 hours' alarms in the system tray tooltip. "
1718 "Check to enter an upper limit on the number to be displayed."));
1719 grid->addWidget(widget, 1, 1, 1, 2, Qt::AlignLeft);
1721 mTooltipShowTime = new QCheckBox(MainWindow::i18n_chk_ShowAlarmTime(), group);
1722 mTooltipShowTime->setMinimumSize(mTooltipShowTime->sizeHint());
1723 connect(mTooltipShowTime, &QAbstractButton::toggled, this, &ViewPrefTab::slotTooltipTimeToggled);
1724 mTooltipShowTime->setWhatsThis(i18nc("@info:whatsthis", "Specify whether to show in the system tray tooltip, the time at which each alarm is due."));
1725 grid->addWidget(mTooltipShowTime, 2, 1, 1, 2, Qt::AlignLeft);
1727 mTooltipShowTimeTo = new QCheckBox(MainWindow::i18n_chk_ShowTimeToAlarm(), group);
1728 mTooltipShowTimeTo->setMinimumSize(mTooltipShowTimeTo->sizeHint());
1729 connect(mTooltipShowTimeTo, &QAbstractButton::toggled, this, &ViewPrefTab::slotTooltipTimeToToggled);
1730 mTooltipShowTimeTo->setWhatsThis(i18nc("@info:whatsthis", "Specify whether to show in the system tray tooltip, how long until each alarm is due."));
1731 grid->addWidget(mTooltipShowTimeTo, 3, 1, 1, 2, Qt::AlignLeft);
1733 widget = new QWidget; // this is to control the QWhatsThis text display area
1734 box = new QHBoxLayout(widget);
1735 box->setMargin(0);
1736 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1737 mTooltipTimeToPrefixLabel = new QLabel(i18nc("@label:textbox", "Prefix:"));
1738 box->addWidget(mTooltipTimeToPrefixLabel);
1739 mTooltipTimeToPrefix = new QLineEdit();
1740 box->addWidget(mTooltipTimeToPrefix);
1741 mTooltipTimeToPrefixLabel->setBuddy(mTooltipTimeToPrefix);
1742 widget->setWhatsThis(i18nc("@info:whatsthis", "Enter the text to be displayed in front of the time until the alarm, in the system tray tooltip."));
1743 grid->addWidget(widget, 4, 2, Qt::AlignLeft);
1744 group->setMaximumHeight(group->sizeHint().height());
1746 group = new QGroupBox(i18nc("@title:group", "Alarm List"));
1747 topGeneral->addWidget(group);
1748 QHBoxLayout* hlayout = new QHBoxLayout(group);
1749 hlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1750 QVBoxLayout* colourLayout = new QVBoxLayout();
1751 colourLayout->setMargin(0);
1752 hlayout->addLayout(colourLayout);
1754 widget = new QWidget; // to group widgets for QWhatsThis text
1755 box = new QHBoxLayout(widget);
1756 box->setMargin(0);
1757 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) / 2);
1758 colourLayout->addWidget(widget);
1759 QLabel* label1 = new QLabel(i18nc("@label:listbox", "Disabled alarm color:"));
1760 box->addWidget(label1);
1761 box->setStretchFactor(new QWidget(widget), 0);
1762 mDisabledColour = new ColourButton();
1763 box->addWidget(mDisabledColour);
1764 label1->setBuddy(mDisabledColour);
1765 widget->setWhatsThis(i18nc("@info:whatsthis", "Choose the text color in the alarm list for disabled alarms."));
1767 widget = new QWidget; // to group widgets for QWhatsThis text
1768 box = new QHBoxLayout(widget);
1769 box->setMargin(0);
1770 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) / 2);
1771 colourLayout->addWidget(widget);
1772 QLabel* label2 = new QLabel(i18nc("@label:listbox", "Archived alarm color:"));
1773 box->addWidget(label2);
1774 box->setStretchFactor(new QWidget(widget), 0);
1775 mArchivedColour = new ColourButton();
1776 box->addWidget(mArchivedColour);
1777 label2->setBuddy(mArchivedColour);
1778 widget->setWhatsThis(i18nc("@info:whatsthis", "Choose the text color in the alarm list for archived alarms."));
1779 hlayout->addStretch();
1781 if (topGeneral)
1782 topGeneral->addStretch(); // top adjust the widgets
1785 group = new QGroupBox(i18nc("@title:group", "Alarm Message Windows"));
1786 topWindows->addWidget(group);
1787 grid = new QGridLayout(group);
1788 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1789 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1790 grid->setColumnStretch(1, 1);
1791 grid->setColumnMinimumWidth(0, indentWidth());
1792 mWindowPosition = new ButtonGroup(group);
1793 connect(mWindowPosition, &ButtonGroup::buttonSet, this, &ViewPrefTab::slotWindowPosChanged);
1795 QString whatsthis = xi18nc("@info:whatsthis",
1796 "<para>Choose how to reduce the chance of alarm messages being accidentally acknowledged:"
1797 "<list><item>Position alarm message windows as far as possible from the current mouse cursor location, or</item>"
1798 "<item>Position alarm message windows in the center of the screen, but disable buttons for a short time after the window is displayed.</item></list></para>");
1799 radio = new QRadioButton(i18nc("@option:radio", "Position windows far from mouse cursor"), group);
1800 mWindowPosition->addButton(radio, 0);
1801 radio->setWhatsThis(whatsthis);
1802 grid->addWidget(radio, 0, 0, 1, 2, Qt::AlignLeft);
1803 radio = new QRadioButton(i18nc("@option:radio", "Center windows, delay activating window buttons"), group);
1804 mWindowPosition->addButton(radio, 1);
1805 radio->setWhatsThis(whatsthis);
1806 grid->addWidget(radio, 1, 0, 1, 2, Qt::AlignLeft);
1808 widget = new QWidget; // this is to control the QWhatsThis text display area
1809 box = new QHBoxLayout(widget);
1810 box->setMargin(0);
1811 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1812 mWindowButtonDelayLabel = new QLabel(i18nc("@label:spinbox", "Button activation delay (seconds):"));
1813 box->addWidget(mWindowButtonDelayLabel);
1814 mWindowButtonDelay = new QSpinBox();
1815 mWindowButtonDelay->setRange(1, 10);
1816 mWindowButtonDelayLabel->setBuddy(mWindowButtonDelay);
1817 box->addWidget(mWindowButtonDelay);
1818 widget->setWhatsThis(i18nc("@info:whatsthis",
1819 "Enter how long its buttons should remain disabled after the alarm message window is shown."));
1820 box->setStretchFactor(new QWidget(widget), 1); // left adjust the controls
1821 grid->addWidget(widget, 2, 1, Qt::AlignLeft);
1823 grid->setRowMinimumHeight(3, style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1825 mModalMessages = new QCheckBox(i18nc("@option:check", "Message windows have a title bar and take keyboard focus"), group);
1826 mModalMessages->setMinimumSize(mModalMessages->sizeHint());
1827 mModalMessages->setWhatsThis(xi18nc("@info:whatsthis",
1828 "<para>Specify the characteristics of alarm message windows:"
1829 "<list><item>If checked, the window is a normal window with a title bar, which grabs keyboard input when it is displayed.</item>"
1830 "<item>If unchecked, the window does not interfere with your typing when "
1831 "it is displayed, but it has no title bar and cannot be moved or resized.</item></list></para>"));
1832 grid->addWidget(mModalMessages, 4, 0, 1, 2, Qt::AlignLeft);
1834 if (topWindows)
1835 topWindows->addStretch(); // top adjust the widgets
1838 void ViewPrefTab::restore(bool, bool allTabs)
1840 if (allTabs || mTabs->currentIndex() == mTabGeneral)
1842 mShowInSystemTray->setChecked(Preferences::showInSystemTray());
1843 int id;
1844 int mins = Preferences::autoHideSystemTray();
1845 switch (mins)
1847 case -1: id = 1; break; // hide if no active alarms
1848 case 0: id = 0; break; // never hide
1849 default:
1851 id = 2;
1852 int days = 0;
1853 int secs = 0;
1854 if (mins % 1440)
1855 secs = mins * 60;
1856 else
1857 days = mins / 1440;
1858 TimePeriod::Units units = secs ? TimePeriod::HoursMinutes
1859 : (days % 7) ? TimePeriod::Days : TimePeriod::Weeks;
1860 Duration duration((secs ? secs : days), (secs ? Duration::Seconds : Duration::Days));
1861 mAutoHideSystemTrayPeriod->setPeriod(duration, false, units);
1862 break;
1865 mAutoHideSystemTray->setButton(id);
1866 setTooltip(Preferences::tooltipAlarmCount(),
1867 Preferences::showTooltipAlarmTime(),
1868 Preferences::showTooltipTimeToAlarm(),
1869 Preferences::tooltipTimeToPrefix());
1870 mDisabledColour->setColor(Preferences::disabledColour());
1871 mArchivedColour->setColor(Preferences::archivedColour());
1873 if (allTabs || mTabs->currentIndex() == mTabWindows)
1875 mWindowPosition->setButton(Preferences::messageButtonDelay() ? 1 : 0);
1876 mWindowButtonDelay->setValue(Preferences::messageButtonDelay());
1877 mModalMessages->setChecked(Preferences::modalMessages());
1881 void ViewPrefTab::apply(bool syncToDisc)
1883 QColor colour = mDisabledColour->color();
1884 if (colour != Preferences::disabledColour())
1885 Preferences::setDisabledColour(colour);
1886 colour = mArchivedColour->color();
1887 if (colour != Preferences::archivedColour())
1888 Preferences::setArchivedColour(colour);
1889 int n = mTooltipShowAlarms->isChecked() ? -1 : 0;
1890 if (n && mTooltipMaxAlarms->isChecked())
1891 n = mTooltipMaxAlarmCount->value();
1892 if (n != Preferences::tooltipAlarmCount())
1893 Preferences::setTooltipAlarmCount(n);
1894 bool b = mTooltipShowTime->isChecked();
1895 if (b != Preferences::showTooltipAlarmTime())
1896 Preferences::setShowTooltipAlarmTime(b);
1897 b = mTooltipShowTimeTo->isChecked();
1898 if (b != Preferences::showTooltipTimeToAlarm())
1899 Preferences::setShowTooltipTimeToAlarm(b);
1900 QString text = mTooltipTimeToPrefix->text();
1901 if (text != Preferences::tooltipTimeToPrefix())
1902 Preferences::setTooltipTimeToPrefix(text);
1903 b = mShowInSystemTray->isChecked();
1904 if (b != Preferences::showInSystemTray())
1905 Preferences::setShowInSystemTray(b);
1906 if (b)
1908 switch (mAutoHideSystemTray->selectedId())
1910 case 0: n = 0; break; // never hide
1911 case 1: n = -1; break; // hide if no active alarms
1912 case 2: // hide if no alarms due within period
1913 n = mAutoHideSystemTrayPeriod->period().asSeconds() / 60;
1914 break;
1916 if (n != Preferences::autoHideSystemTray())
1917 Preferences::setAutoHideSystemTray(n);
1919 n = mWindowPosition->selectedId();
1920 if (n)
1921 n = mWindowButtonDelay->value();
1922 if (n != Preferences::messageButtonDelay())
1923 Preferences::setMessageButtonDelay(n);
1924 b = mModalMessages->isChecked();
1925 if (b != Preferences::modalMessages())
1926 Preferences::setModalMessages(b);
1927 PrefsTabBase::apply(syncToDisc);
1930 void ViewPrefTab::setTooltip(int maxAlarms, bool time, bool timeTo, const QString& prefix)
1932 if (!timeTo)
1933 time = true; // ensure that at least one time option is ticked
1935 // Set the states of the controls without calling signal
1936 // handlers, since these could change the checkboxes' states.
1937 mTooltipShowAlarms->blockSignals(true);
1938 mTooltipShowTime->blockSignals(true);
1939 mTooltipShowTimeTo->blockSignals(true);
1941 mTooltipShowAlarms->setChecked(maxAlarms);
1942 mTooltipMaxAlarms->setChecked(maxAlarms > 0);
1943 mTooltipMaxAlarmCount->setValue(maxAlarms > 0 ? maxAlarms : 1);
1944 mTooltipShowTime->setChecked(time);
1945 mTooltipShowTimeTo->setChecked(timeTo);
1946 mTooltipTimeToPrefix->setText(prefix);
1948 mTooltipShowAlarms->blockSignals(false);
1949 mTooltipShowTime->blockSignals(false);
1950 mTooltipShowTimeTo->blockSignals(false);
1952 // Enable/disable controls according to their states
1953 slotTooltipTimeToToggled(timeTo);
1954 slotTooltipAlarmsToggled(maxAlarms);
1957 void ViewPrefTab::slotTooltipAlarmsToggled(bool on)
1959 mTooltipMaxAlarms->setEnabled(on);
1960 mTooltipMaxAlarmCount->setEnabled(on && mTooltipMaxAlarms->isChecked());
1961 mTooltipShowTime->setEnabled(on);
1962 mTooltipShowTimeTo->setEnabled(on);
1963 on = on && mTooltipShowTimeTo->isChecked();
1964 mTooltipTimeToPrefix->setEnabled(on);
1965 mTooltipTimeToPrefixLabel->setEnabled(on);
1968 void ViewPrefTab::slotTooltipMaxToggled(bool on)
1970 mTooltipMaxAlarmCount->setEnabled(on && mTooltipMaxAlarms->isEnabled());
1973 void ViewPrefTab::slotTooltipTimeToggled(bool on)
1975 if (!on && !mTooltipShowTimeTo->isChecked())
1976 mTooltipShowTimeTo->setChecked(true);
1979 void ViewPrefTab::slotTooltipTimeToToggled(bool on)
1981 if (!on && !mTooltipShowTime->isChecked())
1982 mTooltipShowTime->setChecked(true);
1983 on = on && mTooltipShowTimeTo->isEnabled();
1984 mTooltipTimeToPrefix->setEnabled(on);
1985 mTooltipTimeToPrefixLabel->setEnabled(on);
1988 void ViewPrefTab::slotAutoHideSysTrayChanged(QAbstractButton* button)
1990 mAutoHideSystemTrayPeriod->setEnabled(mAutoHideSystemTray->id(button) == 2);
1993 void ViewPrefTab::slotWindowPosChanged(QAbstractButton* button)
1995 bool enable = mWindowPosition->id(button);
1996 mWindowButtonDelay->setEnabled(enable);
1997 mWindowButtonDelayLabel->setEnabled(enable);
1999 #include "moc_prefdlg_p.cpp"
2000 #include "moc_prefdlg.cpp"
2002 // vim: et sw=4: