Save and restore wpa_gui state when session manager restarts the app

This makes wpa_gui remember whether it was only in the tray when the
session was terminated and starts only in the tray if session manager
restarts it automatically.
This commit is contained in:
Jouni Malinen 2009-01-17 13:45:05 +02:00
parent 6fa68a0ee5
commit a5da9c64c9
3 changed files with 59 additions and 7 deletions

View file

@ -18,10 +18,32 @@
#include <QApplication>
#include "wpagui.h"
class WpaGuiApp : public QApplication
{
public:
WpaGuiApp(int &argc, char **argv);
virtual void saveState(QSessionManager &manager);
WpaGui *w;
};
WpaGuiApp::WpaGuiApp(int &argc, char **argv) : QApplication(argc, argv)
{
}
void WpaGuiApp::saveState(QSessionManager &manager)
{
QApplication::saveState(manager);
w->saveState();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
WpaGui w;
WpaGuiApp app(argc, argv);
WpaGui w(&app);
int ret;
#ifdef CONFIG_NATIVE_WINDOWS
@ -32,6 +54,8 @@ int main(int argc, char *argv[])
}
#endif /* CONFIG_NATIVE_WINDOWS */
app.w = &w;
ret = app.exec();
#ifdef CONFIG_NATIVE_WINDOWS

View file

@ -25,6 +25,7 @@
#include <QMessageBox>
#include <QCloseEvent>
#include <QImageReader>
#include <QSettings>
#include "wpagui.h"
#include "dirent.h"
@ -41,8 +42,8 @@ static int wpagui_printf(const char *, ...)
}
#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);
@ -137,6 +138,15 @@ WpaGui::WpaGui(QWidget *parent, const char *, Qt::WFlags)
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
@ -1294,6 +1304,7 @@ void WpaGui::createTrayIcon(bool trayOnly)
if (!trayOnly)
show();
inTray = trayOnly;
}
@ -1317,10 +1328,13 @@ void WpaGui::trayActivated(QSystemTrayIcon::ActivationReason how)
* 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();
@ -1664,3 +1678,13 @@ void WpaGui::addInterface()
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();
}

View file

@ -28,7 +28,7 @@ class WpaGui : public QMainWindow, public Ui::WpaGui
Q_OBJECT
public:
WpaGui(QWidget *parent = 0, const char *name = 0,
WpaGui(QApplication *app, QWidget *parent = 0, const char *name = 0,
Qt::WFlags fl = 0);
~WpaGui();
@ -40,6 +40,7 @@ public:
virtual void disableNetwork(const QString &sel);
virtual int getNetworkDisabled(const QString &sel);
void setBssFromScan(const QString &bssid);
void saveState();
public slots:
virtual void parse_argv();
@ -136,6 +137,9 @@ private:
AddInterface *add_iface;
bool connectedToService;
QApplication *app;
bool inTray;
};
#endif /* WPAGUI_H */