kalarm Library API Documentation

prefs.cpp

00001 /*
00002  *  prefs.cpp  -  program preferences
00003  *  Program:  kalarm
00004  *  (C) 2001, 2002 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
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *
00020  *  As a special exception, permission is given to link this program
00021  *  with any edition of Qt, and distribute the resulting executable,
00022  *  without including the source code for Qt in the source distribution.
00023  */
00024 
00025 #include "kalarm.h"
00026 
00027 #include <qobjectlist.h>
00028 #include <qlayout.h>
00029 #include <qbuttongroup.h>
00030 #include <qvbox.h>
00031 #include <qlabel.h>
00032 #include <qcheckbox.h>
00033 #include <qradiobutton.h>
00034 #include <qspinbox.h>
00035 #include <qcombobox.h>
00036 #include <qwhatsthis.h>
00037 #include <qstyle.h>
00038 
00039 #include <kdialog.h>
00040 #include <kglobal.h>
00041 #include <klocale.h>
00042 #include <kaboutdata.h>
00043 #include <kapplication.h>
00044 #include <kdebug.h>
00045 
00046 #include "fontcolour.h"
00047 #include "datetime.h"
00048 #include "prefsettings.h"
00049 #include "prefs.moc"
00050 
00051 
00052 PrefsTabBase::PrefsTabBase(QVBox* frame)
00053         : mPage(frame)
00054 {
00055         mPage->setMargin(KDialog::marginHint());
00056 }
00057 
00058 void PrefsTabBase::setSettings(Settings* setts)
00059 {
00060         mSettings = setts;
00061         restore();
00062 }
00063 
00064 void PrefsTabBase::apply(bool syncToDisc)
00065 {
00066         mSettings->saveSettings(syncToDisc);
00067         mSettings->emitSettingsChanged();
00068 }
00069 
00070 
00071 
00072 MiscPrefTab::MiscPrefTab(QVBox* frame)
00073         : PrefsTabBase(frame)
00074 {
00075         QGroupBox* group = new QButtonGroup(i18n("Run Mode"), mPage, "modeGroup");
00076         QGridLayout* grid = new QGridLayout(group, 6, 2, marginKDE2 + KDialog::marginHint(), KDialog::spacingHint());
00077         grid->setColStretch(0, 0);
00078         grid->setColStretch(1, 2);
00079         grid->addColSpacing(0, 3*KDialog::spacingHint());
00080         grid->addRowSpacing(0, fontMetrics().lineSpacing()/2);
00081         int row = 1;
00082 
00083         // Run-in-system-tray radio button has an ID of 0
00084         mRunInSystemTray = new QRadioButton(i18n("Run continuously in system &tray"), group, "runTray");
00085         mRunInSystemTray->setFixedSize(mRunInSystemTray->sizeHint());
00086         connect(mRunInSystemTray, SIGNAL(toggled(bool)), this, SLOT(slotRunModeToggled(bool)));
00087         QWhatsThis::add(mRunInSystemTray,
00088               i18n("Check to run %1 continuously in the KDE system tray.\n\n"
00089                    "Notes:\n"
00090                    "1. With this option selected, closing the system tray icon will quit %2.\n"
00091                    "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. Running in the system tray simply provides easy access and a status indication.")
00092                    .arg(kapp->aboutData()->programName()).arg(kapp->aboutData()->programName()));
00093         grid->addMultiCellWidget(mRunInSystemTray, row, row, 0, 1, AlignLeft);
00094 
00095         mAutostartTrayIcon1 = new QCheckBox(i18n("Autostart at &login"), group, "autoTray");
00096         mAutostartTrayIcon1->setFixedSize(mAutostartTrayIcon1->sizeHint());
00097         QWhatsThis::add(mAutostartTrayIcon1,
00098               i18n("Check to run %1 whenever you start KDE.").arg(kapp->aboutData()->programName()));
00099         grid->addWidget(mAutostartTrayIcon1, ++row, 1, AlignLeft);
00100 
00101         mDisableAlarmsIfStopped = new QCheckBox(i18n("Disa&ble alarms while not running"), group, "disableAl");
00102         mDisableAlarmsIfStopped->setFixedSize(mDisableAlarmsIfStopped->sizeHint());
00103         QWhatsThis::add(mDisableAlarmsIfStopped,
00104               i18n("Check to disable alarms whenever %1 is not running. Alarms will only appear while the system tray icon is visible.").arg(kapp->aboutData()->programName()));
00105         grid->addWidget(mDisableAlarmsIfStopped, ++row, 1, AlignLeft);
00106 
00107         // Run-on-demand radio button has an ID of 3
00108         mRunOnDemand = new QRadioButton(i18n("&Run only on demand"), group, "runDemand");
00109         mRunOnDemand->setFixedSize(mRunOnDemand->sizeHint());
00110         connect(mRunOnDemand, SIGNAL(toggled(bool)), this, SLOT(slotRunModeToggled(bool)));
00111         QWhatsThis::add(mRunOnDemand,
00112               i18n("Check to run %1 only when required.\n\n"
00113                    "Notes:\n"
00114                    "1. Alarms are displayed even when %2 is not running, since alarm monitoring is done by the alarm daemon.\n"
00115                    "2. With this option selected, the system tray icon can be displayed or hidden independently of %3.")
00116                    .arg(kapp->aboutData()->programName()).arg(kapp->aboutData()->programName()).arg(kapp->aboutData()->programName()));
00117         ++row;
00118         grid->addMultiCellWidget(mRunOnDemand, row, row, 0, 1, AlignLeft);
00119 
00120         mAutostartTrayIcon2 = new QCheckBox(i18n("Autostart system tray &icon at login"), group, "autoRun");
00121         mAutostartTrayIcon2->setFixedSize(mAutostartTrayIcon2->sizeHint());
00122         QWhatsThis::add(mAutostartTrayIcon2,
00123               i18n("Check to display the system tray icon whenever you start KDE."));
00124         grid->addWidget(mAutostartTrayIcon2, ++row, 1, AlignLeft);
00125         group->setFixedHeight(group->sizeHint().height());
00126 
00127         QHBox* itemBox = new QHBox(mPage);   // this is to control the QWhatsThis text display area
00128         QHBox* box = new QHBox(itemBox);
00129         box->setSpacing(KDialog::spacingHint());
00130         QLabel* label = new QLabel(i18n("System tray icon &update interval:"), box);
00131         mDaemonTrayCheckInterval = new QSpinBox(1, 9999, 1, box, "daemonCheck");
00132         mDaemonTrayCheckInterval->setMinimumSize(mDaemonTrayCheckInterval->sizeHint());
00133         label->setBuddy(mDaemonTrayCheckInterval);
00134         label = new QLabel(i18n("seconds"), box);
00135         QWhatsThis::add(box,
00136               i18n("How often to update the system tray icon to indicate whether or not the Alarm Daemon is monitoring alarms."));
00137         itemBox->setStretchFactor(new QWidget(itemBox), 1);    // left adjust the controls
00138         itemBox->setFixedHeight(box->sizeHint().height());
00139 
00140         itemBox = new QHBox(mPage);   // this is to control the QWhatsThis text display area
00141         box = new QHBox(itemBox);
00142         box->setSpacing(KDialog::spacingHint());
00143         label = new QLabel(i18n("&Start of day for date-only alarms:"), box);
00144         mStartOfDay = new TimeSpinBox(box);
00145         mStartOfDay->setFixedSize(mStartOfDay->sizeHint());
00146         label->setBuddy(mStartOfDay);
00147         QWhatsThis::add(box,
00148               i18n("The earliest time of day at which a date-only alarm (i.e. an alarm with \"any time\" specified) will be triggered."));
00149         itemBox->setStretchFactor(new QWidget(itemBox), 1);    // left adjust the controls
00150         itemBox->setFixedHeight(box->sizeHint().height());
00151 
00152 #ifdef KALARM_EMAIL
00153         box = new QHBox(mPage);
00154         box->setSpacing(2*KDialog::spacingHint());
00155         label = new QLabel(i18n("Email client:"), box);
00156         mEmailClient = new QButtonGroup(box);
00157         mEmailClient->hide();
00158         QRadioButton* radio = new QRadioButton(i18n("&KMail"), box, "kmail");
00159         radio->setMinimumSize(radio->sizeHint());
00160         mEmailClient->insert(radio, Settings::KMAIL);
00161         radio = new QRadioButton(i18n("S&endmail"), box, "sendmail");
00162         radio->setMinimumSize(radio->sizeHint());
00163         mEmailClient->insert(radio, Settings::SENDMAIL);
00164         box->setFixedHeight(box->sizeHint().height());
00165         QWhatsThis::add(box,
00166               i18n("Choose how to send email when an email alarm is triggered.\n"
00167                    "KMail: A KMail composer window is displayed to enable you to send the email.\n"
00168                    "Sendmail: The email is sent automatically. This option will only work if your system is configured to use 'sendmail' or 'mail'."));
00169 #endif
00170 
00171         itemBox = new QHBox(mPage);   // this is to control the QWhatsThis text display area
00172         mConfirmAlarmDeletion = new QCheckBox(i18n("Con&firm alarm deletions"), itemBox, "confirmDeletion");
00173         mConfirmAlarmDeletion->setMinimumSize(mConfirmAlarmDeletion->sizeHint());
00174         QWhatsThis::add(mConfirmAlarmDeletion,
00175               i18n("Check to be prompted for confirmation each time you delete an alarm."));
00176         itemBox->setStretchFactor(new QWidget(itemBox), 1);    // left adjust the controls
00177         itemBox->setFixedHeight(box->sizeHint().height());
00178 
00179         box = new QHBox(mPage);   // top-adjust all the widgets
00180 }
00181 
00182 void MiscPrefTab::restore()
00183 {
00184         bool systray = mSettings->mRunInSystemTray;
00185         mRunInSystemTray->setChecked(systray);
00186         mRunOnDemand->setChecked(!systray);
00187         mDisableAlarmsIfStopped->setChecked(mSettings->mDisableAlarmsIfStopped);
00188         mAutostartTrayIcon1->setChecked(mSettings->mAutostartTrayIcon);
00189         mAutostartTrayIcon2->setChecked(mSettings->mAutostartTrayIcon);
00190         mConfirmAlarmDeletion->setChecked(mSettings->mConfirmAlarmDeletion);
00191         mDaemonTrayCheckInterval->setValue(mSettings->mDaemonTrayCheckInterval);
00192         mStartOfDay->setValue(mSettings->mStartOfDay.hour()*60 + mSettings->mStartOfDay.minute());
00193 }
00194 
00195 void MiscPrefTab::apply(bool syncToDisc)
00196 {
00197         bool systray = mRunInSystemTray->isChecked();
00198         mSettings->mRunInSystemTray         = systray;
00199         mSettings->mDisableAlarmsIfStopped  = mDisableAlarmsIfStopped->isChecked();
00200         mSettings->mAutostartTrayIcon       = systray ? mAutostartTrayIcon1->isChecked() : mAutostartTrayIcon2->isChecked();
00201         mSettings->mConfirmAlarmDeletion    = mConfirmAlarmDeletion->isChecked();
00202         mSettings->mDaemonTrayCheckInterval = mDaemonTrayCheckInterval->value();
00203         int sod = mStartOfDay->value();
00204         mSettings->mStartOfDay.setHMS(sod/60, sod%60, 0);
00205         PrefsTabBase::apply(syncToDisc);
00206 }
00207 
00208 void MiscPrefTab::setDefaults()
00209 {
00210         bool systray = Settings::default_runInSystemTray;
00211         mRunInSystemTray->setChecked(systray);
00212         mRunOnDemand->setChecked(!systray);
00213         mDisableAlarmsIfStopped->setChecked(Settings::default_disableAlarmsIfStopped);
00214         mAutostartTrayIcon1->setChecked(Settings::default_autostartTrayIcon);
00215         mAutostartTrayIcon2->setChecked(Settings::default_autostartTrayIcon);
00216         mConfirmAlarmDeletion->setChecked(Settings::default_confirmAlarmDeletion);
00217         mDaemonTrayCheckInterval->setValue(Settings::default_daemonTrayCheckInterval);
00218         mStartOfDay->setValue(Settings::default_startOfDay.hour()*60 + Settings::default_startOfDay.minute());
00219 }
00220 
00221 void MiscPrefTab::slotRunModeToggled(bool)
00222 {
00223         bool systray = (mRunInSystemTray->isOn());
00224         mAutostartTrayIcon2->setEnabled(!systray);
00225         mAutostartTrayIcon1->setEnabled(systray);
00226         mDisableAlarmsIfStopped->setEnabled(systray);
00227 }
00228 
00229 
00230 AppearancePrefTab::AppearancePrefTab(QVBox* frame)
00231         : PrefsTabBase(frame)
00232 {
00233         mFontChooser = new FontColourChooser(mPage, 0L, false, QStringList(), true, i18n("Font && Color"), false);
00234 }
00235 
00236 void AppearancePrefTab::restore()
00237 {
00238         mFontChooser->setBgColour(mSettings->mDefaultBgColour);
00239         mFontChooser->setFont(mSettings->mMessageFont);
00240 }
00241 
00242 void AppearancePrefTab::apply(bool syncToDisc)
00243 {
00244         mSettings->mDefaultBgColour = mFontChooser->bgColour();
00245         mSettings->mMessageFont     = mFontChooser->font();
00246         PrefsTabBase::apply(syncToDisc);
00247 }
00248 
00249 void AppearancePrefTab::setDefaults()
00250 {
00251         mFontChooser->setBgColour(Settings::default_defaultBgColour);
00252         mFontChooser->setFont(Settings::default_messageFont);
00253 }
00254 
00255 
00256 DefaultPrefTab::DefaultPrefTab(QVBox* frame)
00257         : PrefsTabBase(frame)
00258 {
00259         QString defsetting = i18n("The default setting for \"%1\" in the alarm edit dialog.");
00260 
00261         QHBox* box = new QHBox(mPage);   // this is to control the QWhatsThis text display area
00262         mDefaultLateCancel = new QCheckBox(i18n("Cancel if &late"), box, "defCancelLate");
00263         mDefaultLateCancel->setMinimumSize(mDefaultLateCancel->sizeHint());
00264         QWhatsThis::add(mDefaultLateCancel, defsetting.arg(i18n("Cancel if late")));
00265         box->setStretchFactor(new QWidget(box), 1);    // left adjust the controls
00266         box->setFixedHeight(box->sizeHint().height());
00267 
00268         box = new QHBox(mPage);   // this is to control the QWhatsThis text display area
00269         mDefaultConfirmAck = new QCheckBox(i18n("Confirm ac&knowledgement"), box, "defConfAck");
00270         mDefaultConfirmAck->setMinimumSize(mDefaultConfirmAck->sizeHint());
00271         QWhatsThis::add(mDefaultConfirmAck, defsetting.arg(i18n("Confirm acknowledgement")));
00272         box->setStretchFactor(new QWidget(box), 1);    // left adjust the controls
00273         box->setFixedHeight(box->sizeHint().height());
00274 
00275         box = new QHBox(mPage);   // this is to control the QWhatsThis text display area
00276         mDefaultBeep = new QCheckBox(i18n("&Beep"), box, "defBeep");
00277         mDefaultBeep->setMinimumSize(mDefaultBeep->sizeHint());
00278         QWhatsThis::add(mDefaultBeep,
00279               i18n("Check to select Beep as the default setting for \"Sound\" in the alarm edit dialog."));
00280         box->setStretchFactor(new QWidget(box), 1);    // left adjust the controls
00281         box->setFixedHeight(box->sizeHint().height());
00282 
00283 #ifdef KALARM_EMAIL
00284         // BCC email to sender
00285         box = new QHBox(mPage);   // this is to control the QWhatsThis text display area
00286         mDefaultEmailBcc = new QCheckBox(i18n("Copy email to &self"), box, "defEmailBcc");
00287         mDefaultEmailBcc->setMinimumSize(mDefaultEmailBcc->sizeHint());
00288         QWhatsThis::add(mDefaultEmailBcc, defsetting.arg(i18n("Copy email to self")));
00289         box->setStretchFactor(new QWidget(box), 1);    // left adjust the controls
00290         box->setFixedHeight(box->sizeHint().height());
00291 #endif
00292 
00293         QHBox* itemBox = new QHBox(mPage);   // this is to control the QWhatsThis text display area
00294         box = new QHBox(itemBox);
00295         box->setSpacing(KDialog::spacingHint());
00296         QLabel* label = new QLabel(i18n("Recurrence &period:"), box);
00297         label->setFixedSize(label->sizeHint());
00298         mDefaultRecurPeriod = new QComboBox(box, "defRecur");
00299         mDefaultRecurPeriod->insertItem(i18n("Hours/Minutes"));
00300         mDefaultRecurPeriod->insertItem(i18n("Days"));
00301         mDefaultRecurPeriod->insertItem(i18n("Weeks"));
00302         mDefaultRecurPeriod->insertItem(i18n("Months"));
00303         mDefaultRecurPeriod->insertItem(i18n("Years"));
00304         mDefaultRecurPeriod->setFixedSize(mDefaultRecurPeriod->sizeHint());
00305         label->setBuddy(mDefaultRecurPeriod);
00306         QWhatsThis::add(box,
00307               i18n("The default setting for the recurrence period in the alarm edit dialog."));
00308         itemBox->setStretchFactor(new QWidget(itemBox), 1);
00309         itemBox->setFixedHeight(box->sizeHint().height());
00310 
00311         box = new QHBox(mPage);   // top-adjust all the widgets
00312 }
00313 
00314 void DefaultPrefTab::restore()
00315 {
00316         mDefaultLateCancel->setChecked(mSettings->mDefaultLateCancel);
00317         mDefaultConfirmAck->setChecked(mSettings->mDefaultConfirmAck);
00318         mDefaultBeep->setChecked(mSettings->mDefaultBeep);
00319         mDefaultRecurPeriod->setCurrentItem(recurIndex(mSettings->mDefaultRecurPeriod));
00320 }
00321 
00322 void DefaultPrefTab::apply(bool syncToDisc)
00323 {
00324         mSettings->mDefaultLateCancel = mDefaultLateCancel->isChecked();
00325         mSettings->mDefaultConfirmAck = mDefaultConfirmAck->isChecked();
00326         mSettings->mDefaultBeep       = mDefaultBeep->isChecked();
00327         switch (mDefaultRecurPeriod->currentItem())
00328         {
00329                 case 4:  mSettings->mDefaultRecurPeriod = RecurrenceEdit::ANNUAL;    break;
00330                 case 3:  mSettings->mDefaultRecurPeriod = RecurrenceEdit::MONTHLY;   break;
00331                 case 2:  mSettings->mDefaultRecurPeriod = RecurrenceEdit::WEEKLY;    break;
00332                 case 1:  mSettings->mDefaultRecurPeriod = RecurrenceEdit::DAILY;     break;
00333                 case 0:
00334                 default: mSettings->mDefaultRecurPeriod = RecurrenceEdit::SUBDAILY;  break;
00335         }
00336         PrefsTabBase::apply(syncToDisc);
00337 }
00338 
00339 void DefaultPrefTab::setDefaults()
00340 {
00341         mDefaultLateCancel->setChecked(mSettings->default_defaultLateCancel);
00342         mDefaultConfirmAck->setChecked(mSettings->default_defaultConfirmAck);
00343         mDefaultBeep->setChecked(mSettings->default_defaultBeep);
00344         mDefaultRecurPeriod->setCurrentItem(recurIndex(mSettings->default_defaultRecurPeriod));
00345 }
00346 
00347 int DefaultPrefTab::recurIndex(RecurrenceEdit::RepeatType type)
00348 {
00349         switch (type)
00350         {
00351                 case RecurrenceEdit::ANNUAL:   return 4;
00352                 case RecurrenceEdit::MONTHLY:  return 3;
00353                 case RecurrenceEdit::WEEKLY:   return 2;
00354                 case RecurrenceEdit::DAILY:    return 1;
00355                 case RecurrenceEdit::SUBDAILY:
00356                 default:                       return 0;
00357         }
00358 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:27 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001