[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:08:13 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=2d6d432

The following commit has been merged in the master branch:
commit 2d6d432d0c8738c1992f3843e2775019c13e2c90
Author: Daniele E. Domenichelli <daniele.domenichelli at iit.it>
Date:   Sun Apr 13 15:19:28 2014 +0200

    Restructure Join Chat Dialog
    
    REVIEW: 117541
    Reviewed-By: David Edmundson <kde at davidedmundson.co.uk>
---
 CMakeLists.txt                        |   2 +-
 KTp/Models/rooms-model.cpp            |  67 +++++-
 KTp/Models/rooms-model.h              |  15 +-
 KTp/Widgets/join-chat-room-dialog.cpp | 311 ++++++++++-----------------
 KTp/Widgets/join-chat-room-dialog.h   |  10 +-
 KTp/Widgets/join-chat-room-dialog.ui  | 383 ++++++++++++++++------------------
 6 files changed, 353 insertions(+), 435 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d4ea59..a1247fa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,7 +10,7 @@ cmake_policy(SET CMP0002 OLD)
 
 set (KTP_VERSION "0.8.0")
 # Bump for every 0.x release, or whenever BC changes
-set (KTP_SONUMBER 7)
+set (KTP_SONUMBER 8) # Bumped for 0.9
 set (KTP_MESSAGE_FILTER_FRAMEWORK_VERSION "4")
 
 find_package (KDE4 REQUIRED)
diff --git a/KTp/Models/rooms-model.cpp b/KTp/Models/rooms-model.cpp
index 3291b58..f16fd57 100644
--- a/KTp/Models/rooms-model.cpp
+++ b/KTp/Models/rooms-model.cpp
@@ -61,6 +61,7 @@ QVariant KTp::RoomsModel::data(const QModelIndex &index, int role) const
     // all columns get an empty space for the decoration
     if (index.column() == PasswordColumn) {
         switch (role) {
+        case Qt::DisplayRole:
         case Qt::DecorationRole:
             if (roomInfo.info.value(QLatin1String("password")).toBool()) {
                 return KIcon(QLatin1String("object-locked"));
@@ -79,8 +80,6 @@ QVariant KTp::RoomsModel::data(const QModelIndex &index, int role) const
     switch(role) {
     case Qt::DisplayRole:
         switch (index.column()) {
-        case PasswordColumn:
-            return QVariant();
         case NameColumn:
             return roomInfo.info.value(QLatin1String("name"));
         case DescriptionColumn:
@@ -186,19 +185,49 @@ QVariant KTp::FavoriteRoomsModel::data(const QModelIndex &index, int role) const
     case Qt::EditRole: // Return same values for both Display and Edit roles
     case Qt::DisplayRole:
         switch (index.column()) {
-        case NameColumn:
-            return room.value(QLatin1String("name"));
+        case BookmarkColumn :
+            return QVariant();
         case HandleNameColumn:
             return room.value(QLatin1String("handle-name"));
         case AccountIdentifierColumn:
             return room.value(QLatin1String("account-identifier"));
         }
     case Qt::ToolTipRole:
-        return room.value(QLatin1String("handle-name"));
+        switch (index.column()) {
+        case BookmarkColumn:
+            if (room.value(QLatin1String("is-bookmarked")).toBool()) {
+                return i18n("Room bookmarked");
+            } else {
+                return i18n("Room not bookmarked");
+            }
+        case HandleNameColumn:
+        case AccountIdentifierColumn:
+            return room.value(QLatin1String("handle-name"));
+        }
+    case Qt::DecorationRole:
+        switch (index.column()) {
+        case BookmarkColumn:
+            if (room.value(QLatin1String("is-bookmarked")).toBool()) {
+                return KIcon(QLatin1String("bookmarks"));
+            } else {
+                return KIcon(KIcon(QLatin1String("bookmarks")).pixmap(32, 32, QIcon::Disabled));
+            }
+        case HandleNameColumn:
+        case AccountIdentifierColumn:
+            return QVariant();
+        }
+    case Qt::CheckStateRole:
+        switch (index.column()) {
+        case BookmarkColumn:
+            return room.value(QLatin1String("is-bookmarked")).toBool() ? Qt::Checked : Qt::Unchecked;
+        case HandleNameColumn:
+        case AccountIdentifierColumn:
+            return QVariant();
+        }
+    case FavoriteRoomsModel::BookmarkRole:
+        room.value(QLatin1String("is-bookmarked")).toBool();
     case FavoriteRoomsModel::HandleNameRole:
         return room.value(QLatin1String("handle-name"));
-    case FavoriteRoomsModel::NameRole:
-        return room.value(QLatin1String("name"));
     case FavoriteRoomsModel::AccountRole:
         return room.value(QLatin1String("account-identifier"));
     case FavoriteRoomsModel::FavoriteRoomRole:
@@ -219,8 +248,8 @@ bool KTp::FavoriteRoomsModel::setData(const QModelIndex &index, const QVariant &
 
     if (role == Qt::EditRole) {
         switch (index.column()) {
-        case NameColumn:
-            room.insert(QLatin1String("name"), value);
+        case BookmarkColumn:
+            room.insert(QLatin1String("is-bookmarked"), value);
             break;
         case HandleNameColumn:
             room.insert(QLatin1String("handle-name"), value);
@@ -234,11 +263,22 @@ bool KTp::FavoriteRoomsModel::setData(const QModelIndex &index, const QVariant &
         Q_EMIT dataChanged(index, index);
         return true;
     }
+    if (role == Qt::CheckStateRole) {
+        switch (index.column()) {
+        case BookmarkColumn:
+            room.insert(QLatin1String("is-bookmarked"), value == Qt::Checked ? true : false);
+            break;
+        }
+        Q_EMIT dataChanged(index, index);
+        return true;
+    }
     return false;
 }
 
 Qt::ItemFlags KTp::FavoriteRoomsModel::flags(const QModelIndex &index) const {
-    Q_UNUSED(index);
+    if (index.column() == BookmarkColumn) {
+        return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+    }
     return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 }
 
@@ -266,6 +306,13 @@ void KTp::FavoriteRoomsModel::removeRoom(const QVariantMap &room)
     endRemoveRows();
 }
 
+void KTp::FavoriteRoomsModel::clearRooms()
+{
+    beginResetModel();
+    m_favoriteRoomsList.clear();
+    endResetModel();
+}
+
 bool KTp::FavoriteRoomsModel::containsRoom(const QString &handle, const QString &account) const
 {
     bool contains = false;
diff --git a/KTp/Models/rooms-model.h b/KTp/Models/rooms-model.h
index 2ff1604..18d0b0a 100644
--- a/KTp/Models/rooms-model.h
+++ b/KTp/Models/rooms-model.h
@@ -34,10 +34,10 @@ class KTP_EXPORT RoomsModel : public QAbstractListModel
 public:
     // TODO: find a suitable icon and add an invitation column
     enum Column {
-        PasswordColumn=0,
+        NameColumn=0,
+        DescriptionColumn,
         MembersColumn,
-        NameColumn,
-        DescriptionColumn
+        PasswordColumn,
     };
 
     enum Roles {
@@ -72,14 +72,14 @@ class KTP_EXPORT FavoriteRoomsModel : public QAbstractListModel
 
 public:
     enum Column {
-        NameColumn = 0,
+        BookmarkColumn = 0,
         HandleNameColumn,
         AccountIdentifierColumn
     };
 
     enum Roles {
         HandleNameRole = Qt::UserRole,
-        NameRole,
+        BookmarkRole,
         AccountRole,
         FavoriteRoomRole
     };
@@ -113,6 +113,11 @@ public:
     void removeRoom(const QVariantMap &room);
 
     /**
+     * rief Remove all rooms from the list.
+     */
+    void clearRooms();
+
+    /**
      * rief Checks if it contains a room (identified by his handle-name).
      *
      * \param handle The handle to look for.
diff --git a/KTp/Widgets/join-chat-room-dialog.cpp b/KTp/Widgets/join-chat-room-dialog.cpp
index 9d55bd9..e8f1317 100644
--- a/KTp/Widgets/join-chat-room-dialog.cpp
+++ b/KTp/Widgets/join-chat-room-dialog.cpp
@@ -30,7 +30,6 @@
 #include <KMessageBox>
 #include <KNotification>
 #include <KPushButton>
-#include <KCompletionBox>
 
 #include <TelepathyQt/Account>
 #include <TelepathyQt/AccountSet>
@@ -53,7 +52,6 @@ KTp::JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager
     , m_model(new RoomsModel(this))
     , m_favoritesModel(new FavoriteRoomsModel(this))
     , m_favoritesProxyModel(new QSortFilterProxyModel(this))
-    , m_recentComp(new KCompletion)
     , m_joinInProgress(false)
 {
     QWidget *joinChatRoomDialog = new QWidget(this);
@@ -61,49 +59,43 @@ KTp::JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager
     ui->feedbackWidget->hide();
 
     setMainWidget(joinChatRoomDialog);
-    setWindowIcon(KIcon(QLatin1String("telepathy-kde")));
+    setWindowIcon(KIcon(QLatin1String("im-irc")));
+    setWindowTitle(i18nc("Dialog title", "Join Chat Room"));
+
+    ui->filterPicture->clear();
+    ui->filterPicture->setPixmap(KIconLoader::global()->loadIcon(QLatin1String("view-filter"), KIconLoader::Small));
 
     // config
     KSharedConfigPtr commonConfig = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
     m_favoriteRoomsGroup = commonConfig->group(QLatin1String("FavoriteRooms"));
     m_recentRoomsGroup = commonConfig->group(QLatin1String("RecentChatRooms"));
 
-    Q_FOREACH (const QString &key, m_recentRoomsGroup.keyList()) {
-        if (!m_recentRoomsGroup.readEntry(key, QStringList()).isEmpty()) {
-            m_recentRooms.insert(key, m_recentRoomsGroup.readEntry(key, QStringList()));
-        }
-    }
-
+    // load favorite and recent rooms
     loadFavoriteRooms();
 
     // disable OK button on start
     button(Ok)->setEnabled(false);
-
-    //set icons
-    ui->addFavoritePushButton->setIcon(KIcon(QLatin1String("list-add")));
-    ui->editFavoritePushButton->setIcon(KIcon(QLatin1String("list-edit")));
-    ui->removeFavoritePushButton->setIcon(KIcon(QLatin1String("list-remove")));
-    ui->removeRecentPushButton->setIcon(KIcon(QLatin1String("list-remove")));
-    ui->clearRecentPushButton->setIcon(KIcon(QLatin1String("edit-clear-list")));
-
+    button(Ok)->setText(i18nc("button", "Join/Create"));
+    button(Ok)->setIcon(KIcon(QLatin1String("im-irc")));
     connect(accountManager->becomeReady(), SIGNAL(finished(Tp::PendingOperation*)),
             this, SLOT(onAccountManagerReady(Tp::PendingOperation*)));
 
-    // favoritesTab
+    // Previous Tab
     m_favoritesProxyModel->setSourceModel(m_favoritesModel);
     m_favoritesProxyModel->setFilterKeyColumn(FavoriteRoomsModel::AccountIdentifierColumn);
+    m_favoritesProxyModel->setSortRole(Qt::CheckStateRole);
     m_favoritesProxyModel->setDynamicSortFilter(true);
 
-    ui->listView->setModel(m_favoritesProxyModel);
-    ui->listView->setModelColumn(FavoriteRoomsModel::NameColumn);
-
-    // recentTab
-    m_recentComp->setCompletionMode(KGlobalSettings::CompletionPopup);
-    m_recentComp->setIgnoreCase(true);
+    ui->previousView->setModel(m_favoritesProxyModel);
+    ui->previousView->setHeaderHidden(true);
+    ui->previousView->header()->setStretchLastSection(false);
+    ui->previousView->header()->setResizeMode(FavoriteRoomsModel::BookmarkColumn, QHeaderView::ResizeToContents);
+    ui->previousView->header()->setResizeMode(FavoriteRoomsModel::HandleNameColumn, QHeaderView::Stretch);
+    ui->previousView->setColumnHidden(FavoriteRoomsModel::AccountIdentifierColumn, true);
+    ui->previousView->sortByColumn(FavoriteRoomsModel::BookmarkColumn, Qt::DescendingOrder);
 
-    ui->lineEdit->setCompletionObject(m_recentComp);
-    ui->lineEdit->setAutoDeleteCompletionObject(true);
 
+    // Search Tab
     QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
     proxyModel->setSourceModel(m_model);
     proxyModel->setSortLocaleAware(true);
@@ -111,30 +103,27 @@ KTp::JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager
     proxyModel->setFilterKeyColumn(RoomsModel::NameColumn);
     proxyModel->setDynamicSortFilter(true);
 
-    ui->treeView->setModel(proxyModel);
-    ui->treeView->header()->setResizeMode(QHeaderView::ResizeToContents);
-    ui->treeView->sortByColumn(RoomsModel::NameColumn, Qt::AscendingOrder);
+    ui->queryView->setModel(proxyModel);
+    ui->queryView->header()->setStretchLastSection(false);
+    ui->queryView->header()->setResizeMode(0, QHeaderView::Stretch);
+    ui->queryView->header()->setResizeMode(1, QHeaderView::Stretch);
+    ui->queryView->header()->setResizeMode(2, QHeaderView::ResizeToContents);
+    ui->queryView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
+    ui->queryView->header()->setSortIndicatorShown(false);
+    ui->queryView->sortByColumn(RoomsModel::NameColumn, Qt::AscendingOrder);
 
     // connects
     connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(onTextChanged(QString)));
-    connect(ui->listView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
-    connect(ui->listView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
+    connect(ui->previousView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
+    connect(ui->previousView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
             this, SLOT(onFavoriteRoomSelectionChanged(QModelIndex,QModelIndex)));
     connect(m_favoritesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
             this, SLOT(onFavoriteRoomDataChanged(QModelIndex,QModelIndex)));
-    connect(ui->addFavoritePushButton, SIGNAL(clicked(bool)), this, SLOT(addFavorite()));
-    connect(ui->editFavoritePushButton, SIGNAL(clicked(bool)), this, SLOT(editFavorite()));
-    connect(ui->removeFavoritePushButton, SIGNAL(clicked(bool)), this, SLOT(removeFavorite()));
-    connect(ui->recentListWidget, SIGNAL(currentTextChanged(QString)), ui->lineEdit, SLOT(setText(QString)));
-    connect(ui->recentListWidget, SIGNAL(currentTextChanged(QString)), this, SLOT(onRecentRoomClicked()));
-    connect(ui->recentListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(accept()));
-    connect(ui->removeRecentPushButton, SIGNAL(clicked(bool)), this , SLOT(removeRecentRoom()));
     connect(ui->clearRecentPushButton, SIGNAL(clicked(bool)), this, SLOT(clearRecentRooms()));
     connect(ui->serverLineEdit, SIGNAL(returnPressed()), this, SLOT(getRoomList()));
-    connect(ui->queryPushButton, SIGNAL(clicked(bool)), this, SLOT(getRoomList()));
-    connect(ui->stopPushButton, SIGNAL(clicked(bool)), this, SLOT(stopListing()));
-    connect(ui->treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(onRoomClicked(QModelIndex)));
-    connect(ui->treeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
+    connect(ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(getRoomList()));
+    connect(ui->queryView, SIGNAL(clicked(QModelIndex)), this, SLOT(onRoomClicked(QModelIndex)));
+    connect(ui->queryView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
     connect(ui->filterBar, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString)));
     connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onAccountSelectionChanged(int)));
     connect(button(Ok), SIGNAL(clicked(bool)), this, SLOT(addRecentRoom()));
@@ -167,7 +156,7 @@ void KTp::JoinChatRoomDialog::onAccountManagerReady(Tp::PendingOperation* operat
 
     // queryTab
     if (ui->comboBox->count() > 0) {
-        ui->queryPushButton->setEnabled(true);
+        ui->queryButton->setEnabled(true);
     }
 
     // apply the filter after populating
@@ -210,177 +199,83 @@ void KTp::JoinChatRoomDialog::onAccountSelectionChanged(int newIndex)
     QString accountIdentifier = ui->comboBox->currentAccount()->uniqueIdentifier();
     m_favoritesProxyModel->setFilterFixedString(accountIdentifier);
 
-    // Provide only rooms recently used with the selected account for completion
-    m_recentComp->clear();
-
-    Q_FOREACH (const QString &room, m_recentRooms.value(accountIdentifier)) {
-        m_recentComp->addItem(room);
-    }
-
-    // Show only rooms recently used with the selected account in the list
-    ui->recentListWidget->clear();
-    ui->recentListWidget->addItems(m_recentRooms.value(accountIdentifier));
-
     // Enable/disable the buttons as appropriate
-    bool recentListNonEmpty = m_recentRooms.value(accountIdentifier).size() > 0;
-
-    ui->clearRecentPushButton->setEnabled(recentListNonEmpty);
-    ui->removeRecentPushButton->setEnabled(recentListNonEmpty);
-}
-
-void KTp::JoinChatRoomDialog::addFavorite()
-{
-    if (!ui->comboBox->currentAccount()) {
-        return;
-    }
-
-    bool ok = false;
-    QString favoriteHandle = ui->lineEdit->text();
-    QString favoriteAccount = ui->comboBox->currentAccount()->uniqueIdentifier();
-
-    if (m_favoritesModel->containsRoom(favoriteHandle, favoriteAccount)) {
-        KMessageBox::sorry(this, i18n("This room is already in your favorites."));
-    } else {
-        QString favoriteName = KInputDialog::getText(i18n("Add room"), i18n("Name"), QString(), &ok);
-
-        if (ok) {
-            QString key = favoriteHandle + favoriteAccount;
-
-            // Write it to the config file
-            QVariantList favorite;
-            favorite.append(favoriteName);
-            favorite.append(favoriteHandle);
-            favorite.append(favoriteAccount);
-            m_favoriteRoomsGroup.writeEntry(key, favorite);
-            m_favoriteRoomsGroup.sync();
-
-            // Insert it into the model
-            QVariantMap room;
-            room.insert(QLatin1String("name"), favoriteName);
-            room.insert(QLatin1String("handle-name"), favoriteHandle);
-            room.insert(QLatin1String("account-identifier"), favoriteAccount);
-            m_favoritesModel->addRoom(room);
-        }
-    }
-}
-
-void KTp::JoinChatRoomDialog::editFavorite()
-{
-    ui->listView->edit(ui->listView->currentIndex());
-}
-
-void KTp::JoinChatRoomDialog::removeFavorite()
-{
-    QString favoriteHandle = ui->listView->currentIndex().data(FavoriteRoomsModel::HandleNameRole).toString();
-    QString favoriteAccount = ui->comboBox->currentAccount()->uniqueIdentifier();
-    QVariantMap room = ui->listView->currentIndex().data(FavoriteRoomsModel::FavoriteRoomRole).value<QVariantMap>();
-
-    QString key = favoriteHandle + favoriteAccount;
-
-    if(m_favoriteRoomsGroup.keyList().contains(key)) {
-        m_favoriteRoomsGroup.deleteEntry(key);
-        m_favoriteRoomsGroup.sync();
-        m_favoritesModel->removeRoom(room);
-
-        if (m_favoritesModel->countForAccount(favoriteAccount) == 0) {
-            ui->removeFavoritePushButton->setEnabled(false);
-        }
-    }
+    ui->clearRecentPushButton->setEnabled(!m_recentRoomsGroup.keyList().empty());
 }
 
 void KTp::JoinChatRoomDialog::onFavoriteRoomDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
 {
-    // Because listView only allows editing of a single row, assume that topLeft points to the changed data.
+    // Because previousView only allows editing of a single row, assume that topLeft points to the changed data.
     Q_UNUSED(bottomRight);
 
+    bool bookmarked = topLeft.data(Qt::CheckStateRole) == Qt::Checked ? true : false;
     const QString &favoriteHandle = topLeft.data(FavoriteRoomsModel::HandleNameRole).toString();
-    const QString &favoriteName = topLeft.data(FavoriteRoomsModel::NameRole).toString();
     const QString &favoriteAccount = topLeft.data(FavoriteRoomsModel::AccountRole).toString();
 
     const QString &key = favoriteHandle + favoriteAccount;
 
     // Write the changed room to the config file
     QVariantList favorite;
-    favorite.append(favoriteName);
     favorite.append(favoriteHandle);
     favorite.append(favoriteAccount);
-    m_favoriteRoomsGroup.writeEntry(key, favorite);
-    m_favoriteRoomsGroup.sync();
+
+    if (bookmarked) {
+        if (m_recentRoomsGroup.keyList().contains(key)) {
+            m_recentRoomsGroup.deleteEntry(key);
+            m_recentRoomsGroup.sync();
+        }
+        m_favoriteRoomsGroup.writeEntry(key, favorite);
+        m_favoriteRoomsGroup.sync();
+    } else {
+        if (m_favoriteRoomsGroup.keyList().contains(key)) {
+            m_favoriteRoomsGroup.deleteEntry(key);
+            m_favoriteRoomsGroup.sync();
+        }
+        m_recentRoomsGroup.writeEntry(key, favorite);
+        m_recentRoomsGroup.sync();
+    }
+
+    onAccountSelectionChanged(ui->comboBox->currentIndex());
 }
 
 void KTp::JoinChatRoomDialog::addRecentRoom()
 {
     Tp::AccountPtr account = ui->comboBox->currentAccount();
-    if (!account) {
+    if (!account || ui->lineEdit->text().isEmpty()) {
         return;
     }
 
-    QString accountIdentifier = account->uniqueIdentifier();
-    QString handle = ui->lineEdit->text();
-
-    if (!handle.isEmpty()) {
-        if (m_recentRooms.contains(accountIdentifier)) {
-            QStringList currentList = m_recentRooms.take(accountIdentifier);
-
-            // If the handle is already in the list move it at the first position
-            // because now it is the most recent
-            if (currentList.contains(handle)) {
-                currentList.move(currentList.indexOf(handle), 0);
-                m_recentRooms.insert(accountIdentifier, currentList);
-            // else just insert it at the first position and check for the size
-            } else {
-                currentList.insert(0, handle);
-
-                if (currentList.size() > 8) {
-                    currentList.removeLast();
-                }
-
-                m_recentRooms.insert(accountIdentifier, currentList);
-            }
-        } else {
-            m_recentRooms.insert(accountIdentifier, QStringList(handle));
-        }
+    QString recentAccount = account->uniqueIdentifier();
+    QString recentHandle = ui->lineEdit->text();
+    const QString &key = recentHandle + recentAccount;
 
-        // Write it to the config
-        m_recentRoomsGroup.writeEntry(accountIdentifier, m_recentRooms.value(accountIdentifier));
-        m_recentRoomsGroup.sync();
-    }
-}
-
-void KTp::JoinChatRoomDialog::removeRecentRoom()
-{
-    QString accountIdentifier = ui->comboBox->currentAccount()->uniqueIdentifier();
-    QString handle = ui->recentListWidget->currentItem()->text();
+    QVariantList recent;
+    recent.append(recentHandle);
+    recent.append(recentAccount);
 
-    // Remove the entry
-    QStringList currentList = m_recentRooms.take(accountIdentifier);
-    currentList.removeOne(handle);
-    m_recentRooms.insert(accountIdentifier, currentList);
-
-    // Update the completion and list
-    onAccountSelectionChanged(ui->comboBox->currentIndex());
+    if(m_favoriteRoomsGroup.keyList().contains(key) || m_recentRoomsGroup.keyList().contains(key)) {
+        return;
+    }
 
-    // Write it to the config
-    m_recentRoomsGroup.writeEntry(accountIdentifier, m_recentRooms.value(accountIdentifier));
+    m_recentRoomsGroup.writeEntry(key, recent);
     m_recentRoomsGroup.sync();
-
-    // Disable the button
-    ui->removeRecentPushButton->setEnabled(false);
 }
 
+
 void KTp::JoinChatRoomDialog::clearRecentRooms()
 {
     QString accountIdentifier = ui->comboBox->currentAccount()->uniqueIdentifier();
 
-    // Remove all entries for the current account
-    m_recentRooms.remove(accountIdentifier);
+    KSharedConfigPtr commonConfig = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+    commonConfig->deleteGroup(QLatin1String("RecentChatRooms"));
+    commonConfig->sync();
 
-    // Update the completion and list
-    onAccountSelectionChanged(ui->comboBox->currentIndex());
+    // Reload the model
+    m_favoritesModel->clearRooms();
+    loadFavoriteRooms();
 
-    // Update the config
-    m_recentRoomsGroup.deleteEntry(accountIdentifier);
-    m_recentRoomsGroup.sync();
+    // Update the list
+    onAccountSelectionChanged(ui->comboBox->currentIndex());
 }
 
 void KTp::JoinChatRoomDialog::getRoomList()
@@ -458,8 +353,12 @@ void KTp::JoinChatRoomDialog::onRoomListChannelClosed(Tp::PendingOperation *oper
         QString errorMsg(operation->errorName() + QLatin1String(": ") + operation->errorMessage());
         sendNotificationToUser(errorMsg);
     } else {
-        ui->queryPushButton->setEnabled(true);
-        ui->stopPushButton->setEnabled(false);
+        ui->queryButton->setEnabled(true);
+        ui->queryButton->setIcon(KIcon(QLatin1String("media-playback-start")));
+        ui->queryButton->setText(i18nc("Button text", "Query"));
+        ui->queryButton->setToolTip(i18nc("Tooltip text", "Start query"));
+        connect(ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(getRoomList()));
+        disconnect(ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(stopListing()));
     }
 }
 
@@ -467,8 +366,12 @@ void KTp::JoinChatRoomDialog::onListing(bool isListing)
 {
     if (isListing) {
         kDebug() << "listing";
-        ui->queryPushButton->setEnabled(false);
-        ui->stopPushButton->setEnabled(true);
+        ui->queryButton->setEnabled(true);
+        ui->queryButton->setIcon(KIcon(QLatin1String("media-playback-stop")));
+        ui->queryButton->setText(i18nc("Button text", "Stop"));
+        ui->queryButton->setToolTip(i18nc("Tooltip text", "Stop query"));
+        disconnect(ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(getRoomList()));
+        connect(ui->queryButton, SIGNAL(clicked(bool)), this, SLOT(stopListing()));
     } else {
         kDebug() << "finished listing";
         Tp::PendingOperation *op =  m_roomListChannel->requestClose();
@@ -487,20 +390,10 @@ void KTp::JoinChatRoomDialog::onFavoriteRoomSelectionChanged(const QModelIndex &
 {
     Q_UNUSED(previous);
     if (current.isValid()) {
-        ui->editFavoritePushButton->setEnabled(true);
-        ui->removeFavoritePushButton->setEnabled(true);
         ui->lineEdit->setText(current.data(FavoriteRoomsModel::HandleNameRole).toString());
-    } else {
-        ui->editFavoritePushButton->setEnabled(false);
-        ui->removeFavoritePushButton->setEnabled(false);
     }
 }
 
-void KTp::JoinChatRoomDialog::onRecentRoomClicked()
-{
-    ui->removeRecentPushButton->setEnabled(true);
-}
-
 void KTp::JoinChatRoomDialog::onRoomClicked(const QModelIndex &index)
 {
     ui->lineEdit->setText(index.data(RoomsModel::HandleNameRole).toString());
@@ -513,13 +406,7 @@ QString KTp::JoinChatRoomDialog::selectedChatRoom() const
 
 void KTp::JoinChatRoomDialog::onTextChanged(QString newText)
 {
-    if (newText.isEmpty()) {
-        button(Ok)->setEnabled(false);
-        ui->addFavoritePushButton->setEnabled(false);
-    } else {
-        button(Ok)->setEnabled(true);
-        ui->addFavoritePushButton->setEnabled(true);
-    }
+    button(Ok)->setEnabled(!newText.isEmpty());
 }
 
 void KTp::JoinChatRoomDialog::onStartChatFinished(Tp::PendingOperation *op)
@@ -562,16 +449,32 @@ void KTp::JoinChatRoomDialog::loadFavoriteRooms()
 
     Q_FOREACH(const QString &key, m_favoriteRoomsGroup.keyList()) {
         QVariantList favorite = m_favoriteRoomsGroup.readEntry(key, QVariantList());
-        QString favoriteName = favorite.at(0).toString();
-        QString favoriteHandle = favorite.at(1).toString();
-        QString favoriteAccount = favorite.at(2).toString();
-
+        // Keep compatibility with KTp 0.8 and previous
+        if(favorite.size() == 3) {
+            // Update the entry in the config file
+            favorite.removeFirst();
+            m_favoriteRoomsGroup.writeEntry(key, favorite);
+            m_favoriteRoomsGroup.sync();
+        }
+        QString favoriteHandle = favorite.at(0).toString();
+        QString favoriteAccount = favorite.at(1).toString();
         QVariantMap room;
-        room.insert(QLatin1String("name"), favoriteName);
+        room.insert(QLatin1String("is-bookmarked"), true);
         room.insert(QLatin1String("handle-name"), favoriteHandle);
         room.insert(QLatin1String("account-identifier"), favoriteAccount);
         roomList.append(room);
     }
 
+    Q_FOREACH (const QString &key, m_recentRoomsGroup.keyList()) {
+        QVariantList recent = m_recentRoomsGroup.readEntry(key, QVariantList());
+        QString recentHandle = recent.at(0).toString();
+        QString recentAccount = recent.at(1).toString();
+        QVariantMap room;
+        room.insert(QLatin1String("is-bookmarked"), false);
+        room.insert(QLatin1String("handle-name"), recentHandle);
+        room.insert(QLatin1String("account-identifier"), recentAccount);
+        roomList.append(room);
+    }
+
     m_favoritesModel->addRooms(roomList);
 }
diff --git a/KTp/Widgets/join-chat-room-dialog.h b/KTp/Widgets/join-chat-room-dialog.h
index 80a1be3..7a33e0a 100644
--- a/KTp/Widgets/join-chat-room-dialog.h
+++ b/KTp/Widgets/join-chat-room-dialog.h
@@ -34,7 +34,6 @@ class JoinChatRoomDialog;
 class RoomsModel;
 class FavoriteRoomsModel;
 class QSortFilterProxyModel;
-class KCompletion;
 
 namespace KTp {
 
@@ -56,11 +55,7 @@ protected:
 private Q_SLOTS:
     void onTextChanged(QString newText);
     void onAccountSelectionChanged(int newIndex);
-    void addFavorite();
-    void editFavorite();
-    void removeFavorite();
     void addRecentRoom();
-    void removeRecentRoom();
     void clearRecentRooms();
     void getRoomList();
     void stopListing();
@@ -71,7 +66,6 @@ private Q_SLOTS:
     void onGotRooms(Tp::RoomInfoList roomInfoList);
     void onFavoriteRoomSelectionChanged(const QModelIndex &current, const QModelIndex &previous);
     void onFavoriteRoomDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
-    void onRecentRoomClicked();
     void onRoomClicked(const QModelIndex &index);
     void onAccountManagerReady(Tp::PendingOperation*);
     void onStartChatFinished(Tp::PendingOperation *op);
@@ -93,12 +87,10 @@ private:
     QSortFilterProxyModel *m_favoritesProxyModel;
     KConfigGroup m_favoriteRoomsGroup;
     KConfigGroup m_recentRoomsGroup;
-    QHash <QString, QStringList> m_recentRooms;
-    KCompletion *m_recentComp;
     bool m_joinInProgress;
-
 };
 
 } //namespace KTp
 
+
 #endif  // JOINCHATROOMDIALOG_H
diff --git a/KTp/Widgets/join-chat-room-dialog.ui b/KTp/Widgets/join-chat-room-dialog.ui
index ca72088..e323833 100644
--- a/KTp/Widgets/join-chat-room-dialog.ui
+++ b/KTp/Widgets/join-chat-room-dialog.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>525</width>
-    <height>325</height>
+    <width>584</width>
+    <height>369</height>
    </rect>
   </property>
   <property name="minimumSize">
@@ -24,218 +24,189 @@
     <widget class="KMessageWidget" name="feedbackWidget" native="true"/>
    </item>
    <item>
-    <widget class="KTp::AccountsComboBox" name="comboBox"/>
-   </item>
-   <item>
-    <widget class="QLabel" name="label">
-     <property name="text">
-      <string>Enter chat room:</string>
+    <widget class="QGroupBox" name="accountGroupBox">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
      </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="KLineEdit" name="lineEdit">
-     <property name="showClearButton" stdset="0">
-      <bool>true</bool>
+     <property name="title">
+      <string>Account</string>
      </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_2">
+      <item>
+       <widget class="KTp::AccountsComboBox" name="comboBox">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+     </layout>
     </widget>
    </item>
    <item>
-    <widget class="QTabWidget" name="tabWidget">
-     <property name="currentIndex">
-      <number>0</number>
+    <widget class="QGroupBox" name="chatRoomGroupBox">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
      </property>
-     <widget class="QWidget" name="favoritesTab">
-      <attribute name="title">
-       <string>Favorites</string>
-      </attribute>
-      <layout class="QVBoxLayout" name="verticalLayout_3">
-       <item>
-        <layout class="QHBoxLayout" name="horizontalLayout_2">
-         <item>
-          <widget class="QListView" name="listView"/>
-         </item>
-         <item>
-          <layout class="QVBoxLayout" name="verticalLayout_4">
-           <item>
-            <widget class="QPushButton" name="addFavoritePushButton">
-             <property name="enabled">
-              <bool>false</bool>
-             </property>
-             <property name="text">
-              <string>Add Room</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QPushButton" name="editFavoritePushButton">
-             <property name="enabled">
-              <bool>false</bool>
-             </property>
-             <property name="text">
-              <string>Edit Room</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QPushButton" name="removeFavoritePushButton">
-             <property name="enabled">
-              <bool>false</bool>
-             </property>
-             <property name="text">
-              <string>Remove Room</string>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <spacer name="verticalSpacer">
-             <property name="orientation">
-              <enum>Qt::Vertical</enum>
-             </property>
-             <property name="sizeHint" stdset="0">
-              <size>
-               <width>20</width>
-               <height>40</height>
-              </size>
-             </property>
-            </spacer>
-           </item>
-          </layout>
-         </item>
-        </layout>
-       </item>
-      </layout>
-     </widget>
-     <widget class="QWidget" name="recentTab">
-      <attribute name="title">
-       <string>Recent</string>
-      </attribute>
-      <layout class="QHBoxLayout" name="horizontalLayout_3">
-       <item>
-        <widget class="QListWidget" name="recentListWidget"/>
-       </item>
-       <item>
-        <layout class="QVBoxLayout" name="verticalLayout_5">
-         <item>
-          <widget class="QPushButton" name="removeRecentPushButton">
-           <property name="enabled">
-            <bool>false</bool>
-           </property>
-           <property name="text">
-            <string>Remove</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QPushButton" name="clearRecentPushButton">
-           <property name="enabled">
-            <bool>false</bool>
-           </property>
-           <property name="text">
-            <string>Clear list</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <spacer name="verticalSpacer_2">
-           <property name="orientation">
-            <enum>Qt::Vertical</enum>
-           </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>20</width>
-             <height>40</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
-        </layout>
-       </item>
-      </layout>
-     </widget>
-     <widget class="QWidget" name="queryTab">
-      <attribute name="title">
-       <string>Query</string>
-      </attribute>
-      <layout class="QVBoxLayout" name="verticalLayout_2">
-       <item>
-        <widget class="QLabel" name="serverLabel">
-         <property name="text">
-          <string>Server to be queried:</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <layout class="QHBoxLayout" name="horizontalLayout">
-         <item>
-          <widget class="KLineEdit" name="serverLineEdit">
-           <property name="placeholderText">
-            <string/>
-           </property>
-           <property name="clickMessage">
-            <string>Leave blank for the selected account's default server</string>
-           </property>
-           <property name="showClearButton" stdset="0">
-            <bool>true</bool>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QPushButton" name="queryPushButton">
-           <property name="enabled">
-            <bool>false</bool>
-           </property>
-           <property name="text">
-            <string>Query</string>
-           </property>
-          </widget>
-         </item>
-         <item>
-          <widget class="QPushButton" name="stopPushButton">
-           <property name="enabled">
-            <bool>false</bool>
-           </property>
-           <property name="text">
-            <string>Stop</string>
-           </property>
-          </widget>
-         </item>
-        </layout>
-       </item>
-       <item>
-        <widget class="QTreeView" name="treeView">
-         <property name="alternatingRowColors">
-          <bool>true</bool>
-         </property>
-         <property name="selectionMode">
-          <enum>QAbstractItemView::ExtendedSelection</enum>
-         </property>
-         <property name="rootIsDecorated">
-          <bool>false</bool>
-         </property>
-         <property name="uniformRowHeights">
-          <bool>true</bool>
-         </property>
-         <property name="allColumnsShowFocus">
-          <bool>true</bool>
-         </property>
+     <property name="title">
+      <string>Chat Room</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <widget class="QTabWidget" name="tabWidget">
+        <property name="currentIndex">
+         <number>0</number>
+        </property>
+        <widget class="QWidget" name="previousTab">
+         <attribute name="title">
+          <string>Previous</string>
+         </attribute>
+         <layout class="QVBoxLayout" name="verticalLayout_4">
+          <item>
+           <widget class="QTreeView" name="previousView">
+            <property name="alternatingRowColors">
+             <bool>true</bool>
+            </property>
+            <property name="rootIsDecorated">
+             <bool>false</bool>
+            </property>
+            <property name="uniformRowHeights">
+             <bool>true</bool>
+            </property>
+            <property name="sortingEnabled">
+             <bool>true</bool>
+            </property>
+            <property name="allColumnsShowFocus">
+             <bool>true</bool>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QPushButton" name="clearRecentPushButton">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="text">
+             <string>Clear Recent Rooms</string>
+            </property>
+            <property name="icon">
+             <iconset theme="edit-clear-list">
+              <normaloff>../../../../../home/drdanz/.designer/backup</normaloff>../../../../../home/drdanz/.designer/backup</iconset>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="KLineEdit" name="lineEdit">
+            <property name="clickMessage">
+             <string>Enter chat room name or address</string>
+            </property>
+            <property name="showClearButton" stdset="0">
+             <bool>true</bool>
+            </property>
+           </widget>
+          </item>
+         </layout>
         </widget>
-       </item>
-       <item>
-        <widget class="KLineEdit" name="filterBar">
-         <property name="placeholderText">
-          <string/>
-         </property>
-         <property name="clickMessage">
-          <string>Search rooms</string>
-         </property>
-         <property name="showClearButton" stdset="0">
-          <bool>true</bool>
-         </property>
+        <widget class="QWidget" name="searchTab">
+         <attribute name="title">
+          <string>Search</string>
+         </attribute>
+         <layout class="QVBoxLayout" name="verticalLayout_3">
+          <item>
+           <widget class="QLabel" name="serverLabel">
+            <property name="text">
+             <string>Server to be queried:</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <layout class="QHBoxLayout" name="queryHLayout">
+            <item>
+             <widget class="KLineEdit" name="serverLineEdit">
+              <property name="placeholderText">
+               <string/>
+              </property>
+              <property name="clickMessage">
+               <string>Leave blank for the selected account's default server</string>
+              </property>
+              <property name="showClearButton" stdset="0">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QToolButton" name="queryButton">
+              <property name="enabled">
+               <bool>false</bool>
+              </property>
+              <property name="text">
+               <string>Query</string>
+              </property>
+              <property name="icon">
+               <iconset theme="media-playback-start">
+                <normaloff/>
+               </iconset>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </item>
+          <item>
+           <widget class="QTreeView" name="queryView">
+            <property name="alternatingRowColors">
+             <bool>true</bool>
+            </property>
+            <property name="rootIsDecorated">
+             <bool>false</bool>
+            </property>
+            <property name="uniformRowHeights">
+             <bool>true</bool>
+            </property>
+            <property name="sortingEnabled">
+             <bool>true</bool>
+            </property>
+            <property name="allColumnsShowFocus">
+             <bool>true</bool>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <layout class="QHBoxLayout" name="filterHLayout">
+            <item>
+             <widget class="QLabel" name="filterPicture">
+              <property name="text">
+               <string notr="true">Filter</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="KLineEdit" name="filterBar">
+              <property name="placeholderText">
+               <string/>
+              </property>
+              <property name="clickMessage">
+               <string>Filter rooms</string>
+              </property>
+              <property name="showClearButton" stdset="0">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </item>
+         </layout>
         </widget>
-       </item>
-      </layout>
-     </widget>
+       </widget>
+      </item>
+     </layout>
     </widget>
    </item>
   </layout>

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list