diff options
Diffstat (limited to 'Swift/QtUI/UserSearch')
-rw-r--r-- | Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtSuggestingJIDInput.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.cpp | 12 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.h | 3 |
4 files changed, 17 insertions, 8 deletions
diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp index 78842a2..57033d8 100644 --- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp +++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp @@ -82,101 +82,105 @@ Contact::ref QtSuggestingJIDInput::getContact() { void QtSuggestingJIDInput::setSuggestions(const std::vector<Contact::ref>& suggestions) { contactListModel_->setList(suggestions); positionPopup(); if (!suggestions.empty()) { treeViewPopup_->setCurrentIndex(contactListModel_->index(0, 0)); showPopup(); } else { currentContact_.reset(); hidePopup(); } } void QtSuggestingJIDInput::clear() { setText(""); currentContact_.reset(); } void QtSuggestingJIDInput::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Up) { if (contactListModel_->rowCount() > 0) { int row = treeViewPopup_->currentIndex().row(); row = (row + contactListModel_->rowCount() - 1) % contactListModel_->rowCount(); treeViewPopup_->setCurrentIndex(contactListModel_->index(row, 0)); } } else if (event->key() == Qt::Key_Down) { if (contactListModel_->rowCount() > 0) { int row = treeViewPopup_->currentIndex().row(); row = (row + contactListModel_->rowCount() + 1) % contactListModel_->rowCount(); treeViewPopup_->setCurrentIndex(contactListModel_->index(row, 0)); } } else if (event->key() == Qt::Key_Return && treeViewPopup_->isVisible()) { QModelIndex index = treeViewPopup_->currentIndex(); if (!contactListModel_->getList().empty() && index.isValid()) { currentContact_ = contactListModel_->getContact(index.row()); - setText(P2QSTRING(currentContact_->jid.toString())); + if (currentContact_->jid.isValid()) { + setText(P2QSTRING(currentContact_->jid.toString())); + } else { + setText(P2QSTRING(currentContact_->name)); + } hidePopup(); clearFocus(); } else { currentContact_.reset(); } editingDone(); } else { QLineEdit::keyPressEvent(event); } } void QtSuggestingJIDInput::handleApplicationFocusChanged(QWidget* /*old*/, QWidget* /*now*/) { /* Using the now argument gives use the wrong widget. This is part of the code needed to prevent stealing of focus when opening a the suggestion window. */ QWidget* now = qApp->focusWidget(); if (!now || (now != treeViewPopup_ && now != this && !now->isAncestorOf(this) && !now->isAncestorOf(treeViewPopup_) && !this->isAncestorOf(now) && !treeViewPopup_->isAncestorOf(now))) { hidePopup(); } } void QtSuggestingJIDInput::handleSettingsChanged(const std::string& setting) { if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) { contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); } } void QtSuggestingJIDInput::handleClicked(const QModelIndex& index) { if (index.isValid()) { currentContact_ = contactListModel_->getContact(index.row()); - onUserSelected(currentContact_->jid); + onUserSelected(currentContact_); hidePopup(); } } void QtSuggestingJIDInput::positionPopup() { QDesktopWidget* desktop = QApplication::desktop(); int screen = desktop->screenNumber(this); QPoint point = mapToGlobal(QPoint(0, height())); QRect geometry = desktop->availableGeometry(screen); int x = point.x(); int y = point.y(); int width = this->width(); int height = 80; int screenWidth = geometry.x() + geometry.width(); if (x + width > screenWidth) { x = screenWidth - width; } height = treeViewPopup_->sizeHintForRow(0) * contactListModel_->rowCount(); height = height > 200 ? 200 : height; int marginLeft; int marginTop; int marginRight; int marginBottom; treeViewPopup_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom); height += marginTop + marginBottom; width += marginLeft + marginRight; treeViewPopup_->setGeometry(x, y, width, height); treeViewPopup_->move(x, y); treeViewPopup_->setMaximumWidth(width); } diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h index 71cd87d..23e7b94 100644 --- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h +++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h @@ -3,64 +3,64 @@ * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * 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 <QLineEdit> #include <QTreeView> #include <Swiften/Base/boost_bsignals.h> #include <Swift/Controllers/Contact.h> namespace Swift { class ContactListDelegate; class SettingsProvider; class ContactListModel; class QtSuggestingJIDInput : public QLineEdit { Q_OBJECT public: QtSuggestingJIDInput(QWidget* parent, SettingsProvider* settings); virtual ~QtSuggestingJIDInput(); Contact::ref getContact(); void setSuggestions(const std::vector<Contact::ref>& suggestions); void clear(); - boost::signal<void (const JID&)> onUserSelected; + boost::signal<void (const Contact::ref&)> onUserSelected; signals: void editingDone(); protected: virtual void keyPressEvent(QKeyEvent* event); private: void handleSettingsChanged(const std::string& setting); private slots: void handleClicked(const QModelIndex& index); void handleApplicationFocusChanged(QWidget* old, QWidget* now); private: void positionPopup(); void showPopup(); void hidePopup(); private: SettingsProvider* settings_; ContactListModel* contactListModel_; QTreeView* treeViewPopup_; ContactListDelegate* contactListDelegate_; Contact::ref currentContact_; }; } diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp index 17214e4..e5bd5d0 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp @@ -46,71 +46,71 @@ QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWin break; case ChatToContact: title = tr("Chat to Users"); break; case InviteToChat: title = tr("Add Users to Chat"); break; } setWindowTitle(title); delegate_ = new UserSearchDelegate(); setFirstPage(title); setSecondPage(); setThirdPage(); detailsPage_ = new QtUserSearchDetailsPage(groups); setPage(4, detailsPage_); connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(handleCurrentChanged(int))); connect(this, SIGNAL(accepted()), this, SLOT(handleAccepted())); clear(); } QtUserSearchWindow::~QtUserSearchWindow() { delete model_; } void QtUserSearchWindow::handleCurrentChanged(int page) { searchNext_ = false; if (firstMultiJIDPage_) { firstMultiJIDPage_->reset(); } resultsPage_->emitCompletenessCheck(); if (page == 1 && lastPage_ == 3) { - addSearchedJIDToList(getContactJID()); + addSearchedJIDToList(getContact()); setSecondPage(); } else if (page == 2 && lastPage_ == 1) { setError(""); /* next won't be called if JID is selected */ JID server = getServerToSearch(); clearForm(); onFormRequested(server); setThirdPage(); } else if (page == 3 && lastPage_ == 2) { JID server = getServerToSearch(); handleSearch(); if (type_ == AddContact) { bool remote = firstPage_->byRemoteSearch_->isChecked(); firstPage_->byRemoteSearch_->setChecked(remote); firstPage_->service_->setEditText(P2QSTRING(server.toString())); } else { bool remote = firstMultiJIDPage_->byRemoteSearch_->isChecked(); setFirstPage(); firstMultiJIDPage_->byRemoteSearch_->setChecked(remote); firstMultiJIDPage_->service_->setEditText(P2QSTRING(server.toString())); } } else if (page == 4) { detailsPage_->clear(); detailsPage_->setJID(getContactJID()); onNameSuggestionRequested(getContactJID()); } lastPage_ = page; } JID QtUserSearchWindow::getServerToSearch() { if (type_ == AddContact) { @@ -238,144 +238,148 @@ JID QtUserSearchWindow::getContactJID() const { } else { 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 if (dynamic_cast<QtFormResultItemModel*>(model_)) { 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 QtUserSearchWindow::getContact() const { + return boost::make_shared<Contact>("", getContactJID(), StatusShow::None, ""); +} + +void QtUserSearchWindow::addSearchedJIDToList(const Contact::ref& contact) { std::vector<JID> jids; - jids.push_back(jid); + jids.push_back(contact->jid); handleJIDsAdded(jids); firstMultiJIDPage_->jid_->clear(); } 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_}; for (int i = 0; i < 8; i++) { legacySearchWidgets[i]->setVisible(enabled[i]); legacySearchWidgets[i]->setEnabled(enabled[i]); } } fieldsPage_->emitCompletenessCheck(); } void QtUserSearchWindow::setNameSuggestions(const std::vector<std::string>& suggestions) { if (detailsPage_) { detailsPage_->setNameSuggestions(suggestions); } } void QtUserSearchWindow::prepopulateJIDAndName(const JID& jid, const std::string& name) { firstPage_->jid_->setText(P2QSTRING(jid.toBare().toString())); detailsPage_->setJID(jid); lastPage_ = 1; restart(); next(); detailsPage_->setName(name); } void QtUserSearchWindow::setContactSuggestions(const std::vector<Contact::ref>& suggestions) { if (type_ == AddContact) { firstPage_->jid_->setSuggestions(suggestions); } else { firstMultiJIDPage_->jid_->setSuggestions(suggestions); } } void QtUserSearchWindow::setJIDs(const std::vector<JID> &jids) { foreach(JID jid, jids) { - addSearchedJIDToList(jid); + addSearchedJIDToList(boost::make_shared<Contact>("", jid, StatusShow::None, "")); } onJIDUpdateRequested(jids); } void QtUserSearchWindow::setRoomJID(const JID& roomJID) { roomJID_ = roomJID; } std::string QtUserSearchWindow::getReason() const { return Q2PSTRING(firstMultiJIDPage_->reason_->text()); } 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) { diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.h b/Swift/QtUI/UserSearch/QtUserSearchWindow.h index 0349ba4..0318b3d 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.h +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.h @@ -45,56 +45,57 @@ namespace Swift { virtual void prepopulateJIDAndName(const JID& jid, const std::string& name); virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions); virtual void setJIDs(const std::vector<JID> &jids); virtual void setRoomJID(const JID &roomJID); virtual std::string getReason() const; virtual std::vector<JID> getJIDs() const; virtual void setCanStartImpromptuChats(bool supportsImpromptu); virtual void updateContacts(const std::vector<Contact::ref> &contacts); virtual void addContacts(const std::vector<Contact::ref>& contacts); virtual void setCanSupplyDescription(bool allowed); protected: virtual int nextId() const; private slots: void handleFirstPageRadioChange(); virtual void handleCurrentChanged(int); virtual void handleAccepted(); void handleContactSuggestionRequested(const QString& text); void addContact(); void handleAddViaSearch(); void handleListChanged(std::vector<Contact::ref> list); void handleJIDsAdded(std::vector<JID> jids); private: void setFirstPage(QString title = ""); void setSecondPage(); void setThirdPage(); private: void clearForm(); void setError(const QString& error); JID getServerToSearch(); void handleSearch(); JID getContactJID() const; - void addSearchedJIDToList(const JID& jid); + Contact::ref getContact() const; + void addSearchedJIDToList(const Contact::ref& contact); private: UIEventStream* eventStream_; UserSearchWindow::Type type_; QAbstractItemModel* model_; UserSearchDelegate* delegate_; QtUserSearchFirstPage* firstPage_; QtUserSearchFirstMultiJIDPage* firstMultiJIDPage_; QtUserSearchFieldsPage* fieldsPage_; QtUserSearchResultsPage* resultsPage_; QtUserSearchDetailsPage* detailsPage_; JID myServer_; JID roomJID_; int lastPage_; std::vector<Contact::ref> contactVector_; SettingsProvider* settings_; bool searchNext_; bool supportsImpromptu_; }; } |