- setSourceModel(parent);
- if(QCoreApplication::instance()->arguments().contains("--debugbufferswitches")) {
- connect(_selectionModelSynchronizer.selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
- this, SLOT(debug_currentChanged(const QModelIndex &, const QModelIndex &)));
- }
+ setSourceModel(parent);
+ if (Quassel::isOptionSet("debugbufferswitches")) {
+ connect(_selectionModelSynchronizer.selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+ this, SLOT(debug_currentChanged(const QModelIndex &, const QModelIndex &)));
+ }
+ connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(newNetwork(NetworkId)));
+ connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(newBuffers(const QModelIndex &, int, int)));
+}
+
+
+bool BufferModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const
+{
+ Q_UNUSED(sourceRow);
+ // only networks and buffers are allowed
+ if (!parent.isValid())
+ return true;
+ if (parent.data(NetworkModel::ItemTypeRole) == NetworkModel::NetworkItemType)
+ return true;
+
+ return false;
+}
+
+
+void BufferModel::newNetwork(NetworkId id)
+{
+ const Network *net = Client::network(id);
+ Q_ASSERT(net);
+ connect(net, SIGNAL(connectionStateSet(Network::ConnectionState)),
+ this, SLOT(networkConnectionChanged(Network::ConnectionState)));
+}
+
+
+void BufferModel::networkConnectionChanged(Network::ConnectionState state)
+{
+ switch (state) {
+ case Network::Connecting:
+ case Network::Initializing:
+ if (currentIndex().isValid())
+ return;
+ {
+ Network *net = qobject_cast<Network *>(sender());
+ Q_ASSERT(net);
+ setCurrentIndex(mapFromSource(Client::networkModel()->networkIndex(net->networkId())));
+ }
+ break;
+ default:
+ return;
+ }
+}
+
+
+void BufferModel::synchronizeView(QAbstractItemView *view)
+{
+ _selectionModelSynchronizer.synchronizeSelectionModel(view->selectionModel());
+}
+
+
+void BufferModel::setCurrentIndex(const QModelIndex &newCurrent)
+{
+ _selectionModelSynchronizer.selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::Current);
+ _selectionModelSynchronizer.selectionModel()->select(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);