diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-03-14 14:15:34 (GMT) |
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2014-04-02 11:14:52 (GMT) |
| commit | c9275affd040ee1ca7c1d599b28df3b363bef888 (patch) | |
| tree | 04afffe1e766f897f2208cf097a307a5fe530032 /Swift/QtUI/Roster/QtTreeWidget.cpp | |
| parent | b92fe0b47d519da5fd55ba55ad0838e1ff69195c (diff) | |
| download | swift-contrib-c9275affd040ee1ca7c1d599b28df3b363bef888.zip swift-contrib-c9275affd040ee1ca7c1d599b28df3b363bef888.tar.bz2 | |
Make the impromptu MUCs behave more like a regular chat.
This hides occupant types in the participant list and initiates a
direct 1-to-1 on occupant double-click instead of MUC-proxied 1-to-1.
Change-Id: I76c57fe52beb3e4236524c1d8cfbd583d3dc3f62
Diffstat (limited to 'Swift/QtUI/Roster/QtTreeWidget.cpp')
| -rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index 91e9a33..ed76a6f 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -1,69 +1,69 @@ /* * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swift/QtUI/Roster/QtTreeWidget.h> #include <boost/smart_ptr/make_shared.hpp> #include <boost/bind.hpp> #include <QUrl> #include <QMimeData> #include <QObject> #include <QLabel> #include <QTimer> #include <QToolTip> #include <Swiften/Base/Platform.h> #include <Swift/Controllers/Roster/ContactRosterItem.h> #include <Swift/Controllers/Roster/GroupRosterItem.h> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> #include <Swift/Controllers/UIEvents/SendFileUIEvent.h> #include <Swift/Controllers/Settings/SettingsProvider.h> #include <Swift/QtUI/QtUISettingConstants.h> - +#include <Swift/QtUI/Roster/RosterModel.h> #include <QtSwiftUtil.h> namespace Swift { -QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent) : QTreeView(parent), tooltipShown_(false) { +QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget messageTarget, QWidget* parent) : QTreeView(parent), messageTarget_(messageTarget), tooltipShown_(false) { eventStream_ = eventStream; settings_ = settings; model_ = new RosterModel(this, settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)); setModel(model_); delegate_ = new RosterDelegate(this, settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); setItemDelegate(delegate_); setHeaderHidden(true); #ifdef SWIFT_PLATFORM_MACOSX setAlternatingRowColors(true); #endif setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); expandAll(); setAnimated(true); setIndentation(0); #ifdef SWIFT_EXPERIMENTAL_FT setAcceptDrops(true); #endif setDragEnabled(true); setRootIsDecorated(true); connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&))); connect(model_, SIGNAL(itemExpanded(const QModelIndex&, bool)), this, SLOT(handleModelItemExpanded(const QModelIndex&, bool))); connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(handleExpanded(const QModelIndex&))); connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(handleCollapsed(const QModelIndex&))); connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&))); settings_->onSettingChanged.connect(boost::bind(&QtTreeWidget::handleSettingChanged, this, _1)); } QtTreeWidget::~QtTreeWidget() { settings_->onSettingChanged.disconnect(boost::bind(&QtTreeWidget::handleSettingChanged, this, _1)); delete model_; delete delegate_; } void QtTreeWidget::handleSettingChanged(const std::string& setting) { @@ -105,76 +105,88 @@ void QtTreeWidget::handleClicked(const QModelIndex& index) { } QModelIndexList QtTreeWidget::getSelectedIndexes() const { // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the // QModelIndexList destructor. // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case // was resolved by linking against the debug libs, ours isn't, and we're not alone) QItemSelection ranges = selectionModel()->selection(); QModelIndexList selectedIndexList; for (int i = 0; i < ranges.count(); ++i) { QModelIndex parent = ranges.at(i).parent(); int right = ranges.at(i).model()->columnCount(parent) - 1; if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) { for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) { selectedIndexList.append(ranges.at(i).model()->index(r, 0, parent)); } } } return selectedIndexList; } void QtTreeWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) { RosterItem* item = NULL; QModelIndexList selectedIndexList = getSelectedIndexes(); if (selectedIndexList.empty() || !selectedIndexList[0].isValid()) { /* I didn't quite understand why using current didn't seem to work here.*/ } else if (current.isValid()) { item = static_cast<RosterItem*>(current.internalPointer()); item = dynamic_cast<ContactRosterItem*>(item); } onSomethingSelectedChanged(item); QTreeView::currentChanged(current, previous); } - void QtTreeWidget::handleItemActivated(const QModelIndex& index) { - RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); - ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item); - if (contact) { - eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(contact->getJID()))); + switch (messageTarget_) { + case MessageDisplayJID: { + QString indexJID = index.data(DisplayJIDRole).toString(); + if (!indexJID.isEmpty()) { + JID target = JID(Q2PSTRING(indexJID)).toBare(); + eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target))); + break; + } + } + case MessageDefaultJID: { + QString indexJID = index.data(JIDRole).toString(); + if (!indexJID.isEmpty()) { + JID target = JID(Q2PSTRING(indexJID)); + eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target))); + } + break; + } } } void QtTreeWidget::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) { event->acceptProposedAction(); } } void QtTreeWidget::dropEvent(QDropEvent *event) { QModelIndex index = indexAt(event->pos()); if (index.isValid()) { RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) { QString filename = event->mimeData()->urls().at(0).toLocalFile(); if (!filename.isEmpty()) { eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(filename))); } } } } } void QtTreeWidget::dragMoveEvent(QDragMoveEvent* event) { QModelIndex index = indexAt(event->pos()); if (index.isValid()) { RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) { event->accept(); return; } } } @@ -198,36 +210,40 @@ bool QtTreeWidget::event(QEvent* event) { return QAbstractItemView::event(event); } void QtTreeWidget::handleExpanded(const QModelIndex& index) { GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer())); if (item) { item->setExpanded(true); } } void QtTreeWidget::handleCollapsed(const QModelIndex& index) { GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer())); if (item) { item->setExpanded(false); } } void QtTreeWidget::handleModelItemExpanded(const QModelIndex& index, bool shouldExpand) { if (!index.isValid()) { return; } bool alreadyRight = this->isExpanded(index) == shouldExpand; if (alreadyRight) { return; } setExpanded(index, shouldExpand); } void QtTreeWidget::drawBranches(QPainter*, const QRect&, const QModelIndex&) const { } void QtTreeWidget::show() { QWidget::show(); } +void QtTreeWidget::setMessageTarget(MessageTarget messageTarget) { + messageTarget_ = messageTarget; +} + } |
Swift