可以保存设置
This commit is contained in:
+7
-1
@@ -1,12 +1,16 @@
|
||||
#include "maintray.h"
|
||||
|
||||
MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): QSystemTrayIcon(parent), menu(new QMenu()),
|
||||
MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): QSystemTrayIcon(parent),
|
||||
menu(new QMenu()), settings("TurnMeOn", "NEU-Dectect"),
|
||||
opWindow(settings.value("id",0).toByteArray(), settings.value("password", 0).toByteArray()),
|
||||
user(username),passwd(password)
|
||||
{
|
||||
opWindow.hide();
|
||||
setIcon(QIcon(tr(":/icon/favicon.ico")));
|
||||
|
||||
netctrl = new NetController(user,passwd,this);
|
||||
netctrl->setUsername(settings.value("id",0).toByteArray());
|
||||
netctrl->setPassword(settings.value("password", 0).toByteArray());
|
||||
|
||||
connect(&opWindow, OptionsWindow::saveSettings, this, updataUserInfo);
|
||||
//发送通知
|
||||
@@ -75,5 +79,7 @@ void MainTray::updataUserInfo(QByteArray id, QByteArray pass)
|
||||
netctrl->setPassword(pass);
|
||||
opWindow.hide();
|
||||
netctrl->sendLoginRequest();
|
||||
settings.setValue("id", id);
|
||||
settings.setValue("password", pass);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <QAction>
|
||||
#include <netcontroller.h>
|
||||
#include <optionswindow.h>
|
||||
#include <QSettings>
|
||||
|
||||
class MainTray: public QSystemTrayIcon
|
||||
{
|
||||
@@ -18,7 +19,9 @@ private:
|
||||
QMenu *menu;
|
||||
QAction *loginAction, *logoutAction, *autoLogin, *optionsAction, *quitAction;
|
||||
NetController *netctrl;
|
||||
QSettings settings;
|
||||
OptionsWindow opWindow;
|
||||
|
||||
bool isAutoLogin = true;
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void showOptions();
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
NetController::NetController(QByteArray id, QByteArray passwd, QObject *parent) : QObject(parent),
|
||||
username(id), password(passwd), flag(Disconnected), manager(this), checkTimer(new QTimer(this))
|
||||
{
|
||||
{
|
||||
checkParam.append("action=get_online_info");
|
||||
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
||||
@@ -32,7 +32,6 @@ private:
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkRequest request;
|
||||
QTimer *checkTimer;
|
||||
|
||||
signals:
|
||||
void getOnline();
|
||||
void getOffline();
|
||||
|
||||
+3
-1
@@ -1,14 +1,16 @@
|
||||
#include "optionswindow.h"
|
||||
|
||||
OptionsWindow::OptionsWindow(QWidget *parent) : QWidget(parent)
|
||||
OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
vlayout = new QVBoxLayout(this);
|
||||
layout = new QFormLayout();
|
||||
hlayout = new QHBoxLayout();
|
||||
|
||||
idEdit = new QLineEdit(this);
|
||||
idEdit->setText(id);
|
||||
passwordEdit = new QLineEdit(this);
|
||||
passwordEdit->setEchoMode(QLineEdit::Password);
|
||||
passwordEdit->setText(pass);
|
||||
|
||||
layout->addRow(tr("用户名"), idEdit);
|
||||
layout->addRow(tr("密码"), passwordEdit);
|
||||
|
||||
+2
-1
@@ -6,12 +6,13 @@
|
||||
#include <QPushButton>
|
||||
#include <QFormLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QSettings>
|
||||
|
||||
class OptionsWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OptionsWindow(QWidget *parent = nullptr);
|
||||
explicit OptionsWindow(QByteArray id, QByteArray pass, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QLineEdit *idEdit, *passwordEdit;
|
||||
|
||||
Reference in New Issue
Block a user