[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:30 UTC 2016


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

The following commit has been merged in the master branch:
commit 149412ffb8e5aac8a4deaebce57f5b33a1eb86fa
Author: Dominik Cermak <d.cermak at arcor.de>
Date:   Tue Jan 31 12:15:20 2012 +0100

    Add support for showing available rooms in join chat room dialog
    
    This adds support for showing available rooms. You can query the default
    server of the selected account or specify a server yourself.
    The list shows if the room is password protected, how many persons are
    there, the name and the description.
    
    CCBUG: 291711
    REVIEW: 103825
---
 CMakeLists.txt                    |   1 +
 dialogs/join-chat-room-dialog.cpp | 146 +++++++++++++++++++++++++++++++++++++-
 dialogs/join-chat-room-dialog.h   |  16 +++++
 dialogs/join-chat-room-dialog.ui  |  89 ++++++++++++++++++++++-
 rooms-model.cpp                   | 146 ++++++++++++++++++++++++++++++++++++++
 rooms-model.h                     |  65 +++++++++++++++++
 6 files changed, 460 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e57d389..e0b5bf9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,6 +24,7 @@ include_directories (${KDE4_INCLUDES}
 
 
 set (ktp_contactlist_SRCS
+     rooms-model.cpp
      contact-list-widget.cpp
      context-menu.cpp
      abstract-contact-delegate.cpp
diff --git a/dialogs/join-chat-room-dialog.cpp b/dialogs/join-chat-room-dialog.cpp
index 164f910..06d0a3a 100644
--- a/dialogs/join-chat-room-dialog.cpp
+++ b/dialogs/join-chat-room-dialog.cpp
@@ -2,6 +2,7 @@
  * This file is part of telepathy-contactslist-prototype
  *
  * Copyright (C) 2011 Francesco Nwokeka <francesco.nwokeka at gmail.com>
+ * Copyright (C) 2012 Dominik Cermak <d.cermak at arcor.de>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -24,22 +25,35 @@
 #include <KTp/Models/accounts-model.h>
 
 #include <KDE/KPushButton>
+#include <KNotification>
 
 #include <TelepathyQt/AccountManager>
+#include <TelepathyQt/RoomListChannel>
+#include <TelepathyQt/ChannelTypeRoomListInterface>
+#include <TelepathyQt/PendingChannel>
+#include <TelepathyQt/PendingReady>
+
+#include <QSortFilterProxyModel>
+
+#include <rooms-model.h>
+
+#include <KDebug>
 
 JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWidget* parent)
     : KDialog(parent, Qt::Dialog)
     , ui(new Ui::JoinChatRoomDialog)
+    , m_model(new RoomsModel(this)
+    )
 {
     QWidget *joinChatRoomDialog = new QWidget(this);
     m_accounts = accountManager->allAccounts();
     ui->setupUi(joinChatRoomDialog);
     setMainWidget(joinChatRoomDialog);
+    setWindowIcon(KIcon("telepathy-kde"));
 
     // disable OK button on start
     button(Ok)->setEnabled(false);
 
-
     // populate combobox with accounts that support chat rooms
     for (int i = 0; i < m_accounts.count(); ++i) {
         Tp::AccountPtr acc = m_accounts.at(i);
@@ -50,8 +64,27 @@ JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWi
         }
     }
 
+    if (ui->comboBox->count() > 0) {
+        ui->queryPushButton->setEnabled(true);
+    }
+
+    QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
+    proxyModel->setSourceModel(m_model);
+    proxyModel->setSortLocaleAware(true);
+    proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
+    proxyModel->setFilterKeyColumn(RoomsModel::NameColumn);
+    proxyModel->setDynamicSortFilter(true);
+
+    ui->treeView->setModel(proxyModel);
+    ui->treeView->header()->setResizeMode(QHeaderView::ResizeToContents);
+    ui->treeView->sortByColumn(RoomsModel::NameColumn, Qt::AscendingOrder);
+
     // connects
     connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(onTextChanged(QString)));
+    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)));
 }
 
 JoinChatRoomDialog::~JoinChatRoomDialog()
