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
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
-rw-r--r--Swift/Controllers/Chat/UserSearchController.cpp24
-rw-r--r--Swift/Controllers/Chat/UserSearchController.h4
-rw-r--r--Swift/Controllers/MainController.cpp6
-rw-r--r--Swift/Controllers/UIInterfaces/UserSearchWindow.h4
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp8
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp4
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp75
7 files changed, 68 insertions, 57 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,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
@@ -85,3 +85,3 @@ void UserSearchController::handleUIEvent(std::shared_ptr<UIEvent> event) {
switch (type_) {
- case AddContact:
+ case Type::AddContact:
if ((addUserRequest = std::dynamic_pointer_cast<RequestAddUserDialogUIEvent>(event))) {
@@ -90,3 +90,3 @@ void UserSearchController::handleUIEvent(std::shared_ptr<UIEvent> event) {
break;
- case StartChat:
+ case Type::StartChat:
if (std::dynamic_pointer_cast<RequestChatWithUserDialogUIEvent>(event)) {
@@ -95,3 +95,3 @@ void UserSearchController::handleUIEvent(std::shared_ptr<UIEvent> event) {
break;
- case InviteToChat:
+ case Type::InviteToChat:
if ((inviteToMUCRequest = std::dynamic_pointer_cast<RequestInviteToMUCUIEvent>(event))) {
@@ -243,3 +243,3 @@ void UserSearchController::handleContactSuggestionsRequested(std::string text) {
// 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)) {
@@ -329,12 +329,12 @@ 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;
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,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
@@ -51,3 +51,3 @@ namespace Swift {
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);
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index e64b23d..b22e467 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -368,3 +368,3 @@ void MainController::handleConnected() {
- userSearchControllerInvite_ = new UserSearchController(UserSearchController::InviteToChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
+ userSearchControllerInvite_ = new UserSearchController(UserSearchController::Type::InviteToChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
#ifdef SWIFT_EXPERIMENTAL_HISTORY
@@ -407,4 +407,4 @@ void MainController::handleConnected() {
- userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
- userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithoutRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
+ userSearchControllerChat_ = new UserSearchController(UserSearchController::Type::StartChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
+ userSearchControllerAdd_ = new UserSearchController(UserSearchController::Type::AddContact, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithoutRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
adHocManager_ = new AdHocManager(JID(boundJID_.getDomain()), uiFactory_, client_->getIQRouter(), uiEventStream_, rosterController_->getWindow());
diff --git a/Swift/Controllers/UIInterfaces/UserSearchWindow.h b/Swift/Controllers/UIInterfaces/UserSearchWindow.h
index 279f4f3..c13e376 100644
--- a/Swift/Controllers/UIInterfaces/UserSearchWindow.h
+++ b/Swift/Controllers/UIInterfaces/UserSearchWindow.h
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
@@ -22,3 +22,3 @@ namespace Swift {
public:
- enum Type {AddContact, ChatToContact, InviteToChat};
+ enum class Type {AddContact, ChatToContact, InviteToChat};
virtual ~UserSearchWindow() {}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
index 1327a8f..8656db7 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
@@ -7,3 +7,3 @@
/*
- * Copyright (c) 2014-2016 Isode Limited.
+ * Copyright (c) 2014-2017 Isode Limited.
* All rights reserved.
@@ -31,9 +31,9 @@ QtUserSearchFirstMultiJIDPage::QtUserSearchFirstMultiJIDPage(UserSearchWindow::T
switch (type) {
- case UserSearchWindow::AddContact:
+ case UserSearchWindow::Type::AddContact:
introText = tr("Add another user to your contact list");
break;
- case UserSearchWindow::ChatToContact:
+ case UserSearchWindow::Type::ChatToContact:
introText = tr("Chat to another user");
break;
- case UserSearchWindow::InviteToChat:
+ case UserSearchWindow::Type::InviteToChat:
introText = tr("Invite contact to chat");
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
index 5d0c9fa..24e79e4 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
* All rights reserved.
@@ -17,3 +17,3 @@ QtUserSearchFirstPage::QtUserSearchFirstPage(UserSearchWindow::Type type, const
setTitle(title);
- setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(type == UserSearchWindow::AddContact ? tr("Add another user to your contact list") : tr("Chat to another user")));
+ setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(type == UserSearchWindow::Type::AddContact ? tr("Add another user to your contact list") : tr("Chat to another user")));
jid_ = new QtSuggestingJIDInput(this, settings);
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
index f150557..e770186 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
@@ -36,3 +36,3 @@ namespace Swift {
-QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups, SettingsProvider* settingsProvider) : eventStream_(eventStream), type_(type), model_(nullptr), firstMultiJIDPage_(nullptr), settings_(settingsProvider), searchNext_(false), supportsImpromptu_(false) {
+QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups, SettingsProvider* settingsProvider) : eventStream_(eventStream), type_(type), model_(nullptr), firstPage_(nullptr), firstMultiJIDPage_(nullptr), settings_(settingsProvider), searchNext_(false), supportsImpromptu_(false) {
setupUi(this);
@@ -47,9 +47,9 @@ QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWin
switch(type) {
- case AddContact:
+ case Type::AddContact:
title = tr("Add Contact");
break;
- case ChatToContact:
+ case Type::ChatToContact:
title = tr("Chat to Users");
break;
- case InviteToChat:
+ case Type::InviteToChat:
title = tr("Add Users to Chat");
@@ -79,3 +79,14 @@ void QtUserSearchWindow::handleCurrentChanged(int page) {
searchNext_ = false;
- if (type_ != AddContact) {
+
+ // Check preconditions per type.
+ if (type_ == Type::AddContact) {
+ assert(firstPage_);
+ assert(!firstMultiJIDPage_);
+ }
+ else {
+ assert(!firstPage_);
+ assert(firstMultiJIDPage_);
+ }
+
+ if (type_ != Type::AddContact) {
firstMultiJIDPage_->reset();
@@ -83,3 +94,3 @@ void QtUserSearchWindow::handleCurrentChanged(int page) {
resultsPage_->emitCompletenessCheck();
- if (firstMultiJIDPage_ && page == 1 && lastPage_ == 3) {
+ if (type_ != Type::AddContact && page == 1 && lastPage_ == 3) {
addSearchedJIDToList(getContact());
@@ -99,3 +110,3 @@ void QtUserSearchWindow::handleCurrentChanged(int page) {
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
bool remote = firstPage_->byRemoteSearch_->isChecked();
@@ -121,3 +132,3 @@ void QtUserSearchWindow::handleCurrentChanged(int page) {
JID QtUserSearchWindow::getServerToSearch() {
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
return firstPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstPage_->service_->currentText().trimmed())) : myServer_;
@@ -133,3 +144,3 @@ void QtUserSearchWindow::handleAccepted() {
switch(type_) {
- case AddContact:
+ case Type::AddContact:
jid = getContactJID();
@@ -137,3 +148,3 @@ void QtUserSearchWindow::handleAccepted() {
break;
- case ChatToContact:
+ case Type::ChatToContact:
if (contactVector_.size() == 1) {
@@ -150,3 +161,3 @@ void QtUserSearchWindow::handleAccepted() {
break;
- case InviteToChat:
+ case Type::InviteToChat:
for (Contact::ref contact : contactVector_) {
@@ -173,3 +184,3 @@ void QtUserSearchWindow::addContact() {
firstMultiJIDPage_->emitCompletenessCheck();
- if (type_ == ChatToContact) {
+ if (type_ == Type::ChatToContact) {
firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
@@ -197,7 +208,7 @@ void QtUserSearchWindow::setWarning(const boost::optional<std::string>& message)
int QtUserSearchWindow::nextId() const {
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
switch (currentId()) {
- case 1: return firstPage_->byJID_->isChecked() ? (type_ == AddContact ? 4 : -1) : 2;
+ case 1: return firstPage_->byJID_->isChecked() ? (type_ == Type::AddContact ? 4 : -1) : 2;
case 2: return 3;
- case 3: return type_ == AddContact ? 4 : -1;
+ case 3: return type_ == Type::AddContact ? 4 : -1;
case 4: return -1;
@@ -263,3 +274,3 @@ JID QtUserSearchWindow::getContactJID() const {
bool useSearchResult;
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
useSearchResult = !firstPage_->byJID_->isChecked();
@@ -317,3 +328,3 @@ void QtUserSearchWindow::show() {
clear();
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
setWarning(boost::optional<std::string>());
@@ -325,3 +336,3 @@ void QtUserSearchWindow::show() {
void QtUserSearchWindow::addSavedServices(const std::vector<JID>& services) {
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
firstPage_->service_->clear();
@@ -376,3 +387,3 @@ void QtUserSearchWindow::prepopulateJIDAndName(const JID& jid, const std::string
void QtUserSearchWindow::setContactSuggestions(const std::vector<Contact::ref>& suggestions) {
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
firstPage_->jid_->setSuggestions(suggestions);
@@ -412,3 +423,3 @@ void QtUserSearchWindow::setCanStartImpromptuChats(bool supportsImpromptu) {
supportsImpromptu_ = supportsImpromptu;
- if (type_ == ChatToContact) {
+ if (type_ == Type::ChatToContact) {
firstMultiJIDPage_->contactList_->setMaximumNoOfContactsToOne(!supportsImpromptu_);
@@ -418,3 +429,3 @@ void QtUserSearchWindow::setCanStartImpromptuChats(bool supportsImpromptu) {
void QtUserSearchWindow::updateContacts(const std::vector<Contact::ref>& contacts) {
- if (type_ != AddContact) {
+ if (type_ != Type::AddContact) {
firstMultiJIDPage_->contactList_->updateContacts(contacts);
@@ -424,3 +435,3 @@ void QtUserSearchWindow::updateContacts(const std::vector<Contact::ref>& contact
void QtUserSearchWindow::addContacts(const std::vector<Contact::ref>& contacts) {
- if (type_ != AddContact) {
+ if (type_ != Type::AddContact) {
/* prevent duplicate JIDs from appearing in the contact list */
@@ -438,3 +449,3 @@ void QtUserSearchWindow::addContacts(const std::vector<Contact::ref>& contacts)
}
- if (type_ != InviteToChat && !supportsImpromptu_ && contactVector_.size() > 1) {
+ if (type_ != Type::InviteToChat && !supportsImpromptu_ && contactVector_.size() > 1) {
contactVector_.resize(1); /* can't chat with more than one user */
@@ -443,3 +454,3 @@ void QtUserSearchWindow::addContacts(const std::vector<Contact::ref>& contacts)
firstMultiJIDPage_->emitCompletenessCheck();
- if (type_ == ChatToContact) {
+ if (type_ == Type::ChatToContact) {
firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? true : (contactVector_.size() < 1));
@@ -461,3 +472,3 @@ void QtUserSearchWindow::handleListChanged(std::vector<Contact::ref> list) {
contactVector_ = list;
- if (type_ == ChatToContact) {
+ if (type_ == Type::ChatToContact) {
firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
@@ -511,3 +522,3 @@ void QtUserSearchWindow::setFirstPage(QString title) {
}
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
firstPage_ = new QtUserSearchFirstPage(type_, title.isEmpty() ? firstPage_->title() : title, settings_);
@@ -556,3 +567,3 @@ void QtUserSearchWindow::setThirdPage() {
#endif
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next()));
@@ -581,3 +592,3 @@ void QtUserSearchWindow::clear() {
QString howText;
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
firstPage_->errorLabel_->setVisible(false);
@@ -591,5 +602,5 @@ void QtUserSearchWindow::clear() {
firstMultiJIDPage_->errorLabel_->setVisible(false);
- if (type_ == ChatToContact) {
+ if (type_ == Type::ChatToContact) {
howText = QString(tr("List of participants:"));
- } else if (type_ == InviteToChat) {
+ } else if (type_ == Type::InviteToChat) {
howText = QString(tr("Who do you want to invite to the chat?"));
@@ -608,3 +619,3 @@ void QtUserSearchWindow::setError(const QString& error) {
if (error.isEmpty()) {
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
firstPage_->errorLabel_->hide();
@@ -615,3 +626,3 @@ void QtUserSearchWindow::setError(const QString& error) {
else {
- if (type_ == AddContact) {
+ if (type_ == Type::AddContact) {
firstPage_->errorLabel_->setText(QString("<font color='red'>%1</font>").arg(error));