36
36
this, SLOT(debug_currentChanged(const QModelIndex &, const QModelIndex &)));
38
38
connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(newNetwork(NetworkId)));
39
connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(newBuffers(const QModelIndex &, int, int)));
41
42
bool BufferModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const {
102
103
qWarning() << "BufferModel::switchToBufferIndex(const QModelIndex &):" << bufferIdx << "does not belong to BufferModel or NetworkModel";
105
void BufferModel::switchToOrJoinBuffer(NetworkId networkId, const QString &name) {
106
void BufferModel::switchToOrJoinBuffer(NetworkId networkId, const QString &name, bool isQuery) {
106
107
BufferId bufId = Client::networkModel()->bufferId(networkId, name);
107
108
if(bufId.isValid()) {
108
109
QModelIndex targetIdx = Client::networkModel()->bufferIndex(bufId);
109
110
switchToBuffer(bufId);
110
if(!targetIdx.data(NetworkModel::ItemActiveRole).toBool())
111
Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString("/JOIN %1").arg(name));
113
Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString("/JOIN %1").arg(name));
111
if(!targetIdx.data(NetworkModel::ItemActiveRole).toBool()) {
112
qDebug() << "switchToOrJoinBuffer failed to switch even though bufId:" << bufId << "is valid.";
113
Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString(isQuery ? "/QUERY %1" : "/JOIN %1").arg(name));
116
_bufferToSwitchTo = qMakePair(networkId, name);
117
Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString(isQuery ? "/QUERY %1" : "/JOIN %1").arg(name));
116
121
void BufferModel::debug_currentChanged(QModelIndex current, QModelIndex previous) {
117
122
Q_UNUSED(previous);
118
123
qDebug() << "Switched current Buffer: " << current << current.data().toString() << "Buffer:" << current.data(NetworkModel::BufferIdRole).value<BufferId>();
126
void BufferModel::newBuffers(const QModelIndex &parent, int start, int end) {
127
if(parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
130
for(int row = start; row <= end; row++) {
131
QModelIndex child = parent.child(row, 0);
132
newBuffer(child.data(NetworkModel::BufferIdRole).value<BufferId>());
136
void BufferModel::newBuffer(BufferId bufferId) {
137
BufferInfo bufferInfo = Client::networkModel()->bufferInfo(bufferId);
138
if(_bufferToSwitchTo.first == bufferInfo.networkId()
139
&& _bufferToSwitchTo.second == bufferInfo.bufferName()) {
140
_bufferToSwitchTo.first = 0;
141
_bufferToSwitchTo.second.clear();
142
switchToBuffer(bufferId);
146
void BufferModel::switchToBufferAfterCreation(NetworkId network, const QString &name) {
147
_bufferToSwitchTo = qMakePair(network, name);