#include <QMessageBox>
#include <QCloseEvent>
#include <QImageReader>
+#include <QSettings>
#include "wpagui.h"
#include "dirent.h"
}
#endif
-WpaGui::WpaGui(QWidget *parent, const char *, Qt::WFlags)
- : QMainWindow(parent)
+WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *, Qt::WFlags)
+ : QMainWindow(parent), app(_app)
{
setupUi(this);
SLOT(startService()));
connect(fileStopServiceAction, SIGNAL(triggered()), this,
SLOT(stopService()));
+
+ addInterfaceAction = new QAction(this);
+ addInterfaceAction->setIconText("Add Interface");
+ fileMenu->insertAction(fileStartServiceAction, addInterfaceAction);
+
+ connect(addInterfaceAction, SIGNAL(triggered()), this,
+ SLOT(addInterface()));
#endif /* CONFIG_NATIVE_WINDOWS */
(void) statusBar();
+ /*
+ * Disable WPS tab by default; it will be enabled if wpa_supplicant is
+ * built with WPS support.
+ */
+ wpsTab->setEnabled(false);
+ wpaguiTab->setTabEnabled(wpaguiTab->indexOf(wpsTab), false);
+
connect(fileEventHistoryAction, SIGNAL(triggered()), this,
SLOT(eventHistory()));
connect(fileSaveConfigAction, SIGNAL(triggered()), this,
eh = NULL;
scanres = NULL;
+ add_iface = NULL;
udr = NULL;
tray_icon = NULL;
startInTray = false;
parse_argv();
+ if (app->isSessionRestored()) {
+ QSettings settings("wpa_supplicant", "wpa_gui");
+ settings.beginGroup("state");
+ if (app->sessionId().compare(settings.value("session_id").
+ toString()) == 0)
+ startInTray = settings.value("in_tray").toBool();
+ settings.endGroup();
+ }
+
if (QSystemTrayIcon::isSystemTrayAvailable())
createTrayIcon(startInTray);
else
show();
+ connectedToService = false;
textStatus->setText("connecting to wpa_supplicant");
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(ping()));
scanres = NULL;
}
+ if (add_iface) {
+ add_iface->close();
+ delete add_iface;
+ add_iface = NULL;
+ }
+
if (udr) {
udr->close();
delete udr;
ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf,
&len, NULL);
if (ret >= 0) {
+ connectedToService = true;
buf[len] = '\0';
pos = strchr(buf, '\n');
if (pos)
QString res(buf);
QStringList types = res.split(QChar(' '));
- actionWPS->setEnabled(types.contains("WSC"));
+ bool wps = types.contains("WSC");
+ actionWPS->setEnabled(wps);
+ wpsTab->setEnabled(wps);
+ wpaguiTab->setTabEnabled(wpaguiTab->indexOf(wpsTab), wps);
}
return 0;
textSsid->clear();
textBssid->clear();
textIpAddress->clear();
+
+#ifdef CONFIG_NATIVE_WINDOWS
+ static bool first = true;
+ if (first && connectedToService &&
+ (ctrl_iface == NULL || *ctrl_iface == '\0')) {
+ first = false;
+ if (QMessageBox::information(
+ this, qAppName(),
+ "No network interfaces in use.\n"
+ "Would you like to add one?",
+ QMessageBox::Yes | QMessageBox::No) ==
+ QMessageBox::Yes)
+ addInterface();
+ }
+#endif /* CONFIG_NATIVE_WINDOWS */
return;
}
if (!trayOnly)
show();
+ inTray = trayOnly;
}
* custom closeEvent handler take care of children */
case QSystemTrayIcon::Trigger:
ackTrayIcon = true;
- if (isVisible())
+ if (isVisible()) {
close();
- else
+ inTray = true;
+ } else {
show();
+ inTray = false;
+ }
break;
case QSystemTrayIcon::MiddleClick:
showTrayStatus();
}
#endif /* CONFIG_NATIVE_WINDOWS */
+
+
+void WpaGui::addInterface()
+{
+ if (add_iface) {
+ add_iface->close();
+ delete add_iface;
+ }
+ add_iface = new AddInterface(this, this);
+ add_iface->show();
+ add_iface->exec();
+}
+
+
+void WpaGui::saveState()
+{
+ QSettings settings("wpa_supplicant", "wpa_gui");
+ settings.beginGroup("state");
+ settings.setValue("session_id", app->sessionId());
+ settings.setValue("in_tray", inTray);
+ settings.endGroup();
+}