diff options
| -rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 17 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatsManager.h | 2 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/UserSearchController.cpp | 3 | ||||
| -rw-r--r-- | Swift/Controllers/Contact.cpp | 12 | ||||
| -rw-r--r-- | Swift/Controllers/ContactProvider.h | 2 | ||||
| -rw-r--r-- | Swift/Controllers/ContactSuggester.cpp | 12 | ||||
| -rw-r--r-- | Swift/Controllers/ContactSuggester.h | 2 | ||||
| -rw-r--r-- | Swift/Controllers/ContactsFromXMPPRoster.cpp | 2 | ||||
| -rw-r--r-- | Swift/Controllers/ContactsFromXMPPRoster.h | 2 | ||||
| -rw-r--r-- | Swift/Controllers/HighlightEditorController.cpp | 2 | ||||
| -rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 8 | ||||
| -rw-r--r-- | Swift/QtUI/QtHighlightEditor.h | 2 | ||||
| -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 |
16 files changed, 67 insertions, 24 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 3db1327..c180024 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -968,19 +968,34 @@ void ChatsManager::handleLocalServiceWalkFinished() { } std::vector<ChatListWindow::Chat> ChatsManager::getRecentChats() const { return std::vector<ChatListWindow::Chat>(recentChats_.begin(), recentChats_.end()); } -std::vector<Contact::ref> Swift::ChatsManager::getContacts() { +std::vector<Contact::ref> Swift::ChatsManager::getContacts(bool withMUCNicks) { std::vector<Contact::ref> result; foreach (ChatListWindow::Chat chat, recentChats_) { if (!chat.isMUC) { result.push_back(boost::make_shared<Contact>(chat.chatName.empty() ? chat.jid.toString() : chat.chatName, chat.jid, chat.statusType, chat.avatarPath)); } } + if (withMUCNicks) { + /* collect MUC nicks */ + typedef std::map<JID, MUCController*>::value_type Item; + foreach (const Item& item, mucControllers_) { + JID mucJID = item.second->getToJID(); + std::map<std::string, JID> participants = item.second->getParticipantJIDs(); + typedef std::map<std::string, JID>::value_type ParticipantType; + foreach (const ParticipantType& participant, participants) { + const JID nickJID = JID(mucJID.getNode(), mucJID.getDomain(), participant.first); + Presence::ref presence = presenceOracle_->getLastPresence(nickJID); + const boost::filesystem::path avatar = avatarManager_->getAvatarPath(nickJID); + result.push_back(boost::make_shared<Contact>(participant.first, JID(), presence->getShow(), avatar)); + } + } + } return result; } ChatsManager::SingleChatWindowFactoryAdapter::SingleChatWindowFactoryAdapter(ChatWindow* chatWindow) : chatWindow_(chatWindow) {} ChatsManager::SingleChatWindowFactoryAdapter::~SingleChatWindowFactoryAdapter() {} ChatWindow* ChatsManager::SingleChatWindowFactoryAdapter::createChatWindow(const JID &, UIEventStream*) { diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h index 179f536..575b3cb 100644 --- a/Swift/Controllers/Chat/ChatsManager.h +++ b/Swift/Controllers/Chat/ChatsManager.h @@ -70,13 +70,13 @@ namespace Swift { virtual ~ChatsManager(); void setAvatarManager(AvatarManager* avatarManager); void setOnline(bool enabled); void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info); void handleIncomingMessage(boost::shared_ptr<Message> message); std::vector<ChatListWindow::Chat> getRecentChats() const; - virtual std::vector<Contact::ref> getContacts(); + virtual std::vector<Contact::ref> getContacts(bool withMUCNicks); boost::signal<void (bool supportsImpromptu)> onImpromptuMUCServiceDiscovered; private: class SingleChatWindowFactoryAdapter : public ChatWindowFactory { public: diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp index f259a9a..f1849c9 100644 --- a/Swift/Controllers/Chat/UserSearchController.cpp +++ b/Swift/Controllers/Chat/UserSearchController.cpp @@ -193,13 +193,14 @@ void UserSearchController::handleNameSuggestionRequest(const JID &jid) { handleVCardChanged(jid, vcard); } } void UserSearchController::handleContactSuggestionsRequested(std::string text) { const std::vector<JID> existingJIDs = window_->getJIDs(); - std::vector<Contact::ref> suggestions = contactSuggester_->getSuggestions(text); + std::vector<Contact::ref> suggestions = contactSuggester_->getSuggestions(text, false); + /* do not suggest contacts that have already been added to the chat list */ std::vector<Contact::ref>::iterator i = suggestions.begin(); while (i != suggestions.end()) { bool found = false; foreach (const JID& jid, existingJIDs) { if ((*i)->jid == jid) { found = true; diff --git a/Swift/Controllers/Contact.cpp b/Swift/Controllers/Contact.cpp index 198443d..be2b83a 100644 --- a/Swift/Controllers/Contact.cpp +++ b/Swift/Controllers/Contact.cpp @@ -14,17 +14,25 @@ Contact::Contact() { } Contact::Contact(const std::string& name, const JID& jid, StatusShow::Type statusType, const boost::filesystem::path& path) : name(name), jid(jid), statusType(statusType), avatarPath(path) { } bool Contact::lexicographicalSortPredicate(const Contact::ref& a, const Contact::ref& b) { - return a->jid < b->jid; + if (a->jid.isValid() && b->jid.isValid()) { + return a->jid < b->jid; + } else { + return a->name < b->name; + } } bool Contact::equalityPredicate(const Contact::ref& a, const Contact::ref& b) { - return a->jid == b->jid; + if (a->jid.isValid() && b->jid.isValid()) { + return a->jid == b->jid; + } else { + return a->name == b->name; + } } bool Contact::sortPredicate(const Contact::ref& a, const Contact::ref& b, const std::string& search) { /* perform case insensitive comparisons */ std::string aLower = a->name; boost::to_lower(aLower); diff --git a/Swift/Controllers/ContactProvider.h b/Swift/Controllers/ContactProvider.h index 0e56de5..acc2bdc 100644 --- a/Swift/Controllers/ContactProvider.h +++ b/Swift/Controllers/ContactProvider.h @@ -18,10 +18,10 @@ namespace Swift { class ContactProvider { public: virtual ~ContactProvider(); - virtual std::vector<Contact::ref> getContacts() = 0; + virtual std::vector<Contact::ref> getContacts(bool withMUCNicks) = 0; }; } diff --git a/Swift/Controllers/ContactSuggester.cpp b/Swift/Controllers/ContactSuggester.cpp index 42e8308..8627aeb 100644 --- a/Swift/Controllers/ContactSuggester.cpp +++ b/Swift/Controllers/ContactSuggester.cpp @@ -40,20 +40,26 @@ ContactSuggester::~ContactSuggester() { void ContactSuggester::addContactProvider(ContactProvider* provider) { contactProviders_.push_back(provider); } bool ContactSuggester::matchContact(const std::string& search, const Contact::ref& c) { - return fuzzyMatch(c->name, search) || fuzzyMatch(c->jid.toString(), search); + if (fuzzyMatch(c->name, search)) { + return true; + } + else if (c->jid.isValid()) { + return fuzzyMatch(c->jid.toString(), search); + } + return false; } -std::vector<Contact::ref> ContactSuggester::getSuggestions(const std::string& search) const { +std::vector<Contact::ref> ContactSuggester::getSuggestions(const std::string& search, bool withMUCNicks) const { std::vector<Contact::ref> results; foreach(ContactProvider* provider, contactProviders_) { - append(results, provider->getContacts()); + append(results, provider->getContacts(withMUCNicks)); } std::sort(results.begin(), results.end(), Contact::lexicographicalSortPredicate); results.erase(std::unique(results.begin(), results.end(), Contact::equalityPredicate), results.end()); results.erase(std::remove_if(results.begin(), results.end(), !lambda::bind(&matchContact, search, lambda::_1)), results.end()); diff --git a/Swift/Controllers/ContactSuggester.h b/Swift/Controllers/ContactSuggester.h index 1c796c9..ae47766 100644 --- a/Swift/Controllers/ContactSuggester.h +++ b/Swift/Controllers/ContactSuggester.h @@ -26,13 +26,13 @@ namespace Swift { public: ContactSuggester(); ~ContactSuggester(); void addContactProvider(ContactProvider* provider); - std::vector<Contact::ref> getSuggestions(const std::string& search) const; + std::vector<Contact::ref> getSuggestions(const std::string& search, bool withMUCNicks) const; public: static bool matchContact(const std::string& search, const Contact::ref& c); /** * Performs fuzzy matching on the string text. Matches when each character of match string is present in sequence in text string. */ static bool fuzzyMatch(std::string text, std::string match); diff --git a/Swift/Controllers/ContactsFromXMPPRoster.cpp b/Swift/Controllers/ContactsFromXMPPRoster.cpp index 7559962..abd62bd 100644 --- a/Swift/Controllers/ContactsFromXMPPRoster.cpp +++ b/Swift/Controllers/ContactsFromXMPPRoster.cpp @@ -24,13 +24,13 @@ namespace Swift { ContactsFromXMPPRoster::ContactsFromXMPPRoster(XMPPRoster* roster, AvatarManager* avatarManager, PresenceOracle* presenceOracle) : roster_(roster), avatarManager_(avatarManager), presenceOracle_(presenceOracle) { } ContactsFromXMPPRoster::~ContactsFromXMPPRoster() { } -std::vector<Contact::ref> ContactsFromXMPPRoster::getContacts() { +std::vector<Contact::ref> ContactsFromXMPPRoster::getContacts(bool /*withMUCNicks*/) { std::vector<Contact::ref> results; std::vector<XMPPRosterItem> rosterItems = roster_->getItems(); foreach(const XMPPRosterItem& rosterItem, rosterItems) { Contact::ref contact = boost::make_shared<Contact>(rosterItem.getName().empty() ? rosterItem.getJID().toString() : rosterItem.getName(), rosterItem.getJID(), StatusShow::None,""); contact->statusType = presenceOracle_->getHighestPriorityPresence(contact->jid) ? presenceOracle_->getHighestPriorityPresence(contact->jid)->getShow() : StatusShow::None; contact->avatarPath = avatarManager_->getAvatarPath(contact->jid); diff --git a/Swift/Controllers/ContactsFromXMPPRoster.h b/Swift/Controllers/ContactsFromXMPPRoster.h index 4adc606..b76adc4 100644 --- a/Swift/Controllers/ContactsFromXMPPRoster.h +++ b/Swift/Controllers/ContactsFromXMPPRoster.h @@ -22,13 +22,13 @@ class XMPPRoster; class ContactsFromXMPPRoster : public ContactProvider { public: ContactsFromXMPPRoster(XMPPRoster* roster, AvatarManager* avatarManager, PresenceOracle* presenceOracle); virtual ~ContactsFromXMPPRoster(); - virtual std::vector<Contact::ref> getContacts(); + virtual std::vector<Contact::ref> getContacts(bool withMUCNicks); private: XMPPRoster* roster_; AvatarManager* avatarManager_; PresenceOracle* presenceOracle_; }; diff --git a/Swift/Controllers/HighlightEditorController.cpp b/Swift/Controllers/HighlightEditorController.cpp index 38007f0..efa3ba2 100644 --- a/Swift/Controllers/HighlightEditorController.cpp +++ b/Swift/Controllers/HighlightEditorController.cpp @@ -46,11 +46,11 @@ void HighlightEditorController::handleUIEvent(boost::shared_ptr<UIEvent> rawEven } } void HighlightEditorController::handleContactSuggestionsRequested(const std::string& text) { if (contactSuggester_) { - highlightEditorWindow_->setContactSuggestions(contactSuggester_->getSuggestions(text)); + highlightEditorWindow_->setContactSuggestions(contactSuggester_->getSuggestions(text, true)); } } } diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index 5aa4560..97774be 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -347,15 +347,19 @@ void QtHighlightEditor::handleContactSuggestionRequested(const QString& text) void QtHighlightEditor::selectSoundFile() { QString path = QFileDialog::getOpenFileName(this, tr("Select sound file..."), QString(), "Sounds (*.wav)"); ui_.soundFile->setText(path); } -void QtHighlightEditor::handleOnUserSelected(const JID& jid) { +void QtHighlightEditor::handleOnUserSelected(const Contact::ref& contact) { /* this might seem like it should be standard behaviour for the suggesting input box, but is not desirable in all cases */ - jid_->setText(P2QSTRING(jid.toString())); + if (contact->jid.isValid()) { + jid_->setText(P2QSTRING(contact->jid.toString())); + } else { + jid_->setText(P2QSTRING(contact->name)); + } } void QtHighlightEditor::populateList() { previousRow_ = -1; ui_.listWidget->clear(); diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h index e0595ad..93a19b6 100644 --- a/Swift/QtUI/QtHighlightEditor.h +++ b/Swift/QtUI/QtHighlightEditor.h @@ -50,13 +50,13 @@ namespace Swift { void widgetClick(); void disableDialog(); void handleContactSuggestionRequested(const QString& text); void selectSoundFile(); private: - void handleOnUserSelected(const JID& jid); + void handleOnUserSelected(const Contact::ref& contact); void populateList(); void selectRow(int row); int getSelectedRow() const; HighlightRule ruleFromDialog(); void ruleToDialog(const HighlightRule& rule); 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 @@ -111,13 +111,17 @@ void QtSuggestingJIDInput::keyPressEvent(QKeyEvent* event) { 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(); @@ -141,13 +145,13 @@ void QtSuggestingJIDInput::handleSettingsChanged(const std::string& setting) { } } 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(); 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 @@ -32,13 +32,13 @@ class QtSuggestingJIDInput : public QLineEdit { 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); 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 @@ -75,13 +75,13 @@ 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(); @@ -267,15 +267,19 @@ JID QtUserSearchWindow::getContactJID() const { 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(); @@ -340,13 +344,13 @@ void QtUserSearchWindow::setContactSuggestions(const std::vector<Contact::ref>& 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; 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 @@ -74,13 +74,14 @@ namespace Swift { 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_; |
Swift