コード例 #1
0
void AccountModifyDlg::save()
{
	/*if(pa && le_name->text().isEmpty()) {
		QMessageBox::information(this, tr("Error"), tr("You must specify a name for the account before you may save it."));
		return;
	}*/

	Jid newJid( JIDUtil::accountFromString(le_jid->text().trimmed()) );
	if ( newJid.node().isEmpty() || newJid.domain().isEmpty() ) {
		if (!PsiOptions::instance()->getOption("options.account.domain").toString().isEmpty()) {
			QMessageBox::information(this, tr("Error"), tr("<i>Username</i> is invalid."));
		}
		else {
			QMessageBox::information(this, tr("Error"), tr("<i>Jabber ID</i> must be specified in the format <i>user@host</i>."));
		}
		return;
	}

	// do not allow duplicate account names
	if (!pa && le_name->text().isEmpty())
		le_name->setText(newJid.domain());
	QString def = le_name->text();
	QString aname = def;
	int n = 0;
	{
		foreach(PsiAccount* pa, psi->contactList()->accounts())
			if(aname == pa->name())
				n++;
	}

	if ( aname == acc.name )
		n--;

	if ( n )
		aname = def + '_' + QString::number(++n);
	le_name->setText( aname );

	acc.name = le_name->text();
	acc.jid = JIDUtil::accountFromString(le_jid->text().trimmed()).bare();
	acc.pass = le_pass->text();
	acc.opt_pass = !acc.pass.isEmpty();

	acc.opt_host = ck_host->isChecked();
	acc.host = le_host->text();
	acc.port = le_port->text().toInt();

	acc.req_mutual_auth = ck_req_mutual->isChecked();
	if (!ck_host->isChecked())
		acc.legacy_ssl_probe = ck_legacy_ssl_probe->isChecked();
	acc.security_level = cb_security_level->itemData(cb_security_level->currentIndex()).toInt();

	acc.opt_automatic_resource = ck_automatic_resource->isChecked();
	acc.resource = le_resource->text();
	acc.priority = le_priority->text().toInt();
	acc.customAuth = ck_custom_auth->isChecked();
	acc.authid = le_authid->text();
	acc.realm = le_realm->text();
	acc.ssl =  (UserAccount::SSLFlag) cb_ssl->itemData(cb_ssl->currentIndex()).toInt();
	acc.allow_plain =  (ClientStream::AllowPlainType) cb_plain->itemData(cb_plain->currentIndex()).toInt();
	acc.opt_compress = ck_compress->isChecked();
	acc.opt_auto = ck_auto->isChecked();
	acc.opt_connectAfterSleep = ck_connectAfterSleep->isChecked();
	acc.opt_reconn = ck_reconn->isChecked();
	acc.opt_log = ck_log->isChecked();
	acc.opt_keepAlive = ck_keepAlive->isChecked();
	acc.dtProxy = le_dtProxy->text();
	acc.stunHost = le_stunHost->text();
	acc.stunPort = le_stunPort->text().toInt();
	if(pa->jingleRtpManager())
		pa->jingleRtpManager()->setStunHost(acc.stunHost, acc.stunPort);

	acc.pgpSecretKey = key;

	acc.proxyID = pc->currentItem();

	if(pa && pa->isActive()) {
		QMessageBox::information(this, tr("Warning"), tr("This account is currently active, so certain changes may not take effect until the next login."));
	}

	if (pa)
		pa->setUserAccount(acc);
	else 
		psi->contactList()->createAccount(acc);

	accept();
}
コード例 #2
0
void AccountModifyDlg::save()
{
	/*if(pa && le_name->text().isEmpty()) {
		QMessageBox::information(this, tr("Error"), tr("You must specify a name for the account before you may save it."));
		return;
	}*/

	Jid newJid( JIDUtil::accountFromString(le_jid->text().trimmed()) );
	if ( newJid.node().isEmpty() || newJid.domain().isEmpty() ) {
		if (!PsiOptions::instance()->getOption("options.account.domain").toString().isEmpty()) {
			QMessageBox::information(this, tr("Error"), tr("<i>Username</i> is invalid."));
		}
		else {
			QMessageBox::information(this, tr("Error"), tr("<i>XMPP Address</i> must be specified in the format <i>user@host</i>."));
		}
		return;
	}

	// do not allow duplicate account names
	if (!pa && le_name->text().isEmpty())
		le_name->setText(newJid.domain());
	QString def = le_name->text();
	QString aname = def;
	int n = 0;
	{
		foreach(PsiAccount* pa, psi->contactList()->accounts())
			if(aname == pa->name())
				n++;
	}

	if ( aname == acc.name )
		n--;

	if ( n )
		aname = def + '_' + QString::number(++n);
	le_name->setText( aname );

	acc.name = le_name->text();
	acc.jid = JIDUtil::accountFromString(le_jid->text().trimmed()).bare();
	acc.pass = le_pass->text();
	acc.opt_pass = !acc.pass.isEmpty();

	acc.opt_host = ck_host->isChecked();
	acc.host = le_host->text();
	acc.port = le_port->text().toInt();

	acc.req_mutual_auth = ck_req_mutual->isChecked();
	acc.security_level = cb_security_level->itemData(cb_security_level->currentIndex()).toInt();

	acc.opt_automatic_resource = (cb_resource->currentIndex() == 1);
	acc.resource = le_resource->text();
	acc.priority_dep_on_status = (cb_priority->currentIndex() == 1);
	acc.priority = sb_priority->value();
	acc.customAuth = ck_custom_auth->isChecked();
	acc.authid = le_authid->text();
	acc.realm = le_realm->text();
	acc.ssl =  (UserAccount::SSLFlag) cb_ssl->itemData(cb_ssl->currentIndex()).toInt();
	acc.allow_plain =  (ClientStream::AllowPlainType) cb_plain->itemData(cb_plain->currentIndex()).toInt();
	acc.opt_compress = ck_compress->isChecked();
	acc.opt_auto = ck_auto->isChecked();
	acc.opt_connectAfterSleep = ck_connectAfterSleep->isChecked();
	acc.opt_autoSameStatus = ck_autoSameStatus->isChecked();
	acc.opt_reconn = ck_reconn->isChecked();
	acc.opt_log = ck_log->isChecked();
	acc.opt_keepAlive = ck_keepAlive->isChecked();
	acc.ibbOnly = ck_ibbOnly->isChecked();
	acc.dtProxy = le_dtProxy->text();
	acc.stunHost = cb_stunHost->currentIndex() ? cb_stunHost->currentText().trimmed() : "";
	acc.stunHosts.clear();
	// first item is no host
	for (int i = 1; i < cb_stunHost->count(); i++) {
		acc.stunHosts << cb_stunHost->itemText(i);
	}
	if (acc.stunHosts.indexOf(acc.stunHost) == -1) {
		acc.stunHosts << acc.stunHost;
	}
	acc.stunUser = le_stunUser->text();
	acc.stunPass = le_stunPass->text();

	acc.storeSaltedHashedPassword = ck_scram_salted_password->isChecked();

	acc.pgpSecretKey = key;

	acc.proxyID = pc->currentItem();

	if (pa) {
		pa->setUserAccount(acc);

		if (pa->isActive()) {
			QMessageBox messageBox(QMessageBox::Information, tr("Warning"),
								   tr("This account is currently active, so certain changes may not take effect until the next login."),
								   QMessageBox::NoButton, this);
			QPushButton* cancel = messageBox.addButton(tr("Reconnect &Later"), QMessageBox::RejectRole);
			QPushButton* reconnect = messageBox.addButton(tr("Reconnect &Now"), QMessageBox::AcceptRole);
			messageBox.setDefaultButton(reconnect);
			messageBox.exec();
			Q_UNUSED(cancel);
			if (messageBox.clickedButton() == reconnect) {
				XMPP::Status status = pa->status();
				pa->setStatus(XMPP::Status::Offline);
				pa->setStatus(status);
			}
		}
		pa->reconfigureFTManager();
	}
	else {
		psi->contactList()->createAccount(acc);
	}

	accept();
}