feat(gui): show the server host country as a flag icon - #691
Merged
Conversation
Since amule-project#440 the core resolves each ed2k server's host country and hands it to the GUI, but the two lists rendered the same piece of data two different ways: the peer list drew a flag bitmap, while the server list prefixed the Server Name column with the ISO code ("de - ServerName", or "? - " when unresolved). The prefix ate horizontal space in a column that is often too narrow already and broke up the name itself. The server list now draws the same flag the peer list does, with the same rule for the unresolved case: no icon rather than a placeholder. Getting an icon into that column meant finishing a migration that was started when the virtual lists landed and deliberately left out: the server list was the last report-mode CMuleListCtrl of the pair, and only a virtual list can answer OnGetItemColumnImage per row. CServerListCtrl now derives from CMuleVirtualListCtrl and renders its cells on demand from the model via GetItemColumnText, which also buys what the other virtual lists already have -- O(1) row lookup instead of the linear FindItem that RefreshServer, RemoveServer and HighlightServer each ran, a std::sort over the model instead of moving native rows, and one coalesced re-sort per update batch instead of an inline SortList per refreshed server. Ping, Users and Files are declared live-sort columns, so sorting by one of them now follows the data. Three things had to be rebuilt against the model rather than the native items: - The connected server's bold font moves from a per-item wxListItem to OnGetItemAttr; HighlightServer just moves m_connected and repaints. - FitColumnsToContent measures the model itself. wxLIST_AUTOSIZE is a no-op on a virtual control -- it has no native items to measure and returns a default width -- so only the header half can still be left to wxLIST_AUTOSIZE_USEHEADER. - RemoveAllServers collects its victims before deleting any, instead of deleting while walking row indices. The confirmations it raises run a nested event loop, and a row index does not survive that; a server pointer does. The flags go in a small image list owned by this one control, seeded with the header sort arrows so they keep their indices, rather than in the list every CMuleListCtrl shares. Each flag is padded onto a transparent 16x16 cell -- wxImageList has one fixed size, and the bundled flags are 16x11, so adding them as-is would stretch them. The gate deciding which country code to show was duplicated between the two lists, and the server list's copy had an extra thePrefs::IsGeoIPEnabled() check that the peer list deliberately does not have. It is redundant on both paths: the core only emits its country tag when its resolver is on, so a tag received over EC already implies it, and the monolithic local lookup is guarded by the resolver's own IsEnabled(). On amulegui that pref is merely a mirror of the core's, refreshed at prefs-sync time, so consulting it could only ever disagree with the tag we were handed. Both lists now share GetDisplayCountryCode(). That helper is a header, not a .cpp, because the answer depends on ENABLE_IP2COUNTRY / CLIENT_GUI and those are per-target compile definitions. CountryFlags.cpp -- the obvious neighbour -- is built into muleappgui, one static library linked into both binaries with neither define set, where it could only ever produce the amulegui answer. Two base-class methods assumed native items and were dead against a virtual model: GetSelectedItems returned nothing, and DeleteAllItems left the model holding pointers to objects the caller was about to free. Both are now handled in CMuleVirtualListCtrl. No new translatable strings.
got3nks
force-pushed
the
feat/server-list-virtual-flags
branch
from
July 29, 2026 10:02
0f5f000 to
0b95edb
Compare
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #686.
Since #440 the core resolves each ed2k server's host country and hands it to the GUI, but the two lists rendered the same piece of data two different ways: the peer list drew a flag bitmap, while the server list prefixed the Server Name column with the ISO code (
de - ServerName, or? -when unresolved). The prefix ate horizontal space in a column that is often too narrow already, and broke up the name itself.The server list now draws the same flag the peer list does, with the same rule for the unresolved case: no icon rather than a placeholder.
Finishing the virtual-list migration
Getting an icon into that column meant finishing a migration that was started when the virtual lists landed and deliberately left out — the server list was the last report-mode
CMuleListCtrlof the pair, and only a virtual list can answerOnGetItemColumnImageper row.CServerListCtrlnow derives fromCMuleVirtualListCtrland renders its cells on demand from the model viaGetItemColumnText. That also buys what the other virtual lists already have: O(1) row lookup instead of the linearFindItemthatRefreshServer,RemoveServerandHighlightServereach ran; astd::sortover the model instead of moving native rows; and one coalesced re-sort per update batch instead of an inlineSortListper refreshed server. Ping, Users and Files are declared live-sort columns, so sorting by one of them now follows the data — which matters most right after a server-list refresh, when UDP replies arrive in bursts.Three things had to be rebuilt against the model rather than the native items:
wxListItemtoOnGetItemAttr;HighlightServerjust movesm_connectedand repaints the two affected rows.FitColumnsToContentmeasures the model itself.wxLIST_AUTOSIZEis a no-op on a virtual control — it has no native items to measure and hands back a default width — so only the header half can still be left towxLIST_AUTOSIZE_USEHEADER.RemoveAllServerscollects its victims before deleting any, instead of deleting while walking row indices. The confirmations it raises run a nested event loop, and a row index does not survive that; a server pointer does.The flags live in a small image list owned by this one control, seeded with the header sort arrows so those keep their indices, rather than in the list every
CMuleListCtrlshares. Each flag is padded onto a transparent 16×16 cell —wxImageListhas one fixed size and the bundled flags are 16×11, so adding them as-is would stretch them vertically.One gate for both lists
The rule deciding which country code to show was duplicated between the two lists, and the server list's copy carried an extra
thePrefs::IsGeoIPEnabled()check the peer list deliberately does not have. It is redundant on both paths: the core only emits its country tag when its resolver is on, so a tag received over EC already implies it, and the monolithic local lookup is guarded by the resolver's ownIsEnabled(). On amulegui that pref is merely a mirror of the core's, refreshed at prefs-sync time, so consulting it could only ever disagree with the tag we were handed. Both lists now shareGetDisplayCountryCode().That helper is a header rather than a
.cppon purpose: the answer depends onENABLE_IP2COUNTRY/CLIENT_GUI, and those are per-target compile definitions.CountryFlags.cpp— the obvious neighbour — is built intomuleappgui, one static library linked into both binaries with neither define set, where it could only ever produce the amulegui answer.Drive-by
Two
CMuleListCtrlmethods assumed native items and were dead against a virtual model:GetSelectedItemsreturned nothing, andDeleteAllItemsleft the model holding pointers to objects the caller was about to free. Both are now handled inCMuleVirtualListCtrl, which is where the other virtual lists get them from too.No new translatable strings, so no catalog changes.
Testing
Built and run on macOS (monolithic aMule and amulegui). Verified in the running app: flags render undistorted for resolved servers and are absent for unresolved ones, header sort arrows still work, the connected server renders bold and clears on disconnect, columns fit their content on load, and server removal (including the static-server confirmation) behaves as before.
Object-level check that both build variants compile the intended branch:
amule.dir/ServerListCtrl.cpp.oreferencesCIP2Country::GetCountryCode/IsEnabled, whileamulegui.dir/ServerListCtrl.cpp.oreferences onlyCCountryFlags::GetFlag— amulegui stays link-clean of the resolver.