diff options
Diffstat (limited to 'Swift/QtUI/ChatList')
-rw-r--r-- | Swift/QtUI/ChatList/ChatListGroupItem.h | 5 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.cpp | 2 |
3 files changed, 4 insertions, 8 deletions
diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h index 427f00b..a9bb9b1 100644 --- a/Swift/QtUI/ChatList/ChatListGroupItem.h +++ b/Swift/QtUI/ChatList/ChatListGroupItem.h @@ -1,45 +1,42 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include <QList> -#include <Swiften/Base/foreach.h> - #include <Swift/QtUI/ChatList/ChatListItem.h> namespace Swift { class ChatListGroupItem : public ChatListItem { public: ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {} virtual ~ChatListGroupItem() {clear();} void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}} void remove(int index) {items_.removeAt(index);} int rowCount() {return items_.size();} ChatListItem* item(int i) {return items_[i];} int row(ChatListItem* item) {return items_.indexOf(item);} QVariant data(int role) const {return (role == Qt::DisplayRole) ? name_ : QVariant();} void clear() { - foreach (ChatListItem* item, items_) { + for (auto item : items_) { delete item; } items_.clear(); } - private: static bool pointerItemLessThan(const ChatListItem* first, const ChatListItem* second) { QString myName = first->data(Qt::DisplayRole).toString().toLower(); QString theirName = second->data(Qt::DisplayRole).toString().toLower(); return myName < theirName; } QString name_; QList<ChatListItem*> items_; bool sorted_; }; } diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp index e5e8963..416b786 100644 --- a/Swift/QtUI/ChatList/ChatListModel.cpp +++ b/Swift/QtUI/ChatList/ChatListModel.cpp @@ -69,87 +69,86 @@ void ChatListModel::removeMUCBookmark(const Swift::MUCBookmark& bookmark) { mucBookmarks_->remove(i); endRemoveRows(); break; } } } void ChatListModel::addWhiteboardSession(const ChatListWindow::Chat& chat) { beginInsertRows(whiteboardsIndex_, 0, whiteboards_->rowCount()); whiteboards_->addItem(new ChatListWhiteboardItem(chat, whiteboards_)); endInsertRows(); } void ChatListModel::removeWhiteboardSession(const JID& jid) { for (int i = 0; i < whiteboards_->rowCount(); i++) { ChatListWhiteboardItem* item = dynamic_cast<ChatListWhiteboardItem*>(whiteboards_->item(i)); if (item->getChat().jid == jid) { beginRemoveRows(whiteboardsIndex_, i, i+1); whiteboards_->remove(i); endRemoveRows(); break; } } } void ChatListModel::setRecents(const std::list<ChatListWindow::Chat>& recents) { beginRemoveRows(recentsIndex_, 0, recents_->rowCount()); recents_->clear(); endRemoveRows(); beginInsertRows(recentsIndex_, 0, recents.size()); - foreach (const ChatListWindow::Chat chat, recents) { + for (const auto& chat : recents) { recents_->addItem(new ChatListRecentItem(chat, recents_)); //whiteboards_->addItem(new ChatListRecentItem(chat, whiteboards_)); } endInsertRows(); } QMimeData* ChatListModel::mimeData(const QModelIndexList& indexes) const { QMimeData* data = QAbstractItemModel::mimeData(indexes); ChatListRecentItem *item = dynamic_cast<ChatListRecentItem*>(getItemForIndex(indexes.first())); if (item == nullptr) { return data; } QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); const ChatListWindow::Chat& chat = item->getChat(); QString mimeType = "application/vnd.swift.contact-jid-list"; if (!chat.impromptuJIDs.size()) { if (chat.isMUC) { mimeType = "application/vnd.swift.contact-jid-muc"; } dataStream << P2QSTRING(chat.jid.toString()); } else { - typedef std::map<std::string, JID> JIDMap; - foreach (const JIDMap::value_type& jid, chat.impromptuJIDs) { + for (const auto& jid : chat.impromptuJIDs) { dataStream << P2QSTRING(jid.second.toString()); } } data->setData(mimeType, itemData); return data; } const ChatListMUCItem* ChatListModel::getChatListMUCItem(const JID& roomJID) const { const ChatListMUCItem* mucItem = nullptr; for (int i = 0; i < mucBookmarks_->rowCount(); i++) { ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i)); if (item->getBookmark().getRoom() == roomJID) { mucItem = item; break; } } return mucItem; } int ChatListModel::columnCount(const QModelIndex& /*parent*/) const { return 1; } ChatListItem* ChatListModel::getItemForIndex(const QModelIndex& index) const { return index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : nullptr; } QVariant ChatListModel::data(const QModelIndex& index, int role) const { ChatListItem* item = getItemForIndex(index); diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index 3fe462a..3caed57 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -153,61 +153,61 @@ void QtChatListWindow::handleAddBookmarkFromRecents() { MUCBookmark bookmark(chat.jid, chat.jid.toBare().toString()); bookmark.setNick(chat.nick); bookmark.setPassword(chat.password); eventStream_->send(std::make_shared<AddMUCBookmarkUIEvent>(bookmark)); } } void QtChatListWindow::handleAddBookmark() { (new QtAddBookmarkWindow(eventStream_))->show(); } void QtChatListWindow::handleEditBookmark() { const ChatListMUCItem* mucItem = dynamic_cast<const ChatListMUCItem*>(contextMenuItem_); if (!mucItem) return; QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, mucItem->getBookmark()); window->show(); } void QtChatListWindow::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) { event->acceptProposedAction(); } } void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) { QModelIndex index = indexAt(event->pos()); ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : nullptr; contextMenuItem_ = baseItem; - foreach(QAction* action, onlineOnlyActions_) { + for (auto action : onlineOnlyActions_) { action->setEnabled(isOnline_); } if (!baseItem) { emptyMenu_->exec(QCursor::pos()); return; } ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem); if (mucItem) { if (!bookmarksEnabled_) { return; } mucMenu_->exec(QCursor::pos()); return; } ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(baseItem); if (recentItem) { const ChatListWindow::Chat& chat = recentItem->getChat(); if (chat.isMUC) { QMenu mucRecentsMenu; QAction* bookmarkAction = nullptr; const ChatListMUCItem* mucItem = model_->getChatListMUCItem(chat.jid); if (mucItem) { contextMenuItem_ = mucItem; bookmarkAction = mucRecentsMenu.addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark())); } else { bookmarkAction = mucRecentsMenu.addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents())); |