kalarm

templatepickdlg.cpp

00001 /*
00002  *  templatepickdlg.cpp  -  dialogue to choose an alarm template
00003  *  Program:  kalarm
00004  *  Copyright (C) 2004 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 <qlayout.h>
00024 #include <qwhatsthis.h>
00025 
00026 #include <klocale.h>
00027 #include <kdebug.h>
00028 
00029 #include "functions.h"
00030 #include "shellprocess.h"
00031 #include "templatelistview.h"
00032 #include "templatepickdlg.moc"
00033 
00034 static const char TMPL_PICK_DIALOG_NAME[] = "TemplatePickDialog";
00035 
00036 
00037 TemplatePickDlg::TemplatePickDlg(QWidget* parent, const char* name)
00038     : KDialogBase(KDialogBase::Plain, i18n("Choose Alarm Template"), Ok|Cancel, Ok, parent, name)
00039 {
00040     QWidget* topWidget = plainPage();
00041     QBoxLayout* topLayout = new QVBoxLayout(topWidget);
00042     topLayout->setSpacing(spacingHint());
00043 
00044     // Display the list of templates, but exclude command alarms if in kiosk mode.
00045     bool includeCmdAlarms = ShellProcess::authorised();
00046     mTemplateList = new TemplateListView(includeCmdAlarms, i18n("Select a template to base the new alarm on."), topWidget, "list");
00047     mTemplateList->setSelectionMode(QListView::Single);
00048     mTemplateList->refresh();      // populate the template list
00049     connect(mTemplateList, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()));
00050     connect(mTemplateList, SIGNAL(executed(QListViewItem*)), SLOT(slotOk()));
00051     topLayout->addWidget(mTemplateList);
00052 
00053     slotSelectionChanged();        // enable or disable the OK button
00054 
00055     QSize s;
00056     if (KAlarm::readConfigWindowSize(TMPL_PICK_DIALOG_NAME, s))
00057         resize(s);
00058 }
00059 
00060 /******************************************************************************
00061 * Return the currently selected alarm template, or 0 if none.
00062 */
00063 const KAEvent* TemplatePickDlg::selectedTemplate() const
00064 {
00065     return mTemplateList->selectedEvent();
00066 }
00067 
00068 /******************************************************************************
00069 * Called when the template selection changes.
00070 * Enable/disable the OK button depending on whether anything is selected.
00071 */
00072 void TemplatePickDlg::slotSelectionChanged()
00073 {
00074     enableButtonOK(mTemplateList->selectedItem());
00075 }
00076 
00077 /******************************************************************************
00078 *  Called when the dialog's size has changed.
00079 *  Records the new size in the config file.
00080 */
00081 void TemplatePickDlg::resizeEvent(QResizeEvent* re)
00082 {
00083     if (isVisible())
00084         KAlarm::writeConfigWindowSize(TMPL_PICK_DIALOG_NAME, re->size());
00085     KDialog::resizeEvent(re);
00086 }
KDE Home | KDE Accessibility Home | Description of Access Keys