SVN_SILENT made messages (.desktop file) - always resolve ours
[kdepim.git] / kalarm / prefdlg.cpp
blobfa21f7dd13f9e045b77343ac09f9adfac7a3b515
1 /*
2 * prefdlg.cpp - program preferences dialog
3 * Program: kalarm
4 * Copyright © 2001-2012 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 <K4AboutData>
68 #include <kapplication.h>
69 #include <kstandardguiitem.h>
70 #include <ksystemtimezone.h>
71 #include <qicon.h>
72 #if KDEPIM_HAVE_X11
73 #include <kwindowinfo.h>
74 #include <kwindowsystem.h>
75 #endif
76 #include <ktoolinvocation.h>
77 #include <KHelpClient>
79 #include <QLabel>
80 #include <QCheckBox>
81 #include <QRadioButton>
82 #include <QPushButton>
83 #include <QTabWidget>
84 #include <QSpinBox>
85 #include <QGroupBox>
86 #include <QGridLayout>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QStyle>
90 #include <QResizeEvent>
91 #include <QStandardPaths>
92 #include <QComboBox>
93 #include "kalarm_debug.h"
95 using namespace KCalCore;
96 using namespace KAlarmCal;
98 static const char PREF_DIALOG_NAME[] = "PrefDialog";
100 // Command strings for executing commands in different types of terminal windows.
101 // %t = window title parameter
102 // %c = command to execute in terminal
103 // %w = command to execute in terminal, with 'sleep 86400' appended
104 // %C = temporary command file to execute in terminal
105 // %W = temporary command file to execute in terminal, with 'sleep 86400' appended
106 static QString xtermCommands[] = {
107 QStringLiteral("xterm -sb -hold -title %t -e %c"),
108 QStringLiteral("konsole --noclose -p tabtitle=%t -e ${SHELL:-sh} -c %c"),
109 QStringLiteral("gnome-terminal -t %t -e %W"),
110 QStringLiteral("eterm --pause -T %t -e %C"), // some systems use eterm...
111 QStringLiteral("Eterm --pause -T %t -e %C"), // while some use Eterm
112 QStringLiteral("rxvt -title %t -e ${SHELL:-sh} -c %w"),
113 QString() // end of list indicator - don't change!
117 /*=============================================================================
118 = Class KAlarmPrefDlg
119 =============================================================================*/
121 KAlarmPrefDlg* KAlarmPrefDlg::mInstance = Q_NULLPTR;
123 void KAlarmPrefDlg::display()
125 if (!mInstance)
127 mInstance = new KAlarmPrefDlg;
128 QSize s;
129 if (KAlarm::readConfigWindowSize(PREF_DIALOG_NAME, s))
130 mInstance->resize(s);
131 mInstance->show();
133 else
135 #if KDEPIM_HAVE_X11
136 KWindowInfo info = KWindowInfo(mInstance->winId(), NET::WMGeometry | NET::WMDesktop);
137 KWindowSystem::setCurrentDesktop(info.desktop());
138 #endif
139 mInstance->setWindowState(mInstance->windowState() & ~Qt::WindowMinimized); // un-minimize it if necessary
140 mInstance->raise();
141 mInstance->activateWindow();
145 KAlarmPrefDlg::KAlarmPrefDlg()
146 : KPageDialog(),
147 mShown(false)
149 setAttribute(Qt::WA_DeleteOnClose);
150 setObjectName(QStringLiteral("PrefDlg")); // used by LikeBack
151 setWindowTitle(i18nc("@title:window", "Configure"));
152 setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Apply);
153 button(QDialogButtonBox::Ok)->setDefault(true);
154 setFaceType(List);
155 mTabScrollGroup = new StackedScrollGroup(this, this);
157 mMiscPage = new MiscPrefTab(mTabScrollGroup);
158 mMiscPageItem = new KPageWidgetItem(mMiscPage, i18nc("@title:tab General preferences", "General"));
159 mMiscPageItem->setHeader(i18nc("@title General preferences", "General"));
160 mMiscPageItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-other")));
161 addPage(mMiscPageItem);
163 mTimePage = new TimePrefTab(mTabScrollGroup);
164 mTimePageItem = new KPageWidgetItem(mTimePage, i18nc("@title:tab", "Time & Date"));
165 mTimePageItem->setHeader(i18nc("@title", "Time and Date"));
166 mTimePageItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-time")));
167 addPage(mTimePageItem);
169 mStorePage = new StorePrefTab(mTabScrollGroup);
170 mStorePageItem = new KPageWidgetItem(mStorePage, i18nc("@title:tab", "Storage"));
171 mStorePageItem->setHeader(i18nc("@title", "Alarm Storage"));
172 mStorePageItem->setIcon(QIcon::fromTheme(QStringLiteral("system-file-manager")));
173 addPage(mStorePageItem);
175 mEmailPage = new EmailPrefTab(mTabScrollGroup);
176 mEmailPageItem = new KPageWidgetItem(mEmailPage, i18nc("@title:tab Email preferences", "Email"));
177 mEmailPageItem->setHeader(i18nc("@title", "Email Alarm Settings"));
178 mEmailPageItem->setIcon(QIcon::fromTheme(QStringLiteral("internet-mail")));
179 addPage(mEmailPageItem);
181 mViewPage = new ViewPrefTab(mTabScrollGroup);
182 mViewPageItem = new KPageWidgetItem(mViewPage, i18nc("@title:tab", "View"));
183 mViewPageItem->setHeader(i18nc("@title", "View Settings"));
184 mViewPageItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-theme")));
185 addPage(mViewPageItem);
187 mEditPage = new EditPrefTab(mTabScrollGroup);
188 mEditPageItem = new KPageWidgetItem(mEditPage, i18nc("@title:tab", "Edit"));
189 mEditPageItem->setHeader(i18nc("@title", "Default Alarm Edit Settings"));
190 mEditPageItem->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
191 addPage(mEditPageItem);
192 connect(button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotOk);
193 connect(button(QDialogButtonBox::Cancel), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotCancel);
194 connect(button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotApply);
195 connect(button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotDefault);
196 connect(button(QDialogButtonBox::Help), &QAbstractButton::clicked, this, &KAlarmPrefDlg::slotHelp);
197 restore(false);
198 adjustSize();
201 KAlarmPrefDlg::~KAlarmPrefDlg()
203 mInstance = Q_NULLPTR;
206 void KAlarmPrefDlg::slotHelp()
208 KHelpClient::invokeHelp(QStringLiteral("preferences"));
211 // Apply the preferences that are currently selected
212 void KAlarmPrefDlg::slotApply()
214 qCDebug(KALARM_LOG);
215 QString errmsg = mEmailPage->validate();
216 if (!errmsg.isEmpty())
218 setCurrentPage(mEmailPageItem);
219 if (KAMessageBox::warningYesNo(this, errmsg) != KMessageBox::Yes)
221 mValid = false;
222 return;
225 errmsg = mEditPage->validate();
226 if (!errmsg.isEmpty())
228 setCurrentPage(mEditPageItem);
229 KAMessageBox::sorry(this, errmsg);
230 mValid = false;
231 return;
233 mValid = true;
234 mEmailPage->apply(false);
235 mViewPage->apply(false);
236 mEditPage->apply(false);
237 mStorePage->apply(false);
238 mTimePage->apply(false);
239 mMiscPage->apply(false);
240 Preferences::self()->save();
243 // Apply the preferences that are currently selected
244 void KAlarmPrefDlg::slotOk()
246 qCDebug(KALARM_LOG);
247 mValid = true;
248 slotApply();
249 if (mValid)
250 QDialog::accept();
253 // Discard the current preferences and close the dialog
254 void KAlarmPrefDlg::slotCancel()
256 qCDebug(KALARM_LOG);
257 restore(false);
258 KPageDialog::reject();
261 // Reset all controls to the application defaults
262 void KAlarmPrefDlg::slotDefault()
264 switch (KAMessageBox::questionYesNoCancel(this, i18nc("@info", "Reset all tabs to their default values, or only reset the current tab?"),
265 QString(),
266 KGuiItem(i18nc("@action:button Reset ALL tabs", "&All")),
267 KGuiItem(i18nc("@action:button Reset the CURRENT tab", "C&urrent"))))
269 case KMessageBox::Yes:
270 restore(true); // restore all tabs
271 break;
272 case KMessageBox::No:
273 Preferences::self()->useDefaults(true);
274 static_cast<PrefsTabBase*>(currentPage()->widget())->restore(true, false);
275 Preferences::self()->useDefaults(false);
276 break;
277 default:
278 break;
282 // Discard the current preferences and use the present ones
283 void KAlarmPrefDlg::restore(bool defaults)
285 qCDebug(KALARM_LOG) << (defaults ? "defaults" : "");
286 if (defaults)
287 Preferences::self()->useDefaults(true);
288 mEmailPage->restore(defaults, true);
289 mViewPage->restore(defaults, true);
290 mEditPage->restore(defaults, true);
291 mStorePage->restore(defaults, true);
292 mTimePage->restore(defaults, true);
293 mMiscPage->restore(defaults, true);
294 if (defaults)
295 Preferences::self()->useDefaults(false);
298 /******************************************************************************
299 * Return the minimum size for the dialog.
300 * If the minimum size would be too high to fit the desktop, the tab contents
301 * are made scrollable.
303 QSize KAlarmPrefDlg::minimumSizeHint() const
305 if (!mTabScrollGroup->sized())
307 QSize s = mTabScrollGroup->adjustSize();
308 if (s.isValid())
310 if (mTabScrollGroup->heightReduction())
312 s = QSize(s.width(), s.height() - mTabScrollGroup->heightReduction());
313 const_cast<KAlarmPrefDlg*>(this)->resize(s);
315 return s;
318 return KPageDialog::minimumSizeHint();
321 void KAlarmPrefDlg::showEvent(QShowEvent* e)
323 KPageDialog::showEvent(e);
324 if (!mShown)
326 mTabScrollGroup->adjustSize(true);
327 mShown = true;
331 /******************************************************************************
332 * Called when the dialog's size has changed.
333 * Records the new size in the config file.
335 void KAlarmPrefDlg::resizeEvent(QResizeEvent* re)
337 if (isVisible())
338 KAlarm::writeConfigWindowSize(PREF_DIALOG_NAME, re->size());
339 KPageDialog::resizeEvent(re);
343 /*=============================================================================
344 = Class PrefsTabBase
345 =============================================================================*/
346 int PrefsTabBase::mIndentWidth = 0;
348 PrefsTabBase::PrefsTabBase(StackedScrollGroup* scrollGroup)
349 : StackedScrollWidget(scrollGroup),
350 mLabelsAligned(false)
352 QFrame *topWidget = new QFrame(this);
353 setWidget(topWidget);
354 mTopLayout = new QVBoxLayout(topWidget);
355 mTopLayout->setMargin(0);
356 mTopLayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
357 if (!mIndentWidth)
359 QRadioButton radio(this);
360 QStyleOptionButton opt;
361 opt.initFrom(&radio);
362 mIndentWidth = style()->subElementRect(QStyle::SE_RadioButtonIndicator, &opt).width();
366 void PrefsTabBase::apply(bool syncToDisc)
368 if (syncToDisc)
369 Preferences::self()->save();
372 void PrefsTabBase::addAlignedLabel(QLabel* label)
374 mLabels += label;
377 void PrefsTabBase::showEvent(QShowEvent*)
379 if (!mLabelsAligned)
381 int wid = 0;
382 int i;
383 int end = mLabels.count();
384 QList<int> xpos;
385 for (i = 0; i < end; ++i)
387 int x = mLabels[i]->mapTo(this, QPoint(0, 0)).x();
388 xpos += x;
389 int w = x + mLabels[i]->sizeHint().width();
390 if (w > wid)
391 wid = w;
393 for (i = 0; i < end; ++i)
395 mLabels[i]->setFixedWidth(wid - xpos[i]);
396 mLabels[i]->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
398 mLabelsAligned = true;
403 /*=============================================================================
404 = Class MiscPrefTab
405 =============================================================================*/
407 MiscPrefTab::MiscPrefTab(StackedScrollGroup* scrollGroup)
408 : PrefsTabBase(scrollGroup)
410 QGroupBox* group = new QGroupBox(i18nc("@title:group", "Run Mode"));
411 topLayout()->addWidget(group);
412 QVBoxLayout* vlayout = new QVBoxLayout(group);
413 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
414 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
416 // Start at login
417 mAutoStart = new QCheckBox(i18nc("@option:check", "Start at login"), group);
418 connect(mAutoStart, &QAbstractButton::clicked, this, &MiscPrefTab::slotAutostartClicked);
419 mAutoStart->setWhatsThis(xi18nc("@info:whatsthis",
420 "<para>Automatically start <application>KAlarm</application> whenever you start KDE.</para>"
421 "<para>This option should always be checked unless you intend to discontinue use of <application>KAlarm</application>.</para>"));
422 vlayout->addWidget(mAutoStart, 0, Qt::AlignLeft);
424 mQuitWarn = new QCheckBox(i18nc("@option:check", "Warn before quitting"), group);
425 mQuitWarn->setWhatsThis(xi18nc("@info:whatsthis", "Check to display a warning prompt before quitting <application>KAlarm</application>."));
426 vlayout->addWidget(mQuitWarn, 0, Qt::AlignLeft);
428 // Confirm alarm deletion?
429 group = new QGroupBox(i18nc("@title:group", "Deletion"));
430 topLayout()->addWidget(group); // this is to allow left adjustment
431 QVBoxLayout *box = new QVBoxLayout(group);
432 mConfirmAlarmDeletion = new QCheckBox(i18nc("@option:check", "Confirm alarm deletions"));
433 mConfirmAlarmDeletion->setMinimumSize(mConfirmAlarmDeletion->sizeHint());
434 mConfirmAlarmDeletion->setWhatsThis(i18nc("@info:whatsthis", "Check to be prompted for confirmation each time you delete an alarm."));
435 box->addWidget(mConfirmAlarmDeletion);
437 // Default alarm deferral time
438 QWidget *widget = new QWidget;
439 box->addWidget(widget);
440 QHBoxLayout *hbox = new QHBoxLayout(widget);
441 hbox->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
442 QLabel* label = new QLabel(i18nc("@label:spinbox", "Default defer time interval:"));
443 hbox->addWidget(label);
444 mDefaultDeferTime = new TimeSpinBox(1, 5999);
445 mDefaultDeferTime->setMinimumSize(mDefaultDeferTime->sizeHint());
446 hbox->addWidget(mDefaultDeferTime);
447 widget->setWhatsThis(i18nc("@info:whatsthis",
448 "Enter the default time interval (hours & minutes) to defer alarms, used by the Defer Alarm dialog."));
449 label->setBuddy(mDefaultDeferTime);
450 hbox->addStretch(1); // left adjust the controls
452 // Terminal window to use for command alarms
453 group = new QGroupBox(i18nc("@title:group", "Terminal for Command Alarms"));
454 group->setWhatsThis(i18nc("@info:whatsthis", "Choose which application to use when a command alarm is executed in a terminal window"));
455 topLayout()->addWidget(group);
456 QGridLayout* grid = new QGridLayout(group);
457 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
458 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
459 int row = 0;
461 mXtermType = new ButtonGroup(group);
462 int index = 0;
463 mXtermFirst = -1;
464 for (mXtermCount = 0; !xtermCommands[mXtermCount].isNull(); ++mXtermCount)
466 QString cmd = xtermCommands[mXtermCount];
467 QStringList args = KShell::splitArgs(cmd);
468 if (args.isEmpty() || QStandardPaths::findExecutable(args[0]).isEmpty())
469 continue;
470 QRadioButton* radio = new QRadioButton(args[0], group);
471 radio->setMinimumSize(radio->sizeHint());
472 mXtermType->addButton(radio, mXtermCount);
473 if (mXtermFirst < 0)
474 mXtermFirst = mXtermCount; // note the id of the first button
475 cmd.replace(QStringLiteral("%t"), KComponentData::mainComponent().aboutData()->programName());
476 cmd.replace(QStringLiteral("%c"), QStringLiteral("<command>"));
477 cmd.replace(QStringLiteral("%w"), QStringLiteral("<command; sleep>"));
478 cmd.replace(QStringLiteral("%C"), QStringLiteral("[command]"));
479 cmd.replace(QStringLiteral("%W"), QStringLiteral("[command; sleep]"));
480 radio->setWhatsThis(
481 xi18nc("@info:whatsthis", "Check to execute command alarms in a terminal window by <icode>%1</icode>", cmd));
482 grid->addWidget(radio, (row = index/3), index % 3, Qt::AlignLeft);
483 ++index;
486 // QHBox used here doesn't allow the QLineEdit to expand!?
487 QHBoxLayout* hlayout = new QHBoxLayout();
488 hlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
489 grid->addLayout(hlayout, row + 1, 0, 1, 3, Qt::AlignLeft);
490 QRadioButton* radio = new QRadioButton(i18nc("@option:radio Other terminal window command", "Other:"), group);
491 hlayout->addWidget(radio);
492 connect(radio, &QAbstractButton::toggled, this, &MiscPrefTab::slotOtherTerminalToggled);
493 mXtermType->addButton(radio, mXtermCount);
494 if (mXtermFirst < 0)
495 mXtermFirst = mXtermCount; // note the id of the first button
496 mXtermCommand = new QLineEdit(group);
497 mXtermCommand->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
498 hlayout->addWidget(mXtermCommand);
499 QString wt =
500 xi18nc("@info:whatsthis", "Enter the full command line needed to execute a command in your chosen terminal window. "
501 "By default the alarm's command string will be appended to what you enter here. "
502 "See the <application>KAlarm</application> Handbook for details of special codes to tailor the command line.");
503 radio->setWhatsThis(wt);
504 mXtermCommand->setWhatsThis(wt);
506 topLayout()->addStretch(); // top adjust the widgets
509 void MiscPrefTab::restore(bool defaults, bool)
511 mAutoStart->setChecked(defaults ? true : Preferences::autoStart());
512 mQuitWarn->setChecked(Preferences::quitWarn());
513 mConfirmAlarmDeletion->setChecked(Preferences::confirmAlarmDeletion());
514 mDefaultDeferTime->setValue(Preferences::defaultDeferTime());
515 QString xtermCmd = Preferences::cmdXTermCommand();
516 int id = mXtermFirst;
517 if (!xtermCmd.isEmpty())
519 for ( ; id < mXtermCount; ++id)
521 if (mXtermType->find(id) && xtermCmd == xtermCommands[id])
522 break;
525 mXtermType->setButton(id);
526 mXtermCommand->setEnabled(id == mXtermCount);
527 mXtermCommand->setText(id == mXtermCount ? xtermCmd : QString());
530 void MiscPrefTab::apply(bool syncToDisc)
532 // First validate anything entered in Other X-terminal command
533 int xtermID = mXtermType->selectedId();
534 if (xtermID >= mXtermCount)
536 QString cmd = mXtermCommand->text();
537 if (cmd.isEmpty())
538 xtermID = -1; // 'Other' is only acceptable if it's non-blank
539 else
541 QStringList args = KShell::splitArgs(cmd);
542 cmd = args.isEmpty() ? QString() : args[0];
543 if (QStandardPaths::findExecutable(cmd).isEmpty())
545 mXtermCommand->setFocus();
546 if (KAMessageBox::warningContinueCancel(topLayout()->parentWidget(), xi18nc("@info", "Command to invoke terminal window not found: <command>%1</command>", cmd))
547 != KMessageBox::Continue)
548 return;
552 if (xtermID < 0)
554 xtermID = mXtermFirst;
555 mXtermType->setButton(mXtermFirst);
558 if (mQuitWarn->isEnabled())
560 bool b = mQuitWarn->isChecked();
561 if (b != Preferences::quitWarn())
562 Preferences::setQuitWarn(b);
564 bool b = mAutoStart->isChecked();
565 if (b != Preferences::autoStart())
567 Preferences::setAutoStart(b);
568 Preferences::setAskAutoStart(true); // cancel any start-at-login prompt suppression
569 if (b)
570 Preferences::setNoAutoStart(false);
571 Preferences::setAutoStartChangedByUser(true); // prevent prompting the user on quit, about start-at-login
573 b = mConfirmAlarmDeletion->isChecked();
574 if (b != Preferences::confirmAlarmDeletion())
575 Preferences::setConfirmAlarmDeletion(b);
576 int i = mDefaultDeferTime->value();
577 if (i != Preferences::defaultDeferTime())
578 Preferences::setDefaultDeferTime(i);
579 QString text = (xtermID < mXtermCount) ? xtermCommands[xtermID] : mXtermCommand->text();
580 if (text != Preferences::cmdXTermCommand())
581 Preferences::setCmdXTermCommand(text);
582 PrefsTabBase::apply(syncToDisc);
585 void MiscPrefTab::slotAutostartClicked()
587 if (!mAutoStart->isChecked()
588 && KAMessageBox::warningYesNo(topLayout()->parentWidget(),
589 xi18nc("@info", "You should not uncheck this option unless you intend to discontinue use of <application>KAlarm</application>"),
590 QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()
591 ) != KMessageBox::Yes)
592 mAutoStart->setChecked(true);
595 void MiscPrefTab::slotOtherTerminalToggled(bool on)
597 mXtermCommand->setEnabled(on);
601 /*=============================================================================
602 = Class TimePrefTab
603 =============================================================================*/
605 TimePrefTab::TimePrefTab(StackedScrollGroup* scrollGroup)
606 : PrefsTabBase(scrollGroup)
608 // Default time zone
609 ItemBox* itemBox = new ItemBox();
610 itemBox->setMargin(0);
611 qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
613 QWidget *widget = new QWidget; // this is to control the QWhatsThis text display area
614 itemBox->addWidget(widget);
615 QHBoxLayout *box = new QHBoxLayout(widget);
616 box->setMargin(0);
617 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
618 QLabel* label = new QLabel(i18nc("@label:listbox", "Time zone:"));
619 box->addWidget(label);
620 addAlignedLabel(label);
621 #if 1
622 mTimeZone = new TimeZoneCombo(widget);
623 mTimeZone->setMaxVisibleItems(15);
624 box->addWidget(mTimeZone);
625 #else
626 mTimeZone = new KComboBox(box);
627 mTimeZone->setMaxVisibleItems(15);
628 const KTimeZones::ZoneMap zones = KSystemTimeZones::zones();
629 for (KTimeZones::ZoneMap::ConstIterator it = zones.constBegin(); it != zones.constEnd(); ++it)
630 mTimeZone->addItem(it.key());
631 #endif
632 widget->setWhatsThis(xi18nc("@info:whatsthis",
633 "Select the time zone which <application>KAlarm</application> should use "
634 "as its default for displaying and entering dates and times."));
635 label->setBuddy(mTimeZone);
636 itemBox->leftAlign();
638 // Holiday region
639 itemBox = new ItemBox();
640 itemBox->setMargin(0);
641 qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
643 widget = new QWidget; // this is to control the QWhatsThis text display area
644 itemBox->addWidget(widget);
645 box = new QHBoxLayout(widget);
646 box->setMargin(0);
647 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
648 label = new QLabel(i18nc("@label:listbox", "Holiday region:"));
649 addAlignedLabel(label);
650 box->addWidget(label);
651 mHolidays = new QComboBox();
652 mHolidays->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
653 box->addWidget(mHolidays);
654 itemBox->leftAlign();
655 label->setBuddy(mHolidays);
656 widget->setWhatsThis(i18nc("@info:whatsthis",
657 "Select which holiday region to use"));
659 QStringList regions = HolidayRegion::regionCodes();
660 QMap<QString, QString> regionsMap;
661 foreach (const QString& regionCode, regions)
663 QString name = HolidayRegion::name(regionCode);
664 QString languageName = KLocale::global()->languageCodeToName(HolidayRegion::languageCode(regionCode));
665 QString label = languageName.isEmpty() ? name : i18nc("Holiday region, region language", "%1 (%2)", name, languageName);
666 regionsMap.insert(label, regionCode);
669 mHolidays->addItem(i18nc("No holiday region", "None"), QString());
670 for (QMapIterator<QString, QString> it(regionsMap); it.hasNext(); )
672 it.next();
673 mHolidays->addItem(it.key(), it.value());
676 // Start-of-day time
677 itemBox = new ItemBox();
678 itemBox->setMargin(0);
679 qobject_cast<QBoxLayout*>(topLayout())->addLayout(itemBox);
681 widget = new QWidget; // this is to control the QWhatsThis text display area
682 itemBox->addWidget(widget);
683 box = new QHBoxLayout(widget);
684 box->setMargin(0);
685 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
686 label = new QLabel(i18nc("@label:spinbox", "Start of day for date-only alarms:"));
687 addAlignedLabel(label);
688 box->addWidget(label);
689 mStartOfDay = new TimeEdit();
690 box->addWidget(mStartOfDay);
691 label->setBuddy(mStartOfDay);
692 widget->setWhatsThis(xi18nc("@info:whatsthis",
693 "<para>The earliest time of day at which a date-only alarm will be triggered.</para>"
694 "<para>%1</para>", TimeSpinBox::shiftWhatsThis()));
695 itemBox->leftAlign();
697 // Working hours
698 QGroupBox* group = new QGroupBox(i18nc("@title:group", "Working Hours"));
699 topLayout()->addWidget(group);
700 QBoxLayout* layout = new QVBoxLayout(group);
701 layout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
702 layout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
704 QWidget* daybox = new QWidget(group); // this is to control the QWhatsThis text display area
705 layout->addWidget(daybox);
706 QGridLayout* wgrid = new QGridLayout(daybox);
707 wgrid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
708 const KLocale* locale = KLocale::global();
709 for (int i = 0; i < 7; ++i)
711 int day = KAlarm::localeDayInWeek_to_weekDay(i);
712 mWorkDays[i] = new QCheckBox(KAlarm::weekDayName(day, locale), daybox);
713 wgrid->addWidget(mWorkDays[i], i/3, i%3, Qt::AlignLeft);
715 daybox->setWhatsThis(i18nc("@info:whatsthis", "Check the days in the week which are work days"));
717 itemBox = new ItemBox(group);
718 itemBox->setMargin(0);
719 layout->addLayout(itemBox);
721 widget = new QWidget; // this is to control the QWhatsThis text display area
722 itemBox->addWidget(widget);
723 box = new QHBoxLayout(widget);
724 box->setMargin(0);
725 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
726 label = new QLabel(i18nc("@label:spinbox", "Daily start time:"));
727 addAlignedLabel(label);
728 box->addWidget(label);
729 mWorkStart = new TimeEdit();
730 box->addWidget(mWorkStart);
731 label->setBuddy(mWorkStart);
732 widget->setWhatsThis(xi18nc("@info:whatsthis",
733 "<para>Enter the start time of the working day.</para>"
734 "<para>%1</para>", TimeSpinBox::shiftWhatsThis()));
735 itemBox->leftAlign();
737 itemBox = new ItemBox(group);
738 itemBox->setMargin(0);
739 layout->addLayout(itemBox);
741 widget = new QWidget; // this is to control the QWhatsThis text display area
742 itemBox->addWidget(widget);
743 box = new QHBoxLayout(widget);
744 box->setMargin(0);
745 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
746 label = new QLabel(i18nc("@label:spinbox", "Daily end time:"));
747 addAlignedLabel(label);
748 box->addWidget(label);
749 mWorkEnd = new TimeEdit();
750 box->addWidget(mWorkEnd);
751 label->setBuddy(mWorkEnd);
752 widget->setWhatsThis(xi18nc("@info:whatsthis",
753 "<para>Enter the end time of the working day.</para>"
754 "<para>%1</para>", TimeSpinBox::shiftWhatsThis()));
755 itemBox->leftAlign();
757 // KOrganizer event duration
758 group = new QGroupBox(i18nc("@title:group", "KOrganizer"));
759 topLayout()->addWidget(group);
760 layout = new QVBoxLayout(group);
761 layout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
762 layout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
764 widget = new QWidget; // this is to control the QWhatsThis text display area
765 layout->addWidget(widget);
766 box = new QHBoxLayout(widget);
767 box->setMargin(0);
768 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
769 label = new QLabel(i18nc("@label:spinbox", "KOrganizer event duration:"));
770 addAlignedLabel(label);
771 box->addWidget(label);
772 mKOrgEventDuration = new TimeSpinBox(0, 5999);
773 mKOrgEventDuration->setMinimumSize(mKOrgEventDuration->sizeHint());
774 box->addWidget(mKOrgEventDuration);
775 widget->setWhatsThis(xi18nc("@info:whatsthis",
776 "<para>Enter the event duration in hours and minutes, for alarms which are copied to KOrganizer.</para>"
777 "<para>%1</para>", TimeSpinBox::shiftWhatsThis()));
778 label->setBuddy(mKOrgEventDuration);
779 box->addStretch(1); // left adjust the controls
781 topLayout()->addStretch(); // top adjust the widgets
784 void TimePrefTab::restore(bool, bool)
786 #if 1
787 mTimeZone->setTimeZone(Preferences::timeZone());
788 #else
789 int tzindex = 0;
790 KTimeZone tz = Preferences::timeZone();
791 if (tz.isValid())
793 QString zone = tz.name();
794 int count = mTimeZone->count();
795 while (tzindex < count && mTimeZone->itemText(tzindex) != zone)
796 ++tzindex;
797 if (tzindex >= count)
798 tzindex = 0;
800 mTimeZone->setCurrentIndex(tzindex);
801 #endif
802 int i = Preferences::holidays().isValid() ? mHolidays->findData(Preferences::holidays().regionCode()) : 0;
803 mHolidays->setCurrentIndex(i);
804 mStartOfDay->setValue(Preferences::startOfDay());
805 mWorkStart->setValue(Preferences::workDayStart());
806 mWorkEnd->setValue(Preferences::workDayEnd());
807 QBitArray days = Preferences::workDays();
808 for (int i = 0; i < 7; ++i)
810 bool x = days.testBit(KAlarm::localeDayInWeek_to_weekDay(i) - 1);
811 mWorkDays[i]->setChecked(x);
813 mKOrgEventDuration->setValue(Preferences::kOrgEventDuration());
816 void TimePrefTab::apply(bool syncToDisc)
818 #if 1
819 KTimeZone tz = mTimeZone->timeZone();
820 if (tz.isValid())
821 Preferences::setTimeZone(tz);
822 #else
823 KTimeZone tz = KSystemTimeZones::zone(mTimeZone->currentText());
824 if (tz.isValid() && tz != Preferences::timeZone())
825 Preferences::setTimeZone(tz);
826 #endif
827 QString hol = mHolidays->itemData(mHolidays->currentIndex()).toString();
828 if (hol != Preferences::holidays().regionCode())
829 Preferences::setHolidayRegion(hol);
830 int t = mStartOfDay->value();
831 QTime sodt(t/60, t%60, 0);
832 if (sodt != Preferences::startOfDay())
833 Preferences::setStartOfDay(sodt);
834 t = mWorkStart->value();
835 Preferences::setWorkDayStart(QTime(t/60, t%60, 0));
836 t = mWorkEnd->value();
837 Preferences::setWorkDayEnd(QTime(t/60, t%60, 0));
838 QBitArray workDays(7);
839 for (int i = 0; i < 7; ++i)
840 if (mWorkDays[i]->isChecked())
841 workDays.setBit(KAlarm::localeDayInWeek_to_weekDay(i) - 1, 1);
842 Preferences::setWorkDays(workDays);
843 Preferences::setKOrgEventDuration(mKOrgEventDuration->value());
844 t = mKOrgEventDuration->value();
845 if (t != Preferences::kOrgEventDuration())
846 Preferences::setKOrgEventDuration(t);
847 PrefsTabBase::apply(syncToDisc);
851 /*=============================================================================
852 = Class StorePrefTab
853 =============================================================================*/
855 StorePrefTab::StorePrefTab(StackedScrollGroup* scrollGroup)
856 : PrefsTabBase(scrollGroup),
857 mCheckKeepChanges(false)
859 // Which resource to save to
860 QGroupBox* group = new QGroupBox(i18nc("@title:group", "New Alarms && Templates"));
861 topLayout()->addWidget(group);
862 QButtonGroup* bgroup = new QButtonGroup(group);
863 QBoxLayout* layout = new QVBoxLayout(group);
864 layout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
865 layout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
867 mDefaultResource = new QRadioButton(i18nc("@option:radio", "Store in default calendar"), group);
868 bgroup->addButton(mDefaultResource);
869 mDefaultResource->setWhatsThis(i18nc("@info:whatsthis", "Add all new alarms and alarm templates to the default calendars, without prompting."));
870 layout->addWidget(mDefaultResource, 0, Qt::AlignLeft);
871 mAskResource = new QRadioButton(i18nc("@option:radio", "Prompt for which calendar to store in"), group);
872 bgroup->addButton(mAskResource);
873 mAskResource->setWhatsThis(xi18nc("@info:whatsthis",
874 "<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>"
875 "<para>Note that archived alarms are always stored in the default archived alarm calendar.</para>"));
876 layout->addWidget(mAskResource, 0, Qt::AlignLeft);
878 // Archived alarms
879 group = new QGroupBox(i18nc("@title:group", "Archived Alarms"));
880 topLayout()->addWidget(group);
881 QGridLayout* grid = new QGridLayout(group);
882 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
883 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
884 grid->setColumnStretch(1, 1);
885 grid->setColumnMinimumWidth(0, indentWidth());
886 mKeepArchived = new QCheckBox(i18nc("@option:check", "Keep alarms after expiry"), group);
887 connect(mKeepArchived, &QAbstractButton::toggled, this, &StorePrefTab::slotArchivedToggled);
888 mKeepArchived->setWhatsThis(
889 i18nc("@info:whatsthis", "Check to archive alarms after expiry or deletion (except deleted alarms which were never triggered)."));
890 grid->addWidget(mKeepArchived, 0, 0, 1, 2, Qt::AlignLeft);
892 QWidget *widget = new QWidget;
893 QHBoxLayout *box = new QHBoxLayout(widget);
894 box->setMargin(0);
895 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
896 mPurgeArchived = new QCheckBox(i18nc("@option:check", "Discard archived alarms after:"));
897 mPurgeArchived->setMinimumSize(mPurgeArchived->sizeHint());
898 box->addWidget(mPurgeArchived);
899 connect(mPurgeArchived, &QAbstractButton::toggled, this, &StorePrefTab::slotArchivedToggled);
900 mPurgeAfter = new SpinBox();
901 mPurgeAfter->setMinimum(1);
902 mPurgeAfter->setSingleShiftStep(10);
903 mPurgeAfter->setMinimumSize(mPurgeAfter->sizeHint());
904 box->addWidget(mPurgeAfter);
905 mPurgeAfterLabel = new QLabel(i18nc("@label Time unit for user-entered number", "days"));
906 mPurgeAfterLabel->setMinimumSize(mPurgeAfterLabel->sizeHint());
907 mPurgeAfterLabel->setBuddy(mPurgeAfter);
908 box->addWidget(mPurgeAfterLabel);
909 widget->setWhatsThis(i18nc("@info:whatsthis", "Uncheck to store archived alarms indefinitely. Check to enter how long archived alarms should be stored."));
910 grid->addWidget(widget, 1, 1, Qt::AlignLeft);
912 mClearArchived = new QPushButton(i18nc("@action:button", "Clear Archived Alarms"), group);
913 connect(mClearArchived, &QAbstractButton::clicked, this, &StorePrefTab::slotClearArchived);
914 mClearArchived->setWhatsThis((CollectionControlModel::enabledCollections(CalEvent::ARCHIVED, false).count() <= 1)
915 ? i18nc("@info:whatsthis", "Delete all existing archived alarms.")
916 : i18nc("@info:whatsthis", "Delete all existing archived alarms (from the default archived alarm calendar only)."));
917 grid->addWidget(mClearArchived, 2, 1, Qt::AlignLeft);
919 topLayout()->addStretch(); // top adjust the widgets
922 void StorePrefTab::restore(bool defaults, bool)
924 mCheckKeepChanges = defaults;
925 if (Preferences::askResource())
926 mAskResource->setChecked(true);
927 else
928 mDefaultResource->setChecked(true);
929 int keepDays = Preferences::archivedKeepDays();
930 if (!defaults)
931 mOldKeepArchived = keepDays;
932 setArchivedControls(keepDays);
933 mCheckKeepChanges = true;
936 void StorePrefTab::apply(bool syncToDisc)
938 bool b = mAskResource->isChecked();
939 if (b != Preferences::askResource())
940 Preferences::setAskResource(mAskResource->isChecked());
941 int days = !mKeepArchived->isChecked() ? 0 : mPurgeArchived->isChecked() ? mPurgeAfter->value() : -1;
942 if (days != Preferences::archivedKeepDays())
943 Preferences::setArchivedKeepDays(days);
944 PrefsTabBase::apply(syncToDisc);
947 void StorePrefTab::setArchivedControls(int purgeDays)
949 mKeepArchived->setChecked(purgeDays);
950 mPurgeArchived->setChecked(purgeDays > 0);
951 mPurgeAfter->setValue(purgeDays > 0 ? purgeDays : 0);
952 slotArchivedToggled(true);
955 void StorePrefTab::slotArchivedToggled(bool)
957 bool keep = mKeepArchived->isChecked();
958 if (keep && !mOldKeepArchived && mCheckKeepChanges
959 && !CollectionControlModel::getStandard(CalEvent::ARCHIVED).isValid())
961 KAMessageBox::sorry(topLayout()->parentWidget(),
962 xi18nc("@info", "<para>A default calendar is required in order to archive alarms, but none is currently enabled.</para>"
963 "<para>If you wish to keep expired alarms, please first use the calendars view to select a default "
964 "archived alarms calendar.</para>"));
965 mKeepArchived->setChecked(false);
966 return;
968 mOldKeepArchived = keep;
969 mPurgeArchived->setEnabled(keep);
970 mPurgeAfter->setEnabled(keep && mPurgeArchived->isChecked());
971 mPurgeAfterLabel->setEnabled(keep);
972 mClearArchived->setEnabled(keep);
975 void StorePrefTab::slotClearArchived()
977 bool single = CollectionControlModel::enabledCollections(CalEvent::ARCHIVED, false).count() <= 1;
978 if (KAMessageBox::warningContinueCancel(topLayout()->parentWidget(),
979 single ? i18nc("@info", "Do you really want to delete all archived alarms?")
980 : i18nc("@info", "Do you really want to delete all alarms in the default archived alarm calendar?"))
981 != KMessageBox::Continue)
982 return;
983 theApp()->purgeAll();
987 /*=============================================================================
988 = Class EmailPrefTab
989 =============================================================================*/
991 EmailPrefTab::EmailPrefTab(StackedScrollGroup* scrollGroup)
992 : PrefsTabBase(scrollGroup),
993 mAddressChanged(false),
994 mBccAddressChanged(false)
996 QWidget *widget = new QWidget;
997 topLayout()->addWidget(widget);
998 QHBoxLayout *box = new QHBoxLayout(widget);
999 box->setSpacing(2 * style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1000 QLabel *label = new QLabel(i18nc("@label", "Email client:"));
1001 box->addWidget(label);
1002 mEmailClient = new ButtonGroup(widget);
1003 QString kmailOption = i18nc("@option:radio", "KMail");
1004 QString sendmailOption = i18nc("@option:radio", "Sendmail");
1005 mKMailButton = new RadioButton(kmailOption);
1006 mKMailButton->setMinimumSize(mKMailButton->sizeHint());
1007 box->addWidget(mKMailButton);
1008 mEmailClient->addButton(mKMailButton, Preferences::kmail);
1009 mSendmailButton = new RadioButton(sendmailOption);
1010 mSendmailButton->setMinimumSize(mSendmailButton->sizeHint());
1011 box->addWidget(mSendmailButton);
1012 mEmailClient->addButton(mSendmailButton, Preferences::sendmail);
1013 connect(mEmailClient, &ButtonGroup::buttonSet, this, &EmailPrefTab::slotEmailClientChanged);
1014 widget->setWhatsThis(xi18nc("@info:whatsthis",
1015 "<para>Choose how to send email when an email alarm is triggered."
1016 "<list><item><interface>%1</interface>: The email is sent automatically via <application>KMail</application>. <application>KMail</application> is started first if necessary.</item>"
1017 "<item><interface>%2</interface>: The email is sent automatically. This option will only work if "
1018 "your system is configured to use <application>sendmail</application> or a sendmail compatible mail transport agent.</item></list></para>",
1019 kmailOption, sendmailOption));
1021 widget = new QWidget; // this is to allow left adjustment
1022 topLayout()->addWidget(widget);
1023 box = new QHBoxLayout(widget);
1024 mEmailCopyToKMail = new QCheckBox(xi18nc("@option:check", "Copy sent emails into <application>KMail</application>'s <resource>%1</resource> folder", KAMail::i18n_sent_mail()));
1025 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()));
1026 box->addWidget(mEmailCopyToKMail);
1027 box->setStretchFactor(new QWidget(widget), 1); // left adjust the controls
1029 widget = new QWidget; // this is to allow left adjustment
1030 topLayout()->addWidget(widget);
1031 box = new QHBoxLayout(widget);
1032 mEmailQueuedNotify = new QCheckBox(i18nc("@option:check", "Notify when remote emails are queued"));
1033 mEmailQueuedNotify->setWhatsThis(
1034 i18nc("@info:whatsthis", "Display a notification message whenever an email alarm has queued an email for sending to a remote system. "
1035 "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."));
1036 box->addWidget(mEmailQueuedNotify);
1037 box->setStretchFactor(new QWidget(widget), 1); // left adjust the controls
1039 // Your Email Address group box
1040 QGroupBox* group = new QGroupBox(i18nc("@title:group", "Your Email Address"));
1041 topLayout()->addWidget(group);
1042 QGridLayout* grid = new QGridLayout(group);
1043 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1044 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1045 grid->setColumnStretch(2, 1);
1047 // 'From' email address controls ...
1048 label = new Label(i18nc("@label 'From' email address", "From:"), group);
1049 grid->addWidget(label, 1, 0);
1050 mFromAddressGroup = new ButtonGroup(group);
1051 connect(mFromAddressGroup, &ButtonGroup::buttonSet, this, &EmailPrefTab::slotFromAddrChanged);
1053 // Line edit to enter a 'From' email address
1054 mFromAddrButton = new RadioButton(group);
1055 mFromAddressGroup->addButton(mFromAddrButton, Preferences::MAIL_FROM_ADDR);
1056 label->setBuddy(mFromAddrButton);
1057 grid->addWidget(mFromAddrButton, 1, 1);
1058 mEmailAddress = new QLineEdit(group);
1059 connect(mEmailAddress, &QLineEdit::textChanged, this, &EmailPrefTab::slotAddressChanged);
1060 QString whatsThis = i18nc("@info:whatsthis", "Your email address, used to identify you as the sender when sending email alarms.");
1061 mFromAddrButton->setWhatsThis(whatsThis);
1062 mEmailAddress->setWhatsThis(whatsThis);
1063 mFromAddrButton->setFocusWidget(mEmailAddress);
1064 grid->addWidget(mEmailAddress, 1, 2);
1066 // 'From' email address to be taken from System Settings
1067 mFromCCentreButton = new RadioButton(i18nc("@option:radio", "Use address from System Settings"), group);
1068 mFromAddressGroup->addButton(mFromCCentreButton, Preferences::MAIL_FROM_SYS_SETTINGS);
1069 mFromCCentreButton->setWhatsThis(
1070 i18nc("@info:whatsthis", "Check to use the email address set in KDE System Settings, to identify you as the sender when sending email alarms."));
1071 grid->addWidget(mFromCCentreButton, 2, 1, 1, 2, Qt::AlignLeft);
1073 // 'From' email address to be picked from KMail's identities when the email alarm is configured
1074 mFromKMailButton = new RadioButton(xi18nc("@option:radio", "Use <application>KMail</application> identities"), group);
1075 mFromAddressGroup->addButton(mFromKMailButton, Preferences::MAIL_FROM_KMAIL);
1076 mFromKMailButton->setWhatsThis(
1077 xi18nc("@info:whatsthis", "Check to use <application>KMail</application>'s email identities to identify you as the sender when sending email alarms. "
1078 "For existing email alarms, <application>KMail</application>'s default identity will be used. "
1079 "For new email alarms, you will be able to pick which of <application>KMail</application>'s identities to use."));
1080 grid->addWidget(mFromKMailButton, 3, 1, 1, 2, Qt::AlignLeft);
1082 // 'Bcc' email address controls ...
1083 grid->setRowMinimumHeight(4, style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1084 label = new Label(i18nc("@label 'Bcc' email address", "Bcc:"), group);
1085 grid->addWidget(label, 5, 0);
1086 mBccAddressGroup = new ButtonGroup(group);
1087 connect(mBccAddressGroup, &ButtonGroup::buttonSet, this, &EmailPrefTab::slotBccAddrChanged);
1089 // Line edit to enter a 'Bcc' email address
1090 mBccAddrButton = new RadioButton(group);
1091 mBccAddressGroup->addButton(mBccAddrButton, Preferences::MAIL_FROM_ADDR);
1092 label->setBuddy(mBccAddrButton);
1093 grid->addWidget(mBccAddrButton, 5, 1);
1094 mEmailBccAddress = new QLineEdit(group);
1095 whatsThis = xi18nc("@info:whatsthis", "Your email address, used for blind copying email alarms to yourself. "
1096 "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.");
1097 mBccAddrButton->setWhatsThis(whatsThis);
1098 mEmailBccAddress->setWhatsThis(whatsThis);
1099 mBccAddrButton->setFocusWidget(mEmailBccAddress);
1100 grid->addWidget(mEmailBccAddress, 5, 2);
1102 // 'Bcc' email address to be taken from System Settings
1103 mBccCCentreButton = new RadioButton(i18nc("@option:radio", "Use address from System Settings"), group);
1104 mBccAddressGroup->addButton(mBccCCentreButton, Preferences::MAIL_FROM_SYS_SETTINGS);
1105 mBccCCentreButton->setWhatsThis(
1106 i18nc("@info:whatsthis", "Check to use the email address set in KDE System Settings, for blind copying email alarms to yourself."));
1107 grid->addWidget(mBccCCentreButton, 6, 1, 1, 2, Qt::AlignLeft);
1109 topLayout()->addStretch(); // top adjust the widgets
1112 void EmailPrefTab::restore(bool defaults, bool)
1114 mEmailClient->setButton(Preferences::emailClient());
1115 mEmailCopyToKMail->setChecked(Preferences::emailCopyToKMail());
1116 setEmailAddress(Preferences::emailFrom(), Preferences::emailAddress());
1117 setEmailBccAddress((Preferences::emailBccFrom() == Preferences::MAIL_FROM_SYS_SETTINGS), Preferences::emailBccAddress());
1118 mEmailQueuedNotify->setChecked(Preferences::emailQueuedNotify());
1119 if (!defaults)
1120 mAddressChanged = mBccAddressChanged = false;
1123 void EmailPrefTab::apply(bool syncToDisc)
1125 int client = mEmailClient->selectedId();
1126 if (client >= 0 && static_cast<Preferences::MailClient>(client) != Preferences::emailClient())
1127 Preferences::setEmailClient(static_cast<Preferences::MailClient>(client));
1128 bool b = mEmailCopyToKMail->isChecked();
1129 if (b != Preferences::emailCopyToKMail())
1130 Preferences::setEmailCopyToKMail(b);
1131 int from = mFromAddressGroup->selectedId();
1132 QString text = mEmailAddress->text().trimmed();
1133 if ((from >= 0 && static_cast<Preferences::MailFrom>(from) != Preferences::emailFrom())
1134 || text != Preferences::emailAddress())
1135 Preferences::setEmailAddress(static_cast<Preferences::MailFrom>(from), text);
1136 b = (mBccAddressGroup->checkedButton() == mBccCCentreButton);
1137 Preferences::MailFrom bfrom = b ? Preferences::MAIL_FROM_SYS_SETTINGS : Preferences::MAIL_FROM_ADDR;;
1138 text = mEmailBccAddress->text().trimmed();
1139 if (bfrom != Preferences::emailBccFrom() || text != Preferences::emailBccAddress())
1140 Preferences::setEmailBccAddress(b, text);
1141 b = mEmailQueuedNotify->isChecked();
1142 if (b != Preferences::emailQueuedNotify())
1143 Preferences::setEmailQueuedNotify(mEmailQueuedNotify->isChecked());
1144 PrefsTabBase::apply(syncToDisc);
1147 void EmailPrefTab::setEmailAddress(Preferences::MailFrom from, const QString& address)
1149 mFromAddressGroup->setButton(from);
1150 mEmailAddress->setText(from == Preferences::MAIL_FROM_ADDR ? address.trimmed() : QString());
1153 void EmailPrefTab::setEmailBccAddress(bool useSystemSettings, const QString& address)
1155 mBccAddressGroup->setButton(useSystemSettings ? Preferences::MAIL_FROM_SYS_SETTINGS : Preferences::MAIL_FROM_ADDR);
1156 mEmailBccAddress->setText(useSystemSettings ? QString() : address.trimmed());
1159 void EmailPrefTab::slotEmailClientChanged(QAbstractButton* button)
1161 mEmailCopyToKMail->setEnabled(button == mSendmailButton);
1164 void EmailPrefTab::slotFromAddrChanged(QAbstractButton* button)
1166 mEmailAddress->setEnabled(button == mFromAddrButton);
1167 mAddressChanged = true;
1170 void EmailPrefTab::slotBccAddrChanged(QAbstractButton* button)
1172 mEmailBccAddress->setEnabled(button == mBccAddrButton);
1173 mBccAddressChanged = true;
1176 QString EmailPrefTab::validate()
1178 if (mAddressChanged)
1180 mAddressChanged = false;
1181 QString errmsg = validateAddr(mFromAddressGroup, mEmailAddress, KAMail::i18n_NeedFromEmailAddress());
1182 if (!errmsg.isEmpty())
1183 return errmsg;
1185 if (mBccAddressChanged)
1187 mBccAddressChanged = false;
1188 return validateAddr(mBccAddressGroup, mEmailBccAddress, i18nc("@info", "No valid 'Bcc' email address is specified."));
1190 return QString();
1193 QString EmailPrefTab::validateAddr(ButtonGroup* group, QLineEdit* addr, const QString& msg)
1195 QString errmsg = xi18nc("@info", "<para>%1</para><para>Are you sure you want to save your changes?</para>", msg);
1196 switch (group->selectedId())
1198 case Preferences::MAIL_FROM_SYS_SETTINGS:
1199 if (!KAMail::controlCentreAddress().isEmpty())
1200 return QString();
1201 errmsg = i18nc("@info", "No email address is currently set in KDE System Settings. %1", errmsg);
1202 break;
1203 case Preferences::MAIL_FROM_KMAIL:
1204 if (Identities::identitiesExist())
1205 return QString();
1206 errmsg = xi18nc("@info", "No <application>KMail</application> identities currently exist. %1", errmsg);
1207 break;
1208 case Preferences::MAIL_FROM_ADDR:
1209 if (!addr->text().trimmed().isEmpty())
1210 return QString();
1211 break;
1213 return errmsg;
1217 /*=============================================================================
1218 = Class EditPrefTab
1219 =============================================================================*/
1221 EditPrefTab::EditPrefTab(StackedScrollGroup* scrollGroup)
1222 : PrefsTabBase(scrollGroup)
1224 KLocalizedString defsetting = kxi18nc("@info:whatsthis", "The default setting for <interface>%1</interface> in the alarm edit dialog.");
1226 mTabs = new QTabWidget();
1227 topLayout()->addWidget(mTabs);
1228 StackedGroupT<QWidget>* tabgroup = new StackedGroupT<QWidget>(mTabs);
1230 StackedWidgetT<QWidget>* topGeneral = new StackedWidgetT<QWidget>(tabgroup);
1231 QVBoxLayout *tgLayout = new QVBoxLayout(topGeneral);
1232 mTabGeneral = mTabs->addTab(topGeneral, i18nc("@title:tab", "General"));
1234 StackedWidgetT<QWidget>* topTypes = new StackedWidgetT<QWidget>(tabgroup);
1235 QVBoxLayout *ttLayout = new QVBoxLayout(topTypes);
1236 mTabTypes = mTabs->addTab(topTypes, i18nc("@title:tab", "Alarm Types"));
1238 StackedWidgetT<QWidget>* topFontColour = new StackedWidgetT<QWidget>(tabgroup);
1239 QVBoxLayout *tfLayout = new QVBoxLayout(topFontColour);
1240 mTabFontColour = mTabs->addTab(topFontColour, i18nc("@title:tab", "Font && Color"));
1242 // MISCELLANEOUS
1243 // Show in KOrganizer
1244 mCopyToKOrganizer = new QCheckBox(EditAlarmDlg::i18n_chk_ShowInKOrganizer());
1245 mCopyToKOrganizer->setMinimumSize(mCopyToKOrganizer->sizeHint());
1246 mCopyToKOrganizer->setWhatsThis(defsetting.subs(EditAlarmDlg::i18n_chk_ShowInKOrganizer()).toString());
1247 tgLayout->addWidget(mCopyToKOrganizer);
1249 // Late cancellation
1250 QWidget *widget = new QWidget;
1251 tgLayout->addWidget(widget);
1252 QHBoxLayout *box = new QHBoxLayout(widget);
1253 box->setMargin(0);
1254 box->setSpacing(0);
1255 mLateCancel = new QCheckBox(LateCancelSelector::i18n_chk_CancelIfLate());
1256 mLateCancel->setMinimumSize(mLateCancel->sizeHint());
1257 mLateCancel->setWhatsThis(defsetting.subs(LateCancelSelector::i18n_chk_CancelIfLate()).toString());
1258 box->addWidget(mLateCancel);
1260 // Recurrence
1261 widget = new QWidget; // this is to control the QWhatsThis text display area
1262 tgLayout->addWidget(widget);
1263 box = new QHBoxLayout(widget);
1264 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1265 box->setMargin(0);
1266 QLabel* label = new QLabel(i18nc("@label:listbox", "Recurrence:"));
1267 box->addWidget(label);
1268 mRecurPeriod = new ComboBox();
1269 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_NoRecur());
1270 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_AtLogin());
1271 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_HourlyMinutely());
1272 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_Daily());
1273 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_Weekly());
1274 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_Monthly());
1275 mRecurPeriod->addItem(RecurrenceEdit::i18n_combo_Yearly());
1276 box->addWidget(mRecurPeriod);
1277 box->addStretch();
1278 label->setBuddy(mRecurPeriod);
1279 widget->setWhatsThis(i18nc("@info:whatsthis", "The default setting for the recurrence rule in the alarm edit dialog."));
1281 // How to handle February 29th in yearly recurrences
1282 QWidget *febBox = new QWidget; // this is to control the QWhatsThis text display area
1283 tgLayout->addWidget(febBox);
1284 QVBoxLayout *vbox = new QVBoxLayout(febBox);
1285 vbox->setMargin(0);
1286 vbox->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1287 label = new QLabel(i18nc("@label", "In non-leap years, repeat yearly February 29th alarms on:"));
1288 label->setAlignment(Qt::AlignLeft);
1289 label->setWordWrap(true);
1290 vbox->addWidget(label);
1291 box = new QHBoxLayout();
1292 vbox->addLayout(box);
1293 vbox->setMargin(0);
1294 box->setSpacing(2 * style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1295 mFeb29 = new ButtonGroup(febBox);
1296 widget = new QWidget();
1297 widget->setFixedWidth(3 * style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1298 box->addWidget(widget);
1299 QRadioButton* radio = new QRadioButton(i18nc("@option:radio", "February 2&8th"));
1300 radio->setMinimumSize(radio->sizeHint());
1301 box->addWidget(radio);
1302 mFeb29->addButton(radio, Preferences::Feb29_Feb28);
1303 radio = new QRadioButton(i18nc("@option:radio", "March &1st"));
1304 radio->setMinimumSize(radio->sizeHint());
1305 box->addWidget(radio);
1306 mFeb29->addButton(radio, Preferences::Feb29_Mar1);
1307 radio = new QRadioButton(i18nc("@option:radio", "Do not repeat"));
1308 radio->setMinimumSize(radio->sizeHint());
1309 box->addWidget(radio);
1310 mFeb29->addButton(radio, Preferences::Feb29_None);
1311 febBox->setWhatsThis(xi18nc("@info:whatsthis",
1312 "For yearly recurrences, choose what date, if any, alarms due on February 29th should occur in non-leap years."
1313 "<note>The next scheduled occurrence of existing alarms is not re-evaluated when you change this setting.</note>"));
1315 tgLayout->addStretch(); // top adjust the widgets
1317 // DISPLAY ALARMS
1318 QGroupBox* group = new QGroupBox(i18nc("@title:group", "Display Alarms"));
1319 ttLayout->addWidget(group);
1320 QVBoxLayout* vlayout = new QVBoxLayout(group);
1321 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1322 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1324 mConfirmAck = new QCheckBox(EditDisplayAlarmDlg::i18n_chk_ConfirmAck());
1325 mConfirmAck->setMinimumSize(mConfirmAck->sizeHint());
1326 mConfirmAck->setWhatsThis(defsetting.subs(EditDisplayAlarmDlg::i18n_chk_ConfirmAck()).toString());
1327 vlayout->addWidget(mConfirmAck, 0, Qt::AlignLeft);
1329 mAutoClose = new QCheckBox(LateCancelSelector::i18n_chk_AutoCloseWinLC());
1330 mAutoClose->setMinimumSize(mAutoClose->sizeHint());
1331 mAutoClose->setWhatsThis(defsetting.subs(LateCancelSelector::i18n_chk_AutoCloseWin()).toString());
1332 vlayout->addWidget(mAutoClose, 0, Qt::AlignLeft);
1334 widget = new QWidget;
1335 vlayout->addWidget(widget);
1336 box = new QHBoxLayout(widget);
1337 box->setMargin(0);
1338 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1339 label = new QLabel(i18nc("@label:listbox", "Reminder units:"));
1340 box->addWidget(label);
1341 mReminderUnits = new QComboBox();
1342 mReminderUnits->addItem(i18nc("@item:inlistbox", "Minutes"), TimePeriod::Minutes);
1343 mReminderUnits->addItem(i18nc("@item:inlistbox", "Hours/Minutes"), TimePeriod::HoursMinutes);
1344 box->addWidget(mReminderUnits);
1345 label->setBuddy(mReminderUnits);
1346 widget->setWhatsThis(i18nc("@info:whatsthis", "The default units for the reminder in the alarm edit dialog, for alarms due soon."));
1347 box->addStretch(1); // left adjust the control
1348 mSpecialActionsButton = new SpecialActionsButton(true);
1349 box->addWidget(mSpecialActionsButton);
1351 // SOUND
1352 QGroupBox* bbox = new QGroupBox(i18nc("@title:group Audio options group", "Sound"));
1353 ttLayout->addWidget(bbox);
1354 vlayout = new QVBoxLayout(bbox);
1355 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1356 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1358 QHBoxLayout *hlayout = new QHBoxLayout;
1359 hlayout->setMargin(0);
1360 vlayout->addLayout(hlayout);
1361 mSound = new QComboBox();
1362 mSound->addItem(SoundPicker::i18n_combo_None()); // index 0
1363 mSound->addItem(SoundPicker::i18n_combo_Beep()); // index 1
1364 mSound->addItem(SoundPicker::i18n_combo_File()); // index 2
1365 if (KPIMTextEdit::TextToSpeech::self()->isReady())
1366 mSound->addItem(SoundPicker::i18n_combo_Speak()); // index 3
1367 mSound->setMinimumSize(mSound->sizeHint());
1368 mSound->setWhatsThis(defsetting.subs(SoundPicker::i18n_label_Sound()).toString());
1369 hlayout->addWidget(mSound);
1370 hlayout->addStretch();
1371 mSoundRepeat = new QCheckBox(i18nc("@option:check", "Repeat sound file"));
1372 mSoundRepeat->setMinimumSize(mSoundRepeat->sizeHint());
1373 mSoundRepeat->setWhatsThis(
1374 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()));
1375 hlayout->addWidget(mSoundRepeat);
1377 widget = new QWidget; // this is to control the QWhatsThis text display area
1378 box = new QHBoxLayout(widget);
1379 box->setMargin(0);
1380 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1381 mSoundFileLabel = new QLabel(i18nc("@label:textbox", "Sound file:"));
1382 box->addWidget(mSoundFileLabel);
1383 mSoundFile = new QLineEdit();
1384 box->addWidget(mSoundFile);
1385 mSoundFileLabel->setBuddy(mSoundFile);
1386 mSoundFileBrowse = new QPushButton();
1387 mSoundFileBrowse->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
1388 connect(mSoundFileBrowse, &QAbstractButton::clicked, this, &EditPrefTab::slotBrowseSoundFile);
1389 mSoundFileBrowse->setToolTip(i18nc("@info:tooltip", "Choose a sound file"));
1390 box->addWidget(mSoundFileBrowse);
1391 widget->setWhatsThis(i18nc("@info:whatsthis", "Enter the default sound file to use in the alarm edit dialog."));
1392 vlayout->addWidget(widget);
1394 // COMMAND ALARMS
1395 group = new QGroupBox(i18nc("@title:group", "Command Alarms"));
1396 ttLayout->addWidget(group);
1397 vlayout = new QVBoxLayout(group);
1398 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1399 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1400 hlayout = new QHBoxLayout();
1401 hlayout->setMargin(0);
1402 vlayout->addLayout(hlayout);
1404 mCmdScript = new QCheckBox(EditCommandAlarmDlg::i18n_chk_EnterScript(), group);
1405 mCmdScript->setMinimumSize(mCmdScript->sizeHint());
1406 mCmdScript->setWhatsThis(defsetting.subs(EditCommandAlarmDlg::i18n_chk_EnterScript()).toString());
1407 hlayout->addWidget(mCmdScript);
1408 hlayout->addStretch();
1410 mCmdXterm = new QCheckBox(EditCommandAlarmDlg::i18n_chk_ExecInTermWindow(), group);
1411 mCmdXterm->setMinimumSize(mCmdXterm->sizeHint());
1412 mCmdXterm->setWhatsThis(defsetting.subs(EditCommandAlarmDlg::i18n_radio_ExecInTermWindow()).toString());
1413 hlayout->addWidget(mCmdXterm);
1415 // EMAIL ALARMS
1416 group = new QGroupBox(i18nc("@title:group", "Email Alarms"));
1417 ttLayout->addWidget(group);
1418 vlayout = new QVBoxLayout(group);
1419 vlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1420 vlayout->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1422 // BCC email to sender
1423 mEmailBcc = new QCheckBox(EditEmailAlarmDlg::i18n_chk_CopyEmailToSelf(), group);
1424 mEmailBcc->setMinimumSize(mEmailBcc->sizeHint());
1425 mEmailBcc->setWhatsThis(defsetting.subs(EditEmailAlarmDlg::i18n_chk_CopyEmailToSelf()).toString());
1426 vlayout->addWidget(mEmailBcc, 0, Qt::AlignLeft);
1428 ttLayout->addStretch();
1430 // FONT / COLOUR TAB
1431 mFontChooser = new FontColourChooser(topFontColour, QStringList(), i18nc("@title:group", "Message Font && Color"), true);
1432 tfLayout->addWidget(mFontChooser);
1435 void EditPrefTab::restore(bool, bool allTabs)
1437 int index;
1438 if (allTabs || mTabs->currentIndex() == mTabGeneral)
1440 mCopyToKOrganizer->setChecked(Preferences::defaultCopyToKOrganizer());
1441 mLateCancel->setChecked(Preferences::defaultLateCancel());
1442 switch (Preferences::defaultRecurPeriod())
1444 case Preferences::Recur_Yearly: index = 6; break;
1445 case Preferences::Recur_Monthly: index = 5; break;
1446 case Preferences::Recur_Weekly: index = 4; break;
1447 case Preferences::Recur_Daily: index = 3; break;
1448 case Preferences::Recur_SubDaily: index = 2; break;
1449 case Preferences::Recur_Login: index = 1; break;
1450 case Preferences::Recur_None:
1451 default: index = 0; break;
1453 mRecurPeriod->setCurrentIndex(index);
1454 mFeb29->setButton(Preferences::defaultFeb29Type());
1456 if (allTabs || mTabs->currentIndex() == mTabTypes)
1458 mConfirmAck->setChecked(Preferences::defaultConfirmAck());
1459 mAutoClose->setChecked(Preferences::defaultAutoClose());
1460 switch (Preferences::defaultReminderUnits())
1462 case TimePeriod::Weeks: index = 3; break;
1463 case TimePeriod::Days: index = 2; break;
1464 default:
1465 case TimePeriod::HoursMinutes: index = 1; break;
1466 case TimePeriod::Minutes: index = 0; break;
1468 mReminderUnits->setCurrentIndex(index);
1469 KAEvent::ExtraActionOptions opts(0);
1470 if (Preferences::defaultExecPreActionOnDeferral())
1471 opts |= KAEvent::ExecPreActOnDeferral;
1472 if (Preferences::defaultCancelOnPreActionError())
1473 opts |= KAEvent::CancelOnPreActError;
1474 if (Preferences::defaultDontShowPreActionError())
1475 opts |= KAEvent::DontShowPreActError;
1476 mSpecialActionsButton->setActions(Preferences::defaultPreAction(), Preferences::defaultPostAction(), opts);
1477 mSound->setCurrentIndex(soundIndex(Preferences::defaultSoundType()));
1478 mSoundFile->setText(Preferences::defaultSoundFile());
1479 mSoundRepeat->setChecked(Preferences::defaultSoundRepeat());
1480 mCmdScript->setChecked(Preferences::defaultCmdScript());
1481 mCmdXterm->setChecked(Preferences::defaultCmdLogType() == Preferences::Log_Terminal);
1482 mEmailBcc->setChecked(Preferences::defaultEmailBcc());
1484 if (allTabs || mTabs->currentIndex() == mTabFontColour)
1486 mFontChooser->setFgColour(Preferences::defaultFgColour());
1487 mFontChooser->setBgColour(Preferences::defaultBgColour());
1488 mFontChooser->setFont(Preferences::messageFont());
1492 void EditPrefTab::apply(bool syncToDisc)
1494 bool b = mAutoClose->isChecked();
1495 if (b != Preferences::defaultAutoClose())
1496 Preferences::setDefaultAutoClose(b);
1497 b = mConfirmAck->isChecked();
1498 if (b != Preferences::defaultConfirmAck())
1499 Preferences::setDefaultConfirmAck(b);
1500 TimePeriod::Units units;
1501 switch (mReminderUnits->currentIndex())
1503 case 3: units = TimePeriod::Weeks; break;
1504 case 2: units = TimePeriod::Days; break;
1505 default:
1506 case 1: units = TimePeriod::HoursMinutes; break;
1507 case 0: units = TimePeriod::Minutes; break;
1509 if (units != Preferences::defaultReminderUnits())
1510 Preferences::setDefaultReminderUnits(units);
1511 QString text = mSpecialActionsButton->preAction();
1512 if (text != Preferences::defaultPreAction())
1513 Preferences::setDefaultPreAction(text);
1514 text = mSpecialActionsButton->postAction();
1515 if (text != Preferences::defaultPostAction())
1516 Preferences::setDefaultPostAction(text);
1517 KAEvent::ExtraActionOptions opts = mSpecialActionsButton->options();
1518 b = opts & KAEvent::ExecPreActOnDeferral;
1519 if (b != Preferences::defaultExecPreActionOnDeferral())
1520 Preferences::setDefaultExecPreActionOnDeferral(b);
1521 b = opts & KAEvent::CancelOnPreActError;
1522 if (b != Preferences::defaultCancelOnPreActionError())
1523 Preferences::setDefaultCancelOnPreActionError(b);
1524 b = opts & KAEvent::DontShowPreActError;
1525 if (b != Preferences::defaultDontShowPreActionError())
1526 Preferences::setDefaultDontShowPreActionError(b);
1527 Preferences::SoundType snd;
1528 switch (mSound->currentIndex())
1530 case 3: snd = Preferences::Sound_Speak; break;
1531 case 2: snd = Preferences::Sound_File; break;
1532 case 1: snd = Preferences::Sound_Beep; break;
1533 case 0:
1534 default: snd = Preferences::Sound_None; break;
1536 if (snd != Preferences::defaultSoundType())
1537 Preferences::setDefaultSoundType(snd);
1538 text = mSoundFile->text();
1539 if (text != Preferences::defaultSoundFile())
1540 Preferences::setDefaultSoundFile(text);
1541 b = mSoundRepeat->isChecked();
1542 if (b != Preferences::defaultSoundRepeat())
1543 Preferences::setDefaultSoundRepeat(b);
1544 b = mCmdScript->isChecked();
1545 if (b != Preferences::defaultCmdScript())
1546 Preferences::setDefaultCmdScript(b);
1547 Preferences::CmdLogType log = mCmdXterm->isChecked() ? Preferences::Log_Terminal : Preferences::Log_Discard;
1548 if (log != Preferences::defaultCmdLogType())
1549 Preferences::setDefaultCmdLogType(log);
1550 b = mEmailBcc->isChecked();
1551 if (b != Preferences::defaultEmailBcc())
1552 Preferences::setDefaultEmailBcc(b);
1553 b = mCopyToKOrganizer->isChecked();
1554 if (b != Preferences::defaultCopyToKOrganizer())
1555 Preferences::setDefaultCopyToKOrganizer(b);
1556 int i = mLateCancel->isChecked() ? 1 : 0;
1557 if (i != Preferences::defaultLateCancel())
1558 Preferences::setDefaultLateCancel(i);
1559 Preferences::RecurType period;
1560 switch (mRecurPeriod->currentIndex())
1562 case 6: period = Preferences::Recur_Yearly; break;
1563 case 5: period = Preferences::Recur_Monthly; break;
1564 case 4: period = Preferences::Recur_Weekly; break;
1565 case 3: period = Preferences::Recur_Daily; break;
1566 case 2: period = Preferences::Recur_SubDaily; break;
1567 case 1: period = Preferences::Recur_Login; break;
1568 case 0:
1569 default: period = Preferences::Recur_None; break;
1571 if (period != Preferences::defaultRecurPeriod())
1572 Preferences::setDefaultRecurPeriod(period);
1573 int feb29 = mFeb29->selectedId();
1574 if (feb29 >= 0 && static_cast<Preferences::Feb29Type>(feb29) != Preferences::defaultFeb29Type())
1575 Preferences::setDefaultFeb29Type(static_cast<Preferences::Feb29Type>(feb29));
1576 QColor colour = mFontChooser->fgColour();
1577 if (colour != Preferences::defaultFgColour())
1578 Preferences::setDefaultFgColour(colour);
1579 colour = mFontChooser->bgColour();
1580 if (colour != Preferences::defaultBgColour())
1581 Preferences::setDefaultBgColour(colour);
1582 QFont font = mFontChooser->font();
1583 if (font != Preferences::messageFont())
1584 Preferences::setMessageFont(font);
1585 PrefsTabBase::apply(syncToDisc);
1588 void EditPrefTab::slotBrowseSoundFile()
1590 QString defaultDir;
1591 QString url = SoundPicker::browseFile(defaultDir, mSoundFile->text());
1592 if (!url.isEmpty())
1593 mSoundFile->setText(url);
1596 int EditPrefTab::soundIndex(Preferences::SoundType type)
1598 switch (type)
1600 case Preferences::Sound_Speak: return 3;
1601 case Preferences::Sound_File: return 2;
1602 case Preferences::Sound_Beep: return 1;
1603 case Preferences::Sound_None:
1604 default: return 0;
1608 QString EditPrefTab::validate()
1610 if (mSound->currentIndex() == soundIndex(Preferences::Sound_File) && mSoundFile->text().isEmpty())
1612 mSoundFile->setFocus();
1613 return xi18nc("@info", "You must enter a sound file when <interface>%1</interface> is selected as the default sound type", SoundPicker::i18n_combo_File());;
1615 return QString();
1619 /*=============================================================================
1620 = Class ViewPrefTab
1621 =============================================================================*/
1623 ViewPrefTab::ViewPrefTab(StackedScrollGroup* scrollGroup)
1624 : PrefsTabBase(scrollGroup)
1626 mTabs = new QTabWidget();
1627 topLayout()->addWidget(mTabs);
1629 QWidget *widget = new QWidget;
1630 QVBoxLayout *topGeneral = new QVBoxLayout(widget);
1631 topGeneral->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin) / 2);
1632 topGeneral->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1633 mTabGeneral = mTabs->addTab(widget, i18nc("@title:tab", "General"));
1635 widget = new QWidget;
1636 QVBoxLayout *topWindows = new QVBoxLayout(widget);
1637 topWindows->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin) / 2);
1638 topWindows->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1639 mTabWindows = mTabs->addTab(widget, i18nc("@title:tab", "Alarm Windows"));
1641 // Run-in-system-tray group box
1642 mShowInSystemTray = new QGroupBox(i18nc("@option:check", "Show in system tray"));
1643 mShowInSystemTray->setCheckable(true);
1644 mShowInSystemTray->setWhatsThis(
1645 xi18nc("@info:whatsthis", "<para>Check to show <application>KAlarm</application>'s icon in the system tray."
1646 " Showing it in the system tray provides easy access and a status indication.</para>"));
1647 topGeneral->addWidget(mShowInSystemTray);
1648 QGridLayout* grid = new QGridLayout(mShowInSystemTray);
1649 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1650 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1651 grid->setColumnStretch(1, 1);
1652 grid->setColumnMinimumWidth(0, indentWidth());
1654 mAutoHideSystemTray = new ButtonGroup(mShowInSystemTray);
1655 connect(mAutoHideSystemTray, &ButtonGroup::buttonSet, this, &ViewPrefTab::slotAutoHideSysTrayChanged);
1657 QRadioButton* radio = new QRadioButton(i18nc("@option:radio Always show KAlarm icon", "Always show"), mShowInSystemTray);
1658 mAutoHideSystemTray->addButton(radio, 0);
1659 radio->setWhatsThis(
1660 xi18nc("@info:whatsthis",
1661 "Check to show <application>KAlarm</application>'s icon in the system tray "
1662 "regardless of whether alarms are due."));
1663 grid->addWidget(radio, 0, 0, 1, 2, Qt::AlignLeft);
1665 radio = new QRadioButton(i18nc("@option:radio", "Automatically hide if no active alarms"), mShowInSystemTray);
1666 mAutoHideSystemTray->addButton(radio, 1);
1667 radio->setWhatsThis(
1668 xi18nc("@info:whatsthis",
1669 "Check to automatically hide <application>KAlarm</application>'s icon in "
1670 "the system tray if there are no active alarms. When hidden, the icon can "
1671 "always be made visible by use of the system tray option to show hidden icons."));
1672 grid->addWidget(radio, 1, 0, 1, 2, Qt::AlignLeft);
1674 QString text = xi18nc("@info:whatsthis",
1675 "Check to automatically hide <application>KAlarm</application>'s icon in the "
1676 "system tray if no alarms are due within the specified time period. When hidden, "
1677 "the icon can always be made visible by use of the system tray option to show hidden icons.");
1678 radio = new QRadioButton(i18nc("@option:radio", "Automatically hide if no alarm due within time period:"), mShowInSystemTray);
1679 radio->setWhatsThis(text);
1680 mAutoHideSystemTray->addButton(radio, 2);
1681 grid->addWidget(radio, 2, 0, 1, 2, Qt::AlignLeft);
1682 mAutoHideSystemTrayPeriod = new TimePeriod(true, mShowInSystemTray);
1683 mAutoHideSystemTrayPeriod->setWhatsThis(text);
1684 mAutoHideSystemTrayPeriod->setMaximumWidth(mAutoHideSystemTrayPeriod->sizeHint().width());
1685 grid->addWidget(mAutoHideSystemTrayPeriod, 3, 1, 1, 1, Qt::AlignLeft);
1686 mShowInSystemTray->setMaximumHeight(mShowInSystemTray->sizeHint().height());
1688 // System tray tooltip group box
1689 QGroupBox* group = new QGroupBox(i18nc("@title:group", "System Tray Tooltip"));
1690 topGeneral->addWidget(group);
1691 grid = new QGridLayout(group);
1692 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1693 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1694 grid->setColumnStretch(2, 1);
1695 grid->setColumnMinimumWidth(0, indentWidth());
1696 grid->setColumnMinimumWidth(1, indentWidth());
1698 mTooltipShowAlarms = new QCheckBox(i18nc("@option:check", "Show next &24 hours' alarms"), group);
1699 mTooltipShowAlarms->setMinimumSize(mTooltipShowAlarms->sizeHint());
1700 connect(mTooltipShowAlarms, &QAbstractButton::toggled, this, &ViewPrefTab::slotTooltipAlarmsToggled);
1701 mTooltipShowAlarms->setWhatsThis(
1702 i18nc("@info:whatsthis", "Specify whether to include in the system tray tooltip, a summary of alarms due in the next 24 hours."));
1703 grid->addWidget(mTooltipShowAlarms, 0, 0, 1, 3, Qt::AlignLeft);
1705 widget = new QWidget;
1706 QHBoxLayout *box = new QHBoxLayout(widget);
1707 box->setMargin(0);
1708 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1709 mTooltipMaxAlarms = new QCheckBox(i18nc("@option:check", "Maximum number of alarms to show:"));
1710 mTooltipMaxAlarms->setMinimumSize(mTooltipMaxAlarms->sizeHint());
1711 box->addWidget(mTooltipMaxAlarms);
1712 connect(mTooltipMaxAlarms, &QAbstractButton::toggled, this, &ViewPrefTab::slotTooltipMaxToggled);
1713 mTooltipMaxAlarmCount = new SpinBox(1, 99);
1714 mTooltipMaxAlarmCount->setSingleShiftStep(5);
1715 mTooltipMaxAlarmCount->setMinimumSize(mTooltipMaxAlarmCount->sizeHint());
1716 box->addWidget(mTooltipMaxAlarmCount);
1717 widget->setWhatsThis(
1718 i18nc("@info:whatsthis", "Uncheck to display all of the next 24 hours' alarms in the system tray tooltip. "
1719 "Check to enter an upper limit on the number to be displayed."));
1720 grid->addWidget(widget, 1, 1, 1, 2, Qt::AlignLeft);
1722 mTooltipShowTime = new QCheckBox(MainWindow::i18n_chk_ShowAlarmTime(), group);
1723 mTooltipShowTime->setMinimumSize(mTooltipShowTime->sizeHint());
1724 connect(mTooltipShowTime, &QAbstractButton::toggled, this, &ViewPrefTab::slotTooltipTimeToggled);
1725 mTooltipShowTime->setWhatsThis(i18nc("@info:whatsthis", "Specify whether to show in the system tray tooltip, the time at which each alarm is due."));
1726 grid->addWidget(mTooltipShowTime, 2, 1, 1, 2, Qt::AlignLeft);
1728 mTooltipShowTimeTo = new QCheckBox(MainWindow::i18n_chk_ShowTimeToAlarm(), group);
1729 mTooltipShowTimeTo->setMinimumSize(mTooltipShowTimeTo->sizeHint());
1730 connect(mTooltipShowTimeTo, &QAbstractButton::toggled, this, &ViewPrefTab::slotTooltipTimeToToggled);
1731 mTooltipShowTimeTo->setWhatsThis(i18nc("@info:whatsthis", "Specify whether to show in the system tray tooltip, how long until each alarm is due."));
1732 grid->addWidget(mTooltipShowTimeTo, 3, 1, 1, 2, Qt::AlignLeft);
1734 widget = new QWidget; // this is to control the QWhatsThis text display area
1735 box = new QHBoxLayout(widget);
1736 box->setMargin(0);
1737 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1738 mTooltipTimeToPrefixLabel = new QLabel(i18nc("@label:textbox", "Prefix:"));
1739 box->addWidget(mTooltipTimeToPrefixLabel);
1740 mTooltipTimeToPrefix = new QLineEdit();
1741 box->addWidget(mTooltipTimeToPrefix);
1742 mTooltipTimeToPrefixLabel->setBuddy(mTooltipTimeToPrefix);
1743 widget->setWhatsThis(i18nc("@info:whatsthis", "Enter the text to be displayed in front of the time until the alarm, in the system tray tooltip."));
1744 grid->addWidget(widget, 4, 2, Qt::AlignLeft);
1745 group->setMaximumHeight(group->sizeHint().height());
1747 group = new QGroupBox(i18nc("@title:group", "Alarm List"));
1748 topGeneral->addWidget(group);
1749 QHBoxLayout* hlayout = new QHBoxLayout(group);
1750 hlayout->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1751 QVBoxLayout* colourLayout = new QVBoxLayout();
1752 colourLayout->setMargin(0);
1753 hlayout->addLayout(colourLayout);
1755 widget = new QWidget; // to group widgets for QWhatsThis text
1756 box = new QHBoxLayout(widget);
1757 box->setMargin(0);
1758 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) / 2);
1759 colourLayout->addWidget(widget);
1760 QLabel* label1 = new QLabel(i18nc("@label:listbox", "Disabled alarm color:"));
1761 box->addWidget(label1);
1762 box->setStretchFactor(new QWidget(widget), 0);
1763 mDisabledColour = new ColourButton();
1764 box->addWidget(mDisabledColour);
1765 label1->setBuddy(mDisabledColour);
1766 widget->setWhatsThis(i18nc("@info:whatsthis", "Choose the text color in the alarm list for disabled alarms."));
1768 widget = new QWidget; // to group widgets for QWhatsThis text
1769 box = new QHBoxLayout(widget);
1770 box->setMargin(0);
1771 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing) / 2);
1772 colourLayout->addWidget(widget);
1773 QLabel* label2 = new QLabel(i18nc("@label:listbox", "Archived alarm color:"));
1774 box->addWidget(label2);
1775 box->setStretchFactor(new QWidget(widget), 0);
1776 mArchivedColour = new ColourButton();
1777 box->addWidget(mArchivedColour);
1778 label2->setBuddy(mArchivedColour);
1779 widget->setWhatsThis(i18nc("@info:whatsthis", "Choose the text color in the alarm list for archived alarms."));
1780 hlayout->addStretch();
1782 if (topGeneral)
1783 topGeneral->addStretch(); // top adjust the widgets
1786 group = new QGroupBox(i18nc("@title:group", "Alarm Message Windows"));
1787 topWindows->addWidget(group);
1788 grid = new QGridLayout(group);
1789 grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
1790 grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1791 grid->setColumnStretch(1, 1);
1792 grid->setColumnMinimumWidth(0, indentWidth());
1793 mWindowPosition = new ButtonGroup(group);
1794 connect(mWindowPosition, &ButtonGroup::buttonSet, this, &ViewPrefTab::slotWindowPosChanged);
1796 QString whatsthis = xi18nc("@info:whatsthis",
1797 "<para>Choose how to reduce the chance of alarm messages being accidentally acknowledged:"
1798 "<list><item>Position alarm message windows as far as possible from the current mouse cursor location, or</item>"
1799 "<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>");
1800 radio = new QRadioButton(i18nc("@option:radio", "Position windows far from mouse cursor"), group);
1801 mWindowPosition->addButton(radio, 0);
1802 radio->setWhatsThis(whatsthis);
1803 grid->addWidget(radio, 0, 0, 1, 2, Qt::AlignLeft);
1804 radio = new QRadioButton(i18nc("@option:radio", "Center windows, delay activating window buttons"), group);
1805 mWindowPosition->addButton(radio, 1);
1806 radio->setWhatsThis(whatsthis);
1807 grid->addWidget(radio, 1, 0, 1, 2, Qt::AlignLeft);
1809 widget = new QWidget; // this is to control the QWhatsThis text display area
1810 box = new QHBoxLayout(widget);
1811 box->setMargin(0);
1812 box->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1813 mWindowButtonDelayLabel = new QLabel(i18nc("@label:spinbox", "Button activation delay (seconds):"));
1814 box->addWidget(mWindowButtonDelayLabel);
1815 mWindowButtonDelay = new QSpinBox();
1816 mWindowButtonDelay->setRange(1, 10);
1817 mWindowButtonDelayLabel->setBuddy(mWindowButtonDelay);
1818 box->addWidget(mWindowButtonDelay);
1819 widget->setWhatsThis(i18nc("@info:whatsthis",
1820 "Enter how long its buttons should remain disabled after the alarm message window is shown."));
1821 box->setStretchFactor(new QWidget(widget), 1); // left adjust the controls
1822 grid->addWidget(widget, 2, 1, Qt::AlignLeft);
1824 grid->setRowMinimumHeight(3, style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
1826 mModalMessages = new QCheckBox(i18nc("@option:check", "Message windows have a title bar and take keyboard focus"), group);
1827 mModalMessages->setMinimumSize(mModalMessages->sizeHint());
1828 mModalMessages->setWhatsThis(xi18nc("@info:whatsthis",
1829 "<para>Specify the characteristics of alarm message windows:"
1830 "<list><item>If checked, the window is a normal window with a title bar, which grabs keyboard input when it is displayed.</item>"
1831 "<item>If unchecked, the window does not interfere with your typing when "
1832 "it is displayed, but it has no title bar and cannot be moved or resized.</item></list></para>"));
1833 grid->addWidget(mModalMessages, 4, 0, 1, 2, Qt::AlignLeft);
1835 if (topWindows)
1836 topWindows->addStretch(); // top adjust the widgets
1839 void ViewPrefTab::restore(bool, bool allTabs)
1841 if (allTabs || mTabs->currentIndex() == mTabGeneral)
1843 mShowInSystemTray->setChecked(Preferences::showInSystemTray());
1844 int id;
1845 int mins = Preferences::autoHideSystemTray();
1846 switch (mins)
1848 case -1: id = 1; break; // hide if no active alarms
1849 case 0: id = 0; break; // never hide
1850 default:
1852 id = 2;
1853 int days = 0;
1854 int secs = 0;
1855 if (mins % 1440)
1856 secs = mins * 60;
1857 else
1858 days = mins / 1440;
1859 TimePeriod::Units units = secs ? TimePeriod::HoursMinutes
1860 : (days % 7) ? TimePeriod::Days : TimePeriod::Weeks;
1861 Duration duration((secs ? secs : days), (secs ? Duration::Seconds : Duration::Days));
1862 mAutoHideSystemTrayPeriod->setPeriod(duration, false, units);
1863 break;
1866 mAutoHideSystemTray->setButton(id);
1867 setTooltip(Preferences::tooltipAlarmCount(),
1868 Preferences::showTooltipAlarmTime(),
1869 Preferences::showTooltipTimeToAlarm(),
1870 Preferences::tooltipTimeToPrefix());
1871 mDisabledColour->setColor(Preferences::disabledColour());
1872 mArchivedColour->setColor(Preferences::archivedColour());
1874 if (allTabs || mTabs->currentIndex() == mTabWindows)
1876 mWindowPosition->setButton(Preferences::messageButtonDelay() ? 1 : 0);
1877 mWindowButtonDelay->setValue(Preferences::messageButtonDelay());
1878 mModalMessages->setChecked(Preferences::modalMessages());
1882 void ViewPrefTab::apply(bool syncToDisc)
1884 QColor colour = mDisabledColour->color();
1885 if (colour != Preferences::disabledColour())
1886 Preferences::setDisabledColour(colour);
1887 colour = mArchivedColour->color();
1888 if (colour != Preferences::archivedColour())
1889 Preferences::setArchivedColour(colour);
1890 int n = mTooltipShowAlarms->isChecked() ? -1 : 0;
1891 if (n && mTooltipMaxAlarms->isChecked())
1892 n = mTooltipMaxAlarmCount->value();
1893 if (n != Preferences::tooltipAlarmCount())
1894 Preferences::setTooltipAlarmCount(n);
1895 bool b = mTooltipShowTime->isChecked();
1896 if (b != Preferences::showTooltipAlarmTime())
1897 Preferences::setShowTooltipAlarmTime(b);
1898 b = mTooltipShowTimeTo->isChecked();
1899 if (b != Preferences::showTooltipTimeToAlarm())
1900 Preferences::setShowTooltipTimeToAlarm(b);
1901 QString text = mTooltipTimeToPrefix->text();
1902 if (text != Preferences::tooltipTimeToPrefix())
1903 Preferences::setTooltipTimeToPrefix(text);
1904 b = mShowInSystemTray->isChecked();
1905 if (b != Preferences::showInSystemTray())
1906 Preferences::setShowInSystemTray(b);
1907 if (b)
1909 switch (mAutoHideSystemTray->selectedId())
1911 case 0: n = 0; break; // never hide
1912 case 1: n = -1; break; // hide if no active alarms
1913 case 2: // hide if no alarms due within period
1914 n = mAutoHideSystemTrayPeriod->period().asSeconds() / 60;
1915 break;
1917 if (n != Preferences::autoHideSystemTray())
1918 Preferences::setAutoHideSystemTray(n);
1920 n = mWindowPosition->selectedId();
1921 if (n)
1922 n = mWindowButtonDelay->value();
1923 if (n != Preferences::messageButtonDelay())
1924 Preferences::setMessageButtonDelay(n);
1925 b = mModalMessages->isChecked();
1926 if (b != Preferences::modalMessages())
1927 Preferences::setModalMessages(b);
1928 PrefsTabBase::apply(syncToDisc);
1931 void ViewPrefTab::setTooltip(int maxAlarms, bool time, bool timeTo, const QString& prefix)
1933 if (!timeTo)
1934 time = true; // ensure that at least one time option is ticked
1936 // Set the states of the controls without calling signal
1937 // handlers, since these could change the checkboxes' states.
1938 mTooltipShowAlarms->blockSignals(true);
1939 mTooltipShowTime->blockSignals(true);
1940 mTooltipShowTimeTo->blockSignals(true);
1942 mTooltipShowAlarms->setChecked(maxAlarms);
1943 mTooltipMaxAlarms->setChecked(maxAlarms > 0);
1944 mTooltipMaxAlarmCount->setValue(maxAlarms > 0 ? maxAlarms : 1);
1945 mTooltipShowTime->setChecked(time);
1946 mTooltipShowTimeTo->setChecked(timeTo);
1947 mTooltipTimeToPrefix->setText(prefix);
1949 mTooltipShowAlarms->blockSignals(false);
1950 mTooltipShowTime->blockSignals(false);
1951 mTooltipShowTimeTo->blockSignals(false);
1953 // Enable/disable controls according to their states
1954 slotTooltipTimeToToggled(timeTo);
1955 slotTooltipAlarmsToggled(maxAlarms);
1958 void ViewPrefTab::slotTooltipAlarmsToggled(bool on)
1960 mTooltipMaxAlarms->setEnabled(on);
1961 mTooltipMaxAlarmCount->setEnabled(on && mTooltipMaxAlarms->isChecked());
1962 mTooltipShowTime->setEnabled(on);
1963 mTooltipShowTimeTo->setEnabled(on);
1964 on = on && mTooltipShowTimeTo->isChecked();
1965 mTooltipTimeToPrefix->setEnabled(on);
1966 mTooltipTimeToPrefixLabel->setEnabled(on);
1969 void ViewPrefTab::slotTooltipMaxToggled(bool on)
1971 mTooltipMaxAlarmCount->setEnabled(on && mTooltipMaxAlarms->isEnabled());
1974 void ViewPrefTab::slotTooltipTimeToggled(bool on)
1976 if (!on && !mTooltipShowTimeTo->isChecked())
1977 mTooltipShowTimeTo->setChecked(true);
1980 void ViewPrefTab::slotTooltipTimeToToggled(bool on)
1982 if (!on && !mTooltipShowTime->isChecked())
1983 mTooltipShowTime->setChecked(true);
1984 on = on && mTooltipShowTimeTo->isEnabled();
1985 mTooltipTimeToPrefix->setEnabled(on);
1986 mTooltipTimeToPrefixLabel->setEnabled(on);
1989 void ViewPrefTab::slotAutoHideSysTrayChanged(QAbstractButton* button)
1991 mAutoHideSystemTrayPeriod->setEnabled(mAutoHideSystemTray->id(button) == 2);
1994 void ViewPrefTab::slotWindowPosChanged(QAbstractButton* button)
1996 bool enable = mWindowPosition->id(button);
1997 mWindowButtonDelay->setEnabled(enable);
1998 mWindowButtonDelayLabel->setEnabled(enable);
2000 #include "moc_prefdlg_p.cpp"
2001 #include "moc_prefdlg.cpp"
2003 // vim: et sw=4: