diff --git a/include/stats/connections/connectionLister.hpp b/include/stats/connections/connectionLister.hpp
index 54c5c04..c4982e2 100644
--- a/include/stats/connections/connectionLister.hpp
+++ b/include/stats/connections/connectionLister.hpp
@@ -12,7 +12,9 @@ namespace Stats
ByDownload,
ByUpload,
ByProcess,
- ByTraffic
+ ByTraffic,
+ ByOutbound,
+ ByProtocol
};
class ConnectionMetadata
diff --git a/include/ui/mainwindow.ui b/include/ui/mainwindow.ui
index 84eac8f..f822bc8 100644
--- a/include/ui/mainwindow.ui
+++ b/include/ui/mainwindow.ui
@@ -441,11 +441,17 @@
Protocol
+
+ Click To Sort By Protocol
+
Outbound
+
+ Click To Sort By Outbound
+
diff --git a/src/stats/connectionLister/connectionLister.cpp b/src/stats/connectionLister/connectionLister.cpp
index bd7dcbe..ed6e695 100644
--- a/src/stats/connectionLister/connectionLister.cpp
+++ b/src/stats/connectionLister/connectionLister.cpp
@@ -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);
diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp
index ef7e6ad..ca0a605 100644
--- a/src/ui/mainwindow.cpp
+++ b/src/ui/mainwindow.cpp
@@ -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