userdatarequest.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * wpa_gui - UserDataRequest class
  3. * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "userdatarequest.h"
  9. #include "wpagui.h"
  10. #include "common/wpa_ctrl.h"
  11. UserDataRequest::UserDataRequest(QWidget *parent, const char *, bool,
  12. Qt::WindowFlags)
  13. : QDialog(parent)
  14. {
  15. setupUi(this);
  16. connect(buttonOk, SIGNAL(clicked()), this, SLOT(sendReply()));
  17. connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
  18. connect(queryEdit, SIGNAL(returnPressed()), this, SLOT(sendReply()));
  19. }
  20. UserDataRequest::~UserDataRequest()
  21. {
  22. }
  23. void UserDataRequest::languageChange()
  24. {
  25. retranslateUi(this);
  26. }
  27. int UserDataRequest::setParams(WpaGui *_wpagui, const char *reqMsg)
  28. {
  29. char *tmp, *pos, *pos2;
  30. wpagui = _wpagui;
  31. tmp = strdup(reqMsg);
  32. if (tmp == NULL)
  33. return -1;
  34. pos = strchr(tmp, '-');
  35. if (pos == NULL) {
  36. free(tmp);
  37. return -1;
  38. }
  39. *pos++ = '\0';
  40. field = tmp;
  41. pos2 = strchr(pos, ':');
  42. if (pos2 == NULL) {
  43. free(tmp);
  44. return -1;
  45. }
  46. *pos2++ = '\0';
  47. networkid = atoi(pos);
  48. queryInfo->setText(pos2);
  49. if (strcmp(tmp, "PASSWORD") == 0) {
  50. queryField->setText(tr("Password: "));
  51. queryEdit->setEchoMode(QLineEdit::Password);
  52. } else if (strcmp(tmp, "NEW_PASSWORD") == 0) {
  53. queryField->setText(tr("New password: "));
  54. queryEdit->setEchoMode(QLineEdit::Password);
  55. } else if (strcmp(tmp, "IDENTITY") == 0)
  56. queryField->setText(tr("Identity: "));
  57. else if (strcmp(tmp, "PASSPHRASE") == 0) {
  58. queryField->setText(tr("Private key passphrase: "));
  59. queryEdit->setEchoMode(QLineEdit::Password);
  60. } else
  61. queryField->setText(field + ":");
  62. free(tmp);
  63. return 0;
  64. }
  65. void UserDataRequest::sendReply()
  66. {
  67. char reply[10];
  68. size_t reply_len = sizeof(reply);
  69. if (wpagui == NULL) {
  70. reject();
  71. return;
  72. }
  73. QString cmd = QString(WPA_CTRL_RSP) + field + '-' +
  74. QString::number(networkid) + ':' +
  75. queryEdit->text();
  76. wpagui->ctrlRequest(cmd.toLocal8Bit().constData(), reply, &reply_len);
  77. accept();
  78. }