kalarm

prefdlg.cpp

00001 /*
00002  *  prefdlg.cpp  -  program preferences dialog
00003  *  Program:  kalarm
00004  *  Copyright (c) 2001-2006 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 
00023 #include <qobjectlist.h>
00024 #include <qlayout.h>
00025 #include <qbuttongroup.h>
00026 #include <qvbox.h>
00027 #include <qlineedit.h>
00028 #include <qcheckbox.h>
00029 #include <qradiobutton.h>
00030 #include <qpushbutton.h>
00031 #include <qcombobox.h>
00032 #include <qwhatsthis.h>
00033 #include <qtooltip.h>
00034 #include <qstyle.h>
00035 
00036 #include <kglobal.h>
00037 #include <klocale.h>
00038 #include <kstandarddirs.h>
00039 #include <kmessagebox.h>
00040 #include <kaboutdata.h>
00041 #include <kapplication.h>
00042 #include <kiconloader.h>
00043 #include <kcolorcombo.h>
00044 #include <kstdguiitem.h>
00045 #include <kdebug.h>
00046 
00047 #include <kalarmd/kalarmd.h>
00048 
00049 #include "alarmcalendar.h"
00050 #include "alarmtimewidget.h"
00051 #include "editdlg.h"
00052 #include "fontcolour.h"
00053 #include "functions.h"
00054 #include "kalarmapp.h"
00055 #include "kamail.h"
00056 #include "label.h"
00057 #include "latecancel.h"
00058 #include "mainwindow.h"
00059 #include "preferences.h"
00060 #include "radiobutton.h"
00061 #include "recurrenceedit.h"
00062 #ifndef WITHOUT_ARTS
00063 #include "sounddlg.h"
00064 #endif
00065 #include "soundpicker.h"
00066 #include "specialactions.h"
00067 #include "timeedit.h"
00068 #include "timespinbox.h"
00069 #include "traywindow.h"
00070 #include "prefdlg.moc"
00071 
00072 // Command strings for executing commands in different types of terminal windows.
00073 // %t = window title parameter
00074 // %c = command to execute in terminal
00075 // %w = command to execute in terminal, with 'sleep 86400' appended
00076 // %C = temporary command file to execute in terminal
00077 // %W = temporary command file to execute in terminal, with 'sleep 86400' appended
00078 static QString xtermCommands[] = {
00079     QString::fromLatin1("xterm -sb -hold -title %t -e %c"),
00080     QString::fromLatin1("konsole --noclose -T %t -e ${SHELL:-sh} -c %c"),
00081     QString::fromLatin1("gnome-terminal -t %t -e %W"),
00082     QString::fromLatin1("eterm --pause -T %t -e %C"),    // some systems use eterm...
00083     QString::fromLatin1("Eterm --pause -T %t -e %C"),    // while some use Eterm
00084     QString::fromLatin1("rxvt -title %t -e ${SHELL:-sh} -c %w"),
00085     QString::null       // end of list indicator - don't change!
00086 };
00087 
00088 
00089 /*=============================================================================
00090 = Class KAlarmPrefDlg
00091 =============================================================================*/
00092 
00093 KAlarmPrefDlg::KAlarmPrefDlg()
00094     : KDialogBase(IconList, i18n("Preferences"), Help | Default | Ok | Apply | Cancel, Ok, 0, 0, true, true)
00095 {
00096     setIconListAllVisible(true);
00097 
00098     QVBox* frame = addVBoxPage(i18n("General"), i18n("General"), DesktopIcon("misc"));
00099     mMiscPage = new MiscPrefTab(frame);
00100 
00101     frame = addVBoxPage(i18n("Email"), i18n("Email Alarm Settings"), DesktopIcon("mail_generic"));
00102     mEmailPage = new EmailPrefTab(frame);
00103 
00104     frame = addVBoxPage(i18n("View"), i18n("View Settings"), DesktopIcon("view_choose"));
00105     mViewPage = new ViewPrefTab(frame);
00106 
00107     frame = addVBoxPage(i18n("Font & Color"), i18n("Default Font and Color"), DesktopIcon("colorize"));
00108     mFontColourPage = new FontColourPrefTab(frame);
00109 
00110     frame = addVBoxPage(i18n("Edit"), i18n("Default Alarm Edit Settings"), DesktopIcon("edit"));
00111     mEditPage = new EditPrefTab(frame);
00112 
00113     restore();
00114     adjustSize();
00115 }
00116 
00117 KAlarmPrefDlg::~KAlarmPrefDlg()
00118 {
00119 }
00120 
00121 // Restore all defaults in the options...
00122 void KAlarmPrefDlg::slotDefault()
00123 {
00124     kdDebug(5950) << "KAlarmPrefDlg::slotDefault()" << endl;
00125     mFontColourPage->setDefaults();
00126     mEmailPage->setDefaults();
00127     mViewPage->setDefaults();
00128     mEditPage->setDefaults();
00129     mMiscPage->setDefaults();
00130 }
00131 
00132 void KAlarmPrefDlg::slotHelp()
00133 {
00134     kapp->invokeHelp("preferences");
00135 }
00136 
00137 // Apply the preferences that are currently selected
00138 void KAlarmPrefDlg::slotApply()
00139 {
00140     kdDebug(5950) << "KAlarmPrefDlg::slotApply()" << endl;
00141     QString errmsg = mEmailPage->validate();
00142     if (!errmsg.isEmpty())
00143     {
00144         showPage(pageIndex(mEmailPage->parentWidget()));
00145         if (KMessageBox::warningYesNo(this, errmsg) != KMessageBox::Yes)
00146         {
00147             mValid = false;
00148             return;
00149         }
00150     }
00151     errmsg = mEditPage->validate();
00152     if (!errmsg.isEmpty())
00153     {
00154         showPage(pageIndex(mEditPage->parentWidget()));
00155         KMessageBox::sorry(this, errmsg);
00156         mValid = false;
00157         return;
00158     }
00159     mValid = true;
00160     mFontColourPage->apply(false);
00161     mEmailPage->apply(false);
00162     mViewPage->apply(false);
00163     mEditPage->apply(false);
00164     mMiscPage->apply(false);
00165     Preferences::syncToDisc();
00166 }
00167 
00168 // Apply the preferences that are currently selected
00169 void KAlarmPrefDlg::slotOk()
00170 {
00171     kdDebug(5950) << "KAlarmPrefDlg::slotOk()" << endl;
00172     mValid = true;
00173     slotApply();
00174     if (mValid)
00175         KDialogBase::slotOk();
00176 }
00177 
00178 // Discard the current preferences and close the dialogue
00179 void KAlarmPrefDlg::slotCancel()
00180 {
00181     kdDebug(5950) << "KAlarmPrefDlg::slotCancel()" << endl;
00182     restore();
00183     KDialogBase::slotCancel();
00184 }
00185 
00186 // Discard the current preferences and use the present ones
00187 void KAlarmPrefDlg::restore()
00188 {
00189     kdDebug(5950) << "KAlarmPrefDlg::restore()" << endl;
00190     mFontColourPage->restore();
00191     mEmailPage->restore();
00192     mViewPage->restore();
00193     mEditPage->restore();
00194     mMiscPage->restore();
00195 }
00196 
00197 
00198 /*=============================================================================
00199 = Class PrefsTabBase
00200 =============================================================================*/
00201 int PrefsTabBase::mIndentWidth = 0;
00202 
00203 PrefsTabBase::PrefsTabBase(QVBox* frame)
00204     : QWidget(frame),
00205       mPage(frame)
00206 {
00207     if (!mIndentWidth)
00208         mIndentWidth = 3 * KDialog::spacingHint();
00209 }
00210 
00211 void PrefsTabBase::apply(bool syncToDisc)
00212 {
00213     Preferences::save(syncToDisc);
00214 }
00215 
00216 
00217 
00218 /*=============================================================================
00219 = Class MiscPrefTab
00220 =============================================================================*/
00221 
00222 MiscPrefTab::MiscPrefTab(QVBox* frame)
00223     : PrefsTabBase(frame)
00224 {
00225     // Get alignment to use in QGridLayout (AlignAuto doesn't work correctly there)
00226     int alignment = QApplication::reverseLayout() ? Qt::AlignRight : Qt::AlignLeft;
00227 
00228     // Autostart alarm daemon
00229     QHBox* itemBox = new QHBox(mPage);   // this is to allow left adjustment
00230     mAutostartDaemon = new QCheckBox(i18n("Start alarm monitoring at lo&gin"), itemBox, "startDaemon");
00231     mAutostartDaemon->setFixedSize(mAutostartDaemon->sizeHint());
00232     connect(mAutostartDaemon, SIGNAL(clicked()), SLOT(slotAutostartDaemonClicked()));
00233     QWhatsThis::add(mAutostartDaemon,
00234           i18n("Automatically start alarm monitoring whenever you start KDE, by running the alarm daemon (%1).\n\n"
00235                "This option should always be checked unless you intend to discontinue use of KAlarm.")
00236               .arg(QString::fromLatin1(DAEMON_APP_NAME)));
00237     itemBox->setStretchFactor(new QWidget(itemBox), 1);    // left adjust the controls
00238 
00239     QGroupBox* group = new QButtonGroup(i18n("Run Mode"), mPage, "modeGroup");
00240     QGridLayout* grid = new QGridLayout(group, 6, 3, KDialog::marginHint(), KDialog::spacingHint());
00241     grid->setColStretch(2, 1);
00242     grid->addColSpacing(0, indentWidth());
00243     grid->addColSpacing(1, indentWidth());
00244     grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
00245     int row = 1;
00246 
00247     // Run-in-system-tray radio button has an ID of 0
00248     mRunInSystemTray = new QRadioButton(i18n("Run continuously in system &tray"), group, "runTray");
00249     mRunInSystemTray->setFixedSize(mRunInSystemTray->sizeHint());
00250     connect(mRunInSystemTray, SIGNAL(toggled(bool)), SLOT(slotRunModeToggled(bool)));
00251     QWhatsThis::add(mRunInSystemTray,
00252           i18n("Check to run KAlarm continuously in the KDE system tray.\n\n"
00253                "Notes:\n"
00254                "1. With this option selected, closing the system tray icon will quit KAlarm.\n"
00255                "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."
00256                " Running in the system tray simply provides easy access and a status indication."));
00257     grid->addMultiCellWidget(mRunInSystemTray, row, row, 0, 2, alignment);
00258     ++row;
00259 
00260     mAutostartTrayIcon1 = new QCheckBox(i18n("Autostart at &login"), group, "autoTray");
00261     mAutostartTrayIcon1->setFixedSize(mAutostartTrayIcon1->sizeHint());
00262 #ifdef AUTOSTART_BY_KALARMD
00263     connect(mAutostartTrayIcon1, SIGNAL(toggled(bool)), SLOT(slotAutostartToggled(bool)));
00264 #endif
00265     QWhatsThis::add(mAutostartTrayIcon1,
00266           i18n("Check to run KAlarm whenever you start KDE."));
00267     grid->addMultiCellWidget(mAutostartTrayIcon1, row, row, 1, 2, alignment);
00268     ++row;
00269 
00270     mDisableAlarmsIfStopped = new QCheckBox(i18n("Disa&ble alarms while not running"), group, "disableAl");
00271     mDisableAlarmsIfStopped->setFixedSize(mDisableAlarmsIfStopped->sizeHint());
00272     connect(mDisableAlarmsIfStopped, SIGNAL(toggled(bool)), SLOT(slotDisableIfStoppedToggled(bool)));
00273     QWhatsThis::add(mDisableAlarmsIfStopped,
00274           i18n("Check to disable alarms whenever KAlarm is not running. Alarms will only appear while the system tray icon is visible."));
00275     grid->addMultiCellWidget(mDisableAlarmsIfStopped, row, row, 1, 2, alignment);
00276     ++row;
00277 
00278     mQuitWarn = new QCheckBox(i18n("Warn before &quitting"), group, "disableAl");
00279     mQuitWarn->setFixedSize(mQuitWarn->sizeHint());
00280     QWhatsThis::add(mQuitWarn,
00281           i18n("Check to display a warning prompt before quitting KAlarm."));
00282     grid->addWidget(mQuitWarn, row, 2, alignment);
00283     ++row;
00284 
00285     // Run-on-demand radio button has an ID of 3
00286     mRunOnDemand = new QRadioButton(i18n("&Run only on demand"), group, "runDemand");
00287     mRunOnDemand->setFixedSize(mRunOnDemand->sizeHint());
00288     connect(mRunOnDemand, SIGNAL(toggled(bool)), SLOT(slotRunModeToggled(bool)));
00289     QWhatsThis::add(mRunOnDemand,
00290           i18n("Check to run KAlarm only when required.\n\n"
00291                "Notes:\n"
00292                "1. Alarms are displayed even when KAlarm is not running, since alarm monitoring is done by the alarm daemon.\n"
00293                "2. With this option selected, the system tray icon can be displayed or hidden independently of KAlarm."));
00294     grid->addMultiCellWidget(mRunOnDemand, row, row, 0, 2, alignment);
00295     ++row;
00296 
00297     mAutostartTrayIcon2 = new QCheckBox(i18n("Autostart system tray &icon at login"), group, "autoRun");
00298     mAutostartTrayIcon2->setFixedSize(mAutostartTrayIcon2->sizeHint());
00299 #ifdef AUTOSTART_BY_KALARMD
00300     connect(mAutostartTrayIcon2, SIGNAL(toggled(bool)), SLOT(slotAutostartToggled(bool)));
00301 #endif
00302     QWhatsThis::add(mAutostartTrayIcon2,
00303           i18n("Check to display the system tray icon whenever you start KDE."));
00304     grid->addMultiCellWidget(mAutostartTrayIcon2, row, row, 1, 2, alignment);
00305     group->setFixedHeight(group->sizeHint().height());
00306 
00307     // Start-of-day time
00308     itemBox = new QHBox(mPage);
00309     QHBox* box = new QHBox(itemBox);   // this is to control the QWhatsThis text display area
00310     box->setSpacing(KDialog::spacingHint());
00311     QLabel* label = new QLabel(i18n("&Start of day for date-only alarms:"), box);
00312     mStartOfDay = new TimeEdit(box);
00313     mStartOfDay->setFixedSize(mStartOfDay->sizeHint());
00314     label->setBuddy(mStartOfDay);
00315     static const QString startOfDayText = i18n("The earliest time of day at which a date-only alarm (i.e. "
00316                                                "an alarm with \"any time\" specified) will be triggered.");
00317     QWhatsThis::add(box, QString("%1\n\n%2").arg(startOfDayText).arg(TimeSpinBox::shiftWhatsThis()));
00318     itemBox->setStretchFactor(new QWidget(itemBox), 1);    // left adjust the controls
00319     itemBox->setFixedHeight(box->sizeHint().height());
00320 
00321     // Confirm alarm deletion?
00322     itemBox = new QHBox(mPage);   // this is to allow left adjustment
00323     mConfirmAlarmDeletion = new QCheckBox(i18n("Con&firm alarm deletions"), itemBox, "confirmDeletion");
00324     mConfirmAlarmDeletion->setMinimumSize(mConfirmAlarmDeletion->sizeHint());
00325     QWhatsThis::add(mConfirmAlarmDeletion,
00326           i18n("Check to be prompted for confirmation each time you delete an alarm."));
00327     itemBox->setStretchFactor(new QWidget(itemBox), 1);    // left adjust the controls
00328     itemBox->setFixedHeight(box->sizeHint().height());
00329 
00330     // Expired alarms
00331     group = new QGroupBox(i18n("Expired Alarms"), mPage);
00332     grid = new QGridLayout(group, 2, 2, KDialog::marginHint(), KDialog::spacingHint());
00333     grid->setColStretch(1, 1);
00334     grid->addColSpacing(0, indentWidth());
00335     grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
00336     mKeepExpired = new QCheckBox(i18n("Keep alarms after e&xpiry"), group, "keepExpired");
00337     mKeepExpired->setFixedSize(mKeepExpired->sizeHint());
00338     connect(mKeepExpired, SIGNAL(toggled(bool)), SLOT(slotExpiredToggled(bool)));
00339     QWhatsThis::add(mKeepExpired,
00340           i18n("Check to store alarms after expiry or deletion (except deleted alarms which were never triggered)."));
00341     grid->addMultiCellWidget(mKeepExpired, 1, 1, 0, 1, alignment);
00342 
00343     box = new QHBox(group);
00344     box->setSpacing(KDialog::spacingHint());
00345     mPurgeExpired = new QCheckBox(i18n("Discard ex&pired alarms after:"), box, "purgeExpired");
00346     mPurgeExpired->setMinimumSize(mPurgeExpired->sizeHint());
00347     connect(mPurgeExpired, SIGNAL(toggled(bool)), SLOT(slotExpiredToggled(bool)));
00348     mPurgeAfter = new SpinBox(box);
00349     mPurgeAfter->setMinValue(1);
00350     mPurgeAfter->setLineShiftStep(10);
00351     mPurgeAfter->setMinimumSize(mPurgeAfter->sizeHint());
00352     mPurgeAfterLabel = new QLabel(i18n("da&ys"), box);
00353     mPurgeAfterLabel->setMinimumSize(mPurgeAfterLabel->sizeHint());
00354     mPurgeAfterLabel->setBuddy(mPurgeAfter);
00355     QWhatsThis::add(box,
00356           i18n("Uncheck to store expired alarms indefinitely. Check to enter how long expired alarms should be stored."));
00357     grid->addWidget(box, 2, 1, alignment);
00358 
00359     mClearExpired = new QPushButton(i18n("Clear Expired Alar&ms"), group);
00360     mClearExpired->setFixedSize(mClearExpired->sizeHint());
00361     connect(mClearExpired, SIGNAL(clicked()), SLOT(slotClearExpired()));
00362     QWhatsThis::add(mClearExpired,
00363           i18n("Delete all existing expired alarms."));
00364     grid->addWidget(mClearExpired, 3, 1, alignment);
00365     group->setFixedHeight(group->sizeHint().height());
00366 
00367     // Terminal window to use for command alarms
00368     group = new QGroupBox(i18n("Terminal for Command Alarms"), mPage);
00369     QWhatsThis::add(group,
00370           i18n("Choose which application to use when a command alarm is executed in a terminal window"));
00371     grid = new QGridLayout(group, 1, 3, KDialog::marginHint(), KDialog::spacingHint());
00372     grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
00373     row = 0;
00374 
00375     mXtermType = new QButtonGroup(group);
00376     mXtermType->hide();
00377     QString whatsThis = i18n("The parameter is a command line, e.g. 'xterm -e'", "Check to execute command alarms in a terminal window by '%1'");
00378     int index = 0;
00379     for (mXtermCount = 0;  !xtermCommands[mXtermCount].isNull();  ++mXtermCount)
00380     {
00381         QString cmd = xtermCommands[mXtermCount];
00382         int i = cmd.find(' ');    // find the end of the terminal window name
00383         QString term = cmd.left(i > 0 ? i : 1000);
00384         if (KStandardDirs::findExe(term).isEmpty())
00385             continue;
00386         QRadioButton* radio = new QRadioButton(term, group);
00387         radio->setMinimumSize(radio->sizeHint());
00388         mXtermType->insert(radio, mXtermCount);
00389         cmd.replace("%t", kapp->aboutData()->programName());
00390         cmd.replace("%c", "<command>");
00391         cmd.replace("%w", "<command; sleep>");
00392         cmd.replace("%C", "[command]");
00393         cmd.replace("%W", "[command; sleep]");
00394         QWhatsThis::add(radio, whatsThis.arg(cmd));
00395         grid->addWidget(radio, (row = index/3 + 1), index % 3, Qt::AlignAuto);
00396         ++index;
00397     }
00398 
00399     box = new QHBox(group);
00400     grid->addMultiCellWidget(box, row + 1, row + 1, 0, 2, Qt::AlignAuto);
00401     QRadioButton* radio = new QRadioButton(i18n("Other:"), box);
00402     radio->setFixedSize(radio->sizeHint());
00403     connect(radio, SIGNAL(toggled(bool)), SLOT(slotOtherTerminalToggled(bool)));
00404     mXtermType->insert(radio, mXtermCount);
00405     mXtermCommand = new QLineEdit(box);
00406     QWhatsThis::add(box,
00407           i18n("Enter the full command line needed to execute a command in your chosen terminal window. "
00408                "By default the alarm's command string will be appended to what you enter here. "
00409                "See the KAlarm Handbook for details of special codes to tailor the command line."));
00410 
00411     mPage->setStretchFactor(new QWidget(mPage), 1);    // top adjust the widgets
00412 }
00413 
00414 void MiscPrefTab::restore()
00415 {
00416     mAutostartDaemon->setChecked(Preferences::mAutostartDaemon);
00417     bool systray = Preferences::mRunInSystemTray;
00418     mRunInSystemTray->setChecked(systray);
00419     mRunOnDemand->setChecked(!systray);
00420     mDisableAlarmsIfStopped->setChecked(Preferences::mDisableAlarmsIfStopped);
00421     mQuitWarn->setChecked(Preferences::quitWarn());
00422     mAutostartTrayIcon1->setChecked(Preferences::mAutostartTrayIcon);
00423     mAutostartTrayIcon2->setChecked(Preferences::mAutostartTrayIcon);
00424     mConfirmAlarmDeletion->setChecked(Preferences::confirmAlarmDeletion());
00425     mStartOfDay->setValue(Preferences::mStartOfDay);
00426     setExpiredControls(Preferences::mExpiredKeepDays);
00427     QString xtermCmd = Preferences::cmdXTermCommand();
00428     int id = 0;
00429     if (!xtermCmd.isEmpty())
00430     {
00431         for ( ;  id < mXtermCount;  ++id)
00432         {
00433             if (mXtermType->find(id)  &&  xtermCmd == xtermCommands[id])
00434                 break;
00435         }
00436     }
00437     mXtermType->setButton(id);
00438     mXtermCommand->setEnabled(id == mXtermCount);
00439     mXtermCommand->setText(id == mXtermCount ? xtermCmd : "");
00440     slotDisableIfStoppedToggled(true);
00441 }
00442 
00443 void MiscPrefTab::apply(bool syncToDisc)
00444 {
00445     // First validate anything entered in Other X-terminal command
00446     int xtermID = mXtermType->selectedId();
00447     if (xtermID >= mXtermCount)
00448     {
00449         QString cmd = mXtermCommand->text();
00450         if (cmd.isEmpty())
00451             xtermID = 0;       // 'Other' is only acceptable if it's non-blank
00452         else
00453         {
00454             int i = cmd.find(' ');    // find the end of the terminal window name
00455             if (i > 0)
00456                 cmd = cmd.left(i);
00457             if (KStandardDirs::findExe(cmd).isEmpty())
00458             {
00459                 mXtermCommand->setFocus();
00460                 if (KMessageBox::warningContinueCancel(this, i18n("Command to invoke terminal window not found:\n%1").arg(cmd))
00461                                 != KMessageBox::Continue)
00462                     return;
00463             }
00464         }
00465     }
00466     bool systray = mRunInSystemTray->isChecked();
00467     Preferences::mRunInSystemTray        = systray;
00468     Preferences::mDisableAlarmsIfStopped = mDisableAlarmsIfStopped->isChecked();
00469     if (mQuitWarn->isEnabled())
00470         Preferences::setQuitWarn(mQuitWarn->isChecked());
00471     Preferences::mAutostartTrayIcon = systray ? mAutostartTrayIcon1->isChecked() : mAutostartTrayIcon2->isChecked();
00472 #ifdef AUTOSTART_BY_KALARMD
00473     Preferences::mAutostartDaemon = mAutostartDaemon->isChecked() || Preferences::mAutostartTrayIcon;
00474 #else
00475     Preferences::mAutostartDaemon = mAutostartDaemon->isChecked();
00476 #endif
00477     Preferences::setConfirmAlarmDeletion(mConfirmAlarmDeletion->isChecked());
00478     int sod = mStartOfDay->value();
00479     Preferences::mStartOfDay.setHMS(sod/60, sod%60, 0);
00480     Preferences::mExpiredKeepDays = !mKeepExpired->isChecked() ? 0
00481                                   : mPurgeExpired->isChecked() ? mPurgeAfter->value() : -1;
00482     Preferences::mCmdXTermCommand = (xtermID < mXtermCount) ? xtermCommands[xtermID] : mXtermCommand->text();
00483     PrefsTabBase::apply(syncToDisc);
00484 }
00485 
00486 void MiscPrefTab::setDefaults()
00487 {
00488     mAutostartDaemon->setChecked(Preferences::default_autostartDaemon);
00489     bool systray = Preferences::default_runInSystemTray;
00490     mRunInSystemTray->setChecked(systray);
00491     mRunOnDemand->setChecked(!systray);
00492     mDisableAlarmsIfStopped->setChecked(Preferences::default_disableAlarmsIfStopped);
00493     mQuitWarn->setChecked(Preferences::default_quitWarn);
00494     mAutostartTrayIcon1->setChecked(Preferences::default_autostartTrayIcon);
00495     mAutostartTrayIcon2->setChecked(Preferences::default_autostartTrayIcon);
00496     mConfirmAlarmDeletion->setChecked(Preferences::default_confirmAlarmDeletion);
00497     mStartOfDay->setValue(Preferences::default_startOfDay);
00498     setExpiredControls(Preferences::default_expiredKeepDays);
00499     mXtermType->setButton(0);
00500     mXtermCommand->setEnabled(false);
00501     slotDisableIfStoppedToggled(true);
00502 }
00503 
00504 void MiscPrefTab::slotAutostartDaemonClicked()
00505 {
00506     if (!mAutostartDaemon->isChecked()
00507     &&  KMessageBox::warningYesNo(this,
00508                               i18n("You should not uncheck this option unless you intend to discontinue use of KAlarm"),
00509                               QString::null, KStdGuiItem::cont(), KStdGuiItem::cancel()
00510                              ) != KMessageBox::Yes)
00511         mAutostartDaemon->setChecked(true); 
00512 }
00513 
00514 void MiscPrefTab::slotRunModeToggled(bool)
00515 {
00516     bool systray = (mRunInSystemTray->isOn());
00517     mAutostartTrayIcon2->setEnabled(!systray);
00518     mAutostartTrayIcon1->setEnabled(systray);
00519     mDisableAlarmsIfStopped->setEnabled(systray);
00520     slotDisableIfStoppedToggled(true);
00521 }
00522 
00523 /******************************************************************************
00524 * If autostart at login is selected, the daemon must be autostarted so that it
00525 * can autostart KAlarm, in which case disable the daemon autostart option.
00526 */
00527 void MiscPrefTab::slotAutostartToggled(bool)
00528 {
00529 #ifdef AUTOSTART_BY_KALARMD
00530     bool autostart = mRunInSystemTray->isChecked() ? mAutostartTrayIcon1->isChecked() : mAutostartTrayIcon2->isChecked();
00531     mAutostartDaemon->setEnabled(!autostart);
00532 #endif
00533 }
00534 
00535 void MiscPrefTab::slotDisableIfStoppedToggled(bool)
00536 {
00537     bool enable = mDisableAlarmsIfStopped->isEnabled()  &&  mDisableAlarmsIfStopped->isChecked();
00538     mQuitWarn->setEnabled(enable);
00539 }
00540 
00541 void MiscPrefTab::setExpiredControls(int purgeDays)
00542 {
00543     mKeepExpired->setChecked(purgeDays);
00544     mPurgeExpired->setChecked(purgeDays > 0);
00545     mPurgeAfter->setValue(purgeDays > 0 ? purgeDays : 0);
00546     slotExpiredToggled(true);
00547 }
00548 
00549 void MiscPrefTab::slotExpiredToggled(bool)
00550 {
00551     bool keep = mKeepExpired->isChecked();
00552     bool after = keep && mPurgeExpired->isChecked();
00553     mPurgeExpired->setEnabled(keep);
00554     mPurgeAfter->setEnabled(after);
00555     mPurgeAfterLabel->setEnabled(keep);
00556     mClearExpired->setEnabled(keep);
00557 }
00558 
00559 void MiscPrefTab::slotClearExpired()
00560 {
00561     AlarmCalendar* cal = AlarmCalendar::expiredCalendarOpen();
00562     if (cal)
00563         cal->purgeAll();
00564 }
00565 
00566 void MiscPrefTab::slotOtherTerminalToggled(bool on)
00567 {
00568     mXtermCommand->setEnabled(on);
00569 }
00570 
00571 
00572 /*=============================================================================
00573 = Class EmailPrefTab
00574 =============================================================================*/
00575 
00576 EmailPrefTab::EmailPrefTab(QVBox* frame)
00577     : PrefsTabBase(frame),
00578       mAddressChanged(false),
00579       mBccAddressChanged(false)
00580 {
00581     QHBox* box = new QHBox(mPage);
00582     box->setSpacing(2*KDialog::spacingHint());
00583     QLabel* label = new QLabel(i18n("Email client:"), box);
00584     mEmailClient = new ButtonGroup(box);
00585     mEmailClient->hide();
00586     RadioButton* radio = new RadioButton(i18n("&KMail"), box, "kmail");
00587     radio->setMinimumSize(radio->sizeHint());
00588     mEmailClient->insert(radio, Preferences::KMAIL);
00589     radio = new RadioButton(i18n("&Sendmail"), box, "sendmail");
00590     radio->setMinimumSize(radio->sizeHint());
00591     mEmailClient->insert(radio, Preferences::SENDMAIL);
00592     connect(mEmailClient, SIGNAL(buttonSet(int)), SLOT(slotEmailClientChanged(int)));
00593     box->setFixedHeight(box->sizeHint().height());
00594     QWhatsThis::add(box,
00595           i18n("Choose how to send email when an email alarm is triggered.\n"
00596                "KMail: The email is added to KMail's outbox if KMail is running. If not, "
00597                "a KMail composer window is displayed to enable you to send the email.\n"
00598                "Sendmail: The email is sent automatically. This option will only work if "
00599                "your system is configured to use 'sendmail' or a sendmail compatible mail transport agent."));
00600 
00601     box = new QHBox(mPage);   // this is to allow left adjustment
00602     mEmailCopyToKMail = new QCheckBox(i18n("Co&py sent emails into KMail's %1 folder").arg(KAMail::i18n_sent_mail()), box);
00603     mEmailCopyToKMail->setFixedSize(mEmailCopyToKMail->sizeHint());
00604     QWhatsThis::add(mEmailCopyToKMail,
00605           i18n("After sending an email, store a copy in KMail's %1 folder").arg(KAMail::i18n_sent_mail()));
00606     box->setStretchFactor(new QWidget(box), 1);    // left adjust the controls
00607     box->setFixedHeight(box->sizeHint().height());
00608 
00609     // Your Email Address group box
00610     QGroupBox* group = new QGroupBox(i18n("Your Email Address"), mPage);
00611     QGridLayout* grid = new QGridLayout(group, 6, 3, KDialog::marginHint(), KDialog::spacingHint());
00612     grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
00613     grid->setColStretch(1, 1);
00614 
00615     // 'From' email address controls ...
00616     label = new Label(EditAlarmDlg::i18n_f_EmailFrom(), group);
00617     label->setFixedSize(label->sizeHint());
00618     grid->addWidget(label, 1, 0);
00619     mFromAddressGroup = new ButtonGroup(group);
00620     mFromAddressGroup->hide();
00621     connect(mFromAddressGroup, SIGNAL(buttonSet(int)), SLOT(slotFromAddrChanged(int)));
00622 
00623     // Line edit to enter a 'From' email address
00624     radio = new RadioButton(group);
00625     mFromAddressGroup->insert(radio, Preferences::MAIL_FROM_ADDR);
00626     radio->setFixedSize(radio->sizeHint());
00627     label->setBuddy(radio);
00628     grid->addWidget(radio, 1, 1);
00629     mEmailAddress = new QLineEdit(group);
00630     connect(mEmailAddress, SIGNAL(textChanged(const QString&)), SLOT(slotAddressChanged()));
00631     QString whatsThis = i18n("Your email address, used to identify you as the sender when sending email alarms.");
00632     QWhatsThis::add(radio, whatsThis);
00633     QWhatsThis::add(mEmailAddress, whatsThis);
00634     radio->setFocusWidget(mEmailAddress);
00635     grid->addWidget(mEmailAddress, 1, 2);
00636 
00637     // 'From' email address to be taken from Control Centre
00638     radio = new RadioButton(i18n("&Use address from Control Center"), group);
00639     radio->setFixedSize(radio->sizeHint());
00640     mFromAddressGroup->insert(radio, Preferences::MAIL_FROM_CONTROL_CENTRE);
00641     QWhatsThis::add(radio,
00642           i18n("Check to use the email address set in the KDE Control Center, to identify you as the sender when sending email alarms."));
00643     grid->addMultiCellWidget(radio, 2, 2, 1, 2, Qt::AlignAuto);
00644 
00645     // 'From' email address to be picked from KMail's identities when the email alarm is configured
00646     radio = new RadioButton(i18n("Use KMail &identities"), group);
00647     radio->setFixedSize(radio->sizeHint());
00648     mFromAddressGroup->insert(radio, Preferences::MAIL_FROM_KMAIL);
00649     QWhatsThis::add(radio,
00650           i18n("Check to use KMail's email identities to identify you as the sender when sending email alarms. "
00651                "For existing email alarms, KMail's default identity will be used. "
00652                "For new email alarms, you will be able to pick which of KMail's identities to use."));
00653     grid->addMultiCellWidget(radio, 3, 3, 1, 2, Qt::AlignAuto);
00654 
00655     // 'Bcc' email address controls ...
00656     grid->addRowSpacing(4, KDialog::spacingHint());
00657     label = new Label(i18n("'Bcc' email address", "&Bcc:"), group);
00658     label->setFixedSize(label->sizeHint());
00659     grid->addWidget(label, 5, 0);
00660     mBccAddressGroup = new ButtonGroup(group);
00661     mBccAddressGroup->hide();
00662     connect(mBccAddressGroup, SIGNAL(buttonSet(int)), SLOT(slotBccAddrChanged(int)));
00663 
00664     // Line edit to enter a 'Bcc' email address
00665     radio = new RadioButton(group);
00666     radio->setFixedSize(radio->sizeHint());
00667     mBccAddressGroup->insert(radio, Preferences::MAIL_FROM_ADDR);
00668     label->setBuddy(radio);
00669     grid->addWidget(radio, 5, 1);
00670     mEmailBccAddress = new QLineEdit(group);
00671     whatsThis = i18n("Your email address, used for blind copying email alarms to yourself. "
00672                      "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.");
00673     QWhatsThis::add(radio, whatsThis);
00674     QWhatsThis::add(mEmailBccAddress, whatsThis);
00675     radio->setFocusWidget(mEmailBccAddress);
00676     grid->addWidget(mEmailBccAddress, 5, 2);
00677 
00678     // 'Bcc' email address to be taken from Control Centre
00679     radio = new RadioButton(i18n("Us&e address from Control Center"), group);
00680     radio->setFixedSize(radio->sizeHint());
00681     mBccAddressGroup->insert(radio, Preferences::MAIL_FROM_CONTROL_CENTRE);
00682     QWhatsThis::add(radio,
00683           i18n("Check to use the email address set in the KDE Control Center, for blind copying email alarms to yourself."));
00684     grid->addMultiCellWidget(radio, 6, 6, 1, 2, Qt::AlignAuto);
00685 
00686     group->setFixedHeight(group->sizeHint().height());
00687 
00688     box = new QHBox(mPage);   // this is to allow left adjustment
00689     mEmailQueuedNotify = new QCheckBox(i18n("&Notify when remote emails are queued"), box);
00690     mEmailQueuedNotify->setFixedSize(mEmailQueuedNotify->sizeHint());
00691     QWhatsThis::add(mEmailQueuedNotify,
00692           i18n("Display a notification message whenever an email alarm has queued an email for sending to a remote system. "
00693                "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."));
00694     box->setStretchFactor(new QWidget(box), 1);    // left adjust the controls
00695     box->setFixedHeight(box->sizeHint().height());
00696 
00697     mPage->setStretchFactor(new QWidget(mPage), 1);    // top adjust the widgets
00698 }
00699 
00700 void EmailPrefTab::restore()
00701 {
00702     mEmailClient->setButton(Preferences::mEmailClient);
00703     mEmailCopyToKMail->setChecked(Preferences::emailCopyToKMail());
00704     setEmailAddress(Preferences::mEmailFrom, Preferences::mEmailAddress);
00705     setEmailBccAddress((Preferences::mEmailBccFrom == Preferences::MAIL_FROM_CONTROL_CENTRE), Preferences::mEmailBccAddress);
00706     mEmailQueuedNotify->setChecked(Preferences::emailQueuedNotify());
00707     mAddressChanged = mBccAddressChanged = false;
00708 }
00709 
00710 void EmailPrefTab::apply(bool syncToDisc)
00711 {
00712     int client = mEmailClient->id(mEmailClient->selected());
00713     Preferences::mEmailClient = (client >= 0) ? Preferences::MailClient(client) : Preferences::default_emailClient;
00714     Preferences::mEmailCopyToKMail = mEmailCopyToKMail->isChecked();
00715     Preferences::setEmailAddress(static_cast<Preferences::MailFrom>(mFromAddressGroup->selectedId()), mEmailAddress->text().stripWhiteSpace());
00716     Preferences::setEmailBccAddress((mBccAddressGroup->selectedId() == Preferences::MAIL_FROM_CONTROL_CENTRE), mEmailBccAddress->text().stripWhiteSpace());
00717     Preferences::setEmailQueuedNotify(mEmailQueuedNotify->isChecked());
00718     PrefsTabBase::apply(syncToDisc);
00719 }
00720 
00721 void EmailPrefTab::setDefaults()
00722 {
00723     mEmailClient->setButton(Preferences::default_emailClient);
00724     setEmailAddress(Preferences::default_emailFrom(), Preferences::default_emailAddress);
00725     setEmailBccAddress((Preferences::default_emailBccFrom == Preferences::MAIL_FROM_CONTROL_CENTRE), Preferences::default_emailBccAddress);
00726     mEmailQueuedNotify->setChecked(Preferences::default_emailQueuedNotify);
00727 }
00728 
00729 void EmailPrefTab::setEmailAddress(Preferences::MailFrom from, const QString& address)
00730 {
00731     mFromAddressGroup->setButton(from);
00732     mEmailAddress->setText(from == Preferences::MAIL_FROM_ADDR ? address.stripWhiteSpace() : QString());
00733 }
00734 
00735 void EmailPrefTab::setEmailBccAddress(bool useControlCentre, const QString& address)
00736 {
00737     mBccAddressGroup->setButton(useControlCentre ? Preferences::MAIL_FROM_CONTROL_CENTRE : Preferences::MAIL_FROM_ADDR);
00738     mEmailBccAddress->setText(useControlCentre ? QString() : address.stripWhiteSpace());
00739 }
00740 
00741 void EmailPrefTab::slotEmailClientChanged(int id)
00742 {
00743     mEmailCopyToKMail->setEnabled(id == Preferences::SENDMAIL);
00744 }
00745 
00746 void EmailPrefTab::slotFromAddrChanged(int id)
00747 {
00748     mEmailAddress->setEnabled(id == Preferences::MAIL_FROM_ADDR);
00749     mAddressChanged = true;
00750 }
00751 
00752 void EmailPrefTab::slotBccAddrChanged(int id)
00753 {
00754     mEmailBccAddress->setEnabled(id == Preferences::MAIL_FROM_ADDR);
00755     mBccAddressChanged = true;
00756 }
00757 
00758 QString EmailPrefTab::validate()
00759 {
00760     if (mAddressChanged)
00761     {
00762         mAddressChanged = false;
00763         QString errmsg = validateAddr(mFromAddressGroup, mEmailAddress, KAMail::i18n_NeedFromEmailAddress());
00764         if (!errmsg.isEmpty())
00765             return errmsg;
00766     }
00767     if (mBccAddressChanged)
00768     {
00769         mBccAddressChanged = false;
00770         return validateAddr(mBccAddressGroup, mEmailBccAddress, i18n("No valid 'Bcc' email address is specified."));
00771     }
00772     return QString::null;
00773 }
00774 
00775 QString EmailPrefTab::validateAddr(ButtonGroup* group, QLineEdit* addr, const QString& msg)
00776 {
00777     QString errmsg = i18n("%1\nAre you sure you want to save your changes?").arg(msg);
00778     switch (group->selectedId())
00779     {
00780         case Preferences::MAIL_FROM_CONTROL_CENTRE:
00781             if (!KAMail::controlCentreAddress().isEmpty())
00782                 return QString::null;
00783             errmsg = i18n("No email address is currently set in the KDE Control Center. %1").arg(errmsg);
00784             break;
00785         case Preferences::MAIL_FROM_KMAIL:
00786             if (KAMail::identitiesExist())
00787                 return QString::null;
00788             errmsg = i18n("No KMail identities currently exist. %1").arg(errmsg);
00789             break;
00790         case Preferences::MAIL_FROM_ADDR:
00791             if (!addr->text().stripWhiteSpace().isEmpty())
00792                 return QString::null;
00793             break;
00794     }
00795     return errmsg;
00796 }
00797 
00798 
00799 /*=============================================================================
00800 = Class FontColourPrefTab
00801 =============================================================================*/
00802 
00803 FontColourPrefTab::FontColourPrefTab(QVBox* frame)
00804     : PrefsTabBase(frame)
00805 {
00806     mFontChooser = new FontColourChooser(mPage, 0, false, QStringList(), i18n("Message Font && Color"), true, false);
00807 
00808     QHBox* layoutBox = new QHBox(mPage);
00809     QHBox* box = new QHBox(layoutBox);    // to group widgets for QWhatsThis text
00810     box->setSpacing(KDialog::spacingHint());
00811     QLabel* label1 = new QLabel(i18n("Di&sabled alarm color:"), box);
00812 //  label1->setMinimumSize(label1->sizeHint());
00813     box->setStretchFactor(new QWidget(box), 1);
00814     mDisabledColour = new KColorCombo(box);
00815     mDisabledColour->setMinimumSize(mDisabledColour->sizeHint());
00816     label1->setBuddy(mDisabledColour);
00817     QWhatsThis::add(box,
00818           i18n("Choose the text color in the alarm list for disabled alarms."));
00819     layoutBox->setStretchFactor(new QWidget(layoutBox), 1);    // left adjust the controls
00820     layoutBox->setFixedHeight(layoutBox->sizeHint().height());
00821 
00822     layoutBox = new QHBox(mPage);
00823     box = new QHBox(layoutBox);    // to group widgets for QWhatsThis text
00824     box->setSpacing(KDialog::spacingHint());
00825     QLabel* label2 = new QLabel(i18n("E&xpired alarm color:"), box);
00826 //  label2->setMinimumSize(label2->sizeHint());
00827     box->setStretchFactor(new QWidget(box), 1);
00828     mExpiredColour = new KColorCombo(box);
00829     mExpiredColour->setMinimumSize(mExpiredColour->sizeHint());
00830     label2->setBuddy(mExpiredColour);
00831     QWhatsThis::add(box,
00832           i18n("Choose the text color in the alarm list for expired alarms."));
00833     layoutBox->setStretchFactor(new QWidget(layoutBox), 1);    // left adjust the controls
00834     layoutBox->setFixedHeight(layoutBox->sizeHint().height());
00835 
00836     // Line up the two sets of colour controls
00837     QSize size = label1->sizeHint();
00838     QSize size2 = label2->sizeHint();
00839     if (size2.width() > size.width())
00840         size.setWidth(size2.width());
00841     label1->setFixedSize(size);
00842     label2->setFixedSize(size);
00843 
00844     mPage->setStretchFactor(new QWidget(mPage), 1);    // top adjust the widgets
00845 }
00846 
00847 void FontColourPrefTab::restore()
00848 {
00849     mFontChooser->setBgColour(Preferences::mDefaultBgColour);
00850     mFontChooser->setColours(Preferences::mMessageColours);
00851     mFontChooser->setFont(Preferences::mMessageFont);
00852     mDisabledColour->setColor(Preferences::mDisabledColour);
00853     mExpiredColour->setColor(Preferences::mExpiredColour);
00854 }
00855 
00856 void FontColourPrefTab::apply(bool syncToDisc)
00857 {
00858     Preferences::mDefaultBgColour = mFontChooser->bgColour();
00859     Preferences::mMessageColours  = mFontChooser->colours();
00860     Preferences::mMessageFont     = mFontChooser->font();
00861     Preferences::mDisabledColour  = mDisabledColour->color();
00862     Preferences::mExpiredColour   = mExpiredColour->color();
00863     PrefsTabBase::apply(syncToDisc);
00864 }
00865 
00866 void FontColourPrefTab::setDefaults()
00867 {
00868     mFontChooser->setBgColour(Preferences::default_defaultBgColour);
00869     mFontChooser->setColours(Preferences::default_messageColours);
00870     mFontChooser->setFont(Preferences::default_messageFont());
00871     mDisabledColour->setColor(Preferences::default_disabledColour);
00872     mExpiredColour->setColor(Preferences::default_expiredColour);
00873 }
00874 
00875 
00876 /*=============================================================================
00877 = Class EditPrefTab
00878 =============================================================================*/
00879 
00880 EditPrefTab::EditPrefTab(QVBox* frame)
00881     : PrefsTabBase(frame)
00882 {
00883     // Get alignment to use in QLabel::setAlignment(alignment | Qt::WordBreak)
00884     // (AlignAuto doesn't work correctly there)
00885     int alignment = QApplication::reverseLayout() ? Qt::AlignRight : Qt::AlignLeft;
00886 
00887     int groupTopMargin = fontMetrics().lineSpacing()/2;
00888     QString defsetting   = i18n("The default setting for \"%1\" in the alarm edit dialog.");
00889     QString soundSetting = i18n("Check to select %1 as the default setting for \"%2\" in the alarm edit dialog.");
00890 
00891     // DISPLAY ALARMS
00892     QGroupBox* group = new QGroupBox(i18n("Display Alarms"), mPage);
00893     QBoxLayout* layout = new QVBoxLayout(group, KDialog::marginHint(), KDialog::spacingHint());
00894     layout->addSpacing(groupTopMargin);
00895 
00896     mConfirmAck = new QCheckBox(EditAlarmDlg::i18n_k_ConfirmAck(), group, "defConfAck");
00897     mConfirmAck->setMinimumSize(mConfirmAck->sizeHint());
00898     QWhatsThis::add(mConfirmAck, defsetting.arg(EditAlarmDlg::i18n_ConfirmAck()));
00899     layout->addWidget(mConfirmAck, 0, Qt::AlignAuto);
00900 
00901     mAutoClose = new QCheckBox(LateCancelSelector::i18n_i_AutoCloseWinLC(), group, "defAutoClose");
00902     mAutoClose->setMinimumSize(mAutoClose->sizeHint());
00903     QWhatsThis::add(mAutoClose, defsetting.arg(LateCancelSelector::i18n_AutoCloseWin()));
00904     layout->addWidget(mAutoClose, 0, Qt::AlignAuto);
00905 
00906     QHBox* box = new QHBox(group);
00907     box->setSpacing(KDialog::spacingHint());
00908     layout->addWidget(box);
00909     QLabel* label = new QLabel(i18n("Reminder &units:"), box);
00910     label->setFixedSize(label->sizeHint());
00911     mReminderUnits = new QComboBox(box, "defWarnUnits");
00912     mReminderUnits->insertItem(TimePeriod::i18n_Hours_Mins(), TimePeriod::HOURS_MINUTES);
00913     mReminderUnits->insertItem(TimePeriod::i18n_Days(), TimePeriod::DAYS);
00914     mReminderUnits->insertItem(TimePeriod::i18n_Weeks(), TimePeriod::WEEKS);
00915     mReminderUnits->setFixedSize(mReminderUnits->sizeHint());
00916     label->setBuddy(mReminderUnits);
00917     QWhatsThis::add(box,
00918           i18n("The default units for the reminder in the alarm edit dialog."));
00919     box->setStretchFactor(new QWidget(box), 1);    // left adjust the control
00920 
00921     mSpecialActionsButton = new SpecialActionsButton(EditAlarmDlg::i18n_SpecialActions(), box);
00922     mSpecialActionsButton->setFixedSize(mSpecialActionsButton->sizeHint());
00923 
00924     // SOUND
00925     QButtonGroup* bgroup = new QButtonGroup(SoundPicker::i18n_Sound(), mPage, "soundGroup");
00926     layout = new QVBoxLayout(bgroup, KDialog::marginHint(), KDialog::spacingHint());
00927     layout->addSpacing(groupTopMargin);
00928 
00929     mSound = new QCheckBox(SoundPicker::i18n_s_Sound(), bgroup, "defSound");
00930     mSound->setMinimumSize(mSound->sizeHint());
00931     QWhatsThis::add(mSound, defsetting.arg(SoundPicker::i18n_Sound()));
00932     layout->addWidget(mSound, 0, Qt::AlignAuto);
00933 
00934     box = new QHBox(bgroup);
00935     box->setSpacing(KDialog::spacingHint());
00936     layout->addWidget(box, 0, Qt::AlignAuto);
00937 
00938     mBeep = new QRadioButton(SoundPicker::i18n_b_Beep(), box, "defBeep");
00939     bgroup->insert(mBeep);
00940     mBeep->setMinimumSize(mBeep->sizeHint());
00941     QWhatsThis::add(mBeep,
00942           soundSetting.arg(SoundPicker::i18n_Beep()).arg(SoundPicker::i18n_Sound()));
00943     mFile = new QRadioButton(SoundPicker::i18n_File(), box, "defFile");
00944     bgroup->insert(mFile);
00945     mFile->setMinimumSize(mFile->sizeHint());
00946     QWhatsThis::add(mFile,
00947           soundSetting.arg(SoundPicker::i18n_File()).arg(SoundPicker::i18n_Sound()));
00948     if (theApp()->speechEnabled())
00949     {
00950         mSpeak = new QRadioButton(SoundPicker::i18n_Speak(), box, "defSpeak");
00951         mSpeak->setMinimumSize(mSpeak->sizeHint());
00952         QWhatsThis::add(mSpeak,
00953               soundSetting.arg(SoundPicker::i18n_Speak()).arg(SoundPicker::i18n_Sound()));
00954         bgroup->insert(mSpeak);
00955     }
00956     else
00957         mSpeak = 0;
00958     box->setStretchFactor(new QWidget(box), 1);    // left adjust the controls
00959 
00960     box = new QHBox(bgroup);   // this is to control the QWhatsThis text display area
00961     box->setSpacing(KDialog::spacingHint());
00962     mSoundFileLabel = new QLabel(i18n("Sound &file:"), box);
00963     mSoundFileLabel->setFixedSize(mSoundFileLabel->sizeHint());
00964     mSoundFile = new QLineEdit(box);
00965     mSoundFileLabel->setBuddy(mSoundFile);
00966     mSoundFileBrowse = new QPushButton(box);
00967     mSoundFileBrowse->setPixmap(SmallIcon("fileopen"));
00968     mSoundFileBrowse->setFixedSize(mSoundFileBrowse->sizeHint());
00969     connect(mSoundFileBrowse, SIGNAL(clicked()), SLOT(slotBrowseSoundFile()));
00970     QToolTip::add(mSoundFileBrowse, i18n("Choose a sound file"));
00971     QWhatsThis::add(box,
00972           i18n("Enter the default sound file to use in the alarm edit dialog."));
00973     box->setFixedHeight(box->sizeHint().height());
00974     layout->addWidget(box);
00975 
00976 #ifndef WITHOUT_ARTS
00977     mSoundRepeat = new QCheckBox(i18n("Repea&t sound file"), bgroup, "defRepeatSound");
00978     mSoundRepeat->setMinimumSize(mSoundRepeat->sizeHint());
00979     QWhatsThis::add(mSoundRepeat, i18n("sound file \"Repeat\" checkbox", "The default setting for sound file \"%1\" in the alarm edit dialog.").arg(SoundDlg::i18n_Repeat()));
00980     layout->addWidget(mSoundRepeat, 0, Qt::AlignAuto);
00981 #endif
00982     bgroup->setFixedHeight(bgroup->sizeHint().height());
00983 
00984     // COMMAND ALARMS
00985     group = new QGroupBox(i18n("Command Alarms"), mPage);
00986     layout = new QVBoxLayout(group, KDialog::marginHint(), KDialog::spacingHint());
00987     layout->addSpacing(groupTopMargin);
00988     layout = new QHBoxLayout(layout, KDialog::spacingHint());
00989 
00990     mCmdScript = new QCheckBox(EditAlarmDlg::i18n_p_EnterScript(), group, "defCmdScript");
00991     mCmdScript->setMinimumSize(mCmdScript->sizeHint());
00992     QWhatsThis::add(mCmdScript, defsetting.arg(EditAlarmDlg::i18n_EnterScript()));
00993     layout->addWidget(mCmdScript);
00994     layout->addStretch();
00995 
00996     mCmdXterm = new QCheckBox(EditAlarmDlg::i18n_w_ExecInTermWindow(), group, "defCmdXterm");
00997     mCmdXterm->setMinimumSize(mCmdXterm->sizeHint());
00998     QWhatsThis::add(mCmdXterm, defsetting.arg(EditAlarmDlg::i18n_ExecInTermWindow()));
00999     layout->addWidget(mCmdXterm);
01000 
01001     // EMAIL ALARMS
01002     group = new QGroupBox(i18n("Email Alarms"), mPage);
01003     layout = new QVBoxLayout(group, KDialog::marginHint(), KDialog::spacingHint());
01004     layout->addSpacing(groupTopMargin);
01005 
01006     // BCC email to sender
01007     mEmailBcc = new QCheckBox(EditAlarmDlg::i18n_e_CopyEmailToSelf(), group, "defEmailBcc");
01008     mEmailBcc->setMinimumSize(mEmailBcc->sizeHint());
01009     QWhatsThis::add(mEmailBcc, defsetting.arg(EditAlarmDlg::i18n_CopyEmailToSelf()));
01010     layout->addWidget(mEmailBcc, 0, Qt::AlignAuto);
01011 
01012     // MISCELLANEOUS
01013     // Show in KOrganizer
01014     mCopyToKOrganizer = new QCheckBox(EditAlarmDlg::i18n_g_ShowInKOrganizer(), mPage, "defShowKorg");
01015     mCopyToKOrganizer->setMinimumSize(mCopyToKOrganizer->sizeHint());
01016     QWhatsThis::add(mCopyToKOrganizer, defsetting.arg(EditAlarmDlg::i18n_ShowInKOrganizer()));
01017 
01018     // Late cancellation
01019     box = new QHBox(mPage);
01020     box->setSpacing(KDialog::spacingHint());
01021     mLateCancel = new QCheckBox(LateCancelSelector::i18n_n_CancelIfLate(), box, "defCancelLate");
01022     mLateCancel->setMinimumSize(mLateCancel->sizeHint());
01023     QWhatsThis::add(mLateCancel, defsetting.arg(LateCancelSelector::i18n_CancelIfLate()));
01024     box->setStretchFactor(new QWidget(box), 1);    // left adjust the control
01025 
01026     // Recurrence
01027     QHBox* itemBox = new QHBox(box);   // this is to control the QWhatsThis text display area
01028     itemBox->setSpacing(KDialog::spacingHint());
01029     label = new QLabel(i18n("&Recurrence:"), itemBox);
01030     label->setFixedSize(label->sizeHint());
01031     mRecurPeriod = new QComboBox(itemBox, "defRecur");
01032     mRecurPeriod->insertItem(RecurrenceEdit::i18n_NoRecur());
01033     mRecurPeriod->insertItem(RecurrenceEdit::i18n_AtLogin());
01034     mRecurPeriod->insertItem(RecurrenceEdit::i18n_HourlyMinutely());
01035     mRecurPeriod->insertItem(RecurrenceEdit::i18n_Daily());
01036     mRecurPeriod->insertItem(RecurrenceEdit::i18n_Weekly());
01037     mRecurPeriod->insertItem(RecurrenceEdit::i18n_Monthly());
01038     mRecurPeriod->insertItem(RecurrenceEdit::i18n_Yearly());
01039     mRecurPeriod->setFixedSize(mRecurPeriod->sizeHint());
01040     label->setBuddy(mRecurPeriod);
01041     QWhatsThis::add(itemBox,
01042           i18n("The default setting for the recurrence rule in the alarm edit dialog."));
01043     box->setFixedHeight(itemBox->sizeHint().height());
01044 
01045     // How to handle February 29th in yearly recurrences
01046     QVBox* vbox = new QVBox(mPage);   // this is to control the QWhatsThis text display area
01047     vbox->setSpacing(KDialog::spacingHint());
01048     label = new QLabel(i18n("In non-leap years, repeat yearly February 29th alarms on:"), vbox);
01049     label->setAlignment(alignment | Qt::WordBreak);
01050     itemBox = new QHBox(vbox);
01051     itemBox->setSpacing(2*KDialog::spacingHint());
01052     mFeb29 = new QButtonGroup(itemBox);
01053     mFeb29->hide();
01054     QWidget* widget = new QWidget(itemBox);
01055     widget->setFixedWidth(3*KDialog::spacingHint());
01056     QRadioButton* radio = new QRadioButton(i18n("February 2&8th"), itemBox);
01057     radio->setMinimumSize(radio->sizeHint());
01058     mFeb29->insert(radio, KARecurrence::FEB29_FEB28);
01059     radio = new QRadioButton(i18n("March &1st"), itemBox);
01060     radio->setMinimumSize(radio->sizeHint());
01061     mFeb29->insert(radio, KARecurrence::FEB29_MAR1);
01062     radio = new QRadioButton(i18n("Do &not repeat"), itemBox);
01063     radio->setMinimumSize(radio->sizeHint());
01064     mFeb29->insert(radio, KARecurrence::FEB29_FEB29);
01065     itemBox->setFixedHeight(itemBox->sizeHint().height());
01066     QWhatsThis::add(vbox,
01067           i18n("For yearly recurrences, choose what date, if any, alarms due on February 29th should occur in non-leap years.\n"
01068                "Note that the next scheduled occurrence of existing alarms is not re-evaluated when you change this setting."));
01069 
01070     mPage->setStretchFactor(new QWidget(mPage), 1);    // top adjust the widgets
01071 }
01072 
01073 void EditPrefTab::restore()
01074 {
01075     mAutoClose->setChecked(Preferences::mDefaultAutoClose);
01076     mConfirmAck->setChecked(Preferences::mDefaultConfirmAck);
01077     mReminderUnits->setCurrentItem(Preferences::mDefaultReminderUnits);
01078     mSpecialActionsButton->setActions(Preferences::mDefaultPreAction, Preferences::mDefaultPostAction);
01079     mSound->setChecked(Preferences::mDefaultSound);
01080     setSoundType(Preferences::mDefaultSoundType);
01081     mSoundFile->setText(Preferences::mDefaultSoundFile);
01082 #ifndef WITHOUT_ARTS
01083     mSoundRepeat->setChecked(Preferences::mDefaultSoundRepeat);
01084 #endif
01085     mCmdScript->setChecked(Preferences::mDefaultCmdScript);
01086     mCmdXterm->setChecked(Preferences::mDefaultCmdLogType == EditAlarmDlg::EXEC_IN_TERMINAL);
01087     mEmailBcc->setChecked(Preferences::mDefaultEmailBcc);
01088     mCopyToKOrganizer->setChecked(Preferences::mDefaultCopyToKOrganizer);
01089     mLateCancel->setChecked(Preferences::mDefaultLateCancel);
01090     mRecurPeriod->setCurrentItem(recurIndex(Preferences::mDefaultRecurPeriod));
01091     mFeb29->setButton(Preferences::mDefaultFeb29Type);
01092 }
01093 
01094 void EditPrefTab::apply(bool syncToDisc)
01095 {
01096     Preferences::mDefaultAutoClose        = mAutoClose->isChecked();
01097     Preferences::mDefaultConfirmAck       = mConfirmAck->isChecked();
01098     Preferences::mDefaultReminderUnits    = static_cast<TimePeriod::Units>(mReminderUnits->currentItem());
01099     Preferences::mDefaultPreAction        = mSpecialActionsButton->preAction();
01100     Preferences::mDefaultPostAction       = mSpecialActionsButton->postAction();
01101     Preferences::mDefaultSound            = mSound->isChecked();
01102     Preferences::mDefaultSoundFile        = mSoundFile->text();
01103     Preferences::mDefaultSoundType        = mSpeak && mSpeak->isOn() ? SoundPicker::SPEAK
01104                                           : mFile->isOn()            ? SoundPicker::PLAY_FILE
01105                                           :                            SoundPicker::BEEP;
01106 #ifndef WITHOUT_ARTS
01107     Preferences::mDefaultSoundRepeat      = mSoundRepeat->isChecked();
01108 #endif
01109     Preferences::mDefaultCmdScript        = mCmdScript->isChecked();
01110     Preferences::mDefaultCmdLogFile       = (mCmdXterm->isChecked() ? EditAlarmDlg::EXEC_IN_TERMINAL : EditAlarmDlg::DISCARD_OUTPUT);
01111     Preferences::mDefaultEmailBcc         = mEmailBcc->isChecked();
01112     Preferences::mDefaultCopyToKOrganizer = mCopyToKOrganizer->isChecked();
01113     Preferences::mDefaultLateCancel       = mLateCancel->isChecked() ? 1 : 0;
01114     switch (mRecurPeriod->currentItem())
01115     {
01116         case 6:  Preferences::mDefaultRecurPeriod = RecurrenceEdit::ANNUAL;    break;
01117         case 5:  Preferences::mDefaultRecurPeriod = RecurrenceEdit::MONTHLY;   break;
01118         case 4:  Preferences::mDefaultRecurPeriod = RecurrenceEdit::WEEKLY;    break;
01119         case 3:  Preferences::mDefaultRecurPeriod = RecurrenceEdit::DAILY;     break;
01120         case 2:  Preferences::mDefaultRecurPeriod = RecurrenceEdit::SUBDAILY;  break;
01121         case 1:  Preferences::mDefaultRecurPeriod = RecurrenceEdit::AT_LOGIN;  break;
01122         case 0:
01123         default: Preferences::mDefaultRecurPeriod = RecurrenceEdit::NO_RECUR;  break;
01124     }
01125     int feb29 = mFeb29->selectedId();
01126     Preferences::mDefaultFeb29Type  = (feb29 >= 0) ? static_cast<KARecurrence::Feb29Type>(feb29) : Preferences::default_defaultFeb29Type;
01127     PrefsTabBase::apply(syncToDisc);
01128 }
01129 
01130 void EditPrefTab::setDefaults()
01131 {
01132     mAutoClose->setChecked(Preferences::default_defaultAutoClose);
01133     mConfirmAck->setChecked(Preferences::default_defaultConfirmAck);
01134     mReminderUnits->setCurrentItem(Preferences::default_defaultReminderUnits);
01135     mSpecialActionsButton->setActions(Preferences::default_defaultPreAction, Preferences::default_defaultPostAction);
01136     mSound->setChecked(Preferences::default_defaultSound);
01137     setSoundType(Preferences::default_defaultSoundType);
01138     mSoundFile->setText(Preferences::default_defaultSoundFile);
01139 #ifndef WITHOUT_ARTS
01140     mSoundRepeat->setChecked(Preferences::default_defaultSoundRepeat);
01141 #endif
01142     mCmdScript->setChecked(Preferences::default_defaultCmdScript);
01143     mCmdXterm->setChecked(Preferences::default_defaultCmdLogType == EditAlarmDlg::EXEC_IN_TERMINAL);
01144     mEmailBcc->setChecked(Preferences::default_defaultEmailBcc);
01145     mCopyToKOrganizer->setChecked(Preferences::default_defaultCopyToKOrganizer);
01146     mLateCancel->setChecked(Preferences::default_defaultLateCancel);
01147     mRecurPeriod->setCurrentItem(recurIndex(Preferences::default_defaultRecurPeriod));
01148     mFeb29->setButton(Preferences::default_defaultFeb29Type);
01149 }
01150 
01151 void EditPrefTab::slotBrowseSoundFile()
01152 {
01153     QString defaultDir;
01154     QString url = SoundPicker::browseFile(defaultDir, mSoundFile->text());
01155     if (!url.isEmpty())
01156         mSoundFile->setText(url);
01157 }
01158 
01159 int EditPrefTab::recurIndex(RecurrenceEdit::RepeatType type)
01160 {
01161     switch (type)
01162     {
01163         case RecurrenceEdit::ANNUAL:   return 6;
01164         case RecurrenceEdit::MONTHLY:  return 5;
01165         case RecurrenceEdit::WEEKLY:   return 4;
01166         case RecurrenceEdit::DAILY:    return 3;
01167         case RecurrenceEdit::SUBDAILY: return 2;
01168         case RecurrenceEdit::AT_LOGIN: return 1;
01169         case RecurrenceEdit::NO_RECUR:
01170         default:                       return 0;
01171     }
01172 }
01173 
01174 void EditPrefTab::setSoundType(SoundPicker::Type type)
01175 {
01176     switch (type)
01177     {
01178         case SoundPicker::PLAY_FILE:
01179             mFile->setChecked(true);
01180             break;
01181         case SoundPicker::SPEAK:
01182             if (mSpeak)
01183             {
01184                 mSpeak->setChecked(true);
01185                 break;
01186             }
01187             // fall through to BEEP
01188         case SoundPicker::BEEP:
01189         default:
01190             mBeep->setChecked(true);
01191             break;
01192     }
01193 }
01194 
01195 QString EditPrefTab::validate()
01196 {
01197     if (mFile->isOn()  &&  mSoundFile->text().isEmpty())
01198     {
01199         mSoundFile->setFocus();
01200         return i18n("You must enter a sound file when %1 is selected as the default sound type").arg(SoundPicker::i18n_File());;
01201     }
01202     return QString::null;
01203 }
01204 
01205 
01206 /*=============================================================================
01207 = Class ViewPrefTab
01208 =============================================================================*/
01209 
01210 ViewPrefTab::ViewPrefTab(QVBox* frame)
01211     : PrefsTabBase(frame)
01212 {
01213     QGroupBox* group = new QGroupBox(i18n("Alarm List"), mPage);
01214     QBoxLayout* layout = new QVBoxLayout(group, KDialog::marginHint(), KDialog::spacingHint());
01215     layout->addSpacing(fontMetrics().lineSpacing()/2);
01216 
01217     mListShowTime = new QCheckBox(MainWindow::i18n_t_ShowAlarmTime(), group, "listTime");
01218     mListShowTime->setMinimumSize(mListShowTime->sizeHint());
01219     connect(mListShowTime, SIGNAL(toggled(bool)), SLOT(slotListTimeToggled(bool)));
01220     QWhatsThis::add(mListShowTime,
01221           i18n("Specify whether to show in the alarm list, the time at which each alarm is due"));
01222     layout->addWidget(mListShowTime, 0, Qt::AlignAuto);
01223 
01224     mListShowTimeTo = new QCheckBox(MainWindow::i18n_n_ShowTimeToAlarm(), group, "listTimeTo");
01225     mListShowTimeTo->setMinimumSize(mListShowTimeTo->sizeHint());
01226     connect(mListShowTimeTo, SIGNAL(toggled(bool)), SLOT(slotListTimeToToggled(bool)));
01227     QWhatsThis::add(mListShowTimeTo,
01228           i18n("Specify whether to show in the alarm list, how long until each alarm is due"));
01229     layout->addWidget(mListShowTimeTo, 0, Qt::AlignAuto);
01230     group->setMaximumHeight(group->sizeHint().height());
01231 
01232     group = new QGroupBox(i18n("System Tray Tooltip"), mPage);
01233     QGridLayout* grid = new QGridLayout(group, 5, 3, KDialog::marginHint(), KDialog::spacingHint());
01234     grid->setColStretch(2, 1);
01235     grid->addColSpacing(0, indentWidth());
01236     grid->addColSpacing(1, indentWidth());
01237     grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
01238 
01239     mTooltipShowAlarms = new QCheckBox(i18n("Show next &24 hours' alarms"), group, "tooltipShow");
01240     mTooltipShowAlarms->setMinimumSize(mTooltipShowAlarms->sizeHint());
01241     connect(mTooltipShowAlarms, SIGNAL(toggled(bool)), SLOT(slotTooltipAlarmsToggled(bool)));
01242     QWhatsThis::add(mTooltipShowAlarms,
01243           i18n("Specify whether to include in the system tray tooltip, a summary of alarms due in the next 24 hours"));
01244     grid->addMultiCellWidget(mTooltipShowAlarms, 1, 1, 0, 2, Qt::AlignAuto);
01245 
01246     QHBox* box = new QHBox(group);
01247     box->setSpacing(KDialog::spacingHint());
01248     mTooltipMaxAlarms = new QCheckBox(i18n("Ma&ximum number of alarms to show:"), box, "tooltipMax");
01249     mTooltipMaxAlarms->setMinimumSize(mTooltipMaxAlarms->sizeHint());
01250     connect(mTooltipMaxAlarms, SIGNAL(toggled(bool)), SLOT(slotTooltipMaxToggled(bool)));
01251     mTooltipMaxAlarmCount = new SpinBox(1, 99, 1, box);
01252     mTooltipMaxAlarmCount->setLineShiftStep(5);
01253     mTooltipMaxAlarmCount->setMinimumSize(mTooltipMaxAlarmCount->sizeHint());
01254     QWhatsThis::add(box,
01255           i18n("Uncheck to display all of the next 24 hours' alarms in the system tray tooltip. "
01256                "Check to enter an upper limit on the number to be displayed."));
01257     grid->addMultiCellWidget(box, 2, 2, 1, 2, Qt::AlignAuto);
01258 
01259     mTooltipShowTime = new QCheckBox(MainWindow::i18n_m_ShowAlarmTime(), group, "tooltipTime");
01260     mTooltipShowTime->setMinimumSize(mTooltipShowTime->sizeHint());
01261     connect(mTooltipShowTime, SIGNAL(toggled(bool)), SLOT(slotTooltipTimeToggled(bool)));
01262     QWhatsThis::add(mTooltipShowTime,
01263           i18n("Specify whether to show in the system tray tooltip, the time at which each alarm is due"));
01264     grid->addMultiCellWidget(mTooltipShowTime, 3, 3, 1, 2, Qt::AlignAuto);
01265 
01266     mTooltipShowTimeTo = new QCheckBox(MainWindow::i18n_l_ShowTimeToAlarm(), group, "tooltipTimeTo");
01267     mTooltipShowTimeTo->setMinimumSize(mTooltipShowTimeTo->sizeHint());
01268     connect(mTooltipShowTimeTo, SIGNAL(toggled(bool)), SLOT(slotTooltipTimeToToggled(bool)));
01269     QWhatsThis::add(mTooltipShowTimeTo,
01270           i18n("Specify whether to show in the system tray tooltip, how long until each alarm is due"));
01271     grid->addMultiCellWidget(mTooltipShowTimeTo, 4, 4, 1, 2, Qt::AlignAuto);
01272 
01273     box = new QHBox(group);   // this is to control the QWhatsThis text display area
01274     box->setSpacing(KDialog::spacingHint());
01275     mTooltipTimeToPrefixLabel = new QLabel(i18n("&Prefix:"), box);
01276     mTooltipTimeToPrefixLabel->setFixedSize(mTooltipTimeToPrefixLabel->sizeHint());
01277     mTooltipTimeToPrefix = new QLineEdit(box);
01278     mTooltipTimeToPrefixLabel->setBuddy(mTooltipTimeToPrefix);
01279     QWhatsThis::add(box,
01280           i18n("Enter the text to be displayed in front of the time until the alarm, in the system tray tooltip"));
01281     box->setFixedHeight(box->sizeHint().height());
01282     grid->addWidget(box, 5, 2, Qt::AlignAuto);
01283     group->setMaximumHeight(group->sizeHint().height());
01284 
01285     mModalMessages = new QCheckBox(i18n("Message &windows have a title bar and take keyboard focus"), mPage, "modalMsg");
01286     mModalMessages->setMinimumSize(mModalMessages->sizeHint());
01287     QWhatsThis::add(mModalMessages,
01288           i18n("Specify the characteristics of alarm message windows:\n"
01289                "- If checked, the window is a normal window with a title bar, which grabs keyboard input when it is displayed.\n"
01290                "- If unchecked, the window does not interfere with your typing when "
01291                "it is displayed, but it has no title bar and cannot be moved or resized."));
01292 
01293     mShowExpiredAlarms = new QCheckBox(MainWindow::i18n_e_ShowExpiredAlarms(), mPage, "showExpired");
01294     mShowExpiredAlarms->setMinimumSize(mShowExpiredAlarms->sizeHint());
01295     QWhatsThis::add(mShowExpiredAlarms,
01296           i18n("Specify whether to show expired alarms in the alarm list"));
01297 
01298     QHBox* itemBox = new QHBox(mPage);   // this is to control the QWhatsThis text display area
01299     box = new QHBox(itemBox);
01300     box->setSpacing(KDialog::spacingHint());
01301     QLabel* label = new QLabel(i18n("System tray icon &update interval:"), box);
01302     mDaemonTrayCheckInterval = new SpinBox(1, 9999, 1, box, "daemonCheck");
01303     mDaemonTrayCheckInterval->setLineShiftStep(10);
01304     mDaemonTrayCheckInterval->setMinimumSize(mDaemonTrayCheckInterval->sizeHint());
01305     label->setBuddy(mDaemonTrayCheckInterval);
01306     label = new QLabel(i18n("seconds"), box);
01307     QWhatsThis::add(box,
01308           i18n("How often to update the system tray icon to indicate whether or not the Alarm Daemon is monitoring alarms."));
01309     itemBox->setStretchFactor(new QWidget(itemBox), 1);    // left adjust the controls
01310     itemBox->setFixedHeight(box->sizeHint().height());
01311 
01312     mPage->setStretchFactor(new QWidget(mPage), 1);    // top adjust the widgets
01313 }
01314 
01315 void ViewPrefTab::restore()
01316 {
01317     setList(Preferences::mShowAlarmTime,
01318             Preferences::mShowTimeToAlarm);
01319     setTooltip(Preferences::mTooltipAlarmCount,
01320                Preferences::mShowTooltipAlarmTime,
01321                Preferences::mShowTooltipTimeToAlarm,
01322                Preferences::mTooltipTimeToPrefix);
01323     mModalMessages->setChecked(Preferences::mModalMessages);
01324     mShowExpiredAlarms->setChecked(Preferences::mShowExpiredAlarms);
01325     mDaemonTrayCheckInterval->setValue(Preferences::mDaemonTrayCheckInterval);
01326 }
01327 
01328 void ViewPrefTab::apply(bool syncToDisc)
01329 {
01330     Preferences::mShowAlarmTime           = mListShowTime->isChecked();
01331     Preferences::mShowTimeToAlarm         = mListShowTimeTo->isChecked();
01332     int n = mTooltipShowAlarms->isChecked() ? -1 : 0;
01333     if (n  &&  mTooltipMaxAlarms->isChecked())
01334         n = mTooltipMaxAlarmCount->value();
01335     Preferences::mTooltipAlarmCount       = n;
01336     Preferences::mShowTooltipAlarmTime    = mTooltipShowTime->isChecked();
01337     Preferences::mShowTooltipTimeToAlarm  = mTooltipShowTimeTo->isChecked();
01338     Preferences::mTooltipTimeToPrefix     = mTooltipTimeToPrefix->text();
01339     Preferences::mModalMessages           = mModalMessages->isChecked();
01340     Preferences::mShowExpiredAlarms       = mShowExpiredAlarms->isChecked();
01341     Preferences::mDaemonTrayCheckInterval = mDaemonTrayCheckInterval->value();
01342     PrefsTabBase::apply(syncToDisc);
01343 }
01344 
01345 void ViewPrefTab::setDefaults()
01346 {
01347     setList(Preferences::default_showAlarmTime,
01348             Preferences::default_showTimeToAlarm);
01349     setTooltip(Preferences::default_tooltipAlarmCount,
01350                Preferences::default_showTooltipAlarmTime,
01351                Preferences::default_showTooltipTimeToAlarm,
01352                Preferences::default_tooltipTimeToPrefix);
01353     mModalMessages->setChecked(Preferences::default_modalMessages);
01354     mShowExpiredAlarms->setChecked(Preferences::default_showExpiredAlarms);
01355     mDaemonTrayCheckInterval->setValue(Preferences::default_daemonTrayCheckInterval);
01356 }
01357 
01358 void ViewPrefTab::setList(bool time, bool timeTo)
01359 {
01360     if (!timeTo)
01361         time = true;    // ensure that at least one option is ticked
01362 
01363     // Set the states of the two checkboxes without calling signal
01364     // handlers, since these could change the checkboxes' states.
01365     mListShowTime->blockSignals(true);
01366     mListShowTimeTo->blockSignals(true);
01367 
01368     mListShowTime->setChecked(time);
01369     mListShowTimeTo->setChecked(timeTo);
01370 
01371     mListShowTime->blockSignals(false);
01372     mListShowTimeTo->blockSignals(false);
01373 }
01374 
01375 void ViewPrefTab::setTooltip(int maxAlarms, bool time, bool timeTo, const QString& prefix)
01376 {
01377     if (!timeTo)
01378         time = true;    // ensure that at least one time option is ticked
01379 
01380     // Set the states of the controls without calling signal
01381     // handlers, since these could change the checkboxes' states.
01382     mTooltipShowAlarms->blockSignals(true);
01383     mTooltipShowTime->blockSignals(true);
01384     mTooltipShowTimeTo->blockSignals(true);
01385 
01386     mTooltipShowAlarms->setChecked(maxAlarms);
01387     mTooltipMaxAlarms->setChecked(maxAlarms > 0);
01388     mTooltipMaxAlarmCount->setValue(maxAlarms > 0 ? maxAlarms : 1);
01389     mTooltipShowTime->setChecked(time);
01390     mTooltipShowTimeTo->setChecked(timeTo);
01391     mTooltipTimeToPrefix->setText(prefix);
01392 
01393     mTooltipShowAlarms->blockSignals(false);
01394     mTooltipShowTime->blockSignals(false);
01395     mTooltipShowTimeTo->blockSignals(false);
01396 
01397     // Enable/disable controls according to their states
01398     slotTooltipTimeToToggled(timeTo);
01399     slotTooltipAlarmsToggled(maxAlarms);
01400 }
01401 
01402 void ViewPrefTab::slotListTimeToggled(bool on)
01403 {
01404     if (!on  &&  !mListShowTimeTo->isChecked())
01405         mListShowTimeTo->setChecked(true);
01406 }
01407 
01408 void ViewPrefTab::slotListTimeToToggled(bool on)
01409 {
01410     if (!on  &&  !mListShowTime->isChecked())
01411         mListShowTime->setChecked(true);
01412 }
01413 
01414 void ViewPrefTab::slotTooltipAlarmsToggled(bool on)
01415 {
01416     mTooltipMaxAlarms->setEnabled(on);
01417     mTooltipMaxAlarmCount->setEnabled(on && mTooltipMaxAlarms->isChecked());
01418     mTooltipShowTime->setEnabled(on);
01419     mTooltipShowTimeTo->setEnabled(on);
01420     on = on && mTooltipShowTimeTo->isChecked();
01421     mTooltipTimeToPrefix->setEnabled(on);
01422     mTooltipTimeToPrefixLabel->setEnabled(on);
01423 }
01424 
01425 void ViewPrefTab::slotTooltipMaxToggled(bool on)
01426 {
01427     mTooltipMaxAlarmCount->setEnabled(on && mTooltipMaxAlarms->isEnabled());
01428 }
01429 
01430 void ViewPrefTab::slotTooltipTimeToggled(bool on)
01431 {
01432     if (!on  &&  !mTooltipShowTimeTo->isChecked())
01433         mTooltipShowTimeTo->setChecked(true);
01434 }
01435 
01436 void ViewPrefTab::slotTooltipTimeToToggled(bool on)
01437 {
01438     if (!on  &&  !mTooltipShowTime->isChecked())
01439         mTooltipShowTime->setChecked(true);
01440     on = on && mTooltipShowTimeTo->isEnabled();
01441     mTooltipTimeToPrefix->setEnabled(on);
01442     mTooltipTimeToPrefixLabel->setEnabled(on);
01443 }
KDE Home | KDE Accessibility Home | Description of Access Keys