Make monolithic client work again
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 24 Nov 2009 22:38:57 +0000 (23:38 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 23:39:41 +0000 (00:39 +0100)
src/client/clientsettings.cpp
src/client/clientsettings.h
src/client/coreaccountmodel.cpp
src/client/coreconnection.cpp
src/client/coreconnection.h
src/qtui/monoapplication.cpp
src/qtui/settingspages/coreaccountsettingspage.cpp

index 55df8c4..42c26cd 100644 (file)
@@ -170,6 +170,10 @@ void CoreAccountSettings::removeAccount(AccountId id) {
   removeLocalKey(QString("%1").arg(id.toInt()));
 }
 
   removeLocalKey(QString("%1").arg(id.toInt()));
 }
 
+void CoreAccountSettings::clearAccounts() {
+  foreach(const QString &key, localChildGroups())
+    removeLocalKey(key);
+}
 
 /***********************************************************************************************/
 // NotificationSettings:
 
 /***********************************************************************************************/
 // NotificationSettings:
index bf24410..0e4b410 100644 (file)
@@ -64,6 +64,8 @@ public:
   bool autoConnectToFixedAccount();
   void setAutoConnectToFixedAccount(bool);
 
   bool autoConnectToFixedAccount();
   void setAutoConnectToFixedAccount(bool);
 
+  void clearAccounts();
+
   void storeAccountData(AccountId id, const QVariantMap &data);
   QVariantMap retrieveAccountData(AccountId);
   void removeAccount(AccountId);
   void storeAccountData(AccountId id, const QVariantMap &data);
   QVariantMap retrieveAccountData(AccountId);
   void removeAccount(AccountId);
index bcd69dc..1734c78 100644 (file)
@@ -58,17 +58,16 @@ void CoreAccountModel::load() {
     // Make sure we have an internal account in monolithic mode
     CoreAccount intAcc;
     intAcc.setInternal(true);
     // Make sure we have an internal account in monolithic mode
     CoreAccount intAcc;
     intAcc.setInternal(true);
-    insertAccount(intAcc);
+    intAcc.setAccountName(tr("Internal Core"));
+    _internalAccount = createOrUpdateAccount(intAcc);
   }
 }
 
 void CoreAccountModel::save() {
   CoreAccountSettings s;
   }
 }
 
 void CoreAccountModel::save() {
   CoreAccountSettings s;
+  s.clearAccounts();
   foreach(const CoreAccount &acc, accounts()) {
   foreach(const CoreAccount &acc, accounts()) {
-    if(acc.isInternal())
-      continue;  // FIXME don't save internal for now - but make sure to handle this correctly once mono can do remotes!
-                 //       we'll have to ensure that autoConnectAccount works with internal as well then
-    QVariantMap map = acc.toVariantMap(true);  // TODO Hook into kwallet/password saving stuff
+    QVariantMap map = acc.toVariantMap(false);  // TODO Hook into kwallet/password saving stuff
     s.storeAccountData(acc.accountId(), map);
   }
 }
     s.storeAccountData(acc.accountId(), map);
   }
 }
