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}) ...@@ -27,29 +27,33 @@ foreach (package ${QT5_PACKAGES})
endforeach () endforeach ()
set(SOURCES 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/ContactModel.cpp
src/components/contacts/ContactsListModel.cpp src/components/contacts/ContactsListModel.cpp
src/components/contacts/ContactsListProxyModel.cpp src/components/contacts/ContactsListProxyModel.cpp
src/components/linphone/LinphoneCore.cpp
src/components/notification/Notification.cpp src/components/notification/Notification.cpp
src/components/settings/AccountSettingsModel.cpp src/components/settings/AccountSettingsModel.cpp
src/components/settings/SettingsModel.cpp src/components/settings/SettingsModel.cpp
src/components/timeline/TimelineModel.cpp src/components/timeline/TimelineModel.cpp
src/logger.cpp
src/main.cpp src/main.cpp
) )
set(HEADERS 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/ContactModel.hpp
src/components/contacts/ContactsListModel.hpp src/components/contacts/ContactsListModel.hpp
src/components/contacts/ContactsListProxyModel.hpp src/components/contacts/ContactsListProxyModel.hpp
src/components/linphone/LinphoneCore.hpp
src/components/notification/Notification.hpp src/components/notification/Notification.hpp
src/components/presence/Presence.hpp src/components/presence/Presence.hpp
src/components/settings/AccountSettingsModel.hpp src/components/settings/AccountSettingsModel.hpp
src/components/settings/SettingsModel.hpp src/components/settings/SettingsModel.hpp
src/components/timeline/TimelineModel.hpp src/components/timeline/TimelineModel.hpp
src/logger.hpp
) )
set(QRC_RESOURCES set(QRC_RESOURCES
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <QIcon> #include <QIcon>
#include <QtDebug> #include <QtDebug>
#include "app.hpp" #include "App.hpp"
#define LANGUAGES_PATH ":/languages/" #define LANGUAGES_PATH ":/languages/"
......
#include <QDateTime> #include <QDateTime>
#include "logger.hpp" #include "Logger.hpp"
#ifdef __linux__ #ifdef __linux__
#define BLUE "\x1B[1;34m" #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 { ...@@ -40,3 +40,10 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const {
return QVariant(); 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: ...@@ -19,6 +19,9 @@ public:
QHash<int, QByteArray> roleNames () const; QHash<int, QByteArray> roleNames () const;
QVariant data (const QModelIndex &index, int role) const; QVariant data (const QModelIndex &index, int role) const;
public slots:
static ContactModel *mapSipAddressToContact (const QString &sipAddress);
private: private:
QList<ContactModel *> m_list; QList<ContactModel *> m_list;
}; };
......
...@@ -131,10 +131,6 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) ...@@ -131,10 +131,6 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
// ------------------------------------------------------------------- // -------------------------------------------------------------------
bool ContactsListProxyModel::isConnectedFilterUsed () const {
return m_use_connected_filter;
}
void ContactsListProxyModel::setConnectedFilter (bool useConnectedFilter) { void ContactsListProxyModel::setConnectedFilter (bool useConnectedFilter) {
m_use_connected_filter = useConnectedFilter; m_use_connected_filter = useConnectedFilter;
invalidate(); invalidate();
......
...@@ -19,6 +19,9 @@ class ContactsListProxyModel : public QSortFilterProxyModel { ...@@ -19,6 +19,9 @@ class ContactsListProxyModel : public QSortFilterProxyModel {
public: public:
ContactsListProxyModel (QObject *parent = Q_NULLPTR); ContactsListProxyModel (QObject *parent = Q_NULLPTR);
static void initContactsListModel (ContactsListModel *list); static void initContactsListModel (ContactsListModel *list);
static ContactsListModel *getContactsListModel () {
return m_list;
}
protected: protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const; bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const;
...@@ -28,7 +31,9 @@ private: ...@@ -28,7 +31,9 @@ private:
float computeStringWeight (const QString &string, float percentage) const; float computeStringWeight (const QString &string, float percentage) const;
float computeContactWeight (const ContactModel &contact) const; float computeContactWeight (const ContactModel &contact) const;
bool isConnectedFilterUsed () const; bool isConnectedFilterUsed () const {
return m_use_connected_filter;
}
void setConnectedFilter (bool useConnectedFilter); void setConnectedFilter (bool useConnectedFilter);
static const QRegExp m_search_separators; 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 @@ ...@@ -5,17 +5,17 @@
TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) {
// TMP. // TMP.
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 << "toto.linphone.sip.linphone.org"; m_addresses << "toto2.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto3.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto4.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto5.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto6.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto7.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto8.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto9.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto10.linphone.sip.linphone.org";
m_addresses << "toto.linphone.sip.linphone.org"; m_addresses << "toto11.linphone.sip.linphone.org";
} }
int TimelineModel::rowCount (const QModelIndex &) const { int TimelineModel::rowCount (const QModelIndex &) const {
...@@ -24,7 +24,7 @@ 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> TimelineModel::roleNames () const {
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles[Qt::DisplayRole] = "$address"; roles[Qt::DisplayRole] = "$timelineEntry";
return roles; return roles;
} }
......
...@@ -7,11 +7,13 @@ ...@@ -7,11 +7,13 @@
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QtDebug> #include <QtDebug>
#include "app.hpp" #include "app/App.hpp"
#include "app/Logger.hpp"
#include "components/contacts/ContactsListProxyModel.hpp" #include "components/contacts/ContactsListProxyModel.hpp"
#include "components/linphone/LinphoneCore.hpp"
#include "components/notification/Notification.hpp" #include "components/notification/Notification.hpp"
#include "components/settings/AccountSettingsModel.hpp" #include "components/settings/AccountSettingsModel.hpp"
#include "logger.hpp" #include "components/timeline/TimelineModel.hpp"
// =================================================================== // ===================================================================
...@@ -54,7 +56,18 @@ void registerTypes () { ...@@ -54,7 +56,18 @@ void registerTypes () {
); );
ContactsListProxyModel::initContactsListModel(new ContactsListModel()); 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) { void addContextProperties (QQmlApplicationEngine &engine) {
...@@ -70,8 +83,10 @@ void addContextProperties (QQmlApplicationEngine &engine) { ...@@ -70,8 +83,10 @@ void addContextProperties (QQmlApplicationEngine &engine) {
// Models. // Models.
context->setContextProperty("AccountSettingsModel", new AccountSettingsModel()); context->setContextProperty("AccountSettingsModel", new AccountSettingsModel());
context->setContextProperty("TimelineModel", new TimelineModel());
// Other. // Other.
context->setContextProperty("LinphoneCore", LinphoneCore::getInstance());
context->setContextProperty("Notification", new Notification()); context->setContextProperty("Notification", new Notification());
} }
......
...@@ -2,6 +2,7 @@ import QtQuick 2.7 ...@@ -2,6 +2,7 @@ import QtQuick 2.7
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import Common 1.0 import Common 1.0
import Linphone 1.0
import Linphone.Styles 1.0 import Linphone.Styles 1.0
// =================================================================== // ===================================================================
...@@ -62,6 +63,10 @@ ColumnLayout { ...@@ -62,6 +63,10 @@ ColumnLayout {
currentIndex: -1 currentIndex: -1
delegate: Item { delegate: Item {
property var contact: ContactsListModel.mapSipAddressToContact(
$timelineEntry
)
height: TimelineStyle.contact.height height: TimelineStyle.contact.height
width: parent.width width: parent.width
...@@ -74,7 +79,7 @@ ColumnLayout { ...@@ -74,7 +79,7 @@ ColumnLayout {
? TimelineStyle.contact.backgroundColor.a ? TimelineStyle.contact.backgroundColor.a
: TimelineStyle.contact.backgroundColor.b : TimelineStyle.contact.backgroundColor.b
) )
contact: $contact contact: parent.contact
sipAddressColor: view.currentIndex === index sipAddressColor: view.currentIndex === index
? TimelineStyle.contact.sipAddress.color.selected ? TimelineStyle.contact.sipAddress.color.selected
: TimelineStyle.contact.sipAddress.color.normal : TimelineStyle.contact.sipAddress.color.normal
...@@ -92,7 +97,7 @@ ColumnLayout { ...@@ -92,7 +97,7 @@ ColumnLayout {
onClicked: { onClicked: {
view.currentIndex = index view.currentIndex = index
timeline.contactSelected($contact) timeline.contactSelected(parent.contact)
} }
} }
} }
......
...@@ -93,7 +93,7 @@ ColumnLayout { ...@@ -93,7 +93,7 @@ ColumnLayout {
anchors.fill: parent anchors.fill: parent
spacing: 0 spacing: 0
model: ContactsListModel { model: ContactsListProxyModel {
id: contacts id: contacts
} }
......
...@@ -90,7 +90,7 @@ ApplicationWindow { ...@@ -90,7 +90,7 @@ ApplicationWindow {
maxMenuHeight: MainWindowStyle.searchBox.maxHeight maxMenuHeight: MainWindowStyle.searchBox.maxHeight
placeholderText: qsTr('mainSearchBarPlaceholder') placeholderText: qsTr('mainSearchBarPlaceholder')
model: ContactsListModel {} model: ContactsListProxyModel {}
delegate: Contact { delegate: Contact {
contact: $contact contact: $contact
...@@ -158,7 +158,7 @@ ApplicationWindow { ...@@ -158,7 +158,7 @@ ApplicationWindow {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
model: ContactsListModel {} // Use History list. model: TimelineModel
onContactSelected: { onContactSelected: {
menu.resetSelectedEntry() 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