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

« back to all changes in this revision

Viewing changes to src/client/client.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:
35
35
#include "clientidentity.h"
36
36
#include "clientignorelistmanager.h"
37
37
#include "clientuserinputhandler.h"
 
38
#include "coreaccountmodel.h"
 
39
#include "coreconnection.h"
38
40
#include "ircchannel.h"
39
41
#include "ircuser.h"
40
42
#include "message.h"
50
52
#include <stdlib.h>
51
53
 
52
54
QPointer<Client> Client::instanceptr = 0;
53
 
AccountId Client::_currentCoreAccount = 0;
 
55
Quassel::Features Client::_coreFeatures = 0;
54
56
 
55
57
/*** Initialization/destruction ***/
56
58
 
95
97
    _ignoreListManager(0),
96
98
    _messageModel(0),
97
99
    _messageProcessor(0),
98
 
    _connectedToCore(false),
99
 
    _syncedToCore(false),
100
 
    _internalCore(false),
 
100
    _coreAccountModel(new CoreAccountModel(this)),
 
101
    _coreConnection(new CoreConnection(_coreAccountModel, this)),
 
102
    _connected(false),
101
103
    _debugLog(&_debugLogBuffer)
102
104
{
103
105
  _signalProxy->synchronize(_ircListHelper);
108
110
}
109
111
 
110
112
void Client::init() {
111
 
  _currentCoreAccount = 0;
112
113
  _networkModel = new NetworkModel(this);
113
114
 
114
115
  connect(this, SIGNAL(networkRemoved(NetworkId)),
138
139
  p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId)));
139
140
  p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
140
141
 
141
 
  connect(p, SIGNAL(disconnected()), this, SLOT(disconnectedFromCore()));
142
 
 
143
142
  //connect(mainUi(), SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &)));
144
143
  connect(mainUi(), SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore()));
145
144
  connect(this, SIGNAL(connected()), mainUi(), SLOT(connectedToCore()));
148
147
  // attach backlog manager
149
148
  p->synchronize(backlogManager());
150
149
  connect(backlogManager(), SIGNAL(messagesReceived(BufferId, int)), _messageModel, SLOT(messagesReceived(BufferId, int)));
 
150
 
 
151
  coreAccountModel()->load();
 
152
 
 
153
  connect(coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), SLOT(connectionStateChanged(CoreConnection::ConnectionState)));
 
154
  coreConnection()->init();
151
155
}
152
156
 
153
157
/*** public static methods ***/
156
160
  return instance()->_mainUi;
157
161
}
158
162
 
159
 
AccountId Client::currentCoreAccount() {
160
 
  return _currentCoreAccount;
161
 
}
162
 
 
163
 
void Client::setCurrentCoreAccount(AccountId id) {
164
 
  _currentCoreAccount = id;
 
163
void Client::setCoreFeatures(Quassel::Features features) {
 
164
  _coreFeatures = features;
165
165
}
166
166
 
167
167
bool Client::isConnected() {
168
 
  return instance()->_connectedToCore;
 
168
  return instance()->_connected;
169
169
}
170
170
 
171
 
bool Client::isSynced() {
172
 
  return instance()->_syncedToCore;
 
171
bool Client::internalCore() {
 
172
  return currentCoreAccount().isInternal();
173
173
}
174
174
 
175
175
/*** Network handling ***/
298
298
 
299
299
/*** core connection stuff ***/
300
300
 
301
 
void Client::setConnectedToCore(AccountId id, QIODevice *socket) {
302
 
  if(socket) { // external core
303
 
    // if the socket is an orphan, the signalProxy adopts it.
304
 
    // -> we don't need to care about it anymore
305
 
    socket->setParent(0);
306
 
    signalProxy()->addPeer(socket);
 
301
void Client::connectionStateChanged(CoreConnection::ConnectionState state) {
 
302
  switch(state) {
 
303
  case CoreConnection::Disconnected:
 
304
    setDisconnectedFromCore();
 
305
    break;
 
306
  case CoreConnection::Synchronized:
 
307
    setSyncedToCore();
 
308
    break;
 
309
  default:
 
310
    break;
307
311
  }
308
 
  _internalCore = !socket;
309
 
  _connectedToCore = true;
310
 
  setCurrentCoreAccount(id);
311
312
}
312
313
 
313
314
void Client::setSyncedToCore() {
315
316
  Q_ASSERT(!_bufferSyncer);
316
317
  _bufferSyncer = new BufferSyncer(this);
317
318
  connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), _networkModel, SLOT(setLastSeenMsgId(BufferId, MsgId)));
 
319
  connect(bufferSyncer(), SIGNAL(markerLineSet(BufferId,MsgId)), _networkModel, SLOT(setMarkerLineMsgId(BufferId,MsgId)));
318
320
  connect(bufferSyncer(), SIGNAL(bufferRemoved(BufferId)), this, SLOT(bufferRemoved(BufferId)));
319
321
  connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString)));
320
322
  connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), this, SLOT(buffersPermanentlyMerged(BufferId, BufferId)));
346
348
  // trigger backlog request once all active bufferviews are initialized
347
349
  connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
348
350
 
349
 
  _syncedToCore = true;
 
351
  _connected = true;
350
352
  emit connected();
351
353
  emit coreConnectionStateChanged(true);
352
354
}
373
375
}
374
376
 
375
377
void Client::disconnectFromCore() {
376
 
  if(!isConnected())
 
378
  if(!coreConnection()->isConnected())
377
379
    return;
378
380
 
379
 
  signalProxy()->removeAllPeers();
 
381
  coreConnection()->disconnectFromCore();
380
382
}
381
383
 
382
 
void Client::disconnectedFromCore() {
383
 
  _connectedToCore = false;
384
 
  _syncedToCore = false;
 
384
void Client::setDisconnectedFromCore() {
 
385
  _connected = false;
 
386
  _coreFeatures = 0;
 
387
 
385
388
  emit disconnected();
386
389
  emit coreConnectionStateChanged(false);
387
390
 
389
392
  messageProcessor()->reset();
390
393
 
391
394
  // Clear internal data. Hopefully nothing relies on it at this point.
392
 
  setCurrentCoreAccount(0);
393
395
 
394
396
  if(_bufferSyncer) {
395
397
    _bufferSyncer->deleteLater();
467
469
}
468
470
 
469
471
void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) {
470
 
  if(!bufferSyncer())
471
 
    return;
472
 
  bufferSyncer()->requestSetLastSeenMsg(id, msgId);
 
472
  if(bufferSyncer())
 
473
    bufferSyncer()->requestSetLastSeenMsg(id, msgId);
 
474
}
 
475
 
 
476
void Client::setBufferMarkerLine(BufferId id, const MsgId &msgId) {
 
477
  if(bufferSyncer())
 
478
    bufferSyncer()->requestSetMarkerLine(id, msgId);
473
479
}
474
480
 
475
481
void Client::removeBuffer(BufferId id) {