[add] Some small updates and fixed #144

This commit is contained in:
Leroy.H.Y 2019-12-01 13:43:11 +08:00
parent ec49dffbb5
commit d0e79f2819
No known key found for this signature in database
GPG Key ID: 6AC1673B587DC37D
10 changed files with 60 additions and 89 deletions

View File

@ -1 +1 @@
1060 1090

View File

@ -225,5 +225,6 @@ unix {
INSTALLS += target desktop icon INSTALLS += target desktop icon
} }
message(" ")
message("Done configuring Qv2ray project. Build output will be at:" $$OUT_PWD) message("Done configuring Qv2ray project. Build output will be at:" $$OUT_PWD)
message("Type `make` or `mingw32-make` to start building Qv2ray") message("Type `make` or `mingw32-make` to start building Qv2ray")

View File

@ -70,12 +70,13 @@ namespace Qv2ray
StringToFile(&json, new QFile(QV2RAY_GENERATED_FILE_PATH)); StringToFile(&json, new QFile(QV2RAY_GENERATED_FILE_PATH));
return 0; return 0;
} }
int FindIndexByTag(INOUTLIST list, QString *tag)
int FindIndexByTag(INOUTLIST list, const QString &tag)
{ {
for (int i = 0; i < list.count(); i++) { for (int i = 0; i < list.count(); i++) {
auto value = list[i].toObject(); auto value = list[i].toObject();
if (value.contains("tag") && value["tag"].toString() == *tag) if (value.contains("tag") && value["tag"].toString() == tag)
return i; return i;
} }

View File

@ -20,7 +20,7 @@ namespace Qv2ray
QMap<QString, QMap<QString, CONFIGROOT>> GetSubscriptionConnections(list<string> subscriptions); QMap<QString, QMap<QString, CONFIGROOT>> GetSubscriptionConnections(list<string> subscriptions);
bool CheckIsComplexConfig(CONFIGROOT root); bool CheckIsComplexConfig(CONFIGROOT root);
int StartPreparation(CONFIGROOT fullConfig); int StartPreparation(CONFIGROOT fullConfig);
int FindIndexByTag(INOUTLIST list, QString *tag); int FindIndexByTag(INOUTLIST list, const QString &tag);
// //
// -------------------------- BEGIN CONFIG CONVERSIONS -------------------------- // -------------------------- BEGIN CONFIG CONVERSIONS --------------------------

View File

@ -229,11 +229,10 @@ namespace Qv2ray
// WARN Mux is missing here. // WARN Mux is missing here.
auto outbound = GenerateOutboundEntry("vmess", vConf, GetRootObject(streaming), QJsonObject(), "0.0.0.0", OUTBOUND_TAG_PROXY); auto outbound = GenerateOutboundEntry("vmess", vConf, GetRootObject(streaming), QJsonObject(), "0.0.0.0", OUTBOUND_TAG_PROXY);
// //
QJsonArray outbounds; root["outbounds"] = QJsonArray() << outbound;
outbounds.append(outbound); // If previous alias is empty, just the PS is needed, else, append a "_"
root["outbounds"] = outbounds; *alias = alias->isEmpty() ? QSTRING(ps) : *alias + "_" + QSTRING(ps);
*alias = *alias + "_" + QSTRING(ps); return root;
RROOT
} }
CONFIGROOT ConvertConfigFromFile(QString sourceFilePath, bool keepInbounds) CONFIGROOT ConvertConfigFromFile(QString sourceFilePath, bool keepInbounds)
@ -258,44 +257,11 @@ namespace Qv2ray
return root; 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) bool RenameConnection(QString originalName, QString newName)
{ {
LOG(MODULE_FILE, "[RENAME] --> ORIGINAL: " + originalName.toStdString() + ", NEW: " + newName.toStdString()) 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); 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;
}
} }
} }
} }

View File

