Fixing the "Add New Buffers automatically"-function for custom bufferviews.
authorMarcus Eggenberger <egs@quassel-irc.org>
Mon, 26 May 2008 15:19:02 +0000 (15:19 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Mon, 26 May 2008 15:19:02 +0000 (15:19 +0000)
In addition you can now hide buffers permanently or temporarily (the
default) from a custom view. In the latter case buffers will be
readded if there are new messages.
Needs core updated! Distclean adviced!

src/common/bufferviewconfig.cpp
src/common/bufferviewconfig.h
src/core/corebufferviewconfig.h
src/uisupport/bufferview.cpp
src/uisupport/bufferview.h
src/uisupport/bufferviewfilter.cpp
src/uisupport/bufferviewfilter.h
version.inc

index 1affaba..88c9dc0 100644 (file)
@@ -115,6 +115,7 @@ void BufferViewConfig::initSetBufferList(const QVariantList &buffers) {
     _buffers << buffer.value<BufferId>();
   }
 
+  // normaly initSeters don't need an emit. this one is to track changes in the settingspage
   emit bufferListSet();
 }
 
@@ -125,9 +126,28 @@ void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers) {
     _buffers << bufferId;
   }
 
+  // normaly initSeters don't need an emit. this one is to track changes in the settingspage
   emit bufferListSet();
 }
 
+QVariantList BufferViewConfig::initRemovedBuffersList() const {
+  QVariantList removedBuffers;
+
+  foreach(BufferId bufferId, _removedBuffers) {
+    removedBuffers << qVariantFromValue(bufferId);
+  }
+
+  return removedBuffers;
+}
+
+void BufferViewConfig::initSetRemovedBuffersList(const QVariantList &buffers) {
+  _removedBuffers.clear();
+
+  foreach(QVariant buffer, buffers) {
+    _removedBuffers << buffer.value<BufferId>();
+  }
+}
+
 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
   if(_buffers.contains(bufferId))
     return;
@@ -136,6 +156,9 @@ void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
     pos = 0;
   if(pos > _buffers.count())
     pos = _buffers.count();
+
+  if(_removedBuffers.contains(bufferId))
+    _removedBuffers.remove(bufferId);
   
   _buffers.insert(pos, bufferId);
   emit bufferAdded(bufferId, pos);
@@ -161,3 +184,12 @@ void BufferViewConfig::removeBuffer(const BufferId &bufferId) {
   _buffers.removeAt(_buffers.indexOf(bufferId));
   emit bufferRemoved(bufferId);
 }
+
+void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId) {
+  if(_buffers.contains(bufferId))
+    _buffers.removeAt(_buffers.indexOf(bufferId));
+  
+  _removedBuffers << bufferId;
+
+  emit bufferPermanentlyRemoved(bufferId);
+}
index 2e2a9aa..81e2cb3 100644 (file)
@@ -67,16 +67,24 @@ public slots:
   virtual inline void requestSetBufferViewName(const QString &bufferViewName) { emit setBufferViewNameRequested(bufferViewName); }
 
   const QList<BufferId> &bufferList() const { return _buffers; }
+  const QSet<BufferId> &removedBuffers() const { return _removedBuffers; }
+
   QVariantList initBufferList() const;
   void initSetBufferList(const QVariantList &buffers);
   void initSetBufferList(const QList<BufferId> &buffers);
 
+  QVariantList initRemovedBuffersList() const;
+  void initSetRemovedBuffersList(const QVariantList &buffers);
+
   void addBuffer(const BufferId &bufferId, int pos);
   virtual inline void requestAddBuffer(const BufferId &bufferId, int pos) { emit addBufferRequested(bufferId, pos); }
   void moveBuffer(const BufferId &bufferId, int pos);
   virtual inline void requestMoveBuffer(const BufferId &bufferId, int pos) { emit moveBufferRequested(bufferId, pos); }
   void removeBuffer(const BufferId &bufferId);
   virtual inline void requestRemoveBuffer(const BufferId &bufferId) { emit removeBufferRequested(bufferId); }
