[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:04:50 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=4e2e6da

The following commit has been merged in the master branch:
commit 4e2e6dafce53f0094f678c3c8fbb6b6b10de7d57
Author: Lasath Fernando <kde at lasath.org>
Date:   Tue Dec 20 23:51:00 2011 +1100

    Further work on chat plasmoid
---
 KTp/Declarative/conversation-target.cpp     |  14 +++-
 KTp/Declarative/conversation-target.h       |   2 +
 KTp/Declarative/conversation.h              |   3 +-
 KTp/Declarative/conversations-model.cpp     |  17 +++-
 KTp/Declarative/messages-model.cpp          | 120 +++++++++++++++++++++++-----
 KTp/Declarative/messages-model.h            |  14 +++-
 KTp/Declarative/telepathy-text-observer.cpp |  27 +++----
 KTp/Declarative/telepathy-text-observer.h   |   2 +-
 8 files changed, 155 insertions(+), 44 deletions(-)

diff --git a/KTp/Declarative/conversation-target.cpp b/KTp/Declarative/conversation-target.cpp
index 7b9e554..9316243 100644
--- a/KTp/Declarative/conversation-target.cpp
+++ b/KTp/Declarative/conversation-target.cpp
@@ -22,6 +22,7 @@
 #include <TelepathyQt4/AvatarData>
 #include <TelepathyQt4/Presence>
 #include <KDebug>
+#include <KIconLoader>
 
 class  ConversationTarget::ConversationTargetPrivate
 {
@@ -50,8 +51,17 @@ void ConversationTarget::setupContactSignals(Tp::ContactPtr contact)
 
 QIcon ConversationTarget::avatar() const
 {
-    //FIXME: return KIcon("im-user") if avatar is unavailable
-    return QIcon(d->contact->avatarData().fileName);
+    QString path = d->contact->avatarData().fileName;
+
+    if(path.isEmpty()) {
+        return KIcon(QLatin1String("im-user"));
+    } else {
+        return QIcon(path);
+    }
+}
+QString ConversationTarget::id() const
+{
+    return d->contact->id();
 }
 
 QString ConversationTarget::nick() const
diff --git a/KTp/Declarative/conversation-target.h b/KTp/Declarative/conversation-target.h
index 4af5a47..8922ef4 100644
--- a/KTp/Declarative/conversation-target.h
+++ b/KTp/Declarative/conversation-target.h
@@ -36,6 +36,7 @@ Q_PROPERTY(QIcon avatar READ avatar NOTIFY avatarChanged);
 Q_PROPERTY(QString nick READ nick NOTIFY nickChanged);
 Q_PROPERTY(QIcon presenceIcon READ presenceIcon NOTIFY presenceIconChanged);
 Q_PROPERTY(QString presenceIconSource READ presenceIconSource NOTIFY presenceIconSourceChanged);
+Q_PROPERTY(QString id READ id)
 
 //turns out you can't have non QObjects as properties
 // Q_PROPERTY(Tp::ContactPtr contact READ contact WRITE setContact NOTIFY contactChanged);
@@ -45,6 +46,7 @@ public:
     virtual ~ConversationTarget();
 
     QIcon   avatar() const;
+    QString id() const;
     QString nick() const;
     QIcon   presenceIcon() const;
     QString presenceIconSource() const;
diff --git a/KTp/Declarative/conversation.h b/KTp/Declarative/conversation.h
index 65e77bc..71c1835 100644
--- a/KTp/Declarative/conversation.h
+++ b/KTp/Declarative/conversation.h
@@ -27,7 +27,6 @@
 #include <TelepathyQt/TextChannel>
 // #include "conversation-model.h"
 #include <KIcon>
-#include "conversation-target.h"
 
 class ConversationTarget;
 class MessagesModel;
@@ -38,12 +37,12 @@ Q_OBJECT
 Q_PROPERTY(MessagesModel* model READ model NOTIFY modelChanged);
 Q_PROPERTY(ConversationTarget* target READ target NOTIFY targetChanged);
 
-
 public:
     Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account);
     Conversation(QObject* parent = 0);
     virtual ~Conversation();
 
+    //FIXME: rename model to messages
     MessagesModel* model() const;
     ConversationTarget* target() const;
 
diff --git a/KTp/Declarative/conversations-model.cpp b/KTp/Declarative/conversations-model.cpp
index 9166541..2c40659 100644
--- a/KTp/Declarative/conversations-model.cpp
+++ b/KTp/Declarative/conversations-model.cpp
@@ -21,6 +21,8 @@
 #include "conversation.h"
 #include "telepathy-text-observer.h"
 #include <KDebug>
+#include "conversation-target.h"
+#include "messages-model.h"
 
 class ConversationsModel::ConversationsModelPrivate
 {
@@ -57,10 +59,19 @@ ConversationsModel::ConversationsModel() :
 
 void ConversationsModel::onInconmingConversation ( Conversation* convo )
 {
-    beginInsertRows(QModelIndex(), rowCount(), rowCount());
+    bool found = false;
+    Q_FOREACH(Conversation *con, d->data) {
+        if(con->target()->id() == convo->target()->id()) {
+            con->model()->setTextChannel(convo->model()->textChannel());
+            found = true;
+        }
+    }
 
-    d->data.append(convo);
-    endInsertRows();
+    if(!found) {
+        beginInsertRows(QModelIndex(), rowCount(), rowCount());
+        d->data.append(convo);
+        endInsertRows();
+    }
 }
 
 ConversationsModel::~ConversationsModel()
diff --git a/KTp/Declarative/messages-model.cpp b/KTp/Declarative/messages-model.cpp
index e377a84..b636f90 100644
--- a/KTp/Declarative/messages-model.cpp
+++ b/KTp/Declarative/messages-model.cpp
@@ -27,6 +27,7 @@ public:
     QString user;
     QString text;
     QDateTime time;
+    QString id;
 
     //FIXME : replace with Tp::ChannelTextMessageType
     enum MessageType {
@@ -34,12 +35,21 @@ public:
         Outgoing,
         Status
     } type;
+
+    MessageItem(QString user, QString text, QDateTime time, MessageType type, QString messageId)
+     : user(user), text(text), time(time), type(type), id(messageId)
+    {
+        if(this->text.endsWith(QLatin1String("
"))) {
+            this->text.chop(1);
+        }
+    }
 };
 
 class MessagesModel::ConversationModelPrivate {
 public:
     Tp::TextChannelPtr textChannel;
     QList<MessageItem> messages;
+    bool visible;
 };
 
 MessagesModel::MessagesModel(QObject* parent):
@@ -54,6 +64,8 @@ MessagesModel::MessagesModel(QObject* parent):
     roles[TimeRole] = "time";
     roles[TypeRole] = "type";
     setRoleNames(roles);
+
+    d->visible = false;
 }
 
 Tp::TextChannelPtr MessagesModel::textChannel()
@@ -63,11 +75,11 @@ Tp::TextChannelPtr MessagesModel::textChannel()
 
 bool MessagesModel::verifyPendingOperation ( Tp::PendingOperation* op )
 {
-    bool success = !op->isError();
-    if(!success) {
+    if(op->isError()) {
         kWarning() << op->errorName() << "+" << op->errorMessage();
+        return false;
     }
-    return success;
+    return true;
 }
 
 void MessagesModel::setupChannelSignals(Tp::TextChannelPtr channel)
@@ -91,41 +103,68 @@ void MessagesModel::setTextChannel(Tp::TextChannelPtr channel)
     //FIXME: check messageQue for any lost messages
     d->textChannel = channel;
 
-    textChannelChanged(channel);
+    Q_EMIT textChannelChanged(channel);
+
+    QList<Tp::ReceivedMessage> que = channel->messageQueue();
+    Q_FOREACH(Tp::ReceivedMessage message, que) {
+        bool messageAlreadyInModel = false;
+        Q_FOREACH(MessageItem current, d->messages) {
+            if(current.id == message.messageToken()) {
+                messageAlreadyInModel = true;
+            }
+        }
+        if(!messageAlreadyInModel) {
+            onMessageReceived(message);
+        }
+    }
 }
 
 void MessagesModel::onMessageReceived(Tp::ReceivedMessage message)
 {
-    kDebug() << "unreadMessagesCount = " << d->textChannel->messageQueue().size();
-    int length = rowCount();
-    beginInsertRows(QModelIndex(), length, length);
-
-    MessageItem newMessage = {
-        message.sender()->alias(),
-        message.text(),
-        message.received(),
-        MessageItem::Incoming
-    };
+    int unreadCount = d->textChannel->messageQueue().size();
+    kDebug() << "unreadMessagesCount =" << unreadCount;
+    kDebug() << "text =" << message.text();
+
+    if(message.messageType() == Tp::ChannelTextMessageTypeNormal) {
+        int length = rowCount();
+        beginInsertRows(QModelIndex(), length, length);
+
+        d->messages.append(MessageItem(
+                message.sender()->alias(),
+                message.text(),
+                message.received(),
+                MessageItem::Incoming,
+                message.messageToken()
+        ));
+
+        endInsertRows();
+
+        if(d->visible) {
+            acknowledgeAllMessages();
+        } else {
+            Q_EMIT unreadCountChanged(unreadCount);
+        }
+    }
 
-    d->messages.append(newMessage);
-    endInsertRows();
 }
 
 void MessagesModel::onMessageSent(Tp::Message message, Tp::MessageSendingFlags flags, QString token)
 {
     Q_UNUSED(flags);
     Q_UNUSED(token);
+
     int length = rowCount();
     beginInsertRows(QModelIndex(), length, length);
+    kDebug() << "text =" << message.text();
 
-    MessageItem newMessage = {
+    d->messages.append(MessageItem(
         tr("Me"),   //FIXME : use actual nickname from Tp::AccountPtr
         message.text(),
         message.sent(),
-        MessageItem::Outgoing
-    };
+        MessageItem::Outgoing,
+        message.messageToken()
+    ));
 
-    d->messages.append(newMessage);
     endInsertRows();
 }
 
@@ -192,10 +231,51 @@ void MessagesModel::removeChannelSignals(Tp::TextChannelPtr channel)
                     );
 }
 