@@ -75,6 +108,108 @@ Tp::AccountPtr JoinChatRoomDialog::selectedAccount() const
     return account;
 }
 
+void JoinChatRoomDialog::getRoomList()
+{
+    Tp::AccountPtr account = selectedAccount();
+
+    // Clear the list from previous items
+    m_model->clearRoomInfoList();
+
+    // Build the channelrequest
+    QVariantMap request;
+    request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"),
+                   TP_QT_IFACE_CHANNEL_TYPE_ROOM_LIST);
+    request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType"),
+                   Tp::HandleTypeNone);
+
+    // If the user provided a server use it, else use the standard server for the selected account
+    if (!ui->serverLineEdit->text().isEmpty()) {
+        request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".Type.RoomList.Server"),
+                       ui->serverLineEdit->text());
+    }
+
+    m_pendingRoomListChannel = account->createAndHandleChannel(request, QDateTime::currentDateTime());
+    connect(m_pendingRoomListChannel, SIGNAL(finished(Tp::PendingOperation*)),
+            this, SLOT(onRoomListChannelReadyForHandling(Tp::PendingOperation*)));
+
+}
+
+void JoinChatRoomDialog::stopListing()
+{
+    m_iface->StopListing();
+}
+
+void JoinChatRoomDialog::onRoomListChannelReadyForHandling(Tp::PendingOperation *operation)
+{
+    if (operation->isError()) {
+        kDebug() << operation->errorName();
+        kDebug() << operation->errorMessage();
+        QString errorMsg(operation->errorName() + QLatin1String(": ") + operation->errorMessage());
+        sendNotificationToUser(errorMsg);
+    } else {
+        m_roomListChannel = m_pendingRoomListChannel->channel();
+
+        connect(m_roomListChannel->becomeReady(),
+                SIGNAL(finished(Tp::PendingOperation*)),
+                SLOT(onRoomListChannelReady(Tp::PendingOperation*)));
+    }
+}
+
+void JoinChatRoomDialog::onRoomListChannelReady(Tp::PendingOperation *operation)
+{
+    if (operation->isError()) {
+        kDebug() << operation->errorName();
+        kDebug() << operation->errorMessage();
+        QString errorMsg(operation->errorName() + QLatin1String(": ") + operation->errorMessage());
+        sendNotificationToUser(errorMsg);
+    } else {
+        m_iface = m_roomListChannel->interface<Tp::Client::ChannelTypeRoomListInterface>();
+
+        m_iface->ListRooms();
+
+        connect(m_iface, SIGNAL(ListingRooms(bool)), SLOT(onListing(bool)));
+        connect(m_iface, SIGNAL(GotRooms(Tp::RoomInfoList)), SLOT(onGotRooms(Tp::RoomInfoList)));
+    }
+}
+
+void JoinChatRoomDialog::onRoomListChannelClosed(Tp::PendingOperation *operation)
+{
+    if (operation->isError()) {
+        kDebug() << operation->errorName();
+        kDebug() << operation->errorMessage();
+        QString errorMsg(operation->errorName() + QLatin1String(": ") + operation->errorMessage());
+        sendNotificationToUser(errorMsg);
+    } else {
+        ui->queryPushButton->setEnabled(true);
+        ui->stopPushButton->setEnabled(false);
+    }
+}
+
+void JoinChatRoomDialog::onListing(bool isListing)
+{
+    if (isListing) {
+        kDebug() << "listing";
+        ui->queryPushButton->setEnabled(false);
+        ui->stopPushButton->setEnabled(true);
+    } else {
+        kDebug() << "finished listing";
+        Tp::PendingOperation *op =  m_roomListChannel->requestClose();
+        connect(op,
+                SIGNAL(finished(Tp::PendingOperation*)),
+                SLOT(onRoomListChannelClosed(Tp::PendingOperation*)));
+    }
+}
+
+void JoinChatRoomDialog::onGotRooms(Tp::RoomInfoList roomInfoList)
+{
+    m_model->addRooms(roomInfoList);
+}
+
+void JoinChatRoomDialog::onRoomClicked(const QModelIndex& index)
+{
+    ui->lineEdit->setText(index.data(RoomsModel::HandleNameRole).toString());
+}
+
 QString JoinChatRoomDialog::selectedChatRoom() const
 {
     return ui->lineEdit->text();
@@ -87,3 +222,12 @@ void JoinChatRoomDialog::onTextChanged(QString newText)
     }
 }
 
