~ubuntu-branches/ubuntu/saucy/quassel/saucy-proposed

« back to all changes in this revision

Viewing changes to src/client/buffermodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-02-17 12:49:50 UTC
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: james.westby@ubuntu.com-20100217124950-v9hajw5d2xa6fszn
Tags: upstream-0.6~beta1
ImportĀ upstreamĀ versionĀ 0.6~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
            this, SLOT(debug_currentChanged(const QModelIndex &, const QModelIndex &)));
37
37
  }
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)));
39
40
}
40
41
 
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";
103
104
}
104
105
 
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));
112
 
  } else
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));
 
114
    }
 
115
  } else {
 
116
    _bufferToSwitchTo = qMakePair(networkId, name);
 
117
    Client::userInput(BufferInfo::fakeStatusBuffer(networkId), QString(isQuery ? "/QUERY %1" : "/JOIN %1").arg(name));
 
118
  }
114
119
}
115
120
 
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>();
119
124
}
 
125
 
 
126
void BufferModel::newBuffers(const QModelIndex &parent, int start, int end) {
 
127
  if(parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
 
128
    return;
 
129
 
 
130
  for(int row = start; row <= end; row++) {
 
131
    QModelIndex child = parent.child(row, 0);
 
132
    newBuffer(child.data(NetworkModel::BufferIdRole).value<BufferId>());
 
133
  }
 
134
}
 
135
 
 
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);
 
143
  }
 
144
}
 
145
 
 
146
void BufferModel::switchToBufferAfterCreation(NetworkId network, const QString &name) {
 
147
  _bufferToSwitchTo = qMakePair(network, name);
 
148
}