mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 02:40:20 +08:00
[add] Some small updates and fixed #144
This commit is contained in:
parent
ec49dffbb5
commit
d0e79f2819
@ -1 +1 @@
|
||||
1060
|
||||
1090
|
||||
|
@ -225,5 +225,6 @@ unix {
|
||||
INSTALLS += target desktop icon
|
||||
}
|
||||
|
||||
message(" ")
|
||||
message("Done configuring Qv2ray project. Build output will be at:" $$OUT_PWD)
|
||||
message("Type `make` or `mingw32-make` to start building Qv2ray")
|
||||
|
@ -70,12 +70,13 @@ namespace Qv2ray
|
||||
StringToFile(&json, new QFile(QV2RAY_GENERATED_FILE_PATH));
|
||||
return 0;
|
||||
}
|
||||
int FindIndexByTag(INOUTLIST list, QString *tag)
|
||||
|
||||
int FindIndexByTag(INOUTLIST list, const QString &tag)
|
||||
{
|
||||
for (int i = 0; i < list.count(); i++) {
|
||||
auto value = list[i].toObject();
|
||||
|
||||
if (value.contains("tag") && value["tag"].toString() == *tag)
|
||||
if (value.contains("tag") && value["tag"].toString() == tag)
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace Qv2ray
|
||||
QMap<QString, QMap<QString, CONFIGROOT>> GetSubscriptionConnections(list<string> subscriptions);
|
||||
bool CheckIsComplexConfig(CONFIGROOT root);
|
||||
int StartPreparation(CONFIGROOT fullConfig);
|
||||
int FindIndexByTag(INOUTLIST list, QString *tag);
|
||||
int FindIndexByTag(INOUTLIST list, const QString &tag);
|
||||
|
||||
//
|
||||
// -------------------------- BEGIN CONFIG CONVERSIONS --------------------------
|
||||
|
@ -229,11 +229,10 @@ namespace Qv2ray
|
||||
// WARN Mux is missing here.
|
||||
auto outbound = GenerateOutboundEntry("vmess", vConf, GetRootObject(streaming), QJsonObject(), "0.0.0.0", OUTBOUND_TAG_PROXY);
|
||||
//
|
||||
QJsonArray outbounds;
|
||||
outbounds.append(outbound);
|
||||
root["outbounds"] = outbounds;
|
||||
*alias = *alias + "_" + QSTRING(ps);
|
||||
RROOT
|
||||
root["outbounds"] = QJsonArray() << outbound;
|
||||
// If previous alias is empty, just the PS is needed, else, append a "_"
|
||||
*alias = alias->isEmpty() ? QSTRING(ps) : *alias + "_" + QSTRING(ps);
|
||||
return root;
|
||||
}
|
||||
|
||||
CONFIGROOT ConvertConfigFromFile(QString sourceFilePath, bool keepInbounds)
|
||||
@ -258,44 +257,11 @@ namespace Qv2ray
|
||||
return root;
|
||||
}
|
||||
|
||||
QMap<QString, CONFIGROOT> GetConnections(list<string> connectionNames)
|
||||
{
|
||||
QMap<QString, CONFIGROOT> list;
|
||||
|
||||
for (auto conn : connectionNames) {
|
||||
QString jsonString = StringFromFile(new QFile(QV2RAY_CONFIG_DIR + QSTRING(conn) + QV2RAY_CONFIG_FILE_EXTENSION));
|
||||
QJsonObject connectionObject = JsonFromString(jsonString);
|
||||
list.insert(QString::fromStdString(conn), CONFIGROOT(connectionObject));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
bool RenameConnection(QString originalName, QString newName)
|
||||
{
|
||||
LOG(MODULE_FILE, "[RENAME] --> ORIGINAL: " + originalName.toStdString() + ", NEW: " + newName.toStdString())
|
||||
return QFile::rename(QV2RAY_CONFIG_DIR + originalName + QV2RAY_CONFIG_FILE_EXTENSION, QV2RAY_CONFIG_DIR + newName + QV2RAY_CONFIG_FILE_EXTENSION);
|
||||
}
|
||||
|
||||
int StartPreparation(CONFIGROOT fullConfig)
|
||||
{
|
||||
// Writes the final configuration to the disk.
|
||||
QString json = JsonToString(fullConfig);
|
||||
StringToFile(&json, new QFile(QV2RAY_GENERATED_FILE_PATH));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FindIndexByTag(QJsonArray list, QString *tag)
|
||||
{
|
||||
for (int i = 0; i < list.count(); i++) {
|
||||
auto value = list[i].toObject();
|
||||
|
||||
if (value.contains("tag") && value["tag"].toString() == *tag)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ ImportConfigWindow::ImportConfigWindow(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
nameTxt->setText(QDateTime::currentDateTime().toString("MM-dd_hh-mm") + "_" + tr("Imported") + "_");
|
||||
nameTxt->setText(QDateTime::currentDateTime().toString("MMdd_hhmm"));
|
||||
}
|
||||
|
||||
QMap<QString, CONFIGROOT> ImportConfigWindow::OpenImport(bool outboundsOnly)
|
||||
@ -60,7 +60,6 @@ void ImportConfigWindow::on_qrFromScreenBtn_clicked()
|
||||
void ImportConfigWindow::on_beginImportBtn_clicked()
|
||||
{
|
||||
QString aliasPrefix = nameTxt->text();
|
||||
CONFIGROOT config;
|
||||
//auto conf = GetGlobalConfig();
|
||||
|
||||
switch (tabWidget->currentIndex()) {
|
||||
@ -68,19 +67,16 @@ void ImportConfigWindow::on_beginImportBtn_clicked()
|
||||
// From File...
|
||||
bool keepInBound = keepImportedInboundCheckBox->isChecked();
|
||||
QString path = fileLineTxt->text();
|
||||
aliasPrefix = aliasPrefix.isEmpty() ? aliasPrefix : QFileInfo(path).fileName();
|
||||
config = ConvertConfigFromFile(path, keepInBound);
|
||||
|
||||
if (config.isEmpty()) {
|
||||
QvMessageBox(this, tr("Import config file"), tr("Import from file failed, for more information, please check the log file."));
|
||||
return;
|
||||
} else if (!ConnectionInstance::ValidateConfig(path)) {
|
||||
if (!ConnectionInstance::ValidateConfig(path)) {
|
||||
QvMessageBox(this, tr("Import config file"), tr("Failed to check the validity of the config file."));
|
||||
return;
|
||||
} else {
|
||||
connections[aliasPrefix] = config;
|
||||
break;
|
||||
}
|
||||
|
||||
aliasPrefix += "_" + QFileInfo(path).fileName();
|
||||
CONFIGROOT config = ConvertConfigFromFile(path, keepInBound);
|
||||
connections[aliasPrefix] = config;
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: {
|
||||
@ -91,13 +87,13 @@ void ImportConfigWindow::on_beginImportBtn_clicked()
|
||||
vmessConnectionStringTxt->clear();
|
||||
errorsList->clear();
|
||||
//
|
||||
LOG(MODULE_IMPORT, to_string(vmessList.count()) + " string found.")
|
||||
LOG(MODULE_IMPORT, to_string(vmessList.count()) + " string found in vmess box.")
|
||||
|
||||
while (!vmessList.isEmpty()) {
|
||||
aliasPrefix = nameTxt->text();
|
||||
auto vmess = vmessList.takeFirst();
|
||||
QString errMessage;
|
||||
config = ConvertConfigFromVMessString(vmess, &aliasPrefix, &errMessage);
|
||||
CONFIGROOT config = ConvertConfigFromVMessString(vmess, &aliasPrefix, &errMessage);
|
||||
|
||||
// If the config is empty or we have any err messages.
|
||||
if (config.isEmpty() || !errMessage.isEmpty()) {
|
||||
@ -110,7 +106,6 @@ void ImportConfigWindow::on_beginImportBtn_clicked()
|
||||
}
|
||||
|
||||
if (!vmessErrors.isEmpty()) {
|
||||
// TODO Show in UI
|
||||
for (auto item : vmessErrors) {
|
||||
vmessConnectionStringTxt->appendPlainText(vmessErrors.key(item));
|
||||
errorsList->addItem(item);
|
||||
|
@ -50,7 +50,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
vinstance = new ConnectionInstance(this);
|
||||
setupUi(this);
|
||||
//
|
||||
highlighter = new Highlighter(conf.uiConfig.useDarkTheme, logText->document());
|
||||
highlighter = new Highlighter(conf.uiConfig.useDarkTheme, vcoreLog.document());
|
||||
logText->setDocument(vcoreLog.document());
|
||||
logText->setFontPointSize(8);
|
||||
vcoreLog.setFontPointSize(8);
|
||||
qvAppLog.setFontPointSize(8);
|
||||
//
|
||||
pacServer = new PACHandler();
|
||||
//
|
||||
this->setWindowIcon(QIcon(":/icons/qv2ray.png"));
|
||||
@ -140,7 +145,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
speedChartObj = new QChart();
|
||||
speedChartObj->setTheme(conf.uiConfig.useDarkTheme ? QChart::ChartThemeDark : QChart::ChartThemeLight);
|
||||
speedChartObj->setTitle("Qv2ray Speed Chart");
|
||||
speedChartObj->setTitle(""); // Fake hidden
|
||||
speedChartObj->legend()->hide();
|
||||
speedChartObj->createDefaultAxes();
|
||||
speedChartObj->addSeries(uploadSerie);
|
||||
@ -185,6 +190,14 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
StartProcessingPlugins(this);
|
||||
}
|
||||
|
||||
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
|
||||
if (logLabel->underMouse()) {
|
||||
logText->setDocument(logSourceId++ % 2 == 0 ? vcoreLog.document() : qvAppLog.document());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
@ -319,7 +332,7 @@ MainWindow::~MainWindow()
|
||||
}
|
||||
void MainWindow::UpdateLog()
|
||||
{
|
||||
logText->append(vinstance->ReadProcessOutput().trimmed());
|
||||
vcoreLog.append(vinstance->ReadProcessOutput().trimmed());
|
||||
}
|
||||
void MainWindow::on_startButton_clicked()
|
||||
{
|
||||
@ -461,7 +474,7 @@ void MainWindow::on_stopButton_clicked()
|
||||
hTray->setToolTip(TRAY_TOOLTIP_PREFIX);
|
||||
QFile(QV2RAY_GENERATED_FILE_PATH).remove();
|
||||
statusLabel->setText(tr("Disconnected"));
|
||||
logText->setText("");
|
||||
logText->setPlainText("");
|
||||
trayMenu->actions()[2]->setEnabled(true);
|
||||
trayMenu->actions()[3]->setEnabled(false);
|
||||
trayMenu->actions()[4]->setEnabled(false);
|
||||
|
@ -86,6 +86,7 @@ class MainWindow : public QMainWindow, Ui::MainWindow
|
||||
|
||||
protected:
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
void closeEvent(QCloseEvent *) override;
|
||||
@ -120,6 +121,10 @@ class MainWindow : public QMainWindow, Ui::MainWindow
|
||||
//
|
||||
PACHandler *pacServer;
|
||||
Highlighter *highlighter;
|
||||
//
|
||||
QTextEdit vcoreLog;
|
||||
QTextEdit qvAppLog;
|
||||
int logSourceId = 0;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -419,11 +419,24 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="5,2">
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="5,0">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<widget class="QLabel" name="logLabel">
|
||||
<property name="text">
|
||||
<string>Log</string>
|
||||
<string>Log (click to switch log source)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QWidget" name="speedChart" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -441,13 +454,6 @@
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Noto Sans'; font-size:8pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Noto Sans';"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="openLinks">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
@ -460,19 +466,6 @@ p, li { white-space: pre-wrap; }
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QWidget" name="speedChart" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
@ -650,7 +643,6 @@ p, li { white-space: pre-wrap; }
|
||||
<tabstop>editJsonBtn</tabstop>
|
||||
<tabstop>pingTestBtn</tabstop>
|
||||
<tabstop>shareBtn</tabstop>
|
||||
<tabstop>logText</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -230,8 +230,7 @@ void RouteEditor::ShowRuleDetail(RuleObject rule)
|
||||
|
||||
if (!QSTRING(rule.outboundTag).isEmpty()) {
|
||||
// Find outbound index by tag.
|
||||
auto tag = QSTRING(rule.outboundTag);
|
||||
auto index = FindIndexByTag(outbounds, &tag);
|
||||
auto index = FindIndexByTag(outbounds, QSTRING(rule.outboundTag));
|
||||
routeOutboundSelector->setCurrentIndex(index);
|
||||
//
|
||||
// Default balancer tag.
|
||||
@ -253,8 +252,7 @@ void RouteEditor::ShowRuleDetail(RuleObject rule)
|
||||
isLoading = false;
|
||||
on_inboundsList_itemChanged(nullptr);
|
||||
//
|
||||
auto outboundTag = QSTRING(rule.outboundTag);
|
||||
int index = FindIndexByTag(outbounds, &outboundTag);
|
||||
int index = FindIndexByTag(outbounds, QSTRING(rule.outboundTag));
|
||||
outboundsList->setCurrentRow(index);
|
||||
//
|
||||
// Networks
|
||||
@ -306,7 +304,7 @@ void RouteEditor::ShowRuleDetail(RuleObject rule)
|
||||
|
||||
if (!inTag.isEmpty()) {
|
||||
// forget about the "" issue.
|
||||
int _index = FindIndexByTag(inbounds, &inTag);
|
||||
int _index = FindIndexByTag(inbounds, inTag);
|
||||
|
||||
// FIXED if an inbound is missing (index out of range)
|
||||
if (_index >= 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user