mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 13:50:12 +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,
|
||||
ByUpload,
|
||||
ByProcess,
|
||||
ByTraffic
|
||||
ByTraffic,
|
||||
ByOutbound,
|
||||
ByProtocol
|
||||
};
|
||||
|
||||
class ConnectionMetadata
|
||||
|
||||
@ -441,11 +441,17 @@
|
||||
<property name="text">
|
||||
<string>Protocol</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click To Sort By Protocol</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Outbound</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click To Sort By Outbound</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
|
||||
@ -114,6 +114,22 @@ namespace Stats
|
||||
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([=] {
|
||||
auto m = GetMainWindow();
|
||||
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)
|
||||
{
|
||||
// TODO this is a very bad idea to hardcode it like this, need to refactor it later
|
||||
if (index == 0)
|
||||
{
|
||||
Stats::connection_lister->setSort(Stats::Default);
|
||||
Stats::ConnectionSort sortType;
|
||||
|
||||
switch (index)
|
||||
{
|
||||
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();
|
||||
}
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user