added custom highlighting (in the settings: behaviour -> highlight)
authorAlexander von Renteln <phon@quassel-irc.org>
Wed, 2 Apr 2008 14:53:30 +0000 (14:53 +0000)
committerAlexander von Renteln <phon@quassel-irc.org>
Wed, 2 Apr 2008 14:53:30 +0000 (14:53 +0000)
src/client/client.cpp
src/client/clientsettings.cpp
src/client/clientsettings.h
src/qtui/mainwin.cpp
src/qtui/settingspages/highlightsettingspage.cpp [new file with mode: 0644]
src/qtui/settingspages/highlightsettingspage.h [new file with mode: 0644]
src/qtui/settingspages/highlightsettingspage.ui [new file with mode: 0644]
src/qtui/settingspages/settingspages.pri
version.inc

index 7d4aeff..865855e 100644 (file)
@@ -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;
+      }
+    }
   }
 }
 
index f35420d..1c3c5cf 100644 (file)
@@ -98,10 +98,30 @@ QHash<int, BufferId> 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();
+}
index 919084e..ee0b0d2 100644 (file)
@@ -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
index b85671e..959cd9b 100644 (file)
@@ -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 (file)
index 0000000..09887ba
--- /dev/null
@@ -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 <QHeaderView>
+
+
+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<int> selectedRows;
+  QList<QTableWidgetItem *> selectedItemList = ui.highlightTable->selectedItems();
+  foreach(QTableWidgetItem *selectedItem, selectedItemList) {
+    selectedRows.append(selectedItem->row());
+  }
+  qSort(selectedRows.begin(), selectedRows.end(), qGreater<int>());
+  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 (file)
index 0000000..04dfd11
--- /dev/null
@@ -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 <QVariantList>
+#include <QTableWidgetItem>
+
+#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<QString, QVariant>:
+    //    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 (file)
index 0000000..3d83985
--- /dev/null
@@ -0,0 +1,88 @@
+<ui version="4.0" >
+ <class>HighlightSettingsPage</class>
+ <widget class="QWidget" name="HighlightSettingsPage" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>438</width>
+    <height>404</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" >
+   <item>
+    <widget class="QGroupBox" name="groupBox" >
+     <property name="title" >
+      <string>Highlight list</string>
+     </property>
+     <layout class="QGridLayout" >
+      <item rowspan="3" row="0" column="0" >
+       <widget class="QTableWidget" name="highlightTable" >
+        <property name="styleSheet" >
+         <string/>
+        </property>
+        <column>
+         <property name="text" >
+          <string>RexEx</string>
+         </property>
+        </column>
+        <column>
+         <property name="text" >
+          <string>Highlight</string>
+         </property>
+        </column>
+        <column>
+         <property name="text" >
+          <string>Enable</string>
+         </property>
+        </column>
+       </widget>
+      </item>
+      <item row="0" column="1" >
+       <widget class="QPushButton" name="add" >
+        <property name="text" >
+         <string>Add</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1" >
+       <widget class="QPushButton" name="remove" >
+        <property name="text" >
+         <string>Remove</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1" >
+       <spacer>
+        <property name="orientation" >
+         <enum>Qt::Vertical</enum>
+        </property>
+        <property name="sizeHint" >
+         <size>
+          <width>20</width>
+          <height>40</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QCheckBox" name="highlightCurrentNick" >
+     <property name="text" >
+      <string>Highlight current nick</string>
+     </property>
+     <property name="checked" >
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
index 4013905..3a15aed 100644 (file)
@@ -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 =
index 62f569f..5017273 100644 (file)
@@ -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;