+  void removeBufferPermanently(const BufferId &bufferId);
+  virtual inline void requestRemoveBufferPermanently(const BufferId &bufferId) { emit removeBufferPermanentlyRequested(bufferId); }
+  
   
 signals:
   void bufferViewNameSet(const QString &bufferViewName);
@@ -93,7 +101,9 @@ signals:
   void bufferMoved(const BufferId &bufferId, int pos);
   void moveBufferRequested(const BufferId &bufferId, int pos);
   void bufferRemoved(const BufferId &bufferId);
+  void bufferPermanentlyRemoved(const BufferId &bufferId);
   void removeBufferRequested(const BufferId &bufferId);
+  void removeBufferPermanentlyRequested(const BufferId &bufferId);
   
   void setBufferViewNameRequested(const QString &bufferViewName);
 
@@ -107,6 +117,7 @@ private:
   int _allowedBufferTypes;
   int _minimumActivity;
   QList<BufferId> _buffers;
+  QSet<BufferId> _removedBuffers;
 };
 
 #endif // BUFFERVIEWCONFIG_H
index b0d9e96..bb7eb95 100644 (file)
@@ -35,6 +35,7 @@ public:
 public slots:
   virtual inline void requestSetBufferViewName(const QString &bufferViewName) { setBufferViewName(bufferViewName); }
   virtual inline void requestRemoveBuffer(const BufferId &bufferId) { removeBuffer(bufferId); }
+  virtual inline void requestRemoveBufferPermanently(const BufferId &bufferId) { removeBufferPermanently(bufferId); }
   virtual inline void requestAddBuffer(const BufferId &bufferId, int pos) { addBuffer(bufferId, pos); }
   virtual inline void requestMoveBuffer(const BufferId &bufferId, int pos) { moveBuffer(bufferId, pos); }
 };
index 526a040..e41bdab 100644 (file)
@@ -54,7 +54,8 @@ BufferView::BufferView(QWidget *parent)
 
     _joinBufferAction(tr("Join"), this),
     _partBufferAction(tr("Part"), this),
-    _hideBufferAction(tr("Hide selected buffers"), this),
+    _hideBufferTemporarilyAction(tr("Hide buffers"), this),
+    _hideBufferPermanentlyAction(tr("Hide buffers permanently"), this),
     _removeBufferAction(tr("Delete buffer"), this),
     _ignoreListAction(tr("Ignore list"), this),
 
@@ -158,8 +159,6 @@ void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig *
   } else {
     BufferViewFilter *filter = new BufferViewFilter(model_, config);
     setModel(filter);
-    connect(this, SIGNAL(removeBuffer(const QModelIndex &)),
-           filter, SLOT(removeBuffer(const QModelIndex &)));
   }
   setConfig(config);
 }
@@ -227,13 +226,26 @@ void BufferView::keyPressEvent(QKeyEvent *event) {
   QTreeView::keyPressEvent(event);
 }
 
-void BufferView::removeSelectedBuffers() {
-  QSet<int> removedRows;
+void BufferView::removeSelectedBuffers(bool permanently) {
+  if(!config())
+    return;
+
+  BufferId bufferId;
+  QSet<BufferId> removedRows;
   foreach(QModelIndex index, selectionModel()->selectedIndexes()) {
-    if(index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType && !removedRows.contains(index.row())) {
-      removedRows << index.row();
-      emit removeBuffer(index);
-    }
+    if(index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
+      continue;
+
+    bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
+    if(removedRows.contains(bufferId))
+      continue;
+
+    removedRows << bufferId;
+    
+    if(permanently)
+      config()->requestRemoveBufferPermanently(bufferId);
+    else
+      config()->requestRemoveBuffer(bufferId);
   }
 }
 
@@ -401,18 +413,21 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) {
       case BufferInfo::ChannelBuffer:
        addItemToMenu(_joinBufferAction, contextMenu, index, InactiveState);
        addItemToMenu(_partBufferAction, contextMenu, index, ActiveState);
-       addItemToMenu(_hideBufferAction, contextMenu, (bool)config());
+       addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
+       addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
        addItemToMenu(_removeBufferAction, contextMenu, index, InactiveState);
        createHideEventsSubMenu(contextMenu);
        addItemToMenu(_ignoreListAction, contextMenu);
        break;
       case BufferInfo::QueryBuffer:
-       addItemToMenu(_hideBufferAction, contextMenu, (bool)config());
+       addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
+       addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
        addItemToMenu(_removeBufferAction, contextMenu);
        createHideEventsSubMenu(contextMenu);
        break;
       default:
-       addItemToMenu(_hideBufferAction, contextMenu, (bool)config());
+       addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
+       addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
        break;
       }
     }
