networksettingsdialog.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #include <QDialogButtonBox>
  2. #include <QMessageBox>
  3. #include <QPushButton>
  4. #include "networksettingsdialog.h"
  5. #include "ui_networksettingsdialog.h"
  6. #include "settings.h"
  7. #include "rcsession.h"
  8. #define SIGN_IN "Sign In"
  9. #define SIGN_OUT "Sign Out"
  10. #define OK "Ok"
  11. NetworkSettingsDialog::NetworkSettingsDialog(RcSession * rcSession,
  12. QWidget * parent) :
  13. QDialog(parent),
  14. ui(new Ui::NetworkSettingsDialog),
  15. m_rcSession(rcSession),
  16. m_justSignedIn(false)
  17. {
  18. ui->setupUi(this);
  19. ui->m_authUserName->setText(Settings::get(Settings::ForumNokiaUserName).toString());
  20. switch (Settings::get(Settings::ProxyConfig).toInt())
  21. {
  22. case Settings::PCK_SystemProxy:
  23. ui->m_systemProxy->setChecked(true);
  24. setEnableManualProxyWidgets(false);
  25. break;
  26. case Settings::PCK_ManualProxy:
  27. ui->m_manualProxy->setChecked(true);
  28. setEnableManualProxyWidgets(true);
  29. ui->m_proxyUrl->setText(Settings::get(Settings::ProxyUrl).toString());
  30. ui->m_proxyPort->setValue(Settings::get(Settings::ProxyPort).toInt());
  31. ui->m_proxyUserName->setText(Settings::get(Settings::ProxyUserName).toString());
  32. ui->m_proxyPassword->setText(Settings::get(Settings::ProxyPassword).toString());
  33. break;
  34. case Settings::PCK_UndefinedProxyConfig:
  35. case Settings::PCK_NoProxy:
  36. default:
  37. ui->m_noProxy->setChecked(true);
  38. setEnableManualProxyWidgets(false);
  39. break;
  40. }
  41. updateSignedOnAppearance();
  42. connect(ui->m_manualProxy,
  43. SIGNAL(toggled(bool)),
  44. this,
  45. SLOT(on_manualProxy_toggled(bool)));
  46. if (m_rcSession != NULL)
  47. {
  48. connect(m_rcSession,
  49. SIGNAL(signInCompleted(bool)),
  50. this,
  51. SLOT(rcSessionSignedInSlot(bool)));
  52. }
  53. }
  54. NetworkSettingsDialog::~NetworkSettingsDialog()
  55. {
  56. if (m_rcSession != NULL)
  57. {
  58. disconnect(m_rcSession,
  59. SIGNAL(refreshRcPropertiesCompleted(bool)),
  60. this,
  61. SLOT(rcSessionSignedInSlot(bool)));
  62. }
  63. delete ui;
  64. }
  65. bool NetworkSettingsDialog::justSignedIn() const
  66. {
  67. return m_justSignedIn;
  68. }
  69. void NetworkSettingsDialog::changeEvent(QEvent *e)
  70. {
  71. QDialog::changeEvent(e);
  72. switch (e->type()) {
  73. case QEvent::LanguageChange:
  74. ui->retranslateUi(this);
  75. break;
  76. default:
  77. break;
  78. }
  79. }
  80. void NetworkSettingsDialog::accept()
  81. {
  82. if (m_rcSession == NULL)
  83. {
  84. // merely for persisting settings
  85. persistSettings();
  86. done(0);
  87. }
  88. else
  89. {
  90. bool
  91. signedOn = m_rcSession->isSignedOn();
  92. if (signedOn)
  93. {
  94. ui->buttonBox->setEnabled(false);
  95. m_rcSession->signOut();
  96. updateSignedOnAppearance();
  97. this->m_justSignedIn = false;
  98. ui->buttonBox->setEnabled(true);
  99. done(0);
  100. }
  101. else
  102. {
  103. ui->buttonBox->setEnabled(false);
  104. persistSettings();
  105. m_rcSession->signIn();
  106. }
  107. }
  108. }
  109. void NetworkSettingsDialog::on_manualProxy_toggled(bool toggle)
  110. {
  111. setEnableManualProxyWidgets(toggle);
  112. }
  113. void NetworkSettingsDialog::rcSessionSignedInSlot(bool success)
  114. {
  115. updateSignedOnAppearance();
  116. m_justSignedIn = success;
  117. ui->buttonBox->setEnabled(true);
  118. if (!success)
  119. {
  120. QMessageBox::warning(this,
  121. "Remote compiler connection failed",
  122. "Signing in failed. Check your Forum Nokia account/password,\n"
  123. "your proxy settings and the availability of SSL library",
  124. QMessageBox::Ok);
  125. }
  126. else
  127. {
  128. done(0);
  129. }
  130. }
  131. void NetworkSettingsDialog::setEnableManualProxyWidgets(bool enabled)
  132. {
  133. ui->m_proxyUrl->setEnabled(enabled);
  134. ui->m_proxyPort->setEnabled(enabled);
  135. ui->m_proxyUserName->setEnabled(enabled);
  136. ui->m_proxyPassword->setEnabled(enabled);
  137. }
  138. void NetworkSettingsDialog::persistSettings()
  139. {
  140. Settings::set(Settings::ForumNokiaUserName,
  141. ui->m_authUserName->text());
  142. Settings::ProxyConfigKind
  143. proxyConfig = Settings::PCK_NoProxy;
  144. if (ui->m_systemProxy->isChecked())
  145. {
  146. proxyConfig = Settings::PCK_SystemProxy;
  147. }
  148. else if (ui->m_manualProxy->isChecked())
  149. {
  150. proxyConfig = Settings::PCK_ManualProxy;
  151. Settings::set(Settings::ProxyUrl,
  152. ui->m_proxyUrl->text());
  153. Settings::set(Settings::ProxyPort,
  154. ui->m_proxyPort->value());
  155. Settings::set(Settings::ProxyUserName,
  156. ui->m_proxyUserName->text());
  157. Settings::set(Settings::ProxyPassword,
  158. ui->m_proxyPassword->text());
  159. }
  160. Settings::set(Settings::ProxyConfig,
  161. proxyConfig);
  162. }
  163. void NetworkSettingsDialog::updateSignedOnAppearance()
  164. {
  165. if (m_rcSession)
  166. {
  167. bool
  168. signedOn = m_rcSession->isSignedOn();
  169. ui->buttonBox->button(QDialogButtonBox::Ok)->setText(signedOn ? SIGN_OUT : SIGN_IN);
  170. ui->m_fNGroupBox->setEnabled(!signedOn);
  171. ui->m_pSGroupBox->setEnabled(!signedOn);
  172. }
  173. else
  174. {
  175. ui->buttonBox->button(QDialogButtonBox::Ok)->setText(OK);
  176. }
  177. }