diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3076a436a..d1072a064 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,29 +27,33 @@ foreach (package ${QT5_PACKAGES}) endforeach () set(SOURCES - src/app.cpp + src/app/App.cpp + src/app/Logger.cpp + src/components/chat/ChatModel.cpp src/components/contacts/ContactModel.cpp src/components/contacts/ContactsListModel.cpp src/components/contacts/ContactsListProxyModel.cpp + src/components/linphone/LinphoneCore.cpp src/components/notification/Notification.cpp src/components/settings/AccountSettingsModel.cpp src/components/settings/SettingsModel.cpp src/components/timeline/TimelineModel.cpp - src/logger.cpp src/main.cpp ) set(HEADERS - src/app.hpp + src/app/App.hpp + src/app/Logger.hpp + src/components/chat/ChatModel.hpp src/components/contacts/ContactModel.hpp src/components/contacts/ContactsListModel.hpp src/components/contacts/ContactsListProxyModel.hpp + src/components/linphone/LinphoneCore.hpp src/components/notification/Notification.hpp src/components/presence/Presence.hpp src/components/settings/AccountSettingsModel.hpp src/components/settings/SettingsModel.hpp src/components/timeline/TimelineModel.hpp - src/logger.hpp ) set(QRC_RESOURCES diff --git a/tests/src/app.cpp b/tests/src/app/App.cpp similarity index 96% rename from tests/src/app.cpp rename to tests/src/app/App.cpp index d58da3fd3..f2ae51a30 100644 --- a/tests/src/app.cpp +++ b/tests/src/app/App.cpp @@ -3,7 +3,7 @@ #include #include -#include "app.hpp" +#include "App.hpp" #define LANGUAGES_PATH ":/languages/" diff --git a/tests/src/app.hpp b/tests/src/app/App.hpp similarity index 100% rename from tests/src/app.hpp rename to tests/src/app/App.hpp diff --git a/tests/src/logger.cpp b/tests/src/app/Logger.cpp similarity index 98% rename from tests/src/logger.cpp rename to tests/src/app/Logger.cpp index 3504441d7..ebb648a60 100644 --- a/tests/src/logger.cpp +++ b/tests/src/app/Logger.cpp @@ -1,6 +1,6 @@ #include -#include "logger.hpp" +#include "Logger.hpp" #ifdef __linux__ #define BLUE "\x1B[1;34m" diff --git a/tests/src/logger.hpp b/tests/src/app/Logger.hpp similarity index 100% rename from tests/src/logger.hpp rename to tests/src/app/Logger.hpp diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/src/components/chat/ChatModel.cpp @@ -0,0 +1 @@ + diff --git a/tests/src/components/chat/ChatModel.hpp b/tests/src/components/chat/ChatModel.hpp new file mode 100644 index 000000000..64efe6d58 --- /dev/null +++ b/tests/src/components/chat/ChatModel.hpp @@ -0,0 +1,15 @@ +#ifndef CHAT_MODEL_H_ +#define CHAT_MODEL_H_ + +#include + +// =================================================================== + +class ChatModel : public QObject { + Q_OBJECT; + +public: + ChatModel (QObject *parent = Q_NULLPTR); +}; + +#endif // CHAT_MODEL_H_ diff --git a/tests/src/components/contacts/ContactsListModel.cpp b/tests/src/components/contacts/ContactsListModel.cpp index 37fd6f69b..8632ec895 100644 --- a/tests/src/components/contacts/ContactsListModel.cpp +++ b/tests/src/components/contacts/ContactsListModel.cpp @@ -40,3 +40,10 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const { return QVariant(); } + +// ------------------------------------------------------------------- + +ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) { + static ContactModel *a = new ContactModel("Aman Than", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); + return a; +} diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp index e14e85bc0..1eb42a959 100644 --- a/tests/src/components/contacts/ContactsListModel.hpp +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -19,6 +19,9 @@ public: QHash roleNames () const; QVariant data (const QModelIndex &index, int role) const; +public slots: + static ContactModel *mapSipAddressToContact (const QString &sipAddress); + private: QList m_list; }; diff --git a/tests/src/components/contacts/ContactsListProxyModel.cpp b/tests/src/components/contacts/ContactsListProxyModel.cpp index 9ac52d428..7990673c5 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.cpp +++ b/tests/src/components/contacts/ContactsListProxyModel.cpp @@ -131,10 +131,6 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) // ------------------------------------------------------------------- -bool ContactsListProxyModel::isConnectedFilterUsed () const { - return m_use_connected_filter; -} - void ContactsListProxyModel::setConnectedFilter (bool useConnectedFilter) { m_use_connected_filter = useConnectedFilter; invalidate(); diff --git a/tests/src/components/contacts/ContactsListProxyModel.hpp b/tests/src/components/contacts/ContactsListProxyModel.hpp index a7580a017..4312c2b3b 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.hpp +++ b/tests/src/components/contacts/ContactsListProxyModel.hpp @@ -19,6 +19,9 @@ class ContactsListProxyModel : public QSortFilterProxyModel { public: ContactsListProxyModel (QObject *parent = Q_NULLPTR); static void initContactsListModel (ContactsListModel *list); + static ContactsListModel *getContactsListModel () { + return m_list; + } protected: bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const; @@ -28,7 +31,9 @@ private: float computeStringWeight (const QString &string, float percentage) const; float computeContactWeight (const ContactModel &contact) const; - bool isConnectedFilterUsed () const; + bool isConnectedFilterUsed () const { + return m_use_connected_filter; + } void setConnectedFilter (bool useConnectedFilter); static const QRegExp m_search_separators; diff --git a/tests/src/components/linphone/LinphoneCore.cpp b/tests/src/components/linphone/LinphoneCore.cpp new file mode 100644 index 000000000..1fee20f3e --- /dev/null +++ b/tests/src/components/linphone/LinphoneCore.cpp @@ -0,0 +1,5 @@ +#include "LinphoneCore.hpp" + +// =================================================================== + +LinphoneCore *LinphoneCore::m_instance = nullptr; diff --git a/tests/src/components/linphone/LinphoneCore.hpp b/tests/src/components/linphone/LinphoneCore.hpp new file mode 100644 index 000000000..242f5a471 --- /dev/null +++ b/tests/src/components/linphone/LinphoneCore.hpp @@ -0,0 +1,28 @@ +#ifndef LINPHONE_CORE_H_ +#define LINPHONE_CORE_H_ + +#include + +// =================================================================== + +class LinphoneCore : public QObject { + Q_OBJECT; + +public: + static void init () { + if (!m_instance) { + m_instance = new LinphoneCore(); + } + } + + static LinphoneCore *getInstance () { + return m_instance; + } + +private: + LinphoneCore (QObject *parent = Q_NULLPTR) {}; + + static LinphoneCore *m_instance; +}; + +#endif // LINPHONE_CORE_H_ diff --git a/tests/src/components/timeline/Timeline.hpp b/tests/src/components/timeline/Timeline.hpp new file mode 100644 index 000000000..713e26a73 --- /dev/null +++ b/tests/src/components/timeline/Timeline.hpp @@ -0,0 +1,20 @@ +#ifndef SETTINGS_MODEL_H_ +#define SETTINGS_MODEL_H_ + +#include + +#include "AccountSettingsModel.hpp" + +// =================================================================== + +class SettingsModel : public QObject { + Q_OBJECT + +public: + SettingsModel (QObject *parent = Q_NULLPTR); + +private: + QList accountsSettings; +}; + +#endif // SETTINGS_MODEL_H_ diff --git a/tests/src/components/timeline/TimelineModel.cpp b/tests/src/components/timeline/TimelineModel.cpp index c54562feb..9d7e88f1f 100644 --- a/tests/src/components/timeline/TimelineModel.cpp +++ b/tests/src/components/timeline/TimelineModel.cpp @@ -5,17 +5,17 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { // TMP. m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; - m_addresses << "toto.linphone.sip.linphone.org"; + m_addresses << "toto1.linphone.sip.linphone.org"; + m_addresses << "toto2.linphone.sip.linphone.org"; + m_addresses << "toto3.linphone.sip.linphone.org"; + m_addresses << "toto4.linphone.sip.linphone.org"; + m_addresses << "toto5.linphone.sip.linphone.org"; + m_addresses << "toto6.linphone.sip.linphone.org"; + m_addresses << "toto7.linphone.sip.linphone.org"; + m_addresses << "toto8.linphone.sip.linphone.org"; + m_addresses << "toto9.linphone.sip.linphone.org"; + m_addresses << "toto10.linphone.sip.linphone.org"; + m_addresses << "toto11.linphone.sip.linphone.org"; } int TimelineModel::rowCount (const QModelIndex &) const { @@ -24,7 +24,7 @@ int TimelineModel::rowCount (const QModelIndex &) const { QHash TimelineModel::roleNames () const { QHash roles; - roles[Qt::DisplayRole] = "$address"; + roles[Qt::DisplayRole] = "$timelineEntry"; return roles; } diff --git a/tests/src/main.cpp b/tests/src/main.cpp index 7d237deca..2e87716f6 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -7,11 +7,13 @@ #include #include -#include "app.hpp" +#include "app/App.hpp" +#include "app/Logger.hpp" #include "components/contacts/ContactsListProxyModel.hpp" +#include "components/linphone/LinphoneCore.hpp" #include "components/notification/Notification.hpp" #include "components/settings/AccountSettingsModel.hpp" -#include "logger.hpp" +#include "components/timeline/TimelineModel.hpp" // =================================================================== @@ -54,7 +56,18 @@ void registerTypes () { ); ContactsListProxyModel::initContactsListModel(new ContactsListModel()); - qmlRegisterType("Linphone", 1, 0, "ContactsListModel"); + qmlRegisterType("Linphone", 1, 0, "ContactsListProxyModel"); + + // Expose the static functions of ContactsListModel. + qmlRegisterSingletonType( + "Linphone", 1, 0, "ContactsListModel", + [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject *{ + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + + return ContactsListProxyModel::getContactsListModel(); + } + ); } void addContextProperties (QQmlApplicationEngine &engine) { @@ -65,13 +78,15 @@ void addContextProperties (QQmlApplicationEngine &engine) { if (component.isError()) { qWarning() << component.errors(); } else { - // context->setContextProperty("CallsWindow", component.create()); + // context->setContextProperty("CallsWindow", component.create()); } // Models. context->setContextProperty("AccountSettingsModel", new AccountSettingsModel()); + context->setContextProperty("TimelineModel", new TimelineModel()); // Other. + context->setContextProperty("LinphoneCore", LinphoneCore::getInstance()); context->setContextProperty("Notification", new Notification()); } diff --git a/tests/ui/modules/Linphone/Timeline.qml b/tests/ui/modules/Linphone/Timeline.qml index 4de783b80..4b1f59bf2 100644 --- a/tests/ui/modules/Linphone/Timeline.qml +++ b/tests/ui/modules/Linphone/Timeline.qml @@ -2,6 +2,7 @@ import QtQuick 2.7 import QtQuick.Layouts 1.3 import Common 1.0 +import Linphone 1.0 import Linphone.Styles 1.0 // =================================================================== @@ -62,6 +63,10 @@ ColumnLayout { currentIndex: -1 delegate: Item { + property var contact: ContactsListModel.mapSipAddressToContact( + $timelineEntry + ) + height: TimelineStyle.contact.height width: parent.width @@ -74,7 +79,7 @@ ColumnLayout { ? TimelineStyle.contact.backgroundColor.a : TimelineStyle.contact.backgroundColor.b ) - contact: $contact + contact: parent.contact sipAddressColor: view.currentIndex === index ? TimelineStyle.contact.sipAddress.color.selected : TimelineStyle.contact.sipAddress.color.normal @@ -92,7 +97,7 @@ ColumnLayout { onClicked: { view.currentIndex = index - timeline.contactSelected($contact) + timeline.contactSelected(parent.contact) } } } diff --git a/tests/ui/views/App/MainWindow/Contacts.qml b/tests/ui/views/App/MainWindow/Contacts.qml index 80034e778..84930eefc 100644 --- a/tests/ui/views/App/MainWindow/Contacts.qml +++ b/tests/ui/views/App/MainWindow/Contacts.qml @@ -93,7 +93,7 @@ ColumnLayout { anchors.fill: parent spacing: 0 - model: ContactsListModel { + model: ContactsListProxyModel { id: contacts } diff --git a/tests/ui/views/App/MainWindow/MainWindow.qml b/tests/ui/views/App/MainWindow/MainWindow.qml index 38bb81962..23e1f94d8 100644 --- a/tests/ui/views/App/MainWindow/MainWindow.qml +++ b/tests/ui/views/App/MainWindow/MainWindow.qml @@ -90,7 +90,7 @@ ApplicationWindow { maxMenuHeight: MainWindowStyle.searchBox.maxHeight placeholderText: qsTr('mainSearchBarPlaceholder') - model: ContactsListModel {} + model: ContactsListProxyModel {} delegate: Contact { contact: $contact @@ -158,7 +158,7 @@ ApplicationWindow { Layout.fillHeight: true Layout.fillWidth: true - model: ContactsListModel {} // Use History list. + model: TimelineModel onContactSelected: { menu.resetSelectedEntry()