SVN_SILENT made messages (.desktop file) - always resolve ours
[kdepim.git] / kalarm / templatemenuaction.cpp
blobfcf8e89efe34619705fa7697a22ce85a4c498626
1 /*
2 * templatemenuaction.cpp - menu action to select a template
3 * Program: kalarm
4 * Copyright © 2005,2006,2008,2011 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"
23 #include "alarmcalendar.h"
24 #include "functions.h"
25 #include "templatemenuaction.h"
27 #include <kalarmcal/kaevent.h>
29 #include <kactionmenu.h>
30 #include <QMenu>
31 #include "kalarm_debug.h"
34 TemplateMenuAction::TemplateMenuAction(const QIcon& icon, const QString& label, QObject* parent)
35 : KActionMenu(icon, label, parent)
37 setDelayed(false);
38 connect(menu(), &QMenu::aboutToShow, this, &TemplateMenuAction::slotInitMenu);
39 connect(menu(), &QMenu::triggered, this, &TemplateMenuAction::slotSelected);
42 /******************************************************************************
43 * Called when the New From Template action is clicked.
44 * Creates a popup menu listing all alarm templates, in sorted name order.
46 void TemplateMenuAction::slotInitMenu()
48 QMenu* m = menu();
49 m->clear();
50 mOriginalTexts.clear();
52 // Compile a sorted list of template names
53 int i, end;
54 QStringList sorted;
55 KAEvent::List templates = KAlarm::templateList();
56 for (i = 0, end = templates.count(); i < end; ++i)
58 QString name = templates[i]->templateName();
59 int j = 0;
60 for (int jend = sorted.count();
61 j < jend && QString::localeAwareCompare(name, sorted[j]) > 0;
62 ++j) ;
63 sorted.insert(j, name);
66 for (i = 0, end = sorted.count(); i < end; ++i)
68 QAction* act = m->addAction(sorted[i]);
69 mOriginalTexts[act] = sorted[i]; // keep original text, since action text has shortcuts added
73 /******************************************************************************
74 * Called when a template is selected from the New From Template popup menu.
75 * Executes a New Alarm dialog, preset from the selected template.
77 void TemplateMenuAction::slotSelected(QAction* action)
79 QMap<QAction*, QString>::ConstIterator it = mOriginalTexts.constFind(action);
80 if (it == mOriginalTexts.constEnd() || it.value().isEmpty())
81 return;
82 KAEvent* templ = AlarmCalendar::resources()->templateEvent(it.value());
83 Q_EMIT selected(templ);
87 // vim: et sw=4: