From 1b113021e8d82f93f46e02cf66428aebfb7d0357 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Tue, 13 Jan 2009 23:41:09 +0100 Subject: [PATCH] Automatically create networks and buffers specified in networks.ini 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 | 24 +++++++++++++++++++----- src/client/client.h | 7 ++++--- src/core/coresession.cpp | 10 +++++++--- src/core/coresession.h | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 4b381090..41ceb1ed 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -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(); } diff --git a/src/client/client.h b/src/client/client.h index a67f2bad..684cb581 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -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(); diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 344f6a78..c90e7f66 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -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 CoreSession::persistentChannels(NetworkId id) const { return Core::persistentChannels(user(), id); - return QHash(); } // 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); diff --git a/src/core/coresession.h b/src/core/coresession.h index 22cfaf23..6e718bea 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -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. -- 2.20.1