File indexing completed on 2024-11-24 04:50:42

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #pragma once
0005 
0006 #include <KContacts/Addressee>
0007 #include <QAbstractListModel>
0008 #include <kcontacts/addressee.h>
0009 
0010 class EmailModel : public QAbstractListModel
0011 {
0012     Q_OBJECT
0013 
0014 public:
0015     enum ExtraRole {
0016         TypeRole = Qt::UserRole + 1,
0017         TypeValueRole,
0018         DefaultRole,
0019         EmailRole,
0020     };
0021     enum Type { Unknown = 0, Home = 1, Work = 2, Other = 4 };
0022     Q_ENUM(Type)
0023 
0024     EmailModel(QObject *parent = nullptr);
0025 
0026     int rowCount(const QModelIndex &parent = {}) const override;
0027     QVariant data(const QModelIndex &idx, int role) const override;
0028     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0029     QHash<int, QByteArray> roleNames() const override;
0030 
0031     void loadContact(const KContacts::Addressee &contact);
0032     void storeContact(KContacts::Addressee &contact) const;
0033 
0034     Q_INVOKABLE void addEmail(const QString &email, EmailModel::Type type);
0035     Q_INVOKABLE void deleteEmail(int row);
0036 
0037 Q_SIGNALS:
0038     void changed(const KContacts::Email::List &emails);
0039 
0040 private:
0041     KContacts::Email::List m_emails;
0042 };