mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 02:40:20 +08:00
update: fixed build (by removing all codes?)
This commit is contained in:
parent
b907167138
commit
b9e2b38965
@ -48,12 +48,12 @@ set(QV2RAY_UI_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/RuleWidget.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/RuleWidget.hpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/RuleWidget.ui
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundOutboundWidget.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundOutboundWidget.hpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundOutboundWidget.ui
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundBalancerWidget.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundBalancerWidget.hpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundBalancerWidget.ui
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundWidget.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundWidget.hpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundWidget.ui
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundWidget.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundWidget.hpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundWidget.ui
|
||||
# Style Manager
|
||||
${CMAKE_SOURCE_DIR}/src/ui/styles/StyleManager.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/styles/StyleManager.hpp
|
||||
|
@ -1 +1 @@
|
||||
5793
|
||||
5794
|
||||
|
@ -405,8 +405,7 @@ namespace Qv2ray::base::objects
|
||||
bool ota;
|
||||
int level;
|
||||
int port;
|
||||
ShadowSocksServerObject()
|
||||
: email(""), address("0.0.0.0"), method("aes-256-cfb"), password(""), ota(false), level(0), port(0){};
|
||||
ShadowSocksServerObject() : email(""), address("0.0.0.0"), method("aes-256-cfb"), password(""), ota(false), level(0), port(0){};
|
||||
JSONSTRUCT_REGISTER(ShadowSocksServerObject, F(email, address, port, method, password, ota, level))
|
||||
};
|
||||
} // namespace protocol
|
||||
|
@ -17,6 +17,21 @@ namespace Qv2ray::base::objects::complex
|
||||
OutboundObjectMode mode;
|
||||
ConnectionId connectionId;
|
||||
QJsonObject json;
|
||||
JSONSTRUCT_REGISTER(OutboundObject, F(tag, mode, connectionId, json))
|
||||
};
|
||||
|
||||
enum MetaOutboundObjectType
|
||||
{
|
||||
METAOUTBOUND_ORIGINAL,
|
||||
METAOUTBOUND_BALANCER,
|
||||
METAOUTBOUND_CHAINED
|
||||
};
|
||||
|
||||
struct OutboundObjectMeta
|
||||
{
|
||||
MetaOutboundObjectType metaType;
|
||||
OutboundObject object;
|
||||
JSONSTRUCT_REGISTER(OutboundObjectMeta, F(metaType, object))
|
||||
};
|
||||
|
||||
class __ChainID;
|
||||
@ -25,5 +40,4 @@ namespace Qv2ray::base::objects::complex
|
||||
typedef IDType<__BalancerID> BalancerID;
|
||||
typedef QList<OutboundObject> ChainObject;
|
||||
typedef BalancerObject BalancerObject;
|
||||
|
||||
} // namespace Qv2ray::base::objects::complex
|
||||
|
@ -199,12 +199,12 @@ namespace Qv2ray::base
|
||||
}
|
||||
QJsonValue toJson() const
|
||||
{
|
||||
return JsonStructHelper::___json_struct_store_data(entries);
|
||||
return JsonStructHelper::Serialize(entries);
|
||||
}
|
||||
void loadJson(const QJsonValue &d)
|
||||
{
|
||||
entries.clear();
|
||||
JsonStructHelper::___json_struct_load_data(entries, d);
|
||||
JsonStructHelper::Deserialize(entries, d);
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
|
@ -47,11 +47,12 @@ namespace Qv2ray::base::safetype
|
||||
template<typename enumKey, typename TValue, typename = typename std::enable_if<std::is_enum<enumKey>::value>::type>
|
||||
struct QvEnumMap : QMap<enumKey, TValue>
|
||||
{
|
||||
// WARN: Changing this will bread all existing JSON.
|
||||
static constexpr auto ENUM_JSON_KEY_PREFIX = "$";
|
||||
void loadJson(const QJsonValue &json_object)
|
||||
{
|
||||
QMap<QString, TValue> data;
|
||||
JsonStructHelper::___json_struct_load_data(data, json_object);
|
||||
JsonStructHelper::Deserialize(data, json_object);
|
||||
this->clear();
|
||||
for (QString k_str : data.keys())
|
||||
{
|
||||
@ -72,7 +73,7 @@ namespace Qv2ray::base::safetype
|
||||
{
|
||||
data[ENUM_JSON_KEY_PREFIX + QString::number(k)] = this->value(k);
|
||||
}
|
||||
return JsonStructHelper::___json_struct_store_data(data).toObject();
|
||||
return JsonStructHelper::Serialize(data).toObject();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -87,45 +87,45 @@ RouteEditor::RouteEditor(QJsonObject connection, QWidget *parent) : QvDialog(par
|
||||
//
|
||||
updateColorScheme();
|
||||
//
|
||||
domainStrategy = root["routing"].toObject()["domainStrategy"].toString();
|
||||
domainStrategyCombo->setCurrentText(domainStrategy);
|
||||
|
||||
// Show connections in the node graph
|
||||
for (const auto &in : root["inbounds"].toArray())
|
||||
{
|
||||
AddInbound(INBOUND(in.toObject()));
|
||||
}
|
||||
|
||||
for (const auto &out : root["outbounds"].toArray())
|
||||
{
|
||||
AddOutbound(OUTBOUND(out.toObject()));
|
||||
}
|
||||
|
||||
for (const auto &item : root["routing"].toObject()["rules"].toArray())
|
||||
{
|
||||
AddRule(RuleObject::fromJson(item.toObject()));
|
||||
}
|
||||
|
||||
// Set default outboung combo text AFTER adding all outbounds.
|
||||
defaultOutbound = getTag(OUTBOUND(root["outbounds"].toArray().first().toObject()));
|
||||
defaultOutboundCombo->setCurrentText(defaultOutbound);
|
||||
|
||||
// // Find and add balancers.
|
||||
// for (auto _balancer : root["routing"].toObject()["balancers"].toArray())
|
||||
// {
|
||||
// auto _balancerObject = _balancer.toObject();
|
||||
// if (!_balancerObject["tag"].toString().isEmpty())
|
||||
// {
|
||||
// balancers.insert(_balancerObject["tag"].toString(), _balancerObject["selector"].toVariant().toStringList());
|
||||
// }
|
||||
// }
|
||||
|
||||
// domainStrategy = root["routing"].toObject()["domainStrategy"].toString();
|
||||
// domainStrategyCombo->setCurrentText(domainStrategy);
|
||||
//
|
||||
//// Show connections in the node graph
|
||||
// for (const auto &in : root["inbounds"].toArray())
|
||||
//{
|
||||
// AddInbound(INBOUND(in.toObject()));
|
||||
//}
|
||||
//
|
||||
// for (const auto &out : root["outbounds"].toArray())
|
||||
//{
|
||||
// AddOutbound(OUTBOUND(out.toObject()));
|
||||
//}
|
||||
//
|
||||
// for (const auto &item : root["routing"].toObject()["rules"].toArray())
|
||||
//{
|
||||
// AddRule(RuleObject::fromJson(item.toObject()));
|
||||
//}
|
||||
//
|
||||
//// Set default outboung combo text AFTER adding all outbounds.
|
||||
// defaultOutbound = getTag(OUTBOUND(root["outbounds"].toArray().first().toObject()));
|
||||
// defaultOutboundCombo->setCurrentText(defaultOutbound);
|
||||
//
|
||||
//// // Find and add balancers.
|
||||
//// for (auto _balancer : root["routing"].toObject()["balancers"].toArray())
|
||||
//// {
|
||||
//// auto _balancerObject = _balancer.toObject();
|
||||
//// if (!_balancerObject["tag"].toString().isEmpty())
|
||||
//// {
|
||||
//// balancers.insert(_balancerObject["tag"].toString(), _balancerObject["selector"].toVariant().toStringList());
|
||||
//// }
|
||||
//// }
|
||||
//
|
||||
for (const auto &group : ConnectionManager->AllGroups())
|
||||
{
|
||||
importGroupBtn->addItem(GetDisplayName(group), group.toString());
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
//
|
||||
// isLoading = false;
|
||||
}
|
||||
|
||||
QvMessageBusSlotImpl(RouteEditor)
|
||||
@ -141,52 +141,52 @@ QvMessageBusSlotImpl(RouteEditor)
|
||||
|
||||
void RouteEditor::onNodeClicked(Node &n)
|
||||
{
|
||||
LOADINGCHECK
|
||||
|
||||
if (isExiting)
|
||||
return;
|
||||
|
||||
auto isOut = outboundNodes.values().contains(n.id());
|
||||
auto isIn = inboundNodes.values().contains(n.id());
|
||||
auto isRule = ruleNodes.values().contains(n.id());
|
||||
|
||||
/* if (isRule)
|
||||
{
|
||||
// It's a rule object
|
||||
currentRuleTag = GetFirstNodeData(n.id(), RuleNode)->GetRuleTag();
|
||||
DEBUG(MODULE_GRAPH, "Selecting rule: " + currentRuleTag)
|
||||
// ShowCurrentRuleDetail();
|
||||
toolBox->setCurrentIndex(1);
|
||||
}
|
||||
else*/
|
||||
if (isOut || isIn)
|
||||
{
|
||||
// It's an inbound or an outbound.
|
||||
QString tag;
|
||||
QString host;
|
||||
int port;
|
||||
QString protocol;
|
||||
|
||||
if (isOut)
|
||||
{
|
||||
const auto root = GetFirstNodeData(n.id(), OutboundNode)->GetOutbound();
|
||||
GetOutboundInfo(*root, &host, &port, &protocol);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto root = GetFirstNodeData(n.id(), InboundNode)->GetInbound();
|
||||
GetInboundInfo(*root, &host, &port, &protocol);
|
||||
}
|
||||
|
||||
tagLabel->setText(tag);
|
||||
protocolLabel->setText(protocol);
|
||||
portLabel->setText(QSTRN(port));
|
||||
hostLabel->setText(host);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(MODULE_GRAPH, "Selected an unknown node, RARE.")
|
||||
}
|
||||
// LOADINGCHECK
|
||||
//
|
||||
// if (isExiting)
|
||||
// return;
|
||||
//
|
||||
// auto isOut = outboundNodes.values().contains(n.id());
|
||||
// auto isIn = inboundNodes.values().contains(n.id());
|
||||
// auto isRule = ruleNodes.values().contains(n.id());
|
||||
//
|
||||
// /* if (isRule)
|
||||
// {
|
||||
// // It's a rule object
|
||||
// currentRuleTag = GetFirstNodeData(n.id(), RuleNode)->GetRuleTag();
|
||||
// DEBUG(MODULE_GRAPH, "Selecting rule: " + currentRuleTag)
|
||||
// // ShowCurrentRuleDetail();
|
||||
// toolBox->setCurrentIndex(1);
|
||||
// }
|
||||
// else*/
|
||||
// if (isOut || isIn)
|
||||
// {
|
||||
// // It's an inbound or an outbound.
|
||||
// QString tag;
|
||||
// QString host;
|
||||
// int port;
|
||||
// QString protocol;
|
||||
//
|
||||
// if (isOut)
|
||||
// {
|
||||
// const auto root = GetFirstNodeData(n.id(), OutboundNode)->GetOutbound();
|
||||
// GetOutboundInfo(*root, &host, &port, &protocol);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// const auto root = GetFirstNodeData(n.id(), InboundNode)->GetInbound();
|
||||
// GetInboundInfo(*root, &host, &port, &protocol);
|
||||
// }
|
||||
//
|
||||
// tagLabel->setText(tag);
|
||||
// protocolLabel->setText(protocol);
|
||||
// portLabel->setText(QSTRN(port));
|
||||
// hostLabel->setText(host);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LOG(MODULE_GRAPH, "Selected an unknown node, RARE.")
|
||||
// }
|
||||
}
|
||||
|
||||
void RouteEditor::onConnectionCreated(QtNodes::Connection const &c)
|
||||
@ -308,96 +308,96 @@ CONFIGROOT RouteEditor::OpenEditor()
|
||||
on_addRouteBtn_clicked();
|
||||
}
|
||||
|
||||
// If clicking OK
|
||||
if (result == QDialog::Accepted)
|
||||
{
|
||||
QJsonArray rulesArray;
|
||||
QJsonArray _balancers;
|
||||
// // If clicking OK
|
||||
// if (result == QDialog::Accepted)
|
||||
// {
|
||||
// QJsonArray rulesArray;
|
||||
// QJsonArray _balancers;
|
||||
//
|
||||
//// Append rules by order
|
||||
// for (auto i = 0; i < ruleListWidget->count(); i++)
|
||||
//{
|
||||
// auto _rule = rules[i];
|
||||
// auto ruleJsonObject = _rule.toJson();
|
||||
//
|
||||
// // Process balancer for a rule
|
||||
// if (_rule.QV2RAY_RULE_USE_BALANCER)
|
||||
// {
|
||||
// // Do not use outbound tag.
|
||||
// ruleJsonObject.remove("outboundTag");
|
||||
//
|
||||
// // // Find balancer list
|
||||
// // if (!balancers.contains(_rule.balancerTag))
|
||||
// // {
|
||||
// // LOG(MODULE_UI, "Cannot find a balancer for tag: " + _rule.balancerTag)
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // auto _balancerList = balancers[_rule.balancerTag];
|
||||
// // QJsonObject balancerEntry;
|
||||
// // balancerEntry["tag"] = _rule.balancerTag;
|
||||
// // balancerEntry["selector"] = QJsonArray::fromStringList(_balancerList);
|
||||
// // _balancers.append(balancerEntry);
|
||||
// // }
|
||||
// }
|
||||
//
|
||||
// // Remove some empty fields.
|
||||
// if (_rule.port.isEmpty())
|
||||
// {
|
||||
// ruleJsonObject.remove("port");
|
||||
// }
|
||||
//
|
||||
// if (_rule.network.isEmpty())
|
||||
// {
|
||||
// ruleJsonObject.remove("network");
|
||||
// }
|
||||
//
|
||||
// rulesArray.append(ruleJsonObject);
|
||||
//}
|
||||
|
||||
// Append rules by order
|
||||
for (auto i = 0; i < ruleListWidget->count(); i++)
|
||||
{
|
||||
auto _rule = rules[i];
|
||||
auto ruleJsonObject = _rule.toJson();
|
||||
|
||||
// Process balancer for a rule
|
||||
if (_rule.QV2RAY_RULE_USE_BALANCER)
|
||||
{
|
||||
// Do not use outbound tag.
|
||||
ruleJsonObject.remove("outboundTag");
|
||||
|
||||
// // Find balancer list
|
||||
// if (!balancers.contains(_rule.balancerTag))
|
||||
// {
|
||||
// LOG(MODULE_UI, "Cannot find a balancer for tag: " + _rule.balancerTag)
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// auto _balancerList = balancers[_rule.balancerTag];
|
||||
// QJsonObject balancerEntry;
|
||||
// balancerEntry["tag"] = _rule.balancerTag;
|
||||
// balancerEntry["selector"] = QJsonArray::fromStringList(_balancerList);
|
||||
// _balancers.append(balancerEntry);
|
||||
// }
|
||||
}
|
||||
|
||||
// Remove some empty fields.
|
||||
if (_rule.port.isEmpty())
|
||||
{
|
||||
ruleJsonObject.remove("port");
|
||||
}
|
||||
|
||||
if (_rule.network.isEmpty())
|
||||
{
|
||||
ruleJsonObject.remove("network");
|
||||
}
|
||||
|
||||
rulesArray.append(ruleJsonObject);
|
||||
}
|
||||
|
||||
QJsonObject routing;
|
||||
routing["domainStrategy"] = domainStrategy;
|
||||
routing["rules"] = rulesArray;
|
||||
routing["balancers"] = _balancers;
|
||||
//
|
||||
QJsonArray _inbounds;
|
||||
QJsonArray _outbounds;
|
||||
|
||||
// Convert our internal data format to QJsonArray
|
||||
for (auto x : inbounds)
|
||||
{
|
||||
if (x.isEmpty())
|
||||
continue;
|
||||
|
||||
_inbounds.append(x.raw());
|
||||
}
|
||||
|
||||
for (auto x : outbounds)
|
||||
{
|
||||
if (x.isEmpty())
|
||||
continue;
|
||||
|
||||
if (getTag(x) == defaultOutbound)
|
||||
{
|
||||
LOG(MODULE_CONNECTION, "Pushing default outbound to the front.")
|
||||
// Put the default outbound to the first.
|
||||
_outbounds.push_front(x.raw());
|
||||
}
|
||||
else
|
||||
{
|
||||
_outbounds.push_back(x.raw());
|
||||
}
|
||||
}
|
||||
|
||||
root["inbounds"] = _inbounds;
|
||||
root["outbounds"] = _outbounds;
|
||||
root["routing"] = routing;
|
||||
return root;
|
||||
}
|
||||
else
|
||||
{
|
||||
return original;
|
||||
}
|
||||
// QJsonObject routing;
|
||||
// routing["domainStrategy"] = domainStrategy;
|
||||
// routing["rules"] = rulesArray;
|
||||
// routing["balancers"] = _balancers;
|
||||
// //
|
||||
// QJsonArray _inbounds;
|
||||
// QJsonArray _outbounds;
|
||||
//
|
||||
// // Convert our internal data format to QJsonArray
|
||||
// for (auto x : inbounds)
|
||||
// {
|
||||
// if (x.isEmpty())
|
||||
// continue;
|
||||
//
|
||||
// _inbounds.append(x.raw());
|
||||
// }
|
||||
//
|
||||
// for (auto x : outbounds)
|
||||
// {
|
||||
// if (x.isEmpty())
|
||||
// continue;
|
||||
//
|
||||
// if (getTag(x) == defaultOutbound)
|
||||
// {
|
||||
// LOG(MODULE_CONNECTION, "Pushing default outbound to the front.")
|
||||
// // Put the default outbound to the first.
|
||||
// _outbounds.push_front(x.raw());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _outbounds.push_back(x.raw());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// root["inbounds"] = _inbounds;
|
||||
// root["outbounds"] = _outbounds;
|
||||
// root["routing"] = routing;
|
||||
// return root;
|
||||
//}
|
||||
// else
|
||||
//{
|
||||
return original;
|
||||
//}
|
||||
}
|
||||
|
||||
RouteEditor::~RouteEditor()
|
||||
@ -414,12 +414,12 @@ void RouteEditor::on_buttonBox_accepted()
|
||||
|
||||
void RouteEditor::on_insertDirectBtn_clicked()
|
||||
{
|
||||
auto freedom = GenerateFreedomOUT("AsIs", "", 0);
|
||||
auto tag = "Freedom_" + QSTRN(QTime::currentTime().msecsSinceStartOfDay());
|
||||
auto out = GenerateOutboundEntry("freedom", freedom, QJsonObject(), QJsonObject(), "0.0.0.0", tag);
|
||||
// ADD NODE
|
||||
AddOutbound(out);
|
||||
statusLabel->setText(tr("Added DIRECT outbound"));
|
||||
// auto freedom = GenerateFreedomOUT("AsIs", "", 0);
|
||||
// auto tag = "Freedom_" + QSTRN(QTime::currentTime().msecsSinceStartOfDay());
|
||||
// auto out = GenerateOutboundEntry("freedom", freedom, QJsonObject(), QJsonObject(), "0.0.0.0", tag);
|
||||
//// ADD NODE
|
||||
// AddOutbound(out);
|
||||
// statusLabel->setText(tr("Added DIRECT outbound"));
|
||||
}
|
||||
|
||||
void RouteEditor::on_addDefaultBtn_clicked()
|
||||
|
@ -11,108 +11,109 @@
|
||||
|
||||
void RouteEditor::AddInbound(INBOUND in)
|
||||
{
|
||||
QString tag = getTag(in);
|
||||
|
||||
if (inboundNodes.contains(tag))
|
||||
tag.append("_" + GenerateRandomString(5));
|
||||
|
||||
in["tag"] = tag;
|
||||
inbounds << in;
|
||||
auto _nodeData = std::make_unique<QvInboundNodeModel>(std::make_shared<InboundNodeData>(std::make_shared<INBOUND>(inbounds.last())));
|
||||
auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||
QPointF pos;
|
||||
pos.setX(0 + GRAPH_GLOBAL_OFFSET_X);
|
||||
pos.setY(inboundNodes.count() * 130 + GRAPH_GLOBAL_OFFSET_Y);
|
||||
nodeScene->setNodePosition(node, pos);
|
||||
inboundNodes.insert(tag, node.id());
|
||||
// QString tag = getTag(in);
|
||||
//
|
||||
// if (inboundNodes.contains(tag))
|
||||
// tag.append("_" + GenerateRandomString(5));
|
||||
//
|
||||
// in["tag"] = tag;
|
||||
// inbounds << in;
|
||||
// auto _nodeData = std::make_unique<QvInboundNodeModel>(std::make_shared<InboundNodeData>(std::make_shared<INBOUND>(inbounds.last())));
|
||||
// auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||
// QPointF pos;
|
||||
// pos.setX(0 + GRAPH_GLOBAL_OFFSET_X);
|
||||
// pos.setY(inboundNodes.count() * 130 + GRAPH_GLOBAL_OFFSET_Y);
|
||||
// nodeScene->setNodePosition(node, pos);
|
||||
// inboundNodes.insert(tag, node.id());
|
||||
}
|
||||
|
||||
void RouteEditor::AddOutbound(OUTBOUND out)
|
||||
{
|
||||
QString tag = getTag(out);
|
||||
|
||||
if (outboundNodes.contains(tag))
|
||||
tag.append("_" + GenerateRandomString(5));
|
||||
|
||||
out["tag"] = tag;
|
||||
outbounds << out;
|
||||
auto _nodeData = std::make_unique<QvOutboundNodeModel>(std::make_shared<OutboundNodeData>(std::make_shared<OUTBOUND>(outbounds.last())));
|
||||
auto pos = nodeGraphWidget->pos();
|
||||
pos.setX(pos.x() + 850 + GRAPH_GLOBAL_OFFSET_X);
|
||||
pos.setY(pos.y() + outboundNodes.count() * 120 + GRAPH_GLOBAL_OFFSET_Y);
|
||||
auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||
nodeScene->setNodePosition(node, pos);
|
||||
outboundNodes.insert(tag, node.id());
|
||||
defaultOutboundCombo->addItem(tag);
|
||||
// QString tag = getTag(out);
|
||||
//
|
||||
// if (outboundNodes.contains(tag))
|
||||
// tag.append("_" + GenerateRandomString(5));
|
||||
//
|
||||
// out["tag"] = tag;
|
||||
// outbounds << out;
|
||||
// auto _nodeData = std::make_unique<QvOutboundNodeModel>(std::make_shared<OutboundNodeData>(std::make_shared<OUTBOUND>(outbounds.last())));
|
||||
// auto pos = nodeGraphWidget->pos();
|
||||
// pos.setX(pos.x() + 850 + GRAPH_GLOBAL_OFFSET_X);
|
||||
// pos.setY(pos.y() + outboundNodes.count() * 120 + GRAPH_GLOBAL_OFFSET_Y);
|
||||
// auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||
// nodeScene->setNodePosition(node, pos);
|
||||
// outboundNodes.insert(tag, node.id());
|
||||
// defaultOutboundCombo->addItem(tag);
|
||||
}
|
||||
|
||||
QString RouteEditor::AddNewRule()
|
||||
{
|
||||
// Add Route
|
||||
RuleObject rule;
|
||||
//
|
||||
rule.QV2RAY_RULE_ENABLED = true;
|
||||
rule.QV2RAY_RULE_USE_BALANCER = false;
|
||||
// Default balancer tag, it's a random string.
|
||||
auto bTag = GenerateRandomString();
|
||||
rule.QV2RAY_RULE_TAG = rules.isEmpty() ? tr("Default rule") : (tr("rule") + "-" + GenerateRandomString(6));
|
||||
rule.balancerTag = bTag;
|
||||
// balancers[bTag] = QStringList();
|
||||
AddRule(rule);
|
||||
return rule.QV2RAY_RULE_TAG;
|
||||
//// Add Route
|
||||
// RuleObject rule;
|
||||
////
|
||||
// rule.QV2RAY_RULE_ENABLED = true;
|
||||
// rule.QV2RAY_RULE_USE_BALANCER = false;
|
||||
//// Default balancer tag, it's a random string.
|
||||
// auto bTag = GenerateRandomString();
|
||||
// rule.QV2RAY_RULE_TAG = rules.isEmpty() ? tr("Default rule") : (tr("rule") + "-" + GenerateRandomString(6));
|
||||
// rule.balancerTag = bTag;
|
||||
//// balancers[bTag] = QStringList();
|
||||
// AddRule(rule);
|
||||
// return rule.QV2RAY_RULE_TAG;
|
||||
return "";
|
||||
}
|
||||
|
||||
void RouteEditor::AddRule(RuleObject rule)
|
||||
{
|
||||
// Prevent duplicate
|
||||
if (ruleNodes.contains(rule.QV2RAY_RULE_TAG))
|
||||
{
|
||||
rule.QV2RAY_RULE_TAG += "-" + GenerateRandomString(5);
|
||||
}
|
||||
|
||||
rules << rule;
|
||||
auto pos = nodeGraphWidget->pos();
|
||||
pos.setX(pos.x() + 350 + GRAPH_GLOBAL_OFFSET_X);
|
||||
pos.setY(pos.y() + ruleNodes.count() * 120 + GRAPH_GLOBAL_OFFSET_Y);
|
||||
auto _nodeData = std::make_unique<QvRuleNodeModel>(std::make_shared<RuleNodeData>(std::make_shared<RuleObject>(rules.last())));
|
||||
auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||
nodeScene->setNodePosition(node, pos);
|
||||
|
||||
for (auto inTag : rule.inboundTag)
|
||||
{
|
||||
if (!inboundNodes.contains(inTag))
|
||||
{
|
||||
LOG(MODULE_UI, "No inbound tag found for rule: " + rule.QV2RAY_RULE_TAG + ", inbound tag: " + inTag)
|
||||
QvMessageBoxWarn(this, tr("No Inbound"), tr("No inbound item found: ") + inTag);
|
||||
rule.inboundTag.removeAll(inTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto inboundNode = inboundNodes.value(inTag);
|
||||
auto conn = nodeScene->createConnection(node, 0, *nodeScene->node(inboundNode), 0);
|
||||
connect(conn.get(), &QtNodes::Connection::connectionCompleted, this, &RouteEditor::onConnectionCreated);
|
||||
}
|
||||
}
|
||||
|
||||
// If not using balancers (use outbound tag)
|
||||
if (!rule.QV2RAY_RULE_USE_BALANCER)
|
||||
{
|
||||
if (outboundNodes.contains(rule.outboundTag))
|
||||
{
|
||||
DEBUG(MODULE_GRAPH, "Found outbound tag: " + rule.outboundTag + ", for rule: " + rule.QV2RAY_RULE_TAG)
|
||||
auto conn = nodeScene->createConnection(*nodeScene->node(outboundNodes.value(rule.outboundTag)), 0, node, 0);
|
||||
connect(conn.get(), &QtNodes::Connection::connectionCompleted, this, &RouteEditor::onConnectionCreated);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(MODULE_GRAPH, "Outbound tag not found: " + rule.outboundTag + ", for: " + rule.QV2RAY_RULE_TAG)
|
||||
// QvMessageBoxWarn(this, tr("No outbound tag"), tr("Please connect
|
||||
// the rule with an outbound."));
|
||||
}
|
||||
}
|
||||
|
||||
this->ruleNodes.insert(rule.QV2RAY_RULE_TAG, node.id());
|
||||
ruleListWidget->addItem(rule.QV2RAY_RULE_TAG);
|
||||
//// Prevent duplicate
|
||||
// if (ruleNodes.contains(rule.QV2RAY_RULE_TAG))
|
||||
//{
|
||||
// rule.QV2RAY_RULE_TAG += "-" + GenerateRandomString(5);
|
||||
//}
|
||||
//
|
||||
// rules << rule;
|
||||
// auto pos = nodeGraphWidget->pos();
|
||||
// pos.setX(pos.x() + 350 + GRAPH_GLOBAL_OFFSET_X);
|
||||
// pos.setY(pos.y() + ruleNodes.count() * 120 + GRAPH_GLOBAL_OFFSET_Y);
|
||||
// auto _nodeData = std::make_unique<QvRuleNodeModel>(std::make_shared<RuleNodeData>(std::make_shared<RuleObject>(rules.last())));
|
||||
// auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||
// nodeScene->setNodePosition(node, pos);
|
||||
//
|
||||
// for (auto inTag : rule.inboundTag)
|
||||
//{
|
||||
// if (!inboundNodes.contains(inTag))
|
||||
// {
|
||||
// LOG(MODULE_UI, "No inbound tag found for rule: " + rule.QV2RAY_RULE_TAG + ", inbound tag: " + inTag)
|
||||
// QvMessageBoxWarn(this, tr("No Inbound"), tr("No inbound item found: ") + inTag);
|
||||
// rule.inboundTag.removeAll(inTag);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// auto inboundNode = inboundNodes.value(inTag);
|
||||
// auto conn = nodeScene->createConnection(node, 0, *nodeScene->node(inboundNode), 0);
|
||||
// connect(conn.get(), &QtNodes::Connection::connectionCompleted, this, &RouteEditor::onConnectionCreated);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//// If not using balancers (use outbound tag)
|
||||
// if (!rule.QV2RAY_RULE_USE_BALANCER)
|
||||
//{
|
||||
// if (outboundNodes.contains(rule.outboundTag))
|
||||
// {
|
||||
// DEBUG(MODULE_GRAPH, "Found outbound tag: " + rule.outboundTag + ", for rule: " + rule.QV2RAY_RULE_TAG)
|
||||
// auto conn = nodeScene->createConnection(*nodeScene->node(outboundNodes.value(rule.outboundTag)), 0, node, 0);
|
||||
// connect(conn.get(), &QtNodes::Connection::connectionCompleted, this, &RouteEditor::onConnectionCreated);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LOG(MODULE_GRAPH, "Outbound tag not found: " + rule.outboundTag + ", for: " + rule.QV2RAY_RULE_TAG)
|
||||
// // QvMessageBoxWarn(this, tr("No outbound tag"), tr("Please connect
|
||||
// // the rule with an outbound."));
|
||||
// }
|
||||
//}
|
||||
//
|
||||
// this->ruleNodes.insert(rule.QV2RAY_RULE_TAG, node.id());
|
||||
// ruleListWidget->addItem(rule.QV2RAY_RULE_TAG);
|
||||
}
|
||||
|
||||
// Do not use reference here, we need deep copy of EVERY QString.
|
||||
|
@ -3,10 +3,10 @@
|
||||
QvInboundNodeModel::QvInboundNodeModel(std::shared_ptr<InboundNodeData> data) : NodeDataModel()
|
||||
{
|
||||
_in = data;
|
||||
widget = new InboundOutboundWidget();
|
||||
widget = new InboundWidget();
|
||||
widget->setWindowFlags(Qt::FramelessWindowHint);
|
||||
widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||
connect(widget, &InboundOutboundWidget::OnSizeUpdated, this, &QvInboundNodeModel::embeddedWidgetSizeUpdated);
|
||||
connect(widget, &InboundWidget::OnSizeUpdated, this, &QvInboundNodeModel::embeddedWidgetSizeUpdated);
|
||||
}
|
||||
|
||||
std::unique_ptr<NodeDataModel> QvInboundNodeModel::clone() const
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "NodeModelsBase.hpp"
|
||||
#include "ui/widgets/node/InboundOutboundWidget.hpp"
|
||||
#include "ui/widgets/node/InboundWidget.hpp"
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
@ -40,5 +40,5 @@ class QvInboundNodeModel : public NodeDataModel
|
||||
QString modelValidationError = tr("Missing or incorrect inputs");
|
||||
//
|
||||
std::shared_ptr<InboundNodeData> _in;
|
||||
InboundOutboundWidget *widget;
|
||||
InboundWidget *widget;
|
||||
};
|
||||
|
@ -24,6 +24,7 @@ namespace Qv2ray::ui::nodemodels
|
||||
{
|
||||
const std::shared_ptr<NodeDataType> NODE_TYPE_OUTBOUND = std::make_shared<NodeDataType>("outbound", QObject::tr("Outbound"));
|
||||
const std::shared_ptr<NodeDataType> NODE_TYPE_INBOUND = std::make_shared<NodeDataType>("inbound", QObject::tr("Inbound"));
|
||||
const std::shared_ptr<NodeDataType> NODE_TYPE_RULE = std::make_shared<NodeDataType>("rule", QObject::tr("Rule"));
|
||||
|
||||
class InboundNodeData : public NodeData
|
||||
{
|
||||
@ -32,7 +33,7 @@ namespace Qv2ray::ui::nodemodels
|
||||
|
||||
std::shared_ptr<NodeDataType> type() const override
|
||||
{
|
||||
return NODE_TYPE_INBOUND;
|
||||
return NODE_TYPE_RULE;
|
||||
}
|
||||
|
||||
std::shared_ptr<INBOUND> GetInbound()
|
||||
@ -47,20 +48,20 @@ namespace Qv2ray::ui::nodemodels
|
||||
class OutboundNodeData : public NodeData
|
||||
{
|
||||
public:
|
||||
explicit OutboundNodeData(std::shared_ptr<OUTBOUND> data) : outboundData(data){};
|
||||
explicit OutboundNodeData(std::shared_ptr<complex::OutboundObjectMeta> data) : outboundData(data){};
|
||||
|
||||
std::shared_ptr<NodeDataType> type() const override
|
||||
{
|
||||
return NODE_TYPE_INBOUND;
|
||||
return NODE_TYPE_OUTBOUND;
|
||||
}
|
||||
|
||||
std::shared_ptr<OUTBOUND> GetOutbound()
|
||||
std::shared_ptr<complex::OutboundObjectMeta> GetOutbound()
|
||||
{
|
||||
return outboundData;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<OUTBOUND> outboundData;
|
||||
std::shared_ptr<complex::OutboundObjectMeta> outboundData;
|
||||
};
|
||||
|
||||
class RuleNodeData : public NodeData
|
||||
|
@ -3,7 +3,7 @@
|
||||
QvOutboundNodeModel::QvOutboundNodeModel(std::shared_ptr<OutboundNodeData> data) : NodeDataModel()
|
||||
{
|
||||
_out = data;
|
||||
widget = new InboundOutboundWidget();
|
||||
widget = new InboundWidget();
|
||||
widget->setWindowFlags(Qt::FramelessWindowHint);
|
||||
widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "ui/models/NodeModelsBase.hpp"
|
||||
#include "ui/widgets/node/InboundOutboundWidget.hpp"
|
||||
#include "ui/widgets/node/InboundWidget.hpp"
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
@ -45,7 +45,7 @@ class QvOutboundNodeModel : public NodeDataModel
|
||||
return _out;
|
||||
}
|
||||
|
||||
void setData(std::shared_ptr<OUTBOUND> data)
|
||||
void setData(std::shared_ptr<complex::OutboundObjectMeta> data)
|
||||
{
|
||||
_out = std::make_shared<OutboundNodeData>(data);
|
||||
widget->adjustSize();
|
||||
@ -70,5 +70,5 @@ class QvOutboundNodeModel : public NodeDataModel
|
||||
QString modelValidationError = tr("Missing or incorrect inputs");
|
||||
//
|
||||
std::shared_ptr<OutboundNodeData> _out;
|
||||
InboundOutboundWidget *widget;
|
||||
InboundWidget *widget;
|
||||
};
|
||||
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ui_InboundOutboundWidget.h"
|
||||
|
||||
class InboundOutboundWidget
|
||||
: public QWidget
|
||||
, private Ui::InboundOutboundWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InboundOutboundWidget(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void OnSizeUpdated();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
};
|
@ -1,11 +1,11 @@
|
||||
#include "InboundOutboundWidget.hpp"
|
||||
#include "InboundWidget.hpp"
|
||||
|
||||
InboundOutboundWidget::InboundOutboundWidget(QWidget *parent) : QWidget(parent)
|
||||
InboundWidget::InboundWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
void InboundOutboundWidget::changeEvent(QEvent *e)
|
||||
void InboundWidget::changeEvent(QEvent *e)
|
||||
{
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type())
|
19
src/ui/widgets/node/InboundWidget.hpp
Normal file
19
src/ui/widgets/node/InboundWidget.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "ui_InboundWidget.h"
|
||||
|
||||
class InboundWidget
|
||||
: public QWidget
|
||||
, private Ui::InboundWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InboundWidget(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void OnSizeUpdated();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>InboundOutboundWidget</class>
|
||||
<widget class="QWidget" name="InboundOutboundWidget">
|
||||
<class>InboundWidget</class>
|
||||
<widget class="QWidget" name="InboundWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
@ -1,15 +1,15 @@
|
||||
#include "OutboundBalancerWidget.hpp"
|
||||
#include "OutboundWidget.hpp"
|
||||
|
||||
#include "base/Qv2rayBase.hpp"
|
||||
|
||||
OutboundBalancerWidget::OutboundBalancerWidget(QWidget *parent) : QWidget(parent)
|
||||
OutboundWidget::OutboundWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
balancerAddBtn->setIcon(QICON_R("add.png"));
|
||||
balancerDelBtn->setIcon(QICON_R("delete.png"));
|
||||
}
|
||||
|
||||
void OutboundBalancerWidget::changeEvent(QEvent *e)
|
||||
void OutboundWidget::changeEvent(QEvent *e)
|
||||
{
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type())
|
||||
@ -19,7 +19,7 @@ void OutboundBalancerWidget::changeEvent(QEvent *e)
|
||||
}
|
||||
}
|
||||
|
||||
void OutboundBalancerWidget::on_balancerAddBtn_clicked()
|
||||
void OutboundWidget::on_balancerAddBtn_clicked()
|
||||
{
|
||||
auto balancerTx = balancerSelectionCombo->currentText();
|
||||
|
||||
@ -35,7 +35,7 @@ void OutboundBalancerWidget::on_balancerAddBtn_clicked()
|
||||
// statusLabel->setText(tr("Balancer is empty, not processing."));
|
||||
}
|
||||
}
|
||||
void OutboundBalancerWidget::on_balancerDelBtn_clicked()
|
||||
void OutboundWidget::on_balancerDelBtn_clicked()
|
||||
{
|
||||
if (balancerList->currentRow() < 0)
|
||||
{
|
@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "ui_OutboundBalancerWidget.h"
|
||||
#include "ui_OutboundWidget.h"
|
||||
|
||||
class OutboundBalancerWidget
|
||||
class OutboundWidget
|
||||
: public QWidget
|
||||
, private Ui::OutboundBalancerWidget
|
||||
, private Ui::OutboundWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OutboundBalancerWidget(QWidget *parent = nullptr);
|
||||
explicit OutboundWidget(QWidget *parent = nullptr);
|
||||
void on_balancerAddBtn_clicked();
|
||||
|
||||
void on_balancerDelBtn_clicked();
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OutboundBalancerWidget</class>
|
||||
<widget class="QWidget" name="OutboundBalancerWidget">
|
||||
<class>OutboundWidget</class>
|
||||
<widget class="QWidget" name="OutboundWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
Loading…
Reference in New Issue
Block a user