diff --git a/Build.Counter b/Build.Counter index bb5b9923..336df569 100644 --- a/Build.Counter +++ b/Build.Counter @@ -1 +1 @@ -1060 +1090 diff --git a/Qv2ray.pro b/Qv2ray.pro index 702d4521..e1f4e797 100644 --- a/Qv2ray.pro +++ b/Qv2ray.pro @@ -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") diff --git a/src/QvCoreConfigOperations.cpp b/src/QvCoreConfigOperations.cpp index 2f7d2c20..5f1beac4 100644 --- a/src/QvCoreConfigOperations.cpp +++ b/src/QvCoreConfigOperations.cpp @@ -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; } diff --git a/src/QvCoreConfigOperations.hpp b/src/QvCoreConfigOperations.hpp index c3682a35..4a837021 100644 --- a/src/QvCoreConfigOperations.hpp +++ b/src/QvCoreConfigOperations.hpp @@ -20,7 +20,7 @@ namespace Qv2ray QMap> GetSubscriptionConnections(list 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 -------------------------- diff --git a/src/QvCoreConfigOperations_Convertion.cpp b/src/QvCoreConfigOperations_Convertion.cpp index fa409afb..31be07d0 100644 --- a/src/QvCoreConfigOperations_Convertion.cpp +++ b/src/QvCoreConfigOperations_Convertion.cpp @@ -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 GetConnections(list connectionNames) - { - QMap 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; - } } } } diff --git a/src/ui/w_ImportConfig.cpp b/src/ui/w_ImportConfig.cpp index 64aff660..c7e843db 100644 --- a/src/ui/w_ImportConfig.cpp +++ b/src/ui/w_ImportConfig.cpp @@ -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 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); diff --git a/src/ui/w_MainWindow.cpp b/src/ui/w_MainWindow.cpp index 702ddec6..c7587f62 100644 --- a/src/ui/w_MainWindow.cpp +++ b/src/ui/w_MainWindow.cpp @@ -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); diff --git a/src/ui/w_MainWindow.hpp b/src/ui/w_MainWindow.hpp index a2e6b870..0c0d1b28 100644 --- a/src/ui/w_MainWindow.hpp +++ b/src/ui/w_MainWindow.hpp @@ -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 diff --git a/src/ui/w_MainWindow.ui b/src/ui/w_MainWindow.ui index 325e5f1e..c1dbfa6e 100644 --- a/src/ui/w_MainWindow.ui +++ b/src/ui/w_MainWindow.ui @@ -419,11 +419,24 @@ - + - + - Log + Log (click to switch log source) + + + + + + + + 300 + 0 + + + + Qt::LeftToRight @@ -441,13 +454,6 @@ QTextEdit::NoWrap - - <!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> - false @@ -460,19 +466,6 @@ p, li { white-space: pre-wrap; } - - - - - 300 - 0 - - - - Qt::LeftToRight - - - @@ -650,7 +643,6 @@ p, li { white-space: pre-wrap; } editJsonBtn pingTestBtn shareBtn - logText diff --git a/src/ui/w_RoutesEditor.cpp b/src/ui/w_RoutesEditor.cpp index 33ce6c8d..07f28b8b 100644 --- a/src/ui/w_RoutesEditor.cpp +++ b/src/ui/w_RoutesEditor.cpp @@ -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) {