summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-04-12 09:05:33 (GMT)
committerTobias Markmann <tm@ayena.de>2017-04-12 09:05:33 (GMT)
commit4024517891d3a222e71e6632c3609fcda08c875e (patch)
tree690020d1a9c1a4c3fd8bff0f59d196ee23b05d60 /Swift/Controllers/Chat
parent43b85e93c7acd865be2de009651e146e9faece96 (diff)
downloadswift-4024517891d3a222e71e6632c3609fcda08c875e.zip
swift-4024517891d3a222e71e6632c3609fcda08c875e.tar.bz2
Assert first page in QtUserSearchWindow wizard based on type
Converted enum to C++11 enum class in process. Coverity raised this issue. Test-Information: All unit tests pass. Using the “Add Contact…” and “Start Chat…” dialogs did not crash. Tested on macOS 10.12.4 with Qt 5.4.2. Change-Id: I0409688b001d1eaaf5fa77a25b1158ce9e611c77
Diffstat (limited to 'Swift/Controllers/Chat')
-rw-r--r--Swift/Controllers/Chat/UserSearchController.cpp24
-rw-r--r--Swift/Controllers/Chat/UserSearchController.h4
2 files changed, 14 insertions, 14 deletions
diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp
index 91de670..30c3c77 100644
--- a/Swift/Controllers/Chat/UserSearchController.cpp
+++ b/Swift/Controllers/Chat/UserSearchController.cpp
@@ -1,32 +1,32 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Chat/UserSearchController.h>
#include <memory>
#include <boost/bind.hpp>
#include <Swiften/Avatars/AvatarManager.h>
#include <Swiften/Base/String.h>
#include <Swiften/Disco/DiscoServiceWalker.h>
#include <Swiften/Disco/GetDiscoInfoRequest.h>
#include <Swiften/Disco/GetDiscoItemsRequest.h>
#include <Swiften/Presence/PresenceOracle.h>
#include <Swiften/VCards/VCardManager.h>
#include <Swift/Controllers/ContactEditController.h>
#include <Swift/Controllers/ContactSuggester.h>
#include <Swift/Controllers/Intl.h>
#include <Swift/Controllers/ProfileSettingsProvider.h>
#include <Swift/Controllers/Roster/RosterController.h>
#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIInterfaces/UserSearchWindow.h>
#include <Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h>
@@ -56,71 +56,71 @@ UserSearchController::~UserSearchController() {
window_->onJIDAddRequested.disconnect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1));
window_->onJIDEditFieldChanged.disconnect(boost::bind(&UserSearchController::handleJIDEditingFinished, this, _1));
delete window_;
}
presenceOracle_->onPresenceChange.disconnect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1));
avatarManager_->onAvatarChanged.disconnect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1));
vcardManager_->onVCardChanged.disconnect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
uiEventStream_->onUIEvent.disconnect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
}
UserSearchWindow* UserSearchController::getUserSearchWindow() {
initializeUserWindow();
assert(window_);
return window_;
}
void UserSearchController::setCanInitiateImpromptuMUC(bool supportsImpromptu) {
if (!window_) {
initializeUserWindow();
}
if (window_) {
window_->setCanStartImpromptuChats(supportsImpromptu);
} // Else doesn't support search
}
void UserSearchController::handleUIEvent(std::shared_ptr<UIEvent> event) {
bool handle = false;
std::shared_ptr<RequestAddUserDialogUIEvent> addUserRequest = std::shared_ptr<RequestAddUserDialogUIEvent>();
auto inviteToMUCRequest = RequestInviteToMUCUIEvent::ref();
switch (type_) {
- case AddContact:
+ case Type::AddContact:
if ((addUserRequest = std::dynamic_pointer_cast<RequestAddUserDialogUIEvent>(event))) {
handle = true;
}
break;
- case StartChat:
+ case Type::StartChat:
if (std::dynamic_pointer_cast<RequestChatWithUserDialogUIEvent>(event)) {
handle = true;
}
break;
- case InviteToChat:
+ case Type::InviteToChat:
if ((inviteToMUCRequest = std::dynamic_pointer_cast<RequestInviteToMUCUIEvent>(event))) {
handle = true;
}
break;
}
if (handle) {
initializeUserWindow();
window_->show();
window_->addSavedServices(savedDirectories_);
if (addUserRequest) {
const std::string& name = addUserRequest->getPredefinedName();
const JID& jid = addUserRequest->getPredefinedJID();
if (!name.empty() && jid.isValid()) {
window_->prepopulateJIDAndName(jid, name);
}
}
else if (inviteToMUCRequest) {
window_->setCanSupplyDescription(!inviteToMUCRequest->isImpromptu());
window_->setJIDs(inviteToMUCRequest->getInvites());
window_->setOriginator(inviteToMUCRequest->getOriginator());
}
return;
}
}
void UserSearchController::handleFormRequested(const JID& service) {
window_->setSearchError(false);
window_->setServerSupportsSearch(true);
//Abort a previous search if is active
@@ -214,61 +214,61 @@ void UserSearchController::handleJIDEditingFinished(const JID& jid) {
if (rosterController_->getItem(jid)) {
window_->setWarning(QT_TRANSLATE_NOOP("", "This contact is already on your contact list."));
}
else if (jid.getNode().empty()) {
window_->setWarning(QT_TRANSLATE_NOOP("", "Part of the address you have entered is missing. An address has a structure of 'user@example.com'."));
}
else {
window_->setWarning(boost::optional<std::string>());
}
}
else {
window_->setWarning(QT_TRANSLATE_NOOP("", "The address you have entered is invalid."));
}
}
void UserSearchController::handleContactSuggestionsRequested(std::string text) {
const std::vector<JID> existingJIDs = window_->getJIDs();
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;
for (const auto& jid : existingJIDs) {
if ((*i)->jid == jid) {
found = true;
break;
}
}
// remove contact suggestions which are already on the contact list in add-contact-mode
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
if (!found && !!rosterController_->getItem((*i)->jid)) {
found = true;
}
}
if (found) {
i = suggestions.erase(i);
} else {
i++;
}
}
window_->setContactSuggestions(suggestions);
}
void UserSearchController::handleVCardChanged(const JID& jid, VCard::ref vcard) {
if (jid == suggestionsJID_) {
window_->setNameSuggestions(ContactEditController::nameSuggestionsFromVCard(vcard));
suggestionsJID_ = JID();
}
handleJIDUpdateRequested(std::vector<JID>(1, jid));
}
void UserSearchController::handleAvatarChanged(const JID& jid) {
handleJIDUpdateRequested(std::vector<JID>(1, jid));
}
void UserSearchController::handlePresenceChanged(Presence::ref presence) {
handleJIDUpdateRequested(std::vector<JID>(1, presence->getFrom().toBare()));
}
@@ -300,70 +300,70 @@ Contact::ref UserSearchController::convertJIDtoContact(const JID& jid) {
contact->name = rosterItem->getName();
} else {
VCard::ref vcard = vcardManager_->getVCard(jid);
if (vcard && !vcard->getFullName().empty()) {
contact->name = vcard->getFullName();
} else {
contact->name = jid.toString();
}
}
// presence lookup
Presence::ref presence = presenceOracle_->getAccountPresence(jid);
if (presence) {
contact->statusType = presence->getShow();
} else {
contact->statusType = StatusShow::None;
}
// avatar lookup
contact->avatarPath = avatarManager_->getAvatarPath(jid);
return contact;
}
void UserSearchController::handleDiscoWalkFinished() {
window_->setServerSupportsSearch(false);
endDiscoWalker();
}
void UserSearchController::initializeUserWindow() {
if (!window_) {
- UserSearchWindow::Type windowType = UserSearchWindow::AddContact;
+ auto windowType = UserSearchWindow::Type::AddContact;
switch(type_) {
- case AddContact:
- windowType = UserSearchWindow::AddContact;
+ case Type::AddContact:
+ windowType = UserSearchWindow::Type::AddContact;
break;
- case StartChat:
- windowType = UserSearchWindow::ChatToContact;
+ case Type::StartChat:
+ windowType = UserSearchWindow::Type::ChatToContact;
break;
- case InviteToChat:
- windowType = UserSearchWindow::InviteToChat;
+ case Type::InviteToChat:
+ windowType = UserSearchWindow::Type::InviteToChat;
break;
}
window_ = factory_->createUserSearchWindow(windowType, uiEventStream_, rosterController_->getGroups());
if (!window_) {
// UI Doesn't support user search
return;
}
window_->onNameSuggestionRequested.connect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1));
window_->onFormRequested.connect(boost::bind(&UserSearchController::handleFormRequested, this, _1));
window_->onSearchRequested.connect(boost::bind(&UserSearchController::handleSearch, this, _1, _2));
window_->onContactSuggestionsRequested.connect(boost::bind(&UserSearchController::handleContactSuggestionsRequested, this, _1));
window_->onJIDUpdateRequested.connect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1));
window_->onJIDAddRequested.connect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1));
window_->onJIDEditFieldChanged.connect(boost::bind(&UserSearchController::handleJIDEditingFinished, this, _1));
window_->setSelectedService(JID(jid_.getDomain()));
window_->clear();
}
}
void UserSearchController::loadSavedDirectories() {
savedDirectories_.clear();
for (auto&& stringItem : String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) {
if(!stringItem.empty()) {
savedDirectories_.push_back(JID(stringItem));
}
}
}
void UserSearchController::addToSavedDirectories(const JID& jid) {
diff --git a/Swift/Controllers/Chat/UserSearchController.h b/Swift/Controllers/Chat/UserSearchController.h
index 4658301..49bb63c 100644
--- a/Swift/Controllers/Chat/UserSearchController.h
+++ b/Swift/Controllers/Chat/UserSearchController.h
@@ -1,82 +1,82 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <boost/signals2.hpp>
#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Elements/DiscoItems.h>
#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/Elements/Presence.h>
#include <Swiften/Elements/SearchPayload.h>
#include <Swiften/Elements/VCard.h>
#include <Swiften/JID/JID.h>
#include <Swift/Controllers/Contact.h>
namespace Swift {
class UIEventStream;
class UIEvent;
class UserSearchWindow;
class UserSearchWindowFactory;
class IQRouter;
class DiscoServiceWalker;
class RosterController;
class VCardManager;
class ContactSuggester;
class AvatarManager;
class PresenceOracle;
class ProfileSettingsProvider;
class UserSearchResult {
public:
UserSearchResult(const JID& jid, const std::map<std::string, std::string>& fields) : jid_(jid), fields_(fields) {}
const JID& getJID() const {return jid_;}
const std::map<std::string, std::string>& getFields() const {return fields_;}
private:
JID jid_;
std::map<std::string, std::string> fields_;
};
class UserSearchController {
public:
- enum Type {AddContact, StartChat, InviteToChat};
+ enum class Type {AddContact, StartChat, InviteToChat};
UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* userSearchWindowFactory, IQRouter* iqRouter, RosterController* rosterController, ContactSuggester* contactSuggester, AvatarManager* avatarManager, PresenceOracle* presenceOracle, ProfileSettingsProvider* settings);
~UserSearchController();
UserSearchWindow* getUserSearchWindow();
void setCanInitiateImpromptuMUC(bool supportsImpromptu);
private:
void handleUIEvent(std::shared_ptr<UIEvent> event);
void handleFormRequested(const JID& service);
void handleDiscoServiceFound(const JID& jid, std::shared_ptr<DiscoInfo> info);
void handleDiscoWalkFinished();
void handleFormResponse(std::shared_ptr<SearchPayload> items, ErrorPayload::ref error);
void handleSearch(std::shared_ptr<SearchPayload> fields, const JID& jid);
void handleSearchResponse(std::shared_ptr<SearchPayload> results, ErrorPayload::ref error);
void handleNameSuggestionRequest(const JID& jid);
void handleContactSuggestionsRequested(std::string text);
void handleVCardChanged(const JID& jid, VCard::ref vcard);
void handleAvatarChanged(const JID& jid);
void handlePresenceChanged(Presence::ref presence);
void handleJIDUpdateRequested(const std::vector<JID>& jids);
void handleJIDAddRequested(const std::vector<JID>& jids);
void handleJIDEditingFinished(const JID& jid);
Contact::ref convertJIDtoContact(const JID& jid);
void endDiscoWalker();
void initializeUserWindow();
void loadSavedDirectories();
void addToSavedDirectories(const JID& jid);
private: