Compare commits
36
Commits
v1.4-beta.2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6a0d974ed | ||
|
|
3ce65fbb8f | ||
|
|
74a05a61ef | ||
|
|
15295c7ffb | ||
|
|
5e071667b6 | ||
|
|
eabe237c75 | ||
|
|
9c1e1c90b7 | ||
|
|
8ee74ecbc0 | ||
|
|
07d93f3a93 | ||
|
|
2dec65b21c | ||
|
|
a547071d8c | ||
|
|
5edde21510 | ||
|
|
d4bed70503 | ||
|
|
77a7f07d24 | ||
|
|
c219a05a63 | ||
|
|
9a13f8e1f3 | ||
|
|
68c9641d56 | ||
|
|
81bdfeda27 | ||
|
|
c42be1b826 | ||
|
|
2bea6943f6 | ||
|
|
cb5b7fdba3 | ||
|
|
e226c7eeea | ||
|
|
555c40e8a4 | ||
|
|
3544e83608 | ||
|
|
3f5efce2fe | ||
|
|
ce4333f6d0 | ||
|
|
34ed28899d | ||
|
|
e50ea2ff48 | ||
|
|
629b3c803d | ||
|
|
cb572f4f10 | ||
|
|
14a1c568d0 | ||
|
|
2da62629a8 | ||
|
|
37bdaec248 | ||
|
|
cb7a142b88 | ||
|
|
08dbdae2a8 | ||
|
|
75fa1a8102 |
@@ -37,3 +37,5 @@ Makefile*
|
||||
# QtCtreator CMake
|
||||
CMakeLists.txt.user*
|
||||
|
||||
msvc_make.bat
|
||||
|
||||
|
||||
+2
-1
@@ -38,4 +38,5 @@ HEADERS += \
|
||||
RESOURCES += \
|
||||
resource.qrc
|
||||
|
||||
RC_ICONS = favicon.ico
|
||||
RC_ICONS = icons\favicon.ico
|
||||
|
||||
|
||||
@@ -1,17 +1,51 @@
|
||||
# NEU-Dectect
|
||||
# NEU-Monitor
|
||||
## 使用教程
|
||||
* 注:软件只有托盘中的图标以及单击显示的菜单,并没有主窗口
|
||||
1. 在设置中填好校园网账号和密码
|
||||
1. 在设置中填好校园网账号,密码以及流量(剩余流量过少时发出提醒,0为无限制)
|
||||
|
||||
2. 开始使用
|
||||
3. 双击托盘图标可以登录
|
||||
## 自动重连
|
||||
在已经登陆的状态下检测到校园网状态变为断开,此时会进行重新登陆,重新登陆等同于在ipgw网页点击`断开连接`后再进行`连接网络`
|
||||
## 网络状态检测
|
||||
|
||||
3. 双击或鼠标中键点击托盘图标可以登录或注销
|
||||
|
||||

|
||||
|
||||

