fix
This commit is contained in:
+25
-10
@@ -14,24 +14,25 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
netctrl->setPassword(settings.value("password", 0).toByteArray());
|
||||
|
||||
connect(&opWindow, OptionsWindow::saveSettings, this, updataUserInfo);
|
||||
//发送通知
|
||||
//连接controller状态改变信号
|
||||
connect(netctrl, NetController::getOnline, this, [this](){
|
||||
showMessage(tr("网络已连接"),tr("校园网登陆成功"), this->icon(), msgDur);
|
||||
currentState = Online;
|
||||
setToolTip(tr("当前状态:连接"));
|
||||
setToolTip(tr("当前状态:连接"/*\n自动重连:") + (isAutoLogin? tr("开启"):tr("关闭")*/));
|
||||
});
|
||||
connect(netctrl, NetController::getOffline, this, [this](bool isForce){
|
||||
connect(netctrl, NetController::getOffline, this, [this](){
|
||||
showMessage(tr("网络已断开"),tr("校园网已注销"), this->icon(), msgDur);
|
||||
currentState = Offline;
|
||||
setToolTip(tr("当前状态:断开"));
|
||||
isForceLogout = isForce;
|
||||
setToolTip(tr("当前状态:断开"/*\n自动重连:") + (isAutoLogin? tr("开启"):tr("关闭")*/));
|
||||
}
|
||||
);
|
||||
connect(netctrl, NetController::getDisconnected, this, [this](){
|
||||
showMessage(tr("无法连接至校园网"),tr("校园网失去连接"), this->icon(), msgDur);
|
||||
setToolTip(tr("当前状态:无法连接"));});
|
||||
showMessage(tr("网络已断开"),tr("无法连接至校园网"), this->icon(), msgDur);
|
||||
currentState = Disconnected;
|
||||
setToolTip(tr("当前状态:无法连接"/*\n自动重连:") + (isAutoLogin? tr("开启"):tr("关闭")*/));});
|
||||
connect(netctrl, NetController::sendInfo, this, handleInfo);
|
||||
|
||||
//菜单Action
|
||||
loginAction = new QAction(tr("连接网络"),this);
|
||||
logoutAction = new QAction(tr("断开网络"),this);
|
||||
autoLogin = new QAction(tr("自动重连"), this);
|
||||
@@ -46,11 +47,16 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
|
||||
autoLogin->setCheckable(true);
|
||||
|
||||
connect(loginAction, QAction::triggered, this,[this](){netctrl->sendLoginRequest();});
|
||||
connect(logoutAction, QAction::triggered, this,[this](){netctrl->sendLogoutRequest();});
|
||||
connect(loginAction, QAction::triggered, this,[this](){
|
||||
netctrl->sendLoginRequest();
|
||||
isForceLogout = false;
|
||||
});
|
||||
connect(logoutAction, QAction::triggered, this,[this](){
|
||||
netctrl->sendLogoutRequest();
|
||||
isForceLogout = true;
|
||||
});
|
||||
connect(autoLogin, QAction::toggled, this, [this](bool set){
|
||||
isAutoLogin = set;
|
||||
netctrl->sendLoginRequest();
|
||||
});
|
||||
connect(optionsAction, QAction::triggered, this, [this](){showOptions();});
|
||||
connect(aboutAction, QAction::triggered, this, showAbout);
|
||||
@@ -75,17 +81,26 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
setContextMenu(menu);
|
||||
|
||||
connect(this, activated, this, handleActivated);
|
||||
connect(this, exit, this, [this](){setVisible(false);});
|
||||
|
||||
autoLoginTimer = new QTimer(this);
|
||||
autoLoginTimer->setInterval(1000);
|
||||
autoLoginTimer->start();
|
||||
connect(autoLoginTimer,QTimer::timeout, this, [this](){
|
||||
// netctrl->checkStatus(); //可只使用一个定时器
|
||||
//Offline状态下自动重连
|
||||
if(currentState == Offline && isAutoLogin && !isForceLogout)
|
||||
netctrl->sendLoginRequest();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
MainTray::~MainTray()
|
||||
{
|
||||
delete menu;
|
||||
delete infoMenu;
|
||||
}
|
||||
|
||||
void MainTray::handleActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
switch (reason) {
|
||||
|
||||
+9
-8
@@ -16,6 +16,7 @@ class MainTray: public QSystemTrayIcon
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainTray(QByteArray username, QByteArray password, QObject *parent = Q_NULLPTR);
|
||||
~MainTray();
|
||||
enum Status {Unknown, Offline, Online, Disconnected};
|
||||
|
||||
private:
|
||||
@@ -25,17 +26,17 @@ private:
|
||||
NetController *netctrl;
|
||||
QSettings settings;
|
||||
OptionsWindow opWindow;
|
||||
QTimer *autoLoginTimer;
|
||||
bool isForceLogout = false;
|
||||
QTimer *autoLoginTimer; //自动重连定时器
|
||||
|
||||
bool isAutoLogin = true;
|
||||
Status currentState = Unknown;
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void showOptions();
|
||||
void showAbout();
|
||||
bool isForceLogout = false; //自动重连flag
|
||||
bool isAutoLogin = true; //手动注销flag
|
||||
Status currentState = Unknown; //当前状态
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason);//处理左键单击
|
||||
void showOptions(); //显示选项窗口
|
||||
void showAbout(); //显示关于窗口
|
||||
|
||||
QByteArray user, passwd;
|
||||
int msgDur = 500;
|
||||
int msgDur = 1000; //通知持续时间
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
+3
-4
@@ -1,7 +1,8 @@
|
||||
#include "netcontroller.h"
|
||||
|
||||
NetController::NetController(QByteArray id, QByteArray passwd, QObject *parent) : QObject(parent),
|
||||
username(id), password(passwd), flag(Disconnected), manager(this), checkTimer(new QTimer(this))
|
||||
username(id), password(passwd), NEUStatus(Unknown), flag(Unknown),
|
||||
manager(this), checkTimer(new QTimer(this))
|
||||
{
|
||||
checkParam.append("action=get_online_info");
|
||||
|
||||
@@ -19,8 +20,7 @@ void NetController::checkStatus()
|
||||
if(NEUStatus==Offline&&flag!=Offline)
|
||||
{
|
||||
flag = Offline;
|
||||
emit getOffline(isForceLogout);
|
||||
isForceLogout = false;
|
||||
emit getOffline();
|
||||
}
|
||||
else if(NEUStatus == Online && flag != Online)
|
||||
{
|
||||
@@ -42,7 +42,6 @@ void NetController::sendCheckRequest()
|
||||
|
||||
void NetController::sendLoginRequest()
|
||||
{
|
||||
isForceLogout = true;
|
||||
request.setUrl(QUrl(loginUrl));
|
||||
|
||||
QByteArray loginParam;
|
||||
|
||||
+1
-2
@@ -32,10 +32,9 @@ private:
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkRequest request;
|
||||
QTimer *checkTimer;
|
||||
bool isForceLogout = false;
|
||||
signals:
|
||||
void getOnline();
|
||||
void getOffline(bool isForce);
|
||||
void getOffline();
|
||||
void getDisconnected();
|
||||
void sendInfo(QString mb, QString sec, QString balance, QString ip);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user