1 /*
2   This file is part of KOrganizer.
3 
4   SPDX-FileCopyrightText: 2000, 2001 Cornelius Schumacher <schumacher@kde.org>
5   SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
8 */
9 
10 #pragma once
11 
12 #include <QDate>
13 #include <QMenu>
14 
15 #include <Akonadi/Calendar/ETMCalendar>
16 #include <Akonadi/Item>
17 
18 /**
19  * Context menu with standard Incidence actions.
20  */
21 class KOEventPopupMenu : public QMenu
22 {
23     Q_OBJECT
24 public:
25     /**
26      * The different types of preset menus available.
27      */
28     enum MenuStyle {
29         NormalView = 0, /**< typical menu shown in most views. this is the default menu style */
30         MiniList = 1, /**< mini-menu with just the basic items, typical in lists */
31     };
32     Q_ENUM(MenuStyle)
33 
34     /**
35      * Create an Incidence menu instance with the NormalView style.
36      */
37     explicit KOEventPopupMenu(const Akonadi::ETMCalendar::Ptr &calendar, QWidget *parent = nullptr);
38 
39     /**
40      * Create an Incidence menu instance with a specified style.
41      */
42     KOEventPopupMenu(const Akonadi::ETMCalendar::Ptr &calendar, MenuStyle menuStyle, QWidget *parent = nullptr);
43 
44     /**
45      * Change the @p calendar used by the Incidence menu.
46      */
47     void setCalendar(const Akonadi::ETMCalendar::Ptr &calendar);
48 
49 public Q_SLOTS:
50     void showIncidencePopup(const Akonadi::Item &, const QDate &);
51     void createEvent(const Akonadi::Item &item);
52     void createNote(const Akonadi::Item &item);
53 
54 protected Q_SLOTS:
55     void popupShow();
56     void popupEdit();
57     void popupPaste();
58     void slotPrint();
59     void printPreview();
60     void popupDelete();
61     void popupCut();
62     void popupCopy();
63     void toggleAlarm();
64     void toggleTodoCompleted();
65     void dissociateOccurrences();
66     void forward();
67     void createTodo();
68     void createEvent();
69     void createNote();
70 
71     void slotCreateNote(const Akonadi::Item &noteItem, const Akonadi::Collection &collection);
72     void slotCreateNewNoteJobFinished(KJob *);
73 
74 Q_SIGNALS:
75     void configChanged();
76     void editIncidenceSignal(const Akonadi::Item &);
77     void showIncidenceSignal(const Akonadi::Item &);
78     void deleteIncidenceSignal(const Akonadi::Item &);
79     void cutIncidenceSignal(const Akonadi::Item &);
80     void copyIncidenceSignal(const Akonadi::Item &);
81     void pasteIncidenceSignal();
82     void toggleAlarmSignal(const Akonadi::Item &);
83     void toggleTodoCompletedSignal(const Akonadi::Item &);
84     void copyIncidenceToResourceSignal(const Akonadi::Item &, const Akonadi::Collection &);
85     void moveIncidenceToResourceSignal(const Akonadi::Item &, const Akonadi::Collection &);
86     void dissociateOccurrencesSignal(const Akonadi::Item &, const QDate &);
87 
88 private:
89     void init(const Akonadi::ETMCalendar::Ptr &calendar, MenuStyle menuStyle);
90     void appendEditOnlyItems();
91     void appendEventOnlyItems();
92     void appendTodoOnlyItems();
93     void appendReminderOnlyItems();
94     void appendRecurrenceOnlyItems();
95     void appendShareOnlyItems();
96 
97     void print(bool previous);
98 
99     Akonadi::ETMCalendar::Ptr mCalendar;
100     Akonadi::Item mCurrentIncidence;
101     QDate mCurrentDate;
102 
103     bool mHasAdditionalItems = false;
104     QList<QAction *> mEditOnlyItems;
105     QList<QAction *> mEventOnlyItems;
106     QList<QAction *> mTodoOnlyItems;
107     QList<QAction *> mReminderOnlyItems;
108     QList<QAction *> mRecurrenceOnlyItems;
109     QList<QAction *> mShareOnlyItems;
110     QAction *mToggleReminder = nullptr;
111     QAction *mDissociateOccurrences = nullptr;
112 };
113 
114