Commit 5692ec5b authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): supports contacts from sqlite3

parent 9cb733a2
...@@ -2,22 +2,6 @@ ...@@ -2,22 +2,6 @@
// =================================================================== // ===================================================================
QString ContactModel::getUsername () const {
return m_username;
}
void ContactModel::setUsername (const QString &username) {
m_username = username;
}
QString ContactModel::getAvatar () const {
return m_avatar;
}
void ContactModel::setAvatar (const QString &avatar) {
m_avatar = avatar;
}
Presence::PresenceStatus ContactModel::getPresenceStatus () const { Presence::PresenceStatus ContactModel::getPresenceStatus () const {
return m_presence_status; return m_presence_status;
} }
......
...@@ -17,14 +17,12 @@ class ContactModel : public QObject { ...@@ -17,14 +17,12 @@ class ContactModel : public QObject {
Q_PROPERTY( Q_PROPERTY(
QString username QString username
READ getUsername READ getUsername
WRITE setUsername
NOTIFY contactUpdated NOTIFY contactUpdated
); );
Q_PROPERTY( Q_PROPERTY(
QString avatar QString avatar
READ getAvatar READ getAvatar
WRITE setAvatar
NOTIFY contactUpdated NOTIFY contactUpdated
); );
...@@ -55,26 +53,25 @@ signals: ...@@ -55,26 +53,25 @@ signals:
void contactUpdated (); void contactUpdated ();
private: private:
QString getUsername () const; QString getUsername () const {
void setUsername (const QString &username); return Utils::linphoneStringToQString(
m_linphone_friend->getName()
);
}
QString getAvatar () const; QString getAvatar () const {
void setAvatar (const QString &avatar); return "";
}
Presence::PresenceStatus getPresenceStatus () const; Presence::PresenceStatus getPresenceStatus () const;
Presence::PresenceLevel getPresenceLevel () const; Presence::PresenceLevel getPresenceLevel () const;
QString getSipAddress () const { QString getSipAddress () const {
// FIXME.
return "toto@linphone.org";
return Utils::linphoneStringToQString( return Utils::linphoneStringToQString(
m_linphone_friend->getAddress()->asString() m_linphone_friend->getAddress()->asString()
); );
} }
QString m_username;
QString m_avatar;
Presence::PresenceStatus m_presence_status = Presence::Offline; Presence::PresenceStatus m_presence_status = Presence::Offline;
std::shared_ptr<linphone::Friend> m_linphone_friend; std::shared_ptr<linphone::Friend> m_linphone_friend;
......
...@@ -45,7 +45,9 @@ void ContactsListProxyModel::initContactsListModel (ContactsListModel *list) { ...@@ -45,7 +45,9 @@ void ContactsListProxyModel::initContactsListModel (ContactsListModel *list) {
qWarning() << "Contacts list model is already defined."; qWarning() << "Contacts list model is already defined.";
} }
bool ContactsListProxyModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const { bool ContactsListProxyModel::filterAcceptsRow (
int source_row, const QModelIndex &source_parent
) const {
QModelIndex index = sourceModel()->index(source_row, 0, source_parent); QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
const ContactModel *contact = qvariant_cast<ContactModel *>( const ContactModel *contact = qvariant_cast<ContactModel *>(
index.data() index.data()
...@@ -74,7 +76,7 @@ bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelInde ...@@ -74,7 +76,7 @@ bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelInde
return ( return (
weight_a > weight_b || ( weight_a > weight_b || (
weight_a == weight_b && weight_a == weight_b &&
contact_a->m_username <= contact_b->m_username contact_a->m_linphone_friend->getName() <= contact_b->m_linphone_friend->getName()
) )
); );
} }
...@@ -112,22 +114,24 @@ float ContactsListProxyModel::computeStringWeight (const QString &string, float ...@@ -112,22 +114,24 @@ float ContactsListProxyModel::computeStringWeight (const QString &string, float
} }
float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) const { float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) const {
float weight = computeStringWeight(contact.m_username, USERNAME_WEIGHT); float weight = computeStringWeight(contact.getUsername(), USERNAME_WEIGHT);
// It exists at least one sip address. // Get all contact's addresses.
const std::list<std::shared_ptr<linphone::Address> > addresses = const std::list<std::shared_ptr<linphone::Address> > addresses =
contact.m_linphone_friend->getAddresses(); contact.m_linphone_friend->getAddresses();
// FIXME. auto it = addresses.cbegin();
return 0;
weight += computeStringWeight(contact.getSipAddress(), MAIN_SIP_ADDRESS_WEIGHT); // It exists at least one sip address.
weight += computeStringWeight(
Utils::linphoneStringToQString((*it)->asString()),
MAIN_SIP_ADDRESS_WEIGHT
);
// Compute for other addresses. // Compute for other addresses.
int size = addresses.size(); int size = addresses.size();
return 0; for (++it; it != addresses.cend(); ++it)
if (size > 1)
for (auto it = ++addresses.cbegin(); it != addresses.cend(); ++it)
weight += computeStringWeight( weight += computeStringWeight(
Utils::linphoneStringToQString((*it)->asString()), Utils::linphoneStringToQString((*it)->asString()),
OTHER_SIP_ADDRESSES_WEIGHT / size OTHER_SIP_ADDRESSES_WEIGHT / size
......
#include <QString>
namespace Utils {
inline QString linphoneStringToQString (const std::string &string) {
return QString::fromLocal8Bit(string.c_str(), string.size());
}
}
...@@ -12,7 +12,7 @@ Item { ...@@ -12,7 +12,7 @@ Item {
property alias presenceLevel: presenceLevel.level property alias presenceLevel: presenceLevel.level
property string username property string username
property var _initialsRegex: /^\s*([^\s]+)(?:\s+([^\s]+))?/ property var _initialsRegex: /^\s*([^\s\.]+)(?:[\s\.]+([^\s\.]+))?/
function _computeInitials () { function _computeInitials () {
var result = username.match(_initialsRegex) var result = username.match(_initialsRegex)
...@@ -22,8 +22,7 @@ Item { ...@@ -22,8 +22,7 @@ Item {
'Unable to get initials of: \'' + username + '\'' 'Unable to get initials of: \'' + username + '\''
) )
return result[1].charAt(0).toUpperCase() + return result[1].charAt(0).toUpperCase() + (
(
result[2] != null result[2] != null
? result[2].charAt(0).toUpperCase() ? result[2].charAt(0).toUpperCase()
: '' : ''
......
...@@ -36,7 +36,7 @@ ColumnLayout { ...@@ -36,7 +36,7 @@ ColumnLayout {
}) })
} }
spacing: Notifier.showCallMessage(5000, "toto@toto.com") || 0 spacing: 0
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// Search Bar & actions. // Search Bar & actions.
......
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