chatmonitor shows own messages again (per default) (configurable via context menu)
authorMarcus Eggenberger <egs@quassel-irc.org>
Fri, 22 Aug 2008 14:23:36 +0000 (16:23 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Fri, 22 Aug 2008 14:23:36 +0000 (16:23 +0200)
src/qtui/chatmonitorfilter.cpp
src/qtui/chatmonitorfilter.h
src/qtui/chatmonitorview.cpp

index 6bec8c3..9817b9b 100644 (file)
 ChatMonitorFilter::ChatMonitorFilter(MessageModel *model, QObject *parent)
   : MessageFilter(model, parent)
 {
+  QtUiSettings qtUiSettings;
+  QString showFieldSettingId = QString("ChatView/%1/showFields").arg(idString());
+  QString showOwnMessagesSettingId = QString("ChatView/%1/showOwnMsgs").arg(idString());
+
+  _showFields = qtUiSettings.value(showFieldSettingId, AllFields).toInt();
+  _showOwnMessages = qtUiSettings.value(showOwnMessagesSettingId, true).toBool();
+  qtUiSettings.notify(showFieldSettingId, this, SLOT(showFieldsSettingsChanged(const QVariant &)));
+  qtUiSettings.notify(showOwnMessagesSettingId, this, SLOT(showOwnMessagesSettingChanged(const QVariant &)));
 }
 
 bool ChatMonitorFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
   Q_UNUSED(sourceParent)
 
   Message::Flags flags = (Message::Flags)sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::FlagsRole).toInt();
-  if(flags & Message::Backlog || flags & Message::Self)
+  if(flags & Message::Backlog || (!_showOwnMessages && flags & Message::Self))
     return false;
 
   Message::Type type = (Message::Type)sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::TypeRole).toInt();
