Changeset View
Changeset View
Standalone View
Standalone View
smsapp/conversationlistmodel.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * This file is part of KDE Telepathy Chat | 2 | * This file is part of KDE Telepathy Chat | ||
3 | * | 3 | * | ||
4 | * Copyright (C) 2018 Aleix Pol Gonzalez <aleixpol@kde.org> | 4 | * Copyright (C) 2018 Aleix Pol Gonzalez <aleixpol@kde.org> | ||
5 | * Copyright (C) 2018 Simon Redman <simon@ergotech.com> | ||||
5 | * | 6 | * | ||
6 | * This library is free software; you can redistribute it and/or | 7 | * This library is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | 8 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | 10 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | 11 | * | ||
11 | * This library is distributed in the hope that it will be useful, | 12 | * This library is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | |||||
99 | } | 100 | } | ||
100 | 101 | | |||
101 | void ConversationListModel::createRowFromMessage(const QVariantMap& msg, int row) | 102 | void ConversationListModel::createRowFromMessage(const QVariantMap& msg, int row) | ||
102 | { | 103 | { | ||
103 | if (row != 0) | 104 | if (row != 0) | ||
104 | return; | 105 | return; | ||
105 | 106 | | |||
106 | const ConversationMessage message(msg); | 107 | const ConversationMessage message(msg); | ||
107 | if (message.type() == -1) | 108 | if (message.type() == -1) { | ||
108 | { | | |||
109 | // The Android side currently hacks in -1 if something weird comes up | 109 | // The Android side currently hacks in -1 if something weird comes up | ||
110 | // TODO: Remove this hack when MMS support is implemented | 110 | // TODO: Remove this hack when MMS support is implemented | ||
111 | return; | 111 | return; | ||
112 | } | 112 | } | ||
113 | 113 | | |||
114 | bool toadd = false; | 114 | bool toadd = false; | ||
115 | QStandardItem* item = conversationForThreadId(message.threadID()); | 115 | QStandardItem* item = conversationForThreadId(message.threadID()); | ||
116 | if (!item) { | 116 | if (!item) { | ||
117 | toadd = true; | 117 | toadd = true; | ||
118 | item = new QStandardItem(); | 118 | item = new QStandardItem(); | ||
119 | QScopedPointer<KPeople::PersonData> personData(lookupPersonByAddress(message.address())); | 119 | QScopedPointer<KPeople::PersonData> personData(lookupPersonByAddress(message.address())); | ||
120 | if (personData) | 120 | if (personData) { | ||
121 | { | | |||
122 | item->setText(personData->name()); | 121 | item->setText(personData->name()); | ||
123 | item->setIcon(QIcon(personData->photo())); | 122 | item->setIcon(QIcon(personData->photo())); | ||
124 | item->setData(personData->personUri(), PersonUriRole); | 123 | item->setData(personData->personUri(), PersonUriRole); | ||
125 | } | 124 | } else { | ||
126 | else | | |||
127 | { | | |||
128 | item->setData(QString(), PersonUriRole); | 125 | item->setData(QString(), PersonUriRole); | ||
129 | item->setText(message.address()); | 126 | item->setText(message.address()); | ||
130 | } | 127 | } | ||
131 | item->setData(message.threadID(), ConversationIdRole); | 128 | item->setData(message.threadID(), ConversationIdRole); | ||
132 | } | 129 | } | ||
133 | item->setData(message.address(), AddressRole); | 130 | item->setData(message.address(), AddressRole); | ||
134 | item->setData(message.type() == ConversationMessage::MessageTypeSent, FromMeRole); | 131 | item->setData(message.type() == ConversationMessage::MessageTypeSent, FromMeRole); | ||
135 | item->setData(message.body(), Qt::ToolTipRole); | 132 | item->setData(message.body(), Qt::ToolTipRole); | ||
136 | item->setData(message.date(), DateRole); | 133 | item->setData(message.date(), DateRole); | ||
137 | 134 | | |||
138 | if (toadd) | 135 | if (toadd) | ||
139 | appendRow(item); | 136 | appendRow(item); | ||
140 | } | 137 | } | ||
141 | 138 | | |||
142 | KPeople::PersonData* ConversationListModel::lookupPersonByAddress(const QString& address) | 139 | KPeople::PersonData* ConversationListModel::lookupPersonByAddress(const QString& address) | ||
143 | { | 140 | { | ||
144 | int rowIndex = 0; | 141 | int rowIndex = 0; | ||
145 | for (rowIndex = 0; rowIndex < m_people.rowCount(); rowIndex++) | 142 | for (rowIndex = 0; rowIndex < m_people.rowCount(); rowIndex++) { | ||
146 | { | | |||
147 | const QString& uri = m_people.get(rowIndex, KPeople::PersonsModel::PersonUriRole).toString(); | 143 | const QString& uri = m_people.get(rowIndex, KPeople::PersonsModel::PersonUriRole).toString(); | ||
148 | KPeople::PersonData* person = new KPeople::PersonData(uri); | 144 | KPeople::PersonData* person = new KPeople::PersonData(uri); | ||
149 | 145 | | |||
150 | const QString& email = person->email(); | 146 | const QString& email = person->email(); | ||
151 | const QString& phoneNumber = canonicalizePhoneNumber(person->contactCustomProperty("phoneNumber").toString()); | 147 | const QString& phoneNumber = canonicalizePhoneNumber(person->contactCustomProperty("phoneNumber").toString()); | ||
152 | 148 | | |||
153 | if (address == email || canonicalizePhoneNumber(address) == phoneNumber) | 149 | if (address == email || canonicalizePhoneNumber(address) == phoneNumber) { | ||
154 | { | | |||
155 | qCDebug(KDECONNECT_SMS_CONVERSATIONS_LIST_MODEL) << "Matched" << address << "to" << person->name(); | 150 | qCDebug(KDECONNECT_SMS_CONVERSATIONS_LIST_MODEL) << "Matched" << address << "to" << person->name(); | ||
156 | return person; | 151 | return person; | ||
157 | } | 152 | } | ||
158 | 153 | | |||
159 | delete person; | 154 | delete person; | ||
160 | } | 155 | } | ||
161 | 156 | | |||
162 | return nullptr; | 157 | return nullptr; | ||
Show All 12 Lines |