#include "bufferviewconfig.h"
#include "client.h"
+#include "clientbacklogmanager.h"
#include "clientbufferviewmanager.h"
#include "networkmodel.h"
{
}
+void BufferViewOverlay::reset() {
+ _aboutToUpdate = false;
+
+ _bufferViewIds.clear();
+ _uninitializedViewCount = 0;
+
+ _networkIds.clear();
+ _allowedBufferTypes = 0;
+ _minimumActivity = 0;
+
+ _buffers.clear();
+ _removedBuffers.clear();
+ _tempRemovedBuffers.clear();
+}
+
+void BufferViewOverlay::save() {
+ CoreAccountSettings().setBufferViewOverlay(_bufferViewIds);
+}
+
+void BufferViewOverlay::restore() {
+ QSet<int> currentIds = _bufferViewIds;
+ reset();
+ currentIds += CoreAccountSettings().bufferViewOverlay();
+
+ QSet<int>::const_iterator iter;
+ for(iter = currentIds.constBegin(); iter != currentIds.constEnd(); iter++) {
+ addView(*iter);
+ }
+}
+
void BufferViewOverlay::addView(int viewId) {
if(_bufferViewIds.contains(viewId))
return;
}
_bufferViewIds << viewId;
+ bool wasInitialized = isInitialized();
_uninitializedViewCount++;
+
if(config->isInitialized()) {
viewInitialized(config);
+
+ if(wasInitialized) {
+ BufferIdList buffers;
+ if(config->networkId().isValid()) {
+ foreach(BufferId bufferId, config->bufferList()) {
+ if(Client::networkModel()->networkId(bufferId) == config->networkId())
+ buffers << bufferId;
+ }
+ foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
+ if(Client::networkModel()->networkId(bufferId) == config->networkId())
+ buffers << bufferId;
+ }
+ } else {
+ buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
+ }
+ Client::backlogManager()->checkForBacklog(buffers);
+ }
+
} else {
disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()));
// we use a queued connection here since manipulating the connection list of a sending object
// doesn't seem to be such a good idea while executing a connected slots.
connect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()), Qt::QueuedConnection);
}
+ save();
}
void BufferViewOverlay::removeView(int viewId) {
update();
if(!wasInitialized && isInitialized())
emit initDone();
+ save();
}
void BufferViewOverlay::viewInitialized(BufferViewConfig *config) {
disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()));
connect(config, SIGNAL(configChanged()), this, SLOT(update()));
-// connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(update()));
-// connect(config, SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(update()));
-// connect(config, SIGNAL(allowedBufferTypesSet(int)), this, SLOT(update()));
-// connect(config, SIGNAL(minimumActivitySet(int)), this, SLOT(update()));
-// connect(config, SIGNAL(bufferListSet()), this, SLOT(update()));
-// connect(config, SIGNAL(bufferAdded(const BufferId &, int)), this, SLOT(update()));
-// connect(config, SIGNAL(bufferRemoved(const BufferId &)), this, SLOT(update()));
-// connect(config, SIGNAL(bufferPermanentlyRemoved(const BufferId &)), this, SLOT(update()));
// check if the view was removed in the meantime...
if(_bufferViewIds.contains(config->bufferViewId()))
void addView(int viewId);
void removeView(int viewId);
+ void reset();
+ void save();
+ void restore();
+
// updates propagated from the actual views
void update();
// create a new BufferViewManager
Q_ASSERT(!_bufferViewManager);
_bufferViewManager = new ClientBufferViewManager(signalProxy(), this);
- connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(createDefaultBufferView()));
+ connect(_bufferViewManager, SIGNAL(initDone()), _bufferViewOverlay, SLOT(restore()));
// create AliasManager
Q_ASSERT(!_aliasManager);
// triggers this slot. But we have to make sure that we know all buffers yet.
// so we check the BufferSyncer and in case it wasn't initialized we wait for that instead
if(!bufferSyncer()->isInitialized()) {
- connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
+ disconnect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
connect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
return;
}
- _backlogManager->requestInitialBacklog();
-}
+ disconnect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
+ disconnect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog()));
-void Client::createDefaultBufferView() {
- if(bufferViewManager()->bufferViewConfigs().isEmpty()) {
- BufferViewConfig config(-1);
- config.setBufferViewName(tr("All Chats"));
- config.initSetBufferList(networkModel()->allBufferIdsSorted());
- bufferViewManager()->requestCreateBufferView(config.toVariantMap());
- }
+ _backlogManager->requestInitialBacklog();
}
void Client::disconnectFromCore() {
_bufferViewManager = 0;
}
+ _bufferViewOverlay->reset();
+
if(_aliasManager) {
_aliasManager->deleteLater();
_aliasManager = 0;
void coreNetworkRemoved(NetworkId);
void requestInitialBacklog();
- void createDefaultBufferView();
void sendBufferedUserInput();
INIT_SYNCABLE_OBJECT(ClientBacklogManager)
ClientBacklogManager::ClientBacklogManager(QObject *parent)
: BacklogManager(parent),
- _requester(0)
+ _requester(0),
+ _initBacklogRequested(false)
{
}
}
void ClientBacklogManager::requestInitialBacklog() {
- if(_requester && !_buffersRequested.isEmpty()) {
- // qWarning() << "ClientBacklogManager::requestInitialBacklog() called twice in the same session! (Backlog has already been requested)";
+ if(_initBacklogRequested) {
+ Q_ASSERT(_requester);
+ qWarning() << "ClientBacklogManager::requestInitialBacklog() called twice in the same session! (Backlog has already been requested)";
return;
}
};
_requester->requestInitialBacklog();
+ _initBacklogRequested = true;
if(_requester->isBuffering()) {
updateProgress(0, _requester->totalBuffers());
}
}
void ClientBacklogManager::checkForBacklog(const QList<BufferId> &bufferIds) {
+ // we ingore all backlogrequests until we had our initial request
+ if(!_initBacklogRequested) {
+ return;
+ }
+
if(!_requester) {
// during client start up this message is to be expected in some situations.
- qDebug() << "ClientBacklogManager::checkForBacklog(): no active backlog requester (yet?).";
+ qDebug() << "ClientBacklogManager::checkForBacklog(): no active backlog requester.";
return;
}
switch(_requester->type()) {
void ClientBacklogManager::reset() {
delete _requester;
_requester = 0;
+ _initBacklogRequested = false;
_buffersRequested.clear();
}
void dispatchMessages(const MessageList &messages, bool sort = false);
BacklogRequester *_requester;
+ bool _initBacklogRequested;
QSet<BufferId> _buffersRequested;
};
#include "clientbufferviewmanager.h"
#include "clientbufferviewconfig.h"
+#include "client.h"
+#include "networkmodel.h"
INIT_SYNCABLE_OBJECT(ClientBufferViewManager)
ClientBufferViewManager::ClientBufferViewManager(SignalProxy *proxy, QObject *parent)
ClientBufferViewConfig *ClientBufferViewManager::clientBufferViewConfig(int bufferViewId) const {
return static_cast<ClientBufferViewConfig *>(bufferViewConfig(bufferViewId));
}
+
+void ClientBufferViewManager::setInitialized() {
+ if(bufferViewConfigs().isEmpty()) {
+ BufferViewConfig config(-1);
+ config.setBufferViewName(tr("All Chats"));
+ config.initSetBufferList(Client::networkModel()->allBufferIdsSorted());
+ requestCreateBufferView(config.toVariantMap());
+ }
+ BufferViewManager::setInitialized();
+}
QList<ClientBufferViewConfig *> clientBufferViewConfigs() const;
ClientBufferViewConfig *clientBufferViewConfig(int bufferViewId) const;
+public slots:
+ virtual void setInitialized();
+
protected:
virtual BufferViewConfig *bufferViewConfigFactory(int bufferViewConfigId);
};
return keyMap;
}
+void CoreAccountSettings::setBufferViewOverlay(const QSet<int> &viewIds) {
+ QVariantList variants;
+ foreach(int viewId, viewIds) {
+ variants << qVariantFromValue(viewId);
+ }
+ setAccountValue("BufferViewOverlay", variants);
+}
+
+QSet<int> CoreAccountSettings::bufferViewOverlay() {
+ QSet<int> viewIds;
+ QVariantList variants = accountValue("BufferViewOverlay").toList();
+ QVariantList::const_iterator iter = variants.constBegin();
+ for(QVariantList::const_iterator iter = variants.constBegin(); iter != variants.constEnd(); iter++) {
+ viewIds << iter->toInt();
+ }
+ return viewIds;
+}
+
void CoreAccountSettings::removeAccount(AccountId id) {
removeLocalKey(QString("%1").arg(id.toInt()));
}
void setJumpKeyMap(const QHash<int, BufferId> &keyMap);
QHash<int, BufferId> jumpKeyMap();
+ void setBufferViewOverlay(const QSet<int> &viewIds);
+ QSet<int> bufferViewOverlay();
+
void setAccountValue(const QString &key, const QVariant &data);
QVariant accountValue(const QString &key, const QVariant &def = QVariant());
}
void MainWin::bufferViewToggled(bool enabled) {
+ if(!enabled && !isVisible()) {
+ // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
+ // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
+ return;
+ }
QAction *action = qobject_cast<QAction *>(sender());
Q_ASSERT(action);
BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
if(enabled) {
Client::bufferViewOverlay()->addView(dock->bufferViewId());
- BufferViewConfig *config = dock->config();
- if(config && config->isInitialized()) {
- BufferIdList buffers;
- if(config->networkId().isValid()) {
- foreach(BufferId bufferId, config->bufferList()) {
- if(Client::networkModel()->networkId(bufferId) == config->networkId())
- buffers << bufferId;
- }
- foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
- if(Client::networkModel()->networkId(bufferId) == config->networkId())
- buffers << bufferId;
- }
- } else {
- buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
- }
- Client::backlogManager()->checkForBacklog(buffers);
- }
} else {
Client::bufferViewOverlay()->removeView(dock->bufferViewId());
}
if(dock && actionData.toInt() != -1) {
removeAction(action);
_bufferViews.removeAll(dock);
- Client::bufferViewOverlay()->removeView(dock->bufferViewId());
dock->deleteLater();
}
}