File indexing completed on 2023-12-03 08:28:38

0001 /*
0002  * This file is part of telepathy-contactslist-prototype
0003  *
0004  * Copyright (C) 2011 Francesco Nwokeka <francesco.nwokeka@gmail.com>
0005  * Copyright (C) 2012 Dominik Cermak <d.cermak@arcor.de>
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Lesser General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2.1 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library; if not, write to the Free Software
0019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0020  */
0021 
0022 #include "join-chat-room-dialog.h"
0023 #include "ui_join-chat-room-dialog.h"
0024 #include "debug.h"
0025 
0026 #include <KTp/Models/rooms-model.h>
0027 
0028 #include <KConfig>
0029 #include <KConfigGroup>
0030 #include <KSharedConfig>
0031 #include <KMessageWidget>
0032 #include <KLocalizedString>
0033 #include <KNotification>
0034 #include <KIconLoader>
0035 
0036 #include <TelepathyQt/Account>
0037 #include <TelepathyQt/AccountSet>
0038 #include <TelepathyQt/AccountCapabilityFilter>
0039 #include <TelepathyQt/AccountManager>
0040 #include <TelepathyQt/AccountPropertyFilter>
0041 #include <TelepathyQt/AndFilter>
0042 #include <TelepathyQt/ChannelTypeRoomListInterface>
0043 #include <TelepathyQt/PendingChannel>
0044 #include <TelepathyQt/PendingReady>
0045 #include <TelepathyQt/RequestableChannelClassSpec>
0046 #include <TelepathyQt/RoomListChannel>
0047 #include <TelepathyQt/PendingChannelRequest>
0048 
0049 #include <QSortFilterProxyModel>
0050 #include <QDialogButtonBox>
0051 
0052 class KTp::JoinChatRoomDialog::Private
0053 {
0054 public:
0055     Private(JoinChatRoomDialog *q) :
0056         ui(new Ui::JoinChatRoomDialog)
0057         , model(new RoomsModel(q))
0058         , favoritesModel(new FavoriteRoomsModel(q))
0059         , favoritesProxyModel(new QSortFilterProxyModel(q))
0060         , joinInProgress(false)
0061     {}
0062 
0063     QList<Tp::AccountPtr> accounts;
0064     Ui::JoinChatRoomDialog *ui;
0065     QDialogButtonBox *buttonBox;
0066     Tp::PendingChannel *pendingRoomListChannel;
0067     Tp::ChannelPtr roomListChannel;
0068     Tp::Client::ChannelTypeRoomListInterface *iface;
0069     RoomsModel *model;
0070     FavoriteRoomsModel *favoritesModel;
0071     QSortFilterProxyModel *favoritesProxyModel;
0072     KConfigGroup favoriteRoomsGroup;
0073     KConfigGroup recentRoomsGroup;
0074     bool joinInProgress;
0075 };
0076 
0077 KTp::JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWidget* parent)
0078     : QDialog(parent, Qt::Dialog)
0079     , d(new Private(this))
0080 {
0081     QWidget *joinChatRoomDialog = new QWidget(this);
0082     d->ui->setupUi(joinChatRoomDialog);
0083     d->ui->feedbackWidget->hide();
0084 
0085     d->buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0086 
0087     QVBoxLayout *mainLayout = new QVBoxLayout(this);
0088     mainLayout->addWidget(joinChatRoomDialog);
0089     mainLayout->addWidget(d->buttonBox);
0090     setLayout(mainLayout);
0091 
0092     setWindowIcon(QIcon::fromTheme(QLatin1String("im-irc")));
0093     setWindowTitle(i18nc("Dialog title", "Join Chat Room"));
0094 
0095     d->ui->filterPicture->clear();
0096     d->ui->filterPicture->setPixmap(KIconLoader::global()->loadIcon(QLatin1String("view-filter"), KIconLoader::Small));
0097 
0098     // config
0099     KSharedConfigPtr commonConfig = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
0100     d->favoriteRoomsGroup = commonConfig->group(QLatin1String("FavoriteRooms"));
0101     d->recentRoomsGroup = commonConfig->group(QLatin1String("RecentChatRooms"));
0102 
0103     // load favorite and recent rooms
0104     loadFavoriteRooms();
0105 
0106     // disable OK button on start
0107     d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
0108     d->buttonBox->button(QDialogButtonBox::Ok)->setText(i18nc("button", "Join/Create"));
0109     d->buttonBox->button(QDialogButtonBox::Ok)->setIcon(QIcon::fromTheme(QLatin1String("im-irc")));
0110 
0111     onAccountSelectionChanged(d->ui->comboBox->currentIndex());
0112     connect(accountManager->becomeReady(), SIGNAL(finished(Tp::PendingOperation*)),
0113             this, SLOT(onAccountManagerReady(Tp::PendingOperation*)));
0114 
0115     // Previous Tab
0116     d->favoritesProxyModel->setSourceModel(d->favoritesModel);
0117     d->favoritesProxyModel->setFilterKeyColumn(FavoriteRoomsModel::AccountIdentifierColumn);
0118     d->favoritesProxyModel->setSortRole(Qt::CheckStateRole);
0119     d->favoritesProxyModel->setDynamicSortFilter(true);
0120 
0121     d->ui->previousView->setModel(d->favoritesProxyModel);
0122     d->ui->previousView->setHeaderHidden(true);
0123     d->ui->previousView->header()->setStretchLastSection(false);
0124     d->ui->previousView->header()->setSectionResizeMode(FavoriteRoomsModel::BookmarkColumn, QHeaderView::ResizeToContents);
0125     d->ui->previousView->header()->setSectionResizeMode(FavoriteRoomsModel::HandleNameColumn, QHeaderView::Stretch);
0126     d->ui->previousView->setColumnHidden(FavoriteRoomsModel::AccountIdentifierColumn, true);
0127     d->ui->previousView->sortByColumn(FavoriteRoomsModel::BookmarkColumn, Qt::DescendingOrder);
0128 
0129     // Search Tab
0130     QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
0131     proxyModel->setSourceModel(d->model);
0132     proxyModel->setSortLocaleAware(true);
0133     proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
0134     proxyModel->setFilterKeyColumn(RoomsModel::NameColumn);
0135     proxyModel->setDynamicSortFilter(true);
0136 
0137     d->ui->queryView->setModel(proxyModel);
0138     d->ui->queryView->header()->setStretchLastSection(false);
0139     d->ui->queryView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
0140     d->ui->queryView->header()->setSectionResizeMode(1, QHeaderView::Stretch);
0141     d->ui->queryView->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
0142     d->ui->queryView->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
0143     d->ui->queryView->header()->setSortIndicatorShown(false);
0144     d->ui->queryView->sortByColumn(RoomsModel::NameColumn, Qt::AscendingOrder);
0145 
0146     // connects
0147     connect(d->ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(onTextChanged(QString)));
0148     connect(d->ui->previousView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
0149     connect(d->ui->previousView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
0150             this, SLOT(onFavoriteRoomSelectionChanged(QModelIndex,QModelIndex)));
0151     connect(d->favoritesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
0152             this, SLOT(onFavoriteRoomDataChanged(QModelIndex,QModelIndex)));
0153     connect(d->ui->clearRecentPushButton, SIGNAL(clicked(bool)), this, SLOT(clearRecentRooms()));
0154     connect(d->ui->serverLineEdit, SIGNAL(returnPressed()), this, SLOT(getRoomList()));
0155     connect(d->ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(getRoomList()));
0156     connect(d->ui->queryView, SIGNAL(clicked(QModelIndex)), this, SLOT(onRoomClicked(QModelIndex)));
0157     connect(d->ui->queryView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
0158     connect(d->ui->filterBar, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString)));
0159     connect(d->ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onAccountSelectionChanged(int)));
0160     connect(d->buttonBox, SIGNAL(accepted()), this, SLOT(addRecentRoom()));
0161     connect(d->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); //FIXME?
0162     connect(d->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0163 }
0164 
0165 void KTp::JoinChatRoomDialog::closeEvent(QCloseEvent* e)
0166 {
0167     // ignore close event if we are in the middle of an operation
0168     if (!d->joinInProgress) {
0169         QDialog::closeEvent(e);
0170     }
0171 }
0172 
0173 
0174 void KTp::JoinChatRoomDialog::onAccountManagerReady(Tp::PendingOperation* operation)
0175 {
0176     Tp::AccountManagerPtr accountManager = Tp::AccountManagerPtr::qObjectCast(
0177         qobject_cast<Tp::PendingReady*>(operation)->proxy()
0178     );
0179     Tp::AccountPropertyFilterPtr isOnlineFilter = Tp::AccountPropertyFilter::create();
0180     isOnlineFilter->addProperty(QLatin1String("online"), true);
0181 
0182     Tp::AccountCapabilityFilterPtr capabilityFilter = Tp::AccountCapabilityFilter::create(
0183                 Tp::RequestableChannelClassSpecList() << Tp::RequestableChannelClassSpec::textChatroom());
0184     Tp::AccountFilterPtr filter = Tp::AndFilter<Tp::Account>::create((QList<Tp::AccountFilterConstPtr>() <<
0185                                              isOnlineFilter <<
0186                                              capabilityFilter));
0187 
0188     d->ui->comboBox->setAccountSet(accountManager->filterAccounts(filter));
0189 
0190     // queryTab
0191     if (d->ui->comboBox->count() > 0) {
0192         d->ui->queryButton->setEnabled(true);
0193     }
0194 
0195     // apply the filter after populating
0196     onAccountSelectionChanged(d->ui->comboBox->currentIndex());
0197 }
0198 
0199 KTp::JoinChatRoomDialog::~JoinChatRoomDialog()
0200 {
0201     delete d->ui;
0202     delete d;
0203 }
0204 
0205 Tp::AccountPtr KTp::JoinChatRoomDialog::selectedAccount() const
0206 {
0207     return d->ui->comboBox->currentAccount();
0208 }
0209 
0210 void KTp::JoinChatRoomDialog::accept()
0211 {
0212     d->ui->feedbackWidget->hide();
0213     const Tp::AccountPtr account = selectedAccount();
0214     if (account) {
0215         setJoinInProgress(true);
0216         Tp::PendingChannelRequest *request = account->ensureTextChatroom(selectedChatRoom());
0217         connect(request, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onStartChatFinished(Tp::PendingOperation*)));
0218     }
0219 }
0220 
0221 
0222 void KTp::JoinChatRoomDialog::onAccountSelectionChanged(int newIndex)
0223 {
0224     // Show only favorites associated with the selected account
0225     Q_UNUSED(newIndex)
0226 
0227     if (!d->ui->comboBox->currentAccount()) {
0228         // Set a filter expression that matches no account identifier
0229         d->favoritesProxyModel->setFilterRegExp(QLatin1String("a^"));
0230         return;
0231     }
0232 
0233     QString accountIdentifier = d->ui->comboBox->currentAccount()->uniqueIdentifier();
0234     d->favoritesProxyModel->setFilterFixedString(accountIdentifier);
0235 
0236     // Enable/disable the buttons as appropriate
0237     d->ui->clearRecentPushButton->setEnabled(!d->recentRoomsGroup.keyList().empty());
0238 }
0239 
0240 void KTp::JoinChatRoomDialog::onFavoriteRoomDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
0241 {
0242     // Because previousView only allows editing of a single row, assume that topLeft points to the changed data.
0243     Q_UNUSED(bottomRight);
0244 
0245     bool bookmarked = topLeft.data(Qt::CheckStateRole) == Qt::Checked ? true : false;
0246     const QString &favoriteHandle = topLeft.data(FavoriteRoomsModel::HandleNameRole).toString();
0247     const QString &favoriteAccount = topLeft.data(FavoriteRoomsModel::AccountRole).toString();
0248 
0249     const QString &key = favoriteHandle + favoriteAccount;
0250 
0251     // Write the changed room to the config file
0252     QVariantList favorite;
0253     favorite.append(favoriteHandle);
0254     favorite.append(favoriteAccount);
0255 
0256     if (bookmarked) {
0257         if (d->recentRoomsGroup.keyList().contains(key)) {
0258             d->recentRoomsGroup.deleteEntry(key);
0259             d->recentRoomsGroup.sync();
0260         }
0261         d->favoriteRoomsGroup.writeEntry(key, favorite);
0262         d->favoriteRoomsGroup.sync();
0263     } else {
0264         if (d->favoriteRoomsGroup.keyList().contains(key)) {
0265             d->favoriteRoomsGroup.deleteEntry(key);
0266             d->favoriteRoomsGroup.sync();
0267         }
0268         d->recentRoomsGroup.writeEntry(key, favorite);
0269         d->recentRoomsGroup.sync();
0270     }
0271 
0272     onAccountSelectionChanged(d->ui->comboBox->currentIndex());
0273 }
0274 
0275 void KTp::JoinChatRoomDialog::addRecentRoom()
0276 {
0277     Tp::AccountPtr account = d->ui->comboBox->currentAccount();
0278     if (!account || d->ui->lineEdit->text().isEmpty()) {
0279         return;
0280     }
0281 
0282     QString recentAccount = account->uniqueIdentifier();
0283     QString recentHandle = d->ui->lineEdit->text();
0284     const QString &key = recentHandle + recentAccount;
0285 
0286     QVariantList recent;
0287     recent.append(recentHandle);
0288     recent.append(recentAccount);
0289 
0290     if(d->favoriteRoomsGroup.keyList().contains(key) || d->recentRoomsGroup.keyList().contains(key)) {
0291         return;
0292     }
0293 
0294     d->recentRoomsGroup.writeEntry(key, recent);
0295     d->recentRoomsGroup.sync();
0296 }
0297 
0298 
0299 void KTp::JoinChatRoomDialog::clearRecentRooms()
0300 {
0301     QString accountIdentifier = d->ui->comboBox->currentAccount()->uniqueIdentifier();
0302 
0303     KSharedConfigPtr commonConfig = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
0304     commonConfig->deleteGroup(QLatin1String("RecentChatRooms"));
0305     commonConfig->sync();
0306 
0307     // Reload the model
0308     d->favoritesModel->clearRooms();
0309     loadFavoriteRooms();
0310 
0311     // Update the list
0312     onAccountSelectionChanged(d->ui->comboBox->currentIndex());
0313 }
0314 
0315 void KTp::JoinChatRoomDialog::getRoomList()
0316 {
0317     Tp::AccountPtr account = d->ui->comboBox->currentAccount();
0318     if (!account) {
0319         return;
0320     }
0321 
0322     // Clear the list from previous items
0323     d->model->clearRoomInfoList();
0324 
0325     // Build the channelrequest
0326     QVariantMap request;
0327     request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"),
0328                    TP_QT_IFACE_CHANNEL_TYPE_ROOM_LIST);
0329     request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType"),
0330                    Tp::HandleTypeNone);
0331 
0332     // If the user provided a server use it, else use the standard server for the selected account
0333     if (!d->ui->serverLineEdit->text().isEmpty()) {
0334         request.insert(TP_QT_IFACE_CHANNEL_TYPE_ROOM_LIST + QLatin1String(".Server"),
0335                        d->ui->serverLineEdit->text());
0336     }
0337 
0338     d->pendingRoomListChannel = account->createAndHandleChannel(request, QDateTime::currentDateTime());
0339     connect(d->pendingRoomListChannel, SIGNAL(finished(Tp::PendingOperation*)),
0340             this, SLOT(onRoomListChannelReadyForHandling(Tp::PendingOperation*)));
0341 
0342 }
0343 
0344 void KTp::JoinChatRoomDialog::stopListing()
0345 {
0346     d->iface->StopListing();
0347 }
0348 
0349 void KTp::JoinChatRoomDialog::onRoomListChannelReadyForHandling(Tp::PendingOperation *operation)
0350 {
0351     if (operation->isError()) {
0352         qCDebug(KTP_WIDGETS) << operation->errorName();
0353         qCDebug(KTP_WIDGETS) << operation->errorMessage();
0354         QString errorMsg(operation->errorName() + QLatin1String(": ") + operation->errorMessage());
0355         sendNotificationToUser(errorMsg);
0356     } else {
0357         d->roomListChannel = d->pendingRoomListChannel->channel();
0358 
0359         connect(d->roomListChannel->becomeReady(),
0360                 SIGNAL(finished(Tp::PendingOperation*)),
0361                 SLOT(onRoomListChannelReady(Tp::PendingOperation*)));
0362     }
0363 }
0364 
0365 void KTp::JoinChatRoomDialog::onRoomListChannelReady(Tp::PendingOperation *operation)
0366 {
0367     if (operation->isError()) {
0368         qCDebug(KTP_WIDGETS) << operation->errorName();
0369         qCDebug(KTP_WIDGETS) << operation->errorMessage();
0370         QString errorMsg(operation->errorName() + QLatin1String(": ") + operation->errorMessage());
0371         sendNotificationToUser(errorMsg);
0372     } else {
0373         d->iface = d->roomListChannel->interface<Tp::Client::ChannelTypeRoomListInterface>();
0374 
0375         d->iface->ListRooms();
0376 
0377         connect(d->iface, SIGNAL(ListingRooms(bool)), SLOT(onListing(bool)));
0378         connect(d->iface, SIGNAL(GotRooms(Tp::RoomInfoList)), SLOT(onGotRooms(Tp::RoomInfoList)));
0379     }
0380 }
0381 
0382 void KTp::JoinChatRoomDialog::onRoomListChannelClosed(Tp::PendingOperation *operation)
0383 {
0384     if (operation->isError()) {
0385         qCDebug(KTP_WIDGETS) << operation->errorName();
0386         qCDebug(KTP_WIDGETS) << operation->errorMessage();
0387         QString errorMsg(operation->errorName() + QLatin1String(": ") + operation->errorMessage());
0388         sendNotificationToUser(errorMsg);
0389     } else {
0390         d->ui->queryButton->setEnabled(true);
0391         d->ui->queryButton->setIcon(QIcon::fromTheme(QLatin1String("media-playback-start")));
0392         d->ui->queryButton->setText(i18nc("Button text", "Query"));
0393         d->ui->queryButton->setToolTip(i18nc("Tooltip text", "Start query"));
0394         connect(d->ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(getRoomList()));
0395         disconnect(d->ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(stopListing()));
0396     }
0397 }
0398 
0399 void KTp::JoinChatRoomDialog::onListing(bool isListing)
0400 {
0401     if (isListing) {
0402         qCDebug(KTP_WIDGETS) << "listing";
0403         d->ui->queryButton->setEnabled(true);
0404         d->ui->queryButton->setIcon(QIcon::fromTheme(QLatin1String("media-playback-stop")));
0405         d->ui->queryButton->setText(i18nc("Button text", "Stop"));
0406         d->ui->queryButton->setToolTip(i18nc("Tooltip text", "Stop query"));
0407         disconnect(d->ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(getRoomList()));
0408         connect(d->ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(stopListing()));
0409     } else {
0410         qCDebug(KTP_WIDGETS) << "finished listing";
0411         Tp::PendingOperation *op =  d->roomListChannel->requestClose();
0412         connect(op,
0413                 SIGNAL(finished(Tp::PendingOperation*)),
0414                 SLOT(onRoomListChannelClosed(Tp::PendingOperation*)));
0415     }
0416 }
0417 
0418 void KTp::JoinChatRoomDialog::onGotRooms(Tp::RoomInfoList roomInfoList)
0419 {
0420     d->model->addRooms(roomInfoList);
0421 }
0422 
0423 void KTp::JoinChatRoomDialog::onFavoriteRoomSelectionChanged(const QModelIndex &current, const QModelIndex &previous)
0424 {
0425     Q_UNUSED(previous);
0426     if (current.isValid()) {
0427         d->ui->lineEdit->setText(current.data(FavoriteRoomsModel::HandleNameRole).toString());
0428     }
0429 }
0430 
0431 void KTp::JoinChatRoomDialog::onRoomClicked(const QModelIndex &index)
0432 {
0433     d->ui->lineEdit->setText(index.data(RoomsModel::HandleNameRole).toString());
0434 }
0435 
0436 QString KTp::JoinChatRoomDialog::selectedChatRoom() const
0437 {
0438     return d->ui->lineEdit->text();
0439 }
0440 
0441 void KTp::JoinChatRoomDialog::onTextChanged(QString newText)
0442 {
0443     d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!newText.isEmpty());
0444 }
0445 
0446 void KTp::JoinChatRoomDialog::onStartChatFinished(Tp::PendingOperation *op)
0447 {
0448     setJoinInProgress(false);
0449     if (op->isError()) {
0450         qCDebug(KTP_WIDGETS) << "failed to join room";
0451         qCDebug(KTP_WIDGETS) << op->errorName() << op->errorMessage();
0452 
0453         d->ui->feedbackWidget->setMessageType(KMessageWidget::KMessageWidget::Error);
0454         d->ui->feedbackWidget->setText(i18n("Could not join chatroom"));
0455         d->ui->feedbackWidget->animatedShow();
0456     } else {
0457         close();
0458     }
0459 }
0460 
0461 void KTp::JoinChatRoomDialog::setJoinInProgress(bool inProgress)
0462 {
0463     d->joinInProgress = inProgress;
0464     layout()->parentWidget()->setEnabled(!inProgress);
0465     d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!inProgress);
0466     d->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(!inProgress);
0467 }
0468 
0469 
0470 void KTp::JoinChatRoomDialog::sendNotificationToUser(const QString& errorMsg)
0471 {
0472     //The pointer is automatically deleted when the event is closed
0473     KNotification *notification;
0474     notification = new KNotification(QLatin1String("telepathyError"), this);
0475 
0476     notification->setText(errorMsg);
0477     notification->sendEvent();
0478 }
0479 
0480 void KTp::JoinChatRoomDialog::loadFavoriteRooms()
0481 {
0482     QList<QVariantMap> roomList;
0483 
0484     Q_FOREACH(const QString &key, d->favoriteRoomsGroup.keyList()) {
0485         QVariantList favorite = d->favoriteRoomsGroup.readEntry(key, QVariantList());
0486         // Keep compatibility with KTp 0.8 and previous
0487         if(favorite.size() == 3) {
0488             // Update the entry in the config file
0489             favorite.removeFirst();
0490             d->favoriteRoomsGroup.writeEntry(key, favorite);
0491             d->favoriteRoomsGroup.sync();
0492         }
0493         QString favoriteHandle = favorite.at(0).toString();
0494         QString favoriteAccount = favorite.at(1).toString();
0495         QVariantMap room;
0496         room.insert(QLatin1String("is-bookmarked"), true);
0497         room.insert(QLatin1String("handle-name"), favoriteHandle);
0498         room.insert(QLatin1String("account-identifier"), favoriteAccount);
0499         roomList.append(room);
0500     }
0501 
0502     Q_FOREACH (const QString &key, d->recentRoomsGroup.keyList()) {
0503         QVariantList recent = d->recentRoomsGroup.readEntry(key, QVariantList());
0504         QString recentHandle = recent.at(0).toString();
0505         QString recentAccount = recent.at(1).toString();
0506         QVariantMap room;
0507         room.insert(QLatin1String("is-bookmarked"), false);
0508         room.insert(QLatin1String("handle-name"), recentHandle);
0509         room.insert(QLatin1String("account-identifier"), recentAccount);
0510         roomList.append(room);
0511     }
0512 
0513     d->favoritesModel->addRooms(roomList);
0514 }