Commit 25183046 authored by Ronan's avatar Ronan
Browse files

feat(MainWindow/Contacts): the contacts list can be filtered with the presence level

parent c6d0d188
......@@ -9,11 +9,11 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
m_list << new ContactModel("Cecelia Cyler", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Daniel Elliott", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Effie Forton", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Agnes Hurner", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Agnes Hurner", "", Presence::Offline, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Luke Lemin", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Claire Manning", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Isabella Ahornton", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Mary Boreno", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Mary Boreno", "", Presence::Offline, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Aman Than", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel(" abdoul", "", Presence::Online, QStringList("toto.linphone.sip.linphone.org"));
......
......@@ -54,7 +54,11 @@ bool ContactsListProxyModel::filterAcceptsRow (int source_row, const QModelIndex
int weight = m_weights[contact] = static_cast<int>(
computeContactWeight(*contact)
);
return weight > 0;
return weight > 0 && (
!m_use_connected_filter ||
contact->getPresenceLevel() != Presence::PresenceLevel::White
);
}
bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
......@@ -124,3 +128,15 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
return weight;
}
// -------------------------------------------------------------------
bool ContactsListProxyModel::isConnectedFilterUsed () const {
return m_use_connected_filter;
}
void ContactsListProxyModel::setConnectedFilter (bool useConnectedFilter) {
m_use_connected_filter = useConnectedFilter;
qDebug() << useConnectedFilter;
invalidate();
}
......@@ -10,6 +10,13 @@
class ContactsListProxyModel : public QSortFilterProxyModel {
Q_OBJECT;
Q_PROPERTY(
bool useConnectedFilter
READ isConnectedFilterUsed
WRITE setConnectedFilter
CONSTANT
);
public:
ContactsListProxyModel (QObject *parent = Q_NULLPTR);
static void initContactsListModel (ContactsListModel *list);
......@@ -22,6 +29,9 @@ private:
float computeStringWeight (const QString &string, float percentage) const;
float computeContactWeight (const ContactModel &contact) const;
bool isConnectedFilterUsed () const;
void setConnectedFilter (bool useConnectedFilter);
static const QRegExp m_search_separators;
// The contacts list is shared between `ContactsListProxyModel`
......@@ -31,6 +41,8 @@ private:
// It's just a cache to save values computed by `filterAcceptsRow`
// and reused by `lessThan`.
mutable QHash<const ContactModel *, int> m_weights;
bool m_use_connected_filter;
};
#endif // CONTACTS_LIST_PROXY_MODEL_H
......@@ -5,6 +5,8 @@ import Linphone.Styles 1.0
// ===================================================================
Row {
id: item
property var texts
property int _selectedButton: 0
......@@ -32,7 +34,7 @@ Row {
onClicked: {
if (_selectedButton !== index) {
_selectedButton = index
clicked(index)
item.clicked(index)
}
}
}
......
......@@ -43,6 +43,8 @@ ColumnLayout {
qsTr('selectAllContacts'),
qsTr('selectConnectedContacts')
]
onClicked: contacts.useConnectedFilter = (button === 1)
}
TextButtonB {
......
......@@ -26,7 +26,7 @@ ColumnLayout {
Avatar {
Layout.fillHeight: true
Layout.preferredWidth: 80
presence: 'connected' // TODO: Use C++.
presenceLevel: Presence.Green // TODO: Use C++.
username: 'Cameron Andrews' // TODO: Use C++.
}
......
......@@ -40,7 +40,7 @@ ApplicationWindow {
Layout.fillHeight: parent.height
id: collapse
onCollapsed: windowStates.state = isCollapsed()
onCollapsed: windowStates.state = collapsed
? 'collapsed'
: ''
}
......
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