Bug fix and add systemtray.

This commit is contained in:
Hork 2019-04-17 21:16:07 +08:00
parent 5e28486386
commit 1f9d763958
4 changed files with 47 additions and 8 deletions

BIN
Himeki.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

View File

@ -7,22 +7,23 @@
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QFileInfo>
void init()
{
if(!QDir(confDir).exists()) {
QDir().mkdir(confDir);
if(!QDir("conf").exists()) {
QDir().mkdir("conf");
qDebug() << "Conf directory created.";
}
QFileInfo confDb(QDir::currentPath() + confDatabase);
if (!confDb.exists()) {
QFileInfo confdb("conf/conf.db");
if (!confdb.exists()) {
QSqlDatabase database;
if (QSqlDatabase::contains("qt_sql_default_connection")) {
database = QSqlDatabase::database("qt_sql_default_connection");
} else {
database = QSqlDatabase::addDatabase("QSQLITE");
database.setDatabaseName(confDatabase);
database.setDatabaseName("conf/conf.db");
if(!database.open()) {
qDebug() << "Failed to open database while creating.";
}
@ -39,8 +40,8 @@ void init()
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
init();
MainWindow w;
w.show();
init();
return a.exec();
}

View File

@ -11,7 +11,7 @@
#include <QFile>
#include "db.h"
#include "vmess.h"
#include <QCloseEvent>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
@ -22,6 +22,11 @@ MainWindow::MainWindow(QWidget *parent) :
ui->configTable->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->configTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
this->v2Inst = new v2Instance();
hTray = new QSystemTrayIcon();
hTray->setToolTip("Hv2ray system tray");
hTray->setIcon(QIcon("Himeki.ico"));
hTray->show();
createTrayAction();
}
MainWindow::~MainWindow()
@ -159,3 +164,30 @@ void MainWindow::on_actionVmess_triggered()
vmess *inVmess = new vmess(this);
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;
}
}

View File

@ -4,6 +4,7 @@
#define confDatabase "conf/conf.db"
#include <QMainWindow>
#include "confedit.h"
#include <QSystemTrayIcon>
class v2Instance;
namespace Ui
@ -18,6 +19,8 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = nullptr);
ConfEdit *e;
v2Instance *v2Inst;
QSystemTrayIcon *hTray;
~MainWindow();
@ -36,10 +39,13 @@ private slots:
void on_rtButton_clicked();
void geneConf(int idIntable);
void on_actionVmess_triggered();
void on_activatedTray(QSystemTrayIcon::ActivationReason reason);
private:
Ui::MainWindow *ui;
v2Instance *v2Inst;
void closeEvent(QCloseEvent *);
void createTrayAction();
};
#endif // MAINWINDOW_H