SVN_SILENT made messages (.desktop file)
[kdepim.git] / kalarm / templatepickdlg.cpp
blobf8c7fcb1a9ab39b843c733c081cd431f262191cb
1 /*
2 * templatepickdlg.cpp - dialog to choose an alarm template
3 * Program: kalarm
4 * Copyright © 2004,2006-2010 by David Jarvie <djarvie@kde.org>
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.
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.
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.
21 #include "kalarm.h"
22 #include "templatepickdlg.moc"
24 #ifndef USE_AKONADI
25 #include "eventlistmodel.h"
26 #include "templatelistfiltermodel.h"
27 #endif
28 #include "functions.h"
29 #include "shellprocess.h"
30 #include "templatelistview.h"
32 #include <klocale.h>
33 #include <kdebug.h>
35 #include <QVBoxLayout>
36 #include <QResizeEvent>
38 static const char TMPL_PICK_DIALOG_NAME[] = "TemplatePickDialog";
41 TemplatePickDlg::TemplatePickDlg(KAEvent::Actions type, QWidget* parent)
42 : KDialog(parent)
44 QWidget* topWidget = new QWidget(this);
45 setMainWidget(topWidget);
46 setCaption(i18nc("@title:window", "Choose Alarm Template"));
47 setButtons(Ok|Cancel);
48 setDefaultButton(Ok);
49 QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
50 topLayout->setMargin(0);
51 topLayout->setSpacing(spacingHint());
53 // Display the list of templates, but exclude command alarms if in kiosk mode.
54 KAEvent::Actions shown = KAEvent::ACT_ALL;
55 if (!ShellProcess::authorised())
57 type = static_cast<KAEvent::Actions>(type & ~KAEvent::ACT_COMMAND);
58 shown = static_cast<KAEvent::Actions>(shown & ~KAEvent::ACT_COMMAND);
60 #ifdef USE_AKONADI
61 mListFilterModel = new TemplateListModel(this);
62 mListFilterModel->setAlarmActionsEnabled(type);
63 mListFilterModel->setAlarmActionFilter(shown);
64 #else
65 mListFilterModel = new TemplateListFilterModel(EventListModel::templates());
66 mListFilterModel->setTypesEnabled(type);
67 mListFilterModel->setTypeFilter(shown);
68 #endif
69 mListView = new TemplateListView(topWidget);
70 mListView->setModel(mListFilterModel);
71 #ifdef USE_AKONADI
72 mListView->sortByColumn(TemplateListModel::TemplateNameColumn, Qt::AscendingOrder);
73 #else
74 mListView->sortByColumn(TemplateListFilterModel::TemplateNameColumn, Qt::AscendingOrder);
75 #endif
76 mListView->setSelectionMode(QAbstractItemView::SingleSelection);
77 mListView->setWhatsThis(i18nc("@info:whatsthis", "Select a template to base the new alarm on."));
78 connect(mListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(slotSelectionChanged()));
79 // Require a real double click (even if KDE is in single-click mode) to accept the selection
80 connect(mListView, SIGNAL(doubleClicked(QModelIndex)), SLOT(accept()));
81 topLayout->addWidget(mListView);
83 slotSelectionChanged(); // enable or disable the OK button
85 QSize s;
86 if (KAlarm::readConfigWindowSize(TMPL_PICK_DIALOG_NAME, s))
87 resize(s);
90 /******************************************************************************
91 * Return the currently selected alarm template, or 0 if none.
93 #ifdef USE_AKONADI
94 KAEvent TemplatePickDlg::selectedTemplate() const
95 #else
96 const KAEvent* TemplatePickDlg::selectedTemplate() const
97 #endif
99 return mListView->selectedEvent();
102 /******************************************************************************
103 * Called when the template selection changes.
104 * Enable/disable the OK button depending on whether anything is selected.
106 void TemplatePickDlg::slotSelectionChanged()
108 bool enable = !mListView->selectionModel()->selectedRows().isEmpty();
109 if (enable)
110 enable = mListView->model()->flags(mListView->selectedIndex()) & Qt::ItemIsEnabled;
111 enableButtonOk(enable);
114 /******************************************************************************
115 * Called when the dialog's size has changed.
116 * Records the new size in the config file.
118 void TemplatePickDlg::resizeEvent(QResizeEvent* re)
120 if (isVisible())
121 KAlarm::writeConfigWindowSize(TMPL_PICK_DIALOG_NAME, re->size());
122 KDialog::resizeEvent(re);
125 // vim: et sw=4: