Commit 558a55de authored by Ronan Abhamon's avatar Ronan Abhamon
parent d4cd3d30
......@@ -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
......
......@@ -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.
......
#include <QDir>
#include <QFile>
#include <QStandardPaths>
#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);
}
#ifndef DATABASE_H_
#define DATABASE_H_
#include <string>
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_
......@@ -3,6 +3,8 @@
#include <QObject>
#include <linphone++/linphone.hh>
#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> 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<linphone::Friend> m_linphone_friend;
};
Q_DECLARE_METATYPE(ContactModel*);
......
#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<linphone::Core> 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<int, QByteArray> 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();
}
......@@ -6,7 +6,7 @@
#include "ContactModel.hpp"
// ===================================================================
#include <QtDebug>
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<int, QByteArray> roleNames () const;
QVariant data (const QModelIndex &index, int role) const;
......
......@@ -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);
......
#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);
}
......@@ -20,12 +20,18 @@ public:
return m_instance;
}
std::shared_ptr<linphone::Core> getCore () {
return m_core;
}
private:
CoreManager (QObject *parent = Q_NULLPTR);
std::shared_ptr<linphone::Core> m_core;
void setDatabasesPaths ();
static CoreManager *m_instance;
std::shared_ptr<linphone::Core> m_core;
};
#endif // CORE_MANAGER_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