kalarm
templatemenuaction.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kalarm.h"
00022
00023 #include <kactionclasses.h>
00024 #include <kpopupmenu.h>
00025 #include <kdebug.h>
00026
00027 #include "alarmcalendar.h"
00028 #include "alarmevent.h"
00029 #include "functions.h"
00030 #include "templatemenuaction.moc"
00031
00032
00033 TemplateMenuAction::TemplateMenuAction(const QString& label, const QString& icon, QObject* receiver,
00034 const char* slot, KActionCollection* actions, const char* name)
00035 : KActionMenu(label, icon, actions, name)
00036 {
00037 setDelayed(false);
00038 connect(popupMenu(), SIGNAL(aboutToShow()), SLOT(slotInitMenu()));
00039 connect(popupMenu(), SIGNAL(activated(int)), SLOT(slotSelected(int)));
00040 connect(this, SIGNAL(selected(const KAEvent&)), receiver, slot);
00041 }
00042
00043
00044
00045
00046
00047 void TemplateMenuAction::slotInitMenu()
00048 {
00049 KPopupMenu* menu = popupMenu();
00050 menu->clear();
00051 mOriginalTexts.clear();
00052 QValueList<KAEvent> templates = KAlarm::templateList();
00053 for (QValueList<KAEvent>::Iterator it = templates.begin(); it != templates.end(); ++it)
00054 {
00055 QString name = (*it).templateName();
00056 menu->insertItem(name);
00057 mOriginalTexts += name;
00058 }
00059 }
00060
00061
00062
00063
00064
00065 void TemplateMenuAction::slotSelected(int id)
00066 {
00067 KPopupMenu* menu = popupMenu();
00068 QString item = mOriginalTexts[menu->indexOf(id)];
00069 if (!item.isEmpty())
00070 {
00071 AlarmCalendar* cal = AlarmCalendar::templateCalendarOpen();
00072 if (cal)
00073 {
00074 KAEvent templ = KAEvent::findTemplateName(*cal, item);
00075 emit selected(templ);
00076 }
00077 }
00078 }
|