kalarm

prefdlg.cpp
1/*
2 * prefdlg.cpp - program preferences dialog
3 * Program: kalarm
4 * Copyright © 2001-2008 by David Jarvie <djarvie@kde.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#include "kalarm.h"
22
23#include <tqobjectlist.h>
24#include <tqlayout.h>
25#include <tqbuttongroup.h>
26#include <tqvbox.h>
27#include <tqlineedit.h>
28#include <tqcheckbox.h>
29#include <tqradiobutton.h>
30#include <tqpushbutton.h>
31#include <tqcombobox.h>
32#include <tqwhatsthis.h>
33#include <tqtooltip.h>
34#include <tqstyle.h>
35
36#include <tdeglobal.h>
37#include <tdelocale.h>
38#include <tdestandarddirs.h>
39#include <kshell.h>
40#include <tdemessagebox.h>
41#include <tdeaboutdata.h>
42#include <tdeapplication.h>
43#include <kiconloader.h>
44#include <kcolorcombo.h>
45#include <kstdguiitem.h>
46#ifdef TQ_WS_X11
47#include <twin.h>
48#endif
49#include <kdebug.h>
50
51#include <kalarmd/kalarmd.h>
52
53#include "alarmcalendar.h"
54#include "alarmtimewidget.h"
55#include "daemon.h"
56#include "editdlg.h"
57#include "fontcolour.h"
58#include "functions.h"
59#include "kalarmapp.h"
60#include "kamail.h"
61#include "label.h"
62#include "latecancel.h"
63#include "mainwindow.h"
64#include "preferences.h"
65#include "radiobutton.h"
66#include "recurrenceedit.h"
67#ifndef WITHOUT_ARTS
68#include "sounddlg.h"
69#endif
70#include "soundpicker.h"
71#include "specialactions.h"
72#include "timeedit.h"
73#include "timespinbox.h"
74#include "traywindow.h"
75#include "prefdlg.moc"
76
77// Command strings for executing commands in different types of terminal windows.
78// %t = window title parameter
79// %c = command to execute in terminal
80// %w = command to execute in terminal, with 'sleep 86400' appended
81// %C = temporary command file to execute in terminal
82// %W = temporary command file to execute in terminal, with 'sleep 86400' appended
83static TQString xtermCommands[] = {
84 TQString::fromLatin1("xterm -sb -hold -title %t -e %c"),
85 TQString::fromLatin1("konsole --noclose -T %t -e ${SHELL:-sh} -c %c"),
86 TQString::fromLatin1("gnome-terminal -t %t -e %W"),
87 TQString::fromLatin1("eterm --pause -T %t -e %C"), // some systems use eterm...
88 TQString::fromLatin1("Eterm --pause -T %t -e %C"), // while some use Eterm
89 TQString::fromLatin1("rxvt -title %t -e ${SHELL:-sh} -c %w"),
90 TQString() // end of list indicator - don't change!
91};
92
93
94/*=============================================================================
95= Class KAlarmPrefDlg
96=============================================================================*/
97
98KAlarmPrefDlg* KAlarmPrefDlg::mInstance = 0;
99
100void KAlarmPrefDlg::display()
101{
102 if (!mInstance)
103 {
104 mInstance = new KAlarmPrefDlg;
105 mInstance->show();
106 }
107 else
108 {
109#ifdef TQ_WS_X11
110 KWin::WindowInfo info = KWin::windowInfo(mInstance->winId(), static_cast<unsigned long>(NET::WMGeometry | NET::WMDesktop));
111 KWin::setCurrentDesktop(info.desktop());
112#endif
113 mInstance->showNormal(); // un-minimise it if necessary
114 mInstance->raise();
115 mInstance->setActiveWindow();
116 }
117}
118
119KAlarmPrefDlg::KAlarmPrefDlg()
120 : KDialogBase(IconList, i18n("Preferences"), Help | Default | Ok | Apply | Cancel, Ok, 0, "PrefDlg", false, true)
121{
122 setWFlags(TQt::WDestructiveClose);
123 setIconListAllVisible(true);
124
125 TQVBox* frame = addVBoxPage(i18n("General"), i18n("General"), DesktopIcon("misc"));
126 mMiscPage = new MiscPrefTab(frame);
127
128 frame = addVBoxPage(i18n("Email"), i18n("Email Alarm Settings"), DesktopIcon("mail_generic"));
129 mEmailPage = new EmailPrefTab(frame);
130
131 frame = addVBoxPage(i18n("View"), i18n("View Settings"), DesktopIcon("view_choose"));
132 mViewPage = new ViewPrefTab(frame);
133
134 frame = addVBoxPage(i18n("Font & Color"), i18n("Default Font and Color"), DesktopIcon("colorize"));
135 mFontColourPage = new FontColourPrefTab(frame);
136
137 frame = addVBoxPage(i18n("Edit"), i18n("Default Alarm Edit Settings"), DesktopIcon("edit"));
138 mEditPage = new EditPrefTab(frame);
139
140 restore();
141 adjustSize();
142}
143
144KAlarmPrefDlg::~KAlarmPrefDlg()
145{
146 mInstance = 0;
147}
148
149// Restore all defaults in the options...
150void KAlarmPrefDlg::slotDefault()
151{
152 kdDebug(5950) << "KAlarmPrefDlg::slotDefault()" << endl;
153 mFontColourPage->setDefaults();
154 mEmailPage->setDefaults();
155 mViewPage->setDefaults();
156 mEditPage->setDefaults();
157 mMiscPage->setDefaults();
158}
159
160void KAlarmPrefDlg::slotHelp()
161{
162 tdeApp->invokeHelp("preferences");
163}
164
165// Apply the preferences that are currently selected
166void KAlarmPrefDlg::slotApply()
167{
168 kdDebug(5950) << "KAlarmPrefDlg::slotApply()" << endl;
169 TQString errmsg = mEmailPage->validate();
170 if (!errmsg.isEmpty())
171 {
172 showPage(pageIndex(mEmailPage->parentWidget()));
173 if (KMessageBox::warningYesNo(this, errmsg) != KMessageBox::Yes)
174 {
175 mValid = false;
176 return;
177 }
178 }
179 errmsg = mEditPage->validate();
180 if (!errmsg.isEmpty())
181 {
182 showPage(pageIndex(mEditPage->parentWidget()));
183 KMessageBox::sorry(this, errmsg);
184 mValid = false;
185 return;
186 }
187 mValid = true;
188 mFontColourPage->apply(false);
189 mEmailPage->apply(false);
190 mViewPage->apply(false);
191 mEditPage->apply(false);
192 mMiscPage->apply(false);
193 Preferences::syncToDisc();
194}
195
196// Apply the preferences that are currently selected
197void KAlarmPrefDlg::slotOk()
198{
199 kdDebug(5950) << "KAlarmPrefDlg::slotOk()" << endl;
200 mValid = true;
201 slotApply();
202 if (mValid)
203 KDialogBase::slotOk();
204}
205
206// Discard the current preferences and close the dialogue
207void KAlarmPrefDlg::slotCancel()
208{
209 kdDebug(5950) << "KAlarmPrefDlg::slotCancel()" << endl;
210 restore();
211 KDialogBase::slotCancel();
212}
213
214// Discard the current preferences and use the present ones
215void KAlarmPrefDlg::restore()
216{
217 kdDebug(5950) << "KAlarmPrefDlg::restore()" << endl;
218 mFontColourPage->restore();
219 mEmailPage->restore();
220 mViewPage->restore();
221 mEditPage->restore();
222 mMiscPage->restore();
223}
224
225
226/*=============================================================================
227= Class PrefsTabBase
228=============================================================================*/
229int PrefsTabBase::mIndentWidth = 0;
230
231PrefsTabBase::PrefsTabBase(TQVBox* frame)
232 : TQWidget(frame),
233 mPage(frame)
234{
235 if (!mIndentWidth)
236 mIndentWidth = style().subRect(TQStyle::SR_RadioButtonIndicator, this).width();
237}
238
239void PrefsTabBase::apply(bool syncToDisc)
240{
241 Preferences::save(syncToDisc);
242}
243
244
245
246/*=============================================================================
247= Class MiscPrefTab
248=============================================================================*/
249
250MiscPrefTab::MiscPrefTab(TQVBox* frame)
251 : PrefsTabBase(frame)
252{
253 // Get alignment to use in TQGridLayout (AlignAuto doesn't work correctly there)
254 int alignment = TQApplication::reverseLayout() ? TQt::AlignRight : TQt::AlignLeft;
255
256 TQGroupBox* group = new TQButtonGroup(i18n("Run Mode"), mPage, "modeGroup");
257 TQGridLayout* grid = new TQGridLayout(group, 6, 2, KDialog::marginHint(), KDialog::spacingHint());
258 grid->setColStretch(2, 1);
259 grid->addColSpacing(0, indentWidth());
260 grid->addColSpacing(1, indentWidth());
261 grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
262
263 // Run-on-demand radio button
264 mRunOnDemand = new TQRadioButton(i18n("&Run only on demand"), group, "runDemand");
265 mRunOnDemand->setFixedSize(mRunOnDemand->sizeHint());
266 connect(mRunOnDemand, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotRunModeToggled(bool)));
267 TQWhatsThis::add(mRunOnDemand,
268 i18n("Check to run KAlarm only when required.\n\n"
269 "Notes:\n"
270 "1. Alarms are displayed even when KAlarm is not running, since alarm monitoring is done by the alarm daemon.\n"
271 "2. With this option selected, the system tray icon can be displayed or hidden independently of KAlarm."));
272 grid->addMultiCellWidget(mRunOnDemand, 1, 1, 0, 2, alignment);
273
274 // Run-in-system-tray radio button
275 mRunInSystemTray = new TQRadioButton(i18n("Run continuously in system &tray"), group, "runTray");
276 mRunInSystemTray->setFixedSize(mRunInSystemTray->sizeHint());
277 connect(mRunInSystemTray, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotRunModeToggled(bool)));
278 TQWhatsThis::add(mRunInSystemTray,
279 i18n("Check to run KAlarm continuously in the TDE system tray.\n\n"
280 "Notes:\n"
281 "1. With this option selected, closing the system tray icon will quit KAlarm.\n"
282 "2. You do not need to select this option in order for alarms to be displayed, since alarm monitoring is done by the alarm daemon."
283 " Running in the system tray simply provides easy access and a status indication."));
284 grid->addMultiCellWidget(mRunInSystemTray, 2, 2, 0, 2, alignment);
285
286 // Run continuously options
287 mDisableAlarmsIfStopped = new TQCheckBox(i18n("Disa&ble alarms while not running"), group, "disableAl");
288 mDisableAlarmsIfStopped->setFixedSize(mDisableAlarmsIfStopped->sizeHint());
289 connect(mDisableAlarmsIfStopped, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotDisableIfStoppedToggled(bool)));
290 TQWhatsThis::add(mDisableAlarmsIfStopped,
291 i18n("Check to disable alarms whenever KAlarm is not running. Alarms will only appear while the system tray icon is visible."));
292 grid->addMultiCellWidget(mDisableAlarmsIfStopped, 3, 3, 1, 2, alignment);
293
294 mQuitWarn = new TQCheckBox(i18n("Warn before &quitting"), group, "disableAl");
295 mQuitWarn->setFixedSize(mQuitWarn->sizeHint());
296 TQWhatsThis::add(mQuitWarn,
297 i18n("Check to display a warning prompt before quitting KAlarm."));
298 grid->addWidget(mQuitWarn, 4, 2, alignment);
299
300 mAutostartTrayIcon = new TQCheckBox(i18n("Autostart at &login"), group, "autoTray");
301#ifdef AUTOSTART_BY_KALARMD
302 connect(mAutostartTrayIcon, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotAutostartToggled(bool)));
303#endif
304 grid->addMultiCellWidget(mAutostartTrayIcon, 5, 5, 0, 2, alignment);
305
306 // Autostart alarm daemon
307 mAutostartDaemon = new TQCheckBox(i18n("Start alarm monitoring at lo&gin"), group, "startDaemon");
308 mAutostartDaemon->setFixedSize(mAutostartDaemon->sizeHint());
309 connect(mAutostartDaemon, TQ_SIGNAL(clicked()), TQ_SLOT(slotAutostartDaemonClicked()));
310 TQWhatsThis::add(mAutostartDaemon,
311 i18n("Automatically start alarm monitoring whenever you start TDE, by running the alarm daemon (%1).\n\n"
312 "This option should always be checked unless you intend to discontinue use of KAlarm.")
313 .arg(TQString::fromLatin1(DAEMON_APP_NAME)));
314 grid->addMultiCellWidget(mAutostartDaemon, 6, 6, 0, 2, alignment);
315
316 group->setFixedHeight(group->sizeHint().height());
317
318 // Start-of-day time
319 TQHBox* itemBox = new TQHBox(mPage);
320 TQHBox* box = new TQHBox(itemBox); // this is to control the TQWhatsThis text display area
321 box->setSpacing(KDialog::spacingHint());
322 TQLabel* label = new TQLabel(i18n("&Start of day for date-only alarms:"), box);
323 mStartOfDay = new TimeEdit(box);
324 mStartOfDay->setFixedSize(mStartOfDay->sizeHint());
325 label->setBuddy(mStartOfDay);
326 static const TQString startOfDayText = i18n("The earliest time of day at which a date-only alarm (i.e. "
327 "an alarm with \"any time\" specified) will be triggered.");
328 TQWhatsThis::add(box, TQString("%1\n\n%2").arg(startOfDayText).arg(TimeSpinBox::shiftWhatsThis()));
329 itemBox->setStretchFactor(new TQWidget(itemBox), 1); // left adjust the controls
330 itemBox->setFixedHeight(box->sizeHint().height());
331
332 // Confirm alarm deletion?
333 itemBox = new TQHBox(mPage); // this is to allow left adjustment
334 mConfirmAlarmDeletion = new TQCheckBox(i18n("Con&firm alarm deletions"), itemBox, "confirmDeletion");
335 mConfirmAlarmDeletion->setMinimumSize(mConfirmAlarmDeletion->sizeHint());
336 TQWhatsThis::add(mConfirmAlarmDeletion,
337 i18n("Check to be prompted for confirmation each time you delete an alarm."));
338 itemBox->setStretchFactor(new TQWidget(itemBox), 1); // left adjust the controls
339 itemBox->setFixedHeight(itemBox->sizeHint().height());
340
341 // Expired alarms
342 group = new TQGroupBox(i18n("Expired Alarms"), mPage);
343 grid = new TQGridLayout(group, 2, 2, KDialog::marginHint(), KDialog::spacingHint());
344 grid->setColStretch(1, 1);
345 grid->addColSpacing(0, indentWidth());
346 grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
347 mKeepExpired = new TQCheckBox(i18n("Keep alarms after e&xpiry"), group, "keepExpired");
348 mKeepExpired->setFixedSize(mKeepExpired->sizeHint());
349 connect(mKeepExpired, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotExpiredToggled(bool)));
350 TQWhatsThis::add(mKeepExpired,
351 i18n("Check to store alarms after expiry or deletion (except deleted alarms which were never triggered)."));
352 grid->addMultiCellWidget(mKeepExpired, 1, 1, 0, 1, alignment);
353
354 box = new TQHBox(group);
355 box->setSpacing(KDialog::spacingHint());
356 mPurgeExpired = new TQCheckBox(i18n("Discard ex&pired alarms after:"), box, "purgeExpired");
357 mPurgeExpired->setMinimumSize(mPurgeExpired->sizeHint());
358 connect(mPurgeExpired, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotExpiredToggled(bool)));
359 mPurgeAfter = new SpinBox(box);
360 mPurgeAfter->setMinValue(1);
361 mPurgeAfter->setLineShiftStep(10);
362 mPurgeAfter->setMinimumSize(mPurgeAfter->sizeHint());
363 mPurgeAfterLabel = new TQLabel(i18n("da&ys"), box);
364 mPurgeAfterLabel->setMinimumSize(mPurgeAfterLabel->sizeHint());
365 mPurgeAfterLabel->setBuddy(mPurgeAfter);
366 TQWhatsThis::add(box,
367 i18n("Uncheck to store expired alarms indefinitely. Check to enter how long expired alarms should be stored."));
368 grid->addWidget(box, 2, 1, alignment);
369
370 mClearExpired = new TQPushButton(i18n("Clear Expired Alar&ms"), group);
371 mClearExpired->setFixedSize(mClearExpired->sizeHint());
372 connect(mClearExpired, TQ_SIGNAL(clicked()), TQ_SLOT(slotClearExpired()));
373 TQWhatsThis::add(mClearExpired,
374 i18n("Delete all existing expired alarms."));
375 grid->addWidget(mClearExpired, 3, 1, alignment);
376 group->setFixedHeight(group->sizeHint().height());
377
378 // Terminal window to use for command alarms
379 group = new TQGroupBox(i18n("Terminal for Command Alarms"), mPage);
380 TQWhatsThis::add(group,
381 i18n("Choose which application to use when a command alarm is executed in a terminal window"));
382 grid = new TQGridLayout(group, 1, 3, KDialog::marginHint(), KDialog::spacingHint());
383 grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
384 int row = 0;
385
386 mXtermType = new TQButtonGroup(group);
387 mXtermType->hide();
388 TQString whatsThis = i18n("The parameter is a command line, e.g. 'xterm -e'", "Check to execute command alarms in a terminal window by '%1'");
389 int index = 0;
390 mXtermFirst = -1;
391 for (mXtermCount = 0; !xtermCommands[mXtermCount].isNull(); ++mXtermCount)
392 {
393 TQString cmd = xtermCommands[mXtermCount];
394 TQStringList args = KShell::splitArgs(cmd);
395 if (args.isEmpty() || TDEStandardDirs::findExe(args[0]).isEmpty())
396 continue;
397 TQRadioButton* radio = new TQRadioButton(args[0], group);
398 radio->setMinimumSize(radio->sizeHint());
399 mXtermType->insert(radio, mXtermCount);
400 if (mXtermFirst < 0)
401 mXtermFirst = mXtermCount; // note the id of the first button
402 cmd.replace("%t", tdeApp->aboutData()->programName());
403 cmd.replace("%c", "<command>");
404 cmd.replace("%w", "<command; sleep>");
405 cmd.replace("%C", "[command]");
406 cmd.replace("%W", "[command; sleep]");
407 TQWhatsThis::add(radio, whatsThis.arg(cmd));
408 grid->addWidget(radio, (row = index/3 + 1), index % 3, TQt::AlignAuto);
409 ++index;
410 }
411
412 box = new TQHBox(group);
413 grid->addMultiCellWidget(box, row + 1, row + 1, 0, 2, TQt::AlignAuto);
414 TQRadioButton* radio = new TQRadioButton(i18n("Other:"), box);
415 radio->setFixedSize(radio->sizeHint());
416 connect(radio, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotOtherTerminalToggled(bool)));
417 mXtermType->insert(radio, mXtermCount);
418 if (mXtermFirst < 0)
419 mXtermFirst = mXtermCount; // note the id of the first button
420 mXtermCommand = new TQLineEdit(box);
421 TQWhatsThis::add(box,
422 i18n("Enter the full command line needed to execute a command in your chosen terminal window. "
423 "By default the alarm's command string will be appended to what you enter here. "
424 "See the KAlarm Handbook for details of special codes to tailor the command line."));
425
426 mPage->setStretchFactor(new TQWidget(mPage), 1); // top adjust the widgets
427}
428
429void MiscPrefTab::restore()
430{
431 mAutostartDaemon->setChecked(Daemon::autoStart());
432 bool systray = Preferences::mRunInSystemTray;
433 mRunInSystemTray->setChecked(systray);
434 mRunOnDemand->setChecked(!systray);
435 mDisableAlarmsIfStopped->setChecked(Preferences::mDisableAlarmsIfStopped);
436 mQuitWarn->setChecked(Preferences::quitWarn());
437 mAutostartTrayIcon->setChecked(Preferences::mAutostartTrayIcon);
438 mConfirmAlarmDeletion->setChecked(Preferences::confirmAlarmDeletion());
439 mStartOfDay->setValue(Preferences::mStartOfDay);
440 setExpiredControls(Preferences::mExpiredKeepDays);
441 TQString xtermCmd = Preferences::cmdXTermCommand();
442 int id = mXtermFirst;
443 if (!xtermCmd.isEmpty())
444 {
445 for ( ; id < mXtermCount; ++id)
446 {
447 if (mXtermType->find(id) && xtermCmd == xtermCommands[id])
448 break;
449 }
450 }
451 mXtermType->setButton(id);
452 mXtermCommand->setEnabled(id == mXtermCount);
453 mXtermCommand->setText(id == mXtermCount ? xtermCmd : "");
454 slotDisableIfStoppedToggled(true);
455}
456
457void MiscPrefTab::apply(bool syncToDisc)
458{
459 // First validate anything entered in Other X-terminal command
460 int xtermID = mXtermType->selectedId();
461 if (xtermID >= mXtermCount)
462 {
463 TQString cmd = mXtermCommand->text();
464 if (cmd.isEmpty())
465 xtermID = -1; // 'Other' is only acceptable if it's non-blank
466 else
467 {
468 TQStringList args = KShell::splitArgs(cmd);
469 cmd = args.isEmpty() ? TQString() : args[0];
470 if (TDEStandardDirs::findExe(cmd).isEmpty())
471 {
472 mXtermCommand->setFocus();
473 if (KMessageBox::warningContinueCancel(this, i18n("Command to invoke terminal window not found:\n%1").arg(cmd))
474 != KMessageBox::Continue)
475 return;
476 }
477 }
478 }
479 if (xtermID < 0)
480 {
481 xtermID = mXtermFirst;
482 mXtermType->setButton(mXtermFirst);
483 }
484
485 bool systray = mRunInSystemTray->isChecked();
486 Preferences::mRunInSystemTray = systray;
487 Preferences::mDisableAlarmsIfStopped = mDisableAlarmsIfStopped->isChecked();
488 if (mQuitWarn->isEnabled())
489 Preferences::setQuitWarn(mQuitWarn->isChecked());
490 Preferences::mAutostartTrayIcon = mAutostartTrayIcon->isChecked();
491#ifdef AUTOSTART_BY_KALARMD
492 bool newAutostartDaemon = mAutostartDaemon->isChecked() || Preferences::mAutostartTrayIcon;
493#else
494 bool newAutostartDaemon = mAutostartDaemon->isChecked();
495#endif
496 if (newAutostartDaemon != Daemon::autoStart())
497 Daemon::enableAutoStart(newAutostartDaemon);
498 Preferences::setConfirmAlarmDeletion(mConfirmAlarmDeletion->isChecked());
499 int sod = mStartOfDay->value();
500 Preferences::mStartOfDay.setHMS(sod/60, sod%60, 0);
501 Preferences::mExpiredKeepDays = !mKeepExpired->isChecked() ? 0
502 : mPurgeExpired->isChecked() ? mPurgeAfter->value() : -1;
503 Preferences::mCmdXTermCommand = (xtermID < mXtermCount) ? xtermCommands[xtermID] : mXtermCommand->text();
504 PrefsTabBase::apply(syncToDisc);
505}
506
507void MiscPrefTab::setDefaults()
508{
509 mAutostartDaemon->setChecked(true);
510 bool systray = Preferences::default_runInSystemTray;
511 mRunInSystemTray->setChecked(systray);
512 mRunOnDemand->setChecked(!systray);
513 mDisableAlarmsIfStopped->setChecked(Preferences::default_disableAlarmsIfStopped);
514 mQuitWarn->setChecked(Preferences::default_quitWarn);
515 mAutostartTrayIcon->setChecked(Preferences::default_autostartTrayIcon);
516 mConfirmAlarmDeletion->setChecked(Preferences::default_confirmAlarmDeletion);
517 mStartOfDay->setValue(Preferences::default_startOfDay);
518 setExpiredControls(Preferences::default_expiredKeepDays);
519 mXtermType->setButton(mXtermFirst);
520 mXtermCommand->setEnabled(false);
521 slotDisableIfStoppedToggled(true);
522}
523
524void MiscPrefTab::slotAutostartDaemonClicked()
525{
526 if (!mAutostartDaemon->isChecked()
527 && KMessageBox::warningYesNo(this,
528 i18n("You should not uncheck this option unless you intend to discontinue use of KAlarm"),
529 TQString(), KStdGuiItem::cont(), KStdGuiItem::cancel()
530 ) != KMessageBox::Yes)
531 mAutostartDaemon->setChecked(true);
532}
533
534void MiscPrefTab::slotRunModeToggled(bool)
535{
536 bool systray = mRunInSystemTray->isOn();
537 mAutostartTrayIcon->setText(systray ? i18n("Autostart at &login") : i18n("Autostart system tray &icon at login"));
538 TQWhatsThis::add(mAutostartTrayIcon, (systray ? i18n("Check to run KAlarm whenever you start TDE.")
539 : i18n("Check to display the system tray icon whenever you start TDE.")));
540 mDisableAlarmsIfStopped->setEnabled(systray);
541 slotDisableIfStoppedToggled(true);
542}
543
544/******************************************************************************
545* If autostart at login is selected, the daemon must be autostarted so that it
546* can autostart KAlarm, in which case disable the daemon autostart option.
547*/
548void MiscPrefTab::slotAutostartToggled(bool)
549{
550#ifdef AUTOSTART_BY_KALARMD
551 mAutostartDaemon->setEnabled(!mAutostartTrayIcon->isChecked());
552#endif
553}
554
555void MiscPrefTab::slotDisableIfStoppedToggled(bool)
556{
557 bool enable = mDisableAlarmsIfStopped->isEnabled() && mDisableAlarmsIfStopped->isChecked();
558 mQuitWarn->setEnabled(enable);
559}
560
561void MiscPrefTab::setExpiredControls(int purgeDays)
562{
563 mKeepExpired->setChecked(purgeDays);
564 mPurgeExpired->setChecked(purgeDays > 0);
565 mPurgeAfter->setValue(purgeDays > 0 ? purgeDays : 0);
566 slotExpiredToggled(true);
567}
568
569void MiscPrefTab::slotExpiredToggled(bool)
570{
571 bool keep = mKeepExpired->isChecked();
572 bool after = keep && mPurgeExpired->isChecked();
573 mPurgeExpired->setEnabled(keep);
574 mPurgeAfter->setEnabled(after);
575 mPurgeAfterLabel->setEnabled(keep);
576 mClearExpired->setEnabled(keep);
577}
578
579void MiscPrefTab::slotClearExpired()
580{
581 AlarmCalendar* cal = AlarmCalendar::expiredCalendarOpen();
582 if (cal)
583 cal->purgeAll();
584}
585
586void MiscPrefTab::slotOtherTerminalToggled(bool on)
587{
588 mXtermCommand->setEnabled(on);
589}
590
591
592/*=============================================================================
593= Class EmailPrefTab
594=============================================================================*/
595
596EmailPrefTab::EmailPrefTab(TQVBox* frame)
597 : PrefsTabBase(frame),
598 mAddressChanged(false),
599 mBccAddressChanged(false)
600{
601 TQHBox* box = new TQHBox(mPage);
602 box->setSpacing(2*KDialog::spacingHint());
603 TQLabel* label = new TQLabel(i18n("Email client:"), box);
604 mEmailClient = new ButtonGroup(box);
605 mEmailClient->hide();
606 RadioButton* radio = new RadioButton(i18n("&KMail"), box, "kmail");
607 radio->setMinimumSize(radio->sizeHint());
608 mEmailClient->insert(radio, Preferences::KMAIL);
609 radio = new RadioButton(i18n("&Sendmail"), box, "sendmail");
610 radio->setMinimumSize(radio->sizeHint());
611 mEmailClient->insert(radio, Preferences::SENDMAIL);
612 connect(mEmailClient, TQ_SIGNAL(buttonSet(int)), TQ_SLOT(slotEmailClientChanged(int)));
613 box->setFixedHeight(box->sizeHint().height());
614 TQWhatsThis::add(box,
615 i18n("Choose how to send email when an email alarm is triggered.\n"
616 "KMail: The email is sent automatically via KMail. KMail is started first if necessary.\n"
617 "Sendmail: The email is sent automatically. This option will only work if "
618 "your system is configured to use sendmail or a sendmail compatible mail transport agent."));
619
620 box = new TQHBox(mPage); // this is to allow left adjustment
621 mEmailCopyToKMail = new TQCheckBox(i18n("Co&py sent emails into KMail's %1 folder").arg(KAMail::i18n_sent_mail()), box);
622 mEmailCopyToKMail->setFixedSize(mEmailCopyToKMail->sizeHint());
623 TQWhatsThis::add(mEmailCopyToKMail,
624 i18n("After sending an email, store a copy in KMail's %1 folder").arg(KAMail::i18n_sent_mail()));
625 box->setStretchFactor(new TQWidget(box), 1); // left adjust the controls
626 box->setFixedHeight(box->sizeHint().height());
627
628 // Your Email Address group box
629 TQGroupBox* group = new TQGroupBox(i18n("Your Email Address"), mPage);
630 TQGridLayout* grid = new TQGridLayout(group, 6, 3, KDialog::marginHint(), KDialog::spacingHint());
631 grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
632 grid->setColStretch(1, 1);
633
634 // 'From' email address controls ...
635 label = new Label(EditAlarmDlg::i18n_f_EmailFrom(), group);
636 label->setFixedSize(label->sizeHint());
637 grid->addWidget(label, 1, 0);
638 mFromAddressGroup = new ButtonGroup(group);
639 mFromAddressGroup->hide();
640 connect(mFromAddressGroup, TQ_SIGNAL(buttonSet(int)), TQ_SLOT(slotFromAddrChanged(int)));
641
642 // Line edit to enter a 'From' email address
643 radio = new RadioButton(group);
644 mFromAddressGroup->insert(radio, Preferences::MAIL_FROM_ADDR);
645 radio->setFixedSize(radio->sizeHint());
646 label->setBuddy(radio);
647 grid->addWidget(radio, 1, 1);
648 mEmailAddress = new TQLineEdit(group);
649 connect(mEmailAddress, TQ_SIGNAL(textChanged(const TQString&)), TQ_SLOT(slotAddressChanged()));
650 TQString whatsThis = i18n("Your email address, used to identify you as the sender when sending email alarms.");
651 TQWhatsThis::add(radio, whatsThis);
652 TQWhatsThis::add(mEmailAddress, whatsThis);
653 radio->setFocusWidget(mEmailAddress);
654 grid->addWidget(mEmailAddress, 1, 2);
655
656 // 'From' email address to be taken from Control Centre
657 radio = new RadioButton(i18n("&Use address from Control Center"), group);
658 radio->setFixedSize(radio->sizeHint());
659 mFromAddressGroup->insert(radio, Preferences::MAIL_FROM_CONTROL_CENTRE);
660 TQWhatsThis::add(radio,
661 i18n("Check to use the email address set in the Trinity Control Center, to identify you as the sender when sending email alarms."));
662 grid->addMultiCellWidget(radio, 2, 2, 1, 2, TQt::AlignAuto);
663
664 // 'From' email address to be picked from KMail's identities when the email alarm is configured
665 radio = new RadioButton(i18n("Use KMail &identities"), group);
666 radio->setFixedSize(radio->sizeHint());
667 mFromAddressGroup->insert(radio, Preferences::MAIL_FROM_KMAIL);
668 TQWhatsThis::add(radio,
669 i18n("Check to use KMail's email identities to identify you as the sender when sending email alarms. "
670 "For existing email alarms, KMail's default identity will be used. "
671 "For new email alarms, you will be able to pick which of KMail's identities to use."));
672 grid->addMultiCellWidget(radio, 3, 3, 1, 2, TQt::AlignAuto);
673
674 // 'Bcc' email address controls ...
675 grid->addRowSpacing(4, KDialog::spacingHint());
676 label = new Label(i18n("'Bcc' email address", "&Bcc:"), group);
677 label->setFixedSize(label->sizeHint());
678 grid->addWidget(label, 5, 0);
679 mBccAddressGroup = new ButtonGroup(group);
680 mBccAddressGroup->hide();
681 connect(mBccAddressGroup, TQ_SIGNAL(buttonSet(int)), TQ_SLOT(slotBccAddrChanged(int)));
682
683 // Line edit to enter a 'Bcc' email address
684 radio = new RadioButton(group);
685 radio->setFixedSize(radio->sizeHint());
686 mBccAddressGroup->insert(radio, Preferences::MAIL_FROM_ADDR);
687 label->setBuddy(radio);
688 grid->addWidget(radio, 5, 1);
689 mEmailBccAddress = new TQLineEdit(group);
690 whatsThis = i18n("Your email address, used for blind copying email alarms to yourself. "
691 "If you want blind copies to be sent to your account on the computer which KAlarm runs on, you can simply enter your user login name.");
692 TQWhatsThis::add(radio, whatsThis);
693 TQWhatsThis::add(mEmailBccAddress, whatsThis);
694 radio->setFocusWidget(mEmailBccAddress);
695 grid->addWidget(mEmailBccAddress, 5, 2);
696
697 // 'Bcc' email address to be taken from Control Centre
698 radio = new RadioButton(i18n("Us&e address from Control Center"), group);
699 radio->setFixedSize(radio->sizeHint());
700 mBccAddressGroup->insert(radio, Preferences::MAIL_FROM_CONTROL_CENTRE);
701 TQWhatsThis::add(radio,
702 i18n("Check to use the email address set in the Trinity Control Center, for blind copying email alarms to yourself."));
703 grid->addMultiCellWidget(radio, 6, 6, 1, 2, TQt::AlignAuto);
704
705 group->setFixedHeight(group->sizeHint().height());
706
707 box = new TQHBox(mPage); // this is to allow left adjustment
708 mEmailQueuedNotify = new TQCheckBox(i18n("&Notify when remote emails are queued"), box);
709 mEmailQueuedNotify->setFixedSize(mEmailQueuedNotify->sizeHint());
710 TQWhatsThis::add(mEmailQueuedNotify,
711 i18n("Display a notification message whenever an email alarm has queued an email for sending to a remote system. "
712 "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."));
713 box->setStretchFactor(new TQWidget(box), 1); // left adjust the controls
714 box->setFixedHeight(box->sizeHint().height());
715
716 mPage->setStretchFactor(new TQWidget(mPage), 1); // top adjust the widgets
717}
718
719void EmailPrefTab::restore()
720{
721 mEmailClient->setButton(Preferences::mEmailClient);
722 mEmailCopyToKMail->setChecked(Preferences::emailCopyToKMail());
723 setEmailAddress(Preferences::mEmailFrom, Preferences::mEmailAddress);
724 setEmailBccAddress((Preferences::mEmailBccFrom == Preferences::MAIL_FROM_CONTROL_CENTRE), Preferences::mEmailBccAddress);
725 mEmailQueuedNotify->setChecked(Preferences::emailQueuedNotify());
726 mAddressChanged = mBccAddressChanged = false;
727}
728
729void EmailPrefTab::apply(bool syncToDisc)
730{
731 int client = mEmailClient->id(mEmailClient->selected());
732 Preferences::mEmailClient = (client >= 0) ? Preferences::MailClient(client) : Preferences::default_emailClient;
733 Preferences::mEmailCopyToKMail = mEmailCopyToKMail->isChecked();
734 Preferences::setEmailAddress(static_cast<Preferences::MailFrom>(mFromAddressGroup->selectedId()), mEmailAddress->text().stripWhiteSpace());
735 Preferences::setEmailBccAddress((mBccAddressGroup->selectedId() == Preferences::MAIL_FROM_CONTROL_CENTRE), mEmailBccAddress->text().stripWhiteSpace());
736 Preferences::setEmailQueuedNotify(mEmailQueuedNotify->isChecked());
737 PrefsTabBase::apply(syncToDisc);
738}
739
740void EmailPrefTab::setDefaults()
741{
742 mEmailClient->setButton(Preferences::default_emailClient);
743 setEmailAddress(Preferences::default_emailFrom(), Preferences::default_emailAddress);
744 setEmailBccAddress((Preferences::default_emailBccFrom == Preferences::MAIL_FROM_CONTROL_CENTRE), Preferences::default_emailBccAddress);
745 mEmailQueuedNotify->setChecked(Preferences::default_emailQueuedNotify);
746}
747
748void EmailPrefTab::setEmailAddress(Preferences::MailFrom from, const TQString& address)
749{
750 mFromAddressGroup->setButton(from);
751 mEmailAddress->setText(from == Preferences::MAIL_FROM_ADDR ? address.stripWhiteSpace() : TQString());
752}
753
754void EmailPrefTab::setEmailBccAddress(bool useControlCentre, const TQString& address)
755{
756 mBccAddressGroup->setButton(useControlCentre ? Preferences::MAIL_FROM_CONTROL_CENTRE : Preferences::MAIL_FROM_ADDR);
757 mEmailBccAddress->setText(useControlCentre ? TQString() : address.stripWhiteSpace());
758}
759
760void EmailPrefTab::slotEmailClientChanged(int id)
761{
762 mEmailCopyToKMail->setEnabled(id == Preferences::SENDMAIL);
763}
764
765void EmailPrefTab::slotFromAddrChanged(int id)
766{
767 mEmailAddress->setEnabled(id == Preferences::MAIL_FROM_ADDR);
768 mAddressChanged = true;
769}
770
771void EmailPrefTab::slotBccAddrChanged(int id)
772{
773 mEmailBccAddress->setEnabled(id == Preferences::MAIL_FROM_ADDR);
774 mBccAddressChanged = true;
775}
776
777TQString EmailPrefTab::validate()
778{
779 if (mAddressChanged)
780 {
781 mAddressChanged = false;
782 TQString errmsg = validateAddr(mFromAddressGroup, mEmailAddress, KAMail::i18n_NeedFromEmailAddress());
783 if (!errmsg.isEmpty())
784 return errmsg;
785 }
786 if (mBccAddressChanged)
787 {
788 mBccAddressChanged = false;
789 return validateAddr(mBccAddressGroup, mEmailBccAddress, i18n("No valid 'Bcc' email address is specified."));
790 }
791 return TQString();
792}
793
794TQString EmailPrefTab::validateAddr(ButtonGroup* group, TQLineEdit* addr, const TQString& msg)
795{
796 TQString errmsg = i18n("%1\nAre you sure you want to save your changes?").arg(msg);
797 switch (group->selectedId())
798 {
799 case Preferences::MAIL_FROM_CONTROL_CENTRE:
800 if (!KAMail::controlCentreAddress().isEmpty())
801 return TQString();
802 errmsg = i18n("No email address is currently set in the Trinity Control Center. %1").arg(errmsg);
803 break;
804 case Preferences::MAIL_FROM_KMAIL:
805 if (KAMail::identitiesExist())
806 return TQString();
807 errmsg = i18n("No KMail identities currently exist. %1").arg(errmsg);
808 break;
809 case Preferences::MAIL_FROM_ADDR:
810 if (!addr->text().stripWhiteSpace().isEmpty())
811 return TQString();
812 break;
813 }
814 return errmsg;
815}
816
817
818/*=============================================================================
819= Class FontColourPrefTab
820=============================================================================*/
821
822FontColourPrefTab::FontColourPrefTab(TQVBox* frame)
823 : PrefsTabBase(frame)
824{
825 mFontChooser = new FontColourChooser(mPage, 0, false, TQStringList(), i18n("Message Font && Color"), true, false);
826 mPage->setStretchFactor(mFontChooser, 1);
827
828 TQFrame* layoutBox = new TQFrame(mPage);
829 TQHBoxLayout* hlayout = new TQHBoxLayout(layoutBox);
830 TQVBoxLayout* colourLayout = new TQVBoxLayout(hlayout, KDialog::spacingHint());
831 hlayout->addStretch();
832
833 TQHBox* box = new TQHBox(layoutBox); // to group widgets for TQWhatsThis text
834 box->setSpacing(KDialog::spacingHint()/2);
835 colourLayout->addWidget(box);
836 TQLabel* label1 = new TQLabel(i18n("Di&sabled alarm color:"), box);
837 box->setStretchFactor(new TQWidget(box), 1);
838 mDisabledColour = new KColorCombo(box);
839 label1->setBuddy(mDisabledColour);
840 TQWhatsThis::add(box,
841 i18n("Choose the text color in the alarm list for disabled alarms."));
842
843 box = new TQHBox(layoutBox); // to group widgets for TQWhatsThis text
844 box->setSpacing(KDialog::spacingHint()/2);
845 colourLayout->addWidget(box);
846 TQLabel* label2 = new TQLabel(i18n("E&xpired alarm color:"), box);
847 box->setStretchFactor(new TQWidget(box), 1);
848 mExpiredColour = new KColorCombo(box);
849 label2->setBuddy(mExpiredColour);
850 TQWhatsThis::add(box,
851 i18n("Choose the text color in the alarm list for expired alarms."));
852}
853
854void FontColourPrefTab::restore()
855{
856 mFontChooser->setBgColour(Preferences::mDefaultBgColour);
857 mFontChooser->setColours(Preferences::mMessageColours);
858 mFontChooser->setFont(Preferences::mMessageFont);
859 mDisabledColour->setColor(Preferences::mDisabledColour);
860 mExpiredColour->setColor(Preferences::mExpiredColour);
861}
862
863void FontColourPrefTab::apply(bool syncToDisc)
864{
865 Preferences::mDefaultBgColour = mFontChooser->bgColour();
866 Preferences::mMessageColours = mFontChooser->colours();
867 Preferences::mMessageFont = mFontChooser->font();
868 Preferences::mDisabledColour = mDisabledColour->color();
869 Preferences::mExpiredColour = mExpiredColour->color();
870 PrefsTabBase::apply(syncToDisc);
871}
872
873void FontColourPrefTab::setDefaults()
874{
875 mFontChooser->setBgColour(Preferences::default_defaultBgColour);
876 mFontChooser->setColours(Preferences::default_messageColours);
877 mFontChooser->setFont(Preferences::default_messageFont());
878 mDisabledColour->setColor(Preferences::default_disabledColour);
879 mExpiredColour->setColor(Preferences::default_expiredColour);
880}
881
882
883/*=============================================================================
884= Class EditPrefTab
885=============================================================================*/
886
887EditPrefTab::EditPrefTab(TQVBox* frame)
888 : PrefsTabBase(frame)
889{
890 // Get alignment to use in TQLabel::setAlignment(alignment | TQt::WordBreak)
891 // (AlignAuto doesn't work correctly there)
892 int alignment = TQApplication::reverseLayout() ? TQt::AlignRight : TQt::AlignLeft;
893
894 int groupTopMargin = fontMetrics().lineSpacing()/2;
895 TQString defsetting = i18n("The default setting for \"%1\" in the alarm edit dialog.");
896 TQString soundSetting = i18n("Check to select %1 as the default setting for \"%2\" in the alarm edit dialog.");
897
898 // DISPLAY ALARMS
899 TQGroupBox* group = new TQGroupBox(i18n("Display Alarms"), mPage);
900 TQBoxLayout* layout = new TQVBoxLayout(group, KDialog::marginHint(), KDialog::spacingHint());
901 layout->addSpacing(groupTopMargin);
902
903 mConfirmAck = new TQCheckBox(EditAlarmDlg::i18n_k_ConfirmAck(), group, "defConfAck");
904 mConfirmAck->setMinimumSize(mConfirmAck->sizeHint());
905 TQWhatsThis::add(mConfirmAck, defsetting.arg(EditAlarmDlg::i18n_ConfirmAck()));
906 layout->addWidget(mConfirmAck, 0, TQt::AlignAuto);
907
908 mAutoClose = new TQCheckBox(LateCancelSelector::i18n_i_AutoCloseWinLC(), group, "defAutoClose");
909 mAutoClose->setMinimumSize(mAutoClose->sizeHint());
910 TQWhatsThis::add(mAutoClose, defsetting.arg(LateCancelSelector::i18n_AutoCloseWin()));
911 layout->addWidget(mAutoClose, 0, TQt::AlignAuto);
912
913 TQHBox* box = new TQHBox(group);
914 box->setSpacing(KDialog::spacingHint());
915 layout->addWidget(box);
916 TQLabel* label = new TQLabel(i18n("Reminder &units:"), box);
917 label->setFixedSize(label->sizeHint());
918 mReminderUnits = new TQComboBox(box, "defWarnUnits");
919 mReminderUnits->insertItem(TimePeriod::i18n_Minutes(), TimePeriod::MINUTES);
920 mReminderUnits->insertItem(TimePeriod::i18n_Hours_Mins(), TimePeriod::HOURS_MINUTES);
921 mReminderUnits->insertItem(TimePeriod::i18n_Days(), TimePeriod::DAYS);
922 mReminderUnits->insertItem(TimePeriod::i18n_Weeks(), TimePeriod::WEEKS);
923 mReminderUnits->setFixedSize(mReminderUnits->sizeHint());
924 label->setBuddy(mReminderUnits);
925 TQWhatsThis::add(box,
926 i18n("The default units for the reminder in the alarm edit dialog."));
927 box->setStretchFactor(new TQWidget(box), 1); // left adjust the control
928
929 mSpecialActionsButton = new SpecialActionsButton(EditAlarmDlg::i18n_SpecialActions(), box);
930 mSpecialActionsButton->setFixedSize(mSpecialActionsButton->sizeHint());
931
932 // SOUND
933 TQButtonGroup* bgroup = new TQButtonGroup(SoundPicker::i18n_Sound(), mPage, "soundGroup");
934 layout = new TQVBoxLayout(bgroup, KDialog::marginHint(), KDialog::spacingHint());
935 layout->addSpacing(groupTopMargin);
936
937 TQBoxLayout* hlayout = new TQHBoxLayout(layout, KDialog::spacingHint());
938 mSound = new TQComboBox(false, bgroup, "defSound");
939 mSound->insertItem(SoundPicker::i18n_None()); // index 0
940 mSound->insertItem(SoundPicker::i18n_Beep()); // index 1
941 mSound->insertItem(SoundPicker::i18n_File()); // index 2
942 if (theApp()->speechEnabled())
943 mSound->insertItem(SoundPicker::i18n_Speak()); // index 3
944 mSound->setMinimumSize(mSound->sizeHint());
945 TQWhatsThis::add(mSound, defsetting.arg(SoundPicker::i18n_Sound()));
946 hlayout->addWidget(mSound);
947 hlayout->addStretch(1);
948
949#ifndef WITHOUT_ARTS
950 mSoundRepeat = new TQCheckBox(i18n("Repea&t sound file"), bgroup, "defRepeatSound");
951 mSoundRepeat->setMinimumSize(mSoundRepeat->sizeHint());
952 TQWhatsThis::add(mSoundRepeat, i18n("sound file \"Repeat\" checkbox", "The default setting for sound file \"%1\" in the alarm edit dialog.").arg(SoundDlg::i18n_Repeat()));
953 hlayout->addWidget(mSoundRepeat);
954#endif
955
956 box = new TQHBox(bgroup); // this is to control the TQWhatsThis text display area
957 box->setSpacing(KDialog::spacingHint());
958 mSoundFileLabel = new TQLabel(i18n("Sound &file:"), box);
959 mSoundFileLabel->setFixedSize(mSoundFileLabel->sizeHint());
960 mSoundFile = new TQLineEdit(box);
961 mSoundFileLabel->setBuddy(mSoundFile);
962 mSoundFileBrowse = new TQPushButton(box);
963 mSoundFileBrowse->setPixmap(SmallIcon("document-open"));
964 mSoundFileBrowse->setFixedSize(mSoundFileBrowse->sizeHint());
965 connect(mSoundFileBrowse, TQ_SIGNAL(clicked()), TQ_SLOT(slotBrowseSoundFile()));
966 TQToolTip::add(mSoundFileBrowse, i18n("Choose a sound file"));
967 TQWhatsThis::add(box,
968 i18n("Enter the default sound file to use in the alarm edit dialog."));
969 box->setFixedHeight(box->sizeHint().height());
970 layout->addWidget(box);
971 bgroup->setFixedHeight(bgroup->sizeHint().height());
972
973 // COMMAND ALARMS
974 group = new TQGroupBox(i18n("Command Alarms"), mPage);
975 layout = new TQVBoxLayout(group, KDialog::marginHint(), KDialog::spacingHint());
976 layout->addSpacing(groupTopMargin);
977 layout = new TQHBoxLayout(layout, KDialog::spacingHint());
978
979 mCmdScript = new TQCheckBox(EditAlarmDlg::i18n_p_EnterScript(), group, "defCmdScript");
980 mCmdScript->setMinimumSize(mCmdScript->sizeHint());
981 TQWhatsThis::add(mCmdScript, defsetting.arg(EditAlarmDlg::i18n_EnterScript()));
982 layout->addWidget(mCmdScript);
983 layout->addStretch();
984
985 mCmdXterm = new TQCheckBox(EditAlarmDlg::i18n_w_ExecInTermWindow(), group, "defCmdXterm");
986 mCmdXterm->setMinimumSize(mCmdXterm->sizeHint());
987 TQWhatsThis::add(mCmdXterm, defsetting.arg(EditAlarmDlg::i18n_ExecInTermWindow()));
988 layout->addWidget(mCmdXterm);
989
990 // EMAIL ALARMS
991 group = new TQGroupBox(i18n("Email Alarms"), mPage);
992 layout = new TQVBoxLayout(group, KDialog::marginHint(), KDialog::spacingHint());
993 layout->addSpacing(groupTopMargin);
994
995 // BCC email to sender
996 mEmailBcc = new TQCheckBox(EditAlarmDlg::i18n_e_CopyEmailToSelf(), group, "defEmailBcc");
997 mEmailBcc->setMinimumSize(mEmailBcc->sizeHint());
998 TQWhatsThis::add(mEmailBcc, defsetting.arg(EditAlarmDlg::i18n_CopyEmailToSelf()));
999 layout->addWidget(mEmailBcc, 0, TQt::AlignAuto);
1000
1001 // MISCELLANEOUS
1002 // Show in KOrganizer
1003 mCopyToKOrganizer = new TQCheckBox(EditAlarmDlg::i18n_g_ShowInKOrganizer(), mPage, "defShowKorg");
1004 mCopyToKOrganizer->setMinimumSize(mCopyToKOrganizer->sizeHint());
1005 TQWhatsThis::add(mCopyToKOrganizer, defsetting.arg(EditAlarmDlg::i18n_ShowInKOrganizer()));
1006
1007 // Late cancellation
1008 box = new TQHBox(mPage);
1009 box->setSpacing(KDialog::spacingHint());
1010 mLateCancel = new TQCheckBox(LateCancelSelector::i18n_n_CancelIfLate(), box, "defCancelLate");
1011 mLateCancel->setMinimumSize(mLateCancel->sizeHint());
1012 TQWhatsThis::add(mLateCancel, defsetting.arg(LateCancelSelector::i18n_CancelIfLate()));
1013 box->setStretchFactor(new TQWidget(box), 1); // left adjust the control
1014
1015 // Recurrence
1016 TQHBox* itemBox = new TQHBox(box); // this is to control the TQWhatsThis text display area
1017 itemBox->setSpacing(KDialog::spacingHint());
1018 label = new TQLabel(i18n("&Recurrence:"), itemBox);
1019 label->setFixedSize(label->sizeHint());
1020 mRecurPeriod = new TQComboBox(itemBox, "defRecur");
1021 mRecurPeriod->insertItem(RecurrenceEdit::i18n_NoRecur());
1022 mRecurPeriod->insertItem(RecurrenceEdit::i18n_AtLogin());
1023 mRecurPeriod->insertItem(RecurrenceEdit::i18n_HourlyMinutely());
1024 mRecurPeriod->insertItem(RecurrenceEdit::i18n_Daily());
1025 mRecurPeriod->insertItem(RecurrenceEdit::i18n_Weekly());
1026 mRecurPeriod->insertItem(RecurrenceEdit::i18n_Monthly());
1027 mRecurPeriod->insertItem(RecurrenceEdit::i18n_Yearly());
1028 mRecurPeriod->setFixedSize(mRecurPeriod->sizeHint());
1029 label->setBuddy(mRecurPeriod);
1030 TQWhatsThis::add(itemBox,
1031 i18n("The default setting for the recurrence rule in the alarm edit dialog."));
1032 box->setFixedHeight(itemBox->sizeHint().height());
1033
1034 // How to handle February 29th in yearly recurrences
1035 TQVBox* vbox = new TQVBox(mPage); // this is to control the TQWhatsThis text display area
1036 vbox->setSpacing(KDialog::spacingHint());
1037 label = new TQLabel(i18n("In non-leap years, repeat yearly February 29th alarms on:"), vbox);
1038 label->setAlignment(alignment | TQt::WordBreak);
1039 itemBox = new TQHBox(vbox);
1040 itemBox->setSpacing(2*KDialog::spacingHint());
1041 mFeb29 = new TQButtonGroup(itemBox);
1042 mFeb29->hide();
1043 TQWidget* widget = new TQWidget(itemBox);
1044 widget->setFixedWidth(3*KDialog::spacingHint());
1045 TQRadioButton* radio = new TQRadioButton(i18n("February 2&8th"), itemBox);
1046 radio->setMinimumSize(radio->sizeHint());
1047 mFeb29->insert(radio, KARecurrence::FEB29_FEB28);
1048 radio = new TQRadioButton(i18n("March &1st"), itemBox);
1049 radio->setMinimumSize(radio->sizeHint());
1050 mFeb29->insert(radio, KARecurrence::FEB29_MAR1);
1051 radio = new TQRadioButton(i18n("Do &not repeat"), itemBox);
1052 radio->setMinimumSize(radio->sizeHint());
1053 mFeb29->insert(radio, KARecurrence::FEB29_FEB29);
1054 itemBox->setFixedHeight(itemBox->sizeHint().height());
1055 TQWhatsThis::add(vbox,
1056 i18n("For yearly recurrences, choose what date, if any, alarms due on February 29th should occur in non-leap years.\n"
1057 "Note that the next scheduled occurrence of existing alarms is not re-evaluated when you change this setting."));
1058
1059 mPage->setStretchFactor(new TQWidget(mPage), 1); // top adjust the widgets
1060}
1061
1062void EditPrefTab::restore()
1063{
1064 mAutoClose->setChecked(Preferences::mDefaultAutoClose);
1065 mConfirmAck->setChecked(Preferences::mDefaultConfirmAck);
1066 mReminderUnits->setCurrentItem(Preferences::mDefaultReminderUnits);
1067 mSpecialActionsButton->setActions(Preferences::mDefaultPreAction, Preferences::mDefaultPostAction);
1068 mSound->setCurrentItem(soundIndex(Preferences::mDefaultSoundType));
1069 mSoundFile->setText(Preferences::mDefaultSoundFile);
1070#ifndef WITHOUT_ARTS
1071 mSoundRepeat->setChecked(Preferences::mDefaultSoundRepeat);
1072#endif
1073 mCmdScript->setChecked(Preferences::mDefaultCmdScript);
1074 mCmdXterm->setChecked(Preferences::mDefaultCmdLogType == EditAlarmDlg::EXEC_IN_TERMINAL);
1075 mEmailBcc->setChecked(Preferences::mDefaultEmailBcc);
1076 mCopyToKOrganizer->setChecked(Preferences::mDefaultCopyToKOrganizer);
1077 mLateCancel->setChecked(Preferences::mDefaultLateCancel);
1078 mRecurPeriod->setCurrentItem(recurIndex(Preferences::mDefaultRecurPeriod));
1079 mFeb29->setButton(Preferences::mDefaultFeb29Type);
1080}
1081
1082void EditPrefTab::apply(bool syncToDisc)
1083{
1084 Preferences::mDefaultAutoClose = mAutoClose->isChecked();
1085 Preferences::mDefaultConfirmAck = mConfirmAck->isChecked();
1086 Preferences::mDefaultReminderUnits = static_cast<TimePeriod::Units>(mReminderUnits->currentItem());
1087 Preferences::mDefaultPreAction = mSpecialActionsButton->preAction();
1088 Preferences::mDefaultPostAction = mSpecialActionsButton->postAction();
1089 switch (mSound->currentItem())
1090 {
1091 case 3: Preferences::mDefaultSoundType = SoundPicker::SPEAK; break;
1092 case 2: Preferences::mDefaultSoundType = SoundPicker::PLAY_FILE; break;
1093 case 1: Preferences::mDefaultSoundType = SoundPicker::BEEP; break;
1094 case 0:
1095 default: Preferences::mDefaultSoundType = SoundPicker::NONE; break;
1096 }
1097 Preferences::mDefaultSoundFile = mSoundFile->text();
1098#ifndef WITHOUT_ARTS
1099 Preferences::mDefaultSoundRepeat = mSoundRepeat->isChecked();
1100#endif
1101 Preferences::mDefaultCmdScript = mCmdScript->isChecked();
1102 Preferences::mDefaultCmdLogType = (mCmdXterm->isChecked() ? EditAlarmDlg::EXEC_IN_TERMINAL : EditAlarmDlg::DISCARD_OUTPUT);
1103 Preferences::mDefaultEmailBcc = mEmailBcc->isChecked();
1104 Preferences::mDefaultCopyToKOrganizer = mCopyToKOrganizer->isChecked();
1105 Preferences::mDefaultLateCancel = mLateCancel->isChecked() ? 1 : 0;
1106 switch (mRecurPeriod->currentItem())
1107 {
1108 case 6: Preferences::mDefaultRecurPeriod = RecurrenceEdit::ANNUAL; break;
1109 case 5: Preferences::mDefaultRecurPeriod = RecurrenceEdit::MONTHLY; break;
1110 case 4: Preferences::mDefaultRecurPeriod = RecurrenceEdit::WEEKLY; break;
1111 case 3: Preferences::mDefaultRecurPeriod = RecurrenceEdit::DAILY; break;
1112 case 2: Preferences::mDefaultRecurPeriod = RecurrenceEdit::SUBDAILY; break;
1113 case 1: Preferences::mDefaultRecurPeriod = RecurrenceEdit::AT_LOGIN; break;
1114 case 0:
1115 default: Preferences::mDefaultRecurPeriod = RecurrenceEdit::NO_RECUR; break;
1116 }
1117 int feb29 = mFeb29->selectedId();
1118 Preferences::mDefaultFeb29Type = (feb29 >= 0) ? static_cast<KARecurrence::Feb29Type>(feb29) : Preferences::default_defaultFeb29Type;
1119 PrefsTabBase::apply(syncToDisc);
1120}
1121
1122void EditPrefTab::setDefaults()
1123{
1124 mAutoClose->setChecked(Preferences::default_defaultAutoClose);
1125 mConfirmAck->setChecked(Preferences::default_defaultConfirmAck);
1126 mReminderUnits->setCurrentItem(Preferences::default_defaultReminderUnits);
1127 mSpecialActionsButton->setActions(Preferences::default_defaultPreAction, Preferences::default_defaultPostAction);
1128 mSound->setCurrentItem(soundIndex(Preferences::default_defaultSoundType));
1129 mSoundFile->setText(Preferences::default_defaultSoundFile);
1130#ifndef WITHOUT_ARTS
1131 mSoundRepeat->setChecked(Preferences::default_defaultSoundRepeat);
1132#endif
1133 mCmdScript->setChecked(Preferences::default_defaultCmdScript);
1134 mCmdXterm->setChecked(Preferences::default_defaultCmdLogType == EditAlarmDlg::EXEC_IN_TERMINAL);
1135 mEmailBcc->setChecked(Preferences::default_defaultEmailBcc);
1136 mCopyToKOrganizer->setChecked(Preferences::default_defaultCopyToKOrganizer);
1137 mLateCancel->setChecked(Preferences::default_defaultLateCancel);
1138 mRecurPeriod->setCurrentItem(recurIndex(Preferences::default_defaultRecurPeriod));
1139 mFeb29->setButton(Preferences::default_defaultFeb29Type);
1140}
1141
1142void EditPrefTab::slotBrowseSoundFile()
1143{
1144 TQString defaultDir;
1145 TQString url = SoundPicker::browseFile(defaultDir, mSoundFile->text());
1146 if (!url.isEmpty())
1147 mSoundFile->setText(url);
1148}
1149
1150int EditPrefTab::soundIndex(SoundPicker::Type type)
1151{
1152 switch (type)
1153 {
1154 case SoundPicker::SPEAK: return 3;
1155 case SoundPicker::PLAY_FILE: return 2;
1156 case SoundPicker::BEEP: return 1;
1157 case SoundPicker::NONE:
1158 default: return 0;
1159 }
1160}
1161
1162int EditPrefTab::recurIndex(RecurrenceEdit::RepeatType type)
1163{
1164 switch (type)
1165 {
1166 case RecurrenceEdit::ANNUAL: return 6;
1167 case RecurrenceEdit::MONTHLY: return 5;
1168 case RecurrenceEdit::WEEKLY: return 4;
1169 case RecurrenceEdit::DAILY: return 3;
1170 case RecurrenceEdit::SUBDAILY: return 2;
1171 case RecurrenceEdit::AT_LOGIN: return 1;
1172 case RecurrenceEdit::NO_RECUR:
1173 default: return 0;
1174 }
1175}
1176
1177TQString EditPrefTab::validate()
1178{
1179 if (mSound->currentItem() == SoundPicker::PLAY_FILE && mSoundFile->text().isEmpty())
1180 {
1181 mSoundFile->setFocus();
1182 return i18n("You must enter a sound file when %1 is selected as the default sound type").arg(SoundPicker::i18n_File());;
1183 }
1184 return TQString();
1185}
1186
1187
1188/*=============================================================================
1189= Class ViewPrefTab
1190=============================================================================*/
1191
1192ViewPrefTab::ViewPrefTab(TQVBox* frame)
1193 : PrefsTabBase(frame)
1194{
1195 TQGroupBox* group = new TQGroupBox(i18n("System Tray Tooltip"), mPage);
1196 TQGridLayout* grid = new TQGridLayout(group, 5, 3, KDialog::marginHint(), KDialog::spacingHint());
1197 grid->setColStretch(2, 1);
1198 grid->addColSpacing(0, indentWidth());
1199 grid->addColSpacing(1, indentWidth());
1200 grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
1201
1202 mTooltipShowAlarms = new TQCheckBox(i18n("Show next &24 hours' alarms"), group, "tooltipShow");
1203 mTooltipShowAlarms->setMinimumSize(mTooltipShowAlarms->sizeHint());
1204 connect(mTooltipShowAlarms, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotTooltipAlarmsToggled(bool)));
1205 TQWhatsThis::add(mTooltipShowAlarms,
1206 i18n("Specify whether to include in the system tray tooltip, a summary of alarms due in the next 24 hours"));
1207 grid->addMultiCellWidget(mTooltipShowAlarms, 1, 1, 0, 2, TQt::AlignAuto);
1208
1209 TQHBox* box = new TQHBox(group);
1210 box->setSpacing(KDialog::spacingHint());
1211 mTooltipMaxAlarms = new TQCheckBox(i18n("Ma&ximum number of alarms to show:"), box, "tooltipMax");
1212 mTooltipMaxAlarms->setMinimumSize(mTooltipMaxAlarms->sizeHint());
1213 connect(mTooltipMaxAlarms, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotTooltipMaxToggled(bool)));
1214 mTooltipMaxAlarmCount = new SpinBox(1, 99, 1, box);
1215 mTooltipMaxAlarmCount->setLineShiftStep(5);
1216 mTooltipMaxAlarmCount->setMinimumSize(mTooltipMaxAlarmCount->sizeHint());
1217 TQWhatsThis::add(box,
1218 i18n("Uncheck to display all of the next 24 hours' alarms in the system tray tooltip. "
1219 "Check to enter an upper limit on the number to be displayed."));
1220 grid->addMultiCellWidget(box, 2, 2, 1, 2, TQt::AlignAuto);
1221
1222 mTooltipShowTime = new TQCheckBox(MainWindow::i18n_m_ShowAlarmTime(), group, "tooltipTime");
1223 mTooltipShowTime->setMinimumSize(mTooltipShowTime->sizeHint());
1224 connect(mTooltipShowTime, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotTooltipTimeToggled(bool)));
1225 TQWhatsThis::add(mTooltipShowTime,
1226 i18n("Specify whether to show in the system tray tooltip, the time at which each alarm is due"));
1227 grid->addMultiCellWidget(mTooltipShowTime, 3, 3, 1, 2, TQt::AlignAuto);
1228
1229 mTooltipShowTimeTo = new TQCheckBox(MainWindow::i18n_l_ShowTimeToAlarm(), group, "tooltipTimeTo");
1230 mTooltipShowTimeTo->setMinimumSize(mTooltipShowTimeTo->sizeHint());
1231 connect(mTooltipShowTimeTo, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotTooltipTimeToToggled(bool)));
1232 TQWhatsThis::add(mTooltipShowTimeTo,
1233 i18n("Specify whether to show in the system tray tooltip, how long until each alarm is due"));
1234 grid->addMultiCellWidget(mTooltipShowTimeTo, 4, 4, 1, 2, TQt::AlignAuto);
1235
1236 box = new TQHBox(group); // this is to control the TQWhatsThis text display area
1237 box->setSpacing(KDialog::spacingHint());
1238 mTooltipTimeToPrefixLabel = new TQLabel(i18n("&Prefix:"), box);
1239 mTooltipTimeToPrefixLabel->setFixedSize(mTooltipTimeToPrefixLabel->sizeHint());
1240 mTooltipTimeToPrefix = new TQLineEdit(box);
1241 mTooltipTimeToPrefixLabel->setBuddy(mTooltipTimeToPrefix);
1242 TQWhatsThis::add(box,
1243 i18n("Enter the text to be displayed in front of the time until the alarm, in the system tray tooltip"));
1244 box->setFixedHeight(box->sizeHint().height());
1245 grid->addWidget(box, 5, 2, TQt::AlignAuto);
1246 group->setMaximumHeight(group->sizeHint().height());
1247
1248 mModalMessages = new TQCheckBox(i18n("Message &windows have a title bar and take keyboard focus"), mPage, "modalMsg");
1249 mModalMessages->setMinimumSize(mModalMessages->sizeHint());
1250 TQWhatsThis::add(mModalMessages,
1251 i18n("Specify the characteristics of alarm message windows:\n"
1252 "- If checked, the window is a normal window with a title bar, which grabs keyboard input when it is displayed.\n"
1253 "- If unchecked, the window does not interfere with your typing when "
1254 "it is displayed, but it has no title bar and cannot be moved or resized."));
1255
1256 TQHBox* itemBox = new TQHBox(mPage); // this is to control the TQWhatsThis text display area
1257 box = new TQHBox(itemBox);
1258 box->setSpacing(KDialog::spacingHint());
1259 TQLabel* label = new TQLabel(i18n("System tray icon &update interval:"), box);
1260 mDaemonTrayCheckInterval = new SpinBox(1, 9999, 1, box, "daemonCheck");
1261 mDaemonTrayCheckInterval->setLineShiftStep(10);
1262 mDaemonTrayCheckInterval->setMinimumSize(mDaemonTrayCheckInterval->sizeHint());
1263 label->setBuddy(mDaemonTrayCheckInterval);
1264 label = new TQLabel(i18n("seconds"), box);
1265 TQWhatsThis::add(box,
1266 i18n("How often to update the system tray icon to indicate whether or not the Alarm Daemon is monitoring alarms."));
1267 itemBox->setStretchFactor(new TQWidget(itemBox), 1); // left adjust the controls
1268 itemBox->setFixedHeight(box->sizeHint().height());
1269
1270 mPage->setStretchFactor(new TQWidget(mPage), 1); // top adjust the widgets
1271}
1272
1273void ViewPrefTab::restore()
1274{
1275 setTooltip(Preferences::mTooltipAlarmCount,
1276 Preferences::mShowTooltipAlarmTime,
1277 Preferences::mShowTooltipTimeToAlarm,
1278 Preferences::mTooltipTimeToPrefix);
1279 mModalMessages->setChecked(Preferences::mModalMessages);
1280 mDaemonTrayCheckInterval->setValue(Preferences::mDaemonTrayCheckInterval);
1281}
1282
1283void ViewPrefTab::apply(bool syncToDisc)
1284{
1285 int n = mTooltipShowAlarms->isChecked() ? -1 : 0;
1286 if (n && mTooltipMaxAlarms->isChecked())
1287 n = mTooltipMaxAlarmCount->value();
1288 Preferences::mTooltipAlarmCount = n;
1289 Preferences::mShowTooltipAlarmTime = mTooltipShowTime->isChecked();
1290 Preferences::mShowTooltipTimeToAlarm = mTooltipShowTimeTo->isChecked();
1291 Preferences::mTooltipTimeToPrefix = mTooltipTimeToPrefix->text();
1292 Preferences::mModalMessages = mModalMessages->isChecked();
1293 Preferences::mDaemonTrayCheckInterval = mDaemonTrayCheckInterval->value();
1294 PrefsTabBase::apply(syncToDisc);
1295}
1296
1297void ViewPrefTab::setDefaults()
1298{
1299 setTooltip(Preferences::default_tooltipAlarmCount,
1300 Preferences::default_showTooltipAlarmTime,
1301 Preferences::default_showTooltipTimeToAlarm,
1302 Preferences::default_tooltipTimeToPrefix);
1303 mModalMessages->setChecked(Preferences::default_modalMessages);
1304 mDaemonTrayCheckInterval->setValue(Preferences::default_daemonTrayCheckInterval);
1305}
1306
1307void ViewPrefTab::setTooltip(int maxAlarms, bool time, bool timeTo, const TQString& prefix)
1308{
1309 if (!timeTo)
1310 time = true; // ensure that at least one time option is ticked
1311
1312 // Set the states of the controls without calling signal
1313 // handlers, since these could change the checkboxes' states.
1314 mTooltipShowAlarms->blockSignals(true);
1315 mTooltipShowTime->blockSignals(true);
1316 mTooltipShowTimeTo->blockSignals(true);
1317
1318 mTooltipShowAlarms->setChecked(maxAlarms);
1319 mTooltipMaxAlarms->setChecked(maxAlarms > 0);
1320 mTooltipMaxAlarmCount->setValue(maxAlarms > 0 ? maxAlarms : 1);
1321 mTooltipShowTime->setChecked(time);
1322 mTooltipShowTimeTo->setChecked(timeTo);
1323 mTooltipTimeToPrefix->setText(prefix);
1324
1325 mTooltipShowAlarms->blockSignals(false);
1326 mTooltipShowTime->blockSignals(false);
1327 mTooltipShowTimeTo->blockSignals(false);
1328
1329 // Enable/disable controls according to their states
1330 slotTooltipTimeToToggled(timeTo);
1331 slotTooltipAlarmsToggled(maxAlarms);
1332}
1333
1334void ViewPrefTab::slotTooltipAlarmsToggled(bool on)
1335{
1336 mTooltipMaxAlarms->setEnabled(on);
1337 mTooltipMaxAlarmCount->setEnabled(on && mTooltipMaxAlarms->isChecked());
1338 mTooltipShowTime->setEnabled(on);
1339 mTooltipShowTimeTo->setEnabled(on);
1340 on = on && mTooltipShowTimeTo->isChecked();
1341 mTooltipTimeToPrefix->setEnabled(on);
1342 mTooltipTimeToPrefixLabel->setEnabled(on);
1343}
1344
1345void ViewPrefTab::slotTooltipMaxToggled(bool on)
1346{
1347 mTooltipMaxAlarmCount->setEnabled(on && mTooltipMaxAlarms->isEnabled());
1348}
1349
1350void ViewPrefTab::slotTooltipTimeToggled(bool on)
1351{
1352 if (!on && !mTooltipShowTimeTo->isChecked())
1353 mTooltipShowTimeTo->setChecked(true);
1354}
1355
1356void ViewPrefTab::slotTooltipTimeToToggled(bool on)
1357{
1358 if (!on && !mTooltipShowTime->isChecked())
1359 mTooltipShowTime->setChecked(true);
1360 on = on && mTooltipShowTimeTo->isEnabled();
1361 mTooltipTimeToPrefix->setEnabled(on);
1362 mTooltipTimeToPrefixLabel->setEnabled(on);
1363}
Provides read and write access to calendar files.
Definition: alarmcalendar.h:37
miscellaneous functions
the KAlarm application object
main application window