mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 19:00:22 +08:00
Merge branch 'dev-subscriptions' into dev
This commit is contained in:
commit
0752209ce0
@ -50,6 +50,7 @@ namespace Qv2ray
|
||||
//
|
||||
// -------------------------- BEGIN CONFIG VALIDATIONS ---------------------------------------------
|
||||
int VerifyVMessProtocolString(QString vmess);
|
||||
QString GetVmessFromBase64OrPlain(QByteArray arr);
|
||||
//
|
||||
// -------------------------- BEGIN CONFIG CONVERSIONS ---------------------------------------------
|
||||
// Save Connection Config
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "QvCoreConfigOperations.h"
|
||||
#include "QvUtils.h"
|
||||
|
||||
namespace Qv2ray
|
||||
{
|
||||
@ -22,5 +23,11 @@ namespace Qv2ray
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
QString GetVmessFromBase64OrPlain(QByteArray arr)
|
||||
{
|
||||
auto result = QString::fromUtf8(arr).trimmed();
|
||||
return result.startsWith("vmess://") ? result : Base64Decode(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <QByteArray>
|
||||
namespace Qv2ray
|
||||
{
|
||||
QvHttpRequestHelper::QvHttpRequestHelper(QObject *parent) : QObject(parent), reply(), request()
|
||||
QvHttpRequestHelper::QvHttpRequestHelper()
|
||||
{
|
||||
}
|
||||
|
||||
@ -29,6 +29,18 @@ namespace Qv2ray
|
||||
request.setRawHeader(key, value);
|
||||
}
|
||||
|
||||
QByteArray QvHttpRequestHelper::syncget(const QString &url)
|
||||
{
|
||||
this->setUrl(url);
|
||||
reply = accessManager.get(request);
|
||||
reply->waitForReadyRead(5000);
|
||||
|
||||
if (!reply->isReadable())
|
||||
return QByteArray();
|
||||
else
|
||||
return reply->readAll();
|
||||
}
|
||||
|
||||
void QvHttpRequestHelper::get(const QString &url)
|
||||
{
|
||||
this->setUrl(url);
|
||||
|
@ -32,11 +32,12 @@ namespace Qv2ray
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QvHttpRequestHelper(QObject *parent);
|
||||
explicit QvHttpRequestHelper();
|
||||
~QvHttpRequestHelper();
|
||||
bool setUrl(const QString &url);
|
||||
void setHeader(const QByteArray &key, const QByteArray &value);
|
||||
// get
|
||||
QByteArray syncget(const QString &url);
|
||||
void get(const QString &url);
|
||||
// insert
|
||||
void post(const QString &url, const QByteArray &data);
|
||||
|
@ -17,5 +17,6 @@ using namespace std;
|
||||
#define MODULE_UI "UI"
|
||||
#define MODULE_NETWORK "NETWORK"
|
||||
#define MODULE_FILE "FILE"
|
||||
#define MODULE_SUBSCRIPTION "SUBSCRIPTION"
|
||||
|
||||
#endif // QVTINYLOG_H
|
||||
|
@ -19,13 +19,14 @@
|
||||
#include "w_ImportConfig.h"
|
||||
#include "w_ConnectionEditWindow.h"
|
||||
#include "w_MainWindow.h"
|
||||
#include "w_SubscribeEditor.h"
|
||||
|
||||
#define TRAY_TOOLTIP_PREFIX "Qv2ray " QV2RAY_VERSION_STRING "\r\n"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
HTTPRequestHelper(this),
|
||||
HTTPRequestHelper(),
|
||||
hTray(new QSystemTrayIcon(this)),
|
||||
vinstance(new Qv2Instance(this))
|
||||
{
|
||||
@ -499,3 +500,9 @@ void MainWindow::on_editConfigButton_clicked()
|
||||
connect(w, &ConnectionEditWindow::s_reload_config, this, &MainWindow::save_reload_globalconfig);
|
||||
w->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_clicked()
|
||||
{
|
||||
SubscribeEditor *w = new SubscribeEditor(this);
|
||||
w->show();
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ class MainWindow : public QMainWindow
|
||||
|
||||
void on_editConfigButton_clicked();
|
||||
|
||||
void on_pushButton_clicked();
|
||||
|
||||
private:
|
||||
void on_action_StartThis_triggered();
|
||||
void on_action_RenameConnection_triggered();
|
||||
|
@ -37,7 +37,7 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="2,3">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,1,1,0,0,0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,1,1,0,0,0,0">
|
||||
<property name="spacing">
|
||||
<number>5</number>
|
||||
</property>
|
||||
@ -72,6 +72,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>#Subsciptions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include "w_SubscribeEditor.h"
|
||||
#include "ui_w_SubscribeEditor.h"
|
||||
#include "QvHTTPRequestHelper.h"
|
||||
#include "QvUtils.h"
|
||||
#include "QvCoreConfigOperations.h"
|
||||
|
||||
|
||||
SubscribeEditor::SubscribeEditor(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@ -37,3 +40,50 @@ void SubscribeEditor::on_buttonBox_accepted()
|
||||
SetGlobalConfig(conf);
|
||||
emit s_update_config();
|
||||
}
|
||||
|
||||
void SubscribeEditor::on_addSubsButton_clicked()
|
||||
{
|
||||
ui->subsribeTable->insertRow(ui->subsribeTable->rowCount());
|
||||
}
|
||||
|
||||
void SubscribeEditor::on_updateButton_clicked()
|
||||
{
|
||||
if (isUpdateInProgress) {
|
||||
QvMessageBox(this, tr("#UpdateInProcess"), tr("#TryLater"));
|
||||
return;
|
||||
}
|
||||
|
||||
isUpdateInProgress = true;
|
||||
int index = ui->subsribeTable->currentRow();
|
||||
auto name = ui->subsribeTable->item(index, 0)->text();
|
||||
auto url = ui->subsribeTable->item(index, 1)->text();
|
||||
auto data = helper.syncget(url);
|
||||
ProcessSubscriptionEntry(data, name);
|
||||
}
|
||||
|
||||
void SubscribeEditor::ProcessSubscriptionEntry(QByteArray result, QString subsciptionName)
|
||||
{
|
||||
auto content = GetVmessFromBase64OrPlain(result).replace("\r", "");
|
||||
|
||||
if (!content.isEmpty()) {
|
||||
auto vmessList = content.split("\n");
|
||||
|
||||
for (auto vmess : vmessList) {
|
||||
auto config = ConvertConfigFromVMessString(vmess, QV2RAY_CONFIG_TYPE_SUBSCRIPTION);
|
||||
|
||||
if (subscriptions.contains(subsciptionName)) {
|
||||
}
|
||||
}
|
||||
|
||||
isUpdateInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SubscribeEditor::on_updateAllButton_clicked()
|
||||
{
|
||||
for (auto rowIndex = 0; ui->subscribeList->count(); rowIndex++) {
|
||||
auto url = ui->subsribeTable->item(rowIndex, 1)->text();
|
||||
helper.get(url);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include "QvUtils.h"
|
||||
#include "QvHTTPRequestHelper.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class w_SubscribeEditor;
|
||||
@ -19,11 +21,22 @@ class SubscribeEditor : public QDialog
|
||||
private slots:
|
||||
void on_buttonBox_accepted();
|
||||
|
||||
void on_addSubsButton_clicked();
|
||||
|
||||
void on_updateButton_clicked();
|
||||
|
||||
void on_updateAllButton_clicked();
|
||||
|
||||
signals:
|
||||
void s_update_config();
|
||||
|
||||
private:
|
||||
void ProcessSubscriptionEntry(QByteArray result, QString subsciptionName);
|
||||
|
||||
bool isUpdateInProgress = false;
|
||||
Ui::w_SubscribeEditor *ui;
|
||||
QvHttpRequestHelper helper;
|
||||
QMap<QString, QList<QJsonObject>> subscriptions;
|
||||
};
|
||||
|
||||
#endif // W_SUBSCRIBEEDITOR_H
|
||||
|
@ -19,180 +19,196 @@
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>6</x>
|
||||
<y>446</y>
|
||||
<width>174</width>
|
||||
<height>34</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>433</x>
|
||||
<y>226</y>
|
||||
<width>281</width>
|
||||
<height>214</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>#ConfigDetail</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="0,3,2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="addSubsButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>#AddConnection</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>A</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/add_connection_btn.png</normaloff>:/icons/add_connection_btn.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="removeSubsButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>#RemoveConnection</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>R</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/remove_connection_btn.png</normaloff>:/icons/remove_connection_btn.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="updateAllButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QTableWidget" name="subsribeTable">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="rowCount">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>114</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>30</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>#Type</string>
|
||||
<string>#SubsGroupName</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="typeLabel">
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>#SubsGroupURL</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>#Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="serverLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>#Config</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QTextBrowser" name="jsonConfigTxt"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>#Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="subscribeList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>430</x>
|
||||
<y>10</y>
|
||||
<width>281</width>
|
||||
<height>211</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTableWidget" name="subsribeTable">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>10</y>
|
||||
<width>371</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="rowCount">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>#SubsGroupName</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>#SubsGroupURL</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>8</x>
|
||||
<y>10</y>
|
||||
<width>34</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="addSubsButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>#AddConnection</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>A</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/add_connection_btn.png</normaloff>:/icons/add_connection_btn.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="removeSubsButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>#RemoveConnection</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>R</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/remove_connection_btn.png</normaloff>:/icons/remove_connection_btn.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>GroupBox</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="subscribeList"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="updateButton">
|
||||
<property name="text">
|
||||
<string>#Update Subscription</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>#ConfigDetail</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>#Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="typeLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>#Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="serverLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>#Config</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QTextBrowser" name="jsonConfigTxt"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>#Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
|
Loading…
Reference in New Issue
Block a user