2 * wpa_gui - WpaGui class
3 * Copyright (c) 2005-2008, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
16 /* Need to get getopt() */
21 #include <QMessageBox>
22 #include <QCloseEvent>
23 #include <QImageReader>
28 #include "userdatarequest.h"
29 #include "networkconfig.h"
33 #define printf wpagui_printf
34 static int wpagui_printf(const char *, ...)
40 WpaGui::WpaGui(QWidget *parent, const char *, Qt::WFlags)
47 connect(fileEventHistoryAction, SIGNAL(triggered()), this,
48 SLOT(eventHistory()));
49 connect(fileSaveConfigAction, SIGNAL(triggered()), this,
51 connect(fileExitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
52 connect(networkAddAction, SIGNAL(triggered()), this,
54 connect(networkEditAction, SIGNAL(triggered()), this,
55 SLOT(editSelectedNetwork()));
56 connect(networkRemoveAction, SIGNAL(triggered()), this,
57 SLOT(removeSelectedNetwork()));
58 connect(networkEnableAllAction, SIGNAL(triggered()), this,
59 SLOT(enableAllNetworks()));
60 connect(networkDisableAllAction, SIGNAL(triggered()), this,
61 SLOT(disableAllNetworks()));
62 connect(networkRemoveAllAction, SIGNAL(triggered()), this,
63 SLOT(removeAllNetworks()));
64 connect(helpIndexAction, SIGNAL(triggered()), this, SLOT(helpIndex()));
65 connect(helpContentsAction, SIGNAL(triggered()), this,
66 SLOT(helpContents()));
67 connect(helpAboutAction, SIGNAL(triggered()), this, SLOT(helpAbout()));
68 connect(disconnectButton, SIGNAL(clicked()), this, SLOT(disconnect()));
69 connect(scanButton, SIGNAL(clicked()), this, SLOT(scan()));
70 connect(connectButton, SIGNAL(clicked()), this, SLOT(connectB()));
71 connect(adapterSelect, SIGNAL(activated(const QString&)), this,
72 SLOT(selectAdapter(const QString&)));
73 connect(networkSelect, SIGNAL(activated(const QString&)), this,
74 SLOT(selectNetwork(const QString&)));
75 connect(addNetworkButton, SIGNAL(clicked()), this, SLOT(addNetwork()));
76 connect(editNetworkButton, SIGNAL(clicked()), this,
77 SLOT(editListedNetwork()));
78 connect(removeNetworkButton, SIGNAL(clicked()), this,
79 SLOT(removeListedNetwork()));
80 connect(networkList, SIGNAL(itemSelectionChanged()), this,
81 SLOT(updateNetworkDisabledStatus()));
82 connect(enableRadioButton, SIGNAL(toggled(bool)), this,
83 SLOT(enableListedNetwork(bool)));
84 connect(disableRadioButton, SIGNAL(toggled(bool)), this,
85 SLOT(disableListedNetwork(bool)));
86 connect(scanNetworkButton, SIGNAL(clicked()), this, SLOT(scan()));
87 connect(networkList, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
88 this, SLOT(editListedNetwork()));
99 ctrl_iface_dir = strdup("/var/run/wpa_supplicant");
103 if (QSystemTrayIcon::isSystemTrayAvailable())
104 createTrayIcon(startInTray);
108 textStatus->setText("connecting to wpa_supplicant");
109 timer = new QTimer(this);
110 connect(timer, SIGNAL(timeout()), SLOT(ping()));
111 timer->setSingleShot(FALSE);
114 if (openCtrlConnection(ctrl_iface) < 0) {
115 printf("Failed to open control connection to "
116 "wpa_supplicant.\n");
120 networkMayHaveChanged = true;
130 wpa_ctrl_detach(monitor_conn);
131 wpa_ctrl_close(monitor_conn);
135 wpa_ctrl_close(ctrl_conn);
160 free(ctrl_iface_dir);
161 ctrl_iface_dir = NULL;
165 void WpaGui::languageChange()
171 void WpaGui::parse_argv()
175 c = getopt(qApp->argc(), qApp->argv(), "i:p:t");
181 ctrl_iface = strdup(optarg);
184 free(ctrl_iface_dir);
185 ctrl_iface_dir = strdup(optarg);
195 int WpaGui::openCtrlConnection(const char *ifname)
199 char buf[2048], *pos, *pos2;
203 if (ifname != ctrl_iface) {
205 ctrl_iface = strdup(ifname);
208 #ifdef CONFIG_CTRL_IFACE_UDP
210 ctrl_iface = strdup("udp");
211 #endif /* CONFIG_CTRL_IFACE_UDP */
212 #ifdef CONFIG_CTRL_IFACE_UNIX
214 DIR *dir = opendir(ctrl_iface_dir);
218 while ((dent = readdir(dir))) {
219 #ifdef _DIRENT_HAVE_D_TYPE
220 /* Skip the file if it is not a socket.
221 * Also accept DT_UNKNOWN (0) in case
222 * the C library or underlying file
223 * system does not support d_type. */
224 if (dent->d_type != DT_SOCK &&
225 dent->d_type != DT_UNKNOWN)
227 #endif /* _DIRENT_HAVE_D_TYPE */
229 if (strcmp(dent->d_name, ".") == 0 ||
230 strcmp(dent->d_name, "..") == 0)
232 printf("Selected interface '%s'\n",
234 ctrl_iface = strdup(dent->d_name);
239 #endif /* CONFIG_CTRL_IFACE_UNIX */
240 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
241 struct wpa_ctrl *ctrl;
247 ctrl = wpa_ctrl_open(NULL);
249 len = sizeof(buf) - 1;
250 ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf,
254 pos = strchr(buf, '\n');
257 ctrl_iface = strdup(buf);
259 wpa_ctrl_close(ctrl);
261 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
264 if (ctrl_iface == NULL)
267 #ifdef CONFIG_CTRL_IFACE_UNIX
268 flen = strlen(ctrl_iface_dir) + strlen(ctrl_iface) + 2;
269 cfile = (char *) malloc(flen);
272 snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ctrl_iface);
273 #else /* CONFIG_CTRL_IFACE_UNIX */
274 flen = strlen(ctrl_iface) + 1;
275 cfile = (char *) malloc(flen);
278 snprintf(cfile, flen, "%s", ctrl_iface);
279 #endif /* CONFIG_CTRL_IFACE_UNIX */
282 wpa_ctrl_close(ctrl_conn);
289 wpa_ctrl_detach(monitor_conn);
290 wpa_ctrl_close(monitor_conn);
294 printf("Trying to connect to '%s'\n", cfile);
295 ctrl_conn = wpa_ctrl_open(cfile);
296 if (ctrl_conn == NULL) {
300 monitor_conn = wpa_ctrl_open(cfile);
302 if (monitor_conn == NULL) {
303 wpa_ctrl_close(ctrl_conn);
306 if (wpa_ctrl_attach(monitor_conn)) {
307 printf("Failed to attach to wpa_supplicant\n");
308 wpa_ctrl_close(monitor_conn);
310 wpa_ctrl_close(ctrl_conn);
315 #if defined(CONFIG_CTRL_IFACE_UNIX) || defined(CONFIG_CTRL_IFACE_UDP)
316 msgNotifier = new QSocketNotifier(wpa_ctrl_get_fd(monitor_conn),
317 QSocketNotifier::Read, this);
318 connect(msgNotifier, SIGNAL(activated(int)), SLOT(receiveMsgs()));
321 adapterSelect->clear();
322 adapterSelect->addItem(ctrl_iface);
323 adapterSelect->setCurrentIndex(0);
325 len = sizeof(buf) - 1;
326 if (wpa_ctrl_request(ctrl_conn, "INTERFACES", 10, buf, &len, NULL) >=
331 pos2 = strchr(pos, '\n');
334 if (strcmp(pos, ctrl_iface) != 0)
335 adapterSelect->addItem(pos);
347 static void wpa_gui_msg_cb(char *msg, size_t)
349 /* This should not happen anymore since two control connections are
351 printf("missed message: %s\n", msg);
355 int WpaGui::ctrlRequest(const char *cmd, char *buf, size_t *buflen)
359 if (ctrl_conn == NULL)
361 ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, buflen,
364 printf("'%s' command timed out.\n", cmd);
366 printf("'%s' command failed.\n", cmd);
372 void WpaGui::updateStatus()
374 char buf[2048], *start, *end, *pos;
377 pingsToStatusUpdate = 10;
379 len = sizeof(buf) - 1;
380 if (ctrl_conn == NULL || ctrlRequest("STATUS", buf, &len) < 0) {
381 textStatus->setText("Could not get status from "
383 textAuthentication->clear();
384 textEncryption->clear();
387 textIpAddress->clear();
393 bool auth_updated = false, ssid_updated = false;
394 bool bssid_updated = false, ipaddr_updated = false;
395 bool status_updated = false;
396 char *pairwise_cipher = NULL, *group_cipher = NULL;
401 end = strchr(start, '\n');
405 while (end[0] && end[1])
410 pos = strchr(start, '=');
413 if (strcmp(start, "bssid") == 0) {
414 bssid_updated = true;
415 textBssid->setText(pos);
416 } else if (strcmp(start, "ssid") == 0) {
418 textSsid->setText(pos);
419 } else if (strcmp(start, "ip_address") == 0) {
420 ipaddr_updated = true;
421 textIpAddress->setText(pos);
422 } else if (strcmp(start, "wpa_state") == 0) {
423 status_updated = true;
424 textStatus->setText(pos);
425 } else if (strcmp(start, "key_mgmt") == 0) {
427 textAuthentication->setText(pos);
428 /* TODO: could add EAP status to this */
429 } else if (strcmp(start, "pairwise_cipher") == 0) {
430 pairwise_cipher = pos;
431 } else if (strcmp(start, "group_cipher") == 0) {
441 if (pairwise_cipher || group_cipher) {
443 if (pairwise_cipher && group_cipher &&
444 strcmp(pairwise_cipher, group_cipher) != 0) {
445 encr.append(pairwise_cipher);
447 encr.append(group_cipher);
448 } else if (pairwise_cipher) {
449 encr.append(pairwise_cipher);
451 encr.append(group_cipher);
452 encr.append(" [group key only]");
454 textEncryption->setText(encr);
456 textEncryption->clear();
461 textAuthentication->clear();
467 textIpAddress->clear();
471 void WpaGui::updateNetworks()
473 char buf[2048], *start, *end, *id, *ssid, *bssid, *flags;
475 int first_active = -1;
476 int was_selected = -1;
477 bool current = false;
479 if (!networkMayHaveChanged)
482 if (networkList->currentRow() >= 0)
483 was_selected = networkList->currentRow();
485 networkSelect->clear();
486 networkList->clear();
488 if (ctrl_conn == NULL)
491 len = sizeof(buf) - 1;
492 if (ctrlRequest("LIST_NETWORKS", buf, &len) < 0)
496 start = strchr(buf, '\n');
503 end = strchr(start, '\n');
507 while (end[0] && end[1])
513 ssid = strchr(id, '\t');
517 bssid = strchr(ssid, '\t');
521 flags = strchr(bssid, '\t');
527 network.append(": ");
528 network.append(ssid);
529 networkSelect->addItem(network);
530 networkList->addItem(network);
532 if (strstr(flags, "[CURRENT]")) {
533 networkSelect->setCurrentIndex(networkSelect->count() -
536 } else if (first_active < 0 &&
537 strstr(flags, "[DISABLED]") == NULL)
538 first_active = networkSelect->count() - 1;
545 if (networkSelect->count() > 1)
546 networkSelect->addItem("Select any network");
548 if (!current && first_active >= 0)
549 networkSelect->setCurrentIndex(first_active);
551 if (was_selected >= 0 && networkList->count() > 0) {
552 if (was_selected < networkList->count())
553 networkList->setCurrentRow(was_selected);
555 networkList->setCurrentRow(networkList->count() - 1);
558 networkList->setCurrentRow(networkSelect->currentIndex());
560 networkMayHaveChanged = false;
564 void WpaGui::helpIndex()
566 printf("helpIndex\n");
570 void WpaGui::helpContents()
572 printf("helpContents\n");
576 void WpaGui::helpAbout()
578 QMessageBox::about(this, "wpa_gui for wpa_supplicant",
579 "Copyright (c) 2003-2008,\n"
580 "Jouni Malinen <j@w1.fi>\n"
581 "and contributors.\n"
583 "This program is free software. You can\n"
584 "distribute it and/or modify it under the terms "
586 "the GNU General Public License version 2.\n"
588 "Alternatively, this software may be distributed\n"
589 "under the terms of the BSD license.\n"
591 "This product includes software developed\n"
592 "by the OpenSSL Project for use in the\n"
593 "OpenSSL Toolkit (http://www.openssl.org/)\n");
597 void WpaGui::disconnect()
600 size_t reply_len = sizeof(reply);
601 ctrlRequest("DISCONNECT", reply, &reply_len);
612 scanres = new ScanResults();
615 scanres->setWpaGui(this);
621 void WpaGui::eventHistory()
628 eh = new EventHistory();
642 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
644 * QSocketNotifier cannot be used with Windows named pipes, so use a
645 * timer to check for received messages for now. This could be
646 * optimized be doing something specific to named pipes or Windows
647 * events, but it is not clear what would be the best way of doing that
651 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
653 if (scanres && !scanres->isVisible()) {
658 if (eh && !eh->isVisible()) {
663 if (udr && !udr->isVisible()) {
668 len = sizeof(buf) - 1;
669 if (ctrlRequest("PING", buf, &len) < 0) {
670 printf("PING failed - trying to reconnect\n");
671 if (openCtrlConnection(ctrl_iface) >= 0) {
672 printf("Reconnected successfully\n");
673 pingsToStatusUpdate = 0;
677 pingsToStatusUpdate--;
678 if (pingsToStatusUpdate <= 0) {
685 static int str_match(const char *a, const char *b)
687 return strncmp(a, b, strlen(b)) == 0;
691 void WpaGui::processMsg(char *msg)
693 char *pos = msg, *pos2;
699 priority = atoi(pos);
700 pos = strchr(pos, '>');
707 WpaMsg wm(pos, priority);
711 while (msgs.count() > 100)
714 /* Update last message with truncated version of the event */
715 if (strncmp(pos, "CTRL-", 5) == 0) {
716 pos2 = strchr(pos, str_match(pos, WPA_CTRL_REQ) ? ':' : ' ');
723 QString lastmsg = pos2;
724 lastmsg.truncate(40);
725 textLastMessage->setText(lastmsg);
727 pingsToStatusUpdate = 0;
728 networkMayHaveChanged = true;
730 if (str_match(pos, WPA_CTRL_REQ))
731 processCtrlReq(pos + strlen(WPA_CTRL_REQ));
732 else if (str_match(pos, WPA_EVENT_SCAN_RESULTS) && scanres)
733 scanres->updateResults();
734 else if (str_match(pos, WPA_EVENT_DISCONNECTED))
735 showTrayMessage(QSystemTrayIcon::Information, 3,
736 "Disconnected from network.");
737 else if (str_match(pos, WPA_EVENT_CONNECTED)) {
738 showTrayMessage(QSystemTrayIcon::Information, 3,
739 "Connection to network established.");
740 QTimer::singleShot(5 * 1000, this, SLOT(showTrayStatus()));
745 void WpaGui::processCtrlReq(const char *req)
751 udr = new UserDataRequest();
754 if (udr->setParams(this, req) < 0) {
764 void WpaGui::receiveMsgs()
769 while (monitor_conn && wpa_ctrl_pending(monitor_conn) > 0) {
770 len = sizeof(buf) - 1;
771 if (wpa_ctrl_recv(monitor_conn, buf, &len) == 0) {
779 void WpaGui::connectB()
782 size_t reply_len = sizeof(reply);
783 ctrlRequest("REASSOCIATE", reply, &reply_len);
787 void WpaGui::selectNetwork( const QString &sel )
791 size_t reply_len = sizeof(reply);
793 if (cmd.startsWith("Select any")) {
796 int pos = cmd.indexOf(':');
798 printf("Invalid selectNetwork '%s'\n",
799 cmd.toAscii().constData());
804 cmd.prepend("SELECT_NETWORK ");
805 ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
810 void WpaGui::enableNetwork(const QString &sel)
814 size_t reply_len = sizeof(reply);
816 if (!cmd.startsWith("all")) {
817 int pos = cmd.indexOf(':');
819 printf("Invalid enableNetwork '%s'\n",
820 cmd.toAscii().constData());
825 cmd.prepend("ENABLE_NETWORK ");
826 ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
831 void WpaGui::disableNetwork(const QString &sel)
835 size_t reply_len = sizeof(reply);
837 if (!cmd.startsWith("all")) {
838 int pos = cmd.indexOf(':');
840 printf("Invalid disableNetwork '%s'\n",
841 cmd.toAscii().constData());
846 cmd.prepend("DISABLE_NETWORK ");
847 ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
852 void WpaGui::editNetwork(const QString &sel)
857 if (!cmd.startsWith("Select any")) {
858 int pos = sel.indexOf(':');
860 printf("Invalid editNetwork '%s'\n",
861 cmd.toAscii().constData());
868 NetworkConfig *nc = new NetworkConfig();
874 nc->paramsFromConfig(id);
883 void WpaGui::editSelectedNetwork()
885 if (networkSelect->count() < 1) {
886 QMessageBox::information(this, "No Networks",
887 "There are no networks to edit.\n");
890 QString sel(networkSelect->currentText());
895 void WpaGui::editListedNetwork()
897 if (networkList->currentRow() < 0) {
898 QMessageBox::information(this, "Select A Network",
899 "Select a network from the list to"
903 QString sel(networkList->currentItem()->text());
908 void WpaGui::triggerUpdate()
911 networkMayHaveChanged = true;
916 void WpaGui::addNetwork()
918 NetworkConfig *nc = new NetworkConfig();
928 void WpaGui::removeNetwork(const QString &sel)
932 size_t reply_len = sizeof(reply);
934 if (cmd.startsWith("Select any"))
937 if (!cmd.startsWith("all")) {
938 int pos = cmd.indexOf(':');
940 printf("Invalid removeNetwork '%s'\n",
941 cmd.toAscii().constData());
946 cmd.prepend("REMOVE_NETWORK ");
947 ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
952 void WpaGui::removeSelectedNetwork()
954 if (networkSelect->count() < 1) {
955 QMessageBox::information(this, "No Networks",
956 "There are no networks to remove.\n");
959 QString sel(networkSelect->currentText());
964 void WpaGui::removeListedNetwork()
966 if (networkList->currentRow() < 0) {
967 QMessageBox::information(this, "Select A Network",
968 "Select a network from the list to"
972 QString sel(networkList->currentItem()->text());
977 void WpaGui::enableAllNetworks()
984 void WpaGui::disableAllNetworks()
991 void WpaGui::removeAllNetworks()
998 int WpaGui::getNetworkDisabled(const QString &sel)
1002 size_t reply_len = sizeof(reply) - 1;
1003 int pos = cmd.indexOf(':');
1005 printf("Invalid getNetworkDisabled '%s'\n",
1006 cmd.toAscii().constData());
1010 cmd.prepend("GET_NETWORK ");
1011 cmd.append(" disabled");
1013 if (ctrlRequest(cmd.toAscii().constData(), reply, &reply_len) >= 0
1014 && reply_len >= 1) {
1015 reply[reply_len] = '\0';
1016 if (!str_match(reply, "FAIL"))
1024 void WpaGui::updateNetworkDisabledStatus()
1026 if (networkList->currentRow() < 0)
1029 QString sel(networkList->currentItem()->text());
1031 switch (getNetworkDisabled(sel)) {
1033 if (!enableRadioButton->isChecked())
1034 enableRadioButton->setChecked(true);
1037 if (!disableRadioButton->isChecked())
1038 disableRadioButton->setChecked(true);
1044 void WpaGui::enableListedNetwork(bool enabled)
1046 if (networkList->currentRow() < 0 || !enabled)
1049 QString sel(networkList->currentItem()->text());
1051 if (getNetworkDisabled(sel) == 1)
1056 void WpaGui::disableListedNetwork(bool disabled)
1058 if (networkList->currentRow() < 0 || !disabled)
1061 QString sel(networkList->currentItem()->text());
1063 if (getNetworkDisabled(sel) == 0)
1064 disableNetwork(sel);
1068 void WpaGui::saveConfig()
1073 len = sizeof(buf) - 1;
1074 ctrlRequest("SAVE_CONFIG", buf, &len);
1078 if (str_match(buf, "FAIL"))
1079 QMessageBox::warning(this, "Failed to save configuration",
1080 "The configuration could not be saved.\n"
1082 "The update_config=1 configuration option\n"
1083 "must be used for configuration saving to\n"
1086 QMessageBox::information(this, "Saved configuration",
1087 "The current configuration was saved."
1092 void WpaGui::selectAdapter( const QString & sel )
1094 if (openCtrlConnection(sel.toAscii().constData()) < 0)
1095 printf("Failed to open control connection to "
1096 "wpa_supplicant.\n");
1102 void WpaGui::createTrayIcon(bool trayOnly)
1104 QApplication::setQuitOnLastWindowClosed(false);
1106 tray_icon = new QSystemTrayIcon(this);
1107 tray_icon->setToolTip(qAppName() + " - wpa_supplicant user interface");
1108 if (QImageReader::supportedImageFormats().contains(QByteArray("svg")))
1109 tray_icon->setIcon(QIcon(":/icons/wpa_gui.svg"));
1111 tray_icon->setIcon(QIcon(":/icons/wpa_gui.png"));
1114 SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
1115 this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
1117 ackTrayIcon = false;
1119 tray_menu = new QMenu(this);
1121 disconnectAction = new QAction("&Disconnect", this);
1122 reconnectAction = new QAction("Re&connect", this);
1123 connect(disconnectAction, SIGNAL(triggered()), this,
1124 SLOT(disconnect()));
1125 connect(reconnectAction, SIGNAL(triggered()), this,
1127 tray_menu->addAction(disconnectAction);
1128 tray_menu->addAction(reconnectAction);
1129 tray_menu->addSeparator();
1131 eventAction = new QAction("&Event History", this);
1132 scanAction = new QAction("Scan &Results", this);
1133 statAction = new QAction("S&tatus", this);
1134 connect(eventAction, SIGNAL(triggered()), this, SLOT(eventHistory()));
1135 connect(scanAction, SIGNAL(triggered()), this, SLOT(scan()));
1136 connect(statAction, SIGNAL(triggered()), this, SLOT(showTrayStatus()));
1137 tray_menu->addAction(eventAction);
1138 tray_menu->addAction(scanAction);
1139 tray_menu->addAction(statAction);
1140 tray_menu->addSeparator();
1142 showAction = new QAction("&Show Window", this);
1143 hideAction = new QAction("&Hide Window", this);
1144 quitAction = new QAction("&Quit", this);
1145 connect(showAction, SIGNAL(triggered()), this, SLOT(show()));
1146 connect(hideAction, SIGNAL(triggered()), this, SLOT(hide()));
1147 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
1148 tray_menu->addAction(showAction);
1149 tray_menu->addAction(hideAction);
1150 tray_menu->addSeparator();
1151 tray_menu->addAction(quitAction);
1153 tray_icon->setContextMenu(tray_menu);
1162 void WpaGui::showTrayMessage(QSystemTrayIcon::MessageIcon type, int sec,
1163 const QString & msg)
1165 if (!QSystemTrayIcon::supportsMessages())
1168 if (isVisible() || !tray_icon || !tray_icon->isVisible())
1171 tray_icon->showMessage(qAppName(), msg, type, sec * 1000);
1175 void WpaGui::trayActivated(QSystemTrayIcon::ActivationReason how)
1178 /* use close() here instead of hide() and allow the
1179 * custom closeEvent handler take care of children */
1180 case QSystemTrayIcon::Trigger:
1187 case QSystemTrayIcon::MiddleClick:
1196 void WpaGui::showTrayStatus()
1201 len = sizeof(buf) - 1;
1202 if (ctrlRequest("STATUS", buf, &len) < 0)
1206 QString msg, status(buf);
1208 QStringList lines = status.split(QRegExp("\\n"));
1209 for (QStringList::Iterator it = lines.begin();
1210 it != lines.end(); it++) {
1211 int pos = (*it).indexOf('=') + 1;
1215 if ((*it).startsWith("bssid="))
1216 msg.append("BSSID:\t" + (*it).mid(pos) + "\n");
1217 else if ((*it).startsWith("ssid="))
1218 msg.append("SSID: \t" + (*it).mid(pos) + "\n");
1219 else if ((*it).startsWith("pairwise_cipher="))
1220 msg.append("PAIR: \t" + (*it).mid(pos) + "\n");
1221 else if ((*it).startsWith("group_cipher="))
1222 msg.append("GROUP:\t" + (*it).mid(pos) + "\n");
1223 else if ((*it).startsWith("key_mgmt="))
1224 msg.append("AUTH: \t" + (*it).mid(pos) + "\n");
1225 else if ((*it).startsWith("wpa_state="))
1226 msg.append("STATE:\t" + (*it).mid(pos) + "\n");
1227 else if ((*it).startsWith("ip_address="))
1228 msg.append("IP: \t" + (*it).mid(pos) + "\n");
1229 else if ((*it).startsWith("Supplicant PAE state="))
1230 msg.append("PAE: \t" + (*it).mid(pos) + "\n");
1231 else if ((*it).startsWith("EAP state="))
1232 msg.append("EAP: \t" + (*it).mid(pos) + "\n");
1236 showTrayMessage(QSystemTrayIcon::Information, 10, msg);
1240 void WpaGui::closeEvent(QCloseEvent *event)
1260 if (tray_icon && !ackTrayIcon) {
1261 /* give user a visual hint that the tray icon exists */
1262 if (QSystemTrayIcon::supportsMessages()) {
1264 showTrayMessage(QSystemTrayIcon::Information, 3,
1265 qAppName() + " will keep running in "
1266 "the system tray.");
1268 QMessageBox::information(this, qAppName() + " systray",
1269 "The program will keep "
1270 "running in the system "