+int MessagesModel::unreadCount() const
+{
+    return d->textChannel->messageQueue().size();
+}
+
+void MessagesModel::acknowledgeAllMessages()
+{
+    QList<Tp::ReceivedMessage> que = d->textChannel->messageQueue();
+
+    kDebug() << "Conversation Visible, Acknowledging " << que.size() << " messages.";
+
+    d->textChannel->acknowledge(que);
+    Q_EMIT unreadCountChanged(que.size());
+}
+
+void MessagesModel::setVisibleToUser(bool visible)
+{
+    kDebug() << visible;
+
+    if(d->visible != visible) {
+        d->visible = visible;
+        Q_EMIT visibleToUserChanged(visible);
+    }
+
+    if(visible) {
+        acknowledgeAllMessages();
+    }
+}
+
+bool MessagesModel::isVisibleToUser() const
+{
+    return d->visible;
+}
+
 MessagesModel::~MessagesModel()
 {
     kDebug();
     delete d;
 }
 
+void MessagesModel::printallmessages()
+{
+    Q_FOREACH(MessageItem msg, d->messages) {
+        kDebug() << msg.text;
+    }
+}
+
 #include "moc_messages-model.cpp"
diff --git a/KTp/Declarative/messages-model.h b/KTp/Declarative/messages-model.h
index 6ce698a..3328f31 100644
--- a/KTp/Declarative/messages-model.h
+++ b/KTp/Declarative/messages-model.h
@@ -29,6 +29,9 @@
 class KDE_TELEPATHY_CHAT_EXPORT MessagesModel : public QAbstractListModel
 {
 Q_OBJECT
+Q_PROPERTY(bool visibleToUser READ isVisibleToUser WRITE setVisibleToUser NOTIFY visibleToUserChanged);
+Q_PROPERTY(int unreadCount READ unreadCount NOTIFY unreadCountChanged);
+//turns out you can't have a non QObject as a property
 // Q_PROPERTY(Tp::TextChannelPtr textChannel
 // 			READ textChannel
 // 			WRITE setTextChannel
@@ -52,8 +55,17 @@ public:
 	Tp::TextChannelPtr textChannel();
 	void setTextChannel(Tp::TextChannelPtr channel);
 
+    bool isVisibleToUser() const;
+    void setVisibleToUser(bool visible);
+
+    void acknowledgeAllMessages();
+    int unreadCount() const;
+
+    Q_INVOKABLE void printallmessages();
 Q_SIGNALS:
-	void textChannelChanged(Tp::TextChannelPtr newChannel);
+    void textChannelChanged(Tp::TextChannelPtr newChannel);
+    void visibleToUserChanged(bool visible);
+    void unreadCountChanged(int unreadMesssagesCount);
 
 public Q_SLOTS:
     Tp::PendingSendMessage* sendNewMessage(QString message);
diff --git a/KTp/Declarative/telepathy-text-observer.cpp b/KTp/Declarative/telepathy-text-observer.cpp
index 7a9c575..3354905 100644
--- a/KTp/Declarative/telepathy-text-observer.cpp
+++ b/KTp/Declarative/telepathy-text-observer.cpp
@@ -67,6 +67,7 @@ public:
         AbstractClientObserver(channelClassList()),
         m_parent(parent)
     {
+
     }
 
     TelepathyTextObserver *m_parent;
@@ -79,42 +80,38 @@ TelepathyTextObserver::TelepathyTextObserver() :
     kDebug();
     Tp::registerTypes();
     Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(),
-                                                                      Tp::Account::FeatureCore);
+                                                                    Tp::Account::FeatureCore);
 
     Tp::ConnectionFactoryPtr  connectionFactory = Tp::ConnectionFactory::create(
         QDBusConnection::sessionBus(),
         Tp::Features() << Tp::Connection::FeatureSelfContact
-                       << Tp::Connection::FeatureCore
+                    << Tp::Connection::FeatureCore
     );
 
     Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
     channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
 
     Tp::Features textFeatures = Tp::Features() << Tp::TextChannel::FeatureMessageQueue
