From 4649188af29520951aa7485c577aa7ab912bef1a Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Thu, 20 Nov 2008 01:21:45 +0100 Subject: [PATCH] properly saving the layout when using the internal core --- src/client/client.cpp | 17 +++++++---------- src/client/client.h | 3 +-- src/client/clientsyncer.cpp | 7 ++++--- src/client/clientsyncer.h | 8 +++++--- src/qtui/coreconnectdlg.cpp | 32 ++++++++++++++++++++++---------- src/qtui/coreconnectdlg.h | 3 +++ 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index bac736b0..0ccde849 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -259,20 +259,17 @@ 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); + } _connectedToCore = true; setCurrentCoreAccount(id); } -void Client::setConnectedToInternalCore() { - _connectedToCore = true; - setCurrentCoreAccount(AccountId()); -} - void Client::setSyncedToCore() { // create buffersyncer Q_ASSERT(!_bufferSyncer); diff --git a/src/client/client.h b/src/client/client.h index 9f881d11..8a68d997 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -174,8 +174,7 @@ private slots: void coreNetworkCreated(NetworkId); void coreNetworkRemoved(NetworkId); - void setConnectedToCore(QIODevice *socket, AccountId id); - void setConnectedToInternalCore(); + void setConnectedToCore(AccountId id, QIODevice *socket = 0); void setSyncedToCore(); void setSecuredConnection(); diff --git a/src/client/clientsyncer.cpp b/src/client/clientsyncer.cpp index 02c9a203..139f44b3 100644 --- a/src/client/clientsyncer.cpp +++ b/src/client/clientsyncer.cpp @@ -169,7 +169,8 @@ void ClientSyncer::coreSocketConnected() { SignalProxy::writeDataToDevice(socket, clientInit); } -void ClientSyncer::useInternalCore() { +void ClientSyncer::useInternalCore(AccountId internalAccountId) { + coreConnectionInfo["AccountId"] = QVariant::fromValue(internalAccountId); emit startInternalCore(); emit connectToInternalCore(Client::instance()->signalProxy()); } @@ -248,7 +249,7 @@ void ClientSyncer::loginToCore(const QString &user, const QString &passwd) { void ClientSyncer::internalSessionStateReceived(const QVariant &packedState) { QVariantMap state = packedState.toMap(); emit sessionProgress(1, 1); - Client::instance()->setConnectedToInternalCore(); + Client::instance()->setConnectedToCore(coreConnectionInfo["AccountId"].value()); syncToCore(state); } @@ -256,7 +257,7 @@ void ClientSyncer::sessionStateReceived(const QVariantMap &state) { emit sessionProgress(1, 1); disconnect(this, SIGNAL(recvPartialItem(quint32, quint32)), this, SIGNAL(sessionProgress(quint32, quint32))); disconnect(socket, 0, this, 0); // rest of communication happens through SignalProxy - Client::instance()->setConnectedToCore(socket, coreConnectionInfo["AccountId"].value()); + Client::instance()->setConnectedToCore(coreConnectionInfo["AccountId"].value(), socket); syncToCore(state); } diff --git a/src/client/clientsyncer.h b/src/client/clientsyncer.h index d321451a..7f07de39 100644 --- a/src/client/clientsyncer.h +++ b/src/client/clientsyncer.h @@ -18,8 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _CLIENTSYNCER_H_ -#define _CLIENTSYNCER_H_ +#ifndef CLIENTSYNCER_H_ +#define CLIENTSYNCER_H_ #include #include @@ -31,6 +31,8 @@ # include #endif +#include "types.h" + class IrcUser; class IrcChannel; class SignalProxy; @@ -68,7 +70,7 @@ public slots: void connectToCore(const QVariantMap &); void loginToCore(const QString &user, const QString &passwd); void disconnectFromCore(); - void useInternalCore(); + void useInternalCore(AccountId internalAccountId); private slots: void coreSocketError(QAbstractSocket::SocketError); diff --git a/src/qtui/coreconnectdlg.cpp b/src/qtui/coreconnectdlg.cpp index 954be2d1..dab92a27 100644 --- a/src/qtui/coreconnectdlg.cpp +++ b/src/qtui/coreconnectdlg.cpp @@ -32,7 +32,8 @@ #include "quassel.h" CoreConnectDlg::CoreConnectDlg(bool autoconnect, QWidget *parent) - : QDialog(parent) + : QDialog(parent), + _internalAccountId(0) { ui.setupUi(this); ui.editAccount->setIcon(SmallIcon("document-properties")); @@ -65,6 +66,10 @@ CoreConnectDlg::CoreConnectDlg(bool autoconnect, QWidget *parent) foreach(AccountId id, s.knownAccounts()) { if(!id.isValid()) continue; QVariantMap data = s.retrieveAccountData(id); + if(data.contains("InternalAccount") && data["InternalAccount"].toBool()) { + _internalAccountId = id; + continue; + } data["AccountId"] = QVariant::fromValue(id); accounts[id] = data; QListWidgetItem *item = new QListWidgetItem(data["AccountName"].toString(), ui.accountList); @@ -150,14 +155,7 @@ void CoreConnectDlg::on_addAccount_clicked() { for(int i = 0; i < ui.accountList->count(); i++) existing << ui.accountList->item(i)->text(); CoreAccountEditDlg dlg(0, QVariantMap(), existing, this); if(dlg.exec() == QDialog::Accepted) { - // find free ID - AccountId id = accounts.count() + 1; - for(AccountId i = 1; i <= accounts.count(); i++) { - if(!accounts.keys().contains(i)) { - id = i; - break; - } - } + AccountId id = findFreeAccountId(); QVariantMap data = dlg.accountData(); data["AccountId"] = QVariant::fromValue(id); accounts[id] = data; @@ -221,7 +219,14 @@ void CoreConnectDlg::on_accountButtonBox_accepted() { } void CoreConnectDlg::on_useInternalCore_clicked() { - clientSyncer->useInternalCore(); + if(!_internalAccountId.isValid()) { + _internalAccountId = findFreeAccountId(); + QVariantMap data; + data["InternalAccount"] = true; + CoreAccountSettings accountSettings; + accountSettings.storeAccountData(_internalAccountId, data); + } + clientSyncer->useInternalCore(_internalAccountId); startSync(); } @@ -450,6 +455,13 @@ void CoreConnectDlg::syncFinished() { } } +AccountId CoreConnectDlg::findFreeAccountId() { + for(AccountId i = 1;; i++) { + if(!accounts.contains(i) && i != _internalAccountId) + return i; + } +} + /***************************************************************************************** * CoreAccountEditDlg *****************************************************************************************/ diff --git a/src/qtui/coreconnectdlg.h b/src/qtui/coreconnectdlg.h index 7abaac9c..3fb8b99e 100644 --- a/src/qtui/coreconnectdlg.h +++ b/src/qtui/coreconnectdlg.h @@ -86,10 +86,13 @@ private slots: void coreNetworksProgress(quint32, quint32); private: + AccountId findFreeAccountId(); + Ui::CoreConnectDlg ui; AccountId autoConnectAccount; QHash accounts; + AccountId _internalAccountId; QVariantMap accountData; AccountId account; -- 2.20.1