Changeset View
Changeset View
Standalone View
Standalone View
src/personsmodel.cpp
Show All 34 Lines | |||||
35 | namespace KPeople | 35 | namespace KPeople | ||
36 | { | 36 | { | ||
37 | class PersonsModelPrivate : public QObject | 37 | class PersonsModelPrivate : public QObject | ||
38 | { | 38 | { | ||
39 | Q_OBJECT | 39 | Q_OBJECT | ||
40 | public: | 40 | public: | ||
41 | PersonsModelPrivate(PersonsModel *q) | 41 | PersonsModelPrivate(PersonsModel *q) | ||
42 | : q(q) | 42 | : q(q) | ||
43 | , genericAvatarImagePath(QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kf5/kpeople/dummy_avatar.png"))) | | |||
44 | , initialFetchesDoneCount(0) | 43 | , initialFetchesDoneCount(0) | ||
45 | , isInitialized(false) | 44 | , isInitialized(false) | ||
46 | , hasError(false) | 45 | , hasError(false) | ||
47 | { | 46 | { | ||
48 | } | 47 | } | ||
49 | PersonsModel *const q; | 48 | PersonsModel *const q; | ||
50 | 49 | | |||
51 | //NOTE This is the opposite way round to the return value from contactMapping() for easier lookups | 50 | //NOTE This is the opposite way round to the return value from contactMapping() for easier lookups | ||
52 | QHash<QString /*contactUri*/, QString /*PersonUri*/> contactToPersons; | 51 | QHash<QString /*contactUri*/, QString /*PersonUri*/> contactToPersons; | ||
53 | 52 | | |||
54 | //hash of person objects indexed by ID | 53 | //hash of person objects indexed by ID | ||
55 | QHash<QString /*Person ID*/, QPersistentModelIndex /*Row*/> personIndex; | 54 | QHash<QString /*Person ID*/, QPersistentModelIndex /*Row*/> personIndex; | ||
56 | 55 | | |||
57 | //a list so we have an order in the model | 56 | //a list so we have an order in the model | ||
58 | QVector<MetaContact> metacontacts; | 57 | QVector<MetaContact> metacontacts; | ||
59 | 58 | | |||
60 | QString genericAvatarImagePath; | | |||
61 | QVector<AllContactsMonitorPtr> m_sourceMonitors; | 59 | QVector<AllContactsMonitorPtr> m_sourceMonitors; | ||
62 | 60 | | |||
63 | int initialFetchesDoneCount; | 61 | int initialFetchesDoneCount; | ||
64 | 62 | | |||
65 | bool isInitialized; | 63 | bool isInitialized; | ||
66 | bool hasError; | 64 | bool hasError; | ||
67 | 65 | | |||
68 | //methods that manipulate the model | 66 | //methods that manipulate the model | ||
Show All 36 Lines | 102 | connect(monitor.data(), &AllContactsMonitor::initialFetchComplete, | |||
105 | d, &PersonsModelPrivate::onMonitorInitialFetchComplete); | 103 | d, &PersonsModelPrivate::onMonitorInitialFetchComplete); | ||
106 | } | 104 | } | ||
107 | d->m_sourceMonitors << monitor; | 105 | d->m_sourceMonitors << monitor; | ||
108 | } | 106 | } | ||
109 | d->onContactsFetched(); | 107 | d->onContactsFetched(); | ||
110 | 108 | | |||
111 | connect(PersonManager::instance(), &PersonManager::contactAddedToPerson, d, &PersonsModelPrivate::onAddContactToPerson); | 109 | connect(PersonManager::instance(), &PersonManager::contactAddedToPerson, d, &PersonsModelPrivate::onAddContactToPerson); | ||
112 | connect(PersonManager::instance(), &PersonManager::contactRemovedFromPerson, d, &PersonsModelPrivate::onRemoveContactsFromPerson); | 110 | connect(PersonManager::instance(), &PersonManager::contactRemovedFromPerson, d, &PersonsModelPrivate::onRemoveContactsFromPerson); | ||
111 | | ||||
112 | initResources(); | ||||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | PersonsModel::~PersonsModel() | 115 | PersonsModel::~PersonsModel() | ||
116 | { | 116 | { | ||
117 | } | 117 | } | ||
118 | 118 | | |||
119 | QHash<int, QByteArray> PersonsModel::roleNames() const | 119 | QHash<int, QByteArray> PersonsModel::roleNames() const | ||
120 | { | 120 | { | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 172 | } else if (pic.canConvert<QUrl>() && pic.toUrl().isLocalFile()) { | |||
173 | QPixmap avatar = QPixmap(pic.toUrl().toLocalFile()); | 173 | QPixmap avatar = QPixmap(pic.toUrl().toLocalFile()); | ||
174 | if (!avatar.isNull()) { | 174 | if (!avatar.isNull()) { | ||
175 | return avatar; | 175 | return avatar; | ||
176 | } | 176 | } | ||
177 | } | 177 | } | ||
178 | 178 | | |||
179 | // If none of the above were valid images, | 179 | // If none of the above were valid images, | ||
180 | // return the generic one | 180 | // return the generic one | ||
181 | return QPixmap(genericAvatarImagePath); | 181 | return QPixmap(QStringLiteral(":/org.kde.kpeople/pixmaps/dummy_avatar.png")); | ||
182 | } | 182 | } | ||
183 | case PersonsModel::PersonUriRole: | 183 | case PersonsModel::PersonUriRole: | ||
184 | return personUri; | 184 | return personUri; | ||
185 | case PersonsModel::PersonVCardRole: | 185 | case PersonsModel::PersonVCardRole: | ||
186 | return QVariant::fromValue<AbstractContact::Ptr>(person); | 186 | return QVariant::fromValue<AbstractContact::Ptr>(person); | ||
187 | case PersonsModel::ContactsVCardRole: | 187 | case PersonsModel::ContactsVCardRole: | ||
188 | return QVariant::fromValue<AbstractContact::List>(metacontacts[personIndex[personUri].row()].contacts()); | 188 | return QVariant::fromValue<AbstractContact::List>(metacontacts[personIndex[personUri].row()].contacts()); | ||
189 | case PersonsModel::GroupsRole: | 189 | case PersonsModel::GroupsRole: | ||
▲ Show 20 Lines • Show All 311 Lines • Show Last 20 Lines |