french -> French
[kdepim.git] / kalarm / templatemenuaction.cpp
blob1d1a99596799e3acc444c21bc91a7320cc6f7d90
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 <kmenu.h>
30 #include <kactionmenu.h>
31 #include <kdebug.h>
34 TemplateMenuAction::TemplateMenuAction(const KIcon& icon, const QString& label, QObject* parent)
35 : KActionMenu(icon, label, parent)
37 setDelayed(false);
38 connect(menu(), SIGNAL(aboutToShow()), SLOT(slotInitMenu()));
39 connect(menu(), SIGNAL(triggered(QAction*)), SLOT(slotSelected(QAction*)));
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 KMenu* 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 emit selected(templ);
86 #include "moc_templatemenuaction.cpp"
87 // vim: et sw=4: