summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/ChatList')
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.cpp39
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.h3
2 files changed, 34 insertions, 8 deletions
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp
index 7455fb5..210124b 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.cpp
+++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp
@@ -62,37 +62,43 @@ QtChatListWindow::~QtChatListWindow() {
}
void QtChatListWindow::handleSettingChanged(const std::string& setting) {
if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
delegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
repaint();
}
}
+void QtChatListWindow::handleClearRecentsRequested() {
+ onClearRecentsRequested();
+}
+
void QtChatListWindow::setBookmarksEnabled(bool enabled) {
bookmarksEnabled_ = enabled;
}
void QtChatListWindow::handleClicked(const QModelIndex& index) {
ChatListGroupItem* item = dynamic_cast<ChatListGroupItem*>(static_cast<ChatListItem*>(index.internalPointer()));
if (item) {
setExpanded(index, !isExpanded(index));
}
}
void QtChatListWindow::setupContextMenus() {
mucMenu_ = new QMenu();
mucMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
mucMenu_->addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark()));
mucMenu_->addAction(tr("Remove Bookmark"), this, SLOT(handleRemoveBookmark()));
+ mucRecentsMenu_ = new QMenu();
+ mucRecentsMenu_->addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents()));
+ mucRecentsMenu_->addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested()));
emptyMenu_ = new QMenu();
emptyMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
-
}
void QtChatListWindow::handleItemActivated(const QModelIndex& index) {
ChatListItem* item = model_->getItemForIndex(index);
if (ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item)) {
if (bookmarksEnabled_) {
onMUCBookmarkActivated(mucItem->getBookmark());
}
}
@@ -136,18 +142,29 @@ void QtChatListWindow::setUnreadCount(int unread) {
emit onCountUpdated(unread);
}
void QtChatListWindow::handleRemoveBookmark() {
ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_);
if (!mucItem) return;
eventStream_->send(boost::shared_ptr<UIEvent>(new RemoveMUCBookmarkUIEvent(mucItem->getBookmark())));
}
+void QtChatListWindow::handleAddBookmarkFromRecents() {
+ ChatListRecentItem* item = dynamic_cast<ChatListRecentItem*>(contextMenuItem_);
+ if (item) {
+ const ChatListWindow::Chat& chat = item->getChat();
+ MUCBookmark bookmark(chat.jid, chat.jid.toBare().toString());
+ bookmark.setNick(chat.nick);
+ bookmark.setPassword(chat.password);
+ eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(bookmark)));
+ }
+}
+
void QtChatListWindow::handleAddBookmark() {
(new QtAddBookmarkWindow(eventStream_))->show();
}
void QtChatListWindow::handleEditBookmark() {
ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_);
if (!mucItem) return;
QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, mucItem->getBookmark());
@@ -162,28 +179,34 @@ void QtChatListWindow::dragEnterEvent(QDragEnterEvent *event) {
void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) {
QModelIndex index = indexAt(event->pos());
ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL;
contextMenuItem_ = baseItem;
if (!baseItem) {
emptyMenu_->exec(QCursor::pos());
return;
}
+
ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem);
if (mucItem) {
if (!bookmarksEnabled_) {
return;
}
mucMenu_->exec(QCursor::pos());
+ return;
}
- else {
- QMenu menu;
- QAction* clearRecents = menu.addAction(tr("Clear recents"));
- menu.addAction(clearRecents);
- QAction* result = menu.exec(event->globalPos());
- if (result == clearRecents) {
- onClearRecentsRequested();
+
+ ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(baseItem);
+ if (recentItem) {
+ const ChatListWindow::Chat& chat = recentItem->getChat();
+ if (chat.isMUC) {
+ mucRecentsMenu_->exec(QCursor::pos());
+ return;
}
}
+
+ QMenu menu;
+ menu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested()));
+ menu.exec(event->globalPos());
}
}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h
index e218266..1cba3a4 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.h
+++ b/Swift/QtUI/ChatList/QtChatListWindow.h
@@ -30,29 +30,32 @@ namespace Swift {
void clearBookmarks();
signals:
void onCountUpdated(int count);
private slots:
void handleItemActivated(const QModelIndex&);
void handleAddBookmark();
void handleEditBookmark();
void handleRemoveBookmark();
+ void handleAddBookmarkFromRecents();
void handleClicked(const QModelIndex& index);
void handleSettingChanged(const std::string& setting);
+ void handleClearRecentsRequested();
protected:
void dragEnterEvent(QDragEnterEvent* event);
void contextMenuEvent(QContextMenuEvent* event);
private:
void setupContextMenus();
bool bookmarksEnabled_;
UIEventStream* eventStream_;
ChatListModel* model_;
ChatListDelegate* delegate_;
QMenu* mucMenu_;
QMenu* emptyMenu_;
+ QMenu* mucRecentsMenu_;
ChatListItem* contextMenuItem_;
SettingsProvider* settings_;
};
}