Commit 8c723cdc authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): provide a way to convert a sip address in contact...

feat(app): provide a way to convert a sip address in contact `ContactsListModel::mapSipAddressToContact` (QML & C++ support)
parent 606808a6
......@@ -27,29 +27,33 @@ foreach (package ${QT5_PACKAGES})
endforeach ()
set(SOURCES
src/app.cpp
src/app/App.cpp
src/app/Logger.cpp
src/components/chat/ChatModel.cpp
src/components/contacts/ContactModel.cpp
src/components/contacts/ContactsListModel.cpp
src/components/contacts/ContactsListProxyModel.cpp
src/components/linphone/LinphoneCore.cpp
src/components/notification/Notification.cpp
src/components/settings/AccountSettingsModel.cpp
src/components/settings/SettingsModel.cpp
src/components/timeline/TimelineModel.cpp
src/logger.cpp
src/main.cpp
)
set(HEADERS
src/app.hpp
src/app/App.hpp
src/app/Logger.hpp
src/components/chat/ChatModel.hpp
src/components/contacts/ContactModel.hpp
src/components/contacts/ContactsListModel.hpp
src/components/contacts/ContactsListProxyModel.hpp
src/components/linphone/LinphoneCore.hpp
src/components/notification/Notification.hpp
src/components/presence/Presence.hpp
src/components/settings/AccountSettingsModel.hpp
src/components/settings/SettingsModel.hpp
src/components/timeline/TimelineModel.hpp
src/logger.hpp
)
set(QRC_RESOURCES
......
......@@ -3,7 +3,7 @@
#include <QIcon>
#include <QtDebug>
#include "app.hpp"
#include "App.hpp"
#define LANGUAGES_PATH ":/languages/"
......
#include <QDateTime>
#include "logger.hpp"
#include "Logger.hpp"
#ifdef __linux__
#define BLUE "\x1B[1;34m"
......
#ifndef CHAT_MODEL_H_
#define CHAT_MODEL_H_
#include <QObject>
// ===================================================================
class ChatModel : public QObject {
Q_OBJECT;
public:
ChatModel (QObject *parent = Q_NULLPTR);
};
#endif // CHAT_MODEL_H_
......@@ -40,3 +40,10 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const {
return QVariant();
}
// -------------------------------------------------------------------
ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) {
static ContactModel *a = new ContactModel("Aman Than", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
return a;
}
......@@ -19,6 +19,9 @@ public:
QHash<int, QByteArray> roleNames () const;
QVariant data (const QModelIndex &index, int role) const;
public slots:
static ContactModel *mapSipAddressToContact (const QString &sipAddress);
private:
QList<ContactModel *> m_list;
};
......
......@@ -131,10 +131,6 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
// -------------------------------------------------------------------
bool ContactsListProxyModel::isConnectedFilterUsed () const {
return m_use_connected_filter;
}
void ContactsListProxyModel::setConnectedFilter (bool useConnectedFilter) {
m_use_connected_filter = useConnectedFilter;
invalidate();
......
......@@ -19,6 +19,9 @@ class ContactsListProxyModel : public QSortFilterProxyModel {
public:
ContactsListProxyModel (QObject *parent = Q_NULLPTR);
static void initContactsListModel (ContactsListModel *list);
static ContactsListModel *getContactsListModel () {
return m_list;
}
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const;
......@@ -28,7 +31,9 @@ private:
float computeStringWeight (const QString &string, float percentage) const;
float computeContactWeight (const ContactModel &contact) const;
bool isConnectedFilterUsed () const;
bool isConnectedFilterUsed () const {
return m_use_connected_filter;
}
void setConnectedFilter (bool useConnectedFilter);
static const QRegExp m_search_separators;
......
#include "LinphoneCore.hpp"
// ===================================================================
LinphoneCore *LinphoneCore::m_instance = nullptr;
#ifndef LINPHONE_CORE_H_
#define LINPHONE_CORE_H_
#include <QObject>
// ===================================================================
class LinphoneCore : public QObject {
Q_OBJECT;
public:
static void init () {
if (!m_instance) {
m_instance = new LinphoneCore();
}
}
static LinphoneCore *getInstance () {
return m_instance;
}
private:
LinphoneCore (QObject *parent = Q_NULLPTR) {};
static LinphoneCore *m_instance;
};
#endif // LINPHONE_CORE_H_
#ifndef SETTINGS_MODEL_H_
#define SETTINGS_MODEL_H_
#include <QObject>
#include "AccountSettingsModel.hpp"
// ===================================================================
class SettingsModel : public QObject {
Q_OBJECT
public:
SettingsModel (QObject *parent = Q_NULLPTR);
private:
QList<AccountSettingsModel *> accountsSettings;
};
#endif // SETTINGS_MODEL_H_
......@@ -5,17 +5,17 @@
TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) {
// TMP.
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org";
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";
}
int TimelineModel::rowCount (const QModelIndex &) const {
......@@ -24,7 +24,7 @@ int TimelineModel::rowCount (const QModelIndex &) const {
QHash<int, QByteArray> TimelineModel::roleNames () const {
QHash<int, QByteArray> roles;
roles[Qt::DisplayRole] = "$address";
roles[Qt::DisplayRole] = "$timelineEntry";
return roles;
}
......
......@@ -7,11 +7,13 @@
#include <QSystemTrayIcon>
#include <QtDebug>
#include "app.hpp"
#include "app/App.hpp"
#include "app/Logger.hpp"
#include "components/contacts/ContactsListProxyModel.hpp"
#include "components/linphone/LinphoneCore.hpp"
#include "components/notification/Notification.hpp"
#include "components/settings/AccountSettingsModel.hpp"
#include "logger.hpp"
#include "components/timeline/TimelineModel.hpp"
// ===================================================================
......@@ -54,7 +56,18 @@ void registerTypes () {
);
ContactsListProxyModel::initContactsListModel(new ContactsListModel());
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListModel");
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
// Expose the static functions of ContactsListModel.
qmlRegisterSingletonType<ContactsListModel>(
"Linphone", 1, 0, "ContactsListModel",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject *{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return ContactsListProxyModel::getContactsListModel();
}
);
}
void addContextProperties (QQmlApplicationEngine &engine) {
......@@ -65,13 +78,15 @@ void addContextProperties (QQmlApplicationEngine &engine) {
if (component.isError()) {
qWarning() << component.errors();
} else {
// context->setContextProperty("CallsWindow", component.create());
// context->setContextProperty("CallsWindow", component.create());
}
// Models.
context->setContextProperty("AccountSettingsModel", new AccountSettingsModel());
context->setContextProperty("TimelineModel", new TimelineModel());
// Other.
context->setContextProperty("LinphoneCore", LinphoneCore::getInstance());
context->setContextProperty("Notification", new Notification());
}
......
......@@ -2,6 +2,7 @@ import QtQuick 2.7
import QtQuick.Layouts 1.3
import Common 1.0
import Linphone 1.0
import Linphone.Styles 1.0
// ===================================================================
......@@ -62,6 +63,10 @@ ColumnLayout {
currentIndex: -1
delegate: Item {
property var contact: ContactsListModel.mapSipAddressToContact(
$timelineEntry
)
height: TimelineStyle.contact.height
width: parent.width
......@@ -74,7 +79,7 @@ ColumnLayout {
? TimelineStyle.contact.backgroundColor.a
: TimelineStyle.contact.backgroundColor.b
)
contact: $contact
contact: parent.contact
sipAddressColor: view.currentIndex === index
? TimelineStyle.contact.sipAddress.color.selected
: TimelineStyle.contact.sipAddress.color.normal
......@@ -92,7 +97,7 @@ ColumnLayout {
onClicked: {
view.currentIndex = index
timeline.contactSelected($contact)
timeline.contactSelected(parent.contact)
}
}
}
......
......@@ -93,7 +93,7 @@ ColumnLayout {
anchors.fill: parent
spacing: 0
model: ContactsListModel {
model: ContactsListProxyModel {
id: contacts
}
......
......@@ -90,7 +90,7 @@ ApplicationWindow {
maxMenuHeight: MainWindowStyle.searchBox.maxHeight
placeholderText: qsTr('mainSearchBarPlaceholder')
model: ContactsListModel {}
model: ContactsListProxyModel {}
delegate: Contact {
contact: $contact
......@@ -158,7 +158,7 @@ ApplicationWindow {
Layout.fillHeight: true
Layout.fillWidth: true
model: ContactsListModel {} // Use History list.
model: TimelineModel
onContactSelected: {
menu.resetSelectedEntry()
......
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