add: added export sharelink and qr support, ssd:// WIP

This commit is contained in:
Qv2ray-dev 2020-02-25 22:16:32 +08:00
parent 0bea5d0f15
commit adb7bc4c1e
7 changed files with 44 additions and 31 deletions

View File

@ -1 +1 @@
3956 3961

View File

@ -2,6 +2,7 @@
#include "Generation.hpp" #include "Generation.hpp"
#include "common/QvHelpers.hpp" #include "common/QvHelpers.hpp"
#include "core/CoreUtils.hpp" #include "core/CoreUtils.hpp"
#include "core/handler/ConnectionHandler.hpp"
namespace Qv2ray::core::connection namespace Qv2ray::core::connection
{ {
@ -22,26 +23,26 @@ namespace Qv2ray::core::connection
return config; return config;
} }
const QString ConvertConfigToString(const ConnectionId &id, bool isSip002)
QString ConvertConfigToString(const CONFIGROOT &server, const QString &alias, bool isSip002)
{ {
auto server = ConnectionManager->GetConnectionRoot(id);
auto alias = ConnectionManager->GetDisplayName(id);
OUTBOUND outbound = OUTBOUND(server["outbounds"].toArray().first().toObject()); OUTBOUND outbound = OUTBOUND(server["outbounds"].toArray().first().toObject());
//auto info = GetConnectionInfo(server); auto type = outbound["protocol"].toString();
//auto type = get<2>(info); QString sharelink = "";
//QString sharelink = "";
// if (type == "vmess") {
//if (type == "vmess") { auto vmessServer = StructFromJsonString<VMessServerObject>(JsonToString(outbound["settings"].toObject()["vnext"].toArray().first().toObject()));
// auto vmessServer = StructFromJsonString<VMessServerObject>(JsonToString(outbound["settings"].toObject()["vnext"].toArray().first().toObject())); auto transport = StructFromJsonString<StreamSettingsObject>(JsonToString(outbound["streamSettings"].toObject()));
// auto transport = StructFromJsonString<StreamSettingsObject>(JsonToString(outbound["streamSettings"].toObject())); sharelink = ConvertConfigToVMessString(transport, vmessServer, alias);
// sharelink = ConvertConfigToVMessString(transport, vmessServer, alias); } else if (type == "shadowsocks") {
//} else if (type == "shadowsocks") { auto ssServer = StructFromJsonString<ShadowSocksServerObject>(JsonToString(outbound["settings"].toObject()["servers"].toArray().first().toObject()));
// auto ssServer = StructFromJsonString<ShadowSocksServerObject>(JsonToString(outbound["settings"].toObject()["servers"].toArray().first().toObject())); sharelink = ConvertConfigToSSString(ssServer, alias, isSip002);
// sharelink = ConvertConfigToSSString(ssServer, alias, isSip002); } else {
//} else { LOG(MODULE_CONNECTION, "Unsupported outbound type: " + type)
// LOG(MODULE_CONNECTION, "Unsupported outbound type: " + type) }
//}
return "WIP"; return sharelink;
//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) // 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)

View File

@ -1,4 +1,5 @@
#include "base/Qv2rayBase.hpp" #include "base/Qv2rayBase.hpp"
#include "core/CoreSafeTypes.hpp"
namespace Qv2ray::core::connection namespace Qv2ray::core::connection
{ {
@ -9,7 +10,7 @@ namespace Qv2ray::core::connection
// General // General
CONFIGROOT ConvertConfigFromString(const QString &link, QString *alias, QString *errMessage); 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 // VMess URI Protocol
CONFIGROOT ConvertConfigFromVMessString(const QString &vmess, QString *alias, QString *errMessage); CONFIGROOT ConvertConfigFromVMessString(const QString &vmess, QString *alias, QString *errMessage);

View File

@ -204,7 +204,7 @@ namespace Qv2ray::core::handlers
StopConnection(); StopConnection();
} }
CONFIGROOT root = CHGetConnectionRoot_p(connections[identifier].groupId, identifier); CONFIGROOT root = GetConnectionRoot(connections[identifier].groupId, identifier);
return CHStartConnection_p(identifier, root); return CHStartConnection_p(identifier, root);
} }
@ -230,7 +230,7 @@ namespace Qv2ray::core::handlers
result = tr("N/A"); result = tr("N/A");
} }
CONFIGROOT root = CHGetConnectionRoot_p(connections[id].groupId, id); CONFIGROOT root = GetConnectionRoot(connections[id].groupId, id);
QStringList protocols; QStringList protocols;
QStringList streamProtocols; QStringList streamProtocols;
auto outbound = root["outbounds"].toArray().first().toObject(); auto outbound = root["outbounds"].toArray().first().toObject();
@ -273,12 +273,12 @@ namespace Qv2ray::core::handlers
delete vCoreInstance; 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; auto path = group.toString() + "/" + id.toString() + QV2RAY_CONFIG_FILE_EXTENSION;
path.prepend(groups[group].isSubscription ? QV2RAY_SUBSCRIPTION_DIR : QV2RAY_CONNECTIONS_DIR); path.prepend(groups[group].isSubscription ? QV2RAY_SUBSCRIPTION_DIR : QV2RAY_CONNECTIONS_DIR);
@ -288,7 +288,7 @@ namespace Qv2ray::core::handlers
const tuple<QString, int> QvConnectionHandler::GetConnectionInfo(const ConnectionId &id) const const tuple<QString, int> QvConnectionHandler::GetConnectionInfo(const ConnectionId &id) const
{ {
auto root = CHGetConnectionRoot_p(id); auto root = GetConnectionRoot(id);
bool validOutboundFound = false; bool validOutboundFound = false;
QString host; QString host;
int port; int port;

View File

@ -42,6 +42,9 @@ namespace Qv2ray::core::handlers
const ConnectionId DuplicateConnection(const ConnectionId &id); const ConnectionId DuplicateConnection(const ConnectionId &id);
const optional<QString> MoveConnectionGroup(const ConnectionId &id, const GroupId &newGroupId); const optional<QString> 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 // Get Conncetion Property
const QString GetConnectionProtocolString(const ConnectionId &id) const; const QString GetConnectionProtocolString(const ConnectionId &id) const;
const tuple<QString, int> GetConnectionInfo(const ConnectionId &connectionId) const; const tuple<QString, int> GetConnectionInfo(const ConnectionId &connectionId) const;
@ -101,8 +104,6 @@ namespace Qv2ray::core::handlers
bool CHGetOutboundData_p(const OUTBOUND &out, QString *host, int *port) const; bool CHGetOutboundData_p(const OUTBOUND &out, QString *host, int *port) const;
optional<QString> CHStartConnection_p(const ConnectionId &id, const CONFIGROOT &root); optional<QString> CHStartConnection_p(const ConnectionId &id, const CONFIGROOT &root);
void CHStopConnection_p(); 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); bool CHSaveConnectionConfig_p(CONFIGROOT obj, const ConnectionId &id, bool override);
private: private:

View File

@ -3,7 +3,6 @@
// We NEED to include the cpp file to define the macros. // We NEED to include the cpp file to define the macros.
#include "w_MainWindow.cpp" #include "w_MainWindow.cpp"
#include "components/proxy/QvProxyConfigurator.hpp" #include "components/proxy/QvProxyConfigurator.hpp"
#include "core/connection/Generation.hpp"
//QTreeWidgetItem *MainWindow::FindItemByIdentifier(QvConnectionObject identifier) //QTreeWidgetItem *MainWindow::FindItemByIdentifier(QvConnectionObject identifier)
//{ //{

View File

@ -1,5 +1,7 @@
#include "ConnectionInfoWidget.hpp" #include "ConnectionInfoWidget.hpp"
#include "core/CoreUtils.hpp" #include "core/CoreUtils.hpp"
#include "core/connection/Serialization.hpp"
#include "3rdparty/qzxing/src/QZXing.h"
ConnectionInfoWidget::ConnectionInfoWidget(QWidget *parent): QWidget(parent) ConnectionInfoWidget::ConnectionInfoWidget(QWidget *parent): QWidget(parent)
{ {
@ -35,12 +37,18 @@ void ConnectionInfoWidget::ShowDetails(const tuple<GroupId, ConnectionId> &_iden
connectBtn->setEnabled(true); connectBtn->setEnabled(true);
duplicateBtn->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); 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")); connectBtn->setIcon(ConnectionManager->IsConnected(connectionId) ? QICON_R("stop.png") : QICON_R("connect.png"));
} else { } else {
//connNameLabel->setText(ConnectionManager->GetDisplayName(groupId));
connectBtn->setIcon(QICON_R("connect.png")); connectBtn->setIcon(QICON_R("connect.png"));
groupLabel->setText(tr("N/A")); groupLabel->setText(tr("N/A"));
protocolLabel->setText(tr("N/A")); protocolLabel->setText(tr("N/A"));
@ -50,6 +58,9 @@ void ConnectionInfoWidget::ShowDetails(const tuple<GroupId, ConnectionId> &_iden
editJsonBtn->setEnabled(false); editJsonBtn->setEnabled(false);
connectBtn->setEnabled(false); connectBtn->setEnabled(false);
duplicateBtn->setEnabled(false); duplicateBtn->setEnabled(false);
//
shareLinkTxt->clear();
qrLabel->clear();
} }
} }