Compare commits
13
Commits
v1.2
...
v1.3-beta.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7f45f5341 | ||
|
|
97cec864d0 | ||
|
|
661c7378b0 | ||
|
|
2ed45b4a86 | ||
|
|
8e27b85fc4 | ||
|
|
7bc558742d | ||
|
|
2fd13b2c3f | ||
|
|
9d84abda06 | ||
|
|
72a43644bd | ||
|
|
81a54e9974 | ||
|
|
b7a1ff371d | ||
|
|
103933fa66 | ||
|
|
4a98fa4d48 |
No files matched your search
File renamed without changes.
@@ -1 +1,17 @@
|
||||
# NEU-Dectect
|
||||
# NEU-Dectect
|
||||
## 使用教程
|
||||
* 注:软件只有托盘中的图标以及单击显示的菜单,并没有主窗口
|
||||
1. 在设置中填好校园网账号和密码
|
||||
2. 开始使用
|
||||
3. 双击托盘图标可以登录
|
||||
## 自动重连
|
||||
在已经登陆的状态下检测到校园网状态变为断开,此时会进行重新登陆,重新登陆等同于在ipgw网页点击`断开连接`后再进行`连接网络`
|
||||
## 网络状态检测
|
||||
网络状态分为
|
||||
* 未连接到校园网
|
||||
* 连接到校园网并已经登陆
|
||||
* 连接到校园网但未登陆
|
||||
|
||||
*为了检测网络状态,此工具会持续发送请求,~~可能由于请求频率过高,有很大概率会出现网关登陆被限制的情况(提示请5分钟之后再尝试)~~
|
||||
|
||||
*请不要短时间内频繁的进行登陆,会出现登陆受限的情况
|
||||
+82
-29
@@ -1,11 +1,17 @@
|
||||
#include "maintray.h"
|
||||
|
||||
MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): QSystemTrayIcon(parent),
|
||||
menu(new QMenu()),infoMenu(new QMenu()), settingsMenu(new QMenu()), settings("TurnMeOn", "NEU-Dectect"),
|
||||
opWindow(settings.value("id",0).toByteArray(), settings.value("password", 0).toByteArray()),
|
||||
user(username),passwd(password)
|
||||
//初始化menu
|
||||
menu(new QMenu()),
|
||||
infoMenu(new QMenu()),
|
||||
settingsMenu(new QMenu()),
|
||||
//初始化settings
|
||||
settings(QSettings::IniFormat, QSettings::UserScope, "TurnMeOn", "NEU-Dectect"),
|
||||
//初始化optionswindow
|
||||
opWindow(settings.value("id", "").toByteArray(), settings.value("password", "").toByteArray()),
|
||||
user(username),
|
||||
passwd(password)
|
||||
{
|
||||
|
||||
opWindow.hide();
|
||||
setIcon(QIcon(tr(":/icon/favicon.ico")));
|
||||
|
||||
@@ -13,23 +19,35 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
netctrl->setUsername(settings.value("id",0).toByteArray());
|
||||
netctrl->setPassword(settings.value("password", 0).toByteArray());
|
||||
|
||||
connect(&opWindow, OptionsWindow::saveSettings, this, updataUserInfo);
|
||||
connect(&opWindow, OptionsWindow::saveSettings, this, updateUserInfo);
|
||||
//连接controller状态改变信号
|
||||
connect(netctrl, NetController::getOnline, this, [this](){
|
||||
showMessage(tr("网络已连接"),tr("校园网登陆成功"), this->icon(), msgDur);
|
||||
currentState = Online;
|
||||
setToolTip(tr("当前状态:连接"/*\n自动重连:") + (isAutoLogin? tr("开启"):tr("关闭")*/));
|
||||
});
|
||||
connect(netctrl, NetController::getOffline, this, [this](){
|
||||
showMessage(tr("网络已断开"),tr("校园网已注销"), this->icon(), msgDur);
|
||||
currentState = Offline;
|
||||
setToolTip(tr("当前状态:断开"/*\n自动重连:") + (isAutoLogin? tr("开启"):tr("关闭")*/));
|
||||
connect(netctrl, NetController::stateChanged, this, [this](NetController::State state){
|
||||
switch (state) {
|
||||
case NetController::Online:
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("网络已连接"),tr("校园网登陆成功"), this->icon(), msgDur);
|
||||
loginAction->setEnabled(true);
|
||||
logoutAction->setEnabled(true);
|
||||
break;
|
||||
case NetController::Offline:
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("网络已断开"),tr("校园网已注销"), this->icon(), msgDur);
|
||||
loginAction->setEnabled(true);
|
||||
logoutAction->setEnabled(true);
|
||||
break;
|
||||
case NetController::Disconnected:
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("网络已断开"),tr("无法连接至校园网"), this->icon(), msgDur);
|
||||
loginAction->setDisabled(true);
|
||||
logoutAction->setDisabled(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
);
|
||||
connect(netctrl, NetController::getDisconnected, this, [this](){
|
||||
showMessage(tr("网络已断开"),tr("无法连接至校园网"), this->icon(), msgDur);
|
||||
currentState = Disconnected;
|
||||
setToolTip(tr("当前状态:无法连接"/*\n自动重连:") + (isAutoLogin? tr("开启"):tr("关闭")*/));});
|
||||
currentState = state;
|
||||
showToolTip(state);
|
||||
});
|
||||
|
||||
connect(netctrl, NetController::sendInfo, this, handleInfo);
|
||||
|
||||
//菜单Action
|
||||
@@ -38,6 +56,7 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
autoLogin = new QAction(tr("自动重连"), this);
|
||||
optionsAction = new QAction(tr("选项"), this);
|
||||
bootAction = new QAction(tr("开机启动"), this);
|
||||
muteAction = new QAction(tr("勿扰模式"), this);
|
||||
aboutAction = new QAction(tr("关于"), this);
|
||||
quitAction = new QAction(tr("退出"), this);
|
||||
|
||||
@@ -48,8 +67,12 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
|
||||
autoLogin->setCheckable(true);
|
||||
bootAction->setCheckable(true);
|
||||
muteAction->setCheckable(true);
|
||||
|
||||
muteAction->setToolTip(tr("勿扰模式下不会发出通知"));
|
||||
|
||||
connect(loginAction, QAction::triggered, this,[this](){
|
||||
netctrl->sendLogoutRequest();
|
||||
netctrl->sendLoginRequest();
|
||||
isForceLogout = false;
|
||||
});
|
||||
@@ -58,8 +81,12 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
isForceLogout = true;
|
||||
});
|
||||
connect(autoLogin, QAction::toggled, this, [this](bool set){
|
||||
isAutoLogin = set;
|
||||
settings.setValue("isAutoLogin", set);
|
||||
isForceLogout = false;
|
||||
showToolTip(currentState);
|
||||
});
|
||||
connect(muteAction, QAction::toggled, this, [this](bool set){
|
||||
settings.setValue("isMute", set);
|
||||
});
|
||||
connect(bootAction, QAction::toggled, this, [this](bool set){
|
||||
settings.setValue("isOnBoot", set);
|
||||
@@ -71,9 +98,12 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
|
||||
autoLogin->setChecked(settings.value("isAutoLogin", true).toBool());
|
||||
bootAction->setChecked(settings.value("isOnBoot", false).toBool());
|
||||
muteAction->setChecked(settings.value("isMute", false).toBool());
|
||||
|
||||
|
||||
settingsMenu->setTitle(tr("设置"));
|
||||
settingsMenu->addAction(optionsAction);
|
||||
settingsMenu->addAction(muteAction);
|
||||
settingsMenu->addAction(bootAction);
|
||||
|
||||
infoMenu->setTitle(tr("账户信息"));
|
||||
@@ -96,15 +126,15 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
connect(this, exit, this, [this](){setVisible(false);});
|
||||
|
||||
autoLoginTimer = new QTimer(this);
|
||||
autoLoginTimer->setInterval(1000);
|
||||
autoLoginTimer->setInterval(checkInterval);
|
||||
autoLoginTimer->start();
|
||||
connect(autoLoginTimer,QTimer::timeout, this, [this](){
|
||||
// netctrl->checkStatus(); //可只使用一个定时器
|
||||
netctrl->checkState();
|
||||
//Offline状态下自动重连
|
||||
if(currentState == Offline && isAutoLogin && !isForceLogout)
|
||||
netctrl->sendLoginRequest();
|
||||
if(currentState == NetController::Offline && autoLogin->isChecked() && !isForceLogout){
|
||||
loginAction->trigger();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
MainTray::~MainTray()
|
||||
@@ -113,9 +143,32 @@ MainTray::~MainTray()
|
||||
delete infoMenu;
|
||||
}
|
||||
|
||||
void MainTray::showToolTip(NetController::State state)
|
||||
{
|
||||
switch (state) {
|
||||
case NetController::Online:
|
||||
setIcon(QIcon(tr(":/icon/favicon.ico")));
|
||||
setToolTip(tr("当前状态:连接\n自动重连:") + (autoLogin->isChecked()? tr("开启"):tr("关闭")));
|
||||
break;
|
||||
case NetController::Offline:
|
||||
setIcon(QIcon(tr(":/icon/offline.ico")));
|
||||
setToolTip(tr("当前状态:断开\n自动重连:") + (autoLogin->isChecked()? tr("开启"):tr("关闭"))+tr("\n双击以登陆"));
|
||||
break;
|
||||
case NetController::Disconnected:
|
||||
setIcon(QIcon(tr(":/icon/offline.ico")));
|
||||
setToolTip(tr("当前状态:无法连接\n自动重连:") + (autoLogin->isChecked()? tr("开启"):tr("关闭")));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainTray::handleActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
switch (reason) {
|
||||
case QSystemTrayIcon::DoubleClick:
|
||||
loginAction->trigger();
|
||||
break;
|
||||
case QSystemTrayIcon::Trigger:
|
||||
contextMenu()->popup(this->geometry().topRight());
|
||||
break;
|
||||
@@ -134,10 +187,10 @@ void MainTray::showAbout()
|
||||
QMessageBox *aboutWindow = new QMessageBox();
|
||||
aboutWindow->setStandardButtons(QMessageBox::Ok);
|
||||
aboutWindow->setText(tr("<h1>NEU-Monitor</h1>"
|
||||
"<p>Based on Qt 5.10.0 (MinGW 5.3.0, 32bit)</p>"
|
||||
"Source Code: <a href=\"https://github.com/TurnMeOn/NEU-Monitor\">https://github.com/TurnMeOn/NEU-Monitor</a><br/>"
|
||||
"<p>Based on Qt 5.10.1 (MinGW 5.3.0, 32bit)</p>"
|
||||
"Source Code: <a href=\"https://github.com/c-my/NEU-Monitor\">https://github.com/c-my/NEU-Monitor</a><br/>"
|
||||
"Email: <address>"
|
||||
"<a href=\"mailto:cmy1113@yeah.net?subject=SerialAsst Feedback\">TurnMeOn</a>"
|
||||
"<a href=\"mailto:cmy1113@yeah.net?subject=SerialAsst Feedback\">Cai.MY</a>"
|
||||
"</address>"));
|
||||
aboutWindow->show();
|
||||
}
|
||||
@@ -158,7 +211,7 @@ void MainTray::setAutoStart(bool set)
|
||||
delete settings;
|
||||
}
|
||||
|
||||
void MainTray::updataUserInfo(QByteArray id, QByteArray pass)
|
||||
void MainTray::updateUserInfo(QByteArray id, QByteArray pass)
|
||||
{
|
||||
netctrl->setUsername(id);
|
||||
netctrl->setPassword(pass);
|
||||
|
||||
+8
-6
@@ -18,34 +18,36 @@ class MainTray: public QSystemTrayIcon
|
||||
public:
|
||||
MainTray(QByteArray username, QByteArray password, QObject *parent = Q_NULLPTR);
|
||||
~MainTray();
|
||||
enum Status {Unknown, Offline, Online, Disconnected};
|
||||
|
||||
private:
|
||||
QMenu *menu, *infoMenu, *settingsMenu;
|
||||
QAction *loginAction, *logoutAction, *autoLogin, *optionsAction, *aboutAction, *quitAction;
|
||||
QAction *mbAction, *timeAction, *balanceAction, *ipAction, *bootAction;
|
||||
QAction *mbAction, *timeAction, *balanceAction, *ipAction, *bootAction, *muteAction;
|
||||
NetController *netctrl;
|
||||
QSettings settings;
|
||||
OptionsWindow opWindow;
|
||||
QTimer *autoLoginTimer; //自动重连定时器
|
||||
|
||||
bool isForceLogout = false; //自动重连flag
|
||||
bool isAutoLogin = true; //手动注销flag
|
||||
Status currentState = Unknown; //当前状态
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason);//处理左键单击
|
||||
|
||||
NetController::State currentState = NetController::Unknown; //当前状态
|
||||
|
||||
void showToolTip(NetController::State state);
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason);//处理左键单击、双击
|
||||
void showOptions(); //显示选项窗口
|
||||
void showAbout(); //显示关于窗口
|
||||
void setAutoStart(bool set);
|
||||
|
||||
QByteArray user, passwd;
|
||||
int msgDur = 1000; //通知持续时间
|
||||
int checkInterval = 1000; //查询状态定时器周期
|
||||
|
||||
|
||||
signals:
|
||||
void exit();
|
||||
|
||||
private slots:
|
||||
void updataUserInfo(QByteArray id, QByteArray pass);
|
||||
void updateUserInfo(QByteArray id, QByteArray pass);
|
||||
void handleInfo(QString mb, QString sec, QString balance, QString ip);
|
||||
|
||||
};
|
||||
|
||||
+26
-19
@@ -1,36 +1,43 @@
|
||||
#include "netcontroller.h"
|
||||
|
||||
NetController::NetController(QByteArray id, QByteArray passwd, QObject *parent) : QObject(parent),
|
||||
username(id), password(passwd), NEUStatus(Unknown), flag(Unknown),
|
||||
manager(this), checkTimer(new QTimer(this))
|
||||
username(id), password(passwd), NEUState(Unknown), lastState(Unknown),
|
||||
manager(this)
|
||||
{
|
||||
checkParam.append("action=get_online_info");
|
||||
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
connect(&manager, QNetworkAccessManager::finished, this, handleResponse);
|
||||
request.setHeader(QNetworkRequest::ContentLengthHeader, "100");
|
||||
request.setRawHeader("Host", "ipgw.neu.edu.cn");
|
||||
request.setRawHeader("Cache-Control", "max-age=0");
|
||||
request.setRawHeader("Origin", "http://ipgw.neu.edu.cn");
|
||||
request.setRawHeader("Upgrade-Insecure-Requests", "1");
|
||||
request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36");
|
||||
request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
|
||||
request.setRawHeader("Referer", "http://ipgw.neu.edu.cn/srun_portal_pc.php?ac_id=1&");
|
||||
request.setRawHeader("Accept-Encoding", "gzip, deflate");
|
||||
request.setRawHeader("Accept-Language", "zh-CN,zh;q=0.9");
|
||||
|
||||
checkTimer->setInterval(1000);
|
||||
connect(checkTimer, QTimer::timeout, this, checkStatus);
|
||||
checkTimer->start();
|
||||
connect(&manager, QNetworkAccessManager::finished, this, handleResponse);
|
||||
}
|
||||
|
||||
void NetController::checkStatus()
|
||||
void NetController::checkState()
|
||||
{
|
||||
sendCheckRequest();
|
||||
if(NEUStatus==Offline&&flag!=Offline)
|
||||
if(NEUState==Offline&&lastState!=Offline)
|
||||
{
|
||||
flag = Offline;
|
||||
emit getOffline();
|
||||
lastState = Offline;
|
||||
emit stateChanged(lastState);
|
||||
}
|
||||
else if(NEUStatus == Online && flag != Online)
|
||||
else if(NEUState == Online && lastState != Online)
|
||||
{
|
||||
flag = Online;
|
||||
emit getOnline();
|
||||
lastState = Online;
|
||||
emit stateChanged(lastState);
|
||||
}
|
||||
else if(NEUStatus == Disconnected && flag != Disconnected)
|
||||
else if(NEUState == Disconnected && lastState != Disconnected)
|
||||
{
|
||||
flag = Disconnected;
|
||||
emit getDisconnected();
|
||||
lastState = Disconnected;
|
||||
emit stateChanged(lastState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,18 +93,18 @@ void NetController::handleResponse(QNetworkReply *reply)
|
||||
QString status = reply->readAll();
|
||||
if(status==offlineString)
|
||||
{
|
||||
NEUStatus = Offline;
|
||||
NEUState = Offline;
|
||||
}
|
||||
else
|
||||
{
|
||||
NEUStatus = Online;
|
||||
NEUState = Online;
|
||||
QStringList infoList = status.split(',');
|
||||
emit sendInfo(infoList[0], infoList[1], infoList[2], infoList[5]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NEUStatus = Disconnected;
|
||||
NEUState = Disconnected;
|
||||
}
|
||||
}
|
||||
else if(url==loginUrl)
|
||||
|
||||
+5
-7
@@ -12,7 +12,7 @@ class NetController : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NetController(QByteArray username, QByteArray password, QObject *parent = nullptr);
|
||||
void checkStatus();
|
||||
void checkState();
|
||||
void sendCheckRequest();
|
||||
void sendLoginRequest();
|
||||
void sendLogoutRequest();
|
||||
@@ -20,22 +20,20 @@ public:
|
||||
void setUsername(QByteArray newName) { username = newName; }
|
||||
void setPassword(QByteArray newPass) { password = newPass; }
|
||||
|
||||
enum Status {Unknown, Offline, Online, Disconnected};
|
||||
enum State {Unknown, Offline, Online, Disconnected};
|
||||
|
||||
private:
|
||||
QString checkUrl = "http://ipgw.neu.edu.cn/include/auth_action.php";
|
||||
QString loginUrl = "http://ipgw.neu.edu.cn/srun_portal_pc.php?ac_id=1&";
|
||||
QString offlineString = "not_online";
|
||||
QByteArray checkParam, username, password;
|
||||
Status NEUStatus = Unknown, flag = Unknown;
|
||||
State NEUState = Unknown, lastState = Unknown;
|
||||
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkRequest request;
|
||||
QTimer *checkTimer;
|
||||
|
||||
signals:
|
||||
void getOnline();
|
||||
void getOffline();
|
||||
void getDisconnected();
|
||||
void stateChanged(State newState);
|
||||
void sendInfo(QString mb, QString sec, QString balance, QString ip);
|
||||
|
||||
public slots:
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
+9
-3
@@ -1,10 +1,13 @@
|
||||
#include "optionswindow.h"
|
||||
|
||||
OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, QWidget *parent) : QWidget(parent)
|
||||
OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
setWindowTitle(tr("选项"));
|
||||
|
||||
vlayout = new QVBoxLayout(this);
|
||||
tabWidget = new QTabWidget(this);
|
||||
page1 = new QWidget(this);
|
||||
|
||||
vlayout = new QVBoxLayout(page1);
|
||||
layout = new QFormLayout();
|
||||
hlayout = new QHBoxLayout();
|
||||
|
||||
@@ -27,7 +30,10 @@ OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, QWidget *parent) :
|
||||
vlayout->addLayout(hlayout);
|
||||
vlayout->setSpacing(20);
|
||||
|
||||
setLayout(vlayout);
|
||||
page1->setLayout(vlayout);
|
||||
|
||||
tabWidget->addTab(page1, tr("常规"));
|
||||
setCentralWidget(tabWidget);
|
||||
|
||||
connect(saveButton, QPushButton::clicked, this, [this](){emit saveSettings(idEdit->text().toUtf8(), passwordEdit->text().toUtf8());});
|
||||
connect(cancleButton, QPushButton::clicked, this, hide);
|
||||
|
||||
+5
-1
@@ -1,20 +1,24 @@
|
||||
#ifndef OPTIONSWINDOW_H
|
||||
#define OPTIONSWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QWidget>
|
||||
#include <QTabWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QFormLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QSettings>
|
||||
|
||||
class OptionsWindow : public QWidget
|
||||
class OptionsWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OptionsWindow(QByteArray id, QByteArray pass, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QTabWidget *tabWidget;
|
||||
QWidget *page1;
|
||||
QLineEdit *idEdit, *passwordEdit;
|
||||
QPushButton *saveButton, *cancleButton;
|
||||
QFormLayout *layout;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icon">
|
||||
<file>favicon.ico</file>
|
||||
<file>offline.ico</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
Reference in new issue
Block a user