File indexing completed on 2024-04-14 04:51:52

0001 /**
0002  * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@kde.org>
0003  * SPDX-FileCopyrightText: 2018 Simon Redman <simon@ergotech.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006  */
0007 
0008 #ifndef CONVERSATIONLISTMODEL_H
0009 #define CONVERSATIONLISTMODEL_H
0010 
0011 #include <QStandardItemModel>
0012 
0013 #include "interfaces/conversationmessage.h"
0014 #include "interfaces/dbusinterfaces.h"
0015 
0016 class ConversationListModel : public QStandardItemModel
0017 {
0018     Q_OBJECT
0019     Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
0020 
0021 public:
0022     ConversationListModel(QObject *parent = nullptr);
0023     ~ConversationListModel() override;
0024 
0025     enum Roles {
0026         /* Roles which apply while working as a single message */
0027         FromMeRole = Qt::UserRole,
0028         SenderRole, // The sender of the message. Undefined if this is an outgoing message
0029         DateRole, // The date of this message
0030         /* Roles which apply while working as the head of a conversation */
0031         AddressesRole, // The Addresses involved in the conversation
0032         ConversationIdRole, // The ThreadID of the conversation
0033         MultitargetRole, // Indicate that this conversation is multitarget
0034         AttachmentPreview, // A thumbnail of the attachment of the message, if any
0035     };
0036     Q_ENUM(Roles)
0037 
0038     QString deviceId() const
0039     {
0040         return m_deviceId;
0041     }
0042     void setDeviceId(const QString & /*deviceId*/);
0043 
0044     Q_SCRIPTABLE void refresh();
0045 
0046     /**
0047      * This method creates conversation with an arbitrary address
0048      */
0049     Q_INVOKABLE void createConversationForAddress(const QString &address);
0050 
0051 public Q_SLOTS:
0052     void handleCreatedConversation(const QDBusVariant &msg);
0053     void handleConversationUpdated(const QDBusVariant &msg);
0054     void createRowFromMessage(const ConversationMessage &message);
0055     void printDBusError(const QDBusError &error);
0056     void displayContacts();
0057 
0058 Q_SIGNALS:
0059     void deviceIdChanged();
0060 
0061 private:
0062     /**
0063      * Get all conversations currently known by the conversationsInterface, if any
0064      */
0065     void prepareConversationsList();
0066 
0067     QStandardItem *conversationForThreadId(qint32 threadId);
0068     QStandardItem *getConversationForAddress(const QString &address);
0069 
0070     DeviceConversationsDbusInterface *m_conversationsInterface;
0071     QString m_deviceId;
0072 };
0073 
0074 #endif // CONVERSATIONLISTMODEL_H