summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/UserSearch/QtUserSearchWindow.cpp')
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp75
1 files changed, 43 insertions, 32 deletions
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));