[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktp-common-internals/mklapetek/SpaceBar] KTp/Declarative: [declarative] Make MainLogModel also an o
From: Martin Klapetek <mklapetek () kde ! org>
Date: 2016-03-09 22:18:29
Message-ID: E1admR3-0002of-B3 () scm ! kde ! org
[Download RAW message or body]
Git commit 0ef01aa909fb615eb39b9b8330ace828b73d92ed by Martin Klapetek.
Committed on 09/03/2016 at 22:15.
Pushed by mklapetek into branch 'mklapetek/SpaceBar'.
[declarative] Make MainLogModel also an observer
This enables to have real-time updates in the model from existing
conversations that are not being handled (eg. new incoming chat that is
not yet approved).
Also makes correcty display the "unread" state
M +30 -2 KTp/Declarative/mainlogmodel.cpp
M +14 -1 KTp/Declarative/mainlogmodel.h
http://commits.kde.org/telepathy-common-internals/0ef01aa909fb615eb39b9b8330ace828b73d92ed
diff --git a/KTp/Declarative/mainlogmodel.cpp b/KTp/Declarative/mainlogmodel.cpp
index a2534b4..d8fdac0 100644
--- a/KTp/Declarative/mainlogmodel.cpp
+++ b/KTp/Declarative/mainlogmodel.cpp
@@ -45,7 +45,8 @@ static inline Tp::ChannelClassSpecList channelClassList()
MainLogModel::MainLogModel(QObject *parent)
: QAbstractListModel(parent),
- Tp::AbstractClientHandler(channelClassList())
+ Tp::AbstractClientHandler(channelClassList()),
+ Tp::AbstractClientObserver(channelClassList(), true)
{
const QString dbLocation = \
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + \
QStringLiteral("/ktp-mobile-logger/");
@@ -196,7 +197,7 @@ bool MainLogModel::canChat(const QString &accountId) const
const QString objectPath = TP_QT_ACCOUNT_OBJECT_PATH_BASE + QLatin1Char('/') + \
accountId;
const Tp::AccountPtr account = \
m_accountManager->accountForObjectPath(objectPath);
- if (account && account->currentPresence().type() != \
Tp::ConnectionPresenceTypeOffline) { + if (!account.isNull() && \
account->currentPresence().type() != Tp::ConnectionPresenceTypeOffline) { return \
true; }
@@ -213,6 +214,11 @@ void MainLogModel::startChat(const QString &accountId, const \
QString &contactId) }
if (m_conversations.contains(accountId + contactId) && \
m_conversations.value(accountId + contactId)->isValid()) { + \
Tp::ChannelDispatchOperationPtr dispatch = m_conversations.value(accountId + \
contactId)->textChannel().data()->property("dispatchOperation").value<Tp::ChannelDispatchOperationPtr>();
+
+ if (!dispatch.isNull()) {
+ dispatch->claim();
+ }
// We already have a conversation, don't request new channel
return;
}
@@ -296,6 +302,28 @@ void MainLogModel::handleChannels(const \
Tp::MethodInvocationContextPtr<> &contex context->setFinished();
}
+void MainLogModel::observeChannels(const Tp::MethodInvocationContextPtr<> &context,
+ const Tp::AccountPtr &account,
+ const Tp::ConnectionPtr &connection,
+ const QList<Tp::ChannelPtr> &channels,
+ const Tp::ChannelDispatchOperationPtr \
&dispatchOperation, + const \
QList<Tp::ChannelRequestPtr> &requestsSatisfied, + \
const Tp::AbstractClientObserver::ObserverInfo &observerInfo) +{
+ Q_UNUSED(context)
+ Q_UNUSED(connection)
+ Q_UNUSED(requestsSatisfied)
+ Q_UNUSED(observerInfo)
+
+ Q_FOREACH(const Tp::ChannelPtr &channel, channels) {
+ Tp::TextChannelPtr textChannel = Tp::TextChannelPtr::dynamicCast(channel);
+ if (textChannel) {
+ textChannel.data()->setProperty("dispatchOperation", \
QVariant::fromValue(dispatchOperation)); + handleChannel(account, \
textChannel); + }
+ }
+}
+
bool MainLogModel::bypassApproval() const
{
return true;
diff --git a/KTp/Declarative/mainlogmodel.h b/KTp/Declarative/mainlogmodel.h
index 5f19d97..8d53463 100644
--- a/KTp/Declarative/mainlogmodel.h
+++ b/KTp/Declarative/mainlogmodel.h
@@ -24,6 +24,8 @@
#include <QSqlQuery>
#include <TelepathyQt/AbstractClientHandler>
+#include <TelepathyQt/AbstractClientObserver>
+#include <TelepathyQt/ChannelDispatchOperation>
#include <KTp/persistent-contact.h>
#include <KTp/types.h>
@@ -39,7 +41,7 @@ public:
Conversation *conversation;
};
-class MainLogModel : public QAbstractListModel, public Tp::AbstractClientHandler
+class MainLogModel : public QAbstractListModel, public Tp::AbstractClientHandler, \
public Tp::AbstractClientObserver {
Q_OBJECT
@@ -77,6 +79,15 @@ public:
const QList<Tp::ChannelRequestPtr> &channelRequests,
const QDateTime &userActionTime,
const HandlerInfo &handlerInfo);
+
+ void observeChannels(const Tp::MethodInvocationContextPtr<> &context,
+ const Tp::AccountPtr &account,
+ const Tp::ConnectionPtr &connection,
+ const QList<Tp::ChannelPtr> &channels,
+ const Tp::ChannelDispatchOperationPtr &dispatchOperation,
+ const QList<Tp::ChannelRequestPtr> &requestsSatisfied,
+ const Tp::AbstractClientObserver::ObserverInfo \
&observerInfo); +
bool bypassApproval() const;
private Q_SLOTS:
@@ -94,4 +105,6 @@ private:
Tp::AccountManagerPtr m_accountManager;
};
+Q_DECLARE_METATYPE(Tp::ChannelDispatchOperationPtr)
+
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic