Commit 25183046 authored by Ronan Abhamon's avatar Ronan Abhamon

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