diff --git a/makespec/BUILDVERSION b/makespec/BUILDVERSION index 2d2c4aa9..0130643d 100644 --- a/makespec/BUILDVERSION +++ b/makespec/BUILDVERSION @@ -1 +1 @@ -3956 +3961 diff --git a/src/core/connection/Serialization.cpp b/src/core/connection/Serialization.cpp index 1fc175de..ab47b53e 100644 --- a/src/core/connection/Serialization.cpp +++ b/src/core/connection/Serialization.cpp @@ -2,6 +2,7 @@ #include "Generation.hpp" #include "common/QvHelpers.hpp" #include "core/CoreUtils.hpp" +#include "core/handler/ConnectionHandler.hpp" namespace Qv2ray::core::connection { @@ -22,26 +23,26 @@ namespace Qv2ray::core::connection return config; } - - QString ConvertConfigToString(const CONFIGROOT &server, const QString &alias, bool isSip002) + const QString ConvertConfigToString(const ConnectionId &id, bool isSip002) { + auto server = ConnectionManager->GetConnectionRoot(id); + auto alias = ConnectionManager->GetDisplayName(id); OUTBOUND outbound = OUTBOUND(server["outbounds"].toArray().first().toObject()); - //auto info = GetConnectionInfo(server); - //auto type = get<2>(info); - //QString sharelink = ""; - // - //if (type == "vmess") { - // auto vmessServer = StructFromJsonString(JsonToString(outbound["settings"].toObject()["vnext"].toArray().first().toObject())); - // auto transport = StructFromJsonString(JsonToString(outbound["streamSettings"].toObject())); - // sharelink = ConvertConfigToVMessString(transport, vmessServer, alias); - //} else if (type == "shadowsocks") { - // auto ssServer = StructFromJsonString(JsonToString(outbound["settings"].toObject()["servers"].toArray().first().toObject())); - // sharelink = ConvertConfigToSSString(ssServer, alias, isSip002); - //} else { - // LOG(MODULE_CONNECTION, "Unsupported outbound type: " + type) - //} - return "WIP"; - //return sharelink; + auto type = outbound["protocol"].toString(); + QString sharelink = ""; + + if (type == "vmess") { + auto vmessServer = StructFromJsonString(JsonToString(outbound["settings"].toObject()["vnext"].toArray().first().toObject())); + auto transport = StructFromJsonString(JsonToString(outbound["streamSettings"].toObject())); + sharelink = ConvertConfigToVMessString(transport, vmessServer, alias); + } else if (type == "shadowsocks") { + auto ssServer = StructFromJsonString(JsonToString(outbound["settings"].toObject()["servers"].toArray().first().toObject())); + sharelink = ConvertConfigToSSString(ssServer, alias, isSip002); + } else { + LOG(MODULE_CONNECTION, "Unsupported outbound type: " + type) + } + + return sharelink; } // From https://github.com/2dust/v2rayN/wiki/%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5%E6%A0%BC%E5%BC%8F%E8%AF%B4%E6%98%8E(ver-2) diff --git a/src/core/connection/Serialization.hpp b/src/core/connection/Serialization.hpp index f72059c3..fffb574d 100644 --- a/src/core/connection/Serialization.hpp +++ b/src/core/connection/Serialization.hpp @@ -1,4 +1,5 @@ #include "base/Qv2rayBase.hpp" +#include "core/CoreSafeTypes.hpp" namespace Qv2ray::core::connection { @@ -9,7 +10,7 @@ namespace Qv2ray::core::connection // General CONFIGROOT ConvertConfigFromString(const QString &link, QString *alias, QString *errMessage); - QString ConvertConfigToString(const CONFIGROOT &server, const QString &alias, bool isSip002 = false); + const QString ConvertConfigToString(const ConnectionId &id, bool isSip002 = false); // VMess URI Protocol CONFIGROOT ConvertConfigFromVMessString(const QString &vmess, QString *alias, QString *errMessage); diff --git a/src/core/handler/ConnectionHandler.cpp b/src/core/handler/ConnectionHandler.cpp index 1acf03a5..0436fd35 100644 --- a/src/core/handler/ConnectionHandler.cpp +++ b/src/core/handler/ConnectionHandler.cpp @@ -204,7 +204,7 @@ namespace Qv2ray::core::handlers StopConnection(); } - CONFIGROOT root = CHGetConnectionRoot_p(connections[identifier].groupId, identifier); + CONFIGROOT root = GetConnectionRoot(connections[identifier].groupId, identifier); return CHStartConnection_p(identifier, root); } @@ -230,7 +230,7 @@ namespace Qv2ray::core::handlers result = tr("N/A"); } - CONFIGROOT root = CHGetConnectionRoot_p(connections[id].groupId, id); + CONFIGROOT root = GetConnectionRoot(connections[id].groupId, id); QStringList protocols; QStringList streamProtocols; auto outbound = root["outbounds"].toArray().first().toObject(); @@ -273,12 +273,12 @@ namespace Qv2ray::core::handlers delete vCoreInstance; } - const CONFIGROOT QvConnectionHandler::CHGetConnectionRoot_p(const ConnectionId &id) const + const CONFIGROOT QvConnectionHandler::GetConnectionRoot(const ConnectionId &id) const { - return connections.contains(id) ? CHGetConnectionRoot_p(connections[id].groupId, id) : CONFIGROOT(); + return connections.contains(id) ? GetConnectionRoot(connections[id].groupId, id) : CONFIGROOT(); } - const CONFIGROOT QvConnectionHandler::CHGetConnectionRoot_p(const GroupId &group, const ConnectionId &id) const + const CONFIGROOT QvConnectionHandler::GetConnectionRoot(const GroupId &group, const ConnectionId &id) const { auto path = group.toString() + "/" + id.toString() + QV2RAY_CONFIG_FILE_EXTENSION; path.prepend(groups[group].isSubscription ? QV2RAY_SUBSCRIPTION_DIR : QV2RAY_CONNECTIONS_DIR); @@ -288,7 +288,7 @@ namespace Qv2ray::core::handlers const tuple QvConnectionHandler::GetConnectionInfo(const ConnectionId &id) const { - auto root = CHGetConnectionRoot_p(id); + auto root = GetConnectionRoot(id); bool validOutboundFound = false; QString host; int port; diff --git a/src/core/handler/ConnectionHandler.hpp b/src/core/handler/ConnectionHandler.hpp index 250663a7..10456a30 100644 --- a/src/core/handler/ConnectionHandler.hpp +++ b/src/core/handler/ConnectionHandler.hpp @@ -42,6 +42,9 @@ namespace Qv2ray::core::handlers const ConnectionId DuplicateConnection(const ConnectionId &id); const optional MoveConnectionGroup(const ConnectionId &id, const GroupId &newGroupId); // + const CONFIGROOT GetConnectionRoot(const ConnectionId &id) const; + const CONFIGROOT GetConnectionRoot(const GroupId &group, const ConnectionId &id) const; + // // Get Conncetion Property const QString GetConnectionProtocolString(const ConnectionId &id) const; const tuple GetConnectionInfo(const ConnectionId &connectionId) const; @@ -101,8 +104,6 @@ namespace Qv2ray::core::handlers bool CHGetOutboundData_p(const OUTBOUND &out, QString *host, int *port) const; optional CHStartConnection_p(const ConnectionId &id, const CONFIGROOT &root); void CHStopConnection_p(); - const CONFIGROOT CHGetConnectionRoot_p(const ConnectionId &id) const; - const CONFIGROOT CHGetConnectionRoot_p(const GroupId &group, const ConnectionId &id) const; bool CHSaveConnectionConfig_p(CONFIGROOT obj, const ConnectionId &id, bool override); private: diff --git a/src/ui/w_MainWindow_extra.cpp b/src/ui/w_MainWindow_extra.cpp index 5604bd15..49bf3779 100644 --- a/src/ui/w_MainWindow_extra.cpp +++ b/src/ui/w_MainWindow_extra.cpp @@ -3,7 +3,6 @@ // We NEED to include the cpp file to define the macros. #include "w_MainWindow.cpp" #include "components/proxy/QvProxyConfigurator.hpp" -#include "core/connection/Generation.hpp" //QTreeWidgetItem *MainWindow::FindItemByIdentifier(QvConnectionObject identifier) //{ diff --git a/src/ui/widgets/ConnectionInfoWidget.cpp b/src/ui/widgets/ConnectionInfoWidget.cpp index fba08c72..7afdd5ea 100644 --- a/src/ui/widgets/ConnectionInfoWidget.cpp +++ b/src/ui/widgets/ConnectionInfoWidget.cpp @@ -1,5 +1,7 @@ #include "ConnectionInfoWidget.hpp" #include "core/CoreUtils.hpp" +#include "core/connection/Serialization.hpp" +#include "3rdparty/qzxing/src/QZXing.h" ConnectionInfoWidget::ConnectionInfoWidget(QWidget *parent): QWidget(parent) { @@ -35,12 +37,18 @@ void ConnectionInfoWidget::ShowDetails(const tuple &_iden connectBtn->setEnabled(true); duplicateBtn->setEnabled(true); // - shareLinkTxt->setText("scheme://user:pass@host:port/path/to/file?arg1=ARG1&arg2=ARG2#tag"); + auto shareLink = ConvertConfigToString(connectionId); + shareLinkTxt->setText(shareLink); shareLinkTxt->setCursorPosition(0); // + QZXingEncoderConfig conf; + conf.border = true; + conf.imageSize = QSize(400, 400); + auto img = QZXing().encodeData(shareLink, conf); + qrLabel->setPixmap(QPixmap::fromImage(img)); + // connectBtn->setIcon(ConnectionManager->IsConnected(connectionId) ? QICON_R("stop.png") : QICON_R("connect.png")); } else { - //connNameLabel->setText(ConnectionManager->GetDisplayName(groupId)); connectBtn->setIcon(QICON_R("connect.png")); groupLabel->setText(tr("N/A")); protocolLabel->setText(tr("N/A")); @@ -50,6 +58,9 @@ void ConnectionInfoWidget::ShowDetails(const tuple &_iden editJsonBtn->setEnabled(false); connectBtn->setEnabled(false); duplicateBtn->setEnabled(false); + // + shareLinkTxt->clear(); + qrLabel->clear(); } }