File indexing completed on 2024-04-28 05:11:33

0001 /*
0002   SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
0003   SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0004 
0005   SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "incidenceeditor-ng.h"
0011 
0012 #include <KCalendarCore/FreeBusy>
0013 #include <KContacts/Addressee>
0014 namespace Ui
0015 {
0016 class EventOrTodoDesktop;
0017 }
0018 
0019 namespace KContacts
0020 {
0021 class Addressee;
0022 class ContactGroup;
0023 }
0024 
0025 class KJob;
0026 
0027 namespace IncidenceEditorNG
0028 {
0029 class AttendeeComboBoxDelegate;
0030 class AttendeeLineEditDelegate;
0031 class AttendeeTableModel;
0032 class ConflictResolver;
0033 class IncidenceDateTime;
0034 
0035 class IncidenceAttendee : public IncidenceEditor
0036 {
0037     Q_OBJECT
0038 public:
0039     using IncidenceEditorNG::IncidenceEditor::load; // So we don't trigger -Woverloaded-virtual
0040     using IncidenceEditorNG::IncidenceEditor::save; // So we don't trigger -Woverloaded-virtual
0041     explicit IncidenceAttendee(QWidget *parent, IncidenceDateTime *dateTime, Ui::EventOrTodoDesktop *ui);
0042     ~IncidenceAttendee() override;
0043 
0044     void load(const KCalendarCore::Incidence::Ptr &incidence) override;
0045     void save(const KCalendarCore::Incidence::Ptr &incidence) override;
0046     [[nodiscard]] bool isDirty() const override;
0047     void printDebugInfo() const override;
0048 
0049     AttendeeTableModel *dataModel() const;
0050     AttendeeComboBoxDelegate *stateDelegate() const;
0051     AttendeeComboBoxDelegate *roleDelegate() const;
0052     AttendeeComboBoxDelegate *responseDelegate() const;
0053     AttendeeLineEditDelegate *attendeeDelegate() const;
0054 
0055     [[nodiscard]] int attendeeCount() const;
0056 
0057 Q_SIGNALS:
0058     void attendeeCountChanged(int);
0059 
0060 public Q_SLOTS:
0061     /// If the user is attendee of the loaded event, one of the following slots
0062     /// can be used to change the status.
0063     void acceptForMe();
0064     void declineForMe();
0065 
0066 private Q_SLOTS:
0067     // checks if row is a group,  that can/should be expanded
0068     void checkIfExpansionIsNeeded(const KCalendarCore::Attendee &attendee);
0069 
0070     // results of the group search job
0071     void groupSearchResult(KJob *job);
0072     void expandResult(KJob *job);
0073     void slotSelectAddresses();
0074     void slotSolveConflictPressed();
0075     void slotUpdateConflictLabel(int);
0076     void slotOrganizerChanged(const QString &organizer);
0077     void slotGroupSubstitutionPressed();
0078 
0079     // wrapper for the conflict resolver
0080     void slotEventDurationChanged();
0081 
0082     void filterLayoutChanged();
0083     void updateCount();
0084 
0085     void slotConflictResolverAttendeeAdded(const QModelIndex &index, int first, int last);
0086     void slotConflictResolverAttendeeRemoved(const QModelIndex &index, int first, int last);
0087     void slotConflictResolverAttendeeChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0088     void slotConflictResolverLayoutChanged();
0089     void slotFreeBusyAdded(const QModelIndex &index, int first, int last);
0090     void slotFreeBusyChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0091     void updateFBStatus();
0092     void updateFBStatus(const KCalendarCore::Attendee &attendee, const KCalendarCore::FreeBusy::Ptr &fb);
0093 
0094     void slotGroupSubstitutionAttendeeAdded(const QModelIndex &index, int first, int last);
0095     void slotGroupSubstitutionAttendeeRemoved(const QModelIndex &index, int first, int last);
0096     void slotGroupSubstitutionAttendeeChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0097     void slotGroupSubstitutionLayoutChanged();
0098 
0099     void slotUpdateCryptoPreferences();
0100 
0101 private:
0102     void updateGroupExpand();
0103 
0104     void insertAddresses(const KContacts::Addressee::List &list);
0105 
0106     void changeStatusForMe(KCalendarCore::Attendee::PartStat);
0107 
0108     /** Returns if I was the organizer of the loaded event */
0109     bool iAmOrganizer() const;
0110 
0111     /** Reads values from a KContacts::Addressee and inserts a new Attendee
0112      * item into the listview with those items. Used when adding attendees
0113      * from the addressbook and expanding distribution lists.
0114      * The optional Attendee parameter can be used to pass in default values
0115      * to be used by the new Attendee.
0116      * pos =-1 means insert attendee before empty line
0117      */
0118     void insertAttendeeFromAddressee(const KContacts::Addressee &a, int pos = -1);
0119     void fillOrganizerCombo();
0120     void setActions(KCalendarCore::Incidence::IncidenceType actions);
0121 
0122     int rowOfAttendee(const QString &uid) const;
0123 
0124     Ui::EventOrTodoDesktop *mUi = nullptr;
0125     QWidget *mParentWidget = nullptr;
0126     ConflictResolver *mConflictResolver = nullptr;
0127 
0128     IncidenceDateTime *mDateTime = nullptr;
0129     QString mOrganizer;
0130 
0131     /** used dataModel to rely on*/
0132     AttendeeTableModel *mDataModel = nullptr;
0133     AttendeeLineEditDelegate *mAttendeeDelegate = nullptr;
0134     AttendeeComboBoxDelegate *const mStateDelegate;
0135     AttendeeComboBoxDelegate *mRoleDelegate = nullptr;
0136     AttendeeComboBoxDelegate *mResponseDelegate = nullptr;
0137 
0138     // the QString is Attendee::uid here
0139     QMap<QString, KContacts::ContactGroup> mGroupList;
0140     QMap<KJob *, QString> mMightBeGroupJobs;
0141     QMap<KJob *, QString> mExpandGroupJobs;
0142 };
0143 }