-void CoreConnectDlg::initPhaseSocketState(QAbstractSocket::SocketState state) {
- QString s;
- QString host = accountData["Host"].toString();
- switch(state) {
- case QAbstractSocket::UnconnectedState: s = tr("Not connected to %1.").arg(host); break;
- case QAbstractSocket::HostLookupState: s = tr("Looking up %1...").arg(host); break;
- case QAbstractSocket::ConnectingState: s = tr("Connecting to %1...").arg(host); break;
- case QAbstractSocket::ConnectedState: s = tr("Connected to %1").arg(host); break;
- default: s = tr("Unknown connection state to %1"); break;
- }
- ui.connectLabel->setText(s);
-}
-
-void CoreConnectDlg::restartPhaseNull() {
- doingAutoConnect = false;
- ui.stackedWidget->setCurrentWidget(ui.accountPage);
- clientSyncer->disconnectFromCore();
-}
-
-/*********************************************************
- * Phase Two: Login
- *********************************************************/
-
-void CoreConnectDlg::startLogin() {
- ui.connectIcon->setPixmap(QPixmap::fromImage(QImage(":/22x22/actions/network-connect")));
- ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
- //ui.loginStack->setMinimumSize(ui.loginStack->sizeHint()); ui.loginStack->updateGeometry();
- ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
- ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
- ui.loginButtonBox->button(QDialogButtonBox::Ok)->setFocus();
- if(!accountData["User"].toString().isEmpty()) {
- ui.user->setText(accountData["User"].toString());
- if(accountData["RememberPasswd"].toBool()) {
- ui.password->setText(accountData["Password"].toString());
- ui.rememberPasswd->setChecked(true);
- ui.loginButtonBox->button(QDialogButtonBox::Ok)->setFocus();
- } else {
- ui.rememberPasswd->setChecked(false);
- ui.password->setFocus();
- }
- } else ui.user->setFocus();
- disconnect(ui.loginButtonBox, 0, this, 0);
- connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(doLogin()));
- connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
- if(doingAutoConnect) doLogin();
-}
-
-void CoreConnectDlg::doLogin() {
- QVariantMap loginData;
- loginData["User"] = ui.user->text();
- loginData["Password"] = ui.password->text();
- loginData["RememberPasswd"] = ui.rememberPasswd->isChecked();
- doLogin(loginData);
-}
-
-void CoreConnectDlg::doLogin(const QVariantMap &loginData) {
- disconnect(ui.loginButtonBox, 0, this, 0);
- connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(doLogin()));
- connect(ui.loginButtonBox, SIGNAL(rejected()), this, SLOT(restartPhaseNull()));
- ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
- ui.loginGroup->setTitle(tr("Logging in..."));
- ui.user->setDisabled(true);
- ui.password->setDisabled(true);
- ui.rememberPasswd->setDisabled(true);
- ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDisabled(true);
- accountData["User"] = loginData["User"];
- accountData["RememberPasswd"] = loginData["RememberPasswd"];
- if(loginData["RememberPasswd"].toBool()) accountData["Password"] = loginData["Password"];
- else accountData.remove("Password");
- ui.user->setText(loginData["User"].toString());
- ui.password->setText(loginData["Password"].toString());
- ui.rememberPasswd->setChecked(loginData["RememberPasswd"].toBool());
- CoreAccountSettings s;
- s.storeAccountData(account, accountData);
- clientSyncer->loginToCore(loginData["User"].toString(), loginData["Password"].toString());
-}
-
-void CoreConnectDlg::setLoginWidgetStates() {
- ui.loginButtonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.user->text().isEmpty() || ui.password->text().isEmpty());
-}
-
-void CoreConnectDlg::loginFailed(const QString &error) {
- if(wizard) {
- wizard->reject();
- }
- ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
- ui.loginGroup->setTitle(tr("Login"));
- ui.user->setEnabled(true);
- ui.password->setEnabled(true);
- ui.rememberPasswd->setEnabled(true);
- ui.coreInfoLabel->setText(error);
- ui.loginButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
- ui.password->setFocus();
- doingAutoConnect = false;
-}
-
-void CoreConnectDlg::startCoreConfig(const QVariantList &backends) {
- storageBackends = backends;
- ui.loginStack->setCurrentWidget(ui.coreConfigPage);
-
- //on_launchCoreConfigWizard_clicked();
-
-}
-
-void CoreConnectDlg::on_launchCoreConfigWizard_clicked() {
- Q_ASSERT(!wizard);
- wizard = new CoreConfigWizard(storageBackends, this);
- connect(wizard, SIGNAL(setupCore(const QVariant &)), clientSyncer, SLOT(doCoreSetup(const QVariant &)));
- connect(wizard, SIGNAL(loginToCore(const QVariantMap &)), this, SLOT(doLogin(const QVariantMap &)));
- connect(clientSyncer, SIGNAL(coreSetupSuccess()), wizard, SLOT(coreSetupSuccess()));
- connect(clientSyncer, SIGNAL(coreSetupFailed(const QString &)), wizard, SLOT(coreSetupFailed(const QString &)));
- connect(wizard, SIGNAL(accepted()), this, SLOT(configWizardAccepted()));
- connect(wizard, SIGNAL(rejected()), this, SLOT(configWizardRejected()));
- connect(clientSyncer, SIGNAL(loginSuccess()), wizard, SLOT(loginSuccess()));
- connect(clientSyncer, SIGNAL(syncFinished()), wizard, SLOT(syncFinished()));
- wizard->show();
-}
-
-void CoreConnectDlg::configWizardAccepted() {
-
- wizard->deleteLater();
- wizard = 0;