mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-23 01:50:17 +08:00
Merge pull request #602 from 0-Kutya-0/dev
added sorting by Outbound and Protocol
This commit is contained in:
commit
fb460c4711
@ -12,7 +12,9 @@ namespace Stats
|
|||||||
ByDownload,
|
ByDownload,
|
||||||
ByUpload,
|
ByUpload,
|
||||||
ByProcess,
|
ByProcess,
|
||||||
ByTraffic
|
ByTraffic,
|
||||||
|
ByOutbound,
|
||||||
|
ByProtocol
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConnectionMetadata
|
class ConnectionMetadata
|
||||||
|
|||||||
@ -441,11 +441,17 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Protocol</string>
|
<string>Protocol</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Click To Sort By Protocol</string>
|
||||||
|
</property>
|
||||||
</column>
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Outbound</string>
|
<string>Outbound</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Click To Sort By Outbound</string>
|
||||||
|
</property>
|
||||||
</column>
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
@ -114,6 +114,22 @@ namespace Stats
|
|||||||
return asc ? a.process > b.process : a.process < b.process;
|
return asc ? a.process > b.process : a.process < b.process;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (sort == ByOutbound)
|
||||||
|
{
|
||||||
|
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b)
|
||||||
|
{
|
||||||
|
if (a.outbound == b.outbound) return asc ? a.id > b.id : a.id < b.id;
|
||||||
|
return asc ? a.outbound > b.outbound : a.outbound < b.outbound;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (sort == ByProtocol)
|
||||||
|
{
|
||||||
|
std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b)
|
||||||
|
{
|
||||||
|
if (a.protocol == b.protocol) return asc ? a.id > b.id : a.id < b.id;
|
||||||
|
return asc ? a.protocol > b.protocol : a.protocol < b.protocol;
|
||||||
|
});
|
||||||
|
}
|
||||||
runOnUiThread([=] {
|
runOnUiThread([=] {
|
||||||
auto m = GetMainWindow();
|
auto m = GetMainWindow();
|
||||||
m->UpdateConnectionListWithRecreate(sorted);
|
m->UpdateConnectionListWithRecreate(sorted);
|
||||||
|
|||||||
@ -235,27 +235,19 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
});
|
});
|
||||||
connect(ui->connections->horizontalHeader(), &QHeaderView::sectionClicked, this, [=](int index)
|
connect(ui->connections->horizontalHeader(), &QHeaderView::sectionClicked, this, [=](int index)
|
||||||
{
|
{
|
||||||
// TODO this is a very bad idea to hardcode it like this, need to refactor it later
|
Stats::ConnectionSort sortType;
|
||||||
if (index == 0)
|
|
||||||
|
switch (index)
|
||||||
{
|
{
|
||||||
Stats::connection_lister->setSort(Stats::Default);
|
case 1: sortType = Stats::ByProcess; break;
|
||||||
|
case 2: sortType = Stats::ByProtocol; break;
|
||||||
|
case 3: sortType = Stats::ByOutbound; break;
|
||||||
|
case 4: sortType = Stats::ByTraffic; break;
|
||||||
|
default: sortType = Stats::Default; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stats::connection_lister->setSort(sortType);
|
||||||
Stats::connection_lister->ForceUpdate();
|
Stats::connection_lister->ForceUpdate();
|
||||||
}
|
|
||||||
if (index == 2 || index == 3)
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (index == 1)
|
|
||||||
{
|
|
||||||
Stats::connection_lister->setSort(Stats::ByProcess);
|
|
||||||
Stats::connection_lister->ForceUpdate();
|
|
||||||
}
|
|
||||||
if (index == 4)
|
|
||||||
{
|
|
||||||
Stats::connection_lister->setSort(Stats::ByTraffic);
|
|
||||||
Stats::connection_lister->ForceUpdate();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// setup Speed Chart
|
// setup Speed Chart
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user