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 0009 class PhoneModel : public QAbstractListModel 0010 { 0011 Q_OBJECT 0012 0013 public: 0014 enum ExtraRole { 0015 TypeRole = Qt::UserRole + 1, 0016 TypeValueRole, 0017 DefaultRole, 0018 SupportSmsRole, 0019 PhoneNumberRole, 0020 }; 0021 0022 enum Type { 0023 Home = 1, /**< Home number */ 0024 Work = 2, /**< Office number */ 0025 Msg = 4, /**< Messaging */ 0026 Pref = 8, /**< Preferred number */ 0027 Voice = 16, /**< Voice */ 0028 Fax = 32, /**< Fax machine */ 0029 Cell = 64, /**< Cell phone */ 0030 Video = 128, /**< Video phone */ 0031 Bbs = 256, /**< Mailbox */ 0032 Modem = 512, /**< Modem */ 0033 Car = 1024, /**< Car phone */ 0034 Isdn = 2048, /**< ISDN connection */ 0035 Pcs = 4096, /**< Personal Communication Service*/ 0036 Pager = 8192, /**< Pager */ 0037 // TODO add Text and textphone support vcard4 0038 Undefined = 16384, /**< Undefined number type */ 0039 }; 0040 Q_ENUM(Type) 0041 0042 PhoneModel(QObject *parent = nullptr); 0043 0044 int rowCount(const QModelIndex &parent = {}) const override; 0045 QVariant data(const QModelIndex &idx, int role) const override; 0046 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0047 QHash<int, QByteArray> roleNames() const override; 0048 0049 void loadContact(const KContacts::Addressee &contact); 0050 void storeContact(KContacts::Addressee &contact) const; 0051 0052 Q_INVOKABLE void addPhoneNumber(const QString &phoneNumber, PhoneModel::Type type); 0053 Q_INVOKABLE void deletePhoneNumber(int row); 0054 0055 Q_SIGNALS: 0056 void changed(const KContacts::PhoneNumber::List &phoneNumbers); 0057 0058 private: 0059 KContacts::PhoneNumber::List m_phoneNumbers; 0060 };