From 558a55de7ad8de112d51bf06461370ea194e3dc2 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 17 Nov 2016 17:20:11 +0100 Subject: [PATCH] unstable Signed-off-by: Ronan Abhamon --- tests/CMakeLists.txt | 4 +- tests/src/app/App.cpp | 5 +- tests/src/app/Database.cpp | 50 +++++++++++++++++++ tests/src/app/Database.hpp | 15 ++++++ .../src/components/contacts/ContactModel.hpp | 18 +++---- .../components/contacts/ContactsListModel.cpp | 27 +++------- .../components/contacts/ContactsListModel.hpp | 7 ++- .../contacts/ContactsListProxyModel.cpp | 2 +- tests/src/components/core/CoreManager.cpp | 29 ++++++++++- tests/src/components/core/CoreManager.hpp | 8 ++- 10 files changed, 127 insertions(+), 38 deletions(-) create mode 100644 tests/src/app/Database.cpp create mode 100644 tests/src/app/Database.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5270d3e84..28d39fc51 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,7 @@ # CMakeLists.txt # ==================================================================== -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.1) project(linphone) set(LINPHONE_EXEC linphone) @@ -30,6 +30,7 @@ list(APPEND LIBS "${CMAKE_SOURCE_DIR}/../OUTPUT/desktop/lib64/liblinphone++.so") set(SOURCES src/app/App.cpp + src/app/Database.cpp src/app/Logger.cpp src/components/chat/ChatModel.cpp src/components/contacts/ContactModel.cpp @@ -45,6 +46,7 @@ set(SOURCES set(HEADERS src/app/App.hpp + src/app/Database.hpp src/app/Logger.hpp src/components/chat/ChatModel.hpp src/components/contacts/ContactModel.hpp diff --git a/tests/src/app/App.cpp b/tests/src/app/App.cpp index 3185fe677..5bbf9e9b2 100644 --- a/tests/src/app/App.cpp +++ b/tests/src/app/App.cpp @@ -46,6 +46,9 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) { // ------------------------------------------------------------------- void App::initContentApp () { + // Init core. + CoreManager::init(); + // Register types and load context properties. registerTypes(); addContextProperties(); @@ -90,7 +93,7 @@ void App::addContextProperties () { if (component.isError()) { qWarning() << component.errors(); } else { - context->setContextProperty("CallsWindow", component.create()); + //context->setContextProperty("CallsWindow", component.create()); } // Models. diff --git a/tests/src/app/Database.cpp b/tests/src/app/Database.cpp new file mode 100644 index 000000000..25726775c --- /dev/null +++ b/tests/src/app/Database.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +#include "Database.hpp" + +#ifdef _WIN32 + #define DATABASES_PATH \ + QStandardPaths::writableLocation(QStandardPaths::DataLocation) +#else + #define DATABASES_PATH \ + QStandardPaths::writableLocation(QStandardPaths::HomeLocation) +#endif + +#define DATABASE_PATH_FRIENDS_LIST ".linphone-friends.db" +#define DATABASE_PATH_CALL_HISTORY_LIST ".linphone-call-history.db" +#define DATABASE_PATH_MESSAGE_HISTORY_LIST ".linphone-history.db" + +// =================================================================== + +inline bool ensureDatabaseFilePathExists (const QString &path) { + QDir dir(DATABASES_PATH); + + if (!dir.exists() && !dir.mkpath(DATABASES_PATH)) + return false; + + QFile file(path); + + return file.exists() || file.open(QIODevice::ReadWrite); +} + +inline std::string getDatabaseFilePath (const QString &filename) { + QString path(DATABASES_PATH + "/"); + path += filename; + return ensureDatabaseFilePathExists(path) + ? QDir::toNativeSeparators(path).toStdString() + : ""; +} + +std::string Database::getFriendsListPath () { + return getDatabaseFilePath(DATABASE_PATH_FRIENDS_LIST); +} + +std::string Database::getCallHistoryPath () { + return getDatabaseFilePath(DATABASE_PATH_CALL_HISTORY_LIST); +} + +std::string Database::getMessageHistoryPath () { + return getDatabaseFilePath(DATABASE_PATH_MESSAGE_HISTORY_LIST); +} diff --git a/tests/src/app/Database.hpp b/tests/src/app/Database.hpp new file mode 100644 index 000000000..a51c4e905 --- /dev/null +++ b/tests/src/app/Database.hpp @@ -0,0 +1,15 @@ +#ifndef DATABASE_H_ +#define DATABASE_H_ + +#include + +namespace Database { + // Returns the databases paths. + // If files cannot be created or are unavailable, a empty string is returned. + // Use the directories separator of used OS. + std::string getFriendsListPath (); + std::string getCallHistoryPath (); + std::string getMessageHistoryPath (); +}; + +#endif // DATABASE_H_ diff --git a/tests/src/components/contacts/ContactModel.hpp b/tests/src/components/contacts/ContactModel.hpp index 5e1ae954d..cade04efb 100644 --- a/tests/src/components/contacts/ContactModel.hpp +++ b/tests/src/components/contacts/ContactModel.hpp @@ -3,6 +3,8 @@ #include +#include + #include "../presence/Presence.hpp" // =================================================================== @@ -46,17 +48,9 @@ class ContactModel : public QObject { ); public: - ContactModel (QObject *parent = Q_NULLPTR) : QObject(parent) { } - ContactModel ( - const QString &username, - const QString &avatar, - const Presence::PresenceStatus &presence_status, - const QStringList &sip_addresses - ): ContactModel () { - m_username = username; - m_avatar = avatar; - m_presence_status = presence_status; - m_sip_addresses = sip_addresses; + ContactModel (std::shared_ptr linphone_friend) { + m_linphone_friend = linphone_friend; + m_sip_addresses << "jiiji"; } signals: @@ -79,6 +73,8 @@ private: QString m_avatar; Presence::PresenceStatus m_presence_status = Presence::Offline; QStringList m_sip_addresses; + + std::shared_ptr m_linphone_friend; }; Q_DECLARE_METATYPE(ContactModel*); diff --git a/tests/src/components/contacts/ContactsListModel.cpp b/tests/src/components/contacts/ContactsListModel.cpp index 8632ec895..79f82e972 100644 --- a/tests/src/components/contacts/ContactsListModel.cpp +++ b/tests/src/components/contacts/ContactsListModel.cpp @@ -1,26 +1,16 @@ +#include "../core/CoreManager.hpp" +#include "ContactsListProxyModel.hpp" + #include "ContactsListModel.hpp" // =================================================================== ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(parent) { - // TMP. - m_list << new ContactModel("Toto Roi", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Mary Boreno", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Cecelia Cyler", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Daniel Elliott", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Effie Forton", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Agnes Hurner", "", Presence::Offline, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Luke Lemin", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Claire Manning", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Isabella Ahornton", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Mary Boreno", "", Presence::Offline, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel("Aman Than", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - m_list << new ContactModel(" abdoul", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); + std::shared_ptr core(CoreManager::getInstance()->getCore()); -} - -int ContactsListModel::rowCount (const QModelIndex &) const { - return m_list.count(); + for (auto friend_ : core->getFriendsLists().front()->getFriends()) { + m_list << new ContactModel(friend_); + } } QHash ContactsListModel::roleNames () const { @@ -44,6 +34,5 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const { // ------------------------------------------------------------------- ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) { - static ContactModel *a = new ContactModel("Aman Than", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org")); - return a; + return ContactsListProxyModel::getContactsListModel()->m_list.front(); } diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp index 1eb42a959..579bfade1 100644 --- a/tests/src/components/contacts/ContactsListModel.hpp +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -6,7 +6,7 @@ #include "ContactModel.hpp" // =================================================================== - +#include class ContactsListModel : public QAbstractListModel { friend class ContactsListProxyModel; @@ -15,7 +15,10 @@ class ContactsListModel : public QAbstractListModel { public: ContactsListModel (QObject *parent = Q_NULLPTR); - int rowCount (const QModelIndex &) const; + int rowCount (const QModelIndex &) const { + return m_list.count(); + } + QHash roleNames () const; QVariant data (const QModelIndex &index, int role) const; diff --git a/tests/src/components/contacts/ContactsListProxyModel.cpp b/tests/src/components/contacts/ContactsListProxyModel.cpp index 7990673c5..bb1e6c84c 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.cpp +++ b/tests/src/components/contacts/ContactsListProxyModel.cpp @@ -32,7 +32,7 @@ ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterPr setSourceModel(m_list); setFilterCaseSensitivity(Qt::CaseInsensitive); - foreach (const ContactModel *contact, m_list->m_list) + for (const ContactModel *contact : m_list->m_list) m_weights[contact] = 0; sort(0); diff --git a/tests/src/components/core/CoreManager.cpp b/tests/src/components/core/CoreManager.cpp index e711d5756..44441266b 100644 --- a/tests/src/components/core/CoreManager.cpp +++ b/tests/src/components/core/CoreManager.cpp @@ -1,9 +1,34 @@ +#include "../../app/Database.hpp" + #include "CoreManager.hpp" // =================================================================== CoreManager *CoreManager::m_instance = nullptr; -CoreManager::CoreManager (QObject *parent) : m_core( +CoreManager::CoreManager (QObject *parent) : m_core( linphone::Factory::get()->createCore(nullptr, "", "", nullptr) -) {} +) { + setDatabasesPaths(); +} + +void CoreManager::setDatabasesPaths () { + std::string database_path; + + database_path = Database::getFriendsListPath(); + if (database_path.length() == 0) + qFatal("Unable to get friends list database path."); + m_core->setFriendsDatabasePath(database_path); + + database_path = Database::getCallHistoryPath(); + if (database_path.length() == 0) + qFatal("Unable to get call history database path."); + m_core->setCallLogsDatabasePath(database_path); + + database_path = Database::getMessageHistoryPath(); + if (database_path.length() == 0) + qFatal("Unable to get message history database path."); + + // FIXME. + // m_core->setChatDatabasePath(database_path); +} diff --git a/tests/src/components/core/CoreManager.hpp b/tests/src/components/core/CoreManager.hpp index 51f6ab2b2..02e0e24d2 100644 --- a/tests/src/components/core/CoreManager.hpp +++ b/tests/src/components/core/CoreManager.hpp @@ -20,12 +20,18 @@ public: return m_instance; } + std::shared_ptr getCore () { + return m_core; + } + private: CoreManager (QObject *parent = Q_NULLPTR); - std::shared_ptr m_core; + void setDatabasesPaths (); static CoreManager *m_instance; + + std::shared_ptr m_core; }; #endif // CORE_MANAGER_H_