kalarm

templatemenuaction.cpp
1 /*
2  * templatemenuaction.cpp - menu action to select a template
3  * Program: kalarm
4  * Copyright © 2005,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 <tdeactionclasses.h>
24 #include <tdepopupmenu.h>
25 #include <kdebug.h>
26 
27 #include "alarmcalendar.h"
28 #include "alarmevent.h"
29 #include "functions.h"
30 #include "templatemenuaction.moc"
31 
32 
33 TemplateMenuAction::TemplateMenuAction(const TQString& label, const TQString& icon, TQObject* receiver,
34  const char* slot, TDEActionCollection* actions, const char* name)
35  : TDEActionMenu(label, icon, actions, name)
36 {
37  setDelayed(false);
38  connect(popupMenu(), TQ_SIGNAL(aboutToShow()), TQ_SLOT(slotInitMenu()));
39  connect(popupMenu(), TQ_SIGNAL(activated(int)), TQ_SLOT(slotSelected(int)));
40  connect(this, TQ_SIGNAL(selected(const KAEvent&)), receiver, slot);
41 }
42 
43 /******************************************************************************
44 * Called when the New From Template action is clicked.
45 * Creates a popup menu listing all alarm templates, in sorted name order.
46 */
47 void TemplateMenuAction::slotInitMenu()
48 {
49  TDEPopupMenu* menu = popupMenu();
50  menu->clear();
51  mOriginalTexts.clear();
52  TQValueList<KAEvent> templates = KAlarm::templateList();
53  for (TQValueList<KAEvent>::ConstIterator it = templates.constBegin(); it != templates.constEnd(); ++it)
54  {
55  TQString name = (*it).templateName();
56  // Insert the template in sorted order
57  TQStringList::Iterator tit;
58  for (tit = mOriginalTexts.begin();
59  tit != mOriginalTexts.end() && TQString::localeAwareCompare(name, *tit) > 0;
60  ++tit);
61  mOriginalTexts.insert(tit, name);
62  }
63  for (TQStringList::ConstIterator tit = mOriginalTexts.constBegin(); tit != mOriginalTexts.constEnd(); ++tit)
64  menu->insertItem(*tit);
65 }
66 
67 /******************************************************************************
68 * Called when a template is selected from the New From Template popup menu.
69 * Executes a New Alarm dialog, preset from the selected template.
70 */
71 void TemplateMenuAction::slotSelected(int id)
72 {
73  TDEPopupMenu* menu = popupMenu();
74  TQString item = mOriginalTexts[menu->indexOf(id)];
75  if (!item.isEmpty())
76  {
77  AlarmCalendar* cal = AlarmCalendar::templateCalendarOpen();
78  if (cal)
79  {
80  KAEvent templ = KAEvent::findTemplateName(*cal, item);
81  emit selected(templ);
82  }
83  }
84 }
represents calendar alarms and events
Provides read and write access to calendar files.
Definition: alarmcalendar.h:37
KAEvent corresponds to a KCal::Event instance.
Definition: alarmevent.h:232
miscellaneous functions