Automatically create networks and buffers specified in networks.ini
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 13 Jan 2009 22:41:09 +0000 (23:41 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 13 Jan 2009 22:59:25 +0000 (23:59 +0100)
In order for a network and certain channels to be added automatically in a blank core
configuration, add the following to a [NetworkName] block in networks.ini:

Default=Yes
DefaultChannels=#channel1,#channel2,#channel3

We'll create the network(s), and on first connect, the given channels will be joined automatically.

src/client/client.cpp
src/client/client.h
src/core/coresession.cpp
src/core/coresession.h

index 4b38109..41ceb1e 100644 (file)
@@ -117,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)));
@@ -167,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) {
@@ -299,9 +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(createDefautBufferView()));
+  connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(createDefaultBufferView()));
 
   createDefaultIdentity();
+  createDefaultNetworks();
 
   _syncedToCore = true;
   emit connected();
@@ -313,7 +314,7 @@ void Client::requestInitialBacklog() {
     Client::backlogManager()->requestInitialBacklog();
 }
 
-void Client::createDefautBufferView() {
+void Client::createDefaultBufferView() {
   if(bufferViewManager()->bufferViewConfigs().isEmpty()) {
     BufferViewConfig config(-1);
     config.setBufferViewName(tr("All Buffers"));
@@ -331,6 +332,19 @@ void Client::createDefaultIdentity() {
   }
 }
 
+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();
 }
index a67f2ba..684cb58 100644 (file)
@@ -90,7 +90,7 @@ public:
    */
   static void removeIdentity(IdentityId id);
 
-  static void createNetwork(const NetworkInfo &info);
+  static void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
   static void updateNetwork(const NetworkInfo &info);
   static void removeNetwork(NetworkId id);
 
@@ -154,7 +154,7 @@ signals:
   void networkCreated(NetworkId id);
   void networkRemoved(NetworkId id);
 
-  void requestCreateNetwork(const NetworkInfo &info);
+  void requestCreateNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
   void requestRemoveNetwork(NetworkId);
 
   void newClientSyncer(ClientSyncer *);
@@ -185,8 +185,9 @@ private slots:
   void setConnectedToCore(AccountId id, QIODevice *socket = 0);
   void setSyncedToCore();
   void requestInitialBacklog();
-  void createDefautBufferView();
+  void createDefaultBufferView();
   void createDefaultIdentity();
+  void createDefaultNetworks();
   void setSecuredConnection();
 
 
index 344f6a7..c90e7f6 100644 (file)
@@ -68,7 +68,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
 
   p->attachSignal(this, SIGNAL(networkCreated(NetworkId)));
   p->attachSignal(this, SIGNAL(networkRemoved(NetworkId)));
-  p->attachSlot(SIGNAL(createNetwork(const NetworkInfo &)), this, SLOT(createNetwork(const NetworkInfo &)));
+  p->attachSlot(SIGNAL(createNetwork(const NetworkInfo &, const QStringList &)), this, SLOT(createNetwork(const NetworkInfo &, const QStringList &)));
   p->attachSlot(SIGNAL(removeNetwork(NetworkId)), this, SLOT(removeNetwork(NetworkId)));
 
   loadSettings();
@@ -182,7 +182,6 @@ void CoreSession::removeClient(QIODevice *iodev) {
 
 QHash<QString, QString> CoreSession::persistentChannels(NetworkId id) const {
   return Core::persistentChannels(user(), id);
-  return QHash<QString, QString>();
 }
 
 // FIXME switch to BufferId
@@ -307,7 +306,7 @@ void CoreSession::removeIdentity(IdentityId id) {
 
 /*** Network Handling ***/
 
-void CoreSession::createNetwork(const NetworkInfo &info_) {
+void CoreSession::createNetwork(const NetworkInfo &info_, const QStringList &persistentChans) {
   NetworkInfo info = info_;
   int id;
 
@@ -331,6 +330,11 @@ void CoreSession::createNetwork(const NetworkInfo &info_) {
     _networks[id] = net;
     signalProxy()->synchronize(net);
     emit networkCreated(id);
+    // create persistent chans
+    foreach(QString channel, persistentChans) {
+      Core::bufferInfo(user(), info.networkId, BufferInfo::ChannelBuffer, channel, true);
+      Core::setChannelPersistent(user(), info.networkId, channel, true);
+    }
   } else {
     qWarning() << qPrintable(tr("CoreSession::createNetwork(): Trying to create a network that already exists, updating instead!"));
     _networks[info.networkId]->requestSetNetworkInfo(info);
index 22cfaf2..6e718be 100644 (file)
@@ -89,7 +89,7 @@ public slots:
   //! Create a network and propagate the changes to the clients.
   /** \param info The network's settings.
    */
-  void createNetwork(const NetworkInfo &info);
+  void createNetwork(const NetworkInfo &info, const QStringList &persistentChannels = QStringList());
 
   //! Remove network and propagate that fact to the clients.
   /** \param network The id of the network to be removed.