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"
31 WpaGui::WpaGui(QWidget *parent, const char *, Qt::WFlags)
38 connect(fileEventHistoryAction, SIGNAL(triggered()), this,
39 SLOT(eventHistory()));
40 connect(fileSaveConfigAction, SIGNAL(triggered()), this,
42 connect(fileExitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
43 connect(networkAddAction, SIGNAL(triggered()), this,
45 connect(networkEditAction, SIGNAL(triggered()), this,
46 SLOT(editSelectedNetwork()));
47 connect(networkRemoveAction, SIGNAL(triggered()), this,
48 SLOT(removeSelectedNetwork()));
49 connect(networkEnableAllAction, SIGNAL(triggered()), this,
50 SLOT(enableAllNetworks()));
51 connect(networkDisableAllAction, SIGNAL(triggered()), this,
52 SLOT(disableAllNetworks()));
53 connect(networkRemoveAllAction, SIGNAL(triggered()), this,
54 SLOT(removeAllNetworks()));
55 connect(helpIndexAction, SIGNAL(triggered()), this, SLOT(helpIndex()));
56 connect(helpContentsAction, SIGNAL(triggered()), this,
57 SLOT(helpContents()));
58 connect(helpAboutAction, SIGNAL(triggered()), this, SLOT(helpAbout()));
59 connect(disconnectButton, SIGNAL(clicked()), this, SLOT(disconnect()));
60 connect(scanButton, SIGNAL(clicked()), this, SLOT(scan()));
61 connect(connectButton, SIGNAL(clicked()), this, SLOT(connectB()));
62 connect(adapterSelect, SIGNAL(activated(const QString&)), this,
63 SLOT(selectAdapter(const QString&)));
64 connect(networkSelect, SIGNAL(activated(const QString&)), this,
65 SLOT(selectNetwork(const QString&)));
66 connect(addNetworkButton, SIGNAL(clicked()), this, SLOT(addNetwork()));
67 connect(editNetworkButton, SIGNAL(clicked()), this,
68 SLOT(editListedNetwork()));
69 connect(removeNetworkButton, SIGNAL(clicked()), this,
70 SLOT(removeListedNetwork()));
71 connect(networkList, SIGNAL(itemSelectionChanged()), this,
72 SLOT(updateNetworkDisabledStatus()));
73 connect(enableRadioButton, SIGNAL(toggled(bool)), this,
74 SLOT(enableListedNetwork(bool)));
75 connect(disableRadioButton, SIGNAL(toggled(bool)), this,
76 SLOT(disableListedNetwork(bool)));
77 connect(scanNetworkButton, SIGNAL(clicked()), this, SLOT(scan()));
78 connect(networkList, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
79 this, SLOT(editListedNetwork()));
90 ctrl_iface_dir = strdup("/var/run/wpa_supplicant");
94 if (QSystemTrayIcon::isSystemTrayAvailable())
95 createTrayIcon(startInTray);
99 textStatus->setText("connecting to wpa_supplicant");
100 timer = new QTimer(this);
101 connect(timer, SIGNAL(timeout()), SLOT(ping()));
102 timer->setSingleShot(FALSE);
105 if (openCtrlConnection(ctrl_iface) < 0) {
106 printf("Failed to open control connection to "
107 "wpa_supplicant.\n");
111 networkMayHaveChanged = true;
121 wpa_ctrl_detach(monitor_conn);
122 wpa_ctrl_close(monitor_conn);
126 wpa_ctrl_close(ctrl_conn);
151 free(ctrl_iface_dir);
152 ctrl_iface_dir = NULL;
156 void WpaGui::languageChange()
162 void WpaGui::parse_argv()
166 c = getopt(qApp->argc(), qApp->argv(), "i:p:t");
172 ctrl_iface = strdup(optarg);
175 free(ctrl_iface_dir);
176 ctrl_iface_dir = strdup(optarg);
186 int WpaGui::openCtrlConnection(const char *ifname)
190 char buf[2048], *pos, *pos2;
194 if (ifname != ctrl_iface) {
196 ctrl_iface = strdup(ifname);
199 #ifdef CONFIG_CTRL_IFACE_UDP
201 ctrl_iface = strdup("udp");
202 #endif /* CONFIG_CTRL_IFACE_UDP */
203 #ifdef CONFIG_CTRL_IFACE_UNIX
205 DIR *dir = opendir(ctrl_iface_dir);
209 while ((dent = readdir(dir))) {
210 #ifdef _DIRENT_HAVE_D_TYPE
211 /* Skip the file if it is not a socket.
212 * Also accept DT_UNKNOWN (0) in case
213 * the C library or underlying file
214 * system does not support d_type. */
215 if (dent->d_type != DT_SOCK &&
216 dent->d_type != DT_UNKNOWN)
218 #endif /* _DIRENT_HAVE_D_TYPE */
220 if (strcmp(dent->d_name, ".") == 0 ||
221 strcmp(dent->d_name, "..") == 0)
223 printf("Selected interface '%s'\n",
225 ctrl_iface = strdup(dent->d_name);
230 #endif /* CONFIG_CTRL_IFACE_UNIX */
231 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
232 struct wpa_ctrl *ctrl;
238 ctrl = wpa_ctrl_open(NULL);
240 len = sizeof(buf) - 1;
241 ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf,
245 pos = strchr(buf, '\n');
248 ctrl_iface = strdup(buf);
250 wpa_ctrl_close(ctrl);
252 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
255 if (ctrl_iface == NULL)
258 #ifdef CONFIG_CTRL_IFACE_UNIX
259 flen = strlen(ctrl_iface_dir) + strlen(ctrl_iface) + 2;
260 cfile = (char *) malloc(flen);
263 snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ctrl_iface);
264 #else /* CONFIG_CTRL_IFACE_UNIX */
265 flen = strlen(ctrl_iface) + 1;
266 cfile = (char *) malloc(flen);
269 snprintf(cfile, flen, "%s", ctrl_iface);
270 #endif /* CONFIG_CTRL_IFACE_UNIX */
273 wpa_ctrl_close(ctrl_conn);
280 wpa_ctrl_detach(monitor_conn);
281 wpa_ctrl_close(monitor_conn);
285 printf("Trying to connect to '%s'\n", cfile);
286 ctrl_conn = wpa_ctrl_open(cfile);
287 if (ctrl_conn == NULL) {
291 monitor_conn = wpa_ctrl_open(cfile);
293 if (monitor_conn == NULL) {
294 wpa_ctrl_close(ctrl_conn);
297 if (wpa_ctrl_attach(monitor_conn)) {
298 printf("Failed to attach to wpa_supplicant\n");
299 wpa_ctrl_close(monitor_conn);
301 wpa_ctrl_close(ctrl_conn);
306 #if defined(CONFIG_CTRL_IFACE_UNIX) || defined(CONFIG_CTRL_IFACE_UDP)
307 msgNotifier = new QSocketNotifier(wpa_ctrl_get_fd(monitor_conn),
308 QSocketNotifier::Read, this);
309 connect(msgNotifier, SIGNAL(activated(int)), SLOT(receiveMsgs()));
312 adapterSelect->clear();
313 adapterSelect->addItem(ctrl_iface);
314 adapterSelect->setCurrentIndex(0);
316 len = sizeof(buf) - 1;
317 if (wpa_ctrl_request(ctrl_conn, "INTERFACES", 10, buf, &len, NULL) >=
322 pos2 = strchr(pos, '\n');
325 if (strcmp(pos, ctrl_iface) != 0)
326 adapterSelect->addItem(pos);
338 static void wpa_gui_msg_cb(char *msg, size_t)
340 /* This should not happen anymore since two control connections are
342 printf("missed message: %s\n", msg);
346 int WpaGui::ctrlRequest(const char *cmd, char *buf, size_t *buflen)
350 if (ctrl_conn == NULL)
352 ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, buflen,
355 printf("'%s' command timed out.\n", cmd);
357 printf("'%s' command failed.\n", cmd);
363 void WpaGui::updateStatus()
365 char buf[2048], *start, *end, *pos;
368 pingsToStatusUpdate = 10;
370 len = sizeof(buf) - 1;
371 if (ctrl_conn == NULL || ctrlRequest("STATUS", buf, &len) < 0) {
372 textStatus->setText("Could not get status from "
374 textAuthentication->clear();
375 textEncryption->clear();
378 textIpAddress->clear();
384 bool auth_updated = false, ssid_updated = false;
385 bool bssid_updated = false, ipaddr_updated = false;
386 bool status_updated = false;
387 char *pairwise_cipher = NULL, *group_cipher = NULL;
392 end = strchr(start, '\n');
396 while (end[0] && end[1])
401 pos = strchr(start, '=');
404 if (strcmp(start, "bssid") == 0) {
405 bssid_updated = true;
406 textBssid->setText(pos);
407 } else if (strcmp(start, "ssid") == 0) {
409 textSsid->setText(pos);
410 } else if (strcmp(start, "ip_address") == 0) {
411 ipaddr_updated = true;
412 textIpAddress->setText(pos);
413 } else if (strcmp(start, "wpa_state") == 0) {
414 status_updated = true;
415 textStatus->setText(pos);
416 } else if (strcmp(start, "key_mgmt") == 0) {
418 textAuthentication->setText(pos);
419 /* TODO: could add EAP status to this */
420 } else if (strcmp(start, "pairwise_cipher") == 0) {
421 pairwise_cipher = pos;
422 } else if (strcmp(start, "group_cipher") == 0) {
432 if (pairwise_cipher || group_cipher) {
434 if (pairwise_cipher && group_cipher &&
435 strcmp(pairwise_cipher, group_cipher) != 0) {
436 encr.append(pairwise_cipher);
438 encr.append(group_cipher);
439 } else if (pairwise_cipher) {
440 encr.append(pairwise_cipher);
442 encr.append(group_cipher);
443 encr.append(" [group key only]");
445 textEncryption->setText(encr);
447 textEncryption->clear();
452 textAuthentication->clear();
458 textIpAddress->clear();
462 void WpaGui::updateNetworks()
464 char buf[2048], *start, *end, *id, *ssid, *bssid, *flags;
466 int first_active = -1;
467 int was_selected = -1;
468 bool current = false;
470 if (!networkMayHaveChanged)
473 if (networkList->currentRow() >= 0)
474 was_selected = networkList->currentRow();
476 networkSelect->clear();
477 networkList->clear();
479 if (ctrl_conn == NULL)
482 len = sizeof(buf) - 1;
483 if (ctrlRequest("LIST_NETWORKS", buf, &len) < 0)
487 start = strchr(buf, '\n');
494 end = strchr(start, '\n');
498 while (end[0] && end[1])
504 ssid = strchr(id, '\t');
508 bssid = strchr(ssid, '\t');
512 flags = strchr(bssid, '\t');
518 network.append(": ");
519 network.append(ssid);
520 networkSelect->addItem(network);
521 networkList->addItem(network);
523 if (strstr(flags, "[CURRENT]")) {
524 networkSelect->setCurrentIndex(networkSelect->count() -
527 } else if (first_active < 0 &&
528 strstr(flags, "[DISABLED]") == NULL)
529 first_active = networkSelect->count() - 1;
536 if (networkSelect->count() > 1)
537 networkSelect->addItem("Select any network");
539 if (!current && first_active >= 0)
540 networkSelect->setCurrentIndex(first_active);
542 if (was_selected >= 0 && networkList->count() > 0) {
543 if (was_selected < networkList->count())
544 networkList->setCurrentRow(was_selected);
546 networkList->setCurrentRow(networkList->count() - 1);
549 networkList->setCurrentRow(networkSelect->currentIndex());
551 networkMayHaveChanged = false;
555 void WpaGui::helpIndex()
557 printf("helpIndex\n");
561 void WpaGui::helpContents()
563 printf("helpContents\n");
567 void WpaGui::helpAbout()
569 QMessageBox::about(this, "wpa_gui for wpa_supplicant",
570 "Copyright (c) 2003-2008,\n"
571 "Jouni Malinen <j@w1.fi>\n"
572 "and contributors.\n"
574 "This program is free software. You can\n"
575 "distribute it and/or modify it under the terms "
577 "the GNU General Public License version 2.\n"
579 "Alternatively, this software may be distributed\n"
580 "under the terms of the BSD license.\n"
582 "This product includes software developed\n"
583 "by the OpenSSL Project for use in the\n"
584 "OpenSSL Toolkit (http://www.openssl.org/)\n");
588 void WpaGui::disconnect()
591 size_t reply_len = sizeof(reply);
592 ctrlRequest("DISCONNECT", reply, &reply_len);
603 scanres = new ScanResults();
606 scanres->setWpaGui(this);
612 void WpaGui::eventHistory()
619 eh = new EventHistory();
633 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
635 * QSocketNotifier cannot be used with Windows named pipes, so use a
636 * timer to check for received messages for now. This could be
637 * optimized be doing something specific to named pipes or Windows
638 * events, but it is not clear what would be the best way of doing that
642 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
644 if (scanres && !scanres->isVisible()) {
649 if (eh && !eh->isVisible()) {
654 if (udr && !udr->isVisible()) {
659 len = sizeof(buf) - 1;
660 if (ctrlRequest("PING", buf, &len) < 0) {
661 printf("PING failed - trying to reconnect\n");
662 if (openCtrlConnection(ctrl_iface) >= 0) {
663 printf("Reconnected successfully\n");
664 pingsToStatusUpdate = 0;
668 pingsToStatusUpdate--;
669 if (pingsToStatusUpdate <= 0) {
676 static int str_match(const char *a, const char *b)
678 return strncmp(a, b, strlen(b)) == 0;
682 void WpaGui::processMsg(char *msg)
684 char *pos = msg, *pos2;
690 priority = atoi(pos);
691 pos = strchr(pos, '>');
698 WpaMsg wm(pos, priority);
702 while (msgs.count() > 100)
705 /* Update last message with truncated version of the event */
706 if (strncmp(pos, "CTRL-", 5) == 0) {
707 pos2 = strchr(pos, str_match(pos, WPA_CTRL_REQ) ? ':' : ' ');
714 QString lastmsg = pos2;
715 lastmsg.truncate(40);
716 textLastMessage->setText(lastmsg);
718 pingsToStatusUpdate = 0;
719 networkMayHaveChanged = true;
721 if (str_match(pos, WPA_CTRL_REQ))
722 processCtrlReq(pos + strlen(WPA_CTRL_REQ));
723 else if (str_match(pos, WPA_EVENT_SCAN_RESULTS) && scanres)
724 scanres->updateResults();
725 else if (str_match(pos, WPA_EVENT_DISCONNECTED))
726 showTrayMessage(QSystemTrayIcon::Information, 3,
727 "Disconnected from network.");
728 else if (str_match(pos, WPA_EVENT_CONNECTED)) {
729 showTrayMessage(QSystemTrayIcon::Information, 3,
730 "Connection to network established.");
731 QTimer::singleShot(5 * 1000, this, SLOT(showTrayStatus()));
736 void WpaGui::processCtrlReq(const char *req)
742 udr = new UserDataRequest();
745 if (udr->setParams(this, req) < 0) {
755 void WpaGui::receiveMsgs()
760 while (monitor_conn && wpa_ctrl_pending(monitor_conn) > 0) {
761 len = sizeof(buf) - 1;
762 if (wpa_ctrl_recv(monitor_conn, buf, &len) == 0) {
770 void WpaGui::connectB()
773 size_t reply_len = sizeof(reply);
774 ctrlRequest("REASSOCIATE", reply, &reply_len);
778 void WpaGui::selectNetwork( const QString &sel )
782 size_t reply_len = sizeof(reply);
784 if (cmd.startsWith("Select any")) {
787 int pos = cmd.indexOf(':');
789 printf("Invalid selectNetwork '%s'\n",
790 cmd.toAscii().constData());
795 cmd.prepend("SELECT_NETWORK ");
796 ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
801 void WpaGui::enableNetwork(const QString &sel)
805 size_t reply_len = sizeof(reply);
807 if (!cmd.startsWith("all")) {
808 int pos = cmd.indexOf(':');
810 printf("Invalid enableNetwork '%s'\n",
811 cmd.toAscii().constData());
816 cmd.prepend("ENABLE_NETWORK ");
817 ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
822 void WpaGui::disableNetwork(const QString &sel)
826 size_t reply_len = sizeof(reply);
828 if (!cmd.startsWith("all")) {
829 int pos = cmd.indexOf(':');
831 printf("Invalid disableNetwork '%s'\n",
832 cmd.toAscii().constData());
837 cmd.prepend("DISABLE_NETWORK ");
838 ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
843 void WpaGui::editNetwork(const QString &sel)
848 if (!cmd.startsWith("Select any")) {
849 int pos = sel.indexOf(':');
851 printf("Invalid editNetwork '%s'\n",
852 cmd.toAscii().constData());
859 NetworkConfig *nc = new NetworkConfig();
865 nc->paramsFromConfig(id);
874 void WpaGui::editSelectedNetwork()
876 if (networkSelect->count() < 1) {
877 QMessageBox::information(this, "No Networks",
878 "There are no networks to edit.\n");
881 QString sel(networkSelect->currentText());
886 void WpaGui::editListedNetwork()
888 if (networkList->currentRow() < 0) {
889 QMessageBox::information(this, "Select A Network",
890 "Select a network from the list to"
894 QString sel(networkList->currentItem()->text());
899 void WpaGui::triggerUpdate()
902 networkMayHaveChanged = true;
907 void WpaGui::addNetwork()
909 NetworkConfig *nc = new NetworkConfig();
919 void WpaGui::removeNetwork(const QString &sel)
923 size_t reply_len = sizeof(reply);
925 if (cmd.startsWith("Select any"))
928 if (!cmd.startsWith("all")) {
929 int pos = cmd.indexOf(':');
931 printf("Invalid removeNetwork '%s'\n",
932 cmd.toAscii().constData());
937 cmd.prepend("REMOVE_NETWORK ");
938 ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
943 void WpaGui::removeSelectedNetwork()
945 if (networkSelect->count() < 1) {
946 QMessageBox::information(this, "No Networks",
947 "There are no networks to remove.\n");
950 QString sel(networkSelect->currentText());
955 void WpaGui::removeListedNetwork()
957 if (networkList->currentRow() < 0) {
958 QMessageBox::information(this, "Select A Network",
959 "Select a network from the list to"
963 QString sel(networkList->currentItem()->text());
968 void WpaGui::enableAllNetworks()
975 void WpaGui::disableAllNetworks()
982 void WpaGui::removeAllNetworks()
989 int WpaGui::getNetworkDisabled(const QString &sel)
993 size_t reply_len = sizeof(reply) - 1;
994 int pos = cmd.indexOf(':');
996 printf("Invalid getNetworkDisabled '%s'\n",
997 cmd.toAscii().constData());
1001 cmd.prepend("GET_NETWORK ");
1002 cmd.append(" disabled");
1004 if (ctrlRequest(cmd.toAscii().constData(), reply, &reply_len) >= 0
1005 && reply_len >= 1) {
1006 reply[reply_len] = '\0';
1007 if (!str_match(reply, "FAIL"))
1015 void WpaGui::updateNetworkDisabledStatus()
1017 if (networkList->currentRow() < 0)
1020 QString sel(networkList->currentItem()->text());
1022 switch (getNetworkDisabled(sel)) {
1024 if (!enableRadioButton->isChecked())
1025 enableRadioButton->setChecked(true);
1028 if (!disableRadioButton->isChecked())
1029 disableRadioButton->setChecked(true);
1035 void WpaGui::enableListedNetwork(bool enabled)
1037 if (networkList->currentRow() < 0 || !enabled)
1040 QString sel(networkList->currentItem()->text());
1042 if (getNetworkDisabled(sel) == 1)
1047 void WpaGui::disableListedNetwork(bool disabled)
1049 if (networkList->currentRow() < 0 || !disabled)
1052 QString sel(networkList->currentItem()->text());
1054 if (getNetworkDisabled(sel) == 0)
1055 disableNetwork(sel);
1059 void WpaGui::saveConfig()
1064 len = sizeof(buf) - 1;
1065 ctrlRequest("SAVE_CONFIG", buf, &len);
1069 if (str_match(buf, "FAIL"))
1070 QMessageBox::warning(this, "Failed to save configuration",
1071 "The configuration could not be saved.\n"
1073 "The update_config=1 configuration option\n"
1074 "must be used for configuration saving to\n"
1077 QMessageBox::information(this, "Saved configuration",
1078 "The current configuration was saved."
1083 void WpaGui::selectAdapter( const QString & sel )
1085 if (openCtrlConnection(sel.toAscii().constData()) < 0)
1086 printf("Failed to open control connection to "
1087 "wpa_supplicant.\n");
1093 void WpaGui::createTrayIcon(bool trayOnly)
1095 QApplication::setQuitOnLastWindowClosed(false);
1097 tray_icon = new QSystemTrayIcon(this);
1098 tray_icon->setToolTip(qAppName() + " - wpa_supplicant user interface");
1099 if (QImageReader::supportedImageFormats().contains(QByteArray("svg")))
1100 tray_icon->setIcon(QIcon(":/icons/wpa_gui.svg"));
1102 tray_icon->setIcon(QIcon(":/icons/wpa_gui.png"));
1105 SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
1106 this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
1108 ackTrayIcon = false;
1110 tray_menu = new QMenu(this);
1112 disconnectAction = new QAction("&Disconnect", this);
1113 reconnectAction = new QAction("Re&connect", this);
1114 connect(disconnectAction, SIGNAL(triggered()), this,
1115 SLOT(disconnect()));
1116 connect(reconnectAction, SIGNAL(triggered()), this,
1118 tray_menu->addAction(disconnectAction);
1119 tray_menu->addAction(reconnectAction);
1120 tray_menu->addSeparator();
1122 eventAction = new QAction("&Event History", this);
1123 scanAction = new QAction("Scan &Results", this);
1124 statAction = new QAction("S&tatus", this);
1125 connect(eventAction, SIGNAL(triggered()), this, SLOT(eventHistory()));
1126 connect(scanAction, SIGNAL(triggered()), this, SLOT(scan()));
1127 connect(statAction, SIGNAL(triggered()), this, SLOT(showTrayStatus()));
1128 tray_menu->addAction(eventAction);
1129 tray_menu->addAction(scanAction);
1130 tray_menu->addAction(statAction);
1131 tray_menu->addSeparator();
1133 showAction = new QAction("&Show Window", this);
1134 hideAction = new QAction("&Hide Window", this);
1135 quitAction = new QAction("&Quit", this);
1136 connect(showAction, SIGNAL(triggered()), this, SLOT(show()));
1137 connect(hideAction, SIGNAL(triggered()), this, SLOT(hide()));
1138 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
1139 tray_menu->addAction(showAction);
1140 tray_menu->addAction(hideAction);
1141 tray_menu->addSeparator();
1142 tray_menu->addAction(quitAction);
1144 tray_icon->setContextMenu(tray_menu);
1153 void WpaGui::showTrayMessage(QSystemTrayIcon::MessageIcon type, int sec,
1154 const QString & msg)
1156 if (!QSystemTrayIcon::supportsMessages())
1159 if (isVisible() || !tray_icon || !tray_icon->isVisible())
1162 tray_icon->showMessage(qAppName(), msg, type, sec * 1000);
1166 void WpaGui::trayActivated(QSystemTrayIcon::ActivationReason how)
1169 /* use close() here instead of hide() and allow the
1170 * custom closeEvent handler take care of children */
1171 case QSystemTrayIcon::Trigger:
1178 case QSystemTrayIcon::MiddleClick:
1187 void WpaGui::showTrayStatus()
1192 len = sizeof(buf) - 1;
1193 if (ctrlRequest("STATUS", buf, &len) < 0)
1197 QString msg, status(buf);
1199 QStringList lines = status.split(QRegExp("\\n"));
1200 for (QStringList::Iterator it = lines.begin();
1201 it != lines.end(); it++) {
1202 int pos = (*it).indexOf('=') + 1;
1206 if ((*it).startsWith("bssid="))
1207 msg.append("BSSID:\t" + (*it).mid(pos) + "\n");
1208 else if ((*it).startsWith("ssid="))
1209 msg.append("SSID: \t" + (*it).mid(pos) + "\n");
1210 else if ((*it).startsWith("pairwise_cipher="))
1211 msg.append("PAIR: \t" + (*it).mid(pos) + "\n");
1212 else if ((*it).startsWith("group_cipher="))
1213 msg.append("GROUP:\t" + (*it).mid(pos) + "\n");
1214 else if ((*it).startsWith("key_mgmt="))
1215 msg.append("AUTH: \t" + (*it).mid(pos) + "\n");
1216 else if ((*it).startsWith("wpa_state="))
1217 msg.append("STATE:\t" + (*it).mid(pos) + "\n");
1218 else if ((*it).startsWith("ip_address="))
1219 msg.append("IP: \t" + (*it).mid(pos) + "\n");
1220 else if ((*it).startsWith("Supplicant PAE state="))
1221 msg.append("PAE: \t" + (*it).mid(pos) + "\n");
1222 else if ((*it).startsWith("EAP state="))
1223 msg.append("EAP: \t" + (*it).mid(pos) + "\n");
1227 showTrayMessage(QSystemTrayIcon::Information, 10, msg);
1231 void WpaGui::closeEvent(QCloseEvent *event)
1251 if (tray_icon && !ackTrayIcon) {
1252 /* give user a visual hint that the tray icon exists */
1253 if (QSystemTrayIcon::supportsMessages()) {
1255 showTrayMessage(QSystemTrayIcon::Information, 3,
1256 qAppName() + " will keep running in "
1257 "the system tray.");
1259 QMessageBox::information(this, qAppName() + " systray",
1260 "The program will keep "
1261 "running in the system "