style button is smaller now
[quassel.git] / src / client / client.cpp
index c25f193..07b3c26 100644 (file)
 #include "clientbufferviewmanager.h"
 #include "clientirclisthelper.h"
 #include "clientidentity.h"
+#include "clientignorelistmanager.h"
 #include "clientuserinputhandler.h"
+#include "coreaccountmodel.h"
+#include "coreconnection.h"
 #include "ircchannel.h"
 #include "ircuser.h"
 #include "message.h"
@@ -49,7 +52,7 @@
 #include <stdlib.h>
 
 QPointer<Client> Client::instanceptr = 0;
-AccountId Client::_currentCoreAccount = 0;
+Quassel::Features Client::_coreFeatures = 0;
 
 /*** Initialization/destruction ***/
 
@@ -91,11 +94,12 @@ Client::Client(QObject *parent)
     _ircListHelper(new ClientIrcListHelper(this)),
     _inputHandler(0),
     _networkConfig(0),
+    _ignoreListManager(0),
     _messageModel(0),
     _messageProcessor(0),
-    _connectedToCore(false),
-    _syncedToCore(false),
-    _internalCore(false),
+    _coreAccountModel(new CoreAccountModel(this)),
+    _coreConnection(new CoreConnection(_coreAccountModel, this)),
+    _connected(false),
     _debugLog(&_debugLogBuffer)
 {
   _signalProxy->synchronize(_ircListHelper);
@@ -106,7 +110,6 @@ Client::~Client() {
 }
 
 void Client::init() {
-  _currentCoreAccount = 0;
   _networkModel = new NetworkModel(this);
 
   connect(this, SIGNAL(networkRemoved(NetworkId)),
@@ -136,8 +139,6 @@ void Client::init() {
   p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId)));
   p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
 
-  connect(p, SIGNAL(disconnected()), this, SLOT(disconnectedFromCore()));
-
   //connect(mainUi(), SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &)));
   connect(mainUi(), SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore()));
   connect(this, SIGNAL(connected()), mainUi(), SLOT(connectedToCore()));
@@ -146,6 +147,11 @@ void Client::init() {
   // attach backlog manager
   p->synchronize(backlogManager());
   connect(backlogManager(), SIGNAL(messagesReceived(BufferId, int)), _messageModel, SLOT(messagesReceived(BufferId, int)));
+
+  coreAccountModel()->load();
+
+  connect(coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), SLOT(connectionStateChanged(CoreConnection::ConnectionState)));
+  coreConnection()->init();
 }
 
 /*** public static methods ***/
@@ -154,20 +160,16 @@ AbstractUi *Client::mainUi() {
   return instance()->_mainUi;
 }
 
-AccountId Client::currentCoreAccount() {
-  return _currentCoreAccount;
-}
-
-void Client::setCurrentCoreAccount(AccountId id) {
-  _currentCoreAccount = id;
+void Client::setCoreFeatures(Quassel::Features features) {
+  _coreFeatures = features;
 }
 
 bool Client::isConnected() {
-  return instance()->_connectedToCore;
+  return instance()->_connected;
 }
 
-bool Client::isSynced() {
-  return instance()->_syncedToCore;
+bool Client::internalCore() {
+  return currentCoreAccount().isInternal();
 }
 
 /*** Network handling ***/
@@ -296,16 +298,17 @@ void Client::sendBufferedUserInput() {
 
 /*** core connection stuff ***/
 
-void Client::setConnectedToCore(AccountId id, QIODevice *socket) {
-  if(socket) { // external core
-    // if the socket is an orphan, the signalProxy adopts it.
-    // -> we don't need to care about it anymore
-    socket->setParent(0);
-    signalProxy()->addPeer(socket);
+void Client::connectionStateChanged(CoreConnection::ConnectionState state) {
+  switch(state) {
+  case CoreConnection::Disconnected:
+    setDisconnectedFromCore();
+    break;
+  case CoreConnection::Synchronized:
+    setSyncedToCore();
+    break;
+  default:
+    break;
   }
-  _internalCore = !socket;
-  _connectedToCore = true;
-  setCurrentCoreAccount(id);
 }
 
 void Client::setSyncedToCore() {
@@ -313,6 +316,7 @@ void Client::setSyncedToCore() {
   Q_ASSERT(!_bufferSyncer);
   _bufferSyncer = new BufferSyncer(this);
   connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), _networkModel, SLOT(setLastSeenMsgId(BufferId, MsgId)));
+  connect(bufferSyncer(), SIGNAL(markerLineSet(BufferId,MsgId)), _networkModel, SLOT(setMarkerLineMsgId(BufferId,MsgId)));
   connect(bufferSyncer(), SIGNAL(bufferRemoved(BufferId)), this, SLOT(bufferRemoved(BufferId)));
   connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString)));
   connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), this, SLOT(buffersPermanentlyMerged(BufferId, BufferId)));
