userdatarequest.cpp 2.2 KB

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