diff options
Diffstat (limited to 'Swift/QtUI/UserSearch/QtUserSearchWindow.cpp')
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
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) { |