@@ -336,10 +340,15 @@ void Client::setSyncedToCore() {
   _networkConfig = new NetworkConfig("GlobalNetworkConfig", this);
   signalProxy()->synchronize(networkConfig());
 
+  // create IgnoreListManager
+  Q_ASSERT(!_ignoreListManager);
+  _ignoreListManager = new ClientIgnoreListManager(this);
+  signalProxy()->synchronize(ignoreListManager());
+
   // trigger backlog request once all active bufferviews are initialized
   connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
 
-  _syncedToCore = true;
+  _connected = true;
   emit connected();
   emit coreConnectionStateChanged(true);
 }
@@ -359,22 +368,23 @@ void Client::requestInitialBacklog() {
 void Client::createDefaultBufferView() {
   if(bufferViewManager()->bufferViewConfigs().isEmpty()) {
     BufferViewConfig config(-1);
-    config.setBufferViewName(tr("All Buffers"));
+    config.setBufferViewName(tr("All Chats"));
     config.initSetBufferList(networkModel()->allBufferIdsSorted());
     bufferViewManager()->requestCreateBufferView(config.toVariantMap());
   }
 }
 
 void Client::disconnectFromCore() {
-  if(!isConnected())
+  if(!coreConnection()->isConnected())
     return;
 
-  signalProxy()->removeAllPeers();
+  coreConnection()->disconnectFromCore();
 }
 
-void Client::disconnectedFromCore() {
-  _connectedToCore = false;
-  _syncedToCore = false;
+void Client::setDisconnectedFromCore() {
+  _connected = false;
+  _coreFeatures = 0;
+
   emit disconnected();
   emit coreConnectionStateChanged(false);
 
@@ -382,7 +392,6 @@ void Client::disconnectedFromCore() {
   messageProcessor()->reset();
 
   // Clear internal data. Hopefully nothing relies on it at this point.
-  setCurrentCoreAccount(0);
 
   if(_bufferSyncer) {
     _bufferSyncer->deleteLater();
@@ -399,6 +408,10 @@ void Client::disconnectedFromCore() {
     _aliasManager = 0;
   }
 
+  if(_ignoreListManager) {
+    _ignoreListManager->deleteLater();
+    _ignoreListManager = 0;
+  }
   // we probably don't want to save pending input for reconnect
   _userInputBuffer.clear();
 
@@ -456,9 +469,13 @@ void Client::recvMessage(const Message &msg) {
 }
 
 void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) {
-  if(!bufferSyncer())
-    return;
-  bufferSyncer()->requestSetLastSeenMsg(id, msgId);
+  if(bufferSyncer())
+    bufferSyncer()->requestSetLastSeenMsg(id, msgId);
+}
+
+void Client::setBufferMarkerLine(BufferId id, const MsgId &msgId) {
+  if(bufferSyncer())
+    bufferSyncer()->requestSetMarkerLine(id, msgId);
 }
 
 void Client::removeBuffer(BufferId id) {
@@ -532,4 +549,3 @@ void Client::logMessage(QtMsgType type, const char *msg) {
     emit instance()->logUpdated(msgString);
   }
 }
-