123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #include <QDialogButtonBox>
- #include <QMessageBox>
- #include <QPushButton>
- #include "networksettingsdialog.h"
- #include "ui_networksettingsdialog.h"
- #include "settings.h"
- #include "rcsession.h"
- #define SIGN_IN "Sign In"
- #define SIGN_OUT "Sign Out"
- #define OK "Ok"
- NetworkSettingsDialog::NetworkSettingsDialog(RcSession * rcSession,
- QWidget * parent) :
- QDialog(parent),
- ui(new Ui::NetworkSettingsDialog),
- m_rcSession(rcSession),
- m_justSignedIn(false)
- {
- ui->setupUi(this);
- ui->m_authUserName->setText(Settings::get(Settings::ForumNokiaUserName).toString());
- switch (Settings::get(Settings::ProxyConfig).toInt())
- {
- case Settings::PCK_SystemProxy:
- ui->m_systemProxy->setChecked(true);
- setEnableManualProxyWidgets(false);
- break;
- case Settings::PCK_ManualProxy:
- ui->m_manualProxy->setChecked(true);
- setEnableManualProxyWidgets(true);
- ui->m_proxyUrl->setText(Settings::get(Settings::ProxyUrl).toString());
- ui->m_proxyPort->setValue(Settings::get(Settings::ProxyPort).toInt());
- ui->m_proxyUserName->setText(Settings::get(Settings::ProxyUserName).toString());
- ui->m_proxyPassword->setText(Settings::get(Settings::ProxyPassword).toString());
- break;
- case Settings::PCK_UndefinedProxyConfig:
- case Settings::PCK_NoProxy:
- default:
- ui->m_noProxy->setChecked(true);
- setEnableManualProxyWidgets(false);
- break;
- }
- updateSignedOnAppearance();
- connect(ui->m_manualProxy,
- SIGNAL(toggled(bool)),
- this,
- SLOT(on_manualProxy_toggled(bool)));
- if (m_rcSession != NULL)
- {
- connect(m_rcSession,
- SIGNAL(signInCompleted(bool)),
- this,
- SLOT(rcSessionSignedInSlot(bool)));
- }
- }
- NetworkSettingsDialog::~NetworkSettingsDialog()
- {
- if (m_rcSession != NULL)
- {
- disconnect(m_rcSession,
- SIGNAL(refreshRcPropertiesCompleted(bool)),
- this,
- SLOT(rcSessionSignedInSlot(bool)));
- }
- delete ui;
- }
- bool NetworkSettingsDialog::justSignedIn() const
- {
- return m_justSignedIn;
- }
- void NetworkSettingsDialog::changeEvent(QEvent *e)
- {
- QDialog::changeEvent(e);
- switch (e->type()) {
- case QEvent::LanguageChange:
- ui->retranslateUi(this);
- break;
- default:
- break;
- }
- }
- void NetworkSettingsDialog::accept()
- {
- if (m_rcSession == NULL)
- {
- // merely for persisting settings
- persistSettings();
- done(0);
- }
- else
- {
- bool
- signedOn = m_rcSession->isSignedOn();
- if (signedOn)
- {
- ui->buttonBox->setEnabled(false);
- m_rcSession->signOut();
- updateSignedOnAppearance();
- this->m_justSignedIn = false;
- ui->buttonBox->setEnabled(true);
- done(0);
- }
- else
- {
- ui->buttonBox->setEnabled(false);
- persistSettings();
- m_rcSession->signIn();
- }
- }
- }
- void NetworkSettingsDialog::on_manualProxy_toggled(bool toggle)
- {
- setEnableManualProxyWidgets(toggle);
- }
- void NetworkSettingsDialog::rcSessionSignedInSlot(bool success)
- {
- updateSignedOnAppearance();
- m_justSignedIn = success;
- ui->buttonBox->setEnabled(true);
- if (!success)
- {
- QMessageBox::warning(this,
- "Remote compiler connection failed",
- "Signing in failed. Check your Forum Nokia account/password,\n"
- "your proxy settings and the availability of SSL library",
- QMessageBox::Ok);
- }
- else
- {
- done(0);
- }
- }
- void NetworkSettingsDialog::setEnableManualProxyWidgets(bool enabled)
- {
- ui->m_proxyUrl->setEnabled(enabled);
- ui->m_proxyPort->setEnabled(enabled);
- ui->m_proxyUserName->setEnabled(enabled);
- ui->m_proxyPassword->setEnabled(enabled);
- }
- void NetworkSettingsDialog::persistSettings()
- {
- Settings::set(Settings::ForumNokiaUserName,
- ui->m_authUserName->text());
- Settings::ProxyConfigKind
- proxyConfig = Settings::PCK_NoProxy;
- if (ui->m_systemProxy->isChecked())
- {
- proxyConfig = Settings::PCK_SystemProxy;
- }
- else if (ui->m_manualProxy->isChecked())
- {
- proxyConfig = Settings::PCK_ManualProxy;
- Settings::set(Settings::ProxyUrl,
- ui->m_proxyUrl->text());
- Settings::set(Settings::ProxyPort,
- ui->m_proxyPort->value());
- Settings::set(Settings::ProxyUserName,
- ui->m_proxyUserName->text());
- Settings::set(Settings::ProxyPassword,
- ui->m_proxyPassword->text());
- }
- Settings::set(Settings::ProxyConfig,
- proxyConfig);
- }
- void NetworkSettingsDialog::updateSignedOnAppearance()
- {
- if (m_rcSession)
- {
- bool
- signedOn = m_rcSession->isSignedOn();
- ui->buttonBox->button(QDialogButtonBox::Ok)->setText(signedOn ? SIGN_OUT : SIGN_IN);
- ui->m_fNGroupBox->setEnabled(!signedOn);
- ui->m_pSGroupBox->setEnabled(!signedOn);
- }
- else
- {
- ui->buttonBox->button(QDialogButtonBox::Ok)->setText(OK);
- }
- }
|