• 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
newalarmaction.cpp
Go to the documentation of this file.
1 /*
2  * newalarmaction.cpp - menu action to select a new alarm type
3  * Program: kalarm
4  * Copyright © 2007-2009,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 #include "newalarmaction.h"
23 
24 #ifdef USE_AKONADI
25 #include "akonadimodel.h"
26 #include "collectionmodel.h"
27 #include "itemlistmodel.h"
28 #else
29 #include "alarmresources.h"
30 #include "eventlistmodel.h"
31 #endif
32 #include "functions.h"
33 #include "shellprocess.h"
34 #include "templatemenuaction.h"
35 
36 #include <kmenu.h>
37 #include <kactionmenu.h>
38 #include <klocale.h>
39 #include <kstandardshortcut.h>
40 #include <kdebug.h>
41 
42 using namespace KAlarmCal;
43 
44 #define DISP_ICON QLatin1String("window-new")
45 #define CMD_ICON QLatin1String("new-command-alarm")
46 #define MAIL_ICON QLatin1String("mail-message-new")
47 #define AUDIO_ICON QLatin1String("new-audio-alarm")
48 #define TEMPLATE_ICON QLatin1String("document-new-from-template")
49 #define DISP_KEY QKeySequence(Qt::CTRL + Qt::Key_D)
50 #define CMD_KEY QKeySequence(Qt::CTRL + Qt::Key_C)
51 #define MAIL_KEY QKeySequence(Qt::CTRL + Qt::Key_M)
52 #define AUDIO_KEY QKeySequence(Qt::CTRL + Qt::Key_U)
53 
54 
55 NewAlarmAction::NewAlarmAction(bool templates, const QString& label, QObject* parent)
56  : KActionMenu(KIcon(QLatin1String("document-new")), label, parent),
57  mTemplateAction(0)
58 {
59  mDisplayAction = new KAction(KIcon(DISP_ICON), (templates ? i18nc("@item:inmenu", "&Display Alarm Template") : i18nc("@action", "New Display Alarm")), parent);
60  menu()->addAction(mDisplayAction);
61  mTypes[mDisplayAction] = EditAlarmDlg::DISPLAY;
62  mCommandAction = new KAction(KIcon(CMD_ICON), (templates ? i18nc("@item:inmenu", "&Command Alarm Template") : i18nc("@action", "New Command Alarm")), parent);
63  menu()->addAction(mCommandAction);
64  mTypes[mCommandAction] = EditAlarmDlg::COMMAND;
65  mEmailAction = new KAction(KIcon(MAIL_ICON), (templates ? i18nc("@item:inmenu", "&Email Alarm Template") : i18nc("@action", "New Email Alarm")), parent);
66  menu()->addAction(mEmailAction);
67  mTypes[mEmailAction] = EditAlarmDlg::EMAIL;
68  mAudioAction = new KAction(KIcon(AUDIO_ICON), (templates ? i18nc("@item:inmenu", "&Audio Alarm Template") : i18nc("@action", "New Audio Alarm")), parent);
69  menu()->addAction(mAudioAction);
70  mTypes[mAudioAction] = EditAlarmDlg::AUDIO;
71  if (!templates)
72  {
73  mDisplayAction->setShortcut(DISP_KEY);
74  mCommandAction->setShortcut(CMD_KEY);
75  mEmailAction->setShortcut(MAIL_KEY);
76  mAudioAction->setShortcut(AUDIO_KEY);
77 
78  // Include New From Template only in non-template menu
79  mTemplateAction = new TemplateMenuAction(KIcon(TEMPLATE_ICON), i18nc("@action", "New Alarm From &Template"), parent);
80  menu()->addAction(mTemplateAction);
81 #ifdef USE_AKONADI
82  connect(AkonadiModel::instance(), SIGNAL(collectionStatusChanged(Akonadi::Collection,AkonadiModel::Change,QVariant,bool)), SLOT(slotCalendarStatusChanged()));
83  connect(TemplateListModel::all(), SIGNAL(haveEventsStatus(bool)), SLOT(slotCalendarStatusChanged()));
84 #else
85  connect(AlarmResources::instance(), SIGNAL(resourceStatusChanged(AlarmResource*,AlarmResources::Change)), SLOT(slotCalendarStatusChanged()));
86  connect(EventListModel::templates(), SIGNAL(haveEventsStatus(bool)), SLOT(slotCalendarStatusChanged()));
87 #endif
88  slotCalendarStatusChanged(); // initialise action states
89  }
90  setDelayed(false);
91  connect(menu(), SIGNAL(aboutToShow()), SLOT(slotInitMenu()));
92  connect(menu(), SIGNAL(triggered(QAction*)), SLOT(slotSelected(QAction*)));
93 }
94 
95 /******************************************************************************
96 * Called when the action is clicked.
97 */
98 void NewAlarmAction::slotInitMenu()
99 {
100  // Don't allow shell commands in kiosk mode
101  mCommandAction->setEnabled(ShellProcess::authorised());
102 }
103 
104 /******************************************************************************
105 * Called when an alarm type is selected from the New popup menu.
106 */
107 void NewAlarmAction::slotSelected(QAction* action)
108 {
109  QMap<QAction*, EditAlarmDlg::Type>::ConstIterator it = mTypes.constFind(action);
110  if (it != mTypes.constEnd())
111  emit selected(it.value());
112 }
113 
114 /******************************************************************************
115 * Called when the status of a calendar has changed.
116 * Enable or disable the New From Template action appropriately.
117 */
118 void NewAlarmAction::slotCalendarStatusChanged()
119 {
120  // Find whether there are any writable active alarm calendars
121 #ifdef USE_AKONADI
122  bool active = !CollectionControlModel::enabledCollections(CalEvent::ACTIVE, true).isEmpty();
123  bool haveEvents = TemplateListModel::all()->haveEvents();
124 #else
125  bool active = AlarmResources::instance()->activeCount(CalEvent::ACTIVE, true);
126  bool haveEvents = EventListModel::templates()->haveEvents();
127 #endif
128  mTemplateAction->setEnabled(active && haveEvents);
129  setEnabled(active);
130 }
131 #include "moc_newalarmaction.cpp"
132 // vim: et sw=4:
NewAlarmAction::NewAlarmAction
NewAlarmAction(bool templates, const QString &label, QObject *parent)
Definition: newalarmaction.cpp:55
MAIL_KEY
#define MAIL_KEY
Definition: newalarmaction.cpp:51
EditAlarmDlg::EMAIL
Definition: editdlg.h:64
EditAlarmDlg::DISPLAY
Definition: editdlg.h:64
EditAlarmDlg::COMMAND
Definition: editdlg.h:64
DISP_ICON
#define DISP_ICON
Definition: newalarmaction.cpp:44
newalarmaction.h
QMap
ShellProcess::authorised
static bool authorised()
MAIL_ICON
#define MAIL_ICON
Definition: newalarmaction.cpp:46
QMap::constFind
const_iterator constFind(const Key &key) const
CMD_KEY
#define CMD_KEY
Definition: newalarmaction.cpp:50
akonadimodel.h
CMD_ICON
#define CMD_ICON
Definition: newalarmaction.cpp:45
AUDIO_KEY
#define AUDIO_KEY
Definition: newalarmaction.cpp:52
NewAlarmAction::selected
void selected(EditAlarmDlg::Type)
DISP_KEY
#define DISP_KEY
Definition: newalarmaction.cpp:49
QObject
itemlistmodel.h
AkonadiModel::instance
static AkonadiModel * instance()
Definition: akonadimodel.cpp:83
QMap::constEnd
const_iterator constEnd() const
eventlistmodel.h
AkonadiModel::Change
Change
Definition: akonadimodel.h:50
QString
TemplateMenuAction
Definition: templatemenuaction.h:29
AUDIO_ICON
#define AUDIO_ICON
Definition: newalarmaction.cpp:47
CollectionControlModel::enabledCollections
static Akonadi::Collection::List enabledCollections(CalEvent::Type, bool writable)
Return the enabled collections which contain a specified mime type.
Definition: collectionmodel.cpp:1229
EventListModel::templates
static EventListModel * templates()
Definition: eventlistmodel.cpp:68
templatemenuaction.h
collectionmodel.h
KActionMenu
QLatin1String
functions.h
miscellaneous functions
kalarm.h
QAction
TemplateListModel::all
static TemplateListModel * all()
Return the model containing all alarm templates.
Definition: itemlistmodel.cpp:276
EventListModel::haveEvents
bool haveEvents() const
Definition: eventlistmodel.h:81
ItemListModel::haveEvents
bool haveEvents() const
Determine whether the model contains any items.
Definition: itemlistmodel.cpp:179
shellprocess.h
EditAlarmDlg::AUDIO
Definition: editdlg.h:64
TEMPLATE_ICON
#define TEMPLATE_ICON
Definition: newalarmaction.cpp:48
QMap::value
const T value(const Key &key) const
QVariant
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