• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
templatemenuaction.cpp
Go to the documentation of this file.
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>
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 "alarmcalendar.h"
24 #include "functions.h"
25 #include "templatemenuaction.h"
26 
27 #include <kalarmcal/kaevent.h>
28 
29 #include <kmenu.h>
30 #include <kactionmenu.h>
31 #include <kdebug.h>
32 
33 
34 TemplateMenuAction::TemplateMenuAction(const KIcon& icon, const QString& label, QObject* parent)
35  : KActionMenu(icon, label, parent)
36 {
37  setDelayed(false);
38  connect(menu(), SIGNAL(aboutToShow()), SLOT(slotInitMenu()));
39  connect(menu(), SIGNAL(triggered(QAction*)), SLOT(slotSelected(QAction*)));
40 }
41 
42 /******************************************************************************
43 * Called when the New From Template action is clicked.
44 * Creates a popup menu listing all alarm templates, in sorted name order.
45 */
46 void TemplateMenuAction::slotInitMenu()
47 {
48  KMenu* m = menu();
49  m->clear();
50  mOriginalTexts.clear();
51 
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)
57  {
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);
64  }
65 
66  for (i = 0, end = sorted.count(); i < end; ++i)
67  {
68  QAction* act = m->addAction(sorted[i]);
69  mOriginalTexts[act] = sorted[i]; // keep original text, since action text has shortcuts added
70  }
71 }
72 
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.
76 */
77 void TemplateMenuAction::slotSelected(QAction* action)
78 {
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);
84 }
85 
86 #include "moc_templatemenuaction.cpp"
87 // vim: et sw=4:
AlarmCalendar::resources
static AlarmCalendar * resources()
Definition: alarmcalendar.h:130
QMap
QMap::constFind
const_iterator constFind(const Key &key) const
alarmcalendar.h
QMap::clear
void clear()
AlarmCalendar::templateEvent
KAEvent * templateEvent(const QString &templateName)
Definition: alarmcalendar.cpp:1868
QList::count
int count(const T &value) const
QObject
QMap::constEnd
const_iterator constEnd() const
QString
QStringList
templatemenuaction.h
TemplateMenuAction::selected
void selected(const KAEvent *)
KActionMenu
functions.h
miscellaneous functions
QList::insert
void insert(int i, const T &value)
kalarm.h
QAction
TemplateMenuAction::TemplateMenuAction
TemplateMenuAction(const KIcon &icon, const QString &label, QObject *parent)
Definition: templatemenuaction.cpp:34
QMap::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal