kalarm

templatepickdlg.cpp
1 /*
2  * templatepickdlg.cpp - dialogue to choose an alarm template
3  * Program: kalarm
4  * Copyright © 2004,2008 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 
23 #include <tqlayout.h>
24 #include <tqwhatsthis.h>
25 
26 #include <tdelocale.h>
27 #include <kdebug.h>
28 
29 #include "functions.h"
30 #include "shellprocess.h"
31 #include "templatelistview.h"
32 #include "templatepickdlg.moc"
33 
34 static const char TMPL_PICK_DIALOG_NAME[] = "TemplatePickDialog";
35 
36 
37 TemplatePickDlg::TemplatePickDlg(TQWidget* parent, const char* name)
38  : KDialogBase(KDialogBase::Plain, i18n("Choose Alarm Template"), Ok|Cancel, Ok, parent, name)
39 {
40  TQWidget* topWidget = plainPage();
41  TQBoxLayout* topLayout = new TQVBoxLayout(topWidget);
42  topLayout->setSpacing(spacingHint());
43 
44  // Display the list of templates, but exclude command alarms if in kiosk mode.
45  bool includeCmdAlarms = ShellProcess::authorised();
46  mTemplateList = new TemplateListView(includeCmdAlarms, i18n("Select a template to base the new alarm on."), topWidget, "list");
47  mTemplateList->setSelectionMode(TQListView::Single);
48  mTemplateList->refresh(); // populate the template list
49  connect(mTemplateList, TQ_SIGNAL(selectionChanged()), TQ_SLOT(slotSelectionChanged()));
50  // Require a real double click (even if KDE is in single-click mode) to accept the selection
51  connect(mTemplateList, TQ_SIGNAL(doubleClicked(TQListViewItem*, const TQPoint&, int)), TQ_SLOT(slotOk()));
52  topLayout->addWidget(mTemplateList);
53 
54  slotSelectionChanged(); // enable or disable the OK button
55 
56  TQSize s;
57  if (KAlarm::readConfigWindowSize(TMPL_PICK_DIALOG_NAME, s))
58  resize(s);
59 }
60 
61 /******************************************************************************
62 * Return the currently selected alarm template, or 0 if none.
63 */
64 const KAEvent* TemplatePickDlg::selectedTemplate() const
65 {
66  return mTemplateList->selectedEvent();
67 }
68 
69 /******************************************************************************
70 * Called when the template selection changes.
71 * Enable/disable the OK button depending on whether anything is selected.
72 */
73 void TemplatePickDlg::slotSelectionChanged()
74 {
75  enableButtonOK(mTemplateList->selectedItem());
76 }
77 
78 /******************************************************************************
79 * Called when the dialog's size has changed.
80 * Records the new size in the config file.
81 */
82 void TemplatePickDlg::resizeEvent(TQResizeEvent* re)
83 {
84  if (isVisible())
85  KAlarm::writeConfigWindowSize(TMPL_PICK_DIALOG_NAME, re->size());
86  KDialog::resizeEvent(re);
87 }
KAEvent corresponds to a KCal::Event instance.
Definition: alarmevent.h:232
miscellaneous functions