mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-25 07:38:11 +00:00
feat(app): supports contacts from sqlite3
This commit is contained in:
parent
9cb733a2b7
commit
5692ec5b0d
6 changed files with 40 additions and 49 deletions
|
|
@ -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 {
|
||||
return m_presence_status;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,12 @@ class ContactModel : public QObject {
|
|||
Q_PROPERTY(
|
||||
QString username
|
||||
READ getUsername
|
||||
WRITE setUsername
|
||||
NOTIFY contactUpdated
|
||||
);
|
||||
|
||||
Q_PROPERTY(
|
||||
QString avatar
|
||||
READ getAvatar
|
||||
WRITE setAvatar
|
||||
NOTIFY contactUpdated
|
||||
);
|
||||
|
||||
|
|
@ -55,26 +53,25 @@ signals:
|
|||
void contactUpdated ();
|
||||
|
||||
private:
|
||||
QString getUsername () const;
|
||||
void setUsername (const QString &username);
|
||||
QString getUsername () const {
|
||||
return Utils::linphoneStringToQString(
|
||||
m_linphone_friend->getName()
|
||||
);
|
||||
}
|
||||
|
||||
QString getAvatar () const;
|
||||
void setAvatar (const QString &avatar);
|
||||
QString getAvatar () const {
|
||||
return "";
|
||||
}
|
||||
|
||||
Presence::PresenceStatus getPresenceStatus () const;
|
||||
Presence::PresenceLevel getPresenceLevel () const;
|
||||
|
||||
QString getSipAddress () const {
|
||||
// FIXME.
|
||||
return "toto@linphone.org";
|
||||
|
||||
return Utils::linphoneStringToQString(
|
||||
m_linphone_friend->getAddress()->asString()
|
||||
);
|
||||
}
|
||||
|
||||
QString m_username;
|
||||
QString m_avatar;
|
||||
Presence::PresenceStatus m_presence_status = Presence::Offline;
|
||||
|
||||
std::shared_ptr<linphone::Friend> m_linphone_friend;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,9 @@ void ContactsListProxyModel::initContactsListModel (ContactsListModel *list) {
|
|||
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);
|
||||
const ContactModel *contact = qvariant_cast<ContactModel *>(
|
||||
index.data()
|
||||
|
|
@ -74,7 +76,7 @@ bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelInde
|
|||
return (
|
||||
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,26 +114,28 @@ float ContactsListProxyModel::computeStringWeight (const QString &string, float
|
|||
}
|
||||
|
||||
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 =
|
||||
contact.m_linphone_friend->getAddresses();
|
||||
|
||||
// FIXME.
|
||||
return 0;
|
||||
weight += computeStringWeight(contact.getSipAddress(), MAIN_SIP_ADDRESS_WEIGHT);
|
||||
auto it = addresses.cbegin();
|
||||
|
||||
// It exists at least one sip address.
|
||||
weight += computeStringWeight(
|
||||
Utils::linphoneStringToQString((*it)->asString()),
|
||||
MAIN_SIP_ADDRESS_WEIGHT
|
||||
);
|
||||
|
||||
// Compute for other addresses.
|
||||
int size = addresses.size();
|
||||
|
||||
return 0;
|
||||
if (size > 1)
|
||||
for (auto it = ++addresses.cbegin(); it != addresses.cend(); ++it)
|
||||
weight += computeStringWeight(
|
||||
Utils::linphoneStringToQString((*it)->asString()),
|
||||
OTHER_SIP_ADDRESSES_WEIGHT / size
|
||||
);
|
||||
for (++it; it != addresses.cend(); ++it)
|
||||
weight += computeStringWeight(
|
||||
Utils::linphoneStringToQString((*it)->asString()),
|
||||
OTHER_SIP_ADDRESSES_WEIGHT / size
|
||||
);
|
||||
|
||||
return weight;
|
||||
}
|
||||
|
|
|
|||
7
tests/src/utils.hpp
Normal file
7
tests/src/utils.hpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <QString>
|
||||
|
||||
namespace Utils {
|
||||
inline QString linphoneStringToQString (const std::string &string) {
|
||||
return QString::fromLocal8Bit(string.c_str(), string.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ Item {
|
|||
property alias presenceLevel: presenceLevel.level
|
||||
property string username
|
||||
|
||||
property var _initialsRegex: /^\s*([^\s]+)(?:\s+([^\s]+))?/
|
||||
property var _initialsRegex: /^\s*([^\s\.]+)(?:[\s\.]+([^\s\.]+))?/
|
||||
|
||||
function _computeInitials () {
|
||||
var result = username.match(_initialsRegex)
|
||||
|
|
@ -22,12 +22,11 @@ Item {
|
|||
'Unable to get initials of: \'' + username + '\''
|
||||
)
|
||||
|
||||
return result[1].charAt(0).toUpperCase() +
|
||||
(
|
||||
result[2] != null
|
||||
? result[2].charAt(0).toUpperCase()
|
||||
: ''
|
||||
)
|
||||
return result[1].charAt(0).toUpperCase() + (
|
||||
result[2] != null
|
||||
? result[2].charAt(0).toUpperCase()
|
||||
: ''
|
||||
)
|
||||
}
|
||||
|
||||
// Image mask. (Circle)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ ColumnLayout {
|
|||
})
|
||||
}
|
||||
|
||||
spacing: Notifier.showCallMessage(5000, "toto@toto.com") || 0
|
||||
spacing: 0
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Search Bar & actions.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue