File indexing completed on 2024-06-23 05:18:36

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     Refactored from earlier code by:
0006     SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org>
0007     SPDX-FileCopyrightText: 2004 Cornelius Schumacher <schumacher@kde.org>
0008 
0009     SPDX-License-Identifier: LGPL-2.0-or-later
0010 */
0011 #pragma once
0012 
0013 #include "messagecomposer_export.h"
0014 
0015 #include "recipientline.h"
0016 
0017 #include <Libkdepim/MultiplyingLineEditor>
0018 
0019 namespace KMime
0020 {
0021 namespace Types
0022 {
0023 class Mailbox;
0024 }
0025 }
0026 namespace MessageComposer
0027 {
0028 /**
0029  * @brief The RecipientLineFactory class
0030  */
0031 class MESSAGECOMPOSER_EXPORT RecipientLineFactory : public KPIM::MultiplyingLineFactory
0032 {
0033     Q_OBJECT
0034 public:
0035     explicit RecipientLineFactory(QObject *parent);
0036     KPIM::MultiplyingLine *newLine(QWidget *parent) override;
0037     int maximumRecipients() override;
0038 };
0039 
0040 class RecipientsPicker;
0041 class RecipientsEditorPrivate;
0042 /**
0043  * @brief The RecipientsEditor class
0044  */
0045 class MESSAGECOMPOSER_EXPORT RecipientsEditor : public KPIM::MultiplyingLineEditor
0046 {
0047     Q_OBJECT
0048 public:
0049     explicit RecipientsEditor(QWidget *parent = nullptr);
0050     explicit RecipientsEditor(RecipientLineFactory *lineFactory, QWidget *parent = nullptr);
0051     ~RecipientsEditor() override;
0052 
0053     [[nodiscard]] Recipient::List recipients() const;
0054     [[nodiscard]] QSharedPointer<Recipient> activeRecipient() const;
0055 
0056     [[nodiscard]] MessageComposer::RecipientsPicker *picker() const;
0057 
0058     bool setRecipientString(const QList<KMime::Types::Mailbox> &mailboxes, Recipient::Type);
0059     [[nodiscard]] QString recipientString(Recipient::Type) const;
0060     [[nodiscard]] QStringList recipientStringList(Recipient::Type) const;
0061 
0062     /** Adds a recipient (or multiple recipients) to one line of the editor.
0063         @param recipient The recipient(s) you want to add.
0064         @param type      The recipient type.
0065     */
0066     bool addRecipient(const QString &recipient, Recipient::Type type);
0067 
0068     /** Removes the recipient provided it can be found and has the given type.
0069         @param recipient The recipient(s) you want to remove.
0070         @param type      The recipient type.
0071     */
0072     void removeRecipient(const QString &recipient, Recipient::Type type);
0073 
0074     /**
0075      * Sets the config file used for storing recent addresses.
0076      */
0077     void setRecentAddressConfig(KConfig *config);
0078 
0079 public Q_SLOTS:
0080     void selectRecipients();
0081     void saveDistributionList();
0082 
0083 protected Q_SLOTS:
0084     void slotPickedRecipient(const Recipient &, bool &tooManyAddress);
0085     void slotLineAdded(KPIM::MultiplyingLine *);
0086     void slotLineDeleted(int pos);
0087     void slotCalculateTotal();
0088     void addRecipient(RecipientLineNG *, const QString &);
0089 
0090 protected:
0091     bool eventFilter(QObject *object, QEvent *event) override;
0092     [[nodiscard]] RecipientLineNG *activeLine() const override;
0093 
0094 Q_SIGNALS:
0095     void focusInRecipientLineEdit();
0096 
0097 private:
0098     std::unique_ptr<RecipientsEditorPrivate> const d;
0099 };
0100 }