kalarm

templatepickdlg.cpp
00001 /*
00002  *  templatepickdlg.cpp  -  dialogue to choose an alarm template
00003  *  Program:  kalarm
00004  *  Copyright © 2004,2008 by David Jarvie <djarvie@kde.org>
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 <tqlayout.h>
00024 #include <tqwhatsthis.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(TQWidget* parent, const char* name)
00038     : KDialogBase(KDialogBase::Plain, i18n("Choose Alarm Template"), Ok|Cancel, Ok, parent, name)
00039 {
00040     TQWidget* topWidget = plainPage();
00041     TQBoxLayout* topLayout = new TQVBoxLayout(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(TQListView::Single);
00048     mTemplateList->refresh();      // populate the template list
00049     connect(mTemplateList, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelectionChanged()));
00050     // Require a real double click (even if KDE is in single-click mode) to accept the selection
00051     connect(mTemplateList, TQT_SIGNAL(doubleClicked(TQListViewItem*, const TQPoint&, int)), TQT_SLOT(slotOk()));
00052     topLayout->addWidget(mTemplateList);
00053 
00054     slotSelectionChanged();        // enable or disable the OK button
00055 
00056     TQSize s;
00057     if (KAlarm::readConfigWindowSize(TMPL_PICK_DIALOG_NAME, s))
00058         resize(s);
00059 }
00060 
00061 /******************************************************************************
00062 * Return the currently selected alarm template, or 0 if none.
00063 */
00064 const KAEvent* TemplatePickDlg::selectedTemplate() const
00065 {
00066     return mTemplateList->selectedEvent();
00067 }
00068 
00069 /******************************************************************************
00070 * Called when the template selection changes.
00071 * Enable/disable the OK button depending on whether anything is selected.
00072 */
00073 void TemplatePickDlg::slotSelectionChanged()
00074 {
00075     enableButtonOK(mTemplateList->selectedItem());
00076 }
00077 
00078 /******************************************************************************
00079 *  Called when the dialog's size has changed.
00080 *  Records the new size in the config file.
00081 */
00082 void TemplatePickDlg::resizeEvent(TQResizeEvent* re)
00083 {
00084     if (isVisible())
00085         KAlarm::writeConfigWindowSize(TMPL_PICK_DIALOG_NAME, re->size());
00086     KDialog::resizeEvent(re);
00087 }