@@ -463,11 +478,16 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) {
     return;
   }
   
-  if(result == &_hideBufferAction) {
+  if(result == &_hideBufferTemporarilyAction) {
     removeSelectedBuffers();
     return;
   }
 
+  if(result == &_hideBufferPermanentlyAction) {
+    removeSelectedBuffers(true);
+    return;
+  }
+
   if(result == &_removeBufferAction) {
     BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
     int res = QMessageBox::question(this, tr("Remove buffer permanently?"),
index cb5a68d..b47904a 100644 (file)
@@ -52,10 +52,11 @@ class BufferView : public QTreeView {
 
   public slots:
     void setRootIndexForNetworkId(const NetworkId &networkId);
-    void removeSelectedBuffers();
+    void removeSelectedBuffers(bool permanently = false);
 
   signals:
     void removeBuffer(const QModelIndex &);
+    void removeBufferPermanently(const QModelIndex &);
 
   protected:
     virtual void keyPressEvent(QKeyEvent *);
@@ -89,7 +90,8 @@ class BufferView : public QTreeView {
 
     QAction _joinBufferAction;
     QAction _partBufferAction;
-    QAction _hideBufferAction;
+    QAction _hideBufferTemporarilyAction;
+    QAction _hideBufferPermanentlyAction;
     QAction _removeBufferAction;
     QAction _ignoreListAction;
 
index 59dd184..0fe6426 100644 (file)
@@ -71,19 +71,32 @@ void BufferViewFilter::setConfig(BufferViewConfig *config) {
   }
 
   _config = config;
-  if(config) {
-    connect(config, SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(addNewBuffersAutomaticallySet(bool)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(hideInactiveBuffersSet(bool)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(allowedBufferTypesSet(int)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(minimumActivitySet(int)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(bufferListSet()), this, SLOT(invalidate()));
-    connect(config, SIGNAL(bufferAdded(const BufferId &, int)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(bufferMoved(const BufferId &, int)), this, SLOT(invalidate()));
-    connect(config, SIGNAL(bufferRemoved(const BufferId &)), this, SLOT(invalidate()));
+  if(config->isInitialized()) {
+    configInitialized();
+  } else {
+    connect(config, SIGNAL(initDone()), this, SLOT(configInitialized()));
+    invalidate();
   }
+}
+
+void BufferViewFilter::configInitialized() {
+  if(!config())
+    return;
+    
+  connect(config(), SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(addNewBuffersAutomaticallySet(bool)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(hideInactiveBuffersSet(bool)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(allowedBufferTypesSet(int)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(minimumActivitySet(int)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(bufferListSet()), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(bufferAdded(const BufferId &, int)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(bufferMoved(const BufferId &, int)), this, SLOT(invalidate()));
+  connect(config(), SIGNAL(bufferRemoved(const BufferId &)), this, SLOT(invalidate()));
+
+  disconnect(config(), SIGNAL(initDone()), this, SLOT(configInitialized()));
+
   invalidate();
 }
 
@@ -134,7 +147,7 @@ bool BufferViewFilter::dropMimeData(const QMimeData *data, Qt::DropAction action
   return true;
 }
 
-void BufferViewFilter::addBuffer(const BufferId &bufferId) {
+void BufferViewFilter::addBuffer(const BufferId &bufferId) const {
   if(!config() || config()->bufferList().contains(bufferId))
     return;
   
@@ -154,36 +167,34 @@ void BufferViewFilter::addBuffer(const BufferId &bufferId) {
   config()->requestAddBuffer(bufferId, pos);
 }
 
-void BufferViewFilter::removeBuffer(const QModelIndex &index) {
-  if(!config() || !index.isValid() || index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
-    return;
-
-  BufferId bufferId = data(index, NetworkModel::BufferIdRole).value<BufferId>();
-  config()->requestRemoveBuffer(bufferId);
-}
-
-
 bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) const {
   BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value<BufferId>();
   Q_ASSERT(bufferId.isValid());
-  if(!_config)
+  if(!config())
     return true;
-  
+
+  int activityLevel = source_bufferIndex.data(NetworkModel::BufferActivityRole).toInt();
   if(config()->networkId().isValid() && config()->networkId() != sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value<NetworkId>())
     return false;
 
-  if(!(_config->allowedBufferTypes() & (BufferInfo::Type)source_bufferIndex.data(NetworkModel::BufferTypeRole).toInt()))
+  if(!(config()->allowedBufferTypes() & (BufferInfo::Type)source_bufferIndex.data(NetworkModel::BufferTypeRole).toInt()))
     return false;
 
-  if(_config->hideInactiveBuffers() && !source_bufferIndex.data(NetworkModel::ItemActiveRole).toBool())
+  if(config()->hideInactiveBuffers() && !source_bufferIndex.data(NetworkModel::ItemActiveRole).toBool())
     return false;
 
-  if(_config->minimumActivity() > source_bufferIndex.data(NetworkModel::BufferActivityRole).toInt()) {
+  if(config()->minimumActivity() > activityLevel) {
     if(bufferId != Client::bufferModel()->standardSelectionModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>())
       return false;
   }
 
-  return _config->bufferList().contains(bufferId);
+  if(config()->bufferList().contains(bufferId))
+    return true;
+
+  if(config()->isInitialized() && !config()->removedBuffers().contains(bufferId) && activityLevel > Buffer::OtherActivity)
+    addBuffer(bufferId);
+
+  return false;
 }
 
 bool BufferViewFilter::filterAcceptNetwork(const QModelIndex &source_index) const {
index 4a80f7e..7fc6239 100644 (file)
@@ -62,7 +62,6 @@ public:
   inline BufferViewConfig *config() const { return _config; }
 
 public slots:
-  void removeBuffer(const QModelIndex &);
   void checkPreviousCurrentForRemoval(const QModelIndex &current, const QModelIndex &previous);
   void checkItemForRemoval(const QModelIndex &index) { checkItemsForRemoval(index, index); }
   void checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight);
@@ -77,7 +76,10 @@ protected:
 
 signals:
   void _dataChanged(const QModelIndex &source_topLeft, const QModelIndex &source_bottomRight);
-  
+
+private slots:
+  void configInitialized();
+    
 private:
   QPointer<BufferViewConfig> _config;
   
@@ -90,7 +92,7 @@ private:
 
   bool filterAcceptBuffer(const QModelIndex &) const;
   bool filterAcceptNetwork(const QModelIndex &) const;
-  void addBuffer(const BufferId &);
+  void addBuffer(const BufferId &) const;
 };
 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferViewFilter::Modes)    
 
index 9ac143e..0b5237c 100644 (file)
@@ -4,8 +4,8 @@
 { using namespace Global;
 
   quasselVersion = "0.2.0-beta2-pre";
-  quasselDate = "2008-05-23";
-  quasselBuild = 857;
+  quasselDate = "2008-05-26";
+  quasselBuild = 859;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 731;