summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp17
-rw-r--r--Swift/Controllers/Chat/ChatsManager.h2
-rw-r--r--Swift/Controllers/Chat/UserSearchController.cpp3
-rw-r--r--Swift/Controllers/Contact.cpp12
-rw-r--r--Swift/Controllers/ContactProvider.h2
-rw-r--r--Swift/Controllers/ContactSuggester.cpp12
-rw-r--r--Swift/Controllers/ContactSuggester.h2
-rw-r--r--Swift/Controllers/ContactsFromXMPPRoster.cpp2
-rw-r--r--Swift/Controllers/ContactsFromXMPPRoster.h2
-rw-r--r--Swift/Controllers/HighlightEditorController.cpp2
-rw-r--r--Swift/QtUI/QtHighlightEditor.cpp8
-rw-r--r--Swift/QtUI/QtHighlightEditor.h2
-rw-r--r--Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp8
-rw-r--r--Swift/QtUI/UserSearch/QtSuggestingJIDInput.h2
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp12
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.h3
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
@@ -971,13 +971,28 @@ 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;
}
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
@@ -73,7 +73,7 @@ namespace Swift {
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;
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
@@ -196,7 +196,8 @@ void UserSearchController::handleNameSuggestionRequest(const JID &jid) {
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;
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
@@ -17,11 +17,19 @@ Contact::Contact(const std::string& name, const JID& jid, StatusShow::Type statu
}
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) {
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
@@ -21,7 +21,7 @@ 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
@@ -43,14 +43,20 @@ void ContactSuggester::addContactProvider(ContactProvider* 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);
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
@@ -29,7 +29,7 @@ namespace Swift {
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);
/**
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
@@ -27,7 +27,7 @@ ContactsFromXMPPRoster::ContactsFromXMPPRoster(XMPPRoster* roster, AvatarManager
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) {
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
@@ -25,7 +25,7 @@ class ContactsFromXMPPRoster : public ContactProvider {
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_;
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
@@ -49,7 +49,7 @@ 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
@@ -350,9 +350,13 @@ void QtHighlightEditor::selectSoundFile()
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()
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
@@ -53,7 +53,7 @@ namespace Swift {
void selectSoundFile();
private:
- void handleOnUserSelected(const JID& jid);
+ void handleOnUserSelected(const Contact::ref& contact);
void populateList();
void selectRow(int row);
int getSelectedRow() const;
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
@@ -114,7 +114,11 @@ void QtSuggestingJIDInput::keyPressEvent(QKeyEvent* event) {
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 {
@@ -144,7 +148,7 @@ 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();
}
}
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
@@ -35,7 +35,7 @@ class QtSuggestingJIDInput : public QLineEdit {
void clear();
- boost::signal<void (const JID&)> onUserSelected;
+ boost::signal<void (const Contact::ref&)> onUserSelected;
signals:
void editingDone();
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
@@ -78,7 +78,7 @@ void QtUserSearchWindow::handleCurrentChanged(int page) {
}
resultsPage_->emitCompletenessCheck();
if (page == 1 && lastPage_ == 3) {
- addSearchedJIDToList(getContactJID());
+ addSearchedJIDToList(getContact());
setSecondPage();
}
else if (page == 2 && lastPage_ == 1) {
@@ -270,9 +270,13 @@ JID QtUserSearchWindow::getContactJID() const {
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();
}
@@ -343,7 +347,7 @@ void QtUserSearchWindow::setContactSuggestions(const std::vector<Contact::ref>&
void QtUserSearchWindow::setJIDs(const std::vector<JID> &jids) {
foreach(JID jid, jids) {
- addSearchedJIDToList(jid);
+ addSearchedJIDToList(boost::make_shared<Contact>("", jid, StatusShow::None, ""));
}
onJIDUpdateRequested(jids);
}
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
@@ -77,7 +77,8 @@ namespace Swift {
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_;