From 3965c1874cf6d141b3575eae4078cd57628515a4 Mon Sep 17 00:00:00 2001
From: Richard Maudsley <richard.maudsley@isode.com>
Date: Fri, 17 Jan 2014 11:18:40 +0000
Subject: Improved natural language rule display.

Change-Id: I1d47a33baac4f8dd0789c61a56f7a2fa8128d925

diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp
index 18101d5..457d397 100644
--- a/Swift/QtUI/QtHighlightEditor.cpp
+++ b/Swift/QtUI/QtHighlightEditor.cpp
@@ -69,7 +69,8 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare
 	connect(ui_.radioButton_6, SIGNAL(clicked()), SLOT(soundCustomSelect()));
 
 	ui_.lineEdit->setVisible(false);
-	ui_.horizontalLayout_2->addWidget(new QtSuggestingJIDInput(this, settings));
+	jid_ = new QtSuggestingJIDInput(this, settings);
+	ui_.horizontalLayout_2->addWidget(jid_);
 
 	setWindowTitle(tr("Highlight Rules"));
 }
@@ -104,6 +105,35 @@ std::string formatNaturalDescription(const HighlightRule& rule)
 		return "This rule has not been marked as a chat or room rule!";
 	}
 
+	std::vector<std::string> senders = rule.getSenders();
+	std::vector<std::string> keywords = rule.getKeywords();
+
+	if (!senders.empty() || !keywords.empty()) {
+		text += " if";
+	}
+
+	if (!senders.empty()) {
+		text += " the sender is called '" + senders[0] + "'";
+	}
+
+	if (!senders.empty() && !keywords.empty()) {
+		text += ", and";
+	}
+
+	if (!keywords.empty()) {
+		text += " the message contains '" + keywords[0] + "'";
+		if (rule.getMatchCase()) {
+			text += " (case sensivitive)";
+		} else {
+			text += " (not case sensivitive)";
+		}
+		if (rule.getMatchWholeWords()) {
+			text += " as a whole word.";
+		} else {
+			text += " as a part of any word.";
+		}
+	}
+
 	return text;
 }
 
@@ -244,7 +274,7 @@ HighlightRule QtHighlightEditor::ruleFromDialog()
 	rule.setMatchMUC(ui_.checkBox_2->isChecked());
 
 	if (ui_.checkBox_3->isChecked()) {
-		QString senderName = ui_.lineEdit->text();
+		QString senderName = jid_->text();
 		if (!senderName.isEmpty()) {
 			std::vector<std::string> senders;
 			senders.push_back(Q2PSTRING(senderName));
@@ -257,7 +287,7 @@ HighlightRule QtHighlightEditor::ruleFromDialog()
 		if (!keywordString.isEmpty()) {
 			std::vector<std::string> keywords;
 			keywords.push_back(Q2PSTRING(keywordString));
-			rule.setSenders(keywords);
+			rule.setKeywords(keywords);
 		}
 	}
 
@@ -290,12 +320,12 @@ void QtHighlightEditor::ruleToDialog(const HighlightRule& rule)
 	std::vector<std::string> senders = rule.getSenders();
 	if (senders.empty()) {
 		ui_.checkBox_3->setChecked(false);
-		ui_.lineEdit->setEnabled(false);
-		ui_.lineEdit->setText("");
+		jid_->setEnabled(false);
+		jid_->setText("");
 	} else {
 		ui_.checkBox_3->setChecked(true);
-		ui_.lineEdit->setEnabled(true);
-		ui_.lineEdit->setText(P2QSTRING(senders[0]));
+		jid_->setEnabled(true);
+		jid_->setText(P2QSTRING(senders[0]));
 	}
 
 	std::vector<std::string> keywords = rule.getKeywords();
diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h
index 792adab..ebae432 100644
--- a/Swift/QtUI/QtHighlightEditor.h
+++ b/Swift/QtUI/QtHighlightEditor.h
@@ -19,6 +19,7 @@
 namespace Swift {
 
 	class QtSettingsProvider;
+	class QtSuggestingJIDInput;
 
 	class QtHighlightEditor : public QWidget, public HighlightEditorWindow {
 		Q_OBJECT
@@ -54,6 +55,7 @@ namespace Swift {
 			Ui::QtHighlightEditor ui_;
 			QtSettingsProvider* settings_;
 			HighlightManager* highlightManager_;
+			QtSuggestingJIDInput* jid_;
 		};
 
 }
-- 
cgit v0.10.2-6-g49f6