diff options
author | Tobias Markmann <tm@ayena.de> | 2015-01-18 19:12:02 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2015-02-05 09:34:57 (GMT) |
commit | edfd69a55e4f52576ab58306da8a82b1df890d5f (patch) | |
tree | 3d2a72b1014d11435f0a5592984d2894441c97e8 | |
parent | 53c86d070255ae1a33b7a3642bb6eb9ce42e7f70 (diff) | |
download | swift-edfd69a55e4f52576ab58306da8a82b1df890d5f.zip swift-edfd69a55e4f52576ab58306da8a82b1df890d5f.tar.bz2 |
Add "Reset defaults" button to highlight editor window.
The button is only shown if the current rules are *not* the default
set of rules.
Test-Information:
Tested on Mac OS X 10.9.5.
Change-Id: Ibf1856af04c6bdacf6102d240e6fe5f6071cb46a
-rw-r--r-- | Swift/Controllers/HighlightAction.cpp | 34 | ||||
-rw-r--r-- | Swift/Controllers/HighlightAction.h | 5 | ||||
-rw-r--r-- | Swift/Controllers/HighlightManager.cpp | 11 | ||||
-rw-r--r-- | Swift/Controllers/HighlightManager.h | 5 | ||||
-rw-r--r-- | Swift/Controllers/HighlightRule.cpp | 38 | ||||
-rw-r--r-- | Swift/Controllers/HighlightRule.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 17 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.ui | 15 |
9 files changed, 112 insertions, 21 deletions
diff --git a/Swift/Controllers/HighlightAction.cpp b/Swift/Controllers/HighlightAction.cpp index 492d4d2..80d9d85 100644 --- a/Swift/Controllers/HighlightAction.cpp +++ b/Swift/Controllers/HighlightAction.cpp @@ -1,12 +1,18 @@ /* * Copyright (c) 2012 Maciej Niedzielski * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #include <Swift/Controllers/HighlightAction.h> namespace Swift { void HighlightAction::setHighlightAllText(bool highlightText) { @@ -22,7 +28,35 @@ void HighlightAction::setPlaySound(bool playSound) playSound_ = playSound; if (!playSound_) { soundFile_.clear(); } } +bool operator ==(HighlightAction const& a, HighlightAction const& b) { + if (a.highlightAllText() != b.highlightAllText()) { + return false; + } + + if (a.getTextColor() != b.getTextColor()) { + return false; + } + + if (a.getTextBackground() != b.getTextBackground()) { + return false; + } + + if (a.playSound() != b.playSound()) { + return false; + } + + if (a.getSoundFile() != b.getSoundFile()) { + return false; + } + + return true; +} + +bool operator !=(HighlightAction const& a, HighlightAction const& b) { + return !(a == b); +} + } diff --git a/Swift/Controllers/HighlightAction.h b/Swift/Controllers/HighlightAction.h index 8136c62..a9e0cee 100644 --- a/Swift/Controllers/HighlightAction.h +++ b/Swift/Controllers/HighlightAction.h @@ -2,13 +2,13 @@ * Copyright (c) 2012 Maciej Niedzielski * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -63,12 +63,15 @@ namespace Swift { std::string textBackground_; bool playSound_; std::string soundFile_; }; + bool operator ==(HighlightAction const& a, HighlightAction const& b); + bool operator !=(HighlightAction const& a, HighlightAction const& b); + template<class Archive> void HighlightAction::serialize(Archive& ar, const unsigned int /*version*/) { ar & highlightText_; ar & textColor_; ar & textBackground_; diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp index ee1e9ed..383f5df 100644 --- a/Swift/Controllers/HighlightManager.cpp +++ b/Swift/Controllers/HighlightManager.cpp @@ -2,13 +2,13 @@ * Copyright (c) 2012 Maciej Niedzielski * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <cassert> @@ -72,12 +72,13 @@ std::string HighlightManager::rulesToString() const std::vector<HighlightRule> HighlightManager::getDefaultRules() { std::vector<HighlightRule> rules; HighlightRule r; r.setMatchChat(true); r.getAction().setPlaySound(true); + r.setMatchWholeWords(true); rules.push_back(r); return rules; } HighlightRule HighlightManager::getRule(int index) const { @@ -133,7 +134,15 @@ void HighlightManager::loadSettings() Highlighter* HighlightManager::createHighlighter() { return new Highlighter(this); } +bool HighlightManager::isDefaultRulesList() const { + return getDefaultRules() == rules_->list_; +} + +void HighlightManager::resetToDefaultRulesList() { + rules_->list_ = getDefaultRules(); +} + } diff --git a/Swift/Controllers/HighlightManager.h b/Swift/Controllers/HighlightManager.h index 4d94bd2..d37643d 100644 --- a/Swift/Controllers/HighlightManager.h +++ b/Swift/Controllers/HighlightManager.h @@ -2,13 +2,13 @@ * Copyright (c) 2012 Maciej Niedzielski * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -45,12 +45,15 @@ namespace Swift { HighlightManager(SettingsProvider* settings); Highlighter* createHighlighter(); boost::shared_ptr<const HighlightManager::HighlightRulesList> getRules() const { return rules_; } + bool isDefaultRulesList() const; + void resetToDefaultRulesList(); + HighlightRule getRule(int index) const; void setRule(int index, const HighlightRule& rule); void insertRule(int index, const HighlightRule& rule); void removeRule(int index); void swapRules(const size_t first, const size_t second); void storeSettings(); diff --git a/Swift/Controllers/HighlightRule.cpp b/Swift/Controllers/HighlightRule.cpp index f1a7cef..40b7560 100644 --- a/Swift/Controllers/HighlightRule.cpp +++ b/Swift/Controllers/HighlightRule.cpp @@ -2,13 +2,13 @@ * Copyright (c) 2012 Maciej Niedzielski * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <algorithm> #include <boost/algorithm/string.hpp> @@ -146,7 +146,43 @@ void HighlightRule::setMatchMUC(bool matchMUC) bool HighlightRule::isEmpty() const { return senders_.empty() && keywords_.empty() && !nickIsKeyword_ && !matchChat_ && !matchMUC_ && action_.isEmpty(); } +bool operator ==(HighlightRule const& a, HighlightRule const& b) { + if (a.getSenders() != b.getSenders()) { + return false; + } + + if (a.getKeywords() != b.getKeywords()) { + return false; + } + + if (a.getNickIsKeyword() != b.getNickIsKeyword()) { + return false; + } + + if (a.getMatchChat() != b.getMatchChat()) { + return false; + } + + if (a.getMatchMUC() != b.getMatchMUC()) { + return false; + } + + if (a.getMatchCase() != b.getMatchCase()) { + return false; + } + + if (a.getMatchWholeWords() != b.getMatchWholeWords()) { + return false; + } + + if (a.getAction() != b.getAction()) { + return false; + } + + return true; +} + } diff --git a/Swift/Controllers/HighlightRule.h b/Swift/Controllers/HighlightRule.h index fdc6109..02b4864 100644 --- a/Swift/Controllers/HighlightRule.h +++ b/Swift/Controllers/HighlightRule.h @@ -2,13 +2,13 @@ * Copyright (c) 2012 Maciej Niedzielski * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -81,12 +81,14 @@ namespace Swift { bool matchChat_; bool matchMUC_; HighlightAction action_; }; + bool operator ==(HighlightRule const& a, HighlightRule const& b); + template<class Archive> void HighlightRule::serialize(Archive& ar, const unsigned int /*version*/) { ar & senders_; ar & keywords_; ar & nickIsKeyword_; diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index df9f6b2..c6e4319 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -2,13 +2,13 @@ * Copyright (c) 2012 Maciej Niedzielski * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <cassert> @@ -35,12 +35,13 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare connect(ui_.newButton, SIGNAL(clicked()), SLOT(onNewButtonClicked())); connect(ui_.deleteButton, SIGNAL(clicked()), SLOT(onDeleteButtonClicked())); connect(ui_.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(onApplyButtonClick())); connect(ui_.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(onCancelButtonClick())); connect(ui_.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(onOkButtonClick())); + connect(ui_.buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(onResetToDefaultRulesClicked())); connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(colorOtherSelect())); connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(colorCustomSelect())); connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect())); connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect())); @@ -119,12 +120,14 @@ void QtHighlightEditor::show() populateList(); if (ui_.listWidget->count()) { selectRow(0); } + updateResetToDefaultRulesVisibility(); + /* prepare default states */ widgetClick(); QWidget::show(); QWidget::activateWindow(); } @@ -243,12 +246,14 @@ void QtHighlightEditor::onCurrentRowChanged(int currentRow) /* grey the dialog if we have nothing selected */ if (currentRow == -1) { disableDialog(); } previousRow_ = currentRow; + + updateResetToDefaultRulesVisibility(); } void QtHighlightEditor::onApplyButtonClick() { selectRow(getSelectedRow()); /* force save */ highlightManager_->storeSettings(); @@ -347,12 +352,18 @@ void QtHighlightEditor::handleContactSuggestionRequested(const QString& text) void QtHighlightEditor::selectSoundFile() { QString path = QFileDialog::getOpenFileName(this, tr("Select sound file..."), QString(), "Sounds (*.wav)"); ui_.soundFile->setText(path); } +void QtHighlightEditor::onResetToDefaultRulesClicked() { + highlightManager_->resetToDefaultRulesList(); + populateList(); + updateResetToDefaultRulesVisibility(); +} + void QtHighlightEditor::handleOnUserSelected(const Contact::ref& contact) { /* this might seem like it should be standard behaviour for the suggesting input box, but is not desirable in all cases */ if (contact->jid.isValid()) { jid_->setText(P2QSTRING(contact->jid.toString())); } else { jid_->setText(P2QSTRING(contact->name)); @@ -536,7 +547,11 @@ void QtHighlightEditor::ruleToDialog(const HighlightRule& rule) } /* set radio button child option states */ setChildWidgetStates(); } +void QtHighlightEditor::updateResetToDefaultRulesVisibility() { + ui_.buttonBox->button(QDialogButtonBox::RestoreDefaults)->setVisible(!highlightManager_->isDefaultRulesList()); +} + } diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h index ad51820..bcceb72 100644 --- a/Swift/QtUI/QtHighlightEditor.h +++ b/Swift/QtUI/QtHighlightEditor.h @@ -2,13 +2,13 @@ * Copyright (c) 2012 Maciej Niedzielski * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2014 Isode Limited. + * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once @@ -48,20 +48,22 @@ namespace Swift { void onOkButtonClick(); void setChildWidgetStates(); void widgetClick(); void disableDialog(); void handleContactSuggestionRequested(const QString& text); void selectSoundFile(); + void onResetToDefaultRulesClicked(); private: void handleOnUserSelected(const Contact::ref& contact); void populateList(); void selectRow(int row); int getSelectedRow() const; HighlightRule ruleFromDialog(); void ruleToDialog(const HighlightRule& rule); + void updateResetToDefaultRulesVisibility(); Ui::QtHighlightEditor ui_; QtSettingsProvider* settings_; HighlightManager* highlightManager_; QtSuggestingJIDInput* jid_; int previousRow_; diff --git a/Swift/QtUI/QtHighlightEditor.ui b/Swift/QtUI/QtHighlightEditor.ui index 775771f..6d2338d 100644 --- a/Swift/QtUI/QtHighlightEditor.ui +++ b/Swift/QtUI/QtHighlightEditor.ui @@ -441,28 +441,15 @@ </widget> </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_9"> <item> - <spacer name="horizontalSpacer_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> <widget class="QDialogButtonBox" name="buttonBox"> <property name="standardButtons"> - <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set> </property> </widget> </item> </layout> </item> </layout> |