[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:09:59 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=caa4e4e

The following commit has been merged in the master branch:
commit caa4e4e53b7074a15936f97730fc875033604f01
Author: Dominik Cermak <d.cermak at arcor.de>
Date:   Wed Mar 14 10:17:31 2012 +0100

    Handle favorites in JoinChatroomDialog
    
    Now one can maintain a list of favorite chatrooms.
    Each account has it's own favorites.
    
    CCBUG: 291711
    REVIEW: 104173
---
 dialogs/join-chat-room-dialog.cpp | 126 +++++++++++++++++++++-
 dialogs/join-chat-room-dialog.h   |  10 ++
 dialogs/join-chat-room-dialog.ui  | 219 ++++++++++++++++++++++++++------------
 rooms-model.cpp                   |  95 +++++++++++++++++
 rooms-model.h                     |  55 ++++++++++
 5 files changed, 430 insertions(+), 75 deletions(-)

diff --git a/dialogs/join-chat-room-dialog.cpp b/dialogs/join-chat-room-dialog.cpp
index 06d0a3a..026c5e4 100644
--- a/dialogs/join-chat-room-dialog.cpp
+++ b/dialogs/join-chat-room-dialog.cpp
@@ -24,14 +24,17 @@
 
 #include <KTp/Models/accounts-model.h>
 
-#include <KDE/KPushButton>
+#include <KConfig>
+#include <KInputDialog>
+#include <KMessageBox>
 #include <KNotification>
+#include <KPushButton>
 
 #include <TelepathyQt/AccountManager>
-#include <TelepathyQt/RoomListChannel>
 #include <TelepathyQt/ChannelTypeRoomListInterface>
 #include <TelepathyQt/PendingChannel>
 #include <TelepathyQt/PendingReady>
+#include <TelepathyQt/RoomListChannel>
 
 #include <QSortFilterProxyModel>
 
@@ -42,7 +45,9 @@
 JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWidget* parent)
     : KDialog(parent, Qt::Dialog)
     , ui(new Ui::JoinChatRoomDialog)
-    , m_model(new RoomsModel(this)
+    , m_model(new RoomsModel(this))
+    , m_favoritesModel(new FavoriteRoomsModel(this))
+    , m_favoritesProxyModel(new QSortFilterProxyModel(this)
     )
 {
     QWidget *joinChatRoomDialog = new QWidget(this);
@@ -51,6 +56,12 @@ JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWi
     setMainWidget(joinChatRoomDialog);
     setWindowIcon(KIcon("telepathy-kde"));
 
+    // config
+    KSharedConfigPtr config = KSharedConfig::openConfig("ktelepathyrc");
+    m_favoriteRoomsGroup = config->group("FavoriteRooms");
+
+    loadFavoriteRooms();
+
     // disable OK button on start
     button(Ok)->setEnabled(false);
 
@@ -64,6 +75,18 @@ JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWi
         }
     }
 
+    // Apply the filter after populating
+    onAccountSelectionChanged(ui->comboBox->currentIndex());
+
+    // FavoritesTab
+    m_favoritesProxyModel->setSourceModel(m_favoritesModel);
+    m_favoritesProxyModel->setFilterKeyColumn(FavoriteRoomsModel::AccountIdentifierColumn);
+    m_favoritesProxyModel->setDynamicSortFilter(true);
+
+    ui->listView->setModel(m_favoritesProxyModel);
+    ui->listView->setModelColumn(FavoriteRoomsModel::NameColumn);
+
+    // QueryTab
     if (ui->comboBox->count() > 0) {
         ui->queryPushButton->setEnabled(true);
     }
@@ -81,10 +104,14 @@ JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWi
 
     // connects
     connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(onTextChanged(QString)));
+    connect(ui->listView, SIGNAL(clicked(QModelIndex)), this, SLOT(onFavoriteRoomClicked(QModelIndex)));
+    connect(ui->addFavoritePushButton, SIGNAL(clicked(bool)), this, SLOT(addFavorite()));
+    connect(ui->removeFavoritePushButton, SIGNAL(clicked(bool)), this, SLOT(removeFavorite()));
     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->filterBar, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString)));
