diff --git a/tests/src/app/App.cpp b/tests/src/app/App.cpp index e3398d3df..a060892aa 100644 --- a/tests/src/app/App.cpp +++ b/tests/src/app/App.cpp @@ -5,8 +5,11 @@ #include #include "../components/chat/ChatModel.hpp" +#include "../components/contacts/ContactModel.hpp" +#include "../components/contacts/ContactsListModel.hpp" #include "../components/contacts/ContactsListProxyModel.hpp" #include "../components/core/CoreManager.hpp" +#include "../components/notifier/Notifier.hpp" #include "../components/settings/AccountSettingsModel.hpp" #include "../components/timeline/TimelineModel.hpp" diff --git a/tests/src/app/App.hpp b/tests/src/app/App.hpp index efe5457e6..eb8236dac 100644 --- a/tests/src/app/App.hpp +++ b/tests/src/app/App.hpp @@ -7,7 +7,7 @@ #include #include -#include "../components/notifier/Notifier.hpp" +class Notifier; // =================================================================== diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp index 6699e670e..e86a0ff5c 100644 --- a/tests/src/components/chat/ChatModel.cpp +++ b/tests/src/components/chat/ChatModel.cpp @@ -1,7 +1,38 @@ +#include "../../utils.hpp" + #include "ChatModel.hpp" // =================================================================== -ChatModel::ChatModel (QObject *parent) : QObject(parent) { - +QHash ChatModel::roleNames () const { + QHash roles; + roles[Qt::DisplayRole] = "$chatEntry"; + return roles; +} + +QVariant ChatModel::data (const QModelIndex &index, int role) const { + int row = index.row(); + + if (row < 0 || row >= m_entries.count()) + return QVariant(); + + if (role == Qt::DisplayRole) + return QVariant::fromValue(m_entries[row]); + + return QVariant(); +} + +// ------------------------------------------------------------------- + +QString ChatModel::getSipAddress () const { + if (!m_chat_room) + return ""; + + return Utils::linphoneStringToQString( + m_chat_room->getPeerAddress()->asString() + ); +} + +void ChatModel::setSipAddress (const QString &sip_address) { + emit sipAddressChanged(sip_address); } diff --git a/tests/src/components/chat/ChatModel.hpp b/tests/src/components/chat/ChatModel.hpp index 411a28f51..de5e9e7b1 100644 --- a/tests/src/components/chat/ChatModel.hpp +++ b/tests/src/components/chat/ChatModel.hpp @@ -1,35 +1,40 @@ #ifndef CHAT_MODEL_H_ #define CHAT_MODEL_H_ -#include +#include +#include // =================================================================== -class ChatModel : public QObject { +class ChatModel : public QAbstractListModel { Q_OBJECT; Q_PROPERTY( - QString remoteSipAddress - READ getRemoteSipAddress - WRITE setRemoteSipAddress - NOTIFY remoteSipAddressChanged + QString sipAddress + READ getSipAddress + WRITE setSipAddress + NOTIFY sipAddressChanged ); public: - ChatModel (QObject *parent = Q_NULLPTR); + ChatModel (QObject *parent = Q_NULLPTR) : QAbstractListModel(parent) {} + + int rowCount (const QModelIndex &index = QModelIndex()) const { + return m_entries.count(); + } + + QHash roleNames () const; + QVariant data (const QModelIndex &index, int role) const; signals: - void remoteSipAddressChanged (QString remote_sip_address); + void sipAddressChanged (const QString &sipAddress); private: - QString getRemoteSipAddress () const { - return m_remote_sip_address; - } - void setRemoteSipAddress (QString &remote_sip_address) { - m_remote_sip_address = remote_sip_address; - } + QString getSipAddress () const; + void setSipAddress (const QString &sip_address); - QString m_remote_sip_address; + QList m_entries; + std::shared_ptr m_chat_room; }; #endif // CHAT_MODEL_H_ diff --git a/tests/src/components/contacts/ContactModel.cpp b/tests/src/components/contacts/ContactModel.cpp index 107dbd395..44a5409b0 100644 --- a/tests/src/components/contacts/ContactModel.cpp +++ b/tests/src/components/contacts/ContactModel.cpp @@ -1,3 +1,5 @@ +#include "../../utils.hpp" + #include "ContactModel.hpp" // =================================================================== @@ -9,3 +11,15 @@ Presence::PresenceStatus ContactModel::getPresenceStatus () const { Presence::PresenceLevel ContactModel::getPresenceLevel () const { return Presence::getPresenceLevel(m_presence_status); } + +QString ContactModel::getUsername () const { + return Utils::linphoneStringToQString( + m_linphone_friend->getName() + ); +} + +QString ContactModel::getSipAddress () const { + return Utils::linphoneStringToQString( + m_linphone_friend->getAddress()->asString() + ); +} diff --git a/tests/src/components/contacts/ContactModel.hpp b/tests/src/components/contacts/ContactModel.hpp index f51e09b09..1e3ad1af6 100644 --- a/tests/src/components/contacts/ContactModel.hpp +++ b/tests/src/components/contacts/ContactModel.hpp @@ -4,7 +4,6 @@ #include #include -#include "../../utils.hpp" #include "../presence/Presence.hpp" // =================================================================== @@ -54,11 +53,7 @@ signals: void contactUpdated (); private: - QString getUsername () const { - return Utils::linphoneStringToQString( - m_linphone_friend->getName() - ); - } + QString getUsername () const; QString getAvatar () const { return ""; @@ -67,11 +62,7 @@ private: Presence::PresenceStatus getPresenceStatus () const; Presence::PresenceLevel getPresenceLevel () const; - QString getSipAddress () const { - return Utils::linphoneStringToQString( - m_linphone_friend->getAddress()->asString() - ); - } + QString getSipAddress () const; Presence::PresenceStatus m_presence_status = Presence::Offline; diff --git a/tests/src/components/contacts/ContactsListModel.cpp b/tests/src/components/contacts/ContactsListModel.cpp index f879467ff..61a8068dc 100644 --- a/tests/src/components/contacts/ContactsListModel.cpp +++ b/tests/src/components/contacts/ContactsListModel.cpp @@ -2,6 +2,7 @@ #include "../../app/App.hpp" #include "../core/CoreManager.hpp" +#include "ContactModel.hpp" #include "ContactsListProxyModel.hpp" #include "ContactsListModel.hpp" diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp index 54ce8d8c3..f9664f4b3 100644 --- a/tests/src/components/contacts/ContactsListModel.hpp +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -2,8 +2,9 @@ #define CONTACTS_LIST_MODEL_H_ #include +#include -#include "ContactModel.hpp" +class ContactModel; // =================================================================== diff --git a/tests/src/components/contacts/ContactsListProxyModel.cpp b/tests/src/components/contacts/ContactsListProxyModel.cpp index 5fe087625..281ad42bd 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.cpp +++ b/tests/src/components/contacts/ContactsListProxyModel.cpp @@ -1,5 +1,9 @@ #include +#include "../../utils.hpp" +#include "ContactModel.hpp" +#include "ContactsListModel.hpp" + #include "ContactsListProxyModel.hpp" #define USERNAME_WEIGHT 50.0 diff --git a/tests/src/components/contacts/ContactsListProxyModel.hpp b/tests/src/components/contacts/ContactsListProxyModel.hpp index c2d1d3054..7d65453a4 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.hpp +++ b/tests/src/components/contacts/ContactsListProxyModel.hpp @@ -3,7 +3,8 @@ #include -#include "ContactsListModel.hpp" +class ContactModel; +class ContactsListModel; // =================================================================== diff --git a/tests/src/components/notifier/Notifier.cpp b/tests/src/components/notifier/Notifier.cpp index e71e9e064..8f9002181 100644 --- a/tests/src/components/notifier/Notifier.cpp +++ b/tests/src/components/notifier/Notifier.cpp @@ -3,6 +3,7 @@ #include #include "../../app/App.hpp" + #include "Notifier.hpp" // Notifications QML properties/methods. diff --git a/tests/src/components/timeline/TimelineModel.cpp b/tests/src/components/timeline/TimelineModel.cpp index 4787df512..6db0a4ab2 100644 --- a/tests/src/components/timeline/TimelineModel.cpp +++ b/tests/src/components/timeline/TimelineModel.cpp @@ -4,6 +4,7 @@ #include #include "../../utils.hpp" +#include "../contacts/ContactsListModel.hpp" #include "../core/CoreManager.hpp" #include "TimelineModel.hpp" diff --git a/tests/src/components/timeline/TimelineModel.hpp b/tests/src/components/timeline/TimelineModel.hpp index 4c830b1ab..432f9ef46 100644 --- a/tests/src/components/timeline/TimelineModel.hpp +++ b/tests/src/components/timeline/TimelineModel.hpp @@ -1,7 +1,9 @@ #ifndef TIMELINE_MODEL_H_ #define TIMELINE_MODEL_H_ -#include "../contacts/ContactsListModel.hpp" +#include + +class ContactsListModel; // ===================================================================