diff --git a/src/QvCoreConfigOperations.h b/src/QvCoreConfigOperations.h index f308082c..5ee7797c 100644 --- a/src/QvCoreConfigOperations.h +++ b/src/QvCoreConfigOperations.h @@ -50,6 +50,7 @@ namespace Qv2ray // // -------------------------- BEGIN CONFIG VALIDATIONS --------------------------------------------- int VerifyVMessProtocolString(QString vmess); + QString GetVmessFromBase64OrPlain(QByteArray arr); // // -------------------------- BEGIN CONFIG CONVERSIONS --------------------------------------------- // Save Connection Config diff --git a/src/QvCoreConfigOperations_Verification.cpp b/src/QvCoreConfigOperations_Verification.cpp index 94f910ff..a8e229dc 100644 --- a/src/QvCoreConfigOperations_Verification.cpp +++ b/src/QvCoreConfigOperations_Verification.cpp @@ -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); + } } } diff --git a/src/QvHTTPRequestHelper.cpp b/src/QvHTTPRequestHelper.cpp index 023966fb..fc105f32 100644 --- a/src/QvHTTPRequestHelper.cpp +++ b/src/QvHTTPRequestHelper.cpp @@ -2,7 +2,7 @@ #include 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); diff --git a/src/QvHTTPRequestHelper.h b/src/QvHTTPRequestHelper.h index e81346e2..97f0d42f 100644 --- a/src/QvHTTPRequestHelper.h +++ b/src/QvHTTPRequestHelper.h @@ -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); diff --git a/src/QvTinyLog.h b/src/QvTinyLog.h index 4dd4a9de..582881e6 100644 --- a/src/QvTinyLog.h +++ b/src/QvTinyLog.h @@ -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 diff --git a/src/w_MainWindow.cpp b/src/w_MainWindow.cpp index 19b39eb3..17937daf 100644 --- a/src/w_MainWindow.cpp +++ b/src/w_MainWindow.cpp @@ -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(); +} diff --git a/src/w_MainWindow.h b/src/w_MainWindow.h index a2095718..da43b09f 100644 --- a/src/w_MainWindow.h +++ b/src/w_MainWindow.h @@ -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(); diff --git a/src/w_MainWindow.ui b/src/w_MainWindow.ui index 78f75608..4080b2e7 100644 --- a/src/w_MainWindow.ui +++ b/src/w_MainWindow.ui @@ -37,7 +37,7 @@ - + 5 @@ -72,6 +72,13 @@ + + + + #Subsciptions + + + diff --git a/src/w_SubscribeEditor.cpp b/src/w_SubscribeEditor.cpp index 6caa8c8b..36a47cc6 100644 --- a/src/w_SubscribeEditor.cpp +++ b/src/w_SubscribeEditor.cpp @@ -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); + } +} + diff --git a/src/w_SubscribeEditor.h b/src/w_SubscribeEditor.h index 265c03f6..794e5272 100644 --- a/src/w_SubscribeEditor.h +++ b/src/w_SubscribeEditor.h @@ -3,6 +3,8 @@ #include #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> subscriptions; }; #endif // W_SUBSCRIBEEDITOR_H diff --git a/src/w_SubscribeEditor.ui b/src/w_SubscribeEditor.ui index c84d9942..1e39c6f5 100644 --- a/src/w_SubscribeEditor.ui +++ b/src/w_SubscribeEditor.ui @@ -19,180 +19,196 @@ true - - - - 6 - 446 - 174 - 34 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 433 - 226 - 281 - 214 - - - - #ConfigDetail - - - - + + + + + + + + 0 + 0 + + + + #AddConnection + + + A + + + + :/icons/add_connection_btn.png:/icons/add_connection_btn.png + + + + + + + + 0 + 0 + + + + #RemoveConnection + + + R + + + + :/icons/remove_connection_btn.png:/icons/remove_connection_btn.png + + + + + + + ... + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectRows + + + 0 + + + false + + + 114 + + + false + + + false + + + 30 + + + true + + - #Type + #SubsGroupName - - - - + + - + #SubsGroupURL - - - - - - #Server - - - - - - - - - - - - - - #Config - - - - - - - - - - #Port - - - - - - - - - 430 - 10 - 281 - 211 - - - - - - - 50 - 10 - 371 - 431 - - - - 0 - - - - #SubsGroupName - - - - - #SubsGroupURL - - - - - - - 8 - 10 - 34 - 431 - - - - - - - - 0 - 0 - - - - #AddConnection - - - A - - - - :/icons/add_connection_btn.png:/icons/add_connection_btn.png - - - - - - - - 0 - 0 - - - - #RemoveConnection - - - R - - - - :/icons/remove_connection_btn.png:/icons/remove_connection_btn.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + + + + + + GroupBox + + + + + + + + + #Update Subscription + + + + + + + #ConfigDetail + + + + + + #Type + + + + + + + + + + + + + + #Server + + + + + + + + + + + + + + #Config + + + + + + + + + + #Port + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + +