Changeset View
Changeset View
Standalone View
Standalone View
smsapp/conversationlistmodel.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
47 | 47 | | |||
48 | void ConversationListModel::setDeviceId(const QString& deviceId) | 48 | void ConversationListModel::setDeviceId(const QString& deviceId) | ||
49 | { | 49 | { | ||
50 | qCCritical(KDECONNECT_SMS_CONVERSATIONS_LIST_MODEL) << "setDeviceId" << deviceId << "of" << this; | 50 | qCCritical(KDECONNECT_SMS_CONVERSATIONS_LIST_MODEL) << "setDeviceId" << deviceId << "of" << this; | ||
51 | if (deviceId == m_deviceId) | 51 | if (deviceId == m_deviceId) | ||
52 | return; | 52 | return; | ||
53 | 53 | | |||
54 | if (m_conversationsInterface) { | 54 | if (m_conversationsInterface) { | ||
55 | disconnect(m_conversationsInterface, SIGNAL(conversationCreated(QString)), this, SLOT(handleCreatedConversation(QString))); | 55 | disconnect(m_conversationsInterface, SIGNAL(conversationCreated(QVariantMap)), this, SLOT(handleCreatedConversation(QVariantMap))); | ||
56 | disconnect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdated(QVariantMap))); | ||||
56 | delete m_conversationsInterface; | 57 | delete m_conversationsInterface; | ||
58 | m_conversationsInterface = nullptr; | ||||
57 | } | 59 | } | ||
58 | 60 | | |||
59 | m_deviceId = deviceId; | 61 | m_deviceId = deviceId; | ||
62 | | ||||
63 | if (deviceId == "") { | ||||
64 | // When the device is first connecting we get junk | ||||
65 | return; | ||||
66 | } | ||||
sredman: What do you think about this being above the checks to delete m_conversationsInterface? That… | |||||
67 | | ||||
60 | m_conversationsInterface = new DeviceConversationsDbusInterface(deviceId, this); | 68 | m_conversationsInterface = new DeviceConversationsDbusInterface(deviceId, this); | ||
61 | connect(m_conversationsInterface, SIGNAL(conversationCreated(QString)), this, SLOT(handleCreatedConversation(QString))); | 69 | connect(m_conversationsInterface, SIGNAL(conversationCreated(QVariantMap)), this, SLOT(handleCreatedConversation(QVariantMap))); | ||
62 | connect(m_conversationsInterface, SIGNAL(conversationMessageReceived(QVariantMap, int)), this, SLOT(createRowFromMessage(QVariantMap, int))); | 70 | connect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdated(QVariantMap))); | ||
63 | prepareConversationsList(); | 71 | prepareConversationsList(); | ||
64 | 72 | | |||
65 | m_conversationsInterface->requestAllConversationThreads(); | 73 | m_conversationsInterface->requestAllConversationThreads(); | ||
66 | } | 74 | } | ||
67 | 75 | | |||
68 | void ConversationListModel::prepareConversationsList() | 76 | void ConversationListModel::prepareConversationsList() | ||
69 | { | 77 | { | ||
70 | | ||||
71 | QDBusPendingReply<QStringList> validThreadIDsReply = m_conversationsInterface->activeConversations(); | | |||
72 | | ||||
73 | setWhenAvailable(validThreadIDsReply, [this](const QStringList& convs) { | | |||
74 | clear(); | 78 | clear(); | ||
75 | for (const QString& conversationId : convs) { | 79 | QDBusPendingReply<QVariantList> validThreadIDsReply = m_conversationsInterface->activeConversations(); | ||
76 | handleCreatedConversation(conversationId); | 80 | | ||
81 | setWhenAvailable(validThreadIDsReply, [this](const QVariantList& convs) { | ||||
82 | for (const QVariant& headMessage : convs) { | ||||
83 | QDBusArgument data = headMessage.value<QDBusArgument>(); | ||||
84 | QVariantMap message; | ||||
85 | data >> message; | ||||
86 | handleCreatedConversation(message); | ||||
77 | } | 87 | } | ||
78 | }, this); | 88 | }, this); | ||
79 | } | 89 | } | ||
80 | 90 | | |||
81 | void ConversationListModel::handleCreatedConversation(const QString& conversationId) | 91 | void ConversationListModel::handleCreatedConversation(const QVariantMap& msg) | ||
82 | { | 92 | { | ||
83 | m_conversationsInterface->requestConversation(conversationId, 0, 1); | 93 | createRowFromMessage(msg); | ||
94 | } | ||||
95 | | ||||
96 | void ConversationListModel::handleConversationUpdated(const QVariantMap& msg) | ||||
97 | { | ||||
98 | return; | ||||
apol: leave empty? | |||||
I left this here so I could put a breakpoint on it and decide what to do with the incoming data 😬 Working on filling out this method is my next to-do to solve bug 398818 sredman: I left this here so I could put a breakpoint on it and decide what to do with the incoming data… | |||||
84 | } | 99 | } | ||
85 | 100 | | |||
86 | void ConversationListModel::printDBusError(const QDBusError& error) | 101 | void ConversationListModel::printDBusError(const QDBusError& error) | ||
87 | { | 102 | { | ||
88 | qCWarning(KDECONNECT_SMS_CONVERSATIONS_LIST_MODEL) << error; | 103 | qCWarning(KDECONNECT_SMS_CONVERSATIONS_LIST_MODEL) << error; | ||
89 | } | 104 | } | ||
90 | 105 | | |||
91 | QStandardItem * ConversationListModel::conversationForThreadId(qint32 threadId) | 106 | QStandardItem * ConversationListModel::conversationForThreadId(qint32 threadId) | ||
92 | { | 107 | { | ||
93 | for(int i=0, c=rowCount(); i<c; ++i) { | 108 | for(int i=0, c=rowCount(); i<c; ++i) { | ||
94 | auto it = item(i, 0); | 109 | auto it = item(i, 0); | ||
95 | if (it->data(ConversationIdRole) == threadId) | 110 | if (it->data(ConversationIdRole) == threadId) | ||
96 | return it; | 111 | return it; | ||
97 | } | 112 | } | ||
98 | return nullptr; | 113 | return nullptr; | ||
99 | } | 114 | } | ||
100 | 115 | | |||
101 | void ConversationListModel::createRowFromMessage(const QVariantMap& msg, int row) | 116 | void ConversationListModel::createRowFromMessage(const QVariantMap& msg) | ||
102 | { | 117 | { | ||
103 | if (row != 0) | | |||
104 | return; | | |||
105 | | ||||
106 | const ConversationMessage message(msg); | 118 | const ConversationMessage message(msg); | ||
107 | if (message.type() == -1) | 119 | if (message.type() == -1) | ||
108 | { | 120 | { | ||
109 | // The Android side currently hacks in -1 if something weird comes up | 121 | // The Android side currently hacks in -1 if something weird comes up | ||
110 | // TODO: Remove this hack when MMS support is implemented | 122 | // TODO: Remove this hack when MMS support is implemented | ||
111 | return; | 123 | return; | ||
112 | } | 124 | } | ||
113 | 125 | | |||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
What do you think about this being above the checks to delete m_conversationsInterface? That way, when the device is disconnected, you can still browse messages locally cached in the conversationDbusInterface.