Commit 758dd1c0 authored by Ronan's avatar Ronan
Browse files

unstable (refactoring)

parent e69d7fcd
# ====================================================================
# ==============================================================================
# CMakeLists.txt
# ====================================================================
# ==============================================================================
cmake_minimum_required(VERSION 3.1)
project(linphone)
......@@ -31,9 +31,9 @@ set(CUSTOM_FLAGS "\
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CUSTOM_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG")
# --------------------------------------------------------------------
# Define packages, libs, sources, headers, resources and languages
# --------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Define packages, libs, sources, headers, resources and languages.
# ------------------------------------------------------------------------------
set(QT5_PACKAGES Core Gui Quick Widgets QuickControls2 LinguistTools)
......@@ -108,7 +108,7 @@ set(LANGUAGES_DIRECTORY assets/languages)
set(I18N_FILENAME i18n.qrc)
set(LANGUAGES en fr)
# --------------------------------------------------------------------
# ------------------------------------------------------------------------------
function (PREPEND list prefix)
set(new_list "")
......@@ -125,9 +125,9 @@ PREPEND(SOURCES "${CMAKE_SOURCE_DIR}/")
PREPEND(HEADERS "${CMAKE_SOURCE_DIR}/")
PREPEND(QRC_RESOURCES "${CMAKE_SOURCE_DIR}/")
# --------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Compute QML files list.
# --------------------------------------------------------------------
# ------------------------------------------------------------------------------
set(QML_SOURCES)
file(STRINGS ${QRC_RESOURCES} QRC_RESOURCES_CONTENT)
......@@ -149,18 +149,18 @@ add_custom_target(
COMMAND "${CMAKE_SOURCE_DIR}/tools/check_qml_syntax"
)
# --------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Init git hooks.
# --------------------------------------------------------------------
# ------------------------------------------------------------------------------
execute_process(COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_SOURCE_DIR}/tools/private/pre-commit"
"${CMAKE_SOURCE_DIR}/../.git/hooks/pre-commit"
)
# --------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Build.
# --------------------------------------------------------------------
# ------------------------------------------------------------------------------
find_package(Qt5 COMPONENTS ${QT5_PACKAGES})
......
......@@ -63,8 +63,9 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
void App::initContentApp () {
qInfo() << "Initializing core manager...";
// Init core.
// Init core & contacts.
CoreManager::init();
ContactsListModel::init();
// Register types and load context properties.
registerTypes();
......@@ -86,13 +87,18 @@ void App::initContentApp () {
void App::registerTypes () {
qInfo() << "Registering types...";
// Register meta types.
qmlRegisterUncreatableType<ContactModel>(
"Linphone", 1, 0, "ContactModel", "ContactModel is uncreatable"
);
qmlRegisterUncreatableType<VcardModel>(
"Linphone", 1, 0, "VcardModel", "VcardModel is uncreatable"
);
qmlRegisterUncreatableType<Presence>(
"Linphone", 1, 0, "Presence", "Presence is uncreatable"
);
qRegisterMetaType<ChatModel::EntryType>("ChatModel::EntryType");
// Register Application/Core.
qmlRegisterSingletonType<App>(
"Linphone", 1, 0, "App",
[](QQmlEngine *, QJSEngine *) -> QObject *{
......@@ -107,28 +113,10 @@ void App::registerTypes () {
}
);
// Register models.
qmlRegisterType<Camera>("Linphone", 1, 0, "Camera");
qmlRegisterUncreatableType<ContactModel>(
"Linphone", 1, 0, "ContactModel", "ContactModel is uncreatable"
);
qmlRegisterUncreatableType<VcardModel>(
"Linphone", 1, 0, "VcardModel", "VcardModel is uncreatable"
);
ContactsListProxyModel::initContactsListModel(new ContactsListModel());
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
qmlRegisterType<ChatModel>("Linphone", 1, 0, "ChatModel");
qmlRegisterType<ChatProxyModel>("Linphone", 1, 0, "ChatProxyModel");
// Register singletons.
qmlRegisterSingletonType<ContactsListModel>(
"Linphone", 1, 0, "ContactsListModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return ContactsListProxyModel::getContactsListModel();
return ContactsListModel::getInstance();
}
);
......@@ -142,9 +130,14 @@ void App::registerTypes () {
qmlRegisterSingletonType<TimelineModel>(
"Linphone", 1, 0, "TimelineModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return new TimelineModel(ContactsListProxyModel::getContactsListModel());
return new TimelineModel();
}
);
qmlRegisterType<Camera>("Linphone", 1, 0, "Camera");
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
qmlRegisterType<ChatModel>("Linphone", 1, 0, "ChatModel");
qmlRegisterType<ChatProxyModel>("Linphone", 1, 0, "ChatProxyModel");
}
void App::addContextProperties () {
......
......@@ -10,6 +10,8 @@ using namespace std;
// =============================================================================
ContactsListModel *ContactsListModel::m_instance = nullptr;
ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(parent) {
m_linphone_friends = CoreManager::getInstance()->getCore()->getFriendsLists().front();
......
......@@ -14,7 +14,6 @@ class ContactsListModel : public QAbstractListModel {
friend class ContactsListProxyModel;
public:
ContactsListModel (QObject *parent = Q_NULLPTR);
~ContactsListModel () = default;
int rowCount (const QModelIndex &index = QModelIndex()) const override;
......@@ -25,6 +24,16 @@ public:
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
static void init () {
if (!ContactsListModel::m_instance) {
m_instance = new ContactsListModel();
}
}
static ContactsListModel *getInstance () {
return m_instance;
}
public slots:
ContactModel *mapSipAddressToContact (const QString &sipAddress) const;
......@@ -32,8 +41,12 @@ public slots:
void removeContact (ContactModel *contact);
private:
ContactsListModel (QObject *parent = Q_NULLPTR);
QList<ContactModel *> m_list;
std::shared_ptr<linphone::FriendList> m_linphone_friends;
static ContactsListModel *m_instance;
};
#endif // CONTACTS_LIST_MODEL_H_
#include <QDebug>
#include "../../utils.hpp"
#include "ContactsListModel.hpp"
#include "ContactsListProxyModel.hpp"
......@@ -17,8 +18,6 @@ using namespace std;
// =============================================================================
ContactsListModel *ContactsListProxyModel::m_list = nullptr;
// Notes:
//
// - First `^` is necessary to search two words with one separator
......@@ -33,8 +32,7 @@ const QRegExp ContactsListProxyModel::m_search_separators("^[^_.-;@ ][_.-;@ ]");
// -----------------------------------------------------------------------------
ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
if (m_list == nullptr)
qFatal("Contacts list model is undefined.");
m_list = ContactsListModel::getInstance();
setSourceModel(m_list);
setFilterCaseSensitivity(Qt::CaseInsensitive);
......@@ -46,13 +44,6 @@ ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterPr
sort(0);
}
void ContactsListProxyModel::initContactsListModel (ContactsListModel *list) {
if (!m_list)
m_list = list;
else
qWarning() << "Contacts list model is already defined.";
}
bool ContactsListProxyModel::filterAcceptsRow (
int source_row,
const QModelIndex &source_parent
......
......@@ -3,10 +3,12 @@
#include <QSortFilterProxyModel>
#include "ContactsListModel.hpp"
#include "../contact/ContactModel.hpp"
// =============================================================================
class ContactsListModel;
class ContactsListProxyModel : public QSortFilterProxyModel {
Q_OBJECT;
......@@ -20,11 +22,6 @@ public:
ContactsListProxyModel (QObject *parent = Q_NULLPTR);
~ContactsListProxyModel () = default;
static void initContactsListModel (ContactsListModel *list);
static ContactsListModel *getContactsListModel () {
return m_list;
}
public slots:
void setFilter (const QString &pattern) {
setFilterFixedString(pattern);
......@@ -45,17 +42,14 @@ private:
void setConnectedFilter (bool use_connected_filter);
ContactsListModel *m_list;
bool m_use_connected_filter = false;
// It's just a cache to save values computed by `filterAcceptsRow`
// and reused by `lessThan`.
mutable QHash<const ContactModel *, unsigned int> m_weights;
bool m_use_connected_filter = false;
static const QRegExp m_search_separators;
// The contacts list is shared between `ContactsListProxyModel`
// it's necessary to initialize it with `initContactsListModel`.
static ContactsListModel *m_list;
};
#endif // CONTACTS_LIST_PROXY_MODEL_H_
......@@ -14,13 +14,13 @@ using namespace std;
// ===================================================================
TimelineModel::TimelineModel (const ContactsListModel *contacts_list) {
TimelineModel::TimelineModel (QObject *parent) : QAbstractListModel(parent) {
init_entries();
// Invalidate model if a contact is removed.
// Better than compare each sip address.
connect(
contacts_list, &ContactsListModel::rowsRemoved, this,
ContactsListModel::getInstance(), &ContactsListModel::rowsRemoved, this,
[this](const QModelIndex &, int, int) {
beginResetModel();
// Nothing.
......
......@@ -11,7 +11,7 @@ class TimelineModel : public QAbstractListModel {
Q_OBJECT;
public:
TimelineModel (const ContactsListModel *contacts_list);
TimelineModel (QObject *parent = Q_NULLPTR);
int rowCount (const QModelIndex &) const override;
QHash<int, QByteArray> roleNames () const override;
......
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