Commit bed7cddf authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app):

  - avoid the usage of a lot of singletons, use methods in `CoreManager` instead
  - create a `UnregisteredSipAddressesProxyModel` model
  - unstable
parent e5d9bf20
...@@ -68,6 +68,7 @@ set(SOURCES ...@@ -68,6 +68,7 @@ set(SOURCES
src/components/settings/SettingsModel.cpp src/components/settings/SettingsModel.cpp
src/components/sip-addresses/SipAddressesModel.cpp src/components/sip-addresses/SipAddressesModel.cpp
src/components/sip-addresses/UnregisteredSipAddressesModel.cpp src/components/sip-addresses/UnregisteredSipAddressesModel.cpp
src/components/sip-addresses/UnregisteredSipAddressesProxyModel.hpp
src/components/timeline/TimelineModel.cpp src/components/timeline/TimelineModel.cpp
src/main.cpp src/main.cpp
) )
...@@ -92,6 +93,7 @@ set(HEADERS ...@@ -92,6 +93,7 @@ set(HEADERS
src/components/settings/SettingsModel.hpp src/components/settings/SettingsModel.hpp
src/components/sip-addresses/SipAddressesModel.hpp src/components/sip-addresses/SipAddressesModel.hpp
src/components/sip-addresses/UnregisteredSipAddressesModel.hpp src/components/sip-addresses/UnregisteredSipAddressesModel.hpp
src/components/sip-addresses/UnregisteredSipAddressesProxyModel.hpp
src/components/timeline/TimelineModel.hpp src/components/timeline/TimelineModel.hpp
src/utils.hpp src/utils.hpp
) )
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "../components/notifier/Notifier.hpp" #include "../components/notifier/Notifier.hpp"
#include "../components/settings/AccountSettingsModel.hpp" #include "../components/settings/AccountSettingsModel.hpp"
#include "../components/sip-addresses/SipAddressesModel.hpp" #include "../components/sip-addresses/SipAddressesModel.hpp"
#include "../components/sip-addresses/UnregisteredSipAddressesProxyModel.hpp"
#include "../components/timeline/TimelineModel.hpp" #include "../components/timeline/TimelineModel.hpp"
#include "App.hpp" #include "App.hpp"
...@@ -64,10 +65,8 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) { ...@@ -64,10 +65,8 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
void App::initContentApp () { void App::initContentApp () {
qInfo() << "Initializing core manager..."; qInfo() << "Initializing core manager...";
// Init core & contacts. // Init core.
CoreManager::init(); CoreManager::init();
ContactsListModel::init();
SipAddressesModel::init();
// Register types and load context properties. // Register types and load context properties.
registerTypes(); registerTypes();
...@@ -99,8 +98,6 @@ void App::registerTypes () { ...@@ -99,8 +98,6 @@ void App::registerTypes () {
"Linphone", 1, 0, "Presence", "Presence is uncreatable" "Linphone", 1, 0, "Presence", "Presence is uncreatable"
); );
qRegisterMetaType<ChatModel::EntryType>("ChatModel::EntryType");
qmlRegisterSingletonType<App>( qmlRegisterSingletonType<App>(
"Linphone", 1, 0, "App", "Linphone", 1, 0, "App",
[](QQmlEngine *, QJSEngine *) -> QObject *{ [](QQmlEngine *, QJSEngine *) -> QObject *{
...@@ -118,14 +115,14 @@ void App::registerTypes () { ...@@ -118,14 +115,14 @@ void App::registerTypes () {
qmlRegisterSingletonType<ContactsListModel>( qmlRegisterSingletonType<ContactsListModel>(
"Linphone", 1, 0, "ContactsListModel", "Linphone", 1, 0, "ContactsListModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{ [](QQmlEngine *, QJSEngine *) -> QObject *{
return ContactsListModel::getInstance(); return CoreManager::getInstance()->getContactsListModel();
} }
); );
qmlRegisterSingletonType<SipAddressesModel>( qmlRegisterSingletonType<SipAddressesModel>(
"Linphone", 1, 0, "SipAddressesModel", "Linphone", 1, 0, "SipAddressesModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{ [](QQmlEngine *, QJSEngine *) -> QObject *{
return SipAddressesModel::getInstance(); return CoreManager::getInstance()->getSipAddressesModel();
} }
); );
...@@ -147,6 +144,9 @@ void App::registerTypes () { ...@@ -147,6 +144,9 @@ void App::registerTypes () {
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel"); qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
qmlRegisterType<ChatModel>("Linphone", 1, 0, "ChatModel"); qmlRegisterType<ChatModel>("Linphone", 1, 0, "ChatModel");
qmlRegisterType<ChatProxyModel>("Linphone", 1, 0, "ChatProxyModel"); qmlRegisterType<ChatProxyModel>("Linphone", 1, 0, "ChatProxyModel");
qmlRegisterType<UnregisteredSipAddressesProxyModel>("Linphone", 1, 0, "UnregisteredSipAddressesProxyModel");
qRegisterMetaType<ChatModel::EntryType>("ChatModel::EntryType");
} }
void App::addContextProperties () { void App::addContextProperties () {
......
...@@ -10,8 +10,6 @@ using namespace std; ...@@ -10,8 +10,6 @@ using namespace std;
// ============================================================================= // =============================================================================
ContactsListModel *ContactsListModel::m_instance = nullptr;
ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(parent) { ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(parent) {
m_linphone_friends = CoreManager::getInstance()->getCore()->getFriendsLists().front(); m_linphone_friends = CoreManager::getInstance()->getCore()->getFriendsLists().front();
......
...@@ -15,6 +15,7 @@ class ContactsListModel : public QAbstractListModel { ...@@ -15,6 +15,7 @@ class ContactsListModel : public QAbstractListModel {
friend class SipAddressesModel; friend class SipAddressesModel;
public: public:
ContactsListModel (QObject *parent = Q_NULLPTR);
~ContactsListModel () = default; ~ContactsListModel () = default;
int rowCount (const QModelIndex &index = QModelIndex()) const override; int rowCount (const QModelIndex &index = QModelIndex()) const override;
...@@ -25,27 +26,13 @@ public: ...@@ -25,27 +26,13 @@ public:
bool removeRow (int row, const QModelIndex &parent = QModelIndex()); bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override; bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
static void init () {
if (!m_instance) {
m_instance = new ContactsListModel();
}
}
static ContactsListModel *getInstance () {
return m_instance;
}
public slots: public slots:
ContactModel *addContact (VcardModel *vcard); ContactModel *addContact (VcardModel *vcard);
void removeContact (ContactModel *contact); void removeContact (ContactModel *contact);
private: private:
ContactsListModel (QObject *parent = Q_NULLPTR);
QList<ContactModel *> m_list; QList<ContactModel *> m_list;
std::shared_ptr<linphone::FriendList> m_linphone_friends; std::shared_ptr<linphone::FriendList> m_linphone_friends;
static ContactsListModel *m_instance;
}; };
#endif // CONTACTS_LIST_MODEL_H_ #endif // CONTACTS_LIST_MODEL_H_
#include <QDebug> #include <QDebug>
#include "../../utils.hpp" #include "../../utils.hpp"
#include "ContactsListModel.hpp" #include "../core/CoreManager.hpp"
#include "ContactsListProxyModel.hpp" #include "ContactsListProxyModel.hpp"
...@@ -32,15 +32,15 @@ const QRegExp ContactsListProxyModel::m_search_separators("^[^_.-;@ ][_.-;@ ]"); ...@@ -32,15 +32,15 @@ const QRegExp ContactsListProxyModel::m_search_separators("^[^_.-;@ ][_.-;@ ]");
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
m_list = ContactsListModel::getInstance(); m_list = CoreManager::getInstance()->getContactsListModel();
setSourceModel(m_list); setSourceModel(m_list);
setFilterCaseSensitivity(Qt::CaseInsensitive); setFilterCaseSensitivity(Qt::CaseInsensitive);
setDynamicSortFilter(false);
for (const ContactModel *contact : m_list->m_list) for (const ContactModel *contact : m_list->m_list)
m_weights[contact] = 0; m_weights[contact] = 0;
setDynamicSortFilter(false);
sort(0); sort(0);
} }
...@@ -125,6 +125,6 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) ...@@ -125,6 +125,6 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
void ContactsListProxyModel::setConnectedFilter (bool use_connected_filter) { void ContactsListProxyModel::setConnectedFilter (bool use_connected_filter) {
if (use_connected_filter != m_use_connected_filter) { if (use_connected_filter != m_use_connected_filter) {
m_use_connected_filter = use_connected_filter; m_use_connected_filter = use_connected_filter;
invalidate(); invalidateFilter();
} }
} }
...@@ -25,7 +25,7 @@ public: ...@@ -25,7 +25,7 @@ public:
public slots: public slots:
void setFilter (const QString &pattern) { void setFilter (const QString &pattern) {
setFilterFixedString(pattern); setFilterFixedString(pattern);
sort(0); invalidateFilter();
} }
protected: protected:
......
...@@ -13,6 +13,16 @@ CoreManager::CoreManager (QObject *parent) : QObject(parent), ...@@ -13,6 +13,16 @@ CoreManager::CoreManager (QObject *parent) : QObject(parent),
setDatabasesPaths(); setDatabasesPaths();
} }
void CoreManager::init () {
if (!m_instance) {
m_instance = new CoreManager();
m_instance->m_contacts_list_model = new ContactsListModel(m_instance);
m_instance->m_sip_addresses_model = new SipAddressesModel(m_instance);
m_instance->m_unregistered_sip_addresses_model = new UnregisteredSipAddressesModel(m_instance);
}
}
VcardModel *CoreManager::createDetachedVcardModel () { VcardModel *CoreManager::createDetachedVcardModel () {
return new VcardModel(linphone::Factory::get()->createVcard()); return new VcardModel(linphone::Factory::get()->createVcard());
} }
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#define CORE_MANAGER_H_ #define CORE_MANAGER_H_
#include "../contact/VcardModel.hpp" #include "../contact/VcardModel.hpp"
#include "../contacts/ContactsListModel.hpp"
#include "../sip-addresses/SipAddressesModel.hpp"
#include "../sip-addresses/UnregisteredSipAddressesModel.hpp"
// ============================================================================= // =============================================================================
...@@ -15,12 +18,24 @@ public: ...@@ -15,12 +18,24 @@ public:
return m_core; return m_core;
} }
static void init () { // ---------------------------------------------------------------------------
if (!m_instance) { // Singleton models.
m_instance = new CoreManager(); // ---------------------------------------------------------------------------
ContactsListModel *getContactsListModel () {
return m_contacts_list_model;
}
SipAddressesModel *getSipAddressesModel () {
return m_sip_addresses_model;
} }
UnregisteredSipAddressesModel *getUnregisteredSipAddressesModel () {
return m_unregistered_sip_addresses_model;
} }
static void init ();
static CoreManager *getInstance () { static CoreManager *getInstance () {
return m_instance; return m_instance;
} }
...@@ -36,6 +51,10 @@ private: ...@@ -36,6 +51,10 @@ private:
void setDatabasesPaths (); void setDatabasesPaths ();
std::shared_ptr<linphone::Core> m_core; std::shared_ptr<linphone::Core> m_core;
ContactsListModel *m_contacts_list_model;
SipAddressesModel *m_sip_addresses_model;
UnregisteredSipAddressesModel *m_unregistered_sip_addresses_model;
static CoreManager *m_instance; static CoreManager *m_instance;
}; };
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
// ============================================================================= // =============================================================================
SipAddressesModel *SipAddressesModel::m_instance = nullptr;
SipAddressesModel::SipAddressesModel (QObject *parent) : QAbstractListModel(parent) { SipAddressesModel::SipAddressesModel (QObject *parent) : QAbstractListModel(parent) {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
...@@ -51,7 +49,7 @@ SipAddressesModel::SipAddressesModel (QObject *parent) : QAbstractListModel(pare ...@@ -51,7 +49,7 @@ SipAddressesModel::SipAddressesModel (QObject *parent) : QAbstractListModel(pare
} }
// Get sip addresses from contacts. // Get sip addresses from contacts.
for (auto &contact : ContactsListModel::getInstance()->m_list) { for (auto &contact : CoreManager::getInstance()->getContactsListModel()->m_list) {
for (const auto &sip_address : contact->getVcardModel()->getSipAddresses()) { for (const auto &sip_address : contact->getVcardModel()->getSipAddresses()) {
auto it = m_sip_addresses.find(sip_address.toString()); auto it = m_sip_addresses.find(sip_address.toString());
......
...@@ -11,6 +11,7 @@ class SipAddressesModel : public QAbstractListModel { ...@@ -11,6 +11,7 @@ class SipAddressesModel : public QAbstractListModel {
Q_OBJECT; Q_OBJECT;
public: public:
SipAddressesModel (QObject *parent = Q_NULLPTR);
~SipAddressesModel () = default; ~SipAddressesModel () = default;
int rowCount (const QModelIndex &index = QModelIndex()) const override; int rowCount (const QModelIndex &index = QModelIndex()) const override;
...@@ -18,25 +19,12 @@ public: ...@@ -18,25 +19,12 @@ public:
QHash<int, QByteArray> roleNames () const override; QHash<int, QByteArray> roleNames () const override;
QVariant data (const QModelIndex &index, int role) const override; QVariant data (const QModelIndex &index, int role) const override;
static void init () {
if (!m_instance)
m_instance = new SipAddressesModel();
}
static SipAddressesModel *getInstance () {
return m_instance;
}
public slots: public slots:
ContactModel *mapSipAddressToContact (const QString &sip_address) const; ContactModel *mapSipAddressToContact (const QString &sip_address) const;
private: private:
SipAddressesModel (QObject *parent = Q_NULLPTR);
QHash<QString, QVariantMap> m_sip_addresses; QHash<QString, QVariantMap> m_sip_addresses;
QList<const QVariantMap *> m_refs; QList<const QVariantMap *> m_refs;
static SipAddressesModel *m_instance;
}; };
#endif // SIP_ADDRESSES_MODEL_H_ #endif // SIP_ADDRESSES_MODEL_H_
#include "../sip-addresses/SipAddressesModel.hpp" #include "../core/CoreManager.hpp"
#include "UnregisteredSipAddressesModel.hpp" #include "UnregisteredSipAddressesModel.hpp"
// ============================================================================= // =============================================================================
UnregisteredSipAddressesModel::UnregisteredSipAddressesModel (QObject *parent) : QSortFilterProxyModel(parent) { UnregisteredSipAddressesModel::UnregisteredSipAddressesModel (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(SipAddressesModel::getInstance()); setSourceModel(CoreManager::getInstance()->getSipAddressesModel());
} }
bool UnregisteredSipAddressesModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const { bool UnregisteredSipAddressesModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
......
#include "UnregisteredSipAddressesProxyModel.hpp"
// =============================================================================
#ifndef UNREGISTERED_SIP_ADDRESSES_PROXY_MODEL_H_
#define UNREGISTERED_SIP_ADDRESSES_PROXY_MODEL_H_
#include "UnregisteredSipAddressesModel.hpp"
// =============================================================================
class UnregisteredSipAddressesProxyModel : public QSortFilterProxyModel {
Q_OBJECT;
};
#endif // UNREGISTERED_SIP_ADDRESSES_PROXY_MODEL_H_
#include "../sip-addresses/SipAddressesModel.hpp" #include "../core/CoreManager.hpp"
#include "TimelineModel.hpp" #include "TimelineModel.hpp"
// ============================================================================= // =============================================================================
TimelineModel::TimelineModel (QObject *parent) : QSortFilterProxyModel(parent) { TimelineModel::TimelineModel (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(SipAddressesModel::getInstance()); setSourceModel(CoreManager::getInstance()->getSipAddressesModel());
sort(0); sort(0);
} }
......
...@@ -27,8 +27,7 @@ ApplicationWindow { ...@@ -27,8 +27,7 @@ ApplicationWindow {
title: MainWindowStyle.title title: MainWindowStyle.title
visible: true visible: true
onActiveFocusItemChanged: activeFocusItem == null && onActiveFocusItemChanged: activeFocusItem == null && smartSearchBar.hideMenu()
smartSearchBar.hideMenu()
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Toolbar properties. // Toolbar properties.
...@@ -88,8 +87,10 @@ ApplicationWindow { ...@@ -88,8 +87,10 @@ ApplicationWindow {
Layout.fillWidth: true Layout.fillWidth: true
entryHeight: MainWindowStyle.searchBox.entryHeight entryHeight: MainWindowStyle.searchBox.entryHeight
maxMenuHeight: MainWindowStyle.searchBox.maxHeight maxMenuHeight: MainWindowStyle.searchBox.maxHeight
model: ContactsListProxyModel {}
placeholderText: qsTr('mainSearchBarPlaceholder') placeholderText: qsTr('mainSearchBarPlaceholder')
contactsModel: ContactsListProxyModel {}
othersSipAddresses: UnregisteredSipAddressesProxyModel {}
} }
} }
} }
......
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