From 3fdf13823a391c7db83e05685e78db19e4110e59 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Fri, 31 Dec 2010 18:34:28 +0000
Subject: Disable user search wizard pages unless they're ready.

Resolves: #731

diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
index acc6a46..7e3c98d 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
@@ -20,16 +20,53 @@
 
 namespace Swift {
 
-bool QtUserSearchFirstPage::isComplete() {
- return true;
+QtUserSearchFirstPage::QtUserSearchFirstPage() {
+	setupUi(this);
+	connect(jid_, SIGNAL(textChanged(const QString&)), this, SLOT(emitCompletenessCheck()));
+	connect(service_, SIGNAL(textChanged(const QString&)), this, SLOT(emitCompletenessCheck()));
+}
+
+QtUserSearchFieldsPage::QtUserSearchFieldsPage() {
+	setupUi(this);
+}
+
+QtUserSearchResultsPage::QtUserSearchResultsPage() {
+	setupUi(this);
+	connect(results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
+	connect(results_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
+	connect(results_, SIGNAL(entered(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
+}
+
+bool QtUserSearchFirstPage::isComplete() const {
+	bool complete = false;
+	if (byJID_->isChecked()) {
+		complete = JID(Q2PSTRING(jid_->text())).isValid();
+	} else if (byLocalSearch_->isChecked()) {
+		complete = true;
+	} else if (byRemoteSearch_->isChecked()) {
+		complete = JID(Q2PSTRING(service_->currentText())).isValid();
+	}
+	return complete;
+}
+
+bool QtUserSearchFieldsPage::isComplete() const {
+	return nickInput_->isEnabled() || firstInput_->isEnabled() || lastInput_->isEnabled() || emailInput_->isEnabled();
+}
+
+bool QtUserSearchResultsPage::isComplete() const {
+	return results_->currentIndex().isValid();
+}
+
+void QtUserSearchFirstPage::emitCompletenessCheck() {
+	emit completeChanged();
 }
 
-bool QtUserSearchFieldsPage::isComplete() {
- return true;
+void QtUserSearchFieldsPage::emitCompletenessCheck() {
+	emit completeChanged();
 }
 
-bool QtUserSearchResultsPage::isComplete() {
-	return true;
+void QtUserSearchResultsPage::emitCompletenessCheck() {
+	emit completeChanged();
 }
 
 QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type) : type_(type) {
@@ -199,6 +236,7 @@ void QtUserSearchWindow::setSearchFields(boost::shared_ptr<SearchPayload> fields
 		legacySearchWidgets[i]->setVisible(enabled[i]);
 		legacySearchWidgets[i]->setEnabled(enabled[i]);
 	}
+	fieldsPage_->emitCompletenessCheck();
 }
 //
 //void QtUserSearchWindow::handleActivated(const QModelIndex& index) {
@@ -238,6 +276,7 @@ void QtUserSearchWindow::clearForm() {
 	for (int i = 0; i < 8; i++) {
 		legacySearchWidgets[i]->hide();
 	}
+	fieldsPage_->emitCompletenessCheck();
 }
 
 void QtUserSearchWindow::clear() {
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.h b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
index 4672d32..cc6eefb 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
@@ -25,28 +25,28 @@ namespace Swift {
 	class QtUserSearchFirstPage : public QWizardPage, public Ui::QtUserSearchFirstPage {
 		Q_OBJECT
 		public:
-			QtUserSearchFirstPage() {
-				setupUi(this);
-			}
-			virtual bool isComplete();
+			QtUserSearchFirstPage();
+			virtual bool isComplete() const;
+		public slots:
+			void emitCompletenessCheck();
 	};
 
 	class QtUserSearchFieldsPage : public QWizardPage, public Ui::QtUserSearchFieldsPage {
 		Q_OBJECT
 		public:
-			QtUserSearchFieldsPage() {
-				setupUi(this);
-			}
-			virtual bool isComplete();
+			QtUserSearchFieldsPage();
+			virtual bool isComplete() const;
+		public slots:
+			void emitCompletenessCheck();
 	};
 
 	class QtUserSearchResultsPage : public QWizardPage, public Ui::QtUserSearchResultsPage {
 		Q_OBJECT
 		public:
-			QtUserSearchResultsPage() {
-				setupUi(this);
-			}
-			virtual bool isComplete();
+			QtUserSearchResultsPage();
+			virtual bool isComplete() const;
+		public slots:
+			void emitCompletenessCheck();
 	};
 
 	class QtUserSearchWindow : public QWizard, public UserSearchWindow, private Ui::QtUserSearchWizard {
-- 
cgit v0.10.2-6-g49f6