+void JoinChatRoomDialog::sendNotificationToUser(const QString& errorMsg)
+{
+    //The pointer is automatically deleted when the event is closed
+    KNotification *notification;
+    notification = new KNotification(QLatin1String("telepathyError"), this);
+
+    notification->setText(errorMsg);
+    notification->sendEvent();
+}
diff --git a/dialogs/join-chat-room-dialog.h b/dialogs/join-chat-room-dialog.h
index d0aba22..b5f7c67 100644
--- a/dialogs/join-chat-room-dialog.h
+++ b/dialogs/join-chat-room-dialog.h
@@ -28,6 +28,8 @@ namespace Ui {
     class JoinChatRoomDialog;
 }
 
+class RoomsModel;
+
 class JoinChatRoomDialog : public KDialog
 {
     Q_OBJECT
@@ -41,10 +43,24 @@ public:
 
 private slots:
     void onTextChanged(QString newText);
+    void getRoomList();
+    void stopListing();
+    void onRoomListChannelReadyForHandling(Tp::PendingOperation *operation);
+    void onRoomListChannelReady(Tp::PendingOperation *operation);
+    void onRoomListChannelClosed(Tp::PendingOperation *operation);
+    void onListing(bool isListing);
+    void onGotRooms(Tp::RoomInfoList roomInfoList);
+    void onRoomClicked(const QModelIndex &index);
 
 private:
+    void sendNotificationToUser(const QString& errorMsg);
+
     QList<Tp::AccountPtr> m_accounts;
     Ui::JoinChatRoomDialog *ui;
+    Tp::PendingChannel *m_pendingRoomListChannel;
+    Tp::ChannelPtr m_roomListChannel;
+    Tp::Client::ChannelTypeRoomListInterface *m_iface;
+    RoomsModel *m_model;
 };
 
 
diff --git a/dialogs/join-chat-room-dialog.ui b/dialogs/join-chat-room-dialog.ui
index 6c64151..bec0805 100644
--- a/dialogs/join-chat-room-dialog.ui
+++ b/dialogs/join-chat-room-dialog.ui
@@ -6,10 +6,19 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>134</height>
+    <width>525</width>
+    <height>325</height>
    </rect>
   </property>
+  <property name="minimumSize">
+   <size>
+    <width>525</width>
+    <height>0</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>Join Chatroom</string>
+  </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="KComboBox" name="comboBox"/>
@@ -24,6 +33,82 @@
    <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">
+      <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>
  <customwidgets>
