/***************************************************************************
- * Copyright (C) 2005-09 by the Quassel Project *
+ * Copyright (C) 2005-2018 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "ignorelistsettingspage.h"
+#include <QDebug>
+#include <QEvent>
#include <QHeaderView>
#include <QItemSelectionModel>
+#include <QMessageBox>
#include <QModelIndex>
#include <QPainter>
-#include <QMessageBox>
#include <QString>
-#include <QEvent>
-#include <QDebug>
-#include "iconloader.h"
-IgnoreListSettingsPage::IgnoreListSettingsPage(QWidget *parent)
+#include "expressionmatch.h"
+#include "icon.h"
+#include "util.h"
+
+IgnoreListSettingsPage::IgnoreListSettingsPage(QWidget* parent)
: SettingsPage(tr("IRC"), tr("Ignore List"), parent)
{
ui.setupUi(this);
_delegate = new IgnoreListDelegate(ui.ignoreListView);
- ui.newIgnoreRuleButton->setIcon(SmallIcon("list-add"));
- ui.deleteIgnoreRuleButton->setIcon(SmallIcon("edit-delete"));
- ui.editIgnoreRuleButton->setIcon(SmallIcon("configure"));
+ ui.newIgnoreRuleButton->setIcon(icon::get("list-add"));
+ ui.deleteIgnoreRuleButton->setIcon(icon::get("edit-delete"));
+ ui.editIgnoreRuleButton->setIcon(icon::get("configure"));
ui.ignoreListView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui.ignoreListView->setSelectionMode(QAbstractItemView::SingleSelection);
ui.ignoreListView->viewport()->setAttribute(Qt::WA_Hover);
ui.ignoreListView->viewport()->setMouseTracking(true);
- connect(ui.ignoreListView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(selectionChanged(const QItemSelection &, const QItemSelection &)));
- connect(ui.newIgnoreRuleButton, SIGNAL(clicked()), this, SLOT(newIgnoreRule()));
- connect(ui.deleteIgnoreRuleButton, SIGNAL(clicked()), this, SLOT(deleteSelectedIgnoreRule()));
- connect(ui.editIgnoreRuleButton, SIGNAL(clicked()), this, SLOT(editSelectedIgnoreRule()));
- connect(&_ignoreListModel, SIGNAL(configChanged(bool)), this, SLOT(setChangedState(bool)));
- connect(&_ignoreListModel, SIGNAL(modelReady(bool)), this, SLOT(enableDialog(bool)));
+ connect(ui.ignoreListView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &IgnoreListSettingsPage::selectionChanged);
+ connect(ui.newIgnoreRuleButton, &QAbstractButton::clicked, this, [this]() { newIgnoreRule(); });
+ connect(ui.deleteIgnoreRuleButton, &QAbstractButton::clicked, this, &IgnoreListSettingsPage::deleteSelectedIgnoreRule);
+ connect(ui.editIgnoreRuleButton, &QAbstractButton::clicked, this, &IgnoreListSettingsPage::editSelectedIgnoreRule);
+ connect(&_ignoreListModel, &IgnoreListModel::configChanged, this, &IgnoreListSettingsPage::setChangedState);
+ connect(&_ignoreListModel, &IgnoreListModel::modelReady, this, &IgnoreListSettingsPage::enableDialog);
enableDialog(_ignoreListModel.isReady());
}
-
IgnoreListSettingsPage::~IgnoreListSettingsPage()
{
delete _delegate;
}
-
void IgnoreListSettingsPage::load()
{
- if (_ignoreListModel.configChanged())
+ if (_ignoreListModel.hasConfigChanged())
_ignoreListModel.revert();
ui.ignoreListView->selectionModel()->reset();
ui.editIgnoreRuleButton->setEnabled(false);
}
-
void IgnoreListSettingsPage::defaults()
{
_ignoreListModel.loadDefaults();
}
-
void IgnoreListSettingsPage::save()
{
- if (_ignoreListModel.configChanged()) {
+ if (_ignoreListModel.hasConfigChanged()) {
_ignoreListModel.commit();
}
ui.ignoreListView->selectionModel()->reset();
ui.editIgnoreRuleButton->setEnabled(false);
}
-
void IgnoreListSettingsPage::enableDialog(bool enabled)
{
ui.newIgnoreRuleButton->setEnabled(enabled);
setEnabled(enabled);
}
-
-void IgnoreListSettingsPage::selectionChanged(const QItemSelection &selection, const QItemSelection &)
+void IgnoreListSettingsPage::selectionChanged(const QItemSelection& selection, const QItemSelection&)
{
bool state = !selection.isEmpty();
ui.deleteIgnoreRuleButton->setEnabled(state);
ui.editIgnoreRuleButton->setEnabled(state);
}
-
void IgnoreListSettingsPage::deleteSelectedIgnoreRule()
{
if (!ui.ignoreListView->selectionModel()->hasSelection())
_ignoreListModel.removeIgnoreRule(ui.ignoreListView->selectionModel()->selectedIndexes()[0].row());
}
-
-void IgnoreListSettingsPage::newIgnoreRule(QString rule)
+void IgnoreListSettingsPage::newIgnoreRule(const QString& rule)
{
IgnoreListManager::IgnoreListItem newItem = IgnoreListManager::IgnoreListItem();
- newItem.strictness = IgnoreListManager::SoftStrictness;
- newItem.scope = IgnoreListManager::GlobalScope;
- newItem.isRegEx = false;
- newItem.isActive = true;
+ newItem.setStrictness(IgnoreListManager::SoftStrictness);
+ newItem.setScope(IgnoreListManager::GlobalScope);
+ newItem.setIsRegEx(false);
+ newItem.setIsEnabled(true);
bool enableOkButton = false;
if (!rule.isEmpty()) {
// we're called from contextmenu
- newItem.ignoreRule = rule;
+ newItem.setContents(rule);
enableOkButton = true;
}
- IgnoreListEditDlg *dlg = new IgnoreListEditDlg(newItem, this, enableOkButton);
+ auto* dlg = new IgnoreListEditDlg(newItem, this, enableOkButton);
dlg->enableOkButton(enableOkButton);
while (dlg->exec() == QDialog::Accepted) {
if (!_ignoreListModel.newIgnoreRule(dlg->ignoreListItem())) {
if (QMessageBox::warning(this,
- tr("Rule already exists"),
- tr("There is already a rule\n\"%1\"\nPlease choose another rule.")
- .arg(dlg->ignoreListItem().ignoreRule),
- QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok)
+ tr("Rule already exists"),
+ tr("There is already a rule\n\"%1\"\nPlease choose another rule.").arg(dlg->ignoreListItem().contents()),
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Ok)
== QMessageBox::Cancel)
break;
dlg->deleteLater();
}
-
void IgnoreListSettingsPage::editSelectedIgnoreRule()
{
if (!ui.ignoreListView->selectionModel()->hasSelection())
}
}
-
-void IgnoreListSettingsPage::editIgnoreRule(const QString &ignoreRule)
+void IgnoreListSettingsPage::editIgnoreRule(const QString& ignoreRule)
{
ui.ignoreListView->selectionModel()->select(_ignoreListModel.indexOf(ignoreRule), QItemSelectionModel::Select);
- if (ui.ignoreListView->selectionModel()->hasSelection()) // && ui.ignoreListView->selectionModel()->selectedIndexes()[0].row() != -1)
+ if (ui.ignoreListView->selectionModel()->hasSelection()) // && ui.ignoreListView->selectionModel()->selectedIndexes()[0].row() != -1)
editSelectedIgnoreRule();
else
newIgnoreRule(ignoreRule);
}
-
/*
IgnoreListDelegate
*/
-void IgnoreListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+void IgnoreListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if (index.column() == 0) {
- QStyle *style = QApplication::style();
+ QStyle* style = QApplication::style();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
QStyleOptionButton opts;
opts.direction = option.direction;
opts.rect = option.rect;
- opts.rect.moveLeft(option.rect.center().rx()-10);
+ opts.rect.moveLeft(option.rect.center().rx() - 10);
opts.state = option.state;
opts.state |= index.data().toBool() ? QStyle::State_On : QStyle::State_Off;
style->drawControl(QStyle::CE_CheckBox, &opts, painter);
QStyledItemDelegate::paint(painter, option, index);
}
-
// provide interactivity for the checkboxes
-bool IgnoreListDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
- const QStyleOptionViewItem &option, const QModelIndex &index)
+bool IgnoreListDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
{
Q_UNUSED(option)
switch (event->type()) {
}
}
-
/*
IgnoreListEditDlg
*/
-IgnoreListEditDlg::IgnoreListEditDlg(const IgnoreListManager::IgnoreListItem &item, QWidget *parent, bool enabled)
- : QDialog(parent), _ignoreListItem(item), _hasChanged(enabled)
+IgnoreListEditDlg::IgnoreListEditDlg(const IgnoreListManager::IgnoreListItem& item, QWidget* parent, bool enabled)
+ : QDialog(parent)
+ , _ignoreListItem(item)
+ , _hasChanged(enabled)
{
ui.setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, false);
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
- ui.ignoreRuleLineEdit->setText(item.ignoreRule);
+ ui.ignoreRuleLineEdit->setText(item.contents());
- if (item.type == IgnoreListManager::MessageIgnore)
+ if (item.type() == IgnoreListManager::MessageIgnore)
ui.messageTypeButton->setChecked(true);
- else if (item.type == IgnoreListManager::CtcpIgnore)
+ else if (item.type() == IgnoreListManager::CtcpIgnore)
ui.ctcpTypeButton->setChecked(true);
else
ui.senderTypeButton->setChecked(true);
- ui.isRegExCheckBox->setChecked(item.isRegEx);
- ui.isActiveCheckBox->setChecked(item.isActive);
+ ui.isRegExCheckBox->setChecked(item.isRegEx());
+ ui.isActiveCheckBox->setChecked(item.isEnabled());
- if (item.strictness == IgnoreListManager::HardStrictness)
+ if (item.strictness() == IgnoreListManager::HardStrictness)
ui.permanentStrictnessButton->setChecked(true);
else
ui.dynamicStrictnessButton->setChecked(true);
- switch (item.scope) {
+ switch (item.scope()) {
case IgnoreListManager::NetworkScope:
ui.networkScopeButton->setChecked(true);
ui.scopeRuleTextEdit->setEnabled(true);
ui.scopeRuleTextEdit->setEnabled(false);
}
- if (item.scope == IgnoreListManager::GlobalScope)
+ if (item.scope() == IgnoreListManager::GlobalScope)
ui.scopeRuleTextEdit->clear();
else
- ui.scopeRuleTextEdit->setPlainText(item.scopeRule);
+ ui.scopeRuleTextEdit->setPlainText(item.scopeRule());
- connect(ui.ignoreRuleLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(widgetHasChanged()));
- connect(ui.scopeRuleTextEdit, SIGNAL(textChanged()), this, SLOT(widgetHasChanged()));
- connect(&_typeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(widgetHasChanged()));
- connect(&_strictnessButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(widgetHasChanged()));
- connect(&_scopeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(widgetHasChanged()));
- connect(ui.isRegExCheckBox, SIGNAL(stateChanged(int)), this, SLOT(widgetHasChanged()));
- connect(ui.isActiveCheckBox, SIGNAL(stateChanged(int)), this, SLOT(widgetHasChanged()));
+ connect(ui.ignoreRuleLineEdit, &QLineEdit::textChanged, this, &IgnoreListEditDlg::widgetHasChanged);
+ connect(ui.scopeRuleTextEdit, &QPlainTextEdit::textChanged, this, &IgnoreListEditDlg::widgetHasChanged);
+ connect(&_typeButtonGroup, selectOverload<int>(&QButtonGroup::buttonClicked), this, &IgnoreListEditDlg::widgetHasChanged);
+ connect(&_strictnessButtonGroup, selectOverload<int>(&QButtonGroup::buttonClicked), this, &IgnoreListEditDlg::widgetHasChanged);
+ connect(&_scopeButtonGroup, selectOverload<int>(&QButtonGroup::buttonClicked), this, &IgnoreListEditDlg::widgetHasChanged);
+ connect(ui.isRegExCheckBox, &QCheckBox::stateChanged, this, &IgnoreListEditDlg::widgetHasChanged);
+ connect(ui.isActiveCheckBox, &QCheckBox::stateChanged, this, &IgnoreListEditDlg::widgetHasChanged);
- connect(ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(aboutToAccept()));
+ connect(ui.buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &IgnoreListEditDlg::aboutToAccept);
widgetHasChanged();
}
-
void IgnoreListEditDlg::widgetHasChanged()
{
if (ui.messageTypeButton->isChecked())
- _clonedIgnoreListItem.type = IgnoreListManager::MessageIgnore;
+ _clonedIgnoreListItem.setType(IgnoreListManager::MessageIgnore);
else if (ui.ctcpTypeButton->isChecked())
- _clonedIgnoreListItem.type = IgnoreListManager::CtcpIgnore;
+ _clonedIgnoreListItem.setType(IgnoreListManager::CtcpIgnore);
else
- _clonedIgnoreListItem.type = IgnoreListManager::SenderIgnore;
+ _clonedIgnoreListItem.setType(IgnoreListManager::SenderIgnore);
if (ui.permanentStrictnessButton->isChecked())
- _clonedIgnoreListItem.strictness = IgnoreListManager::HardStrictness;
+ _clonedIgnoreListItem.setStrictness(IgnoreListManager::HardStrictness);
else
- _clonedIgnoreListItem.strictness = IgnoreListManager::SoftStrictness;
+ _clonedIgnoreListItem.setStrictness(IgnoreListManager::SoftStrictness);
if (ui.networkScopeButton->isChecked()) {
- _clonedIgnoreListItem.scope = IgnoreListManager::NetworkScope;
+ _clonedIgnoreListItem.setScope(IgnoreListManager::NetworkScope);
ui.scopeRuleTextEdit->setEnabled(true);
}
else if (ui.channelScopeButton->isChecked()) {
- _clonedIgnoreListItem.scope = IgnoreListManager::ChannelScope;
+ _clonedIgnoreListItem.setScope(IgnoreListManager::ChannelScope);
ui.scopeRuleTextEdit->setEnabled(true);
}
else {
- _clonedIgnoreListItem.scope = IgnoreListManager::GlobalScope;
+ _clonedIgnoreListItem.setScope(IgnoreListManager::GlobalScope);
ui.scopeRuleTextEdit->setEnabled(false);
}
- if (_clonedIgnoreListItem.scope == IgnoreListManager::GlobalScope) {
- _clonedIgnoreListItem.scopeRule = QString();
+ if (_clonedIgnoreListItem.scope() == IgnoreListManager::GlobalScope) {
+ _clonedIgnoreListItem.setScopeRule(QString());
}
else {
- QStringList text = ui.scopeRuleTextEdit->toPlainText().split(";", QString::SkipEmptyParts);
- QStringList::iterator it = text.begin();
- while (it != text.end()) {
- *it = it->trimmed();
- ++it;
- }
-
- _clonedIgnoreListItem.scopeRule = text.join("; ");
+ // Trim the resulting MultiWildcard expression
+ _clonedIgnoreListItem.setScopeRule(ExpressionMatch::trimMultiWildcardWhitespace(ui.scopeRuleTextEdit->toPlainText()));
}
- _clonedIgnoreListItem.ignoreRule = ui.ignoreRuleLineEdit->text();
- _clonedIgnoreListItem.isRegEx = ui.isRegExCheckBox->isChecked();
- _clonedIgnoreListItem.isActive = ui.isActiveCheckBox->isChecked();
+ _clonedIgnoreListItem.setContents(ui.ignoreRuleLineEdit->text());
+ _clonedIgnoreListItem.setIsRegEx(ui.isRegExCheckBox->isChecked());
+ _clonedIgnoreListItem.setIsEnabled(ui.isActiveCheckBox->isChecked());
- if (!_clonedIgnoreListItem.ignoreRule.isEmpty() && _clonedIgnoreListItem != _ignoreListItem)
+ if (!_clonedIgnoreListItem.contents().isEmpty() && _clonedIgnoreListItem != _ignoreListItem)
_hasChanged = true;
else
_hasChanged = false;
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(_hasChanged);
}
-
void IgnoreListEditDlg::enableOkButton(bool state)
{
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(state);