File indexing completed on 2024-05-12 05:14:53

0001 /*
0002  *  newalarmaction.h  -  menu action to select a new alarm type
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2007-2021 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include "editdlg.h"
0012 
0013 #include <KActionMenu>
0014 #include <QMap>
0015 #include <QAction>
0016 
0017 namespace KAlarmCal { class KAEvent; }
0018 class KActionCollection;
0019 class TemplateMenuAction;
0020 
0021 class NewAlarmAction : public KActionMenu
0022 {
0023     Q_OBJECT
0024 public:
0025     /** Create a New Alarm action which provides a sub-menu containing each alarm type.
0026      *  @param templates   The sub-menu should provide actions to create an alarm
0027      *                     template of each type, not an alarm of each type.
0028      *  @param label       The action's label.
0029      *  @param parent      Parent widget.
0030      *  @param collection  Action collection. If supplied, each action must be
0031      *                     given a name within the collection using setActionNames().
0032      */
0033     NewAlarmAction(bool templates, const QString& label, QObject* parent, KActionCollection* collection = nullptr);
0034 
0035     ~NewAlarmAction() override {}
0036 
0037     /** If a KActionCollection was supplied to the constructor, add the actions
0038      *  to the collection, and configure to allow the user to set a global shortcut
0039      *  for the non-alarm template actions.
0040      *  @param displayName   Name of 'New display alarm' action within the KActionCollection.
0041      *  @param commandName   Name of 'New command alarm' action within the KActionCollection.
0042      *  @param emailName     Name of 'New email alarm' action within the KActionCollection.
0043      *  @param audioName     Name of 'New audio alarm' action within the KActionCollection.
0044      *  @param templateName  Name of 'New alarm from template' action within the KActionCollection.
0045      */
0046     void setActionNames(const QString& displayName, const QString& commandName,
0047                         const QString& emailName, const QString& audioName,
0048                         const QString& templateName = QString());
0049 
0050     /** Return the 'New display alarm' action. */
0051     QAction* displayAlarmAction() const  { return mDisplayAction; }
0052 
0053     /** Return the 'New command alarm' action. */
0054     QAction* commandAlarmAction() const  { return mCommandAction; }
0055 
0056     /** Return the 'New email alarm' action. */
0057     QAction* emailAlarmAction() const  { return mEmailAction; }
0058 
0059     /** Return the 'New audio alarm' action. */
0060     QAction* audioAlarmAction() const  { return mAudioAction; }
0061 
0062     /** Return the 'New alarm from template' action. */
0063     TemplateMenuAction* fromTemplateAlarmAction() const  { return mTemplateAction; }
0064 
0065 Q_SIGNALS:
0066     /** Signal emitted when a new alarm action is selected from the sub-menu. */
0067     void selected(EditAlarmDlg::Type);
0068 
0069     /** Signal emitted when a new alarm from template action is selected from
0070      *  the sub-menu. */
0071     void selectedTemplate(const KAlarmCal::KAEvent&);
0072 
0073 private Q_SLOTS:
0074     void   slotSelected(QAction*);
0075     void   slotInitMenu();
0076     void   slotCalendarStatusChanged();
0077 
0078 private:
0079     QAction*            mDisplayAction;
0080     QAction*            mCommandAction;
0081     QAction*            mEmailAction;
0082     QAction*            mAudioAction;
0083     TemplateMenuAction* mTemplateAction {nullptr};  // New From Template action, for non-template menu only
0084     KActionCollection*  mActionCollection;
0085     QMap<QAction*, EditAlarmDlg::Type> mTypes;
0086 };
0087 
0088 // vim: et sw=4: