The context menu "hide events" in the bufferviews are now working.
authorMarcus Eggenberger <egs@quassel-irc.org>
Fri, 24 Oct 2008 11:59:06 +0000 (13:59 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Fri, 24 Oct 2008 11:59:06 +0000 (13:59 +0200)
This is currently on a per buffer basis as default settings require a new settings page (lazy me...)
Disabled Indexing of the GraphicsScene again and I intend to leave it that way until my BR @ Qt (which I yet need to file... (lazy me...)) is fixed.

12 files changed:
src/client/buffersettings.cpp
src/client/buffersettings.h
src/client/clientsettings.cpp
src/client/clientsettings.h
src/client/messagefilter.cpp
src/client/messagefilter.h
src/common/settings.cpp
src/common/settings.h
src/qtui/chatline.cpp
src/qtui/chatscene.cpp
src/uisupport/bufferview.cpp
src/uisupport/bufferview.h

index eda1137..c42cd81 100644 (file)
 
 #include "buffersettings.h"
 
-BufferSettings::BufferSettings(const QString &group) : ClientSettings(group) {
+BufferSettings::BufferSettings(BufferId bufferId)
+  : ClientSettings(QString("Buffer/%1").arg(bufferId.toInt()))
+{
+}
+
+BufferSettings::BufferSettings(const QString &idString)
+  : ClientSettings(QString("Buffer/%1").arg(idString))
+{
+}
 
+bool BufferSettings::hasFilter() {
+  return localValue("hasMessageTypeFilter", false).toBool();
 }
 
-void BufferSettings::setValue(const QString &key, const QVariant &data) {
-  setLocalValue(key, data);
+int BufferSettings::messageFilter() {
+  return localValue("MessageTypeFilter", 0).toInt();
 }
 
-QVariant BufferSettings::value(const QString &key, const QVariant &def) {
-  return localValue(key, def);
+void BufferSettings::filterMessage(Message::Type msgType, bool filter) {
+  if(!hasFilter())
+    setLocalValue("hasMessageTypeFilter", true);
+  if(filter)
+    setLocalValue("MessageTypeFilter", localValue("MessageTypeFilter", 0).toInt() | msgType);
+  else
+    setLocalValue("MessageTypeFilter", localValue("MessageTypeFilter", 0).toInt() & ~msgType);
 }
index f4266a5..d60236d 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _BUFFERSETTINGS_H_
-#define _BUFFERSETTINGS_H_
+#ifndef BUFFERSETTINGS_H
+#define BUFFERSETTINGS_H
 
 #include "clientsettings.h"
+#include "message.h"
+#include "types.h"
 
 class BufferSettings : public ClientSettings {
+public:
+  BufferSettings(const QString &idString = "__default__");
+  BufferSettings(BufferId bufferId);
 
-  public:
-    BufferSettings(const QString &group = "Buffer");
-
-    void setValue(const QString &key, const QVariant &data);
-    QVariant value(const QString &key, const QVariant &def = QVariant());
-
+  inline void setValue(const QString &key, const QVariant &data) { setLocalValue(key, data); }
+  inline QVariant value(const QString &key, const QVariant &def = QVariant()) { return localValue(key, def); }
 
+  bool hasFilter();
+  int messageFilter();
+  void filterMessage(Message::Type msgType, bool filter);
 };
 
 
index 02a8c9c..9a05459 100644 (file)
@@ -32,8 +32,14 @@ ClientSettings::~ClientSettings() {
 
 /***********************************************************************************************/
 
-CoreAccountSettings::CoreAccountSettings(const QString &subgroup) : ClientSettings("CoreAccounts") {
-  _subgroup = subgroup;
+CoreAccountSettings::CoreAccountSettings(const QString &subgroup)
+  : ClientSettings("CoreAccounts"),
+    _subgroup(subgroup)
+{
+}
+
+void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) {
+  ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), receiver, slot);
 }
 
 QList<AccountId> CoreAccountSettings::knownAccounts() {
index 01353d7..f3ac247 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _CLIENTSETTINGS_H_
-#define _CLIENTSETTINGS_H_
+#ifndef CLIENTSETTINGS_H
+#define CLIENTSETTINGS_H
 
 #include "settings.h"
 #include "types.h"
 
 class ClientSettings : public Settings {
+public:
+  virtual ~ClientSettings();
 
-  public:
-    virtual ~ClientSettings();
-
-  protected:
-    ClientSettings(QString group = "General");
-
+protected:
+  ClientSettings(QString group = "General");
 };
 
 // Deriving from CoreAccountSettings:
@@ -42,30 +40,31 @@ class ClientSettings : public Settings {
 // Note that you'll get invalid data (and setting is ignored) if you are not connected to a core!
 
 class CoreAccountSettings : public ClientSettings {
+public:
+  // stores account-specific data in CoreAccounts/$ACCID/$SUBGROUP/$KEY)
+  CoreAccountSettings(const QString &subgroup = "General");
 
-  public:
-    // stores account-specific data in CoreAccounts/$ACCID/$SUBGROUP/$KEY)
-    CoreAccountSettings(const QString &subgroup = "General");
+  virtual void notify(const QString &key, QObject *receiver, const char *slot);
 
-    QList<AccountId> knownAccounts();
-    AccountId lastAccount();
-    void setLastAccount(AccountId);
-    AccountId autoConnectAccount();
-    void setAutoConnectAccount(AccountId);
+  QList<AccountId> knownAccounts();
+  AccountId lastAccount();
+  void setLastAccount(AccountId);
+  AccountId autoConnectAccount();
+  void setAutoConnectAccount(AccountId);
 
-    void storeAccountData(AccountId id, const QVariantMap &data);
-    QVariantMap retrieveAccountData(AccountId);
-    void removeAccount(AccountId);
+  void storeAccountData(AccountId id, const QVariantMap &data);
+  QVariantMap retrieveAccountData(AccountId);
+  void removeAccount(AccountId);
 
-    void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
-    QHash<int, BufferId> jumpKeyMap();
+  void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
+  QHash<int, BufferId> jumpKeyMap();
 
-  protected:
-    void setAccountValue(const QString &key, const QVariant &data);
-    QVariant accountValue(const QString &key, const QVariant &def = QVariant());
+protected:
+  void setAccountValue(const QString &key, const QVariant &data);
+  QVariant accountValue(const QString &key, const QVariant &def = QVariant());
 
-  private:
-    QString _subgroup;
+private:
+  QString _subgroup;
 };
 
 class NotificationSettings : public ClientSettings {
index c1253da..3ef02ee 100644 (file)
  ***************************************************************************/
 
 #include "messagefilter.h"
+#include "buffersettings.h"
 
 MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent)
-  : QSortFilterProxyModel(parent)
+  : QSortFilterProxyModel(parent),
+    _messageTypeFilter(0)
 {
+  init();
   setSourceModel(source);
 }
 
 MessageFilter::MessageFilter(MessageModel *source, const QList<BufferId> &buffers, QObject *parent)
   : QSortFilterProxyModel(parent),
-    _validBuffers(buffers.toSet())
+    _validBuffers(buffers.toSet()),
+    _messageTypeFilter(0)
 {
+  init();
   setSourceModel(source);
 }
 
+void MessageFilter::init() {
+  BufferSettings defaultSettings;
+  _messageTypeFilter = defaultSettings.messageFilter();
+  defaultSettings.notify("MessageTypeFilter", this, SLOT(messageTypeFilterChanged()));
+
+  BufferSettings mySettings(idString());
+  if(mySettings.hasFilter())
+    _messageTypeFilter = mySettings.messageFilter();
+  mySettings.notify("MessageTypeFilter", this, SLOT(messageTypeFilterChanged()));
+}
+
+void MessageFilter::messageTypeFilterChanged() {
+  int newFilter;
+  BufferSettings defaultSettings();
+  newFilter = BufferSettings().messageFilter();
+
+  BufferSettings mySettings(idString());
+  if(mySettings.hasFilter())
+    newFilter = mySettings.messageFilter();
+
+  if(_messageTypeFilter != newFilter) {
+    _messageTypeFilter = newFilter;
+    invalidateFilter();
+  }
+}
+
 QString MessageFilter::idString() const {
   if(_validBuffers.isEmpty())
     return "*";
@@ -49,10 +80,14 @@ QString MessageFilter::idString() const {
 
 bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
   Q_UNUSED(sourceParent);
+  QModelIndex sourceIdx = sourceModel()->index(sourceRow, 0);
+  if(_messageTypeFilter & sourceModel()->data(sourceIdx, MessageModel::TypeRole).toInt())
+    return false;
+
   if(_validBuffers.isEmpty())
     return true;
 
-  BufferId id = sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::BufferIdRole).value<BufferId>();
+  BufferId id = sourceModel()->data(sourceIdx, MessageModel::BufferIdRole).value<BufferId>();
   if(!id.isValid()) {
     return true;
   }
index 09e64fc..8f2cc18 100644 (file)
@@ -40,8 +40,14 @@ public:
   inline bool isSingleBufferFilter() const { return _validBuffers.count() == 1; }
   inline bool containsBuffer(const BufferId &id) const { return _validBuffers.contains(id); }
 
+public slots:
+  void messageTypeFilterChanged();
+
 private:
+  void init();
+
   QSet<BufferId> _validBuffers;
+  int _messageTypeFilter;
 };
 
 #endif
index 83fb8fb..12f1f69 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <QSettings>
 #include <QStringList>
-#include <QDebug>
 
 #ifdef Q_WS_QWS
 #include <Qtopia>
index 08db0cd..8ccee16 100644 (file)
@@ -41,7 +41,7 @@ public:
   enum Mode { Default, Custom };
 
 public:
-  void notify(const QString &key, QObject *receiver, const char *slot);
+  virtual void notify(const QString &key, QObject *receiver, const char *slot);
 
 protected:
   inline Settings(QString group_, QString appName_) : group(group_), appName(appName_) {}
index 1ef2f37..ce208be 100644 (file)
@@ -172,14 +172,17 @@ void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
 
   // new line marker
   const QAbstractItemModel *model_ = model();
-  if(model_ && row() > 0) {
+  if(model_ && row() > 0  && chatScene()->isSingleBufferScene()) {
     QModelIndex prevRowIdx = model_->index(row() - 1, 0);
-    MsgId msgId = model_->data(prevRowIdx, MessageModel::MsgIdRole).value<MsgId>();
-    Message::Flags flags = (Message::Flags)model_->data(model_->index(row(), 0), MessageModel::FlagsRole).toInt();
+    MsgId prevMsgId = model_->data(prevRowIdx, MessageModel::MsgIdRole).value<MsgId>();
+    QModelIndex myIdx = model_->index(row(), 0);
+    MsgId myMsgId = model_->data(myIdx, MessageModel::MsgIdRole).value<MsgId>();
+    Message::Flags flags = (Message::Flags)model_->data(myIdx, MessageModel::FlagsRole).toInt();
     // don't show the marker if we wrote that new line
     if(!(flags & Message::Self)) {
-      BufferId bufferId = model_->data(prevRowIdx, MessageModel::BufferIdRole).value<BufferId>();
-      if(msgId == Client::networkModel()->lastSeenMsgId(bufferId) && chatScene()->isSingleBufferScene()) {
+      BufferId bufferId = BufferId(chatScene()->idString().toInt());
+      MsgId lastSeenMsgId = Client::networkModel()->lastSeenMsgId(bufferId);
+      if(lastSeenMsgId < myMsgId && lastSeenMsgId >= prevMsgId) {
        QtUiStyleSettings s("Colors");
        QLinearGradient gradient(0, 0, 0, contentsItem().fontMetrics()->lineSpacing());
        gradient.setColorAt(0, s.value("newMsgMarkerFG", QColor(Qt::red)).value<QColor>());
index 41032f4..f71c857 100644 (file)
@@ -93,6 +93,8 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w
   webPreview.deleteTimer.setInterval(600000);
   connect(&webPreview.deleteTimer, SIGNAL(timeout()), this, SLOT(deleteWebPreviewEvent()));
 #endif
+
+  setItemIndexMethod(QGraphicsScene::NoIndex);
 }
 
 ChatScene::~ChatScene() {
@@ -302,7 +304,7 @@ void ChatScene::setWidth(qreal width) {
 
   // disabling the index while doing this complex updates is about
   // 2 to 10 times faster!
-  setItemIndexMethod(QGraphicsScene::NoIndex);
+  //setItemIndexMethod(QGraphicsScene::NoIndex);
 
   QList<ChatLine *>::iterator lineIter = _lines.end();
   QList<ChatLine *>::iterator lineIterBegin = _lines.begin();
@@ -312,7 +314,7 @@ void ChatScene::setWidth(qreal width) {
     lineIter--;
     (*lineIter)->setGeometryByWidth(width, contentsWidth, linePos);
   }
-  setItemIndexMethod(QGraphicsScene::BspTreeIndex);
+  //setItemIndexMethod(QGraphicsScene::BspTreeIndex);
 
   updateSceneRect(width);
   setHandleXLimits();
@@ -335,7 +337,7 @@ void ChatScene::firstHandlePositionChanged(qreal xpos) {
 
   // disabling the index while doing this complex updates is about
   // 2 to 10 times faster!
-  setItemIndexMethod(QGraphicsScene::NoIndex);
+  //setItemIndexMethod(QGraphicsScene::NoIndex);
 
   QList<ChatLine *>::iterator lineIter = _lines.end();
   QList<ChatLine *>::iterator lineIterBegin = _lines.begin();
@@ -347,7 +349,7 @@ void ChatScene::firstHandlePositionChanged(qreal xpos) {
     lineIter--;
     (*lineIter)->setFirstColumn(timestampWidth, senderWidth, senderPos);
   }
-  setItemIndexMethod(QGraphicsScene::BspTreeIndex);
+  //setItemIndexMethod(QGraphicsScene::BspTreeIndex);
 
   setHandleXLimits();
 
@@ -369,7 +371,7 @@ void ChatScene::secondHandlePositionChanged(qreal xpos) {
 
   // disabling the index while doing this complex updates is about
   // 2 to 10 times faster!
-  setItemIndexMethod(QGraphicsScene::NoIndex);
+  //setItemIndexMethod(QGraphicsScene::NoIndex);
 
   QList<ChatLine *>::iterator lineIter = _lines.end();
   QList<ChatLine *>::iterator lineIterBegin = _lines.begin();
@@ -381,7 +383,7 @@ void ChatScene::secondHandlePositionChanged(qreal xpos) {
     lineIter--;
     (*lineIter)->setSecondColumn(senderWidth, contentsWidth, contentsPos, linePos);
   }
-  setItemIndexMethod(QGraphicsScene::BspTreeIndex);
+  //setItemIndexMethod(QGraphicsScene::BspTreeIndex);
 
   setHandleXLimits();
 
index 5f33df4..11564b5 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "buffermodel.h"
 #include "bufferviewfilter.h"
+#include "buffersettings.h"
 #include "buffersyncer.h"
 #include "client.h"
 #include "iconloader.h"
@@ -61,22 +62,15 @@ BufferView::BufferView(QWidget *parent)
 
     _hideJoinAction(tr("Join Events"), this),
     _hidePartAction(tr("Part Events"), this),
-    _hideKillAction(tr("Kill Events"), this),
     _hideQuitAction(tr("Quit Events"), this),
     _hideModeAction(tr("Mode Events"), this)
 
 {
   _hideJoinAction.setCheckable(true);
   _hidePartAction.setCheckable(true);
-  _hideKillAction.setCheckable(true);
   _hideQuitAction.setCheckable(true);
   _hideModeAction.setCheckable(true);
-  _hideJoinAction.setEnabled(false);
-  _hidePartAction.setEnabled(false);
   _ignoreListAction.setEnabled(false);
-  _hideKillAction.setEnabled(false);
-  _hideQuitAction.setEnabled(false);
-  _hideModeAction.setEnabled(false);
 
   showChannelList.setIcon(SmallIcon("format-list-unordered"));
 
@@ -389,12 +383,16 @@ void BufferView::addSeparatorToMenu(QMenu &menu, const QModelIndex &index, ItemA
   }
 }
 
-QMenu *BufferView::createHideEventsSubMenu(QMenu &menu) {
-  // QMenu *hideEventsMenu = new QMenu(tr("Hide Events"), &menu);
+QMenu *BufferView::createHideEventsSubMenu(QMenu &menu, BufferId bufferId) {
+  int filter = BufferSettings(bufferId).messageFilter();
+  _hideJoinAction.setChecked(filter & Message::Join);
+  _hidePartAction.setChecked(filter & Message::Part);
+  _hideQuitAction.setChecked(filter & Message::Quit);
+  _hideModeAction.setChecked(filter & Message::Mode);
+  
   QMenu *hideEventsMenu = menu.addMenu(tr("Hide Events"));
   hideEventsMenu->addAction(&_hideJoinAction);
   hideEventsMenu->addAction(&_hidePartAction);
-  hideEventsMenu->addAction(&_hideKillAction);
   hideEventsMenu->addAction(&_hideQuitAction);
   hideEventsMenu->addAction(&_hideModeAction);
   return hideEventsMenu;
@@ -445,14 +443,14 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) {
        addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
        addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
        addItemToMenu(_removeBufferAction, contextMenu, index, InactiveState);
-       createHideEventsSubMenu(contextMenu);
+       createHideEventsSubMenu(contextMenu, bufferInfo.bufferId());
        addItemToMenu(_ignoreListAction, contextMenu);
        break;
       case BufferInfo::QueryBuffer:
        addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
        addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
        addItemToMenu(_removeBufferAction, contextMenu);
-       createHideEventsSubMenu(contextMenu);
+       createHideEventsSubMenu(contextMenu, bufferInfo.bufferId());
        break;
       default:
        addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
@@ -526,6 +524,27 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) {
     return;
   }
 
+  if(result == & _hideJoinAction) {
+    BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
+    BufferSettings(bufferId).filterMessage(Message::Join, _hideJoinAction.isChecked());
+    return;
+  }
+  if(result == &_hidePartAction) {
+    BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
+    BufferSettings(bufferId).filterMessage(Message::Part, _hidePartAction.isChecked());
+    return;
+  }
+  if(result == &_hideQuitAction) {
+    BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
+    BufferSettings(bufferId).filterMessage(Message::Quit, _hideQuitAction.isChecked());
+    return;
+  }
+  if(result == &_hideModeAction) {
+    BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
+    BufferSettings(bufferId).filterMessage(Message::Mode, _hideModeAction.isChecked());
+    return;
+  }
+
 }
 
 void BufferView::wheelEvent(QWheelEvent* event) {
index 1005942..a8231d9 100644 (file)
@@ -101,7 +101,6 @@ private:
   
   QAction _hideJoinAction;
   QAction _hidePartAction;
-  QAction _hideKillAction;
   QAction _hideQuitAction;
   QAction _hideModeAction;
 
@@ -118,7 +117,7 @@ private:
                     ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
   void addSeparatorToMenu(QMenu &menu, const QModelIndex &index,
                          ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
-  QMenu *createHideEventsSubMenu(QMenu &menu);
+  QMenu *createHideEventsSubMenu(QMenu &menu, BufferId bufferId);
 };
 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferView::ItemActiveStates)