From: Alexander von Renteln Date: Wed, 2 Apr 2008 14:53:30 +0000 (+0000) Subject: added custom highlighting (in the settings: behaviour -> highlight) X-Git-Tag: 0.2.0-alpha5~33 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=7a814314a9bb879f3af6148ce74f31d6427650db added custom highlighting (in the settings: behaviour -> highlight) --- diff --git a/src/client/client.cpp b/src/client/client.cpp index 7d4aeff4..865855ec 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -543,11 +543,36 @@ AbstractUiMsg *Client::layoutMsg(const Message &msg) { } void Client::checkForHighlight(Message &msg) { + NotificationSettings notificationSettings; const Network *net = network(msg.bufferInfo().networkId()); if(net && !net->myNick().isEmpty()) { - QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(net->myNick()) + "(\\W.*)?$"); - if((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && !(msg.flags() & Message::Self) && nickRegExp.exactMatch(msg.text())) - msg.setFlags(msg.flags() | Message::Highlight); + if(notificationSettings.highlightCurrentNick()) { + QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(net->myNick()) + "(\\W.*)?$"); + if((msg.type() & (Message::Plain | Message::Notice | Message::Action)) + && !(msg.flags() & Message::Self) + && nickRegExp.exactMatch(msg.text())) { + msg.setFlags(msg.flags() | Message::Highlight); + return; + } + } + foreach(QVariant highlight, notificationSettings.highlightList()) { + QVariantMap highlightRule = highlight.toMap(); + if(!highlightRule["enable"].toBool()) + continue; + QString name = highlightRule["name"].toString(); + QRegExp userRegExp; + if(highlightRule["regex"].toBool()) { + userRegExp = QRegExp(name); + } else { + userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(name) + "(\\W.*)?$"); + } + if((msg.type() & (Message::Plain | Message::Notice | Message::Action)) + && !(msg.flags() & Message::Self) + && userRegExp.exactMatch(msg.text())) { + msg.setFlags(msg.flags() | Message::Highlight); + return; + } + } } } diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index f35420d0..1c3c5cf1 100644 --- a/src/client/clientsettings.cpp +++ b/src/client/clientsettings.cpp @@ -98,10 +98,30 @@ QHash CoreAccountSettings::jumpKeyMap() { } return keyMap; } - void CoreAccountSettings::removeAccount(AccountId id) { removeLocalKey(QString("%1").arg(id.toInt())); } +/***********************************************************************************************/ +// NotificationSettings: + +NotificationSettings::NotificationSettings() : ClientSettings("Notification") { +} + +void NotificationSettings::setHighlightList(const QVariantList &highlightList) { + setLocalValue("highlightList", highlightList); +} + +QVariantList NotificationSettings::highlightList() { + return localValue("highlightList").toList(); +} + +void NotificationSettings::setHighlightCurrentNick(const bool &highlightCurrentNick) { + setLocalValue("highlightCurrentNick", highlightCurrentNick); +} + +bool NotificationSettings::highlightCurrentNick() { + return localValue("highlightCurrentNick", true).toBool(); +} diff --git a/src/client/clientsettings.h b/src/client/clientsettings.h index 919084e8..ee0b0d2d 100644 --- a/src/client/clientsettings.h +++ b/src/client/clientsettings.h @@ -68,4 +68,16 @@ class CoreAccountSettings : public ClientSettings { QString _subgroup; }; +class NotificationSettings : public ClientSettings { + + public: + NotificationSettings(); + + void setHighlightList(const QVariantList &highlightList); + QVariantList highlightList(); + + void setHighlightCurrentNick(const bool &highlightCurrentNick); + bool highlightCurrentNick(); + +}; #endif diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index b85671e9..959cd9bd 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -50,6 +50,7 @@ #include "settingspages/colorsettingspage.h" #include "settingspages/fontssettingspage.h" #include "settingspages/generalsettingspage.h" +#include "settingspages/highlightsettingspage.h" #include "settingspages/identitiessettingspage.h" #include "settingspages/networkssettingspage.h" @@ -201,6 +202,7 @@ void MainWin::setupSettingsDlg() { settingsDlg->registerSettingsPage(new AppearanceSettingsPage(settingsDlg)); //General //Category: Behaviour settingsDlg->registerSettingsPage(new GeneralSettingsPage(settingsDlg)); + settingsDlg->registerSettingsPage(new HighlightSettingsPage(settingsDlg)); //Category: General settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg)); settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg)); diff --git a/src/qtui/settingspages/highlightsettingspage.cpp b/src/qtui/settingspages/highlightsettingspage.cpp new file mode 100644 index 00000000..09887ba7 --- /dev/null +++ b/src/qtui/settingspages/highlightsettingspage.cpp @@ -0,0 +1,195 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Highlight Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Highlight Public License for more details. * + * * + * You should have received a copy of the GNU Highlight 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. * + ***************************************************************************/ + +#include "highlightsettingspage.h" + +#include "qtui.h" +#include "uisettings.h" + +#include + + +HighlightSettingsPage::HighlightSettingsPage(QWidget *parent) + : SettingsPage(tr("Behaviour"), tr("Highlight"), parent) { + ui.setupUi(this); + ui.highlightTable->verticalHeader()->hide(); + ui.highlightTable->setShowGrid(false); + ui.highlightTable->setColumnWidth( 0, 50 ); + ui.highlightTable->setColumnWidth( 2, 50 ); + ui.highlightTable->horizontalHeader()->setResizeMode(0, QHeaderView::Fixed); + ui.highlightTable->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch); + ui.highlightTable->horizontalHeader()->setResizeMode(2, QHeaderView::Fixed); + + connect(ui.add, SIGNAL(clicked(bool)), this, SLOT(addNewRow())); + connect(ui.remove, SIGNAL(clicked(bool)), this, SLOT(removeSelectedRows())); + //TODO: search for a better signal (one that emits everytime a selection has been changed for one item) + connect(ui.highlightTable, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(selectRow(QTableWidgetItem *))); + + connect(ui.highlightCurrentNick, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.add, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); + connect(ui.remove, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); + connect(ui.highlightTable, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(tableChanged(QTableWidgetItem *))); +} + +bool HighlightSettingsPage::hasDefaults() const { + return true; +} + +void HighlightSettingsPage::defaults() { + ui.highlightCurrentNick->setChecked(true); + emptyTable(); + + widgetHasChanged(); +} + +void HighlightSettingsPage::addNewRow(bool regex, QString name, bool enable) { + ui.highlightTable->setRowCount(ui.highlightTable->rowCount()+1); + QTableWidgetItem *regexItem = new QTableWidgetItem(""); + if(regex) + regexItem->setCheckState(Qt::Checked); + else + regexItem->setCheckState(Qt::Unchecked); + regexItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable); + QTableWidgetItem *nameItem = new QTableWidgetItem(name); + QTableWidgetItem *enableItem = new QTableWidgetItem(""); + if(enable) + enableItem->setCheckState(Qt::Checked); + else + enableItem->setCheckState(Qt::Unchecked); + enableItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable); + + int lastRow = ui.highlightTable->rowCount()-1; + ui.highlightTable->setItem(lastRow, 0, regexItem); + ui.highlightTable->setItem(lastRow, 1, nameItem); + ui.highlightTable->setItem(lastRow, 2, enableItem); + + QVariantMap highlightRule; + highlightRule["regex"] = regex; + highlightRule["name"] = name; + highlightRule["enable"] = enable; + + highlightList.append(highlightRule); +} + +void HighlightSettingsPage::removeSelectedRows() { + QList selectedRows; + QList selectedItemList = ui.highlightTable->selectedItems(); + foreach(QTableWidgetItem *selectedItem, selectedItemList) { + selectedRows.append(selectedItem->row()); + } + qSort(selectedRows.begin(), selectedRows.end(), qGreater()); + int lastRow = -1; + foreach(int row, selectedRows) { + if(row != lastRow) { + ui.highlightTable->removeRow(row); + highlightList.removeAt(row); + } + lastRow = row; + } +} + +void HighlightSettingsPage::selectRow(QTableWidgetItem *item) { + int row = item->row(); + bool selected = item->isSelected(); + ui.highlightTable->setRangeSelected(QTableWidgetSelectionRange(row, 0, row, 2), selected); +} + +void HighlightSettingsPage::emptyTable() { + // ui.highlight and highlightList should have the same size, but just to make sure. + if(ui.highlightTable->rowCount() != highlightList.size()) { + qDebug() << "something is wrong: ui.highlight and highlightList don't have the same size!"; + } + while(ui.highlightTable->rowCount()) { + ui.highlightTable->removeRow(0); + } + while(highlightList.size()) { + highlightList.removeLast(); + } +} + +void HighlightSettingsPage::tableChanged(QTableWidgetItem *item) { + if(item->row()+1 > highlightList.size()) + return; + + QVariantMap highlightRule = highlightList.value(item->row()).toMap(); + + switch(item->column()) + { + case 0: + highlightRule["regex"] = (item->checkState() == Qt::Checked); + break; + case 1: + if(item->text() == "") + item->setText(tr("this shouldn't be empty")); + highlightRule["name"] = item->text(); + break; + case 2: + highlightRule["enable"] = (item->checkState() == Qt::Checked); + break; + } + highlightList[item->row()] = highlightRule; + emit widgetHasChanged(); +} + +void HighlightSettingsPage::load() { + NotificationSettings notificationSettings; + + emptyTable(); + + foreach(QVariant highlight, notificationSettings.highlightList()) { + QVariantMap highlightRule = highlight.toMap(); + bool regex = highlightRule["regex"].toBool(); + QString name = highlightRule["name"].toString(); + bool enable = highlightRule["enable"].toBool(); + + addNewRow(regex, name, enable); + } + + ui.highlightCurrentNick->setChecked(notificationSettings.highlightCurrentNick()); + + setChangedState(false); +} + +void HighlightSettingsPage::save() { + NotificationSettings notificationSettings; + notificationSettings.setHighlightList(highlightList); + notificationSettings.setHighlightCurrentNick(ui.highlightCurrentNick->isChecked()); + + load(); + setChangedState(false); +} + +void HighlightSettingsPage::widgetHasChanged() { + bool changed = testHasChanged(); + if(changed != hasChanged()) setChangedState(changed); +} + +bool HighlightSettingsPage::testHasChanged() { + NotificationSettings notificationSettings; + + if(notificationSettings.highlightCurrentNick() != ui.highlightCurrentNick->isChecked()) return true; + if(notificationSettings.highlightList() != highlightList) return true; + + return true; +} + + + + diff --git a/src/qtui/settingspages/highlightsettingspage.h b/src/qtui/settingspages/highlightsettingspage.h new file mode 100644 index 00000000..04dfd117 --- /dev/null +++ b/src/qtui/settingspages/highlightsettingspage.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Highlight Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Highlight Public License for more details. * + * * + * You should have received a copy of the GNU Highlight 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. * + ***************************************************************************/ + +#ifndef _HIGHLIGHTSETTINGSPAGE_H_ +#define _HIGHLIGHTSETTINGSPAGE_H_ + +#include +#include + +#include "settingspage.h" +#include "ui_highlightsettingspage.h" + +class HighlightSettingsPage : public SettingsPage { + Q_OBJECT + + public: + HighlightSettingsPage(QWidget *parent = 0); + + bool hasDefaults() const; + + public slots: + void save(); + void load(); + void defaults(); + + private slots: + void widgetHasChanged(); + void addNewRow(bool regex = false, QString name = tr("highlight rule"), bool enable = true); + void removeSelectedRows(); + void selectRow(QTableWidgetItem *item); + void tableChanged(QTableWidgetItem *item); + + private: + Ui::HighlightSettingsPage ui; + QVariantList highlightList; + // QVariant -> QHash: + // regex: bool + // name: QString + // enable: bool + + void emptyTable(); + + bool testHasChanged(); +}; + +#endif diff --git a/src/qtui/settingspages/highlightsettingspage.ui b/src/qtui/settingspages/highlightsettingspage.ui new file mode 100644 index 00000000..3d83985d --- /dev/null +++ b/src/qtui/settingspages/highlightsettingspage.ui @@ -0,0 +1,88 @@ + + HighlightSettingsPage + + + + 0 + 0 + 438 + 404 + + + + Form + + + + + + Highlight list + + + + + + + + + + RexEx + + + + + Highlight + + + + + Enable + + + + + + + + Add + + + + + + + Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Highlight current nick + + + true + + + + + + + + diff --git a/src/qtui/settingspages/settingspages.pri b/src/qtui/settingspages/settingspages.pri index 40139052..3a15aed6 100644 --- a/src/qtui/settingspages/settingspages.pri +++ b/src/qtui/settingspages/settingspages.pri @@ -1,6 +1,6 @@ # Putting $FOO in SETTINGSPAGES automatically includes # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui -SETTINGSPAGES = appearance bufferview color fonts general identities networks +SETTINGSPAGES = appearance bufferview color fonts general highlight identities networks # Specify additional files (e.g. for subdialogs) here! SP_SRCS = diff --git a/version.inc b/version.inc index 62f569fa..5017273c 100644 --- a/version.inc +++ b/version.inc @@ -5,7 +5,7 @@ quasselVersion = "0.2.0-alpha5-pre"; quasselDate = "2008-04-01"; - quasselBuild = 684; + quasselBuild = 685; //! Minimum client build number the core needs clientBuildNeeded = 642;