SVN_SILENT made messages (after extraction)
[kdepim.git] / kalarm / templatepickdlg.cpp
blob73db16b54360330fbcfe38aad83c1d63ac24a3d7
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.h"
24 #include "functions.h"
25 #include "shellprocess.h"
26 #include "templatelistview.h"
28 #include <KLocalizedString>
29 #include <KConfigGroup>
31 #include <QVBoxLayout>
32 #include <QResizeEvent>
33 #include <QDialogButtonBox>
34 #include <QPushButton>
35 #include "kalarm_debug.h"
37 static const char TMPL_PICK_DIALOG_NAME[] = "TemplatePickDialog";
40 TemplatePickDlg::TemplatePickDlg(KAEvent::Actions type, QWidget* parent)
41 : QDialog(parent)
43 QWidget* topWidget = new QWidget(this);
44 QVBoxLayout* mainLayout = new QVBoxLayout;
45 setLayout(mainLayout);
46 mainLayout->addWidget(topWidget);
47 setWindowTitle(i18nc("@title:window", "Choose Alarm Template"));
48 QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
49 mainLayout->addWidget(buttonBox);
50 mOkButton = buttonBox->button(QDialogButtonBox::Ok);
51 mOkButton->setDefault(true);
52 mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
53 connect(buttonBox, &QDialogButtonBox::accepted, this, &TemplatePickDlg::accept);
54 connect(buttonBox, &QDialogButtonBox::rejected, this, &TemplatePickDlg::reject);
55 QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
56 topLayout->setMargin(0);
58 // Display the list of templates, but exclude command alarms if in kiosk mode.
59 KAEvent::Actions shown = KAEvent::ACT_ALL;
60 if (!ShellProcess::authorised())
62 type = static_cast<KAEvent::Actions>(type & ~KAEvent::ACT_COMMAND);
63 shown = static_cast<KAEvent::Actions>(shown & ~KAEvent::ACT_COMMAND);
65 mListFilterModel = new TemplateListModel(this);
66 mListFilterModel->setAlarmActionsEnabled(type);
67 mListFilterModel->setAlarmActionFilter(shown);
68 mListView = new TemplateListView(topWidget);
69 mainLayout->addWidget(mListView);
70 mListView->setModel(mListFilterModel);
71 mListView->sortByColumn(TemplateListModel::TemplateNameColumn, Qt::AscendingOrder);
72 mListView->setSelectionMode(QAbstractItemView::SingleSelection);
73 mListView->setWhatsThis(i18nc("@info:whatsthis", "Select a template to base the new alarm on."));
74 connect(mListView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TemplatePickDlg::slotSelectionChanged);
75 // Require a real double click (even if KDE is in single-click mode) to accept the selection
76 connect(mListView, &TemplateListView::doubleClicked, this, &TemplatePickDlg::accept);
77 topLayout->addWidget(mListView);
79 slotSelectionChanged(); // enable or disable the OK button
81 QSize s;
82 if (KAlarm::readConfigWindowSize(TMPL_PICK_DIALOG_NAME, s))
83 resize(s);
86 /******************************************************************************
87 * Return the currently selected alarm template, or 0 if none.
89 KAEvent TemplatePickDlg::selectedTemplate() const
91 return mListView->selectedEvent();
94 /******************************************************************************
95 * Called when the template selection changes.
96 * Enable/disable the OK button depending on whether anything is selected.
98 void TemplatePickDlg::slotSelectionChanged()
100 bool enable = !mListView->selectionModel()->selectedRows().isEmpty();
101 if (enable)
102 enable = mListView->model()->flags(mListView->selectedIndex()) & Qt::ItemIsEnabled;
103 mOkButton->setEnabled(enable);
106 /******************************************************************************
107 * Called when the dialog's size has changed.
108 * Records the new size in the config file.
110 void TemplatePickDlg::resizeEvent(QResizeEvent* re)
112 if (isVisible())
113 KAlarm::writeConfigWindowSize(TMPL_PICK_DIALOG_NAME, re->size());
114 QDialog::resizeEvent(re);
118 // vim: et sw=4: