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