Automatically create networks and buffers specified in networks.ini
[quassel.git] / src / client / client.cpp
index 52a2d13..41ceb1e 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   Copyright (C) 2005-09 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -25,6 +25,7 @@
 #include "buffermodel.h"
 #include "buffersettings.h"
 #include "buffersyncer.h"
+#include "bufferviewconfig.h"
 #include "bufferviewmanager.h"
 #include "clientbacklogmanager.h"
 #include "clientirclisthelper.h"
@@ -81,6 +82,7 @@ Client::Client(QObject *parent)
     _messageProcessor(0),
     _connectedToCore(false),
     _syncedToCore(false),
+    _internalCore(false),
     _debugLog(&_debugLogBuffer)
 {
   _signalProxy->synchronize(_ircListHelper);
@@ -115,7 +117,7 @@ void Client::init() {
   p->attachSlot(SIGNAL(identityCreated(const Identity &)), this, SLOT(coreIdentityCreated(const Identity &)));
   p->attachSlot(SIGNAL(identityRemoved(IdentityId)), this, SLOT(coreIdentityRemoved(IdentityId)));
 
-  p->attachSignal(this, SIGNAL(requestCreateNetwork(const NetworkInfo &)), SIGNAL(createNetwork(const NetworkInfo &)));
+  p->attachSignal(this, SIGNAL(requestCreateNetwork(const NetworkInfo &, const QStringList &)), SIGNAL(createNetwork(const NetworkInfo &, const QStringList &)));
   p->attachSignal(this, SIGNAL(requestRemoveNetwork(NetworkId)), SIGNAL(removeNetwork(NetworkId)));
   p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId)));
   p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
@@ -165,8 +167,8 @@ const Network * Client::network(NetworkId networkid) {
   else return 0;
 }
 
-void Client::createNetwork(const NetworkInfo &info) {
-  emit instance()->requestCreateNetwork(info);
+void Client::createNetwork(const NetworkInfo &info, const QStringList &persistentChannels) {
+  emit instance()->requestCreateNetwork(info, persistentChannels);
 }
 
 void Client::removeNetwork(NetworkId id) {
@@ -275,6 +277,7 @@ void Client::setConnectedToCore(AccountId id, QIODevice *socket) {
     socket->setParent(0);
     signalProxy()->addPeer(socket);
   }
+  _internalCore = !socket;
   _connectedToCore = true;
   setCurrentCoreAccount(id);
 }
@@ -296,6 +299,10 @@ void Client::setSyncedToCore() {
   Q_ASSERT(!_bufferViewManager);
   _bufferViewManager = new BufferViewManager(signalProxy(), this);
   connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
+  connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(createDefaultBufferView()));
+
+  createDefaultIdentity();
+  createDefaultNetworks();
 
   _syncedToCore = true;
   emit connected();
@@ -307,6 +314,37 @@ void Client::requestInitialBacklog() {
     Client::backlogManager()->requestInitialBacklog();
 }
 
+void Client::createDefaultBufferView() {
+  if(bufferViewManager()->bufferViewConfigs().isEmpty()) {
+    BufferViewConfig config(-1);
+    config.setBufferViewName(tr("All Buffers"));
+    config.initSetBufferList(networkModel()->allBufferIdsSorted());
+    bufferViewManager()->requestCreateBufferView(config.toVariantMap());
+  }
+}
+
+void Client::createDefaultIdentity() {
+  if(_identities.isEmpty()) {
+    Identity identity;
+    identity.setToDefaults();
+    identity.setIdentityName(tr("Default Identity"));
+    createIdentity(identity);
+  }
+}
+
+void Client::createDefaultNetworks() {
+  if(_networks.isEmpty()) {
+    QStringList defaultNets = Network::presetNetworks(true);
+    foreach(QString net, defaultNets) {
+      NetworkInfo info = Network::networkInfoFromPreset(net);
+      if(info.networkName.isEmpty())
+        continue;
+      QStringList defaultChans = Network::presetDefaultChannels(net);
+      createNetwork(info, defaultChans);
+    }
+  }
+}
+
 void Client::setSecuredConnection() {
   emit securedConnection();
 }