+    connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onAccountSelectionChanged(int)));
 }
 
 JoinChatRoomDialog::~JoinChatRoomDialog()
@@ -108,6 +135,61 @@ Tp::AccountPtr JoinChatRoomDialog::selectedAccount() const
     return account;
 }
 
+void JoinChatRoomDialog::onAccountSelectionChanged(int newIndex)
+{
+    QString accountIdentifier = ui->comboBox->itemData(newIndex).toString();
+    m_favoritesProxyModel->setFilterFixedString(accountIdentifier);
+}
+
+void JoinChatRoomDialog::addFavorite()
+{
+    bool ok = false;
+    QString favoriteHandle = ui->lineEdit->text();
+    QString favoriteAccount = ui->comboBox->itemData(ui->comboBox->currentIndex()).toString();
+
+    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("name", favoriteName);
+            room.insert("handle-name", favoriteHandle);
+            room.insert("account-identifier", favoriteAccount);
+            m_favoritesModel->addRoom(room);
+        }
+    }
+}
+
+void JoinChatRoomDialog::removeFavorite()
+{
+    QString favoriteHandle = ui->listView->currentIndex().data(FavoriteRoomsModel::HandleNameRole).toString();
+    QVariantMap room = ui->listView->currentIndex().data(FavoriteRoomsModel::FavoriteRoomRole).value<QVariantMap>();
+
+    if(m_favoriteRoomsGroup.keyList().contains(favoriteHandle)) {
+        m_favoriteRoomsGroup.deleteEntry(favoriteHandle);
+        m_favoriteRoomsGroup.sync();
+
+        m_favoritesModel->removeRoom(room);
+
+        if (m_favoritesModel->rowCount() == 0) {
+            ui->removeFavoritePushButton->setEnabled(false);
+        }
+    }
+}
+
 void JoinChatRoomDialog::getRoomList()
 {
     Tp::AccountPtr account = selectedAccount();
@@ -205,6 +287,16 @@ void JoinChatRoomDialog::onGotRooms(Tp::RoomInfoList roomInfoList)
     m_model->addRooms(roomInfoList);
 }
 
+void JoinChatRoomDialog::onFavoriteRoomClicked(const QModelIndex &index)
+{
+    if (index.isValid()) {
+        ui->removeFavoritePushButton->setEnabled(true);
+        ui->lineEdit->setText(index.data(FavoriteRoomsModel::HandleNameRole).toString());
+    } else {
+        ui->removeFavoritePushButton->setEnabled(false);
+    }
+}
+
 void JoinChatRoomDialog::onRoomClicked(const QModelIndex& index)
 {
     ui->lineEdit->setText(index.data(RoomsModel::HandleNameRole).toString());
@@ -217,8 +309,12 @@ QString JoinChatRoomDialog::selectedChatRoom() const
 
 void JoinChatRoomDialog::onTextChanged(QString newText)
 {
-    if (button(Ok)->isEnabled() == newText.isEmpty()) {
-        button(Ok)->setEnabled(!newText.isEmpty());
+    if (newText.isEmpty()) {
+        button(Ok)->setEnabled(false);
+        ui->addFavoritePushButton->setEnabled(false);
+    } else {
+        button(Ok)->setEnabled(true);
+        ui->addFavoritePushButton->setEnabled(true);
     }
 }
 
@@ -231,3 +327,23 @@ void JoinChatRoomDialog::sendNotificationToUser(const QString& errorMsg)
     notification->setText(errorMsg);
     notification->sendEvent();
 }
+
+void JoinChatRoomDialog::loadFavoriteRooms()
+{
+    QList<QVariantMap> roomList;
+
+    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();
+
+        QVariantMap room;
+        room.insert("name", favoriteName);
+        room.insert("handle-name", favoriteHandle);
+        room.insert("account-identifier", favoriteAccount);
+        roomList.append(room);
+    }
+
+    m_favoritesModel->addRooms(roomList);
+}
diff --git a/dialogs/join-chat-room-dialog.h b/dialogs/join-chat-room-dialog.h
index b5f7c67..686fe31 100644
--- a/dialogs/join-chat-room-dialog.h
+++ b/dialogs/join-chat-room-dialog.h
@@ -29,6 +29,8 @@ namespace Ui {
 }
 
 class RoomsModel;
