diff options
Diffstat (limited to 'Swift/QtUI/QtHighlightEditor.cpp')
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 170 |
1 files changed, 94 insertions, 76 deletions
diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index e59c747..0fdec97 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -57,8 +57,7 @@ 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_.chatAndRoomRadio, SIGNAL(clicked()), SLOT(widgetClick())); - connect(ui_.senderCheck, 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())); @@ -153,6 +152,9 @@ void QtHighlightEditor::show() selectRow(0); } + /* prepare default states */ + widgetClick(); + QWidget::show(); QWidget::activateWindow(); } @@ -212,7 +214,7 @@ void QtHighlightEditor::onNewButtonClicked() void QtHighlightEditor::onDeleteButtonClicked() { int selectedRow = getSelectedRow(); - assert(selectedRow > 0); + assert(selectedRow>=0 && selectedRow<ui_.listWidget->count()); delete ui_.listWidget->takeItem(selectedRow); highlightManager_->removeRule(selectedRow); } @@ -236,7 +238,9 @@ void QtHighlightEditor::onCurrentRowChanged(int currentRow) } /* grey the dialog if we have nothing selected */ - enableDialog(currentRow != -1); + if (currentRow == -1) { + disableDialog(); + } previousRow_ = currentRow; } @@ -258,15 +262,9 @@ void QtHighlightEditor::onOkButtonClick() close(); } -void QtHighlightEditor::widgetClick() +void QtHighlightEditor::setChildWidgetStates() { - HighlightRule rule = ruleFromDialog(); - const std::string description = formatNaturalDescription(rule); - ui_.ruleDescription->setText(P2QSTRING(description)); - - if (ui_.listWidget->currentItem()) { - ui_.listWidget->currentItem()->setText(P2QSTRING(description)); - } + /* disable appropriate radio button child widgets */ if (ui_.chatRadio->isChecked()) { if (ui_.nickIsKeyword->isChecked()) { @@ -279,47 +277,60 @@ void QtHighlightEditor::widgetClick() } else { /* chats and rooms */ ui_.nickIsKeyword->setEnabled(true); } + + if (ui_.senderRadio->isChecked()) { + jid_->setEnabled(true); + } else { + jid_->setEnabled(false); + } + + if (ui_.keywordRadio->isChecked()) { + ui_.keyword->setEnabled(true); + ui_.matchWholeWords->setEnabled(true); + ui_.matchCase->setEnabled(true); + } else { + ui_.keyword->setEnabled(false); + ui_.matchWholeWords->setEnabled(false); + ui_.matchCase->setEnabled(false); + } } -void QtHighlightEditor::enableDialog(bool state) +void QtHighlightEditor::widgetClick() { - if (!state) { /* also clear the value, if applicable */ - ui_.chatRadio->setChecked(true); - ui_.senderCheck->setChecked(false); - jid_->setText(""); - ui_.keywordRadio->setChecked(false); - ui_.keyword->setText(""); - ui_.nickIsKeyword->setChecked(false); - ui_.matchWholeWords->setChecked(false); - ui_.matchCase->setChecked(false); - ui_.noColorRadio->setChecked(true); - ui_.foregroundColor->setEnabled(state); - ui_.backgroundColor->setEnabled(state); - ui_.noSoundRadio->setChecked(true); - ui_.foregroundColor->setColor(QColor()); - ui_.backgroundColor->setColor(QColor()); - ui_.soundFile->setText(""); - ui_.foregroundColor->setEnabled(false); - ui_.backgroundColor->setEnabled(false); - ui_.soundFile->setEnabled(false); - ui_.soundFileButton->setEnabled(false); + HighlightRule rule = ruleFromDialog(); + const std::string description = formatNaturalDescription(rule); + ui_.ruleDescription->setText(P2QSTRING(description)); + + if (ui_.listWidget->currentItem()) { + ui_.listWidget->currentItem()->setText(P2QSTRING(description)); } - //ui_.chatCheck->setEnabled(state); - //ui_.roomCheck->setEnabled(state); - ui_.senderCheck->setEnabled(state); - jid_->setEnabled(state); - ui_.nickIsKeyword->setEnabled(state); - ui_.keyword->setEnabled(state); - ui_.nickIsKeyword->setEnabled(state); - ui_.matchWholeWords->setEnabled(state); - ui_.matchCase->setEnabled(state); - ui_.noColorRadio->setEnabled(state); - ui_.defaultColorRadio->setEnabled(state); - ui_.customColorRadio->setEnabled(state); - ui_.noSoundRadio->setEnabled(state); - ui_.defaultSoundRadio->setEnabled(state); - ui_.customSoundRadio->setEnabled(state); + setChildWidgetStates(); +} + +void QtHighlightEditor::disableDialog() +{ + /* TODO: check all of these */ + + ui_.chatRadio->setChecked(true); + ui_.senderRadio->setChecked(false); + jid_->setText(""); + ui_.keywordRadio->setChecked(false); + ui_.keyword->setText(""); + ui_.nickIsKeyword->setChecked(false); + ui_.matchWholeWords->setChecked(false); + ui_.matchCase->setChecked(false); + ui_.noColorRadio->setChecked(true); + ui_.foregroundColor->setEnabled(false); + ui_.backgroundColor->setEnabled(false); + ui_.noSoundRadio->setChecked(true); + ui_.foregroundColor->setColor(QColor()); + ui_.backgroundColor->setColor(QColor()); + ui_.soundFile->setText(""); + ui_.foregroundColor->setEnabled(false); + ui_.backgroundColor->setEnabled(false); + ui_.soundFile->setEnabled(false); + ui_.soundFileButton->setEnabled(false); } void QtHighlightEditor::handleContactSuggestionRequested(const QString& text) @@ -355,19 +366,14 @@ HighlightRule QtHighlightEditor::ruleFromDialog() HighlightRule rule; if (ui_.chatRadio->isChecked()) { - if (ui_.roomRadio->isChecked()) { - rule.setMatchChat(true); - rule.setMatchMUC(true); - } else { - rule.setMatchChat(true); - rule.setMatchMUC(false); - } + rule.setMatchChat(true); + rule.setMatchMUC(false); } else { rule.setMatchChat(false); rule.setMatchMUC(true); } - if (ui_.senderCheck->isChecked()) { + if (ui_.senderRadio->isChecked()) { QString senderName = jid_->text(); if (!senderName.isEmpty()) { std::vector<std::string> senders; @@ -420,35 +426,44 @@ HighlightRule QtHighlightEditor::ruleFromDialog() void QtHighlightEditor::ruleToDialog(const HighlightRule& rule) { - //ui_.chatCheck->setChecked(rule.getMatchChat()); - //ui_.roomCheck->setChecked(rule.getMatchMUC()); + ui_.chatRadio->setEnabled(true); + ui_.roomRadio->setEnabled(true); - std::vector<std::string> senders = rule.getSenders(); - if (senders.empty()) { - ui_.senderCheck->setChecked(false); - jid_->setEnabled(false); - jid_->setText(""); + if (rule.getMatchChat()) { + ui_.chatRadio->setChecked(true); + ui_.roomRadio->setChecked(false); } else { - ui_.senderCheck->setChecked(true); - jid_->setEnabled(true); + ui_.chatRadio->setChecked(false); + ui_.roomRadio->setChecked(true); + } + + ui_.allMsgRadio->setEnabled(true); + ui_.allMsgRadio->setChecked(true); /* this is the default radio button */ + jid_->setText(""); + ui_.matchWholeWords->setChecked(false); + ui_.matchCase->setChecked(false); + + ui_.nickIsKeyword->setEnabled(true); + if (rule.getNickIsKeyword()) { + ui_.nickIsKeyword->setChecked(true); + } + + ui_.senderRadio->setEnabled(true); + std::vector<std::string> senders = rule.getSenders(); + if (!senders.empty()) { + ui_.senderRadio->setChecked(true); jid_->setText(P2QSTRING(senders[0])); } + ui_.keywordRadio->setEnabled(true); std::vector<std::string> keywords = rule.getKeywords(); - if (keywords.empty()) { - ui_.nickIsKeyword->setChecked(false); - ui_.keyword->setEnabled(false); - ui_.keyword->setText(""); - } else { - ui_.nickIsKeyword->setChecked(true); - ui_.keyword->setEnabled(true); + if (!keywords.empty()) { + ui_.keywordRadio->setChecked(true); ui_.keyword->setText(P2QSTRING(keywords[0])); + ui_.matchWholeWords->setChecked(rule.getMatchWholeWords()); + ui_.matchCase->setChecked(rule.getMatchCase()); } - ui_.nickIsKeyword->setChecked(rule.getNickIsKeyword()); - ui_.matchWholeWords->setChecked(rule.getMatchWholeWords()); - ui_.matchCase->setChecked(rule.getMatchCase()); - const HighlightAction& action = rule.getAction(); if (action.highlightText()) { @@ -480,6 +495,9 @@ void QtHighlightEditor::ruleToDialog(const HighlightRule& rule) } else { ui_.noSoundRadio->setChecked(true); } + + /* set radio button child option states */ + setChildWidgetStates(); } } |