@ -21,7 +21,7 @@ ImportConfigWindow::ImportConfigWindow(QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
setupUi(this); 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) QMap<QString, CONFIGROOT> ImportConfigWindow::OpenImport(bool outboundsOnly)
@ -60,7 +60,6 @@ void ImportConfigWindow::on_qrFromScreenBtn_clicked()
void ImportConfigWindow::on_beginImportBtn_clicked() void ImportConfigWindow::on_beginImportBtn_clicked()
{ {
QString aliasPrefix = nameTxt->text(); QString aliasPrefix = nameTxt->text();
CONFIGROOT config;
//auto conf = GetGlobalConfig(); //auto conf = GetGlobalConfig();
switch (tabWidget->currentIndex()) { switch (tabWidget->currentIndex()) {
@ -68,20 +67,17 @@ void ImportConfigWindow::on_beginImportBtn_clicked()
// From File... // From File...
bool keepInBound = keepImportedInboundCheckBox->isChecked(); bool keepInBound = keepImportedInboundCheckBox->isChecked();
QString path = fileLineTxt->text(); QString path = fileLineTxt->text();
aliasPrefix = aliasPrefix.isEmpty() ? aliasPrefix : QFileInfo(path).fileName();
config = ConvertConfigFromFile(path, keepInBound);
if (config.isEmpty()) { if (!ConnectionInstance::ValidateConfig(path)) {
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)) {
QvMessageBox(this, tr("Import config file"), tr("Failed to check the validity of the config file.")); QvMessageBox(this, tr("Import config file"), tr("Failed to check the validity of the config file."));
return; return;
} else { }
aliasPrefix += "_" + QFileInfo(path).fileName();
CONFIGROOT config = ConvertConfigFromFile(path, keepInBound);
connections[aliasPrefix] = config; connections[aliasPrefix] = config;
break; break;
} }
}
case 1: { case 1: {
QStringList vmessList = SplitLines(vmessConnectionStringTxt->toPlainText()); QStringList vmessList = SplitLines(vmessConnectionStringTxt->toPlainText());
@ -91,13 +87,13 @@ void ImportConfigWindow::on_beginImportBtn_clicked()
vmessConnectionStringTxt->clear(); vmessConnectionStringTxt->clear();
errorsList->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()) { while (!vmessList.isEmpty()) {
aliasPrefix = nameTxt->text(); aliasPrefix = nameTxt->text();
auto vmess = vmessList.takeFirst(); auto vmess = vmessList.takeFirst();
QString errMessage; 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 the config is empty or we have any err messages.
if (config.isEmpty() || !errMessage.isEmpty()) { if (config.isEmpty() || !errMessage.isEmpty()) {
@ -110,7 +106,6 @@ void ImportConfigWindow::on_beginImportBtn_clicked()
} }
if (!vmessErrors.isEmpty()) { if (!vmessErrors.isEmpty()) {
// TODO Show in UI
for (auto item : vmessErrors) { for (auto item : vmessErrors) {
vmessConnectionStringTxt->appendPlainText(vmessErrors.key(item)); vmessConnectionStringTxt->appendPlainText(vmessErrors.key(item));
errorsList->addItem(item); errorsList->addItem(item);

View File

@ -50,7 +50,12 @@ MainWindow::MainWindow(QWidget *parent)
vinstance = new ConnectionInstance(this); vinstance = new ConnectionInstance(this);
setupUi(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(); pacServer = new PACHandler();
// //
this->setWindowIcon(QIcon(":/icons/qv2ray.png")); this->setWindowIcon(QIcon(":/icons/qv2ray.png"));
@ -140,7 +145,7 @@ MainWindow::MainWindow(QWidget *parent)
speedChartObj = new QChart(); speedChartObj = new QChart();
speedChartObj->setTheme(conf.uiConfig.useDarkTheme ? QChart::ChartThemeDark : QChart::ChartThemeLight); speedChartObj->setTheme(conf.uiConfig.useDarkTheme ? QChart::ChartThemeDark : QChart::ChartThemeLight);
speedChartObj->setTitle("Qv2ray Speed Chart"); speedChartObj->setTitle(""); // Fake hidden
speedChartObj->legend()->hide(); speedChartObj->legend()->hide();
speedChartObj->createDefaultAxes(); speedChartObj->createDefaultAxes();
speedChartObj->addSeries(uploadSerie); speedChartObj->addSeries(uploadSerie);
@ -185,6 +190,14 @@ MainWindow::MainWindow(QWidget *parent)
StartProcessingPlugins(this); 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) void MainWindow::keyPressEvent(QKeyEvent *e)
{ {
@ -319,7 +332,7 @@ MainWindow::~MainWindow()
} }
void MainWindow::UpdateLog() void MainWindow::UpdateLog()
{ {
logText->append(vinstance->ReadProcessOutput().trimmed()); vcoreLog.append(vinstance->ReadProcessOutput().trimmed());
} }
void MainWindow::on_startButton_clicked() void MainWindow::on_startButton_clicked()
{ {
@ -461,7 +474,7 @@ void MainWindow::on_stopButton_clicked()
hTray->setToolTip(TRAY_TOOLTIP_PREFIX); hTray->setToolTip(TRAY_TOOLTIP_PREFIX);
QFile(QV2RAY_GENERATED_FILE_PATH).remove(); QFile(QV2RAY_GENERATED_FILE_PATH).remove();
statusLabel->setText(tr("Disconnected")); statusLabel->setText(tr("Disconnected"));
logText->setText(""); logText->setPlainText("");
trayMenu->actions()[2]->setEnabled(true); trayMenu->actions()[2]->setEnabled(true);
trayMenu->actions()[3]->setEnabled(false); trayMenu->actions()[3]->setEnabled(false);
trayMenu->actions()[4]->setEnabled(false); trayMenu->actions()[4]->setEnabled(false);

View File

@ -86,6 +86,7 @@ class MainWindow : public QMainWindow, Ui::MainWindow
protected: protected:
void mouseReleaseEvent(QMouseEvent *e) override;
void keyPressEvent(QKeyEvent *e) override; void keyPressEvent(QKeyEvent *e) override;
void timerEvent(QTimerEvent *event) override; void timerEvent(QTimerEvent *event) override;
void closeEvent(QCloseEvent *) override; void closeEvent(QCloseEvent *) override;
@ -120,6 +121,10 @@ class MainWindow : public QMainWindow, Ui::MainWindow
// //
PACHandler *pacServer; PACHandler *pacServer;
Highlighter *highlighter; Highlighter *highlighter;
//
QTextEdit vcoreLog;
QTextEdit qvAppLog;
int logSourceId = 0;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -419,11 +419,24 @@
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2"> <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"> <item row="0" column="0">
<widget class="QLabel" name="label_11"> <widget class="QLabel" name="logLabel">
<property name="text"> <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> </property>
</widget> </widget>
</item> </item>
@ -441,13 +454,6 @@
<property name="lineWrapMode"> <property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum> <enum>QTextEdit::NoWrap</enum>
</property> </property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-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';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openLinks"> <property name="openLinks">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -460,19 +466,6 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
@ -650,7 +643,6 @@ p, li { white-space: pre-wrap; }
<tabstop>editJsonBtn</tabstop> <tabstop>editJsonBtn</tabstop>
<tabstop>pingTestBtn</tabstop> <tabstop>pingTestBtn</tabstop>
<tabstop>shareBtn</tabstop> <tabstop>shareBtn</tabstop>
<tabstop>logText</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -230,8 +230,7 @@ void RouteEditor::ShowRuleDetail(RuleObject rule)
if (!QSTRING(rule.outboundTag).isEmpty()) { if (!QSTRING(rule.outboundTag).isEmpty()) {
// Find outbound index by tag. // Find outbound index by tag.
auto tag = QSTRING(rule.outboundTag); auto index = FindIndexByTag(outbounds, QSTRING(rule.outboundTag));
auto index = FindIndexByTag(outbounds, &tag);
routeOutboundSelector->setCurrentIndex(index); routeOutboundSelector->setCurrentIndex(index);
// //
// Default balancer tag. // Default balancer tag.
@ -253,8 +252,7 @@ void RouteEditor::ShowRuleDetail(RuleObject rule)
isLoading = false; isLoading = false;
on_inboundsList_itemChanged(nullptr); on_inboundsList_itemChanged(nullptr);
// //
auto outboundTag = QSTRING(rule.outboundTag); int index = FindIndexByTag(outbounds, QSTRING(rule.outboundTag));
int index = FindIndexByTag(outbounds, &outboundTag);
outboundsList->setCurrentRow(index); outboundsList->setCurrentRow(index);
// //
// Networks // Networks
@ -306,7 +304,7 @@ void RouteEditor::ShowRuleDetail(RuleObject rule)
if (!inTag.isEmpty()) { if (!inTag.isEmpty()) {
// forget about the "" issue. // forget about the "" issue.
int _index = FindIndexByTag(inbounds, &inTag); int _index = FindIndexByTag(inbounds, inTag);
// FIXED if an inbound is missing (index out of range) // FIXED if an inbound is missing (index out of range)
if (_index >= 0) { if (_index >= 0) {