28 #include <TelepathyQt/ChannelClassSpec>
29 #include <TelepathyQt/TextChannel>
30 #include <TelepathyQt/ClientRegistrar>
34 return Tp::ChannelClassSpecList() << Tp::ChannelClassSpec::textChat();
37 class ConversationsModel::ConversationsModelPrivate
40 QList<Conversation*> conversations;
46 d(new ConversationsModelPrivate)
48 QHash<int, QByteArray> roles;
57 qDeleteAll(d->conversations);
64 if (index.isValid()) {
66 result = QVariant::fromValue<Conversation*>(d->conversations[index.row()]);
67 kDebug() <<
"returning value " << result;
76 return d->conversations.count();
80 const Tp::AccountPtr &account,
81 const Tp::ConnectionPtr &connection,
82 const QList<Tp::ChannelPtr> &channels,
83 const QList<Tp::ChannelRequestPtr> &channelRequests,
84 const QDateTime &userActionTime,
85 const HandlerInfo &handlerInfo)
88 Q_UNUSED(handlerInfo);
91 bool shouldDelegate =
false;
94 Tp::TextChannelPtr textChannel;
95 Q_FOREACH(
const Tp::ChannelPtr &channel, channels) {
96 textChannel = Tp::TextChannelPtr::dynamicCast(channel);
102 Q_ASSERT(textChannel);
106 Q_FOREACH(
const Tp::ChannelRequestPtr channelRequest, channelRequests) {
107 kDebug() << channelRequest->hints().allHints();
108 shouldDelegate = channelRequest->hints().hint(QLatin1String(
"org.freedesktop.Telepathy.ChannelRequest"), QLatin1String(
"DelegateToPreferredHandler")).toBool();
117 if (convo->
target()->
id() == textChannel->targetId() &&
120 if (!shouldDelegate) {
135 if (!handled && !shouldDelegate) {
138 d->conversations.append(newConvo);
139 connect(newConvo, SIGNAL(validityChanged(
bool)), SLOT(handleValidityChange(
bool)));
140 connect(newConvo, SIGNAL(conversationDelegated()), SLOT(conversationDelegated()));
143 context->setFinished();
156 account->ensureTextChat(contact, QDateTime::currentDateTime(),
157 QLatin1String(
"org.freedesktop.Telepathy.Client.KDE.TextUi.ConversationWatcher"));
160 void ConversationsModel::handleValidityChange(
bool valid)
163 removeConversation(qobject_cast<Conversation*>(QObject::sender()));
167 void ConversationsModel::conversationDelegated()
169 removeConversation(qobject_cast<Conversation*>(QObject::sender()));
172 void ConversationsModel::removeConversation(
Conversation* conv)
174 int index = d->conversations.indexOf(conv);
176 beginRemoveRows(QModelIndex(), index, index);
177 d->conversations.removeAt(index);
181 kError() <<
"attempting to delete non-existent conversation";
187 if(d->conversations.isEmpty()) {
190 Q_ASSERT(qBound(0, fromRow, d->conversations.count()-1) == fromRow);
193 for(
int i = fromRow; i != fromRow || first; i = (i + 1) % d->conversations.count()) {
194 if(d->conversations[i]->messages()->unreadCount() > 0) {