kalarm

templatemenuaction.cpp

00001 /*
00002  *  templatemenuaction.cpp  -  menu action to select a template
00003  *  Program:  kalarm
00004  *  Copyright (C) 2005 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 *  Called when the New From Template action is clicked.
00045 *  Creates a popup menu listing all alarm templates.
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 *  Called when a template is selected from the New From Template popup menu.
00063 *  Executes a New Alarm dialog, preset from the selected template.
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys