X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=b599c9aab04ced81dd86d5d1f608bda3b49247ee;hp=b17fa28ae0fc8a230984b02b31aea896264e8b9d;hb=93800658bba5dcbeca7f3deb02dd7091c455efe8;hpb=0d49f7e83bd1055711e66aa880f3a0d62f7eefc9 diff --git a/src/client/client.cpp b/src/client/client.cpp index b17fa28a..b599c9aa 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -25,20 +25,25 @@ #include "buffermodel.h" #include "buffersettings.h" #include "buffersyncer.h" +#include "bufferviewconfig.h" #include "bufferviewmanager.h" #include "clientbacklogmanager.h" #include "clientirclisthelper.h" -#include "identity.h" +#include "clientidentity.h" #include "ircchannel.h" #include "ircuser.h" #include "message.h" #include "messagemodel.h" #include "network.h" #include "networkmodel.h" +#include "quassel.h" #include "quasselui.h" #include "signalproxy.h" #include "util.h" +#include +#include + QPointer Client::instanceptr = 0; AccountId Client::_currentCoreAccount = 0; @@ -52,21 +57,21 @@ Client *Client::instance() { void Client::destroy() { if(instanceptr) { - delete instanceptr->mainUi; + delete instanceptr->mainUi(); instanceptr->deleteLater(); instanceptr = 0; } } void Client::init(AbstractUi *ui) { - instance()->mainUi = ui; + instance()->_mainUi = ui; instance()->init(); } Client::Client(QObject *parent) : QObject(parent), _signalProxy(new SignalProxy(SignalProxy::Client, this)), - mainUi(0), + _mainUi(0), _networkModel(0), _bufferModel(0), _bufferSyncer(0), @@ -76,7 +81,9 @@ Client::Client(QObject *parent) _messageModel(0), _messageProcessor(0), _connectedToCore(false), - _syncedToCore(false) + _syncedToCore(false), + _internalCore(false), + _debugLog(&_debugLogBuffer) { _signalProxy->synchronize(_ircListHelper); } @@ -93,8 +100,8 @@ void Client::init() { _networkModel, SLOT(networkRemoved(NetworkId))); _bufferModel = new BufferModel(_networkModel); - _messageModel = mainUi->createMessageModel(this); - _messageProcessor = mainUi->createMessageProcessor(this); + _messageModel = mainUi()->createMessageModel(this); + _messageProcessor = mainUi()->createMessageProcessor(this); SignalProxy *p = signalProxy(); @@ -105,7 +112,7 @@ void Client::init() { p->attachSignal(this, SIGNAL(sendInput(BufferInfo, QString))); p->attachSignal(this, SIGNAL(requestNetworkStates())); - p->attachSignal(this, SIGNAL(requestCreateIdentity(const Identity &)), SIGNAL(createIdentity(const Identity &))); + p->attachSignal(this, SIGNAL(requestCreateIdentity(const Identity &, const QVariantMap &)), SIGNAL(createIdentity(const Identity &, const QVariantMap &))); p->attachSignal(this, SIGNAL(requestRemoveIdentity(IdentityId)), SIGNAL(removeIdentity(IdentityId))); p->attachSlot(SIGNAL(identityCreated(const Identity &)), this, SLOT(coreIdentityCreated(const Identity &))); p->attachSlot(SIGNAL(identityRemoved(IdentityId)), this, SLOT(coreIdentityRemoved(IdentityId))); @@ -117,15 +124,22 @@ void Client::init() { 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())); - connect(this, SIGNAL(disconnected()), mainUi, 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())); + connect(this, SIGNAL(disconnected()), mainUi(), SLOT(disconnectedFromCore())); + // attach backlog manager + p->synchronize(backlogManager()); + connect(backlogManager(), SIGNAL(messagesReceived(BufferId, int)), _messageModel, SLOT(messagesReceived(BufferId, int))); } /*** public static methods ***/ +AbstractUi *Client::mainUi() { + return instance()->_mainUi; +} + AccountId Client::currentCoreAccount() { return _currentCoreAccount; } @@ -202,13 +216,18 @@ QList Client::identityIds() { return instance()->_identities.keys(); } -const Identity * Client::identity(IdentityId id) { +const Identity *Client::identity(IdentityId id) { if(instance()->_identities.contains(id)) return instance()->_identities[id]; else return 0; } -void Client::createIdentity(const Identity &id) { - emit instance()->requestCreateIdentity(id); +void Client::createIdentity(const CertIdentity &id) { + QVariantMap additional; +#ifdef HAVE_SSL + additional["KeyPem"] = id.sslKey().toPem(); + additional["CertPem"] = id.sslCert().toPem(); +#endif + emit instance()->requestCreateIdentity(id, additional); } void Client::updateIdentity(IdentityId id, const QVariantMap &ser) { @@ -251,20 +270,18 @@ void Client::userInput(BufferInfo bufferInfo, QString message) { /*** core connection stuff ***/ -void Client::setConnectedToCore(QIODevice *socket, AccountId id) { - // 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::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); + } + _internalCore = !socket; _connectedToCore = true; setCurrentCoreAccount(id); } -void Client::setConnectedToInternalCore() { - _connectedToCore = true; - setCurrentCoreAccount(AccountId()); -} - void Client::setSyncedToCore() { // create buffersyncer Q_ASSERT(!_bufferSyncer); @@ -272,19 +289,48 @@ void Client::setSyncedToCore() { connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), _networkModel, SLOT(setLastSeenMsgId(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))); + connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), _messageModel, SLOT(buffersPermanentlyMerged(BufferId, BufferId))); + connect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + connect(networkModel(), SIGNAL(setLastSeenMsg(BufferId, MsgId)), bufferSyncer(), SLOT(requestSetLastSeenMsg(BufferId, const MsgId &))); signalProxy()->synchronize(bufferSyncer()); - // attach backlog manager - signalProxy()->synchronize(backlogManager()); - // create a new BufferViewManager + Q_ASSERT(!_bufferViewManager); _bufferViewManager = new BufferViewManager(signalProxy(), this); + connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + connect(bufferViewManager(), SIGNAL(initDone()), this, SLOT(createDefautBufferView())); + + createDefaultIdentity(); _syncedToCore = true; emit connected(); emit coreConnectionStateChanged(true); } +void Client::requestInitialBacklog() { + if(bufferViewManager()->isInitialized() && bufferSyncer()->isInitialized()) + Client::backlogManager()->requestInitialBacklog(); +} + +void Client::createDefautBufferView() { + 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::setSecuredConnection() { emit securedConnection(); } @@ -331,10 +377,10 @@ void Client::disconnectedFromCore() { } Q_ASSERT(_networks.isEmpty()); - QHash::iterator idIter = _identities.begin(); + QHash::iterator idIter = _identities.begin(); while(idIter != _identities.end()) { + emit identityRemoved(idIter.key()); Identity *id = idIter.value(); - emit identityRemoved(id->id()); idIter = _identities.erase(idIter); id->deleteLater(); } @@ -362,9 +408,9 @@ void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) { //recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg))); } -void Client::recvMessage(const Message &msg_) { - Message msg = msg_; - messageProcessor()->process(msg); +void Client::recvMessage(const Message &msg) { + Message msg_ = msg; + messageProcessor()->process(msg_); } void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) { @@ -378,6 +424,18 @@ void Client::removeBuffer(BufferId id) { bufferSyncer()->requestRemoveBuffer(id); } +void Client::renameBuffer(BufferId bufferId, const QString &newName) { + if(!bufferSyncer()) + return; + bufferSyncer()->requestRenameBuffer(bufferId, newName); +} + +void Client::mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2) { + if(!bufferSyncer()) + return; + bufferSyncer()->requestMergeBuffersPermanently(bufferId1, bufferId2); +} + void Client::bufferRemoved(BufferId bufferId) { // select a sane buffer (status buffer) /* we have to manually select a buffer because otherwise inconsitent changes @@ -402,3 +460,22 @@ void Client::bufferRenamed(BufferId bufferId, const QString &newName) { networkModel()->setData(bufferIndex, newName, Qt::DisplayRole); } } + +void Client::buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2) { + QModelIndex idx = networkModel()->bufferIndex(bufferId1); + bufferModel()->setCurrentIndex(bufferModel()->mapFromSource(idx)); + networkModel()->removeBuffer(bufferId2); +} + +void Client::logMessage(QtMsgType type, const char *msg) { + fprintf(stderr, "%s\n", msg); + fflush(stderr); + if(type == QtFatalMsg) { + Quassel::logFatalMessage(msg); + } else { + QString msgString = QString("%1\n").arg(msg); + instance()->_debugLog << msgString; + emit instance()->logUpdated(msgString); + } +} +