Commit a20c32af authored by Ronan Abhamon's avatar Ronan Abhamon

feat(TimelineModel): init with sqlite data

parent 9eb533b7
......@@ -6,6 +6,7 @@ cmake_minimum_required(VERSION 3.1)
project(linphone)
set(LINPHONE_EXEC linphone)
set(CMAKE_CXX_STANDARD 11)
# Use automatically moc from Qt5.
set(CMAKE_AUTOMOC ON)
......
......@@ -109,6 +109,10 @@
<file>ui/modules/Common/View/ScrollableListView.qml</file>
<file>ui/modules/Linphone/Account/AccountStatus.qml</file>
<file>ui/modules/Linphone/Call/CallControls.qml</file>
<file>ui/modules/Linphone/Call/ConnectedCallsControl.qml</file>
<file>ui/modules/Linphone/Call/IncomingCallControls.qml</file>
<file>ui/modules/Linphone/Call/OutgoingCallControls.qml</file>
<file>ui/modules/Linphone/Call/PausedCallControls.qml</file>
<file>ui/modules/Linphone/Chat/Chat.qml</file>
<file>ui/modules/Linphone/Chat/Event.qml</file>
<file>ui/modules/Linphone/Chat/IncomingMessage.qml</file>
......
......@@ -16,6 +16,8 @@
#define DATABASE_PATH_CALL_HISTORY_LIST ".linphone-call-history.db"
#define DATABASE_PATH_MESSAGE_HISTORY_LIST ".linphone-history.db"
using namespace std;
// ===================================================================
inline bool ensureDatabaseFilePathExists (const QString &path) {
......@@ -29,7 +31,7 @@ inline bool ensureDatabaseFilePathExists (const QString &path) {
return file.exists() || file.open(QIODevice::ReadWrite);
}
inline std::string getDatabaseFilePath (const QString &filename) {
inline string getDatabaseFilePath (const QString &filename) {
QString path(DATABASES_PATH + "/");
path += filename;
return ensureDatabaseFilePathExists(path)
......@@ -37,14 +39,14 @@ inline std::string getDatabaseFilePath (const QString &filename) {
: "";
}
std::string Database::getFriendsListPath () {
string Database::getFriendsListPath () {
return getDatabaseFilePath(DATABASE_PATH_FRIENDS_LIST);
}
std::string Database::getCallHistoryPath () {
string Database::getCallHistoryPath () {
return getDatabaseFilePath(DATABASE_PATH_CALL_HISTORY_LIST);
}
std::string Database::getMessageHistoryPath () {
string Database::getMessageHistoryPath () {
return getDatabaseFilePath(DATABASE_PATH_MESSAGE_HISTORY_LIST);
}
......@@ -3,14 +3,16 @@
#include "ContactsListModel.hpp"
using namespace std;
// ===================================================================
ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(parent) {
std::shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore());
shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore());
// Init contacts with linphone friends list.
for (auto friend_ : core->getFriendsLists().front()->getFriends()) {
m_list << new ContactModel(friend_);
for (auto&& contact : core->getFriendsLists().front()->getFriends()) {
m_list << new ContactModel(contact);
}
}
......
......@@ -6,7 +6,7 @@
#include "ContactModel.hpp"
// ===================================================================
#include <QtDebug>
class ContactsListModel : public QAbstractListModel {
friend class ContactsListProxyModel;
......
......@@ -11,6 +11,8 @@
#define FACTOR_POS_3 0.70
#define FACTOR_POS_OTHER 0.60
using namespace std;
// ===================================================================
ContactsListModel *ContactsListProxyModel::m_list = nullptr;
......@@ -117,10 +119,10 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
float weight = computeStringWeight(contact.getUsername(), USERNAME_WEIGHT);
// Get all contact's addresses.
const std::list<std::shared_ptr<linphone::Address> > addresses =
const list<shared_ptr<linphone::Address> > addresses =
contact.m_linphone_friend->getAddresses();
auto it = addresses.cbegin();
auto&& it = addresses.cbegin();
// It exists at least one sip address.
weight += computeStringWeight(
......
......@@ -28,7 +28,5 @@ void CoreManager::setDatabasesPaths () {
database_path = Database::getMessageHistoryPath();
if (database_path.length() == 0)
qFatal("Unable to get message history database path.");
// FIXME.
// m_core->setChatDatabasePath(database_path);
m_core->setChatDatabasePath(database_path);
}
#include <algorithm>
#include <QDateTime>
#include <linphone++/linphone.hh>
#include "../../utils.hpp"
#include "../core/CoreManager.hpp"
#include "TimelineModel.hpp"
using namespace std;
// ===================================================================
TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) {
// TMP.
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";
// Returns an iterator entry position to insert a new entry.
auto search_entry = [this](
const QVariantMap &map,
const QList<QMap<QString, QVariant> >::iterator *start = NULL
) {
return lower_bound(
start ? *start : m_entries.begin(), m_entries.end(), map,
[](const QVariantMap &a, const QVariantMap &b) {
return a["timestamp"] < b["timestamp"];
}
);
};
shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore());
// Insert chat rooms events.
for (auto&& chat_room : core->getChatRooms()) {
list<shared_ptr<linphone::ChatMessage> > history = chat_room->getHistory(0);
if (history.size() == 0)
continue;
// Last message must be at the end of history.
shared_ptr<linphone::ChatMessage> message = history.back();
// Insert event message in timeline entries.
QVariantMap map;
map["timestamp"] = QDateTime::fromTime_t(message->getTime());
map["sipAddresses"] = Utils::linphoneStringToQString(
chat_room->getPeerAddress()->asString()
);
m_entries.insert(search_entry(map), map);
}
// Insert calls events.
QHash<QString, bool> address_done;
for (auto&& call_log : core->getCallLogs()) {
// Get a sip uri to check.
QString address = Utils::linphoneStringToQString(
call_log->getRemoteAddress()->asString()
);
if (address_done.value(address))
continue; // Already used.
address_done[address] = true;
// Make a new map.
QVariantMap map;
map["timestamp"] = QDateTime::fromTime_t(
call_log->getStartDate() + call_log->getDuration()
);
map["sipAddresses"] = address;
// Search existing entry.
auto&& it = find_if(
m_entries.begin(), m_entries.end(), [&address](const QVariantMap &map) {
return address == map["sipAddresses"].toString();
}
);
// Is it a new entry?
if (it == m_entries.cend())
m_entries.insert(search_entry(map), map);
else if (map["timestamp"] > (*it)["timestamp"]) {
// Remove old entry and insert.
it = m_entries.erase(it) - 1;
m_entries.insert(search_entry(map, &it), map);
}
}
}
int TimelineModel::rowCount (const QModelIndex &) const {
return m_addresses.count();
return m_entries.count();
}
QHash<int, QByteArray> TimelineModel::roleNames () const {
......@@ -31,11 +99,11 @@ QHash<int, QByteArray> TimelineModel::roleNames () const {
QVariant TimelineModel::data (const QModelIndex &index, int role) const {
int row = index.row();
if (row < 0 || row >= m_addresses.count())
if (row < 0 || row >= m_entries.count())
return QVariant();
if (role == Qt::DisplayRole)
return QVariant::fromValue(m_addresses[row]);
return m_entries[row];
return QVariant();
}
......@@ -16,7 +16,11 @@ public:
QVariant data (const QModelIndex &index, int role) const;
private:
QStringList m_addresses;
// A timeline enty is a object that contains:
// - A QDateTime `timestamp`.
// - A `sipAddresses` value, if it exists only one address, it's
// a string, otherwise it's a string array.
QList<QVariantMap> m_entries;
};
#endif // TIMELINE_MODEL_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment