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