Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e989257bbd | ||
|
|
8c186f245a | ||
|
|
0defc28d09 | ||
|
|
a17975671e | ||
|
|
fe6b02327d | ||
|
|
c99872a9c6 | ||
|
|
c84b5453db | ||
|
|
5eb2456909 | ||
|
|
2aac621284 |
No files matched your search
@@ -37,3 +37,5 @@ HEADERS += \
|
||||
|
||||
RESOURCES += \
|
||||
resource.qrc
|
||||
|
||||
RC_ICONS = favicon.ico
|
||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 48 KiB |
@@ -4,10 +4,11 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
a.setQuitOnLastWindowClosed(false);
|
||||
a.setApplicationName(QObject::tr("NEU-Monitor"));
|
||||
a.setWindowIcon(QIcon(QObject::tr(":/icon/favicon.ico")));
|
||||
MainTray *tray = new MainTray("","");
|
||||
QObject::connect(tray, MainTray::exit, &a, QApplication::quit);
|
||||
tray->show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
+116
-18
@@ -1,10 +1,11 @@
|
||||
#include "maintray.h"
|
||||
|
||||
MainTray::MainTray(QByteArray username, QByteArray password, QObject *parent): QSystemTrayIcon(parent),
|
||||
menu(new QMenu()), settings("TurnMeOn", "NEU-Dectect"),
|
||||
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)
|
||||
{
|
||||
|
||||
opWindow.hide();
|
||||
setIcon(QIcon(tr(":/icon/favicon.ico")));
|
||||
|
||||
@@ -13,55 +14,110 @@ 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);});
|
||||
connect(netctrl, NetController::getOffline, this, [this](bool isForce){
|
||||
showMessage(tr("网络已断开"),tr("校园网已注销"), this->icon(), msgDur);
|
||||
if(!isForce && isAutoLogin){
|
||||
qDebug()<<isAutoLogin;
|
||||
netctrl->sendLoginRequest();
|
||||
}
|
||||
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::getDisconnected, this, [this](){
|
||||
showMessage(tr("无法连接至校园网"),tr("校园网失去连接"), this->icon(), msgDur);});
|
||||
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);
|
||||
optionsAction = new QAction(tr("设置"), this);
|
||||
optionsAction = new QAction(tr("选项"), this);
|
||||
bootAction = new QAction(tr("开机启动"), this);
|
||||
aboutAction = new QAction(tr("关于"), this);
|
||||
quitAction = new QAction(tr("退出"), this);
|
||||
|
||||
autoLogin->setCheckable(true);
|
||||
mbAction = new QAction(tr("已用流量: "),this);
|
||||
timeAction = new QAction(tr("已用时长: "),this);
|
||||
balanceAction = new QAction(tr("账户余额: "),this);
|
||||
ipAction = new QAction(tr("IP地址: "),this);
|
||||
|
||||
connect(loginAction, QAction::triggered, this,[this](){netctrl->sendLoginRequest();});
|
||||
connect(logoutAction, QAction::triggered, this,[this](){netctrl->sendLogoutRequest();});
|
||||
autoLogin->setCheckable(true);
|
||||
bootAction->setCheckable(true);
|
||||
|
||||
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();
|
||||
settings.setValue("isAutoLogin", 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();});
|
||||
|
||||
autoLogin->setChecked(true);
|
||||
autoLogin->setChecked(settings.value("isAutoLogin", true).toBool());
|
||||
bootAction->setChecked(settings.value("isOnBoot", false).toBool());
|
||||
|
||||
settingsMenu->setTitle(tr("设置"));
|
||||
settingsMenu->addAction(optionsAction);
|
||||
settingsMenu->addAction(bootAction);
|
||||
|
||||
infoMenu->setTitle(tr("账户信息"));
|
||||
infoMenu->addAction(mbAction);
|
||||
infoMenu->addAction(timeAction);
|
||||
infoMenu->addAction(balanceAction);
|
||||
infoMenu->addAction(ipAction);
|
||||
|
||||
menu->addAction(loginAction);
|
||||
menu->addAction(logoutAction);
|
||||
menu->addAction(autoLogin);
|
||||
menu->addAction(optionsAction);
|
||||
menu->addMenu(infoMenu);
|
||||
menu->addMenu(settingsMenu);
|
||||
menu->addAction(aboutAction);
|
||||
menu->addAction(quitAction);
|
||||
|
||||
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) {
|
||||
case QSystemTrayIcon::Trigger:
|
||||
contextMenu()->show();
|
||||
contextMenu()->popup(this->geometry().topRight());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -73,6 +129,35 @@ void MainTray::showOptions()
|
||||
opWindow.show();
|
||||
}
|
||||
|
||||
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/>"
|
||||
"Email: <address>"
|
||||
"<a href=\"mailto:cmy1113@yeah.net?subject=SerialAsst Feedback\">TurnMeOn</a>"
|
||||
"</address>"));
|
||||
aboutWindow->show();
|
||||
}
|
||||
|
||||
void MainTray::setAutoStart(bool set)
|
||||
{
|
||||
QString application_name = QApplication::applicationName();
|
||||
QSettings *settings = new QSettings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
if(set)
|
||||
{
|
||||
QString application_path = QApplication::applicationFilePath();
|
||||
settings->setValue(application_name, application_path.replace("/", "\\"));
|
||||
}
|
||||
else
|
||||
{
|
||||
settings->remove(application_name);
|
||||
}
|
||||
delete settings;
|
||||
}
|
||||
|
||||
void MainTray::updataUserInfo(QByteArray id, QByteArray pass)
|
||||
{
|
||||
netctrl->setUsername(id);
|
||||
@@ -83,3 +168,16 @@ void MainTray::updataUserInfo(QByteArray id, QByteArray pass)
|
||||
settings.setValue("password", pass);
|
||||
}
|
||||
|
||||
void MainTray::handleInfo(QString mb, QString sec, QString balance, QString ip)
|
||||
{
|
||||
QString mbString = QString::number(mb.toDouble()/1000000.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);
|
||||
mbAction->setText(tr("已用流量:\t") + mbString + tr(" M"));
|
||||
timeAction->setText(tr("已用时长:\t") + QString::number(hour) + ":" +QString::number(min) + ":" + second);
|
||||
balanceAction->setText(tr("账户余额:\t") + balance);
|
||||
ipAction->setText(tr("IP地址:\t") + ip);
|
||||
}
|
||||
|
||||
+19
-6
@@ -8,32 +8,45 @@
|
||||
#include <netcontroller.h>
|
||||
#include <optionswindow.h>
|
||||
#include <QSettings>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QApplication>
|
||||
|
||||
class MainTray: public QSystemTrayIcon
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainTray(QByteArray username, QByteArray password, QObject *parent = Q_NULLPTR);
|
||||
~MainTray();
|
||||
enum Status {Unknown, Offline, Online, Disconnected};
|
||||
|
||||
private:
|
||||
QMenu *menu;
|
||||
QAction *loginAction, *logoutAction, *autoLogin, *optionsAction, *quitAction;
|
||||
QMenu *menu, *infoMenu, *settingsMenu;
|
||||
QAction *loginAction, *logoutAction, *autoLogin, *optionsAction, *aboutAction, *quitAction;
|
||||
QAction *mbAction, *timeAction, *balanceAction, *ipAction, *bootAction;
|
||||
NetController *netctrl;
|
||||
QSettings settings;
|
||||
OptionsWindow opWindow;
|
||||
QTimer *autoLoginTimer; //自动重连定时器
|
||||
|
||||
bool isAutoLogin = true;
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void showOptions();
|
||||
bool isForceLogout = false; //自动重连flag
|
||||
bool isAutoLogin = true; //手动注销flag
|
||||
Status currentState = Unknown; //当前状态
|
||||
void handleActivated(QSystemTrayIcon::ActivationReason reason);//处理左键单击
|
||||
void showOptions(); //显示选项窗口
|
||||
void showAbout(); //显示关于窗口
|
||||
void setAutoStart(bool set);
|
||||
|
||||
QByteArray user, passwd;
|
||||
int msgDur = 500;
|
||||
int msgDur = 1000; //通知持续时间
|
||||
|
||||
|
||||
signals:
|
||||
void exit();
|
||||
|
||||
private slots:
|
||||
void updataUserInfo(QByteArray id, QByteArray pass);
|
||||
void handleInfo(QString mb, QString sec, QString balance, QString ip);
|
||||
|
||||
};
|
||||
|
||||
|
||||
+5
-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;
|
||||
@@ -92,6 +91,8 @@ void NetController::handleResponse(QNetworkReply *reply)
|
||||
else
|
||||
{
|
||||
NEUStatus = Online;
|
||||
QStringList infoList = status.split(',');
|
||||
emit sendInfo(infoList[0], infoList[1], infoList[2], infoList[5]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
+2
-2
@@ -32,11 +32,11 @@ 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);
|
||||
|
||||
public slots:
|
||||
void handleResponse(QNetworkReply *reply);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
OptionsWindow::OptionsWindow(QByteArray id, QByteArray pass, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setWindowTitle(tr("选项"));
|
||||
|
||||
vlayout = new QVBoxLayout(this);
|
||||
layout = new QFormLayout();
|
||||
hlayout = new QHBoxLayout();
|
||||
|
||||
Reference in new issue
Block a user