mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 10:50:23 +08:00
Bug fix and add systemtray.
This commit is contained in:
parent
5e28486386
commit
1f9d763958
BIN
Himeki.ico
Executable file
BIN
Himeki.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 264 KiB |
13
src/main.cpp
13
src/main.cpp
@ -7,22 +7,23 @@
|
|||||||
#include <QSqlDatabase>
|
#include <QSqlDatabase>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
if(!QDir(confDir).exists()) {
|
if(!QDir("conf").exists()) {
|
||||||
QDir().mkdir(confDir);
|
QDir().mkdir("conf");
|
||||||
qDebug() << "Conf directory created.";
|
qDebug() << "Conf directory created.";
|
||||||
}
|
}
|
||||||
QFileInfo confDb(QDir::currentPath() + confDatabase);
|
QFileInfo confdb("conf/conf.db");
|
||||||
if (!confDb.exists()) {
|
if (!confdb.exists()) {
|
||||||
QSqlDatabase database;
|
QSqlDatabase database;
|
||||||
if (QSqlDatabase::contains("qt_sql_default_connection")) {
|
if (QSqlDatabase::contains("qt_sql_default_connection")) {
|
||||||
database = QSqlDatabase::database("qt_sql_default_connection");
|
database = QSqlDatabase::database("qt_sql_default_connection");
|
||||||
} else {
|
} else {
|
||||||
database = QSqlDatabase::addDatabase("QSQLITE");
|
database = QSqlDatabase::addDatabase("QSQLITE");
|
||||||
database.setDatabaseName(confDatabase);
|
database.setDatabaseName("conf/conf.db");
|
||||||
if(!database.open()) {
|
if(!database.open()) {
|
||||||
qDebug() << "Failed to open database while creating.";
|
qDebug() << "Failed to open database while creating.";
|
||||||
}
|
}
|
||||||
@ -39,8 +40,8 @@ void init()
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
init();
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
init();
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "vmess.h"
|
#include "vmess.h"
|
||||||
|
#include <QCloseEvent>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
@ -22,6 +22,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->configTable->setContextMenuPolicy(Qt::CustomContextMenu);
|
ui->configTable->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(ui->configTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
|
connect(ui->configTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
|
||||||
this->v2Inst = new v2Instance();
|
this->v2Inst = new v2Instance();
|
||||||
|
hTray = new QSystemTrayIcon();
|
||||||
|
hTray->setToolTip("Hv2ray system tray");
|
||||||
|
hTray->setIcon(QIcon("Himeki.ico"));
|
||||||
|
hTray->show();
|
||||||
|
createTrayAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -159,3 +164,30 @@ void MainWindow::on_actionVmess_triggered()
|
|||||||
vmess *inVmess = new vmess(this);
|
vmess *inVmess = new vmess(this);
|
||||||
inVmess->show();
|
inVmess->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
this->hide();
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createTrayAction()
|
||||||
|
{
|
||||||
|
QAction actionShow(this);
|
||||||
|
QAction actionQuit(this);
|
||||||
|
QAction actionStart(this);
|
||||||
|
QAction actionRestart(this);
|
||||||
|
QObject::connect(hTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(on_activatedTray(QSystemTrayIcon::ActivationReason)));
|
||||||
|
}
|
||||||
|
void MainWindow::on_activatedTray(QSystemTrayIcon::ActivationReason reason)
|
||||||
|
{
|
||||||
|
switch (reason) {
|
||||||
|
case QSystemTrayIcon::Trigger:
|
||||||
|
this->show();
|
||||||
|
break;
|
||||||
|
case QSystemTrayIcon::DoubleClick:
|
||||||
|
this->show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#define confDatabase "conf/conf.db"
|
#define confDatabase "conf/conf.db"
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include "confedit.h"
|
#include "confedit.h"
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
class v2Instance;
|
class v2Instance;
|
||||||
namespace Ui
|
namespace Ui
|
||||||
@ -18,6 +19,8 @@ class MainWindow : public QMainWindow
|
|||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
ConfEdit *e;
|
ConfEdit *e;
|
||||||
|
v2Instance *v2Inst;
|
||||||
|
QSystemTrayIcon *hTray;
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
|
||||||
@ -36,10 +39,13 @@ private slots:
|
|||||||
void on_rtButton_clicked();
|
void on_rtButton_clicked();
|
||||||
void geneConf(int idIntable);
|
void geneConf(int idIntable);
|
||||||
void on_actionVmess_triggered();
|
void on_actionVmess_triggered();
|
||||||
|
void on_activatedTray(QSystemTrayIcon::ActivationReason reason);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
v2Instance *v2Inst;
|
void closeEvent(QCloseEvent *);
|
||||||
|
void createTrayAction();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user