|
||||
### 自动登陆
|
||||
1. 在已经登陆的状态下检测到校园网状态变为断开,此时会进行重新登陆,重新登陆等同于在网关页面点击`断开连接`后再进行`连接网络`
|
||||
2. 首次启动应用时进行登陆
|
||||
3. 手动点击断开网络后不会自动重新登陆
|
||||
|
||||
### 断开连接
|
||||
|
||||
* 当前在线:仅注销当前连接
|
||||
* 当前断开:断开全部连接
|
||||
|
||||
### 作为移动端登陆
|
||||
|
||||
开启此功能后将作为移动端登陆,由于校园网限制只能一个移动端和一个桌面端登陆,可用这一功能实现两台PC同时在线。
|
||||
|
||||
### 勿扰模式
|
||||
|
||||
该模式下不会发出系统通知
|
||||
|
||||
### 账户信息
|
||||
|
||||
信息只有在进行登陆时才会更新
|
||||
|
||||
单击`IP地址`可将IP复制到剪切板
|
||||
|
||||
### 网络状态检测
|
||||
|
||||
*为了检测网络状态,此工具会持续向查询信息接口发送请求*
|
||||
|
||||
网络状态分为
|
||||
* 未连接到校园网
|
||||
* 连接到校园网并已经登陆
|
||||
* 连接到校园网但未登陆
|
||||
|
||||
*为了检测网络状态,此工具会持续发送请求,~~可能由于请求频率过高,有很大概率会出现网关登陆被限制的情况(提示请5分钟之后再尝试)~~
|
||||
**请不要短时间内频繁的进行登陆,否则会出现登陆受限的情况**
|
||||
|
||||
*请不要短时间内频繁的进行登陆,会出现登陆受限的情况
|
||||
## 注意事项
|
||||
|
||||
1. 一旦网管登陆等接口出现变动,该软件会部分或全部失效
|
||||
2. 请不要短时间内频繁的进行登陆,否则会出现登陆受限的情况
|
||||
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
@@ -1,6 +1,8 @@
|
||||
#include "maintray.h"
|
||||
#include "maintray.h"
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -8,9 +10,12 @@ int main(int argc, char *argv[])
|
||||
a.setQuitOnLastWindowClosed(false);
|
||||
a.setApplicationName(QObject::tr("NEU-Monitor"));
|
||||
a.setWindowIcon(QIcon(QObject::tr(":/icon/favicon.ico")));
|
||||
a.setFont(QFont("Microsoft YaHei Light", 9));
|
||||
MainTray *tray = new MainTray("","");
|
||||
QObject::connect(tray, MainTray::exit, &a, QApplication::quit);
|
||||
// QFontDatabase::addApplicationFont(QString(":/resource/SourceHanSansCN-Regular.otf"));
|
||||
// QFont font("SourceHanSourceHanSansCN", 9);
|
||||
// a.setFont(font);
|
||||
// a.setFont(QFont("Microsoft YaHei", 9));
|
||||
MainTray *tray = new MainTray();
|
||||
QObject::connect(tray, &MainTray::exit, &a, &QApplication::quit);
|
||||
tray->show();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
+257
-122
@@ -1,138 +1,136 @@
|
||||
#include "maintray.h"
|
||||
#include "maintray.h"
|
||||
|
||||
MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): QSystemTrayIcon(parent),
|
||||
|
||||
MainTray::MainTray(QObject *parent) : QSystemTrayIcon(parent),
|
||||
//初始化menu
|
||||
menu(new QMenu()),
|
||||
infoMenu(new QMenu()),
|
||||
settingsMenu(new QMenu()),
|
||||
//初始化settings
|
||||
settings(QSettings::IniFormat, QSettings::UserScope, "Cai.MY", "NEU-Monitor"),
|
||||
//初始化optionswindow
|
||||
opWindow(settings.value("id", "").toByteArray(), settings.value("password", "").toByteArray(), settings.value("total traffic", 60).toInt()),
|
||||
user(username),
|
||||
passwd(password)
|
||||
user(settings.value("id", "").toByteArray()),
|
||||
passwd(QByteArray::fromBase64(settings.value("password", "").toByteArray())),
|
||||
totalTraffic(settings.value("total traffic", 0).toInt()),
|
||||
isMobile(settings.value("isMobile", false).toBool()),
|
||||
forceLogin(settings.value("forceLogin", false).toBool()),
|
||||
opWindow(user, passwd, totalTraffic)
|
||||
{
|
||||
opWindow.hide();
|
||||
setIcon(QIcon(tr(":/icon/favicon.ico")));
|
||||
|
||||
netctrl = new NetController(user,passwd,this);
|
||||
user = settings.value("id",0).toByteArray();
|
||||
passwd = settings.value("password", 0).toByteArray();
|
||||
totalTraffic = settings.value("total traffic", 60).toInt();
|
||||
opWindow.hide();
|
||||
setIcon(QIcon(olIconPath));
|
||||
|
||||
netctrl = new NetController(user, passwd, this); //passwd为解密后密码
|
||||
netctrl->setUsername(user);
|
||||
netctrl->setPassword(passwd);
|
||||
netctrl->setTotalTraffic(totalTraffic);
|
||||
netctrl->setMobile(isMobile);
|
||||
|
||||
connect(&opWindow, OptionsWindow::saveSettings, this, updateUserInfo);
|
||||
connect(&opWindow, &OptionsWindow::saveSettings, this, &MainTray::updateUserInfo);
|
||||
//连接controller状态改变信号
|
||||
connect(netctrl, NetController::stateChanged, this, [this](NetController::State state){
|
||||
switch (state) {
|
||||
case NetController::Online:
|
||||
isForceLogin = false;
|
||||
setIcon(QIcon(tr(":/icon/favicon.ico")));
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("网络已连接"),tr("校园网登陆成功"), this->icon(), msgDur);
|
||||
loginAction->setEnabled(true);
|
||||
logoutAction->setEnabled(true);
|
||||
break;
|
||||
case NetController::Offline:
|
||||
if(!isForceLogin){
|
||||
setIcon(QIcon(tr(":/icon/offline.ico")));
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("网络已断开"),tr("校园网已注销"), this->icon(), msgDur);
|
||||
loginAction->setEnabled(true);
|
||||
logoutAction->setEnabled(true);
|
||||
}
|
||||
break;
|
||||
case NetController::Disconnected:
|
||||
setIcon(QIcon(tr(":/icon/offline.ico")));
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("网络已断开"),tr("无法连接至校园网"), this->icon(), msgDur);
|
||||
loginAction->setDisabled(true);
|
||||
logoutAction->setDisabled(true);
|
||||
break;
|
||||
case NetController::WrongPass:
|
||||
setIcon(QIcon(tr(":/icon/offline.ico")));
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("登陆失败"),tr("密码错误"), this->icon(), msgDur);
|
||||
break;
|
||||
case NetController::Owed:
|
||||
setIcon(QIcon(tr(":/icon/offline.ico")));
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("登陆失败"),tr("已欠费"), this->icon(), msgDur);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
currentState = state;
|
||||
showToolTip(state);
|
||||
});
|
||||
connect(netctrl, &NetController::sendState, this, &MainTray::handleState);
|
||||
|
||||
|
||||
connect(this, QSystemTrayIcon::messageClicked, this, [this](){
|
||||
if(currentState == NetController::WrongPass)
|
||||
connect(this, &QSystemTrayIcon::messageClicked, this, [this]() {
|
||||
if (currentState == NetController::WrongPass)
|
||||
opWindow.show();
|
||||
});
|
||||
|
||||
connect(netctrl, NetController::sendInfo, this, handleInfo);
|
||||
connect(netctrl, &NetController::sendInfo, this, &MainTray::handleInfo);
|
||||
|
||||
//菜单Action
|
||||
loginAction = new QAction(tr("连接网络"),this);
|
||||
logoutAction = new QAction(tr("断开网络"),this);
|
||||
autoLogin = new QAction(tr("自动重连"), this);
|
||||
loginAction = new QAction(tr("连接网络"), this);
|
||||
logoutAction = new QAction(tr("断开网络"), this);
|
||||
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);
|
||||
|
||||
mbAction = new QAction(tr("已用流量: "),this);
|
||||
timeAction = new QAction(tr("已用时长: "),this);
|
||||
balanceAction = new QAction(tr("账户余额: "),this);
|
||||
ipAction = new QAction(tr("IP地址: "),this);
|
||||
mbAction = new QAction(tr("已用流量: "), this);
|
||||
timeAction = new QAction(tr("已用时长: "), this);
|
||||
balanceAction = new QAction(tr("账户余额: "), this);
|
||||
ipAction = new QAction(tr("IP地址: "), this);
|
||||
|
||||
mobileAction = new QAction(tr("移动端登陆"), this);
|
||||
mobileAction->setCheckable(true);
|
||||
mobileAction->setToolTip(tr("假装自己是个手机"));
|
||||
|
||||
forceLoginAction = new QAction(tr("强制登陆"), this);
|
||||
forceLoginAction->setCheckable(true);
|
||||
forceLoginAction->setToolTip(tr("先断开已有的所有连接再登陆"));
|
||||
|
||||
connect(ipAction, &QAction::triggered, this, [this]() {
|
||||
QStringList ipList = ipAction->text().split('\t');
|
||||
if (ipList.size() > 1)
|
||||
{
|
||||
QClipboard *clipBoard = QApplication::clipboard();
|
||||
clipBoard->setText(ipList.at(1));
|
||||
}
|
||||
if (!muteAction->isChecked())
|
||||
{
|
||||
showMessage(tr("复制成功"), tr("IP地址已复制到剪切板"));
|
||||
}
|
||||
});
|
||||
|
||||
autoLogin->setCheckable(true);
|
||||
bootAction->setCheckable(true);
|
||||
muteAction->setCheckable(true);
|
||||
|
||||
muteAction->setToolTip(tr("勿扰模式下不会发出通知"));
|
||||
|
||||
connect(loginAction, QAction::triggered, this,[this](){
|
||||
connect(loginAction, &QAction::triggered, this, [this]() {
|
||||
isForceLogin = true;
|
||||
netctrl->sendLogoutRequest();
|
||||
// netctrl->sendLogoutRequest(true);
|
||||
if (forceLogin) {
|
||||
logoutAction->trigger();
|
||||
}
|
||||
hasWarned = false;
|
||||
netctrl->sendLoginRequest();
|
||||
isForceLogout = false;
|
||||
});
|
||||
connect(logoutAction, QAction::triggered, this,[this](){
|
||||
netctrl->sendLogoutRequest();
|
||||
connect(logoutAction, &QAction::triggered, this, [this]() {
|
||||
netctrl->sendLogoutRequest(currentState != NetController::Online); //若不在线则断开全部链接
|
||||
isForceLogout = true;
|
||||
});
|
||||
connect(autoLogin, QAction::toggled, this, [this](bool set){
|
||||
connect(autoLogin, &QAction::toggled, this, [this](bool set) {
|
||||
settings.setValue("isAutoLogin", set);
|
||||
isForceLogout = false;
|
||||
showToolTip(currentState);
|
||||
});
|
||||
connect(muteAction, QAction::toggled, this, [this](bool set){
|
||||
connect(muteAction, &QAction::toggled, this, [this](bool set) {
|
||||
settings.setValue("isMute", set);
|
||||
});
|
||||
connect(bootAction, QAction::toggled, this, [this](bool set){
|
||||
connect(bootAction, &QAction::toggled, this, [this](bool set) {
|
||||
settings.setValue("isOnBoot", set);
|
||||
setAutoStart(set);
|
||||
});
|
||||
connect(optionsAction, QAction::triggered, this, [this](){showOptions();});
|
||||
connect(aboutAction, QAction::triggered, this, showAbout);
|
||||
connect(quitAction, QAction::triggered, this,[this](){emit exit();});
|
||||
connect(optionsAction, &QAction::triggered, this, [this]() { showOptions(); });
|
||||
connect(aboutAction, &QAction::triggered, this, &MainTray::showAbout);
|
||||
connect(quitAction, &QAction::triggered, this, [this]() {
|
||||
emit exit();
|
||||
});
|
||||
|
||||
connect(mobileAction, &QAction::triggered, this, [this](bool set) {
|
||||
settings.setValue("isMobile", set);
|
||||
isMobile = set;
|
||||
netctrl->setMobile(set);
|
||||
});
|
||||
|
||||
connect(forceLoginAction, &QAction::triggered, this, [this](bool set) {
|
||||
settings.setValue("forceLogin", set);
|
||||
forceLogin = set;
|
||||
});
|
||||
|
||||
autoLogin->setChecked(settings.value("isAutoLogin", true).toBool());
|
||||
bootAction->setChecked(settings.value("isOnBoot", false).toBool());
|
||||
muteAction->setChecked(settings.value("isMute", false).toBool());
|
||||
|
||||
mobileAction->setChecked(settings.value("isMobile", false).toBool());
|
||||
|
||||
settingsMenu->setTitle(tr("设置"));
|
||||
settingsMenu->addAction(optionsAction);
|
||||
settingsMenu->addAction(muteAction);
|
||||
settingsMenu->addAction(bootAction);
|
||||
settingsMenu->addAction(mobileAction);
|
||||
settingsMenu->addAction(forceLoginAction);
|
||||
|
||||
infoMenu->setTitle(tr("账户信息"));
|
||||
infoMenu->addAction(mbAction);
|
||||
@@ -150,22 +148,18 @@ MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): Q
|
||||
|
||||
setContextMenu(menu);
|
||||
|
||||
connect(this, activated, this, handleActivated);
|
||||
connect(this, exit, this, [this](){setVisible(false);});
|
||||
connect(this, &MainTray::activated, this, &MainTray::handleActivated);
|
||||
connect(this, &MainTray::exit, this, [this]() { setVisible(false); });
|
||||
|
||||
autoLoginTimer = new QTimer(this);
|
||||
autoLoginTimer->setInterval(checkInterval);
|
||||
autoLoginTimer->start();
|
||||
connect(autoLoginTimer,QTimer::timeout, this, [this](){
|
||||
connect(autoLoginTimer, &QTimer::timeout, this, [this]() {
|
||||
netctrl->checkState();
|
||||
//Offline状态下自动重连
|
||||
if(currentState == NetController::Offline && autoLogin->isChecked() && !isForceLogout){
|
||||
loginAction->trigger();
|
||||
}
|
||||
});
|
||||
|
||||
showToolTip(currentState);
|
||||
if(settings.value("id").isNull()||settings.value("password").isNull())
|
||||
if (settings.value("id").isNull() || settings.value("password").isNull())
|
||||
{
|
||||
opWindow.show();
|
||||
}
|
||||
@@ -175,17 +169,19 @@ MainTray::~MainTray()
|
||||
{
|
||||
delete menu;
|
||||
delete infoMenu;
|
||||
delete autoLoginTimer;
|
||||
}
|
||||
|
||||
void MainTray::showToolTip(NetController::State state)
|
||||
{
|
||||
QString tooltipString;
|
||||
switch (state) {
|
||||
switch (state)
|
||||
{
|
||||
case NetController::Online:
|
||||
tooltipString += tr("当前状态:连接");
|
||||
tooltipString += tr("当前状态:在线");
|
||||
break;
|
||||
case NetController::Offline:
|
||||
tooltipString += tr("当前状态:断开 (双击登陆)");
|
||||
tooltipString += tr("当前状态:断开");
|
||||
break;
|
||||
case NetController::Disconnected:
|
||||
tooltipString += tr("当前状态:无法连接");
|
||||
@@ -199,13 +195,14 @@ void MainTray::showToolTip(NetController::State state)
|
||||
case NetController::WrongPass:
|
||||
tooltipString += tr("当前状态:密码错误");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
tooltipString += tr("\n自动重连:");
|
||||
tooltipString += autoLogin->isChecked()? tr("开启"):tr("关闭");
|
||||
if(state == NetController::Online){
|
||||
switch (trafficstate) {
|
||||
tooltipString += tr("(") + (netctrl->getMobile() ? tr("Mobile") : tr("PC")) + tr(")");
|
||||
tooltipString += tr("\n自动登陆:");
|
||||
tooltipString += autoLogin->isChecked() ? tr("开启") : tr("关闭");
|
||||
if (state == NetController::Online)
|
||||
{
|
||||
switch (trafficstate)
|
||||
{
|
||||
case Over:
|
||||
tooltipString += tr("\n流量已超额");
|
||||
break;
|
||||
@@ -221,10 +218,18 @@ void MainTray::showToolTip(NetController::State state)
|
||||
|
||||
void MainTray::handleActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
switch (reason) {
|
||||
switch (reason)
|
||||
{
|
||||
case QSystemTrayIcon::DoubleClick:
|
||||
if(currentState == NetController::Offline)
|
||||
case QSystemTrayIcon::MiddleClick:
|
||||
if (currentState == NetController::Offline)
|
||||
{
|
||||
loginAction->trigger();
|
||||
}
|
||||
else if (currentState == NetController::Online)
|
||||
{
|
||||
logoutAction->trigger();
|
||||
}
|
||||
break;
|
||||
case QSystemTrayIcon::Trigger:
|
||||
contextMenu()->popup(this->geometry().topRight());
|
||||
@@ -244,19 +249,27 @@ void MainTray::showAbout()
|
||||
QMessageBox *aboutWindow = new QMessageBox();
|
||||
aboutWindow->setStandardButtons(QMessageBox::Ok);
|
||||
aboutWindow->setText(tr("<h1>NEU-Monitor</h1>"
|
||||
"<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\">Cai.MY</a>"
|
||||
"</address>"));
|
||||
"<h3>Version: 1.4.1</h3>"
|
||||
"<p>Based on Qt ")+getQtVersion() + tr("(") +
|
||||
getCompilerVersion() +
|
||||
tr(
|
||||
")</p>"
|
||||
"Configuration file path: <a href = \"") + settings.fileName() +
|
||||
tr("\">") + settings.fileName() + tr("</a><br/>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=Neu-Monitor-v1.4.1 Feedback\">Cai.MY</a>"
|
||||
"</address>"));
|
||||
aboutWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
aboutWindow->setModal(false);
|
||||
aboutWindow->show();
|
||||
}
|
||||
|
||||
void MainTray::setAutoStart(bool set)
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
QString application_name = QApplication::applicationName();
|
||||
QSettings *settings = new QSettings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
if(set)
|
||||
if (set)
|
||||
{
|
||||
QString application_path = QApplication::applicationFilePath();
|
||||
settings->setValue(application_name, application_path.replace("/", "\\"));
|
||||
@@ -266,50 +279,172 @@ void MainTray::setAutoStart(bool set)
|
||||
settings->remove(application_name);
|
||||
}
|
||||
delete settings;
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/autostart";
|
||||
QFile file(path + "/ipgw.desktop");
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
|
||||
{
|
||||
if (!muteAction->isChecked())
|
||||
{
|
||||
showMessage(tr("设置失败"), tr("读写/home/user/.config/autostart/失败"), this->icon(), msgDur);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (set)
|
||||
{
|
||||
QTextStream in(&file);
|
||||
in << "[Desktop Entry]\n"
|
||||
<< "Type=Application\n"
|
||||
<< "Version=1.0\n"
|
||||
<< "Name=NEU-Monitor\n"
|
||||
<< "Comment=NEU-Monitor startup script\n"
|
||||
<< "Exec=" << qApp->applicationFilePath() << " --hidden\n"
|
||||
<< "StartupNotify=false\n"
|
||||
<< "Terminal=false\n";
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
file.remove();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainTray::updateUserInfo(QByteArray id, QByteArray pass, int traffic)
|
||||
QString MainTray::getQtVersion()
|
||||
{
|
||||
return QString::number(QT_VERSION_MAJOR)+tr(".")+QString::number(QT_VERSION_MINOR)+tr(".")+QString::number(QT_VERSION_PATCH);
|
||||
}
|
||||
|
||||
QString MainTray::getCompilerVersion()
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
return tr("GCC ")QString::number(__GNUC__)+tr(".")+QString::number(__GNUC_MINOR__)+tr(".")+QString::number(__GNUC_PATCHLEVEL__);
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
return tr("MSVC ") + QString::number(_MSC_FULL_VER);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void MainTray::updateUserInfo(QByteArray id, QByteArray pass, int traffic) //pass为未加密的密码
|
||||
{
|
||||
logoutAction->trigger(); //注销当前via old info
|
||||
netctrl->setUsername(id);
|
||||
netctrl->setPassword(pass);
|
||||
netctrl->setTotalTraffic(traffic);
|
||||
netctrl->setMobile(isMobile);
|
||||
user = id;
|
||||
passwd = pass;
|
||||
totalTraffic = traffic;
|
||||
opWindow.hide();
|
||||
netctrl->sendLoginRequest();
|
||||
loginAction->trigger();
|
||||
hasWarned = false;
|
||||
settings.setValue("id", id);
|
||||
settings.setValue("password", pass);
|
||||
settings.setValue("password", pass.toBase64());
|
||||
settings.setValue("total traffic", traffic);
|
||||
}
|
||||
|
||||
void MainTray::handleState(NetController::State state)
|
||||
{
|
||||
if (state != currentState)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case NetController::Online:
|
||||
isForceLogin = false;
|
||||
setIcon(QIcon(olIconPath));
|
||||
if (!muteAction->isChecked())
|
||||
showMessage(tr("网络已连接"), tr("校园网登陆成功"), this->icon(), msgDur);
|
||||
currentState = state;
|
||||
break;
|
||||
case NetController::Offline:
|
||||
if (currentState == NetController::WrongPass || currentState == NetController::Owed)
|
||||
return;
|
||||
setIcon(QIcon(offIconPath));
|
||||
if (!muteAction->isChecked())
|
||||
showMessage(tr("网络已断开"), tr("校园网已注销"), this->icon(), msgDur);
|
||||
//自动登陆
|
||||
if (autoLogin->isChecked() && !isForceLogout)
|
||||
{
|
||||
QTimer::singleShot(1000, loginAction, SLOT(trigger()));
|
||||
// loginAction->trigger();
|
||||
}
|
||||
currentState = state;
|
||||
break;
|
||||
case NetController::Disconnected:
|
||||
setIcon(QIcon(offIconPath));
|
||||
if (!muteAction->isChecked())
|
||||
showMessage(tr("网络已断开"), tr("无法连接至校园网"), this->icon(), msgDur);
|
||||
currentState = state;
|
||||
break;
|
||||
case NetController::WrongPass:
|
||||
setIcon(QIcon(offIconPath));
|
||||
if (!muteAction->isChecked())
|
||||
showMessage(tr("登陆失败"), tr("密码错误"), this->icon(), msgDur);
|
||||
currentState = state;
|
||||
break;
|
||||
case NetController::Owed:
|
||||
setIcon(QIcon(offIconPath));
|
||||
if (!muteAction->isChecked())
|
||||
showMessage(tr("登陆失败"), tr("已欠费"), this->icon(), msgDur);
|
||||
currentState = state;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
showToolTip(state);
|
||||
}
|
||||
}
|
||||
|
||||
void MainTray::handleInfo(QString byte, QString sec, QString balance, QString ip)
|
||||
{
|
||||
QString mbString = QString::number(byte.toDouble()/1000000.0, 'f', 2);
|
||||
QString gbString = QString::number(byte.toDouble()/1000000000.0, 'f', 2);
|
||||
QString leftoverString = QString::number(totalTraffic - byte.toDouble()/1000000000.0, 'f',2 );
|
||||
int totalSec = sec.toInt();
|
||||
int hour = (totalSec/3600);
|
||||
int min = ((totalSec-hour*3600)/60);
|
||||
QString second = QString::number(totalSec-hour*3600-min*60);
|
||||
QString mbString = QString::number(byte.toDouble() / 1000000.0, 'f', 2);
|
||||
QString gbString = QString::number(byte.toDouble() / 1000000000.0, 'f', 2);
|
||||
QString leftoverString = QString::number(totalTraffic - byte.toDouble() / 1000000000.0, 'f', 2);
|
||||
double totalSec = sec.toDouble();
|
||||
double hour = (totalSec / 3600);
|
||||
int min = int((totalSec - hour * 3600) / 60);
|
||||
QString second = QString::number(totalSec - hour * 3600 - min * 60);
|
||||
mbAction->setText(tr("已用流量:\t") + mbString + tr(" M"));
|
||||
timeAction->setText(tr("已用时长:\t") + QString::number(hour) + ":" +QString::number(min) + ":" + second);
|
||||
balanceAction->setText(tr("账户余额:\t") + balance);
|
||||
timeAction->setText(tr("已用时长:\t") + QString::number(hour, 'f', 2) + tr(" 小时") /*+ ":" +QString::number(min) + ":" + second*/);
|
||||
balanceAction->setText(tr("账户余额:\t") + balance + tr(" 元"));
|
||||
ipAction->setText(tr("IP地址:\t") + ip);
|
||||
if(!hasWarned){
|
||||
if (!hasWarned && totalTraffic > 0)
|
||||
{
|
||||
hasWarned = true;
|
||||
if(byte.toDouble() / 1000000.0 > totalTraffic * 1024){//流量已超
|
||||
if (byte.toDouble() / 1000000.0 > totalTraffic * 1024)
|
||||
{ //流量已超
|
||||
trafficstate = Over;
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("流量警告"), tr("本月流量已超"), QSystemTrayIcon::Warning);
|
||||
if (!muteAction->isChecked())
|
||||
QTimer::singleShot(5000, this, [this] {
|
||||
showMessage(tr("流量警告"), tr("本月流量已超"), QSystemTrayIcon::Warning);
|
||||
});
|
||||
}
|
||||
else if(byte.toDouble() / 1000000.0 + 5000 > totalTraffic * 1024){//流量将超
|
||||
else if (byte.toDouble() / 1000000.0 + 5000 > totalTraffic * 1024)
|
||||
{ //流量将超
|
||||
trafficstate = Nearly;
|
||||
if(!muteAction->isChecked())
|
||||
showMessage(tr("流量预警"), tr("剩余流量:") + leftoverString + tr("G"));
|
||||
if (!muteAction->isChecked())
|
||||
QTimer::singleShot(5000, this, [this, leftoverString] {
|
||||
showMessage(tr("流量预警"), tr("剩余流量:") + leftoverString + tr("G"));
|
||||
});
|
||||
}
|
||||
showToolTip(currentState);
|
||||
}
|
||||
}
|
||||
|
||||
//void MainTray::writeLog(QString content, bool timeStamp)
|
||||
//{
|
||||
// if (!logFile.isOpen())
|
||||
// logFile.open(QIODevice::Append | QIODevice::Text);
|
||||
// if (timeStamp)
|
||||
// logFile.write(QDateTime::currentDateTime().toString("[yyyy.MM.dd hh:mm:ss] ").toUtf8());
|
||||
// logFile.write(content.toUtf8());
|
||||
// logFile.write(tr("\n").toUtf8());
|
||||
// // qDebug()<<"Write log"<<content;
|
||||
// logFile.close();
|
||||
//}
|
||||
|
||||
+55
-31
@@ -1,6 +1,10 @@
|
||||
#ifndef MAINTRAY_H
|
||||
#ifndef MAINTRAY_H
|
||||
#define MAINTRAY_H
|
||||
|
||||
#if _MSC_VER >= 1600
|
||||
#pragma execution_character_set("utf-8")
|
||||
#endif
|
||||
|
||||
#include <QObject>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QMenu>
|
||||
@@ -11,50 +15,70 @@
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QtGlobal>
|
||||
#include <QClipboard>
|
||||
#include <QStandardPaths>
|
||||
#include <QTextStream>
|
||||
#include <QDateTime>
|
||||
|
||||
class MainTray: public QSystemTrayIcon
|
||||
class MainTray : public QSystemTrayIcon
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainTray(QByteArray username, QByteArray password, QObject *parent = Q_NULLPTR);
|
||||
~MainTray();
|
||||
enum TrafficState{Normal, Over, Nearly };
|
||||
MainTray(QObject *parent = Q_NULLPTR);
|
||||
~MainTray();
|
||||
enum TrafficState
|
||||
{
|
||||
Normal,
|
||||
Over,
|
||||
Nearly
|
||||
};
|
||||
|
||||
private:
|
||||
QMenu *menu, *infoMenu, *settingsMenu;
|
||||
QAction *loginAction, *logoutAction, *autoLogin, *optionsAction, *aboutAction, *quitAction;
|
||||
QAction *mbAction, *timeAction, *balanceAction, *ipAction, *bootAction, *muteAction;
|
||||
NetController *netctrl;
|
||||
QSettings settings;
|
||||
OptionsWindow opWindow;
|
||||
QTimer *autoLoginTimer; //自动重连定时器
|
||||
QMenu *menu, *infoMenu, *settingsMenu;
|
||||
QAction *loginAction, *logoutAction, *autoLogin, *optionsAction, *aboutAction, *quitAction;
|
||||
QAction *mbAction, *timeAction, *balanceAction, *ipAction, *bootAction, *muteAction, *mobileAction;
|
||||
QAction *forceLoginAction;
|
||||
NetController *netctrl;
|
||||
QSettings settings;
|
||||
|
||||
bool isForceLogout = false;
|
||||
bool isForceLogin = false;
|
||||
bool hasWarned = false;
|
||||
QByteArray user, passwd;
|
||||
int totalTraffic;
|
||||
bool isMobile = false;
|
||||
bool forceLogin = false;
|
||||
|
||||
NetController::State currentState = NetController::Unknown; //当前状态
|
||||
TrafficState trafficstate = Normal;
|
||||
OptionsWindow opWindow;
|
||||
QTimer *autoLoginTimer; //自动重连定时器
|
||||
|
||||
void showToolTip(NetController::State state);
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason);//处理左键单击、双击
|
||||
void showOptions(); //显示选项窗口
|
||||
void showAbout(); //显示关于窗口
|
||||
void setAutoStart(bool set);
|
||||
QString olIconPath = tr(":/icons/favicon.ico");
|
||||
QString offIconPath = tr(":/icons/offline.ico");
|
||||
|
||||
QByteArray user, passwd;
|
||||
int totalTraffic;
|
||||
int msgDur = 500; //通知持续时间
|
||||
int checkInterval = 1000; //查询状态定时器周期
|
||||
bool isForceLogout = false;
|
||||
bool isForceLogin = false;
|
||||
bool hasWarned = false;
|
||||
|
||||
NetController::State currentState = NetController::Unknown; //当前状态
|
||||
TrafficState trafficstate = Normal;
|
||||
|
||||
void showToolTip(NetController::State state);
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason); //处理左键单击、双击
|
||||
void showOptions(); //显示选项窗口
|
||||
void showAbout(); //显示关于窗口
|
||||
void setAutoStart(bool set);
|
||||
|
||||
int msgDur = 500; //通知持续时间
|
||||
int checkInterval = 1000; //查询状态定时器周期
|
||||
|
||||
inline QString getQtVersion();
|
||||
inline QString getCompilerVersion();
|
||||
signals:
|
||||
void exit();
|
||||
void exit();
|
||||
|
||||
private slots:
|
||||
void updateUserInfo(QByteArray id, QByteArray pass, int traffic);
|
||||
void handleInfo(QString mb, QString sec, QString balance, QString ip);
|
||||
|
||||
void updateUserInfo(QByteArray id, QByteArray pass, int traffic);
|
||||
void handleState(NetController::State state);
|
||||
void handleInfo(QString mb, QString sec, QString balance, QString ip);
|
||||
};
|
||||
|
||||
#endif // MAINTRAY_H
|
||||
|
||||
+85
-84
@@ -1,66 +1,57 @@
|
||||
#include "netcontroller.h"
|
||||
#include "netcontroller.h"
|
||||
|
||||
NetController::NetController(QByteArray id, QByteArray passwd, QObject *parent) : QObject(parent),
|
||||
username(id), password(passwd), NEUState(Unknown), lastState(Unknown),
|
||||
manager(this)
|
||||
{
|
||||
username(id), password(passwd), manager(this)
|
||||
{
|
||||
checkParam.append("action=get_online_info");
|
||||
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
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");
|
||||
desktopRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
desktopRequest.setHeader(QNetworkRequest::ContentLengthHeader, "100");
|
||||
desktopRequest.setRawHeader("Host", "ipgw.neu.edu.cn");
|
||||
desktopRequest.setRawHeader("Cache-Control", "max-age=0");
|
||||
desktopRequest.setRawHeader("Origin", "http://ipgw.neu.edu.cn");
|
||||
desktopRequest.setRawHeader("Upgrade-Insecure-Requests", "1");
|
||||
#ifdef Q_OS_LINUX
|
||||
desktopRequest.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36");
|
||||
#endif
|
||||
|
||||
connect(&manager, QNetworkAccessManager::finished, this, handleResponse);
|
||||
#ifdef Q_OS_WIN32
|
||||
desktopRequest.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");
|
||||
#endif
|
||||
desktopRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
|
||||
desktopRequest.setRawHeader("Referer", "http://ipgw.neu.edu.cn/srun_portal_pc.php?ac_id=1&");
|
||||
desktopRequest.setRawHeader("Accept-Encoding", "gzip, deflate");
|
||||
desktopRequest.setRawHeader("Accept-Language", "zh-CN,zh;q=0.9");
|
||||
|
||||
mobileRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
|
||||
mobileRequest.setRawHeader("Accept-Encoding", "gzip, deflate");
|
||||
mobileRequest.setRawHeader("Accept-Language", "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7");
|
||||
mobileRequest.setRawHeader("Cache-Control", "max-age=0");
|
||||
// mobileRequest.setHeader(QNetworkRequest::ContentLengthHeader, "85"); //XXX:这行一定不能有
|
||||
mobileRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
mobileRequest.setRawHeader("Host", "ipgw.neu.edu.cn");
|
||||
mobileRequest.setRawHeader("Origin", "http://ipgw.neu.edu.cn");
|
||||
mobileRequest.setRawHeader("Proxy-Connection", "keep-alive");
|
||||
mobileRequest.setRawHeader("Referer", "http://ipgw.neu.edu.cn/srun_portal_phone.php?ac_id=1&");
|
||||
mobileRequest.setRawHeader("Upgrade-Insecure-Requests", "1");
|
||||
mobileRequest.setRawHeader("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Mobile Safari/537.36");
|
||||
|
||||
connect(&manager, &QNetworkAccessManager::finished, this, &NetController::handleResponse);
|
||||
}
|
||||
|
||||
void NetController::checkState()
|
||||
{
|
||||
sendCheckRequest();
|
||||
if(NEUState == Offline && lastState != Offline/* && offlineCount++ > 1*/)
|
||||
{
|
||||
lastState = Offline;
|
||||
emit stateChanged(NEUState);
|
||||
}
|
||||
else if(NEUState == Online && lastState != Online)
|
||||
{
|
||||
lastState = Online;
|
||||
emit stateChanged(NEUState);
|
||||
}
|
||||
else if(NEUState == Disconnected && lastState != Disconnected)
|
||||
{
|
||||
lastState = Disconnected;
|
||||
emit stateChanged(NEUState);
|
||||
}
|
||||
else if(NEUState == WrongPass && lastState != WrongPass)
|
||||
{
|
||||
lastState = WrongPass;
|
||||
emit stateChanged(NEUState);
|
||||
}
|
||||
else if(NEUState == Owed && lastState != Owed)
|
||||
{
|
||||
lastState = Owed;
|
||||
emit stateChanged(NEUState);
|
||||
}
|
||||
}
|
||||
|
||||
void NetController::sendCheckRequest()
|
||||
{
|
||||
request.setUrl(QUrl(checkUrl));
|
||||
manager.post(request, checkParam);
|
||||
desktopRequest.setUrl(QUrl(checkUrl));
|
||||
manager.post(desktopRequest, checkParam);
|
||||
}
|
||||
|
||||
void NetController::sendLoginRequest()
|
||||
{
|
||||
request.setUrl(QUrl(loginUrl));
|
||||
|
||||
QByteArray loginParam;
|
||||
loginParam.append("action=login&");
|
||||
loginParam.append("nas_ip=&");
|
||||
@@ -73,76 +64,86 @@ void NetController::sendLoginRequest()
|
||||
loginParam.append("username=");
|
||||
loginParam.append(username);
|
||||
|
||||
manager.post(request, loginParam);
|
||||
if (!isMobile)
|
||||
{
|
||||
desktopRequest.setUrl(QUrl(desktopLoginUrl));
|
||||
manager.post(desktopRequest, loginParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
mobileRequest.setUrl(QUrl(mobileLoginUrl));
|
||||
manager.post(mobileRequest, loginParam);
|
||||
}
|
||||
}
|
||||
|
||||
void NetController::sendLogoutRequest()
|
||||
void NetController::sendLogoutRequest(bool isAll)
|
||||
{
|
||||
request.setUrl(QUrl(loginUrl));
|
||||
|
||||
QByteArray logoutParam;
|
||||
logoutParam.append("action=logout&");
|
||||
logoutParam.append("ajax=1&");
|
||||
logoutParam.append("password=");
|
||||
logoutParam.append(password);
|
||||
logoutParam.append("&username=");
|
||||
if (isAll)
|
||||
{
|
||||
logoutParam.append("password="); //有password是全部断开
|
||||
logoutParam.append(password);
|
||||
logoutParam.append("&");
|
||||
}
|
||||
logoutParam.append("username=");
|
||||
logoutParam.append(username);
|
||||
|
||||
manager.post(request, logoutParam);
|
||||
if (!isMobile)
|
||||
{
|
||||
desktopRequest.setUrl(QUrl(desktopLoginUrl));
|
||||
manager.post(desktopRequest, logoutParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
mobileRequest.setUrl(QUrl(mobileLoginUrl));
|
||||
manager.post(mobileRequest, logoutParam);
|
||||
}
|
||||
}
|
||||
|
||||
void NetController::handleResponse(QNetworkReply *reply)
|
||||
{
|
||||
// qDebug()<<reply->url();
|
||||
QString url = reply->url().toString();
|
||||
reply->deleteLater();
|
||||
if(url==checkUrl)
|
||||
if (url == checkUrl)
|
||||
{
|
||||
if(reply->error()==QNetworkReply::NoError)
|
||||
if (reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
QString status = reply->readAll();
|
||||
if(status==offlineString)
|
||||
if (status == offlineString)
|
||||
{
|
||||
if(NEUState!=WrongPass && NEUState!=Owed && offlineCount++ > 1)
|
||||
{
|
||||
offlineCount = 0;
|
||||
disconnectCount = 0;
|
||||
lastState = NEUState;
|
||||
NEUState = Offline;
|
||||
}
|
||||
emit sendState(Offline);
|
||||
}
|
||||
else
|
||||
{
|
||||
offlineCount = 0;
|
||||
disconnectCount = 0;
|
||||
lastState = NEUState;
|
||||
NEUState = Online;
|
||||
emit sendState(Online);
|
||||
QStringList infoList = status.split(',');
|
||||
emit sendInfo(infoList[0], infoList[1], infoList[2], infoList[5]);
|
||||
}
|
||||
}
|
||||
else if(disconnectCount++ > 1)
|
||||
else
|
||||
{
|
||||
offlineCount = 0;
|
||||
disconnectCount = 0;
|
||||
lastState = NEUState;
|
||||
NEUState = Disconnected;
|
||||
emit sendState(Disconnected);
|
||||
}
|
||||
}
|
||||
else if(url==loginUrl)
|
||||
else if (url == desktopLoginUrl)
|
||||
{
|
||||
QString loginPage(reply->readAll());
|
||||
if(loginPage.contains(QString("已欠费"))){//欠费
|
||||
lastState = NEUState;
|
||||
NEUState = Owed;
|
||||
if (loginPage.contains(QString("已欠费")))
|
||||
{ //欠费
|
||||
emit sendState(Owed);
|
||||
}
|
||||
else if(loginPage.contains("Password is error")){//密码错误
|
||||
lastState = NEUState;
|
||||
NEUState = WrongPass;
|
||||
else if (loginPage.contains("Password is error"))
|
||||
{ //密码错误
|
||||
emit sendState(WrongPass);
|
||||
}
|
||||
else if(loginPage.contains("网络已连接")){//登陆成功
|
||||
lastState = NEUState;
|
||||
NEUState = Online;
|
||||
else if (loginPage.contains("网络已连接"))
|
||||
{ //登陆成功
|
||||
emit sendState(Online);
|
||||
}
|
||||
}
|
||||
// else if (url == mobileLoginUrl)
|
||||
// {
|
||||
// qDebug()<<reply->readAll().toStdString();
|
||||
// }
|
||||
}
|
||||
|
||||
+34
-23
@@ -1,4 +1,4 @@
|
||||
#ifndef NETCONTROLLER_H
|
||||
#ifndef NETCONTROLLER_H
|
||||
#define NETCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
@@ -9,38 +9,49 @@
|
||||
|
||||
class NetController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NetController(QByteArray username, QByteArray password, QObject *parent = nullptr);
|
||||
void checkState();
|
||||
void sendCheckRequest();
|
||||
void sendLoginRequest();
|
||||
void sendLogoutRequest();
|
||||
explicit NetController(QByteArray username, QByteArray password, QObject *parent = nullptr);
|
||||
void checkState();
|
||||
void sendCheckRequest();
|
||||
void sendLoginRequest();
|
||||
void sendLogoutRequest(bool isAll = false);
|
||||
|
||||
void setUsername(QByteArray newName) { username = newName; }
|
||||
void setPassword(QByteArray newPass) { password = newPass; }
|
||||
void setTotalTraffic(int newTraffic) { traffic = newTraffic; }
|
||||
inline void setUsername(QByteArray newName) { username = newName; }
|
||||
inline void setPassword(QByteArray newPass) { password = newPass; }
|
||||
inline void setTotalTraffic(int newTraffic) { traffic = newTraffic; }
|
||||
inline void setMobile(bool isMobile) { this->isMobile = isMobile; }
|
||||
inline bool getMobile() { return this->isMobile; }
|
||||
|
||||
enum State {Unknown, Offline, Online, Disconnected, Owed, WrongPass};
|
||||
enum State
|
||||
{
|
||||
Unknown,
|
||||
Offline,
|
||||
Online,
|
||||
Disconnected,
|
||||
Owed,
|
||||
WrongPass
|
||||
};
|
||||
|
||||
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;
|
||||
int traffic;
|
||||
State NEUState = Unknown, lastState = Unknown;
|
||||
int offlineCount = 0, disconnectCount = 0;
|
||||
QString checkUrl = "http://ipgw.neu.edu.cn/include/auth_action.php";
|
||||
QString desktopLoginUrl = "http://ipgw.neu.edu.cn/srun_portal_pc.php?ac_id=1&";
|
||||
QString mobileLoginUrl = "http://ipgw.neu.edu.cn/srun_portal_phone.php?ac_id=1&";
|
||||
QString offlineString = "not_online";
|
||||
QByteArray checkParam, username, password;
|
||||
int traffic;
|
||||
bool isMobile;
|
||||
int onlineCount = 0, offlineCount = 0, disconnectCount = 0;
|
||||
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkRequest request;
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkRequest desktopRequest, mobileRequest;
|
||||
|
||||
signals:
|
||||
void stateChanged(State newState);
|
||||
void sendInfo(QString mb, QString sec, QString balance, QString ip);
|
||||
void sendState(State newState);
|
||||
void sendInfo(QString mb, QString sec, QString balance, QString ip);
|
||||
|
||||
public slots:
|
||||
void handleResponse(QNetworkReply *reply);
|
||||
void handleResponse(QNetworkReply *reply);
|
||||
};
|
||||
|
||||
#endif // NETCONTROLLER_H
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
+34
-11
@@ -1,6 +1,6 @@
|
||||
#include "optionswindow.h"
|
||||
#include "optionswindow.h"
|
||||
|
||||
OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, int traffic, QWidget *parent) : QMainWindow(parent)
|
||||
OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, int traffic, QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
setWindowTitle(tr("选项"));
|
||||
|
||||
@@ -13,21 +13,43 @@ OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, int traffic, QWidg
|
||||
|
||||
idEdit = new QLineEdit(this);
|
||||
idEdit->setText(id);
|
||||
idEdit->setPlaceholderText(tr("学(工)号"));
|
||||
|
||||
passwordEdit = new QLineEdit(this);
|
||||
passwordEdit->setEchoMode(QLineEdit::Password);
|
||||
passwordEdit->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
passwordEdit->setText(pass);
|
||||
passwordEdit->setToolTip(tr("密码仅用于登陆"));
|
||||
passwordEdit->setPlaceholderText(tr("请输入密码"));
|
||||
|
||||
trafficSpin = new QSpinBox(this);
|
||||
trafficSpin->setValue(traffic);
|
||||
trafficSpin->setToolTip(tr("在流量将要用尽时进行提醒"));
|
||||
// mobileCheck = new QCheckBox(tr("作为移动端登陆"), this);
|
||||
// mobileCheck->setChecked(isMobile);
|
||||
// mobileCheck->setToolTip(tr("实现PC多终端在线"));
|
||||
|
||||
trafficBox = new QComboBox(this);
|
||||
trafficBox->setEditable(true);
|
||||
trafficBox->setValidator(new QIntValidator(0, INT_MAX));
|
||||
trafficBox->setToolTip(tr("0为无限制"));
|
||||
trafficBox->addItem(tr("5"));
|
||||
trafficBox->addItem(tr("25"));
|
||||
trafficBox->addItem(tr("60"));
|
||||
trafficBox->setCurrentText(QString::number(traffic));
|
||||
|
||||
|
||||
|
||||
trafficLabel = new QLabel(tr("流量(G)"), this);
|
||||
trafficLabel->setToolTip(tr("在流量将要用尽时进行提醒"));
|
||||
|
||||
layout->addRow(tr("用户名"), idEdit);
|
||||
layout->addRow(tr("密码"), passwordEdit);
|
||||
layout->addRow(tr("流量(G)"), trafficSpin);
|
||||
layout->addRow(trafficLabel, trafficBox);
|
||||
layout->setSpacing(20);
|
||||
|
||||
saveButton = new QPushButton("确定", this);
|
||||
saveButton->setDefault(true);
|
||||
saveButton->setToolTip(tr("保存设置并关闭"));
|
||||
cancleButton = new QPushButton("取消", this);
|
||||
cancleButton->setShortcut(Qt::Key_Escape);
|
||||
hlayout->addWidget(saveButton);
|
||||
hlayout->addWidget(cancleButton);
|
||||
|
||||
@@ -40,9 +62,10 @@ OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, int traffic, QWidg
|
||||
tabWidget->addTab(page1, tr("常规"));
|
||||
setCentralWidget(tabWidget);
|
||||
|
||||
connect(saveButton, QPushButton::clicked, this, [this](){emit saveSettings(idEdit->text().toUtf8(),
|
||||
passwordEdit->text().toUtf8(),
|
||||
trafficSpin->value());
|
||||
});
|
||||
connect(cancleButton, QPushButton::clicked, this, hide);
|
||||
connect(saveButton, &QPushButton::clicked, this, [this]() {
|
||||
emit saveSettings(idEdit->text().toUtf8(),
|
||||
passwordEdit->text().toUtf8(),
|
||||
trafficBox->currentText().toInt());
|
||||
});
|
||||
connect(cancleButton, &QPushButton::clicked, this, &OptionsWindow::hide);
|
||||
}
|
||||
|
||||
+22
-13
@@ -1,34 +1,43 @@
|
||||
#ifndef OPTIONSWINDOW_H
|
||||
#ifndef OPTIONSWINDOW_H
|
||||
#define OPTIONSWINDOW_H
|
||||
|
||||
#if _MSC_VER >= 1600
|
||||
#pragma execution_character_set("utf-8")
|
||||
#endif
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QWidget>
|
||||
#include <QTabWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
#include <QPushButton>
|
||||
#include <QFormLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QSettings>
|
||||
|
||||
class OptionsWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OptionsWindow(QByteArray id, QByteArray pass, int traffic, QWidget *parent = nullptr);
|
||||
explicit OptionsWindow(QByteArray id, QByteArray pass, int traffic, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QTabWidget *tabWidget;
|
||||
QWidget *page1;
|
||||
QLineEdit *idEdit, *passwordEdit;
|
||||
QSpinBox *trafficSpin;
|
||||
QPushButton *saveButton, *cancleButton;
|
||||
QFormLayout *layout;
|
||||
QVBoxLayout *vlayout;
|
||||
QHBoxLayout *hlayout;
|
||||
QTabWidget *tabWidget;
|
||||
QWidget *page1;
|
||||
QLineEdit *idEdit, *passwordEdit;
|
||||
QPushButton *saveButton, *cancleButton;
|
||||
QFormLayout *layout;
|
||||
QVBoxLayout *vlayout;
|
||||
QHBoxLayout *hlayout;
|
||||
QCheckBox *mobileCheck;
|
||||
QComboBox *trafficBox;
|
||||
|
||||
QLabel *trafficLabel;
|
||||
|
||||
signals:
|
||||
void saveSettings(QByteArray id, QByteArray pass, int traffic);
|
||||
void saveSettings(QByteArray id, QByteArray pass, int traffic);
|
||||
public slots:
|
||||
};
|
||||
|
||||
|
||||
+5
-3
@@ -1,6 +1,8 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icon">
|
||||
<file>favicon.ico</file>
|
||||
<file>offline.ico</file>
|
||||
<qresource prefix="/icon"/>
|
||||
<qresource prefix="/">
|
||||
<file>icons/favicon.ico</file>
|
||||
<file>icons/offline.ico</file>
|
||||
<file>resource/SourceHanSansCN-Regular.otf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user