@@ -49,8 +57,6 @@ QVariant ChatMonitorFilter::data(const QModelIndex &index, int role) const {
   if(index.column() != ChatLineModel::SenderColumn || role != ChatLineModel::DisplayRole)
     return MessageFilter::data(index, role);
 
-  int showFields_ = showFields();
-
   BufferId bufid = data(index, ChatLineModel::BufferIdRole).value<BufferId>();
   if(!bufid.isValid()) {
     qDebug() << "ChatMonitorFilter::data(): chatline belongs to an invalid buffer!";
@@ -60,10 +66,10 @@ QVariant ChatMonitorFilter::data(const QModelIndex &index, int role) const {
   QModelIndex source_index = mapToSource(index);
 
   QStringList fields;
-  if(showFields_ & NetworkField) {
+  if(_showFields & NetworkField) {
     fields << Client::networkModel()->networkName(bufid);
   }
-  if(showFields_ & BufferField) {
+  if(_showFields & BufferField) {
     fields << Client::networkModel()->bufferName(bufid);
   }
 
@@ -77,28 +83,33 @@ QVariant ChatMonitorFilter::data(const QModelIndex &index, int role) const {
 }
 
 void ChatMonitorFilter::addShowField(int field) {
-  QtUiSettings s;
-  int fields = s.value(showFieldSettingId(), AllFields).toInt();
-  if(fields & field)
+  if(_showFields & field)
     return;
 
-  fields |= field;
-  s.setValue(showFieldSettingId(), fields);
-  showFieldSettingsChanged();
+  QtUiSettings().setValue(QString("ChatView/%1/showFields").arg(idString()), _showFields | field); 
 }
 
 void ChatMonitorFilter::removeShowField(int field) {
-  QtUiSettings s;
-  int fields = s.value(showFieldSettingId(), AllFields).toInt();
-  if(!(fields & field))
+  if(!(_showFields & field))
+    return;
+
+  QtUiSettings().setValue(QString("ChatView/%1/showFields").arg(idString()), _showFields ^ field);
+}
+
+void ChatMonitorFilter::setShowOwnMessages(bool show) {
+  if(_showOwnMessages == show)
     return;
 
-  fields ^= field;
-  s.setValue(showFieldSettingId(), fields);
-  showFieldSettingsChanged();
+  QtUiSettings().setValue(QString("ChatView/%1/showOwnMsgs").arg(idString()), show);
 }
 
-void ChatMonitorFilter::showFieldSettingsChanged() {
+void ChatMonitorFilter::showFieldsSettingsChanged(const QVariant &newValue) {
+  int newFields = newValue.toInt();
+  if(_showFields == newFields)
+    return;
+
+  _showFields = newFields;
+  
   int rows = rowCount();
   if(rows == 0)
     return;
@@ -106,3 +117,6 @@ void ChatMonitorFilter::showFieldSettingsChanged() {
   emit dataChanged(index(0, ChatLineModel::SenderColumn), index(rows - 1, ChatLineModel::SenderColumn));
 }
 
+void ChatMonitorFilter::showOwnMessagesSettingChanged(const QVariant &newValue) {
+  _showOwnMessages = newValue.toBool();
+}
index c1258b6..468b56d 100644 (file)
@@ -44,14 +44,21 @@ public:
   virtual QString idString() const { return "ChatMonitor"; }
   virtual QVariant data(const QModelIndex &index, int role) const;
 
-  inline QString showFieldSettingId() const { return QString("ChatView/%1/showFields").arg(idString()); }
-  inline int showFields() const { return QtUiSettings().value(showFieldSettingId(), AllFields).toInt(); }
+  int showFields() const { return _showFields; }
+  bool showOwnMessages() const { return _showOwnMessages; }
+
+public slots:
   void addShowField(int field);
   void removeShowField(int field);
+  void setShowOwnMessages(bool show);
 
-private:
+private slots:
+  void showFieldsSettingsChanged(const QVariant &newValue);
+  void showOwnMessagesSettingChanged(const QVariant &newValue);
 
-  void showFieldSettingsChanged();
+private:
+  int _showFields;
+  bool _showOwnMessages;
 };
 
 #endif
index 3f31591..0c40998 100644 (file)
@@ -41,21 +41,25 @@ ChatMonitorView::ChatMonitorView(ChatMonitorFilter *filter, QWidget *parent)
 }
 
 void ChatMonitorView::contextMenuEvent(QContextMenuEvent *event) {
-  if(scene()->sectionByScenePos(event->pos()) != ChatLineModel::SenderColumn)
-    return;
-
-  int showFields = _filter->showFields();
-
   QMenu contextMenu(this);
-  QAction *showNetworkAction = contextMenu.addAction(tr("Show network name"), this, SLOT(showFieldsChanged(bool)));
-  showNetworkAction->setCheckable(true);
-  showNetworkAction->setChecked(showFields & ChatMonitorFilter::NetworkField);
-  showNetworkAction->setData(ChatMonitorFilter::NetworkField);
-
-  QAction *showBufferAction = contextMenu.addAction(tr("Show buffer name"), this, SLOT(showFieldsChanged(bool)));
-  showBufferAction->setCheckable(true);
-  showBufferAction->setChecked(showFields & ChatMonitorFilter::BufferField);
-  showBufferAction->setData(ChatMonitorFilter::BufferField);
+
+  QAction *showOwnNicksAction = contextMenu.addAction(tr("Show own messages"), _filter, SLOT(setShowOwnMessages(bool)));
+  showOwnNicksAction->setCheckable(true);
+  showOwnNicksAction->setChecked(_filter->showOwnMessages());
+    
+  if(scene()->sectionByScenePos(event->pos()) == ChatLineModel::SenderColumn) {
+    contextMenu.addSeparator();
+
+    QAction *showNetworkAction = contextMenu.addAction(tr("Show network name"), this, SLOT(showFieldsChanged(bool)));
+    showNetworkAction->setCheckable(true);
+    showNetworkAction->setChecked(_filter->showFields() & ChatMonitorFilter::NetworkField);
+    showNetworkAction->setData(ChatMonitorFilter::NetworkField);
+
+    QAction *showBufferAction = contextMenu.addAction(tr("Show buffer name"), this, SLOT(showFieldsChanged(bool)));
+    showBufferAction->setCheckable(true);
+    showBufferAction->setChecked(_filter->showFields() & ChatMonitorFilter::BufferField);
+    showBufferAction->setData(ChatMonitorFilter::BufferField);
+  }
 
   contextMenu.exec(QCursor::pos());
 }