[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:05:30 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=0e58920
The following commit has been merged in the master branch:
commit 0e58920ab33e1a004b79428ec03ee57ff0a4873c
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Sat Sep 8 21:23:51 2012 +0100
Move join chat room dialog to common internals
REVIEW: 104534
---
KTp/Models/CMakeLists.txt | 2 +
KTp/Models/rooms-model.cpp | 254 ++++++++++++++++++
KTp/Models/rooms-model.h | 135 ++++++++++
KTp/Widgets/CMakeLists.txt | 3 +
KTp/Widgets/join-chat-room-dialog.cpp | 469 ++++++++++++++++++++++++++++++++++
KTp/Widgets/join-chat-room-dialog.h | 91 +++++++
KTp/Widgets/join-chat-room-dialog.ui | 244 ++++++++++++++++++
7 files changed, 1198 insertions(+)
diff --git a/KTp/Models/CMakeLists.txt b/KTp/Models/CMakeLists.txt
index e6a65b4..4bdff28 100644
--- a/KTp/Models/CMakeLists.txt
+++ b/KTp/Models/CMakeLists.txt
@@ -14,6 +14,7 @@ set (ktp_models_private_SRCS
proxy-tree-node.cpp
tree-node.cpp
flat-model-proxy.cpp
+ rooms-model.cpp
)
set (ktp_models_private_HDRS
@@ -26,6 +27,7 @@ set (ktp_models_private_HDRS
proxy-tree-node.h
tree-node.h
flat-model-proxy.h
+ rooms-model.h
)
kde4_add_library (ktpmodelsprivate SHARED
diff --git a/KTp/Models/rooms-model.cpp b/KTp/Models/rooms-model.cpp
new file mode 100644
index 0000000..4c3bb4f
--- /dev/null
+++ b/KTp/Models/rooms-model.cpp
@@ -0,0 +1,254 @@
+/*
+ * 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
+KTp::RoomsModel::RoomsModel(QObject *parent): QAbstractListModel(parent)
+{
+}
+
+int KTp::RoomsModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid()) {
+ return 0;
+ } else {
+ return m_roomInfoList.size();
+ }
+}
+
+int KTp::RoomsModel::columnCount(const QModelIndex &parent) const
+{
+ if (parent.isValid()) {
+ return 0;
+ } else {
+ return 4;
+ }
+}
+
+QVariant KTp::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(QLatin1String("password")).toBool()) {
+ return KIcon(QLatin1String("object-locked"));
+ } else {
+ return QVariant();
+ }
+ case Qt::ToolTipRole:
+ if (roomInfo.info.value(QLatin1String("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(QLatin1String("name"));
+ case DescriptionColumn:
+ return roomInfo.info.value(QLatin1String("description"));
+ case MembersColumn:
+ return roomInfo.info.value(QLatin1String("members"));
+ }
+ case Qt::ToolTipRole:
+ switch (index.column()) {
+ case MembersColumn:
+ return i18n("Member count");
+ }
+ case RoomsModel::HandleNameRole:
+ return roomInfo.info.value(QLatin1String("handle-name"));
+ }
+
+ return QVariant();
+}
+
+QVariant KTp::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(QLatin1String("object-locked"));
+ case MembersColumn:
+ return KIcon(QLatin1String("meeting-participant"));
+ }
+ }
+ }
+
+ return QVariant();
+}
+
+void KTp::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 KTp::RoomsModel::clearRoomInfoList()
+{
+ if (m_roomInfoList.size() > 0) {
+ beginRemoveRows(QModelIndex(), 0, m_roomInfoList.size() - 1);
+ m_roomInfoList.clear();
+ endRemoveRows();
+ }
+}
+
+// FavoriteRoomsModel
+KTp::FavoriteRoomsModel::FavoriteRoomsModel(QObject *parent): QAbstractListModel(parent)
+{
+}
+
+int KTp::FavoriteRoomsModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid()) {
+ return 0;
+ } else {
+ return m_favoriteRoomsList.size();
+ }
+}
+
+int KTp::FavoriteRoomsModel::columnCount(const QModelIndex &parent) const
+{
+ if (parent.isValid()) {
+ return 0;
+ } else {
+ return 3;
+ }
+}
+
+QVariant KTp::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(QLatin1String("name"));
+ 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"));
+ case FavoriteRoomsModel::HandleNameRole:
+ return room.value(QLatin1String("handle-name"));
+ case FavoriteRoomsModel::FavoriteRoomRole:
+ return QVariant::fromValue<QVariantMap>(room);
+ }
+
+ return QVariant();
+}
+
+void KTp::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 KTp::FavoriteRoomsModel::addRoom(const QVariantMap &room)
+{
+ beginInsertRows(QModelIndex(), m_favoriteRoomsList.size(), m_favoriteRoomsList.size());
+ m_favoriteRoomsList.append(room);
+ endInsertRows();
+}
+
+void KTp::FavoriteRoomsModel::removeRoom(const QVariantMap &room)
+{
+ int row = m_favoriteRoomsList.indexOf(room);
+ beginRemoveRows(QModelIndex(), row, row);
+ m_favoriteRoomsList.removeOne(room);
+ endRemoveRows();
+}
+
+bool KTp::FavoriteRoomsModel::containsRoom(const QString &handle, const QString &account) const
+{
+ bool contains = false;
+
+ Q_FOREACH(const QVariantMap &room, m_favoriteRoomsList) {
+ if ((room.value(QLatin1String("handle-name")) == handle) && (room.value(QLatin1String("account-identifier")) == account)) {
+ contains = true;
+ }
+ }
+
+ return contains;
+}
+
+int KTp::FavoriteRoomsModel::countForAccount(const QString &account) const
+{
+ int count = 0;
+
+ Q_FOREACH (const QVariantMap &room, m_favoriteRoomsList) {
+ if (room.value(QLatin1String("account-identifier")) == account) {
+ count++;
+ }
+ }
+
+ return count;
+}
diff --git a/KTp/Models/rooms-model.h b/KTp/Models/rooms-model.h
new file mode 100644
index 0000000..2630141
--- /dev/null
+++ b/KTp/Models/rooms-model.h
@@ -0,0 +1,135 @@
+/*
+ * 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 ROOMS_MODEL_H
+#define ROOMS_MODEL_H
+
+#include <QtCore/QAbstractListModel>
+#include <TelepathyQt/Types>
+
+#include <KTp/ktp-export.h>
+
+namespace KTp {
+
+class KTP_EXPORT 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;
+};
+
+class KTP_EXPORT 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) const;
+
+ /**
+ * rief Returns the count of rooms for the specified account.
+ *
+ * \param account The account to return the count for.
+ *
+ *
eturn The count of rooms.
+ */
+ int countForAccount(const QString &account) const;
+
+private:
+ QList<QVariantMap> m_favoriteRoomsList;
+};
+
+} // namespace KTp
+
+#endif // ROOMS_MODEL_H
diff --git a/KTp/Widgets/CMakeLists.txt b/KTp/Widgets/CMakeLists.txt
index 0dcf7c1..8435709 100644
--- a/KTp/Widgets/CMakeLists.txt
+++ b/KTp/Widgets/CMakeLists.txt
@@ -6,16 +6,19 @@ set (ktp_widgets_private_SRCS
contact-grid-widget.cpp
contact-grid-dialog.cpp
add-contact-dialog.cpp
+ join-chat-room-dialog.cpp
)
set (ktp_widgets_private_HDRS
contact-grid-widget.h
contact-grid-dialog.h
add-contact-dialog.h
+ join-chat-room-dialog.h
)
kde4_add_ui_files (ktp_widgets_private_SRCS
add-contact-dialog.ui
+ join-chat-room-dialog.ui
)
kde4_add_library (ktpwidgetsprivate SHARED
diff --git a/KTp/Widgets/join-chat-room-dialog.cpp b/KTp/Widgets/join-chat-room-dialog.cpp
new file mode 100644
index 0000000..18e21bf
--- /dev/null
+++ b/KTp/Widgets/join-chat-room-dialog.cpp
@@ -0,0 +1,469 @@
+/*
+ * 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
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "join-chat-room-dialog.h"
+#include "ui_join-chat-room-dialog.h"
+
+#include <KTp/Models/accounts-model.h>
+#include <KTp/Models/rooms-model.h>
+
+#include <KConfig>
+#include <KInputDialog>
+#include <KMessageBox>
+#include <KNotification>
+#include <KPushButton>
+#include <KCompletionBox>
+
+#include <TelepathyQt/AccountManager>
+#include <TelepathyQt/ChannelTypeRoomListInterface>
+#include <TelepathyQt/PendingChannel>
+#include <TelepathyQt/PendingReady>
+#include <TelepathyQt/RoomListChannel>
+
+#include <QSortFilterProxyModel>
+
+#include <KDebug>
+
+KTp::JoinChatRoomDialog::JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWidget* parent)
+ : KDialog(parent, Qt::Dialog)
+ , ui(new Ui::JoinChatRoomDialog)
+ , m_model(new RoomsModel(this))
+ , m_favoritesModel(new FavoriteRoomsModel(this))
+ , m_favoritesProxyModel(new QSortFilterProxyModel(this))
+ , m_recentComp(new KCompletion)
+{
+ QWidget *joinChatRoomDialog = new QWidget(this);
+ m_accounts = accountManager->allAccounts();
+ ui->setupUi(joinChatRoomDialog);
+ setMainWidget(joinChatRoomDialog);
+ setWindowIcon(KIcon(QLatin1String("telepathy-kde")));
+
+ // 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()));
+ }
+ }
+
+ loadFavoriteRooms();
+
+ // disable OK button on start
+ button(Ok)->setEnabled(false);
+
+ //set icons
+ ui->addFavoritePushButton->setIcon(KIcon(QLatin1String("list-add")));
+ ui->removeFavoritePushButton->setIcon(KIcon(QLatin1String("list-remove")));
+ ui->removeRecentPushButton->setIcon(KIcon(QLatin1String("list-remove")));
+ ui->clearRecentPushButton->setIcon(KIcon(QLatin1String("edit-clear-list")));
+
+ // populate combobox with accounts that support chat rooms
+ for (int i = 0; i < m_accounts.count(); ++i) {
+ Tp::AccountPtr acc = m_accounts.at(i);
+
+ if (acc->capabilities().textChatrooms() && acc->isOnline()) {
+ // add unique data to identify the correct account later on
+ ui->comboBox->addItem(KIcon(acc->iconName()), acc->displayName(), acc->uniqueIdentifier());
+ }
+ }
+
+ // 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);
+
+ // recentTab
+ m_recentComp->setCompletionMode(KGlobalSettings::CompletionPopup);
+ m_recentComp->setIgnoreCase(true);
+
+ ui->lineEdit->setCompletionObject(m_recentComp);
+ ui->lineEdit->setAutoDeleteCompletionObject(true);
+
+ // queryTab
+ 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->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->recentListWidget, SIGNAL(currentTextChanged(QString)), ui->lineEdit, SLOT(setText(QString)));
+ connect(ui->recentListWidget, SIGNAL(currentTextChanged(QString)), this, SLOT(onRecentRoomClicked()));
+ connect(ui->removeRecentPushButton, SIGNAL(clicked(bool)), this , SLOT(removeRecentRoom()));
+ connect(ui->clearRecentPushButton, SIGNAL(clicked(bool)), this, SLOT(clearRecentRooms()));
+ 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)));
+ connect(button(Ok), SIGNAL(clicked(bool)), this, SLOT(addRecentRoom()));
+}
+
+KTp::JoinChatRoomDialog::~JoinChatRoomDialog()
+{
+ delete ui;
+}
+
+Tp::AccountPtr KTp::JoinChatRoomDialog::selectedAccount() const
+{
+ Tp::AccountPtr account;
+ bool found = false;
+
+ for (int i = 0; i < m_accounts.count() && !found; ++i) {
+ if (m_accounts.at(i)->uniqueIdentifier() == ui->comboBox->itemData(ui->comboBox->currentIndex()).toString()) {
+ account = m_accounts.at(i);
+ found = true;
+ }
+ }
+
+ // account should never be empty
+ return account;
+}
+
+void KTp::JoinChatRoomDialog::onAccountSelectionChanged(int newIndex)
+{
+ // Show only favorites associated with the selected account
+ QString accountIdentifier = ui->comboBox->itemData(newIndex).toString();
+ 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()
+{
+ 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(QLatin1String("name"), favoriteName);
+ room.insert(QLatin1String("handle-name"), favoriteHandle);
+ room.insert(QLatin1String("account-identifier"), favoriteAccount);
+ m_favoritesModel->addRoom(room);
+ }
+ }
+}
+
+void KTp::JoinChatRoomDialog::removeFavorite()
+{
+ QString favoriteHandle = ui->listView->currentIndex().data(FavoriteRoomsModel::HandleNameRole).toString();
+ QString favoriteAccount = ui->comboBox->itemData(ui->comboBox->currentIndex()).toString();
+ 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);
+ }
+ }
+}
+
+void KTp::JoinChatRoomDialog::addRecentRoom()
+{
+ QString accountIdentifier = ui->comboBox->itemData(ui->comboBox->currentIndex()).toString();
+ 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));
+ }
+
+ // Write it to the config
+ m_recentRoomsGroup.writeEntry(accountIdentifier, m_recentRooms.value(accountIdentifier));
+ m_recentRoomsGroup.sync();
+ }
+}
+
+void KTp::JoinChatRoomDialog::removeRecentRoom()
+{
+ QString accountIdentifier = ui->comboBox->itemData(ui->comboBox->currentIndex()).toString();
+ QString handle = ui->recentListWidget->currentItem()->text();
+
+ // 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());
+
+ // Write it to the config
+ m_recentRoomsGroup.writeEntry(accountIdentifier, m_recentRooms.value(accountIdentifier));
+ m_recentRoomsGroup.sync();
+
+ // Disable the button
+ ui->removeRecentPushButton->setEnabled(false);
+}
+
+void KTp::JoinChatRoomDialog::clearRecentRooms()
+{
+ QString accountIdentifier = ui->comboBox->itemData(ui->comboBox->currentIndex()).toString();
+
+ // Remove all entries for the current account
+ m_recentRooms.remove(accountIdentifier);
+
+ // Update the completion and list
+ onAccountSelectionChanged(ui->comboBox->currentIndex());
+
+ // Update the config
+ m_recentRoomsGroup.deleteEntry(accountIdentifier);
+ m_recentRoomsGroup.sync();
+}
+
+void KTp::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 KTp::JoinChatRoomDialog::stopListing()
+{
+ m_iface->StopListing();
+}
+
+void KTp::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 KTp::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 KTp::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 KTp::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 KTp::JoinChatRoomDialog::onGotRooms(Tp::RoomInfoList roomInfoList)
+{
+ m_model->addRooms(roomInfoList);
+}
+
+void KTp::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 KTp::JoinChatRoomDialog::onRecentRoomClicked()
+{
+ ui->removeRecentPushButton->setEnabled(true);
+}
+
+void KTp::JoinChatRoomDialog::onRoomClicked(const QModelIndex& index)
+{
+ ui->lineEdit->setText(index.data(RoomsModel::HandleNameRole).toString());
+}
+
+QString KTp::JoinChatRoomDialog::selectedChatRoom() const
+{
+ return ui->lineEdit->text();
+}
+
+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);
+ }
+}
+
+void KTp::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();
+}
+
+void KTp::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(QLatin1String("name"), favoriteName);
+ room.insert(QLatin1String("handle-name"), favoriteHandle);
+ room.insert(QLatin1String("account-identifier"), favoriteAccount);
+ 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
new file mode 100644
index 0000000..3c99e78
--- /dev/null
+++ b/KTp/Widgets/join-chat-room-dialog.h
@@ -0,0 +1,91 @@
+/*
+ * This file is part of telepathy-contactslist-prototype
+ *
+ * Copyright (C) 2011 Francesco Nwokeka <francesco.nwokeka at gmail.com>
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef JOINCHATROOMDIALOG_H
+#define JOINCHATROOMDIALOG_H
+
+#include <TelepathyQt/AccountManager>
+#include <KDialog>
+#include <KTp/Models/rooms-model.h>
+
+#include <KTp/ktp-export.h>
+
+namespace Ui {
+ class JoinChatRoomDialog;
+}
+
+class RoomsModel;
+class FavoriteRoomsModel;
+class QSortFilterProxyModel;
+class KCompletion;
+
+namespace KTp {
+
+class KTP_EXPORT JoinChatRoomDialog : public KDialog
+{
+ Q_OBJECT
+
+public:
+ explicit JoinChatRoomDialog(Tp::AccountManagerPtr accountManager, QWidget *parent = 0);
+ ~JoinChatRoomDialog();
+
+ Tp::AccountPtr selectedAccount() const; /** returns selected account */
+ QString selectedChatRoom() const; /** returns selected chat room */
+
+private Q_SLOTS:
+ void onTextChanged(QString newText);
+ void onAccountSelectionChanged(int newIndex);
+ void addFavorite();
+ void removeFavorite();
+ void addRecentRoom();
+ void removeRecentRoom();
+ void clearRecentRooms();
+ 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 onFavoriteRoomClicked(const QModelIndex &index);
+ void onRecentRoomClicked();
+ void onRoomClicked(const QModelIndex &index);
+
+private:
+ void sendNotificationToUser(const QString& errorMsg);
+ void loadFavoriteRooms();
+
+ QList<Tp::AccountPtr> m_accounts;
+ Ui::JoinChatRoomDialog *ui;
+ Tp::PendingChannel *m_pendingRoomListChannel;
+ Tp::ChannelPtr m_roomListChannel;
+ Tp::Client::ChannelTypeRoomListInterface *m_iface;
+ RoomsModel *m_model;
+ FavoriteRoomsModel *m_favoritesModel;
+ QSortFilterProxyModel *m_favoritesProxyModel;
+ KConfigGroup m_favoriteRoomsGroup;
+ KConfigGroup m_recentRoomsGroup;
+ QHash <QString, QStringList> m_recentRooms;
+ KCompletion *m_recentComp;
+};
+
+} //namespace KTp
+
+#endif // JOINCHATROOMDIALOG_H
diff --git a/KTp/Widgets/join-chat-room-dialog.ui b/KTp/Widgets/join-chat-room-dialog.ui
new file mode 100644
index 0000000..2d077c4
--- /dev/null
+++ b/KTp/Widgets/join-chat-room-dialog.ui
@@ -0,0 +1,244 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>JoinChatRoomDialog</class>
+ <widget class="QWidget" name="JoinChatRoomDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <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"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Enter chat room:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KLineEdit" name="lineEdit">
+ <property name="showClearButton" stdset="0">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <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>
+ </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>
+ </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>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>KComboBox</class>
+ <extends>QComboBox</extends>
+ <header>kcombobox.h</header>
+ </customwidget>
+ <customwidget>
+ <class>KLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>klineedit.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list