[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:49 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=8aeb799
The following commit has been merged in the master branch:
commit 8aeb799e5b0445fc88e017c58aa67cf2a3f0b816
Author: Lasath Fernando <kde at lasath.org>
Date: Tue Dec 20 23:51:00 2011 +1100
Further work on chat plasmoid
---
lib/CMakeLists.txt | 2 +
lib/conversation-target.cpp | 14 ++-
lib/conversation-target.h | 2 +
lib/conversation.h | 3 +-
lib/conversations-model.cpp | 17 +++-
lib/messages-model.cpp | 120 +++++++++++++++++++++-----
lib/messages-model.h | 14 ++-
lib/telepathy-text-observer.cpp | 27 +++---
lib/telepathy-text-observer.h | 2 +-
plasmoid/contents/ui/ChatWidget.qml | 13 ++-
plasmoid/contents/ui/ConversationDelegate.qml | 109 +++++++++++------------
plasmoid/contents/ui/main.qml | 70 +++++++++------
12 files changed, 265 insertions(+), 128 deletions(-)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index e2bca3f..7bd555a 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -16,6 +16,7 @@ set(ktpchat_SRCS
chat-search-bar.cpp
logmanager.cpp
messages-model.cpp
+# static-conversation.cpp
telepathy-text-observer.cpp
)
@@ -33,6 +34,7 @@ set(ktpchat_HDRS
conversation-target.h
conversations-model.h
messages-model.h
+# static-conversation.h
telepathy-text-observer.h
)
diff --git a/lib/conversation-target.cpp b/lib/conversation-target.cpp
index 7b9e554..9316243 100644
--- a/lib/conversation-target.cpp
+++ b/lib/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/lib/conversation-target.h b/lib/conversation-target.h
index 4af5a47..8922ef4 100644
--- a/lib/conversation-target.h
+++ b/lib/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/lib/conversation.h b/lib/conversation.h
index 65e77bc..71c1835 100644
--- a/lib/conversation.h
+++ b/lib/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/lib/conversations-model.cpp b/lib/conversations-model.cpp
index 9166541..2c40659 100644
--- a/lib/conversations-model.cpp
+++ b/lib/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/lib/messages-model.cpp b/lib/messages-model.cpp
index e377a84..b636f90 100644
--- a/lib/messages-model.cpp
+++ b/lib/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/lib/messages-model.h b/lib/messages-model.h
index 6ce698a..3328f31 100644
--- a/lib/messages-model.h
+++ b/lib/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/lib/telepathy-text-observer.cpp b/lib/telepathy-text-observer.cpp
index 7a9c575..3354905 100644
--- a/lib/telepathy-text-observer.cpp
+++ b/lib/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/lib/telepathy-text-observer.h b/lib/telepathy-text-observer.h
index 9025081..0815750 100644
--- a/lib/telepathy-text-observer.h
+++ b/lib/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
diff --git a/plasmoid/contents/ui/ChatWidget.qml b/plasmoid/contents/ui/ChatWidget.qml
index 24231f3..a5286cf 100644
--- a/plasmoid/contents/ui/ChatWidget.qml
+++ b/plasmoid/contents/ui/ChatWidget.qml
@@ -64,10 +64,15 @@ Item {
Item {
id:chatArea
- anchors.top: space.bottom
- anchors.left: parent.left; anchors.right: parent.right
- anchors.bottom: input.top
- anchors.margins: 5
+ anchors {
+ top: space.bottom
+ left: parent.left
+ right: parent.right
+ bottom: input.top
+
+ leftMargin: 5
+ rightMargin: leftMargin
+ }
// PlasmaComponents.Highlight { anchors.fill: chatArea }
diff --git a/plasmoid/contents/ui/ConversationDelegate.qml b/plasmoid/contents/ui/ConversationDelegate.qml
index da0c4a8..5bc282b 100644
--- a/plasmoid/contents/ui/ConversationDelegate.qml
+++ b/plasmoid/contents/ui/ConversationDelegate.qml
@@ -1,10 +1,25 @@
-import Qt 4.7
+import QtQuick 1.1
import org.kde.telepathy.declarativeplugins 0.1
import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.graphicswidgets 0.1 as PlasmaWidgets
import org.kde.plasma.components 0.1 as PlasmaComponents
Item {
+ id:base
+ width: height
+
+ property alias image: icon.icon
+ property alias text: icon.text
+ property bool pressed: false
+ property string overlayText: "0"
+
+ signal clicked
+
+// Rectangle {
+// anchors.fill: parent
+// color: "blue"
+// }
+
PlasmaCore.FrameSvgItem {
id: canvas
@@ -12,48 +27,50 @@ Item {
imagePath: "widgets/tasks"
opacity: 1
anchors.fill: parent
-// anchors.margins: 5
- }
-// height: icon.height + 10
-// width: icon.width + 10
- width: height
-
- PlasmaCore.Dialog {
- id: dialog
- windowFlags: Qt.Dialog
- mainItem: ChatWidget {
- width: 250
- height: 350
- conv: model.conversation
-
- onCloseRequested: mouse.popupApplet()
- }
}
//ise listitem?
PlasmaWidgets.IconWidget {
id: icon
// text: model.conversation.target.nick
- icon: model.conversation.target.presenceIcon
-// anchors {
-// top: parent.top
-// bottom: parent.bottom
-// // left: parent.left
-// }
+// icon: model.conversation.target.presenceIcon
+
anchors.fill: parent
anchors.margins: 5
-// width: height
-
-// size: "32x32"
-// size: {
-// console.log("height = " + parent.height);
-// console.log("width = " + parent.width);
-// return Qt.size(icon.height, icon.height);
-// }
-// Component.onCompleted: {
-// console.log("height = " + parent.height);
-// console.log("width = " + parent.width);
-// }
+
+ orientation: Qt.Horizontal
+ }
+
+ Item {
+ id: notification
+ anchors {
+ right: parent.right
+ top: parent.top
+ }
+
+ width: parent.width / 3
+ height: parent.height / 3
+
+ Rectangle {
+ id: background
+ anchors.fill: parent
+ color: "red"
+ radius: 3
+ }
+
+ Text {
+ id: text
+ anchors.fill: parent
+
+ font.pixelSize: parent.height
+ text: base.overlayText
+ color: "white"
+
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ }
+
+ visible: base.overlayText != "0"
}
MouseArea {
@@ -63,29 +80,15 @@ Item {
hoverEnabled: true
//move le onClicked into main
- onClicked: popupApplet()
- function popupApplet() {
- if(dialog.visible == false) {
- var point = dialog.popupPosition(icon, Qt.AlignBottom);
- console.log("Showing dialog at (" + point.x + "," + point.y + ")");
-
- dialog.x = point.x;
- dialog.y = point.y;
-
- dialog.visible = true;
- } else {
- console.log("height = " + dialog.height);
- console.log("width = " + dialog.width);
- dialog.visible = false;
- }
- }
+ onClicked: base.clicked()
+
+ preventStealing: true
}
states: [
State {
name: "focus"
- //use property instead
- when: dialog.visible
+ when: pressed
PropertyChanges {
target: canvas
prefix: "focus"
diff --git a/plasmoid/contents/ui/main.qml b/plasmoid/contents/ui/main.qml
index fa2982d..99cbf4b 100644
--- a/plasmoid/contents/ui/main.qml
+++ b/plasmoid/contents/ui/main.qml
@@ -6,31 +6,7 @@ import org.kde.plasma.components 0.1 as PlasmaComponents
// import "createDialog.js" as MyScript
Item {
-// PlasmaCore.SvgItem {
-// elementId: "horizzontal-line"
-// anchors.fill:parent
-// svg: PlasmaCore.Svg {
-// id: mySvg
-// imagePath: "widgets/line"
-// }
-// }
-
-// PlasmaCore.FrameSvgItem {
-// id: surface
-//
-// anchors.fill: parent
-// // prefix: (internal.userPressed || checked) ? "pressed" : "normal"
-// //internal: if there is no hover status, don't paint on mouse over in touchscreens
-// // opacity: (internal.userPressed || checked || !flat || (shadow.hasOverState && mouse.containsMouse)) ? 1 : 0
-// // Behavior on opacity {
-// // PropertyAnimation { duration: 100 }
-// // }
-// }
-// PlasmaComponents.ListItem {
-// anchors.fill: parent
-// enabled: true
-// sectionDelegate: true
-// }
+
ListView {
id: base
anchors.fill: parent
@@ -40,10 +16,50 @@ Item {
}
delegate : ConversationDelegate {
+ id:conv
anchors.top: parent.top
-// height: 60
anchors.bottom: parent.bottom
-// anchors.margins: 5
+
+ image: model.conversation.target.avatar
+// text: model.conversation.target.nick
+ overlayText: model.conversation.model.unreadCount
+
+ pressed: dialog.visible
+ onClicked: popupApplet();
+
+ //FIXME: put in a loader to not slow down the model
+ PlasmaCore.Dialog {
+ id: dialog
+ windowFlags: Qt.Dialog
+ mainItem: ChatWidget {
+ width: 250
+ height: 350
+ conv: model.conversation
+
+ onCloseRequested: conv.popupApplet()
+ onConversationEndRequested: {
+ model.conversation.model.printallmessages();
+ }
+ }
+ }
+
+ function popupApplet() {
+ if(dialog.visible == false) {
+ var point = dialog.popupPosition(conv, Qt.AlignBottom);
+ console.log("Showing dialog at (" + point.x + "," + point.y + ")");
+
+ dialog.x = point.x;
+ dialog.y = point.y;
+
+ dialog.visible = true;
+ model.conversation.model.visibleToUser = true;
+ } else {
+ console.log("height = " + dialog.height);
+ console.log("width = " + dialog.width);
+ dialog.visible = false;
+ model.conversation.model.visibleToUser = false;
+ }
+ }
}
}
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list