From c5569840d50b68a518d474917be804efc543c088 Mon Sep 17 00:00:00 2001 From: Sebastian Goth Date: Sun, 13 Sep 2009 15:27:21 +0200 Subject: [PATCH] Various ignorelist fixes - Now works even with KDE integration - Don't add empty rules - Don't leak memory --- .../settingspages/ignorelistsettingspage.cpp | 6 ++- src/uisupport/contextmenuactionprovider.cpp | 44 ++++++++++++++----- src/uisupport/contextmenuactionprovider.h | 1 + src/uisupport/networkmodelcontroller.cpp | 28 ++++++++---- 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/qtui/settingspages/ignorelistsettingspage.cpp b/src/qtui/settingspages/ignorelistsettingspage.cpp index 61f08645..d4963864 100644 --- a/src/qtui/settingspages/ignorelistsettingspage.cpp +++ b/src/qtui/settingspages/ignorelistsettingspage.cpp @@ -108,7 +108,11 @@ void IgnoreListSettingsPage::deleteSelectedIgnoreRule() { void IgnoreListSettingsPage::newIgnoreRule(QString rule) { IgnoreListManager::IgnoreListItem newItem = IgnoreListManager::IgnoreListItem(); + newItem.strictness = IgnoreListManager::SoftStrictness; + newItem.scope = IgnoreListManager::GlobalScope; + newItem.isRegEx = false; newItem.isActive = true; + bool enableOkButton = false; if(!rule.isEmpty()) { // we're called from contextmenu @@ -118,7 +122,6 @@ void IgnoreListSettingsPage::newIgnoreRule(QString rule) { IgnoreListEditDlg *dlg = new IgnoreListEditDlg(newItem, this, enableOkButton); dlg->enableOkButton(enableOkButton); - while(dlg->exec() == QDialog::Accepted) { if(!_ignoreListModel.newIgnoreRule(dlg->ignoreListItem())) { if(QMessageBox::warning(this, @@ -260,6 +263,7 @@ IgnoreListEditDlg::IgnoreListEditDlg(const IgnoreListManager::IgnoreListItem &it connect(ui.isActiveCheckBox, SIGNAL(stateChanged(int)), this, SLOT(widgetHasChanged())); connect(ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(aboutToAccept())); + widgetHasChanged(); } void IgnoreListEditDlg::widgetHasChanged() { diff --git a/src/uisupport/contextmenuactionprovider.cpp b/src/uisupport/contextmenuactionprovider.cpp index 03c2de60..fbe45415 100644 --- a/src/uisupport/contextmenuactionprovider.cpp +++ b/src/uisupport/contextmenuactionprovider.cpp @@ -125,6 +125,13 @@ ContextMenuActionProvider::ContextMenuActionProvider(QObject *parent) : NetworkM QMenu *ignoreMenu = new QMenu(); _nickIgnoreMenuAction = new Action(tr("Ignore"), 0); _nickIgnoreMenuAction->setMenu(ignoreMenu); + + // These are disabled actions used as descriptions + // They don't need any of the Action fancyness so we use plain QActions + _ignoreDescriptions << new QAction(tr("Add Ignore Rule"), this); + _ignoreDescriptions << new QAction(tr("Existing Rules"), this); + foreach(QAction *act, _ignoreDescriptions) + act->setEnabled(false); } ContextMenuActionProvider::~ContextMenuActionProvider() { @@ -136,6 +143,8 @@ ContextMenuActionProvider::~ContextMenuActionProvider() { _nickModeMenuAction->deleteLater(); _nickIgnoreMenuAction->menu()->deleteLater(); _nickIgnoreMenuAction->deleteLater(); + qDeleteAll(_ignoreDescriptions); + _ignoreDescriptions.clear(); } void ContextMenuActionProvider::addActions(QMenu *menu, BufferId bufId, QObject *receiver, const char *method) { @@ -398,35 +407,50 @@ void ContextMenuActionProvider::addIgnoreMenu(QMenu *menu, const QString &hostma // if we don't have the data, we skip actions where we would need it bool haveWhoData = !ident.isEmpty() && !host.isEmpty(); - - ignoreMenu->addAction(tr("Add Ignore Rule"))->setEnabled(false); + // add "Add Ignore Rule" description + ignoreMenu->addAction(_ignoreDescriptions.at(0)); if(haveWhoData) { - action(NickIgnoreUser)->setText(QString("*!%1@%2").arg(ident, host)); - action(NickIgnoreHost)->setText(QString("*!*@%1").arg(host)); - action(NickIgnoreDomain)->setText(domain.at(0) == '.' ? QString("*!%1@*%2").arg(ident, domain) - : QString("*!%1@%2").arg(ident, domain)); + QString text; + text = QString("*!%1@%2").arg(ident, host); + action(NickIgnoreUser)->setText(text); + action(NickIgnoreUser)->setProperty("ignoreRule", text); + + text = QString("*!*@%1").arg(host); + action(NickIgnoreHost)->setText(text); + action(NickIgnoreHost)->setProperty("ignoreRule", text); + + text = domain.at(0) == '.' ? QString("*!%1@*%2").arg(ident, domain) + : QString("*!%1@%2").arg(ident, domain); - if(!ignoreMap.contains(action(NickIgnoreUser)->text())) + action(NickIgnoreDomain)->setText(text); + action(NickIgnoreDomain)->setProperty("ignoreRule", text); + + if(!ignoreMap.contains(action(NickIgnoreUser)->property("ignoreRule").toString())) ignoreMenu->addAction(action(NickIgnoreUser)); - if(!ignoreMap.contains(action(NickIgnoreHost)->text())) + if(!ignoreMap.contains(action(NickIgnoreHost)->property("ignoreRule").toString())) ignoreMenu->addAction(action(NickIgnoreHost)); - if(!ignoreMap.contains(action(NickIgnoreDomain)->text())) + if(!ignoreMap.contains(action(NickIgnoreDomain)->property("ignoreRule").toString())) ignoreMenu->addAction(action(NickIgnoreDomain)); } + + action(NickIgnoreCustom)->setProperty("ignoreRule", hostmask); ignoreMenu->addAction(action(NickIgnoreCustom)); + ignoreMenu->addSeparator(); if(haveWhoData) { QMap::const_iterator ruleIter = ignoreMap.begin(); int counter = 0; if(!ignoreMap.isEmpty()) - ignoreMenu->addAction(tr("Existing Rules"))->setEnabled(false); + // add "Existing Rules" description + ignoreMenu->addAction(_ignoreDescriptions.at(1)); while(ruleIter != ignoreMap.constEnd()) { if(counter < 5) { ActionType type = static_cast(NickIgnoreToggleEnabled0 + counter*0x100000); Action *act = action(type); act->setText(ruleIter.key()); + act->setProperty("ignoreRule", ruleIter.key()); act->setChecked(ruleIter.value()); ignoreMenu->addAction(act); } diff --git a/src/uisupport/contextmenuactionprovider.h b/src/uisupport/contextmenuactionprovider.h index c6753fa6..5bd7f6d7 100644 --- a/src/uisupport/contextmenuactionprovider.h +++ b/src/uisupport/contextmenuactionprovider.h @@ -71,6 +71,7 @@ private: Action *_nickCtcpMenuAction; Action *_nickModeMenuAction; Action *_nickIgnoreMenuAction; + QList _ignoreDescriptions; }; #endif diff --git a/src/uisupport/networkmodelcontroller.cpp b/src/uisupport/networkmodelcontroller.cpp index cb882f81..588071c1 100644 --- a/src/uisupport/networkmodelcontroller.cpp +++ b/src/uisupport/networkmodelcontroller.cpp @@ -366,9 +366,6 @@ void NetworkModelController::handleNickAction(ActionType type, QAction *action) if(!bufferInfo.isValid()) continue; - // the validity of that cast is checked on contextmenu creation, take care - IrcUser *ircUser = qobject_cast(index.data(NetworkModel::IrcUserRole).value()); - switch(type) { case NickWhois: Client::userInput(bufferInfo, QString("/WHOIS %1 %1").arg(nick)); @@ -414,36 +411,51 @@ void NetworkModelController::handleNickAction(ActionType type, QAction *action) Client::userInput(bufferInfo, QString("/QUERY %1").arg(nick)); break; case NickIgnoreUser: + { + IrcUser *ircUser = qobject_cast(index.data(NetworkModel::IrcUserRole).value()); + if(!ircUser) + break; Client::ignoreListManager()->requestAddIgnoreListItem(IgnoreListManager::SenderIgnore, - action->text(), + action->property("ignoreRule").toString(), false, IgnoreListManager::SoftStrictness, IgnoreListManager::NetworkScope, ircUser->network()->networkName(), true); break; + } case NickIgnoreHost: + { + IrcUser *ircUser = qobject_cast(index.data(NetworkModel::IrcUserRole).value()); + if(!ircUser) + break; Client::ignoreListManager()->requestAddIgnoreListItem(IgnoreListManager::SenderIgnore, - action->text(), + action->property("ignoreRule").toString(), false, IgnoreListManager::SoftStrictness, IgnoreListManager::NetworkScope, ircUser->network()->networkName(), true); break; + } case NickIgnoreDomain: + { + IrcUser *ircUser = qobject_cast(index.data(NetworkModel::IrcUserRole).value()); + if(!ircUser) + break; Client::ignoreListManager()->requestAddIgnoreListItem(IgnoreListManager::SenderIgnore, - action->text(), + action->property("ignoreRule").toString(), false, IgnoreListManager::SoftStrictness, IgnoreListManager::NetworkScope, ircUser->network()->networkName(), true); break; + } case NickIgnoreCustom: // forward that to mainwin since we can access the settingspage only from there - emit showIgnoreList(ircUser->hostmask()); + emit showIgnoreList(action->property("ignoreRule").toString()); break; case NickIgnoreToggleEnabled0: case NickIgnoreToggleEnabled1: case NickIgnoreToggleEnabled2: case NickIgnoreToggleEnabled3: case NickIgnoreToggleEnabled4: - Client::ignoreListManager()->requestToggleIgnoreRule(action->text()); + Client::ignoreListManager()->requestToggleIgnoreRule(action->property("ignoreRule").toString()); break; default: qWarning() << "Unhandled nick action"; -- 2.20.1