[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:20:57 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=9d5204b
The following commit has been merged in the master branch:
commit 9d5204ba8a4a4ea29da478949ea69f0ec992f243
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Mon Jan 30 23:31:57 2012 +0000
Fix duplication of messages model
---
lib/CMakeLists.txt | 2 -
lib/messages-model.cpp | 295 -------------------------------------------------
lib/messages-model.h | 85 --------------
3 files changed, 382 deletions(-)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index d778d1a..fa89481 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -16,7 +16,6 @@ set(ktpchat_SRCS
chat-text-edit.cpp
chat-search-bar.cpp
logmanager.cpp
- messages-model.cpp
telepathy-text-observer.cpp
)
@@ -34,7 +33,6 @@ set(ktpchat_HDRS
conversation-target.h
conversation-que-manager.h
conversations-model.h
- messages-model.h
telepathy-text-observer.h
)
diff --git a/lib/messages-model.cpp b/lib/messages-model.cpp
deleted file mode 100644
index 3b4d4db..0000000
--- a/lib/messages-model.cpp
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- Copyright (C) 2011 Lasath Fernando <kde at lasath.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-
-#include "messages-model.h"
-
-#include <KDebug>
-#include <TelepathyQt/ReceivedMessage>
-
-class MessageItem
-{
-public:
- QString user;
- QString text;
- QDateTime time;
- QString id;
-
- //FIXME : replace with Tp::ChannelTextMessageType
- enum MessageType {
- Incoming,
- Outgoing,
- Status
- } type;
-
- MessageItem(QString user, QString text, QDateTime time, MessageType type, QString messageId)
- : user(user), text(text), time(time), id(messageId), type(type) {
- if (this->text.endsWith(QLatin1String("
"))) {
- this->text.chop(1);
- }
- }
-};
-
-class MessagesModel::MessagesModelPrivate
-{
-public:
- Tp::TextChannelPtr textChannel;
- QList<MessageItem> messages;
- bool visible;
-};
-
-MessagesModel::MessagesModel(QObject *parent):
- QAbstractListModel(parent),
- d(new MessagesModelPrivate)
-{
- kDebug();
-
- QHash<int, QByteArray> roles;
- roles[UserRole] = "user";
- roles[TextRole] = "text";
- roles[TimeRole] = "time";
- roles[TypeRole] = "type";
- setRoleNames(roles);
-
- d->visible = false;
-}
-
-Tp::TextChannelPtr MessagesModel::textChannel()
-{
- return d->textChannel;
-}
-
-bool MessagesModel::verifyPendingOperation(Tp::PendingOperation *op)
-{
- bool operationSucceeded = true;
-
- if (op->isError()) {
- kWarning() << op->errorName() << "+" << op->errorMessage();
- operationSucceeded = false;
- }
-
- return operationSucceeded;
-}
-
-void MessagesModel::setupChannelSignals(Tp::TextChannelPtr channel)
-{
- QObject::connect(channel.data(),
- SIGNAL(messageReceived(Tp::ReceivedMessage)),
- SLOT(onMessageReceived(Tp::ReceivedMessage)));
- QObject::connect(channel.data(),
- SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
- SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
-}
-
-void MessagesModel::setTextChannel(Tp::TextChannelPtr channel)
-{
- kDebug();
- setupChannelSignals(channel);
-
- if (d->textChannel) {
- removeChannelSignals(d->textChannel);
- }
-
- d->textChannel = channel;
- Q_EMIT textChannelChanged(d->textChannel);
-
- QList<Tp::ReceivedMessage> messageQueue = channel->messageQueue();
- Q_FOREACH(Tp::ReceivedMessage message, messageQueue) {
- bool messageAlreadyInModel = false;
- Q_FOREACH(MessageItem current, d->messages) {
- //FIXME: docs say messageToken can return an empty string. What to do if that happens?
- //Tp::Message has an == operator. maybe I can use that?
- if (current.id == message.messageToken()) {
- messageAlreadyInModel = true;
- break;
- }
- }
- if (!messageAlreadyInModel) {
- onMessageReceived(message);
- }
- }
-}
-
-void MessagesModel::onMessageReceived(Tp::ReceivedMessage message)
-{
- int unreadCount = d->textChannel->messageQueue().size();
- kDebug() << "unreadMessagesCount =" << unreadCount;
- kDebug() << "text =" << message.text();
- kDebug() << "messageToken =" << message.messageToken();
-
- 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 {
- enqueSelf();
- Q_EMIT unreadCountChanged(unreadCount);
- }
- }
-
-}
-
-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();
-
- d->messages.append(MessageItem(
- tr("Me"), //FIXME : use actual nickname from Tp::AccountPtr
- message.text(),
- message.sent(),
- MessageItem::Outgoing,
- message.messageToken()
- ));
-
- endInsertRows();
-}
-
-QVariant MessagesModel::data(const QModelIndex& index, int role) const
-{
- QVariant result;
-
- if (index.isValid()) {
- MessageItem *requestedData = &d->messages[index.row()];
-
- switch (role) {
- case UserRole:
- result = requestedData->user;
- break;
- case TextRole:
- result = requestedData->text;
- break;
- case TypeRole:
- result = requestedData->type;
- break;
- case TimeRole:
- result = requestedData->time;
- break;
- };
- } else {
- kError() << "Attempting to access data at invalid index (" << index << ")";
- }
-
- return result;
-}
-
-int MessagesModel::rowCount(const QModelIndex& parent) const
-{
- Q_UNUSED(parent);
- return d->messages.size();
-}
-
-void MessagesModel::sendNewMessage(const QString &message)
-{
- if (message.isEmpty()) {
- kWarning() << "Attempting to send empty string";
- } else {
- connect(d->textChannel->send(message),
- SIGNAL(finished(Tp::PendingOperation*)),
- SLOT(verifyPendingOperation(Tp::PendingOperation*)));
- }
-}
-
-void MessagesModel::removeChannelSignals(Tp::TextChannelPtr channel)
-{
- QObject::disconnect(channel.data(),
- SIGNAL(messageReceived(Tp::ReceivedMessage)),
- this,
- SLOT(onMessageReceived(Tp::ReceivedMessage))
- );
- QObject::disconnect(channel.data(),
- SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
- this,
- SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString))
- );
-}
-
-int MessagesModel::unreadCount() const
-{
- return d->textChannel->messageQueue().size();
-}
-
-void MessagesModel::acknowledgeAllMessages()
-{
- QList<Tp::ReceivedMessage> queue
- = d->textChannel->messageQueue();
-
- kDebug() << "Conversation Visible, Acknowledging " << queue.size() << " messages.";
-
- d->textChannel->acknowledge(queue);
- removeSelfFromQueue();
- Q_EMIT unreadCountChanged(queue.size());
-}
-
-void MessagesModel::selfDequed()
-{
- Q_EMIT popoutRequested();
-}
-
-void MessagesModel::setVisibleToUser(bool visible)
-{
- kDebug() << visible;
-
- if (d->visible != visible) {
- d->visible = visible;
- Q_EMIT visibleToUserChanged(d->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;
- }
- beginResetModel();
-// d->messages.clear();
- endResetModel();
-}
-
-#include "moc_messages-model.cpp"
diff --git a/lib/messages-model.h b/lib/messages-model.h
deleted file mode 100644
index 7467f57..0000000
--- a/lib/messages-model.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- Copyright (C) 2011 Lasath Fernando <kde at lasath.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-
-#ifndef MESSAGES_MODEL_H
-#define MESSAGES_MODEL_H
-
-#include "ktpchat_export.h"
-
-#include <QAbstractItemModel>
-#include <TelepathyQt/TextChannel>
-#include "conversation-que-manager.h"
-
-
-class KDE_TELEPATHY_CHAT_EXPORT MessagesModel : public QAbstractListModel, public Queable
-{
- Q_OBJECT
- Q_PROPERTY(bool visibleToUser READ isVisibleToUser WRITE setVisibleToUser NOTIFY visibleToUserChanged);
- Q_PROPERTY(int unreadCount READ unreadCount NOTIFY unreadCountChanged);
-
-public:
- MessagesModel(QObject *parent = 0);
- virtual ~MessagesModel();
-
- enum Roles {
- UserRole = Qt::UserRole,
- TextRole,
- TypeRole,
- TimeRole
- };
-
- virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
-
- Tp::TextChannelPtr textChannel();
- void setTextChannel(Tp::TextChannelPtr channel);
-
- bool isVisibleToUser() const;
- void setVisibleToUser(bool visible);
-
- void acknowledgeAllMessages();
- int unreadCount() const;
-
- //debug function. will do whatever I feel like at the time ;-)
- Q_INVOKABLE void printallmessages();
-Q_SIGNALS:
- void textChannelChanged(Tp::TextChannelPtr newChannel);
- void visibleToUserChanged(bool visible);
- //TODO: figure out how to check if unread messages have been acknowledged by something else
- void unreadCountChanged(int unreadMesssagesCount);
- void popoutRequested();
-
-public Q_SLOTS:
- void sendNewMessage(const QString& message);
-
-private Q_SLOTS:
- void onMessageReceived(Tp::ReceivedMessage);
- void onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString);
- bool verifyPendingOperation(Tp::PendingOperation *op);
-
-private:
- void setupChannelSignals(Tp::TextChannelPtr channel);
- void removeChannelSignals(Tp::TextChannelPtr channel);
- virtual void selfDequed();
-
- class MessagesModelPrivate;
- MessagesModelPrivate *d;
-};
-
-#endif // CONVERSATION_MODEL_H
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list