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