X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fignorelistmodel.cpp;h=17d122eeef8bd57480a1cca6c53a41f826c292b4;hb=921e54680da16fcf2adb7a90506875aceb6633a4;hp=ec09dec4e974d60bb93970f31f7757d70d3e7a1c;hpb=577206b749ceca0eac05320a7e93d5fe2308b011;p=quassel.git
diff --git a/src/qtui/settingspages/ignorelistmodel.cpp b/src/qtui/settingspages/ignorelistmodel.cpp
index ec09dec4..17d122ee 100644
--- a/src/qtui/settingspages/ignorelistmodel.cpp
+++ b/src/qtui/settingspages/ignorelistmodel.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2005-09 by the Quassel Project *
+ * Copyright (C) 2005-2015 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -15,7 +15,7 @@
* 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 "ignorelistmodel.h"
@@ -28,252 +28,300 @@
#include "signalproxy.h"
IgnoreListModel::IgnoreListModel(QObject *parent)
- : QAbstractItemModel(parent),
+ : QAbstractItemModel(parent),
_configChanged(false),
_modelReady(false)
{
- // we need this signal for future connects to reset the data;
- connect(Client::instance(), SIGNAL(connected()), this, SLOT(clientConnected()));
- connect(Client::instance(), SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
-
- if(Client::isConnected())
- clientConnected();
- else
- emit modelReady(false);
+ // we need this signal for future connects to reset the data;
+ connect(Client::instance(), SIGNAL(connected()), this, SLOT(clientConnected()));
+ connect(Client::instance(), SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
+
+ if (Client::isConnected())
+ clientConnected();
+ else
+ emit modelReady(false);
}
-QVariant IgnoreListModel::data(const QModelIndex &index, int role) const {
- if(!_modelReady)
- return QVariant();
-
- if(!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount())
- return QVariant();
- switch(role) {
- case Qt::ToolTipRole:
- switch(index.column()) {
- /*
- case 0: return "Type:
"
- "BySender:
"
- "The ignore rule is matched against the nick!ident@host.mask sender-string.
"
- "ByMessage:
"
- "The ignore rule is matched against the message content.";
- case 1:
- return "Strictness:
"
- "Dynamic:
"
- "Messages are hidden but still get stored in the database.
Deactivate or delete an ignore rule to show the messages again
"
- "Permanent:
"
- "Messages are never stored or shown anywhere.";
- */
- case 0:
- return tr("Enable / Disable:
"
- "Only enabled rules are filtered.
"
- "For dynamic rules, disabling actually shows the filtered messages again");
- case 2:
- return tr("Ignore rule:
"
- "Depending on the type of the rule, the text is matched against either:
"
- "- the message content:
"
- "Example:
"
- " \"*foobar*\" matches any text containing the word \"foobar\"
"
- "- the sender string nick!ident@host.name
"
- "Example:
"
- " \"*@foobar.com\" matches any sender from host foobar.com
"
- " \"stupid!.+\" (RegEx) matches any sender with nickname \"stupid\" from any host
");
+QVariant IgnoreListModel::data(const QModelIndex &index, int role) const
+{
+ if (!_modelReady)
+ return QVariant();
+
+ if (!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount())
+ return QVariant();
+
+ switch (role) {
+ case Qt::ToolTipRole:
+ switch (index.column()) {
+ /*
+ case 0: return "Type:
"
+ "BySender:
"
+ "The ignore rule is matched against the nick!ident@host.mask sender-string.
"
+ "ByMessage:
"
+ "The ignore rule is matched against the message content.";
+ case 1:
+ return "Strictness:
"
+ "Dynamic:
"
+ "Messages are hidden but still get stored in the database.
Deactivate or delete an ignore rule to show the messages again
"
+ "Permanent:
"
+ "Messages are never stored or shown anywhere.";
+ */
+ case 0:
+ return tr("Enable / Disable:
"
+ "Only enabled rules are filtered.
"
+ "For dynamic rules, disabling actually shows the filtered messages again");
+ case 2:
+ return tr("Ignore rule:
"
+ "Depending on the type of the rule, the text is matched against either:
"
+ "- the message content:
"
+ "Example:
"
+ " \"*foobar*\" matches any text containing the word \"foobar\"
"
+ "- the sender string nick!ident@host.name
"
+ "Example:
"
+ " \"*@foobar.com\" matches any sender from host foobar.com
"
+ " \"stupid!.+\" (RegEx) matches any sender with nickname \"stupid\" from any host
");
+ default:
+ return QVariant();
+ }
+ case Qt::DisplayRole:
+ switch (index.column()) {
+ case 1:
+ if (ignoreListManager()[index.row()].type == IgnoreListManager::SenderIgnore)
+ return tr("By Sender");
+ else
+ return tr("By Message");
+ }
+ case Qt::EditRole:
+ switch (index.column()) {
+ case 0:
+ return ignoreListManager()[index.row()].isActive;
+ case 1:
+ return ignoreListManager()[index.row()].type;
+ case 2:
+ return ignoreListManager()[index.row()].ignoreRule;
+ default:
+ return QVariant();
+ }
default:
- return QVariant();
+ return QVariant();
}
- case Qt::DisplayRole:
- switch(index.column()) {
- case 1:
- if(ignoreListManager()[index.row()].type == IgnoreListManager::SenderIgnore)
- return tr("By Sender");
- else
- return tr("By Message");
- }
- case Qt::EditRole:
- switch(index.column()) {
+}
+
+
+bool IgnoreListModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (!_modelReady)
+ return false;
+
+ if (!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount() || role != Qt::EditRole)
+ return false;
+
+ QVariant newValue = value;
+ if (newValue.isNull())
+ return false;
+
+ switch (index.column()) {
case 0:
- return ignoreListManager()[index.row()].isActive;
+ cloneIgnoreListManager()[index.row()].isActive = newValue.toBool();
+ return true;
case 1:
- return ignoreListManager()[index.row()].type;
+ cloneIgnoreListManager()[index.row()].type = (IgnoreListManager::IgnoreType)newValue.toInt();
+ return true;
case 2:
- return ignoreListManager()[index.row()].ignoreRule;
+ if (ignoreListManager().contains(newValue.toString())) {
+ return false;
+ }
+ else {
+ cloneIgnoreListManager()[index.row()].ignoreRule = newValue.toString();
+ return true;
+ }
default:
- return QVariant();
+ return false;
}
- default:
- return QVariant();
- }
}
-bool IgnoreListModel::setData(const QModelIndex &index, const QVariant &value, int role) {
- if(!_modelReady)
- return false;
- if(!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount() || role != Qt::EditRole)
- return false;
+bool IgnoreListModel::newIgnoreRule(const IgnoreListManager::IgnoreListItem &item)
+{
+ IgnoreListManager &manager = cloneIgnoreListManager();
+ if (manager.contains(item.ignoreRule))
+ return false;
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ // manager.addIgnoreListItem(item);
+ manager.addIgnoreListItem(item.type, item.ignoreRule, item.isRegEx, item.strictness, item.scope,
+ item.scopeRule, item.isActive);
+ endInsertRows();
+ return true;
+}
- QVariant newValue = value;
- if(newValue.isNull())
- return false;
- switch(index.column()) {
- case 0:
- cloneIgnoreListManager()[index.row()].isActive = newValue.toBool();
- return true;
- case 1:
- cloneIgnoreListManager()[index.row()].type = (IgnoreListManager::IgnoreType)newValue.toInt();
- return true;
- case 2:
- if(ignoreListManager().contains(newValue.toString())) {
- return false;
- } else {
- cloneIgnoreListManager()[index.row()].ignoreRule = newValue.toString();
- return true;
+void IgnoreListModel::loadDefaults()
+{
+ /*if(!_modelReady)
+ return;
+
+ IgnoreListManager &manager = cloneIgnoreListManager();
+
+ if(!manager.isEmpty()) {
+ beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
+ for(int i = rowCount() - 1; i >= 0; i--)
+ manager.removeAt(i);
+ endRemoveRows();
}
- default:
- return false;
- }
-}
-bool IgnoreListModel::newIgnoreRule(const IgnoreListManager::IgnoreListItem &item) {
- IgnoreListManager &manager = cloneIgnoreListManager();
- if(manager.contains(item.ignoreRule))
- return false;
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- manager.addIgnoreListItem(item);
- endInsertRows();
- return true;
+ IgnoreListManager::IgnoreList defaults = IgnoreListModel::defaults();
+ beginInsertRows(QModelIndex(), 0, defaults.count() - 1);
+ foreach(IgnoreListManager::IgnoreListItem item, defaults) {
+ manager.addIgnoreListItem(item.ignoreRule, item.isRegEx, item.strictness, item.scope, item.scopeRule);
+ }
+ endInsertRows();*/
}
-void IgnoreListModel::loadDefaults() {
- /*if(!_modelReady)
- return;
- IgnoreListManager &manager = cloneIgnoreListManager();
+void IgnoreListModel::removeIgnoreRule(int index)
+{
+ if (index < 0 || index >= rowCount())
+ return;
- if(!manager.isEmpty()) {
- beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
- for(int i = rowCount() - 1; i >= 0; i--)
- manager.removeAt(i);
+ IgnoreListManager &manager = cloneIgnoreListManager();
+ beginRemoveRows(QModelIndex(), index, index);
+ manager.removeAt(index);
endRemoveRows();
- }
-
- IgnoreListManager::IgnoreList defaults = IgnoreListModel::defaults();
- beginInsertRows(QModelIndex(), 0, defaults.count() - 1);
- foreach(IgnoreListManager::IgnoreListItem item, defaults) {
- manager.addIgnoreListItem(item.ignoreRule, item.isRegEx, item.strictness, item.scope, item.scopeRule);
- }
- endInsertRows();*/
}
-void IgnoreListModel::removeIgnoreRule(int index) {
- if(index < 0 || index >= rowCount())
- return;
- IgnoreListManager &manager = cloneIgnoreListManager();
- beginRemoveRows(QModelIndex(), index, index);
- manager.removeAt(index);
- endRemoveRows();
+Qt::ItemFlags IgnoreListModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid()) {
+ return Qt::ItemIsDropEnabled;
+ }
+ else {
+ return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
+ }
}
-Qt::ItemFlags IgnoreListModel::flags(const QModelIndex &index) const {
- if(!index.isValid()) {
- return Qt::ItemIsDropEnabled;
- } else {
- return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
- }
-}
+QVariant IgnoreListModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ QStringList header;
+ header << tr("Enabled")
+ << tr("Type")
+ << tr("Ignore Rule");
+
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
+ return header[section];
-QVariant IgnoreListModel::headerData(int section, Qt::Orientation orientation, int role) const {
- QStringList header;
- header << tr("Enabled")
- << tr("Type")
- << tr("Ignore Rule");
+ return QVariant();
+}
- if(orientation == Qt::Horizontal && role == Qt::DisplayRole)
- return header[section];
- return QVariant();
+QModelIndex IgnoreListModel::index(int row, int column, const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ if (row >= rowCount() || column >= columnCount())
+ return QModelIndex();
+
+ return createIndex(row, column);
}
-QModelIndex IgnoreListModel::index(int row, int column, const QModelIndex &parent) const {
- Q_UNUSED(parent);
- if(row >= rowCount() || column >= columnCount())
- return QModelIndex();
- return createIndex(row, column);
+const IgnoreListManager &IgnoreListModel::ignoreListManager() const
+{
+ if (_configChanged)
+ return _clonedIgnoreListManager;
+ else
+ return *Client::ignoreListManager();
}
-const IgnoreListManager &IgnoreListModel::ignoreListManager() const {
- if(_configChanged)
- return _clonedIgnoreListManager;
- else
- return *Client::ignoreListManager();
+IgnoreListManager &IgnoreListModel::ignoreListManager()
+{
+ if (_configChanged)
+ return _clonedIgnoreListManager;
+ else
+ return *Client::ignoreListManager();
}
-IgnoreListManager &IgnoreListModel::ignoreListManager() {
- if(_configChanged)
+
+IgnoreListManager &IgnoreListModel::cloneIgnoreListManager()
+{
+ if (!_configChanged) {
+ _clonedIgnoreListManager = *Client::ignoreListManager();
+ _configChanged = true;
+ emit configChanged(true);
+ }
return _clonedIgnoreListManager;
- else
- return *Client::ignoreListManager();
}
-IgnoreListManager &IgnoreListModel::cloneIgnoreListManager() {
- if(!_configChanged) {
- _clonedIgnoreListManager = *Client::ignoreListManager();
- _configChanged = true;
- emit configChanged(true);
- }
- return _clonedIgnoreListManager;
-}
-void IgnoreListModel::revert() {
- if(!_configChanged)
- return;
+void IgnoreListModel::revert()
+{
+ if (!_configChanged)
+ return;
- _configChanged = false;
- emit configChanged(false);
- reset();
+ _configChanged = false;
+ emit configChanged(false);
+ beginResetModel();
+ endResetModel();
}
-void IgnoreListModel::commit() {
- if(!_configChanged)
- return;
- Client::ignoreListManager()->requestUpdate(_clonedIgnoreListManager.toVariantMap());
- revert();
+void IgnoreListModel::commit()
+{
+ if (!_configChanged)
+ return;
+
+ Client::ignoreListManager()->requestUpdate(_clonedIgnoreListManager.toVariantMap());
+ revert();
}
-void IgnoreListModel::initDone() {
- _modelReady = true;
- reset();
- emit modelReady(true);
+
+void IgnoreListModel::initDone()
+{
+ _modelReady = true;
+ beginResetModel();
+ endResetModel();
+ emit modelReady(true);
}
-void IgnoreListModel::clientConnected() {
- connect(Client::ignoreListManager(), SIGNAL(updated()), SLOT(revert()));
- if(Client::ignoreListManager()->isInitialized())
- initDone();
- else
- connect(Client::ignoreListManager(), SIGNAL(initDone()), SLOT(initDone()));
+
+void IgnoreListModel::clientConnected()
+{
+ connect(Client::ignoreListManager(), SIGNAL(updated()), SLOT(revert()));
+ if (Client::ignoreListManager()->isInitialized())
+ initDone();
+ else
+ connect(Client::ignoreListManager(), SIGNAL(initDone()), SLOT(initDone()));
}
-void IgnoreListModel::clientDisconnected() {
- // clear
- _clonedIgnoreListManager = ClientIgnoreListManager();
- _modelReady = false;
- reset();
- emit modelReady(false);
+
+void IgnoreListModel::clientDisconnected()
+{
+ // clear
+ _clonedIgnoreListManager = ClientIgnoreListManager();
+ _modelReady = false;
+ beginResetModel();
+ endResetModel();
+ emit modelReady(false);
}
-const IgnoreListManager::IgnoreListItem &IgnoreListModel::ignoreListItemAt(int row) const {
- return ignoreListManager()[row];
+
+const IgnoreListManager::IgnoreListItem &IgnoreListModel::ignoreListItemAt(int row) const
+{
+ return ignoreListManager()[row];
}
+
+
// FIXME use QModelIndex?
-void IgnoreListModel::setIgnoreListItemAt(int row, const IgnoreListManager::IgnoreListItem &item) {
- cloneIgnoreListManager()[row] = item;
- emit dataChanged(createIndex(row, 0), createIndex(row, 2));
+void IgnoreListModel::setIgnoreListItemAt(int row, const IgnoreListManager::IgnoreListItem &item)
+{
+ cloneIgnoreListManager()[row] = item;
+ emit dataChanged(createIndex(row, 0), createIndex(row, 2));
+}
+
+
+const QModelIndex IgnoreListModel::indexOf(const QString &rule)
+{
+ return createIndex(ignoreListManager().indexOf(rule), 2);
}