diff --git a/rooms-model.cpp b/rooms-model.cpp
new file mode 100644
index 0000000..8a5cbb0
--- /dev/null
+++ b/rooms-model.cpp
@@ -0,0 +1,146 @@
+/*
+ * Rooms Model - A model of chatrooms.
+ * Copyright (C) 2012  Dominik Cermak <d.cermak at arcor.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "rooms-model.h"
+#include <KIcon>
+#include <KLocale>
+
+RoomsModel::RoomsModel(QObject *parent): QAbstractListModel(parent)
+{
+}
+
+int RoomsModel::rowCount(const QModelIndex &parent) const
+{
+    if (parent.isValid()) {
+        return 0;
+    } else {
+        return m_roomInfoList.size();
+    }
+}
+
+int RoomsModel::columnCount(const QModelIndex &parent) const
+{
+    if (parent.isValid()) {
+        return 0;
+    } else {
+        return 4;
+    }
+}
+
+QVariant RoomsModel::data(const QModelIndex &index, int role) const
+{
+    if (!index.isValid()) {
+        return QVariant();
+    }
+
+    if (index.row() >= m_roomInfoList.count()) {
+        return QVariant();
+    }
+
+    const int row = index.row();
+    const Tp::RoomInfo &roomInfo = m_roomInfoList.at(row);
+
+    // this is handled here because when putting it in the switch below
+    // all columns get an empty space for the decoration
+    if (index.column() == PasswordColumn) {
+        switch (role) {
+        case Qt::DecorationRole:
+            if (roomInfo.info.value("password").toBool()) {
+                return KIcon("object-locked");
+            } else {
+                return QVariant();
+            }
+        case Qt::ToolTipRole:
+            if (roomInfo.info.value("password").toBool()) {
+                return i18n("Password required");
+            } else {
+                return i18n("No password required");
+            }
+        }
+    }
+
+    switch(role) {
+    case Qt::DisplayRole:
+        switch (index.column()) {
+        case PasswordColumn:
+            return QVariant();
+        case NameColumn:
+            return roomInfo.info.value(QString("name"));
+        case DescriptionColumn:
+            return roomInfo.info.value(QString("description"));
+        case MembersColumn:
+            return roomInfo.info.value(QString("members"));
+        }
+    case Qt::ToolTipRole:
+        switch (index.column()) {
+        case MembersColumn:
+            return i18n("Member count");
+        }
+    case RoomsModel::HandleNameRole:
+        return roomInfo.info.value(QString("handle-name"));
+    }
+
+    return QVariant();
+}
+
+QVariant RoomsModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+    if (role != Qt::DisplayRole && role != Qt::DecorationRole) {
+        return QVariant();
+    }
+
+    if (orientation == Qt::Horizontal) {
+        switch (role) {
+        case Qt::DisplayRole:
+            switch (section) {
+            case NameColumn:
+                return i18nc("Chatrooms name", "Name");
+            case DescriptionColumn:
+                return i18nc("Chatrooms description", "Description");
+            }
+        case Qt::DecorationRole:
+            switch (section) {
+            case PasswordColumn:
+                return KIcon("object-locked");
+            case MembersColumn:
+                return KIcon("meeting-participant");
+            }
+        }
+    }
+
+    return QVariant();
+}
+
+void RoomsModel::addRooms(const Tp::RoomInfoList newRoomList)
+{
+    if (newRoomList.size() > 0) {
+        beginInsertRows(QModelIndex(), m_roomInfoList.size(), m_roomInfoList.size() + newRoomList.size() - 1);
+        m_roomInfoList.append(newRoomList);
+        endInsertRows();
+    }
+}
+
+void RoomsModel::clearRoomInfoList()
+{
+    if (m_roomInfoList.size() > 0) {
+        beginRemoveRows(QModelIndex(), 0, m_roomInfoList.size() - 1);
+        m_roomInfoList.clear();
+        endRemoveRows();
+    }
+}
diff --git a/rooms-model.h b/rooms-model.h
new file mode 100644
index 0000000..675ea4c
--- /dev/null
+++ b/rooms-model.h
@@ -0,0 +1,65 @@
+/*
+ * Rooms Model - A model of chatrooms.
+ * Copyright (C) 2012  Dominik Cermak <d.cermak at arcor.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef ROOMSMODEL_H
+#define ROOMSMODEL_H
+
+#include <QtCore/QAbstractListModel>
+#include <TelepathyQt/Types>
+
+class RoomsModel : public QAbstractListModel
+{
+    Q_OBJECT
+
+public:
+    // TODO: find a suitable icon and add an invitation column
+    enum Column {
+        PasswordColumn=0,
+        MembersColumn,
+        NameColumn,
+        DescriptionColumn
+    };
+
+    enum Roles {
+        HandleNameRole = Qt::UserRole
+    };
+
+    explicit RoomsModel(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;
+    virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+
+    /**
+     * rief Add new rooms to the list.
+     *
+     * \param newRoomList The list with the new rooms to add.
+     */
+    void addRooms(const Tp::RoomInfoList newRoomList);
+
+    /**
+     * rief Clear the room list.
+     */
+    void clearRoomInfoList();
+
+private:
+    Tp::RoomInfoList m_roomInfoList;
+};
+
+#endif // ROOMSMODEL_H

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list