Commit ba371b3f authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): use c++ models for contacts list (in progress)

parent dc38da1d
......@@ -9,6 +9,8 @@ RESOURCES = resources.qrc
SOURCES = \
src/app.cpp \
src/main.cpp \
src/models/contacts/ContactModel.cpp \
src/models/contacts/ContactsListModel.cpp \
src/models/notification/NotificationModel.cpp \
src/models/settings/AccountSettingsListModel.cpp \
src/models/settings/AccountSettingsModel.cpp \
......@@ -16,6 +18,8 @@ SOURCES = \
HEADERS = \
src/app.hpp \
src/models/contacts/ContactModel.hpp \
src/models/contacts/ContactsListModel.hpp \
src/models/notification/NotificationModel.hpp \
src/models/settings/AccountSettingsListModel.hpp \
src/models/settings/AccountSettingsModel.hpp \
......
......@@ -14,10 +14,10 @@
<file>imgs/history.svg</file>
<file>imgs/home.svg</file>
<file>imgs/incoming_call.svg</file>
<file>imgs/led_absent.svg</file>
<file>imgs/led_connected.svg</file>
<file>imgs/led_disconnected.svg</file>
<file>imgs/led_do_not_disturb.svg</file>
<file>imgs/led_green.svg</file>
<file>imgs/led_orange.svg</file>
<file>imgs/led_red.svg</file>
<file>imgs/led_white.svg</file>
<file>imgs/linphone.png</file>
<file>imgs/lost_incoming_call.svg</file>
<file>imgs/lost_outgoing_call.svg</file>
......@@ -36,6 +36,7 @@
<file>ui/modules/Linphone/Contact/Avatar.qml</file>
<file>ui/modules/Linphone/Contact/ContactDescription.qml</file>
<file>ui/modules/Linphone/Contact/Contact.qml</file>
<file>ui/modules/Linphone/Contact/PresenceLevel.qml</file>
<file>ui/modules/Linphone/Dialog/ConfirmDialog.qml</file>
<file>ui/modules/Linphone/Dialog/DialogDescription.qml</file>
<file>ui/modules/Linphone/Dialog/DialogPlus.qml</file>
......
......@@ -9,6 +9,7 @@
#include <QtDebug>
#include "app.hpp"
#include "models/contacts/ContactsListModel.hpp"
#include "models/notification/NotificationModel.hpp"
// ===================================================================
......@@ -46,7 +47,22 @@ void setTrayIcon (QQmlApplicationEngine &engine) {
tray_icon->show();
}
void registerTypes () {
qmlRegisterUncreatableType<ContactModel>(
"Linphone", 1, 0, "ContactModel", "ContactModel is uncreatable"
);
}
void addContextProperties (QQmlApplicationEngine &engine) {
QQmlContext *context = engine.rootContext();
context->setContextProperty("Notification", new NotificationModel());
context->setContextProperty("ContactsList", new ContactsListModel());
}
int main (int argc, char *argv[]) {
registerTypes();
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
App app(argc, argv);
QQmlApplicationEngine engine;
......@@ -69,9 +85,7 @@ int main (int argc, char *argv[]) {
else
setTrayIcon(engine);
// Warning: Add global context Notification for all views!
NotificationModel notification;
engine.rootContext()->setContextProperty("Notification", &notification);
addContextProperties(engine);
// Run!
return app.exec();
......
#include "ContactModel.hpp"
// ===================================================================
#ifndef CONTACT_MODEL_H
#define CONTACT_MODEL_H
#include <QObject>
// ===================================================================
class ContactModel : public QObject {
Q_OBJECT;
Q_PROPERTY(
QString username
READ getUsername
WRITE setUsername
NOTIFY contactUpdated
);
Q_PROPERTY(
QString avatar
READ getAvatar
WRITE setAvatar
NOTIFY contactUpdated
);
Q_PROPERTY(
Presence presence
READ getPresence
CONSTANT
);
Q_PROPERTY(
PresenceLevel presenceLevel
READ getPresenceLevel
CONSTANT
);
Q_PROPERTY(
QStringList sipAddresses
READ getSipAddresses
WRITE setSipAddresses
NOTIFY contactUpdated
);
public:
enum Presence {
Online,
BeRightBack,
Away,
OnThePhone,
OutToLunch,
DoNotDisturb,
Moved,
UsingAnotherMessagingService,
Offline
};
Q_ENUM(Presence);
enum PresenceLevel {
Green,
Orange,
Red,
White
};
Q_ENUM(PresenceLevel);
ContactModel (QObject *parent = Q_NULLPTR) : QObject(parent) { }
ContactModel (
const QString &username,
const QString &avatar,
const Presence &presence,
const QStringList &sip_addresses
): ContactModel() {
m_username = username;
m_avatar = avatar;
m_presence = presence;
m_sip_addresses = sip_addresses;
}
signals:
void contactUpdated ();
private:
QString getUsername () const {
return m_username;
}
void setUsername (const QString &username) {
m_username = username;
}
QString getAvatar () const {
return m_avatar;
}
void setAvatar (const QString &avatar) {
m_avatar = avatar;
}
Presence getPresence () const {
return m_presence;
}
PresenceLevel getPresenceLevel () const {
if (m_presence == Online)
return Green;
if (m_presence == DoNotDisturb)
return Red;
if (m_presence == Offline)
return White;
return Orange;
}
QStringList getSipAddresses () const {
return m_sip_addresses;
}
void setSipAddresses (const QStringList &sip_addresses) {
m_sip_addresses = sip_addresses;
}
QString m_username;
QString m_avatar;
Presence m_presence = Online;
QStringList m_sip_addresses;
};
Q_DECLARE_METATYPE(ContactModel*);
#endif // CONTACT_MODEL_H
#include "ContactsListModel.hpp"
// ===================================================================
#ifndef CONTACTS_LIST_MODEL_H
#define CONTACTS_LIST_MODEL_H
#include <QAbstractListModel>
#include "ContactModel.hpp"
// ===================================================================
class ContactsListModel : public QAbstractListModel {
Q_OBJECT
public:
enum Roles {
ContactRole = Qt::UserRole + 1
};
ContactsListModel (QObject *parent = Q_NULLPTR): QAbstractListModel(parent) {
m_list << new ContactModel("Toto Roi", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Cecelia Cyler", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Daniel Elliott", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Effie Forton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Agnes Hurner", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Luke Lemin", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Olga Manning", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Isabella Ahornton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
}
int rowCount (const QModelIndex &) const {
return m_list.count();
}
QHash<int, QByteArray> roleNames () const {
QHash<int, QByteArray> roles;
roles[ContactRole] = "$contact";
return roles;
}
QVariant data (const QModelIndex &index, int role) const {
if (index.row() < 0 || index.row() >= m_list.count())
return QVariant();
if (role == ContactRole)
return QVariant::fromValue(m_list[index.row()]);
return QVariant();
}
private:
QList<ContactModel *> m_list;
};
#endif // CONTACTS_LIST_MODEL_H
......@@ -8,7 +8,7 @@ import Linphone.Styles 1.0
Item {
property alias image: imageToFilter.source
property string presence
property alias presenceLevel: presenceLevel.level
property string username
function _computeInitials () {
......@@ -57,13 +57,12 @@ Item {
}
// Presence.
Icon {
PresenceLevel {
id: presenceLevel
anchors.bottom: parent.bottom
anchors.right: parent.right
height: parent.height / 3
icon: presence
? 'led_' + presence
: ''
width: parent.width / 3
}
}
......@@ -9,7 +9,7 @@ import Linphone.Styles 1.0
Item {
property alias actions: actionBar.data
property alias image: avatar.image
property alias presence: avatar.presence
property alias presenceLevel: avatar.presenceLevel
property alias sipAddress: description.sipAddress
property alias username: avatar.username
......
import QtQuick 2.7
import Linphone 1.0
// ===================================================================
Icon {
property int level: -1
function _getColorString () {
if (level === ContactModel.Green) {
return 'green'
}
if (level === ContactModel.Orange) {
return 'orange'
}
if (level === ContactModel.Red) {
return 'red'
}
if (level === ContactModel.White) {
return 'white'
}
}
icon: {
var level = _getColorString()
return level ? 'led_' + level : ''
}
}
pragma Singleton
import QtQuick 2.7
QtObject {
property QtObject initials: QtObject {
property color color: '#FFFFFF'
property int fontSize: 10
}
property QtObject mask: QtObject {
property color color: '#8F8F8F'
property int radius: 50
}
}
pragma Singleton
import QtQuick 2.7
QtObject {
property QtObject sipAddress: QtObject {
property color color: '#5A585B'
property int fontSize: 10
}
property QtObject username: QtObject {
property color color: '#5A585B'
property int fontSize: 11
}
}
pragma Singleton
import QtQuick 2.7
QtObject {
property int contentHeight: 32
property int height: 50
property int leftMargin: 14
property int rightMargin: 14
property int spacing: 14
}
......@@ -44,7 +44,7 @@ ColumnLayout {
Layout.fillWidth: true
delegate: Contact {
presence: $presence
presenceLevel: $presence
sipAddress: $sipAddress
username: $username
width: parent.width
......
......@@ -21,6 +21,7 @@ Collapse 1.0 Collapse.qml
Avatar 1.0 Contact/Avatar.qml
Contact 1.0 Contact/Contact.qml
ContactDescription 1.0 Contact/ContactDescription.qml
PresenceLevel 1.0 Contact/PresenceLevel.qml
# Dialog
DialogPlus 1.0 Dialog/DialogPlus.qml
......
......@@ -58,94 +58,8 @@ ColumnLayout {
anchors.fill: parent
spacing: 2
// TODO: Remove, use C++ model instead.
model: ListModel {
ListElement {
$image: ''
$presence: 'connected'
$username: 'Isabella Ahornton'
}
ListElement {
$image: ''
$presence: 'connected'
$username: 'Mary Boreno'
}
ListElement {
$image: ''
$presence: 'disconnected'
$username: 'Cecelia Cyler'
}
ListElement {
$image: ''
$presence: 'absent'
$username: 'Daniel Elliott'
}
ListElement {
$image: ''
$presence: 'do_not_disturb'
$username: 'Effie Forton'
}
ListElement {
$image: ''
$presence: 'do_not_disturb'
$username: 'Agnes Hurner'
}
ListElement {
$image: ''
$presence: 'disconnected'
$username: 'Luke Leming'
}
ListElement {
$image: ''
$presence: 'connected'
$username: 'Olga Manning'
}
ListElement {
$image: ''
$presence: 'connected'
$username: 'Isabella Ahornton'
}
ListElement {
$image: ''
$presence: 'connected'
$username: 'Mary Boreno'
}
ListElement {
$image: ''
$presence: 'disconnected'
$username: 'Cecelia Cyler'
}
ListElement {
$image: ''
$presence: 'disconnected'
$username: 'Toto'
}
ListElement {
$image: ''
$presence: 'absent'
$username: 'Daniel Elliott'
}
ListElement {
$image: ''
$presence: 'do_not_disturb'
$username: 'Effie Forton'
}
ListElement {
$image: ''
$presence: 'do_not_disturb'
$username: 'Agnes Hurner'
}
ListElement {
$image: ''
$presence: 'disconnected'
$username: 'Luke Leming'
}
ListElement {
$image: ''
$presence: 'connected'
$username: 'Olga Manning'
}
}
model: ContactsList
delegate: Rectangle {
color: '#FFFFFF'
height: 50
......@@ -174,8 +88,8 @@ ColumnLayout {
Avatar {
Layout.fillHeight: parent.height
Layout.preferredWidth: 30
image: $image
username: $username
image: $contact.avatar
username: $contact.username
}
// Presence.
......@@ -183,10 +97,9 @@ ColumnLayout {
Layout.fillHeight: parent.height
Layout.preferredWidth: 20
Image {
PresenceLevel {
anchors.fill: parent
fillMode: Image.PreserveAspectFit
source: 'qrc:/imgs/led_' + $presence + '.svg'
level: $contact.presenceLevel
}
}
......@@ -200,7 +113,7 @@ ColumnLayout {
clip: true
color: '#5A585B'
font.bold: true
text: $username
text: $contact.username
verticalAlignment: Text.AlignVCenter
}
}
......
......@@ -90,7 +90,7 @@ ApplicationWindow {
model: model1
delegate: Contact {
presence: $presence
presenceLevel: $presence
sipAddress: $sipAddress
username: $username
width: parent.width
......@@ -160,42 +160,42 @@ ApplicationWindow {
model: ListModel {
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'jim.williams.zzzz.yyyy.kkkk.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'toto.lala.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'disconnected'
$presence: 0
$sipAddress: 'machin.truc.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'absent'
$presence: 0
$sipAddress: 'hey.listen.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'do_not_disturb'
$presence: 0
$sipAddress: 'valentin.cognito.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'do_not_disturb'
$presence: 0
$sipAddress: 'charles.henri.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'disconnected'
$presence: 0
$sipAddress: 'yesyes.nono.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'nsa.sip.linphone.org'
$username: 'Toto'
}
......@@ -239,82 +239,82 @@ ApplicationWindow {
id: model1
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'jim.williams.zzzz.yyyy.kkkk.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'toto.lala.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'disconnected'
$presence: 0
$sipAddress: 'machin.truc.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'absent'
$presence: 0
$sipAddress: 'hey.listen.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'do_not_disturb'
$presence: 0
$sipAddress: 'valentin.cognito.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'do_not_disturb'
$presence: 0
$sipAddress: 'charles.henri.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'disconnected'
$presence: 0
$sipAddress: 'yesyes.nono.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'nsa.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'jim.williams.zzzz.yyyy.kkkk.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'toto.lala.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'disconnected'
$presence: 0
$sipAddress: 'machin.truc.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'absent'
$presence: 0
$sipAddress: 'hey.listen.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'do_not_disturb'
$presence: 0
$sipAddress: 'valentin.cognito.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'do_not_disturb'
$presence: 0
$sipAddress: 'charles.henri.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'disconnected'
$presence: 0
$sipAddress: 'yesyes.nono.sip.linphone.org'
$username: 'Toto'
}
ListElement {
$presence: 'connected'
$presence: 0
$sipAddress: 'nsa.sip.linphone.org'
$username: 'Toto'
}
......
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