summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-01-21 10:07:29 (GMT)
committerRichard Maudsley <richard.maudsley@isode.com>2014-01-21 10:07:29 (GMT)
commit5f187f420d69c264d6b36a5c32f003514ab45ed8 (patch)
treede7287247be6abe29df92a8a7f7d037246d0b6ab
parent1a08c7c69f46455d131362003b7a4fbdb6642510 (diff)
downloadswift-5f187f420d69c264d6b36a5c32f003514ab45ed8.zip
swift-5f187f420d69c264d6b36a5c32f003514ab45ed8.tar.bz2
UI tweaks.
Change-Id: Id6b5c793df039eb4a9ada11987ed825896cde194
-rw-r--r--Swift/QtUI/QtHighlightEditor.cpp61
1 files changed, 41 insertions, 20 deletions
diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp
index aabe7d2..7bb7736 100644
--- a/Swift/QtUI/QtHighlightEditor.cpp
+++ b/Swift/QtUI/QtHighlightEditor.cpp
@@ -58,11 +58,12 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare
/* we need to be notified if any of the state changes so that we can update our textual rule description */
connect(ui_.chatRadio, SIGNAL(clicked()), SLOT(widgetClick()));
connect(ui_.roomRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.nickIsKeyword, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.allMsgRadio, SIGNAL(clicked()), SLOT(widgetClick()));
connect(ui_.senderRadio, SIGNAL(clicked()), SLOT(widgetClick()));
connect(jid_, SIGNAL(textChanged(const QString&)), SLOT(widgetClick()));
connect(ui_.keywordRadio, SIGNAL(clicked()), SLOT(widgetClick()));
connect(ui_.keyword, SIGNAL(textChanged(const QString&)), SLOT(widgetClick()));
- connect(ui_.nickIsKeyword, SIGNAL(clicked()), SLOT(widgetClick()));
connect(ui_.matchWholeWords, SIGNAL(clicked()), SLOT(widgetClick()));
connect(ui_.matchCase, SIGNAL(clicked()), SLOT(widgetClick()));
connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
@@ -86,7 +87,7 @@ QtHighlightEditor::~QtHighlightEditor()
{
}
-std::string formatNaturalDescription(const HighlightRule& rule)
+std::string formatLongDescription(const HighlightRule& rule)
{
//This rule will match messages either in chats or in rooms if the sender
// is called 'Admin', and the message contains 'Urgent' (not case sensitive)
@@ -141,6 +142,32 @@ std::string formatNaturalDescription(const HighlightRule& rule)
return text;
}
+std::string formatShortDescription(const HighlightRule &rule)
+{
+ const std::string chatOrRoom = (rule.getMatchChat() ? "chat" : "room");
+
+ std::vector<std::string> senders = rule.getSenders();
+ std::vector<std::string> keywords = rule.getKeywords();
+
+ if (senders.empty() && keywords.empty() && !rule.getNickIsKeyword()) {
+ return std::string("All ") + chatOrRoom + " messages.";
+ }
+
+ if (rule.getNickIsKeyword()) {
+ return std::string("All ") + chatOrRoom + " messages that mention my name.";
+ }
+
+ if (!senders.empty()) {
+ return std::string("All ") + chatOrRoom + " messages from " + senders[0] + ".";
+ }
+
+ if (!keywords.empty()) {
+ return std::string("All ") + chatOrRoom + " messages mentioning the keyword '" + keywords[0] + "'.";
+ }
+
+ return "Unknown Rule";
+}
+
void QtHighlightEditor::show()
{
ui_.listWidget->clear();
@@ -148,7 +175,7 @@ void QtHighlightEditor::show()
highlightManager_->loadSettings();
foreach(const HighlightRule &rule, highlightManager_->getRules()) {
QListWidgetItem *item = new QListWidgetItem();
- item->setText(P2QSTRING(formatNaturalDescription(rule)));
+ item->setText(P2QSTRING(formatShortDescription(rule)));
ui_.listWidget->addItem(item);
}
@@ -166,14 +193,6 @@ void QtHighlightEditor::show()
void QtHighlightEditor::setHighlightManager(HighlightManager* highlightManager)
{
highlightManager_ = highlightManager;
-
- //itemModel_->setHighlightManager(highlightManager);
- //ui_.newButton->setEnabled(highlightManager != NULL);
-//
- //ui_.ruleWidget->setEnabled(false);
- //ui_.deleteButton->setEnabled(false);
- //ui_.moveUpButton->setEnabled(false);
- //ui_.moveDownButton->setEnabled(false);
}
void QtHighlightEditor::setContactSuggestions(const std::vector<Contact>& suggestions)
@@ -208,9 +227,11 @@ void QtHighlightEditor::soundCustomSelect()
void QtHighlightEditor::onNewButtonClicked()
{
int row = getSelectedRow() + 1;
- highlightManager_->insertRule(row, HighlightRule());
+ HighlightRule newRule;
+ newRule.setMatchChat(true);
+ highlightManager_->insertRule(row, newRule);
QListWidgetItem *item = new QListWidgetItem();
- item->setText("New rule");
+ item->setText(P2QSTRING(formatShortDescription(newRule)));
ui_.listWidget->insertItem(row, item);
selectRow(row);
}
@@ -249,7 +270,7 @@ void QtHighlightEditor::onCurrentRowChanged(int currentRow)
if (currentRow != -1) {
HighlightRule rule = highlightManager_->getRule(currentRow);
ruleToDialog(rule);
- ui_.ruleDescription->setText(P2QSTRING(formatNaturalDescription(rule)));
+ ui_.ruleDescription->setText(P2QSTRING(formatLongDescription(rule)));
}
/* grey the dialog if we have nothing selected */
@@ -312,15 +333,14 @@ void QtHighlightEditor::setChildWidgetStates()
void QtHighlightEditor::widgetClick()
{
+ setChildWidgetStates();
+
HighlightRule rule = ruleFromDialog();
- const std::string description = formatNaturalDescription(rule);
- ui_.ruleDescription->setText(P2QSTRING(description));
+ ui_.ruleDescription->setText(P2QSTRING(formatLongDescription(rule)));
if (ui_.listWidget->currentItem()) {
- ui_.listWidget->currentItem()->setText(P2QSTRING(description));
+ ui_.listWidget->currentItem()->setText(P2QSTRING(formatShortDescription(rule)));
}
-
- setChildWidgetStates();
}
void QtHighlightEditor::disableDialog()
@@ -369,6 +389,7 @@ void QtHighlightEditor::selectRow(int row)
ui_.listWidget->item(i)->setSelected(false);
}
}
+ ui_.listWidget->setCurrentRow(row);
}
int QtHighlightEditor::getSelectedRow() const
@@ -402,7 +423,7 @@ HighlightRule QtHighlightEditor::ruleFromDialog()
}
}
- if (ui_.nickIsKeyword->isChecked()) {
+ if (ui_.keywordRadio->isChecked()) {
QString keywordString = ui_.keyword->text();
if (!keywordString.isEmpty()) {
std::vector<std::string> keywords;