Use full config to compare profiles

This commit is contained in:
Nova 2025-12-08 15:43:39 +03:30 committed by parhelia512
parent 61f747361e
commit 312d6d3a27
4 changed files with 14 additions and 21 deletions

View File

@ -8,7 +8,6 @@ namespace Configs {
static void Uniq( static void Uniq(
const QList<std::shared_ptr<ProxyEntity>> &in, const QList<std::shared_ptr<ProxyEntity>> &in,
QList<std::shared_ptr<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address = false, // def by bean
bool keep_last = false // def keep first bool keep_last = false // def keep first
); );
@ -16,15 +15,13 @@ namespace Configs {
const QList<std::shared_ptr<ProxyEntity>> &src, const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &outSrc, QList<std::shared_ptr<ProxyEntity>> &outSrc,
QList<std::shared_ptr<ProxyEntity>> &outDst, QList<std::shared_ptr<ProxyEntity>> &outDst
bool by_address = false // def by bean
); );
static void OnlyInSrc( static void OnlyInSrc(
const QList<std::shared_ptr<ProxyEntity>> &src, const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out
bool by_address = false // def by bean
); );
static void OnlyInSrc_ByPointer( static void OnlyInSrc_ByPointer(

View File

@ -461,7 +461,7 @@ namespace Subscription {
Configs::ProfileFilter::OnlyInSrc_ByPointer(out_all, in, out); Configs::ProfileFilter::OnlyInSrc_ByPointer(out_all, in, out);
Configs::ProfileFilter::OnlyInSrc(in, out, only_in); Configs::ProfileFilter::OnlyInSrc(in, out, only_in);
Configs::ProfileFilter::OnlyInSrc(out, in, only_out); Configs::ProfileFilter::OnlyInSrc(out, in, only_out);
Configs::ProfileFilter::Common(in, out, update_keep, update_del, false); Configs::ProfileFilter::Common(in, out, update_keep, update_del);
QString notice_added; QString notice_added;
QString notice_deleted; QString notice_deleted;
if (only_out.size() < 1000) if (only_out.size() < 1000)

View File

@ -2,19 +2,17 @@
namespace Configs { namespace Configs {
QString ProfileFilter_ent_key(const std::shared_ptr<Configs::ProxyEntity> &ent, bool by_address) { QString ProfileFilter_ent_key(const std::shared_ptr<Configs::ProxyEntity> &ent) {
by_address &= ent->type != "custom"; return ent->outbound->ExportJsonLink();
return by_address ? (ent->outbound->DisplayAddress() + ent->outbound->DisplayType())
: QJsonObject2QString(ent->outbound->ToJson({"c_cfg", "c_out"}), true) + ent->outbound->DisplayType();
} }
void ProfileFilter::Uniq(const QList<std::shared_ptr<ProxyEntity>> &in, void ProfileFilter::Uniq(const QList<std::shared_ptr<ProxyEntity>> &in,
QList<std::shared_ptr<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address, bool keep_last) { bool keep_last) {
QMap<QString, std::shared_ptr<ProxyEntity>> hashMap; QMap<QString, std::shared_ptr<ProxyEntity>> hashMap;
for (const auto &ent: in) { for (const auto &ent: in) {
QString key = ProfileFilter_ent_key(ent, by_address); QString key = ProfileFilter_ent_key(ent);
if (hashMap.contains(key)) { if (hashMap.contains(key)) {
if (keep_last) { if (keep_last) {
out.removeAll(hashMap[key]); out.removeAll(hashMap[key]);
@ -31,16 +29,15 @@ namespace Configs {
void ProfileFilter::Common(const QList<std::shared_ptr<ProxyEntity>> &src, void ProfileFilter::Common(const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &outSrc, QList<std::shared_ptr<ProxyEntity>> &outSrc,
QList<std::shared_ptr<ProxyEntity>> &outDst, QList<std::shared_ptr<ProxyEntity>> &outDst) {
bool by_address) {
QMap<QString, std::shared_ptr<ProxyEntity>> hashMap; QMap<QString, std::shared_ptr<ProxyEntity>> hashMap;
for (const auto &ent: src) { for (const auto &ent: src) {
QString key = ProfileFilter_ent_key(ent, by_address); QString key = ProfileFilter_ent_key(ent);
hashMap[key] = ent; hashMap[key] = ent;
} }
for (const auto &ent: dst) { for (const auto &ent: dst) {
QString key = ProfileFilter_ent_key(ent, by_address); QString key = ProfileFilter_ent_key(ent);
if (hashMap.contains(key)) { if (hashMap.contains(key)) {
outDst += ent; outDst += ent;
outSrc += hashMap[key]; outSrc += hashMap[key];
@ -50,16 +47,15 @@ namespace Configs {
void ProfileFilter::OnlyInSrc(const QList<std::shared_ptr<ProxyEntity>> &src, void ProfileFilter::OnlyInSrc(const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out) {
bool by_address) {
QMap<QString, bool> hashMap; QMap<QString, bool> hashMap;
for (const auto &ent: dst) { for (const auto &ent: dst) {
QString key = ProfileFilter_ent_key(ent, by_address); QString key = ProfileFilter_ent_key(ent);
hashMap[key] = true; hashMap[key] = true;
} }
for (const auto &ent: src) { for (const auto &ent: src) {
QString key = ProfileFilter_ent_key(ent, by_address); QString key = ProfileFilter_ent_key(ent);
if (!hashMap.contains(key)) out += ent; if (!hashMap.contains(key)) out += ent;
} }
} }

View File

@ -1706,7 +1706,7 @@ void MainWindow::on_menu_delete_repeat_triggered () {
QList<std::shared_ptr<Configs::ProxyEntity>> out; QList<std::shared_ptr<Configs::ProxyEntity>> out;
QList<std::shared_ptr<Configs::ProxyEntity>> out_del; QList<std::shared_ptr<Configs::ProxyEntity>> out_del;
Configs::ProfileFilter::Uniq (Configs::profileManager-> CurrentGroup ()-> GetProfileEnts (), out, true , false ); Configs::ProfileFilter::Uniq (Configs::profileManager-> CurrentGroup ()-> GetProfileEnts (), out, false );
Configs::ProfileFilter::OnlyInSrc_ByPointer (Configs::profileManager-> CurrentGroup ()-> GetProfileEnts (), out, out_del); Configs::ProfileFilter::OnlyInSrc_ByPointer (Configs::profileManager-> CurrentGroup ()-> GetProfileEnts (), out, out_del);
int remove_display_count = 0 ; int remove_display_count = 0 ;