@@ -167,8 +166,6 @@ AccountId CoreAccountModel::createOrUpdateAccount(const CoreAccount &newAcc) {
 
 void CoreAccountModel::insertAccount(const CoreAccount &acc) {
   if(acc.isInternal()) {
 
 void CoreAccountModel::insertAccount(const CoreAccount &acc) {
   if(acc.isInternal()) {
-    if(Quassel::runMode() == Quassel::Monolithic)
-      return;
     if(internalAccount().isValid()) {
       qWarning() << "Trying to insert a second internal account in CoreAccountModel, ignoring";
       return;
     if(internalAccount().isValid()) {
       qWarning() << "Trying to insert a second internal account in CoreAccountModel, ignoring";
       return;
index f290756..0b342ed 100644 (file)
@@ -99,9 +99,9 @@ void CoreConnection::resetConnection() {
 
   _netsToSync.clear();
   _numNetsToSync = 0;
 
   _netsToSync.clear();
   _numNetsToSync = 0;
-  _state = Disconnected;
 
   setProgressMaximum(-1); // disable
 
   setProgressMaximum(-1); // disable
+  setState(Disconnected);
   emit connectionMsg(tr("Disconnected from core."));
 }
 
   emit connectionMsg(tr("Disconnected from core."));
 }
 
@@ -159,6 +159,8 @@ void CoreConnection::setState(ConnectionState state) {
   if(state != _state) {
     _state = state;
     emit stateChanged(state);
   if(state != _state) {
     _state = state;
     emit stateChanged(state);
+    if(state == Disconnected)
+      emit disconnected();
   }
 }
 
   }
 }
 
@@ -178,7 +180,6 @@ void CoreConnection::coreSocketError(QAbstractSocket::SocketError) {
 }
 
 void CoreConnection::coreSocketDisconnected() {
 }
 
 void CoreConnection::coreSocketDisconnected() {
-  setState(Disconnected);
   emit disconnected();
   resetConnection();
   // FIXME handle disconnects gracefully
   emit disconnected();
   resetConnection();
   // FIXME handle disconnects gracefully
@@ -244,20 +245,30 @@ bool CoreConnection::connectToCore(AccountId accId) {
 
   CoreAccountSettings s;
 
 
   CoreAccountSettings s;
 
-  if(!accId.isValid()) {
-    // check our settings and figure out what to do
-    if(!s.autoConnectOnStartup())
-      return false;
-    if(s.autoConnectToFixedAccount())
-      accId = s.autoConnectAccount();
-    else
-      accId = s.lastAccount();
-    if(!accId.isValid())
+  // FIXME: Don't force connection to internal core in mono client
+  if(Quassel::runMode() == Quassel::Monolithic) {
+    _account = accountModel()->account(accountModel()->internalAccount());
+    Q_ASSERT(_account.isValid());
+  } else {
+    if(!accId.isValid()) {
+      // check our settings and figure out what to do
+      if(!s.autoConnectOnStartup())
+        return false;
+      if(s.autoConnectToFixedAccount())
+        accId = s.autoConnectAccount();
+      else
+        accId = s.lastAccount();
+      if(!accId.isValid())
+        return false;
+    }
+    _account = accountModel()->account(accId);
+    if(!_account.accountId().isValid()) {
       return false;
       return false;
-  }
-  _account = accountModel()->account(accId);
-  if(!_account.accountId().isValid()) {
-    return false;
+    }
+    if(Quassel::runMode() != Quassel::Monolithic) {
+      if(_account.isInternal())
+        return false;
+    }
   }
 
   s.setLastAccount(accId);
   }
 
   s.setLastAccount(accId);
@@ -268,6 +279,16 @@ bool CoreConnection::connectToCore(AccountId accId) {
 void CoreConnection::connectToCurrentAccount() {
   resetConnection();
 
 void CoreConnection::connectToCurrentAccount() {
   resetConnection();
 
+  if(currentAccount().isInternal()) {
+    if(Quassel::runMode() != Quassel::Monolithic) {
+      qWarning() << "Cannot connect to internal core in client-only mode!";
+      return;
+    }
+    emit startInternalCore();
+    emit connectToInternalCore(Client::instance()->signalProxy());
+    return;
+  }
+
   Q_ASSERT(!_socket);
 #ifdef HAVE_SSL
   QSslSocket *sock = new QSslSocket(Client::instance());
   Q_ASSERT(!_socket);
 #ifdef HAVE_SSL
   QSslSocket *sock = new QSslSocket(Client::instance());
@@ -408,10 +429,16 @@ void CoreConnection::sessionStateReceived(const QVariantMap &state) {
   disconnect(_socket, SIGNAL(readyRead()), this, 0);
   disconnect(_socket, SIGNAL(connected()), this, 0);
 
   disconnect(_socket, SIGNAL(readyRead()), this, 0);
   disconnect(_socket, SIGNAL(connected()), this, 0);
 
-  //Client::instance()->setConnectedToCore(currentAccount().accountId(), _socket);
   syncToCore(state);
 }
 
   syncToCore(state);
 }
 
+void CoreConnection::internalSessionStateReceived(const QVariant &packedState) {
+  updateProgress(100, 100);
+
+  setState(Synchronizing);
+  syncToCore(packedState.toMap());
+}
+
 void CoreConnection::syncToCore(const QVariantMap &sessionState) {
   setProgressText(tr("Receiving network states"));
   updateProgress(0, 100);
 void CoreConnection::syncToCore(const QVariantMap &sessionState) {
   setProgressText(tr("Receiving network states"));
   updateProgress(0, 100);
index a74c12d..f1afab9 100644 (file)
@@ -36,6 +36,7 @@
 
 class CoreAccountModel;
 class Network;
 
 class CoreAccountModel;
 class Network;
+class SignalProxy;
 
 class CoreConnection : public QObject {
   Q_OBJECT
 
 class CoreConnection : public QObject {
   Q_OBJECT
@@ -83,6 +84,8 @@ signals:
   void progressTextChanged(const QString &);
 
   void startCoreSetup(const QVariantList &);
   void progressTextChanged(const QString &);
 
   void startCoreSetup(const QVariantList &);
+  void startInternalCore();
+  void connectToInternalCore(SignalProxy *proxy);
 
   // This signal MUST be handled synchronously!
   void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString());
 
   // This signal MUST be handled synchronously!
   void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString());
@@ -105,7 +108,7 @@ private slots:
   void checkSyncState();
 
   void syncToCore(const QVariantMap &sessionState);
   void checkSyncState();
 
   void syncToCore(const QVariantMap &sessionState);
-  //void internalSessionStateReceived(const QVariant &packedState);
+  void internalSessionStateReceived(const QVariant &packedState);
   void sessionStateReceived(const QVariantMap &state);
 
   void setWarningsHandler(const char *slot);
   void sessionStateReceived(const QVariantMap &state);
 
   void setWarningsHandler(const char *slot);
index 60df4c5..5ed2611 100644 (file)
@@ -39,9 +39,10 @@ bool MonolithicApplication::init() {
   if(!Quassel::init()) // parse args
     return false;
 
   if(!Quassel::init()) // parse args
     return false;
 
+  connect(Client::coreConnection(), SIGNAL(startInternalCore()), SLOT(startInternalCore()));
+
   if(isOptionSet("port")) {
   if(isOptionSet("port")) {
-    _internal->init();
-    _internalInitDone = true;
+    startInternalCore();
   }
 
   return QtUiApplication::init();
   }
 
   return QtUiApplication::init();
@@ -59,6 +60,7 @@ void MonolithicApplication::startInternalCore() {
     _internalInitDone = true;
   }
   Core *core = Core::instance();
     _internalInitDone = true;
   }
   Core *core = Core::instance();
-  //connect(syncer, SIGNAL(connectToInternalCore(SignalProxy *)), core, SLOT(setupInternalClientSession(SignalProxy *)));
-  //connect(core, SIGNAL(sessionState(const QVariant &)), syncer, SLOT(internalSessionStateReceived(const QVariant &)));
+  CoreConnection *connection = Client::coreConnection();
+  connect(connection, SIGNAL(connectToInternalCore(SignalProxy *)), core, SLOT(setupInternalClientSession(SignalProxy *)));
+  connect(core, SIGNAL(sessionState(const QVariant &)), connection, SLOT(internalSessionStateReceived(const QVariant &)));
 }
 }
index 0cee736..be08cb5 100644 (file)
@@ -54,10 +54,24 @@ void CoreAccountSettingsPage::setStandAlone(bool standalone) {
 
 void CoreAccountSettingsPage::load() {
   _model->update(Client::coreAccountModel());
 
 void CoreAccountSettingsPage::load() {
   _model->update(Client::coreAccountModel());
-
   SettingsPage::load();
   SettingsPage::load();
+
+  CoreAccountSettings s;
+
+  if(Quassel::runMode() != Quassel::Monolithic) {
+    // make sure we don't have selected the internal account as autoconnect account
+
+    if(s.autoConnectOnStartup() && s.autoConnectToFixedAccount()) {
+      CoreAccount acc = _model->account(s.autoConnectAccount());
+      if(acc.isInternal())
+        ui.autoConnectOnStartup->setChecked(false);
+    }
+  }
   ui.accountView->setCurrentIndex(model()->index(0, 0));
   ui.accountView->selectionModel()->select(model()->index(0, 0), QItemSelectionModel::Select);
   ui.accountView->setCurrentIndex(model()->index(0, 0));
   ui.accountView->selectionModel()->select(model()->index(0, 0), QItemSelectionModel::Select);
+
+  QModelIndex idx = model()->accountIndex(s.autoConnectAccount());
+  ui.autoConnectAccount->setCurrentIndex(idx.isValid() ? idx.row() : 0);
   setWidgetStates();
 }
 
   setWidgetStates();
 }
 
@@ -74,7 +88,6 @@ QVariant CoreAccountSettingsPage::loadAutoWidgetValue(const QString &widgetName)
     AccountId id = s.autoConnectAccount();
     if(!id.isValid())
       return QVariant();
     AccountId id = s.autoConnectAccount();
     if(!id.isValid())
       return QVariant();
-    ui.autoConnectAccount->setCurrentIndex(model()->accountIndex(id).row());
     return id.toInt();
   }
   return SettingsPage::loadAutoWidgetValue(widgetName);
     return id.toInt();
   }
   return SettingsPage::loadAutoWidgetValue(widgetName);
@@ -180,10 +193,11 @@ void CoreAccountSettingsPage::on_accountView_doubleClicked(const QModelIndex &in
 }
 
 void CoreAccountSettingsPage::setWidgetStates() {
 }
 
 void CoreAccountSettingsPage::setWidgetStates() {
-  bool selected = ui.accountView->selectionModel()->selectedIndexes().count();
+  AccountId accId = selectedAccount();
+  bool editable = accId.isValid() && accId != model()->internalAccount();
 
 
-  ui.editAccountButton->setEnabled(selected);
-  ui.deleteAccountButton->setEnabled(selected);
+  ui.editAccountButton->setEnabled(editable);
+  ui.deleteAccountButton->setEnabled(editable);
 }
 
 void CoreAccountSettingsPage::widgetHasChanged() {
 }
 
 void CoreAccountSettingsPage::widgetHasChanged() {