summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-06-30 10:42:05 (GMT)
committerSwift Review <review@swift.im>2014-07-09 12:53:37 (GMT)
commit1edfc36235cc67d303ceb2bcf0630affc509f2f7 (patch)
tree0ca86a9e5e0dbcd3876ce91b4bf4feec5321c9c9 /Swift/QtUI
parent05d9e618e4c756e50b633448f0546614a645a13d (diff)
downloadswift-contrib-1edfc36235cc67d303ceb2bcf0630affc509f2f7.zip
swift-contrib-1edfc36235cc67d303ceb2bcf0630affc509f2f7.tar.bz2
Fix attempting to start impromptu chat when impromptu not supported.
Test-Information: Connect to a server where impromptu is NOT supported. Confirm that adding multiple users by dragging or typing into the JID box is not allowed. Connect to a server where impromptu is supported. Confirm that it is still possible to drag multiple users and add multiple users by typing into the JID box. Change-Id: Ibb4c1f7d6a5820f7ccf3629c1e0d30a441d9d159
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.cpp4
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.h1
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp4
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp16
4 files changed, 17 insertions, 8 deletions
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.cpp b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
index 4adc929..6504f3e 100644
--- a/Swift/QtUI/UserSearch/QtContactListWidget.cpp
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
@@ -45,53 +45,57 @@ QtContactListWidget::QtContactListWidget(QWidget* parent, SettingsProvider* sett
setItemDelegateForColumn(0, contactListDelegate_);
setItemDelegateForColumn(1, removableItemDelegate_);
header()->resizeSection(1, removableItemDelegate_->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
header()->setStretchLastSection(false);
#if QT_VERSION >= 0x050000
header()->setSectionResizeMode(0, QHeaderView::Stretch);
#else
header()->setResizeMode(0, QHeaderView::Stretch);
#endif
}
QtContactListWidget::~QtContactListWidget() {
delete contactListDelegate_;
delete removableItemDelegate_;
}
void QtContactListWidget::setList(const std::vector<Contact::ref>& list) {
contactListModel_->setList(list);
}
std::vector<Contact::ref> QtContactListWidget::getList() const {
return contactListModel_->getList();
}
Contact::ref QtContactListWidget::getContact(const size_t i) {
return contactListModel_->getContact(i);
}
void QtContactListWidget::setMaximumNoOfContactsToOne(bool limited) {
limited_ = limited;
}
+bool QtContactListWidget::isFull() const {
+ return limited_ && (getList().size() == 1);
+}
+
void QtContactListWidget::updateContacts(const std::vector<Contact::ref>& contactUpdates) {
std::vector<Contact::ref> contacts = contactListModel_->getList();
foreach(const Contact::ref& contactUpdate, contactUpdates) {
for(size_t n = 0; n < contacts.size(); n++) {
if (contactUpdate->jid == contacts[n]->jid) {
contacts[n] = contactUpdate;
break;
}
}
}
contactListModel_->setList(contacts);
}
void QtContactListWidget::handleSettingsChanged(const std::string&) {
contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
}
}
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.h b/Swift/QtUI/UserSearch/QtContactListWidget.h
index 601d320..112f3ee 100644
--- a/Swift/QtUI/UserSearch/QtContactListWidget.h
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.h
@@ -8,55 +8,56 @@
* Copyright (c) 2014 Kevin Smith and Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <vector>
#include <QTreeView>
#include <Swift/Controllers/Contact.h>
#include <Swiften/Base/Log.h>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
namespace Swift {
class ContactListDelegate;
class ContactListModel;
class SettingsProvider;
class QtRemovableItemDelegate;
class QtContactListWidget : public QTreeView {
Q_OBJECT
public:
QtContactListWidget(QWidget* parent, SettingsProvider* settings);
virtual ~QtContactListWidget();
void setList(const std::vector<Contact::ref>& list);
std::vector<Contact::ref> getList() const;
Contact::ref getContact(const size_t i);
void setMaximumNoOfContactsToOne(bool limited);
+ bool isFull() const;
public slots:
void updateContacts(const std::vector<Contact::ref>& contactUpdates);
signals:
void onListChanged(std::vector<Contact::ref> list);
void onJIDsAdded(const std::vector<JID>& jids);
private:
void handleSettingsChanged(const std::string&);
private:
SettingsProvider* settings_;
ContactListModel* contactListModel_;
ContactListDelegate* contactListDelegate_;
QtRemovableItemDelegate* removableItemDelegate_;
bool limited_;
};
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
index 597c88b..8ea49c4 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
@@ -40,59 +40,61 @@ QtUserSearchFirstMultiJIDPage::QtUserSearchFirstMultiJIDPage(UserSearchWindow::T
}
setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(introText));
contactList_ = new QtContactListWidget(this, settings);
horizontalLayout_5->addWidget(contactList_);
jid_ = new QtSuggestingJIDInput(this, settings);
horizontalLayout_6->insertWidget(0, jid_);
connect(contactList_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SLOT(emitCompletenessCheck()));
connect(jid_, SIGNAL(editingDone()), this, SLOT(handleEditingDone()));
setAcceptDrops(true);
}
bool QtUserSearchFirstMultiJIDPage::isComplete() const {
return !contactList_->getList().empty();
}
void QtUserSearchFirstMultiJIDPage::reset() {
reason_->clear();
}
void QtUserSearchFirstMultiJIDPage::emitCompletenessCheck() {
emit completeChanged();
}
void QtUserSearchFirstMultiJIDPage::handleEditingDone() {
addContactButton_->setFocus();
}
void QtUserSearchFirstMultiJIDPage::dragEnterEvent(QDragEnterEvent *event) {
if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")
|| event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
- event->acceptProposedAction();
+ if (!contactList_->isFull()) {
+ event->acceptProposedAction();
+ }
}
}
void QtUserSearchFirstMultiJIDPage::dropEvent(QDropEvent *event) {
if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list");
QDataStream dataStream(&dataBytes, QIODevice::ReadOnly);
std::vector<JID> jids;
while (!dataStream.atEnd()) {
QString jidString;
dataStream >> jidString;
jids.push_back(Q2PSTRING(jidString));
}
onJIDsDropped(jids);
} else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
QMessageBox* messageBox = new QMessageBox(this);
messageBox->setText(tr("You can't invite a room to chat."));
messageBox->setWindowTitle(tr("Error inviting room to chat"));
messageBox->show();
}
}
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
index 40b4e28..260ccfe 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
@@ -238,77 +238,73 @@ JID QtUserSearchWindow::getContactJID() const {
useSearchResult = true;
}
if (useSearchResult) {
if (dynamic_cast<UserSearchModel*>(model_)) {
UserSearchResult* userItem = static_cast<UserSearchResult*>(resultsPage_->results_->currentIndex().internalPointer());
if (userItem) { /* Remember to leave this if we change to dynamic cast */
jid = userItem->getJID();
}
} else {
int row = resultsPage_->results_->currentIndex().row();
Form::FormItem item = dynamic_cast<QtFormResultItemModel*>(model_)->getForm()->getItems().at(row);
JID fallbackJid;
foreach(FormField::ref field, item) {
if (field->getType() == FormField::JIDSingleType) {
jid = JID(field->getJIDSingleValue());
break;
}
if (field->getName() == "jid") {
fallbackJid = field->getValues()[0];
}
}
if (!jid.isValid()) {
jid = fallbackJid;
}
}
}
else {
jid = JID(Q2PSTRING(firstPage_->jid_->text().trimmed()));
}
return jid;
}
void QtUserSearchWindow::addSearchedJIDToList(const JID& jid) {
- Contact::ref contact = boost::make_shared<Contact>(jid, jid.toString(), StatusShow::None, "");
- contactVector_.push_back(contact);
- firstMultiJIDPage_->contactList_->setList(contactVector_);
- firstMultiJIDPage_->emitCompletenessCheck();
- if (type_ == ChatToContact) {
- firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
- }
+ std::vector<JID> jids;
+ jids.push_back(jid);
+ handleJIDsAdded(jids);
}
void QtUserSearchWindow::show() {
clear();
QWidget::show();
}
void QtUserSearchWindow::addSavedServices(const std::vector<JID>& services) {
if (type_ == AddContact) {
firstPage_->service_->clear();
foreach (JID jid, services) {
firstPage_->service_->addItem(P2QSTRING(jid.toString()));
}
firstPage_->service_->clearEditText();
} else {
firstMultiJIDPage_->service_->clear();
foreach (JID jid, services) {
firstMultiJIDPage_->service_->addItem(P2QSTRING(jid.toString()));
}
firstMultiJIDPage_->service_->clearEditText();
}
}
void QtUserSearchWindow::setSearchFields(boost::shared_ptr<SearchPayload> fields) {
fieldsPage_->fetchingThrobber_->hide();
fieldsPage_->fetchingThrobber_->movie()->stop();
fieldsPage_->fetchingLabel_->hide();
fieldsPage_->instructionsLabel_->setText(fields->getInstructions() ? P2QSTRING(fields->getInstructions().get()) : "Enter search terms");
if (fields->getForm()) {
fieldsPage_->setFormWidget(new QtFormWidget(fields->getForm(), fieldsPage_));
} else {
fieldsPage_->setFormWidget(NULL);
bool enabled[8] = {fields->getNick(), fields->getNick(), fields->getFirst(), fields->getFirst(), fields->getLast(), fields->getLast(), fields->getEMail(), fields->getEMail()};
QWidget* legacySearchWidgets[8] = {fieldsPage_->nickInputLabel_, fieldsPage_->nickInput_, fieldsPage_->firstInputLabel_, fieldsPage_->firstInput_, fieldsPage_->lastInputLabel_, fieldsPage_->lastInput_, fieldsPage_->emailInputLabel_, fieldsPage_->emailInput_};
@@ -362,72 +358,78 @@ std::vector<JID> QtUserSearchWindow::getJIDs() const {
std::vector<JID> jids;
foreach (Contact::ref contact, contactVector_) {
jids.push_back(contact->jid);
}
return jids;
}
void QtUserSearchWindow::setCanStartImpromptuChats(bool supportsImpromptu) {
supportsImpromptu_ = supportsImpromptu;
if (type_ == ChatToContact) {
firstMultiJIDPage_->contactList_->setMaximumNoOfContactsToOne(!supportsImpromptu_);
}
}
void QtUserSearchWindow::updateContacts(const std::vector<Contact::ref>& contacts) {
if (type_ != AddContact) {
firstMultiJIDPage_->contactList_->updateContacts(contacts);
}
}
void QtUserSearchWindow::addContacts(const std::vector<Contact::ref>& contacts) {
if (type_ != AddContact) {
/* prevent duplicate JIDs from appearing in the contact list */
foreach (Contact::ref newContact, contacts) {
bool found = false;
foreach (Contact::ref oldContact, contactVector_) {
if (newContact->jid == oldContact->jid) {
found = true;
break;
}
}
if (!found) {
contactVector_.push_back(newContact);
}
}
+ if (!supportsImpromptu_ && contactVector_.size() > 1) {
+ contactVector_.resize(1); /* can't chat with more than one user */
+ }
firstMultiJIDPage_->contactList_->setList(contactVector_);
firstMultiJIDPage_->emitCompletenessCheck();
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? true : (contactVector_.size() < 1));
+ }
}
}
void QtUserSearchWindow::setCanSupplyDescription(bool allowed) {
firstMultiJIDPage_->label->setVisible(allowed);
firstMultiJIDPage_->reason_->setVisible(allowed);
}
void QtUserSearchWindow::handleAddViaSearch() {
searchNext_ = true;
next();
}
void QtUserSearchWindow::handleListChanged(std::vector<Contact::ref> list) {
contactVector_ = list;
if (type_ == ChatToContact) {
firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
}
}
void QtUserSearchWindow::handleJIDsAdded(std::vector<JID> jids) {
onJIDAddRequested(jids);
}
void QtUserSearchWindow::setResults(const std::vector<UserSearchResult>& results) {
UserSearchModel *newModel = new UserSearchModel();
newModel->setResults(results);
resultsPage_->results_->setModel(newModel);
resultsPage_->results_->setItemDelegate(delegate_);
resultsPage_->results_->setHeaderHidden(true);
delete model_;
model_ = newModel;
resultsPage_->setNoResults(model_->rowCount() == 0);
resultsPage_->emitCompletenessCheck();
}