+class FavoriteRoomsModel;
+class QSortFilterProxyModel;
 
 class JoinChatRoomDialog : public KDialog
 {
@@ -43,6 +45,9 @@ public:
 
 private slots:
     void onTextChanged(QString newText);
+    void onAccountSelectionChanged(int newIndex);
+    void addFavorite();
+    void removeFavorite();
     void getRoomList();
     void stopListing();
     void onRoomListChannelReadyForHandling(Tp::PendingOperation *operation);
@@ -50,10 +55,12 @@ private slots:
     void onRoomListChannelClosed(Tp::PendingOperation *operation);
     void onListing(bool isListing);
     void onGotRooms(Tp::RoomInfoList roomInfoList);
+    void onFavoriteRoomClicked(const QModelIndex &index);
     void onRoomClicked(const QModelIndex &index);
 
 private:
     void sendNotificationToUser(const QString& errorMsg);
+    void loadFavoriteRooms();
 
     QList<Tp::AccountPtr> m_accounts;
     Ui::JoinChatRoomDialog *ui;
@@ -61,6 +68,9 @@ private:
     Tp::ChannelPtr m_roomListChannel;
     Tp::Client::ChannelTypeRoomListInterface *m_iface;
     RoomsModel *m_model;
+    FavoriteRoomsModel *m_favoritesModel;
+    QSortFilterProxyModel *m_favoritesProxyModel;
+    KConfigGroup m_favoriteRoomsGroup;
 };
 
 
diff --git a/dialogs/join-chat-room-dialog.ui b/dialogs/join-chat-room-dialog.ui
index bec0805..839d644 100644
--- a/dialogs/join-chat-room-dialog.ui
+++ b/dialogs/join-chat-room-dialog.ui
@@ -31,82 +31,161 @@
     </widget>
    </item>
    <item>
-    <widget class="KLineEdit" name="lineEdit"/>
-   </item>
-   <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">
+    <widget class="KLineEdit" name="lineEdit">
+     <property name="showClearButton" stdset="0">
       <bool>true</bool>
      </property>
     </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>
+    <widget class="QTabWidget" name="tabWidget">
+     <property name="currentIndex">
+      <number>0</number>
      </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>
+             <property name="icon">
+              <iconset theme="list-add">
+               <normaloff/>
+              </iconset>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <widget class="QPushButton" name="removeFavoritePushButton">
+             <property name="enabled">
+              <bool>false</bool>
+             </property>
+             <property name="text">
+              <string>Remove Room</string>
+             </property>
+             <property name="icon">
+              <iconset theme="list-remove">
+               <normaloff/>
+              </iconset>
+             </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="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>
+        </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>
+       </item>
+      </layout>
+     </widget>
     </widget>
    </item>
   </layout>
diff --git a/rooms-model.cpp b/rooms-model.cpp
index 8a5cbb0..1edba64 100644
--- a/rooms-model.cpp
+++ b/rooms-model.cpp
@@ -21,6 +21,7 @@
 #include <KIcon>
 #include <KLocale>
 
+// RoomsModel
 RoomsModel::RoomsModel(QObject *parent): QAbstractListModel(parent)
 {
 }
@@ -144,3 +145,97 @@ void RoomsModel::clearRoomInfoList()
         endRemoveRows();
     }
 }