-                                               << Tp::TextChannel::FeatureMessageSentSignal
-                                               << Tp::TextChannel::FeatureChatState
-                                               << Tp::TextChannel::FeatureMessageCapabilities;
+                                            << Tp::TextChannel::FeatureMessageSentSignal
+                                            << Tp::TextChannel::FeatureChatState
+                                            << Tp::TextChannel::FeatureMessageCapabilities;
     channelFactory->addFeaturesForTextChats(textFeatures);
     channelFactory->addFeaturesForTextChatrooms(textFeatures);
 
     Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(
         Tp::Features() << Tp::Contact::FeatureAlias
-                       << Tp::Contact::FeatureAvatarToken
-                       << Tp::Contact::FeatureAvatarData
-                       << Tp::Contact::FeatureCapabilities
-                       << Tp::Contact::FeatureSimplePresence
+                    << Tp::Contact::FeatureAvatarToken
+                    << Tp::Contact::FeatureAvatarData
+                    << Tp::Contact::FeatureCapabilities
+                    << Tp::Contact::FeatureSimplePresence
     );
 
     //TODO: check these to make sure I'm only requesting features I actually use.
     d->registrar = Tp::ClientRegistrar::create(accountFactory, connectionFactory,
-                                               channelFactory, contactFactory);
-
+                                            channelFactory, contactFactory);
     d->registrar->registerClient(d, QLatin1String("KDE.TextUi.ConversationWatcher"));
 }
 
-
 TelepathyTextObserver::~TelepathyTextObserver()
 {
-}
-
-// #include "moc_conversation-watcher.cpp"
+}
\ No newline at end of file
diff --git a/KTp/Declarative/telepathy-text-observer.h b/KTp/Declarative/telepathy-text-observer.h
index 9025081..0815750 100644
--- a/KTp/Declarative/telepathy-text-observer.h
+++ b/KTp/Declarative/telepathy-text-observer.h
@@ -38,7 +38,7 @@ Q_SIGNALS:
 	void newConversation(Conversation *con);
 private:
 	class ConversationClientObserver;
-	Tp::SharedPtr<ConversationClientObserver> d;
+	Tp::SharedPtr<ConversationClientObserver> d /*= Tp::SharedPtr<ConversationClientObserver>()*/;
 };
 
 #endif // CONVERSATION_WATCHER_H

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list