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
15 #include "userdatarequest.h"
16 #include "wpagui.h"
17 #include "wpa_ctrl.h"
18
19
UserDataRequest(QWidget * parent,const char *,bool,Qt::WFlags)20 UserDataRequest::UserDataRequest(QWidget *parent, const char *, bool,
21 Qt::WFlags)
22 : QDialog(parent)
23 {
24 setupUi(this);
25
26 connect(buttonOk, SIGNAL(clicked()), this, SLOT(sendReply()));
27 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
28 connect(queryEdit, SIGNAL(returnPressed()), this, SLOT(sendReply()));
29 }
30
31
~UserDataRequest()32 UserDataRequest::~UserDataRequest()
33 {
34 }
35
36
languageChange()37 void UserDataRequest::languageChange()
38 {
39 retranslateUi(this);
40 }
41
42
setParams(WpaGui * _wpagui,const char * reqMsg)43 int UserDataRequest::setParams(WpaGui *_wpagui, const char *reqMsg)
44 {
45 char *tmp, *pos, *pos2;
46 wpagui = _wpagui;
47 tmp = strdup(reqMsg);
48 if (tmp == NULL)
49 return -1;
50 pos = strchr(tmp, '-');
51 if (pos == NULL) {
52 free(tmp);
53 return -1;
54 }
55 *pos++ = '\0';
56 field = tmp;
57 pos2 = strchr(pos, ':');
58 if (pos2 == NULL) {
59 free(tmp);
60 return -1;
61 }
62 *pos2++ = '\0';
63
64 networkid = atoi(pos);
65 queryInfo->setText(pos2);
66 if (strcmp(tmp, "PASSWORD") == 0) {
67 queryField->setText("Password: ");
68 queryEdit->setEchoMode(QLineEdit::Password);
69 } else if (strcmp(tmp, "NEW_PASSWORD") == 0) {
70 queryField->setText("New password: ");
71 queryEdit->setEchoMode(QLineEdit::Password);
72 } else if (strcmp(tmp, "IDENTITY") == 0)
73 queryField->setText("Identity: ");
74 else if (strcmp(tmp, "PASSPHRASE") == 0) {
75 queryField->setText("Private key passphrase: ");
76 queryEdit->setEchoMode(QLineEdit::Password);
77 } else
78 queryField->setText(field + ":");
79 free(tmp);
80
81 return 0;
82 }
83
84
sendReply()85 void UserDataRequest::sendReply()
86 {
87 char reply[10];
88 size_t reply_len = sizeof(reply);
89
90 if (wpagui == NULL) {
91 reject();
92 return;
93 }
94
95 QString cmd = QString(WPA_CTRL_RSP) + field + '-' +
96 QString::number(networkid) + ':' +
97 queryEdit->text();
98 wpagui->ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
99 accept();
100 }
101