+
+// FavoriteRoomsModel
+FavoriteRoomsModel::FavoriteRoomsModel(QObject *parent): QAbstractListModel(parent)
+{
+}
+
+int FavoriteRoomsModel::rowCount(const QModelIndex &parent) const
+{
+    if (parent.isValid()) {
+        return 0;
+    } else {
+        return m_favoriteRoomsList.size();
+    }
+}
+
+int FavoriteRoomsModel::columnCount(const QModelIndex &parent) const
+{
+    if (parent.isValid()) {
+        return 0;
+    } else {
+        return 3;
+    }
+}
+
+QVariant FavoriteRoomsModel::data(const QModelIndex &index, int role) const
+{
+    if (!index.isValid()) {
+        return QVariant();
+    }
+
+    if (index.row() >= m_favoriteRoomsList.size()) {
+        return QVariant();
+    }
+
+    const int row = index.row();
+    const QVariantMap &room = m_favoriteRoomsList.at(row);
+
+    switch(role) {
+    case Qt::DisplayRole:
+        switch (index.column()) {
+        case NameColumn:
+            return room.value("name");
+        case HandleNameColumn:
+            return room.value("handle-name");
+        case AccountIdentifierColumn:
+            return room.value("account-identifier");
+        }
+    case Qt::ToolTipRole:
+        return room.value("handle-name");
+    case FavoriteRoomsModel::HandleNameRole:
+        return room.value("handle-name");
+    case FavoriteRoomsModel::FavoriteRoomRole:
+        return QVariant::fromValue<QVariantMap>(room);
+    }
+
+    return QVariant();
+}
+
+void FavoriteRoomsModel::addRooms(const QList<QVariantMap> newRoomList)
+{
+    if (newRoomList.size() > 0) {
+        beginInsertRows(QModelIndex(), m_favoriteRoomsList.size(), m_favoriteRoomsList.size() + newRoomList.size() - 1);
+        m_favoriteRoomsList.append(newRoomList);
+        endInsertRows();
+    }
+}
+
+void FavoriteRoomsModel::addRoom(const QVariantMap &room)
+{
+    beginInsertRows(QModelIndex(), m_favoriteRoomsList.size(), m_favoriteRoomsList.size());
+    m_favoriteRoomsList.append(room);
+    endInsertRows();
+}
+
+void FavoriteRoomsModel::removeRoom(const QVariantMap &room)
+{
+    int row = m_favoriteRoomsList.indexOf(room);
+    beginRemoveRows(QModelIndex(), row, row);
+    m_favoriteRoomsList.removeOne(room);
+    endRemoveRows();
+}
+
+bool FavoriteRoomsModel::containsRoom(const QString &handle, const QString &account)
+{
+    bool contains = false;
+
+    Q_FOREACH(const QVariantMap &room, m_favoriteRoomsList) {
+        if ((room.value("handle-name") == handle) && (room.value("account-identifier") == account)) {
+            contains = true;
+        }
+    }
+
+    return contains;
+}
diff --git a/rooms-model.h b/rooms-model.h
index 675ea4c..4040d34 100644
--- a/rooms-model.h
+++ b/rooms-model.h
@@ -62,4 +62,59 @@ private:
     Tp::RoomInfoList m_roomInfoList;
 };
 
+class FavoriteRoomsModel : public QAbstractListModel
+{
+    Q_OBJECT
+
+public:
+    enum Column {
+        NameColumn = 0,
+        HandleNameColumn,
+        AccountIdentifierColumn
+    };
+
+    enum Roles {
+        HandleNameRole = Qt::UserRole,
+        FavoriteRoomRole
+    };
+
+    explicit FavoriteRoomsModel(QObject *parent = 0);
+    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+    /**
+     * rief Add new rooms to the list.
+     *
+     * \param newRoomList The list with the new rooms to add.
+     */
+    void addRooms(const QList<QVariantMap> newRoomList);
+
+    /**
+     * rief Add a new room to the list.
+     *
+     * \param room The room to add.
+     */
+    void addRoom(const QVariantMap &room);
+
+    /**
+     * rief Remove a room from the list.
+     *
+     * \param room The room to remove.
+     */
+    void removeRoom(const QVariantMap &room);
+
+    /**
+     * rief Checks if it contains a room (identified by his handle-name).
+     *
+     * \param handle The handle to look for.
+     *
+     * 
eturn True if it contains the room else false.
+     */
+    bool containsRoom(const QString &handle, const QString &account);
+
+private:
+    QList<QVariantMap> m_favoriteRoomsList;
+};
+
 #endif // ROOMSMODEL_H

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list