-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontactlistmodel.cpp
More file actions
80 lines (64 loc) · 1.98 KB
/
contactlistmodel.cpp
File metadata and controls
80 lines (64 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "contactlistmodel.h"
#include <QTimer>
#include <QDebug>
#include <re.h>
#include <baresip.h>
void ContactListModel::update() {
//qInfo() << "ContactListModel::update" << rowCount() << topleft << bottomright;
//emit dataChanged(topleft, bottomright);
/*pl foo;
pl_set_str(&foo, "\"cool dname\" <sip:test@example.com>");
contact_add(baresip_contacts(), 0, &foo);
*/
beginResetModel();
endResetModel();
}
ContactListModel::ContactListModel()
{
QTimer* timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
}
int ContactListModel::rowCount(const QModelIndex &parent) const
{
struct contacts* c = baresip_contacts();
struct list* cl = contact_list(c);
return list_count(cl);
}
QVariant ContactListModel::data(const QModelIndex &index, int role) const
{
Q_ASSERT(index.column() == 0);
struct contacts* c = baresip_contacts();
struct list* cl = contact_list(c);
struct le* entry = cl->head;
for (int i = 0; i < index.row(); i++) {
entry = entry->next;
if (!entry) {
qWarning() << "Accessing invalid index " << index.row() << "of contact list";
return 0;
}
}
switch (role) {
case NameRole: {
struct pl dname = contact_addr((contact*) entry)->dname;
return QLatin1String(dname.p, dname.l);
}
case URIRole: {
struct pl uri = contact_addr((contact*) entry)->auri;
return QLatin1String(uri.p, uri.l);
}
case PresenceStatusRole:
return contact_presence((contact*) entry);
default:
qWarning() << "ContactListModel: Accessing unknown role" << role;
return 0;
}
}
QHash<int, QByteArray> ContactListModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[NameRole] = "dname";
roles[PresenceStatusRole] = "presence";
roles[URIRole] = "uri";
return roles;
}