Commit 0ca53298 authored by Lasath Fernando's avatar Lasath Fernando

Make MessagesModel automaticall remove invalided chats and Implement close button

parent eb100db7
......@@ -29,9 +29,12 @@ class Conversation::ConversationPrivate
public:
MessagesModel *messages;
ConversationTarget *target;
bool valid;
};
Conversation::Conversation(const Tp::TextChannelPtr& channel, const Tp::AccountPtr& account, QObject *parent) :
Conversation::Conversation(const Tp::TextChannelPtr& channel,
const Tp::AccountPtr& account,
QObject *parent) :
QObject(parent),
d (new ConversationPrivate)
{
......@@ -41,6 +44,10 @@ Conversation::Conversation(const Tp::TextChannelPtr& channel, const Tp::AccountP
d->messages->setTextChannel(channel);
d->target = new ConversationTarget(channel->targetContact(), this);
d->valid = channel->isValid();
connect(channel.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
SLOT(invalidate(Tp::DBusProxy*,QString,QString)));
}
Conversation::Conversation(QObject *parent) : QObject(parent)
......@@ -59,6 +66,26 @@ ConversationTarget* Conversation::target() const
return d->target;
}
bool Conversation::isValid()
{
return d->valid;
}
void Conversation::invalidate(Tp::DBusProxy* proxy, const QString& errorName, const QString& errorMessage)
{
kDebug() << proxy << errorName << ":" << errorMessage;
d->valid = false;
Q_EMIT validityChanged(d->valid);
}
void Conversation::requestClose()
{
kDebug();
d->messages->requestClose();
}
Conversation::~Conversation()
{
kDebug();
......
......@@ -38,6 +38,7 @@ Q_OBJECT
Q_PROPERTY(ConversationTarget* target READ target CONSTANT);
Q_PROPERTY(MessagesModel* messages READ messages CONSTANT);
Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged);
public:
Conversation(const Tp::TextChannelPtr &channel, const Tp::AccountPtr &account, QObject *parent = 0);
......@@ -47,6 +48,17 @@ public:
MessagesModel* messages() const;
ConversationTarget* target() const;
bool isValid();
Q_SIGNALS:
void validityChanged(bool isValid);
public Q_SLOTS:
void requestClose();
private Q_SLOTS:
void invalidate(Tp::DBusProxy *proxy, const QString &errorName, const QString &errorMessage);
private:
class ConversationPrivate;
ConversationPrivate *d;
......
......@@ -83,10 +83,24 @@ void ConversationsModel::onInconmingConversation(Conversation *newConvo)
if (!handled) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
d->conversations.append(newConvo);
connect(newConvo, SIGNAL(validityChanged(bool)), SLOT(handleValidityChange(bool)));
endInsertRows();
}
}
void ConversationsModel::handleValidityChange(bool valid)
{
if(!valid) {
Conversation* sender = qobject_cast<Conversation*>(QObject::sender());
int index = d->conversations.indexOf(sender);
beginRemoveRows(QModelIndex(), index, index);
d->conversations.removeAt(index);
sender->deleteLater();
endRemoveRows();
}
}
ConversationsModel::~ConversationsModel()
{
delete d;
......
......@@ -47,6 +47,7 @@ private:
private Q_SLOTS:
void onInconmingConversation(Conversation *convo);
void handleValidityChange(bool);
};
#endif // CONVERSATIONS_MODEL_H
......@@ -282,6 +282,15 @@ MessagesModel::~MessagesModel()
delete d;
}
void MessagesModel::requestClose()
{
kDebug();
Tp::PendingOperation *op = d->textChannel->requestClose();
connect(op, SIGNAL(finished(Tp::PendingOperation*)),
SLOT(verifyPendingOperation(Tp::PendingOperation*)));
}
void MessagesModel::printallmessages()
{
Q_FOREACH(MessageItem msg, d->messages) {
......
......@@ -51,8 +51,10 @@ public:
bool isVisibleToUser() const;
void setVisibleToUser(bool visible);
int unreadCount() const;
void acknowledgeAllMessages();
int unreadCount() const;
void requestClose();
//debug function. will do whatever I feel like at the time ;-)
Q_INVOKABLE void printallmessages();
......
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