Commit 0fdc1aed authored by Lasath Fernando's avatar Lasath Fernando Committed by David Edmundson
Browse files

first round of changes for review comments.

parent 0e5931b7
......@@ -29,7 +29,7 @@ class Queable
friend class ConversationQueManager;
protected:
Queable(ConversationQueManager* que = 0);
Queable(ConversationQueManager* queue = 0);
virtual ~Queable();
void enqueSelf();
......
......@@ -67,7 +67,7 @@ QString ConversationTarget::nick() const
return d->contact->alias();
}
QIcon ConversationTarget::presenceIcon() const
KIcon ConversationTarget::presenceIcon() const
{
return KIcon(presenceIconSource());
}
......@@ -106,13 +106,13 @@ QString ConversationTarget::iconSourceForPresence(Tp::ConnectionPresenceType pre
}
void ConversationTarget::onPresenceChanged(Tp::Presence)
void ConversationTarget::onPresenceChanged(const Tp::Presence&)
{
Q_EMIT presenceIconSourceChanged(presenceIconSource());
Q_EMIT presenceIconChanged(presenceIcon());
}
void ConversationTarget::onAvatarDataChanged(Tp::AvatarData)
void ConversationTarget::onAvatarDataChanged(const Tp::AvatarData&)
{
Q_EMIT avatarChanged(avatar());
}
......@@ -122,7 +122,7 @@ Tp::ContactPtr ConversationTarget::contact() const
return d->contact;
}
void ConversationTarget::setContact(Tp::ContactPtr contact)
void ConversationTarget::setContact(const Tp::ContactPtr &contact)
{
if (d->contact) {
removeContactSignals(d->contact);
......
......@@ -30,33 +30,29 @@
class KDE_TELEPATHY_CHAT_EXPORT ConversationTarget : public QObject
{
Q_OBJECT
Q_OBJECT
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);
Q_PROPERTY(QIcon avatar READ avatar NOTIFY avatarChanged);
Q_PROPERTY(QString nick READ nick NOTIFY nickChanged);
Q_PROPERTY(KIcon presenceIcon READ presenceIcon NOTIFY presenceIconChanged);
Q_PROPERTY(QString presenceIconSource READ presenceIconSource NOTIFY presenceIconSourceChanged);
Q_PROPERTY(QString id READ id)
public:
ConversationTarget( Tp::ContactPtr contact = Tp::ContactPtr());
ConversationTarget(Tp::ContactPtr contact = Tp::ContactPtr());
virtual ~ConversationTarget();
QIcon avatar() const;
QString id() const;
QString nick() const;
QIcon presenceIcon() const;
KIcon presenceIcon() const;
QString presenceIconSource() const;
Tp::ContactPtr contact() const;
void setContact(Tp::ContactPtr contact);
void setContact(const Tp::ContactPtr &contact);
static QString iconSourceForPresence(Tp::ConnectionPresenceType presence);
Q_SIGNALS:
void avatarChanged(QIcon avatar);
void nickChanged(QString nick);
......@@ -66,8 +62,8 @@ Q_SIGNALS:
void contactChanged(Tp::ContactPtr contact);
private Q_SLOTS:
void onAvatarDataChanged ( Tp::AvatarData );
void onPresenceChanged ( Tp::Presence );
void onAvatarDataChanged(const Tp::AvatarData&);
void onPresenceChanged(const Tp::Presence&);
private:
void setupContactSignals(Tp::ContactPtr contact);
......@@ -78,3 +74,4 @@ private:
};
#endif // CONVERSATION_TARGET_H
// kate: indent-mode cstyle; space-indent on; indent-width 4; replace-tabs on;
......@@ -35,9 +35,9 @@ class KDE_TELEPATHY_CHAT_EXPORT Conversation : public QObject
{
Q_OBJECT
Q_PROPERTY(ConversationTarget* target READ target NOTIFY targetChanged);
Q_PROPERTY(ConversationTarget* target READ target CONSTANT);
//TODO: rename this to messages
Q_PROPERTY(MessagesModel* model READ model NOTIFY modelChanged);
Q_PROPERTY(MessagesModel* model READ model CONSTANT);
public:
Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account);
......@@ -48,10 +48,6 @@ public:
MessagesModel* model() const;
ConversationTarget* target() const;
Q_SIGNALS:
void modelChanged(MessagesModel* newModel);
void targetChanged(ConversationTarget* target);
private:
class ConversationPrivate;
ConversationPrivate *d;
......
......@@ -28,15 +28,15 @@ class ConversationsModel::ConversationsModelPrivate
{
public:
TelepathyTextObserver watcher;
QList<Conversation*> data;
QList<Conversation*> conversations;
};
QVariant ConversationsModel::data ( const QModelIndex& index, int role ) const
{
QVariant result;
if(index.row() >= 0 && index.row() < d->data.count()) {
if(index.row() >= 0 && index.row() < d->conversations.count()) {
Q_ASSERT(role == ConversationRole);
result = QVariant::fromValue<QObject*>(d->data[index.row()]);
result = QVariant::fromValue<QObject*>(d->conversations[index.row()]);
kDebug() << "returning value " << result;
}
return result;
......@@ -44,7 +44,7 @@ QVariant ConversationsModel::data ( const QModelIndex& index, int role ) const
int ConversationsModel::rowCount ( const QModelIndex& parent ) const
{
return d->data.count();
return d->conversations.count();
}
ConversationsModel::ConversationsModel() :
......@@ -57,19 +57,25 @@ ConversationsModel::ConversationsModel() :
QObject::connect(&d->watcher, SIGNAL(newConversation(Conversation*)), SLOT(onInconmingConversation(Conversation*)));
}
void ConversationsModel::onInconmingConversation ( Conversation* convo )
void ConversationsModel::onInconmingConversation ( Conversation* newConvo )
{
bool found = false;
Q_FOREACH(Conversation *con, d->data) {
if(con->target()->id() == convo->target()->id()) {
con->model()->setTextChannel(convo->model()->textChannel());
found = true;
Tp::TextChannelPtr newChannel = newConvo->model()->textChannel();
if (!newChannel->targetHandleType() == Tp::HandleTypeNone) {
//loop through all tabs checking for matches
Q_FOREACH(Conversation *convo, d->conversations) {
if (convo->target()->id() == newChannel->targetId()
&& convo->model()->textChannel()->targetHandleType() == newChannel->targetHandleType()) {
found = true;
break;
}
}
}
if(!found) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
d->data.append(convo);
d->conversations.append(newConvo);
endInsertRows();
}
}
......
......@@ -22,7 +22,8 @@
#include <KDebug>
#include <TelepathyQt/ReceivedMessage>
class MessageItem {
class MessageItem
{
public:
QString user;
QString text;
......@@ -37,15 +38,15 @@ public:
} 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("\n"))) {
: user(user), text(text), time(time), id(messageId), type(type) {
if (this->text.endsWith(QLatin1String("\n"))) {
this->text.chop(1);
}
}
};
class MessagesModel::ConversationModelPrivate {
class MessagesModel::ConversationModelPrivate
{
public:
Tp::TextChannelPtr textChannel;
QList<MessageItem> messages;
......@@ -53,8 +54,8 @@ public:
};
MessagesModel::MessagesModel(QObject* parent):
QAbstractListModel(parent),
d(new ConversationModelPrivate)
QAbstractListModel(parent),
d(new ConversationModelPrivate)
{
kDebug();
......@@ -73,9 +74,9 @@ Tp::TextChannelPtr MessagesModel::textChannel()
return d->textChannel;
}
bool MessagesModel::verifyPendingOperation ( Tp::PendingOperation* op )
bool MessagesModel::verifyPendingOperation(Tp::PendingOperation* op)
{
if(op->isError()) {
if (op->isError()) {
kWarning() << op->errorName() << "+" << op->errorMessage();
return false;
}
......@@ -85,11 +86,11 @@ bool MessagesModel::verifyPendingOperation ( Tp::PendingOperation* op )
void MessagesModel::setupChannelSignals(Tp::TextChannelPtr channel)
{
QObject::connect(channel.constData(),
SIGNAL(messageReceived(Tp::ReceivedMessage)),
SLOT(onMessageReceived(Tp::ReceivedMessage)));
SIGNAL(messageReceived(Tp::ReceivedMessage)),
SLOT(onMessageReceived(Tp::ReceivedMessage)));
QObject::connect(channel.constData(),
SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
}
void MessagesModel::setTextChannel(Tp::TextChannelPtr channel)
......@@ -97,7 +98,7 @@ void MessagesModel::setTextChannel(Tp::TextChannelPtr channel)
kDebug();
setupChannelSignals(channel);
if(d->textChannel) {
if (d->textChannel) {
removeChannelSignals(channel);
}
//FIXME: check messageQue for any lost messages
......@@ -105,15 +106,17 @@ void MessagesModel::setTextChannel(Tp::TextChannelPtr channel)
Q_EMIT textChannelChanged(channel);
QList<Tp::ReceivedMessage> que = channel->messageQueue();
Q_FOREACH(Tp::ReceivedMessage message, que) {
QList<Tp::ReceivedMessage> queue
= channel->messageQueue();
Q_FOREACH(Tp::ReceivedMessage message, queue
) {
bool messageAlreadyInModel = false;
Q_FOREACH(MessageItem current, d->messages) {
if(current.id == message.messageToken()) {
if (current.id == message.messageToken()) {
messageAlreadyInModel = true;
}
}
if(!messageAlreadyInModel) {
if (!messageAlreadyInModel) {
onMessageReceived(message);
}
}
......@@ -125,21 +128,21 @@ void MessagesModel::onMessageReceived(Tp::ReceivedMessage message)
kDebug() << "unreadMessagesCount =" << unreadCount;
kDebug() << "text =" << message.text();
if(message.messageType() == Tp::ChannelTextMessageTypeNormal) {
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()
));
message.sender()->alias(),
message.text(),
message.received(),
MessageItem::Incoming,
message.messageToken()
));
endInsertRows();
if(d->visible) {
if (d->visible) {
acknowledgeAllMessages();
} else {
enqueSelf();
......@@ -159,12 +162,12 @@ void MessagesModel::onMessageSent(Tp::Message message, Tp::MessageSendingFlags f
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()
));
tr("Me"), //FIXME : use actual nickname from Tp::AccountPtr
message.text(),
message.sent(),
MessageItem::Outgoing,
message.messageToken()
));
endInsertRows();
}
......@@ -173,22 +176,22 @@ QVariant MessagesModel::data(const QModelIndex& index, int role) const
{
QVariant result;
if(index.row() < d->messages.size()) {
if (index.row() < d->messages.size()) {
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;
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 << ")";
......@@ -203,19 +206,15 @@ int MessagesModel::rowCount(const QModelIndex& parent) const
return d->messages.size();
}
Tp::PendingSendMessage* MessagesModel::sendNewMessage ( QString message )
void MessagesModel::sendNewMessage(QString message)
{
Tp::PendingSendMessage* msg = 0;
if(message.isEmpty()) {
if (message.isEmpty()) {
kWarning() << "Attempting to send empty string";
} else {
msg = d->textChannel->send(message);
connect(msg, SIGNAL(finished(Tp::PendingOperation*)),
connect(d->textChannel->send(message),
SIGNAL(finished(Tp::PendingOperation*)),
SLOT(verifyPendingOperation(Tp::PendingOperation*)));
}
return msg;
}
void MessagesModel::removeChannelSignals(Tp::TextChannelPtr channel)
......@@ -224,12 +223,12 @@ void MessagesModel::removeChannelSignals(Tp::TextChannelPtr channel)
SIGNAL(messageReceived(Tp::ReceivedMessage)),
this,
SLOT(onMessageReceived(Tp::ReceivedMessage))
);
);
QObject::disconnect(channel.constData(),
SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
this,
SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString))
);
);
}
int MessagesModel::unreadCount() const
......@@ -239,13 +238,17 @@ int MessagesModel::unreadCount() const
void MessagesModel::acknowledgeAllMessages()
{
QList<Tp::ReceivedMessage> que = d->textChannel->messageQueue();
QList<Tp::ReceivedMessage> queue
= d->textChannel->messageQueue();
kDebug() << "Conversation Visible, Acknowledging " << que.size() << " messages.";
kDebug() << "Conversation Visible, Acknowledging " << queue
.size() << " messages.";
d->textChannel->acknowledge(que);
d->textChannel->acknowledge(queue
);
removeSelfFromQue();
Q_EMIT unreadCountChanged(que.size());
Q_EMIT unreadCountChanged(queue
.size());
}
void MessagesModel::selfDequed()
......@@ -257,12 +260,12 @@ void MessagesModel::setVisibleToUser(bool visible)
{
kDebug() << visible;
if(d->visible != visible) {
if (d->visible != visible) {
d->visible = visible;
Q_EMIT visibleToUserChanged(d->visible);
}
if(visible) {
if (visible) {
acknowledgeAllMessages();
}
}
......@@ -289,3 +292,4 @@ void MessagesModel::printallmessages()
}
#include "moc_messages-model.cpp"
// kate: indent-mode cstyle; space-indent on; indent-width 4; replace-tabs on;
......@@ -32,12 +32,6 @@ class KDE_TELEPATHY_CHAT_EXPORT MessagesModel : public QAbstractListModel, publi
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
// NOTIFY textChannelChanged
// )
public:
MessagesModel(QObject* parent = 0);
......@@ -62,6 +56,7 @@ public:
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);
......@@ -71,7 +66,7 @@ Q_SIGNALS:
void popoutRequested();
public Q_SLOTS:
Tp::PendingSendMessage* sendNewMessage(QString message);
void sendNewMessage(QString message);
private Q_SLOTS:
void onMessageReceived(Tp::ReceivedMessage);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment