Skip to content

Add country flags for external IP#23731

Open
devIlluSioN wants to merge 3 commits intoqbittorrent:masterfrom
devIlluSioN:master
Open

Add country flags for external IP#23731
devIlluSioN wants to merge 3 commits intoqbittorrent:masterfrom
devIlluSioN:master

Conversation

@devIlluSioN
Copy link

@devIlluSioN devIlluSioN commented Jan 11, 2026

Motivation

Currently, the WebUI and DesktopGUI displays the external IP address in the status bar, but unlike peer IPs, it doesn't show the associated country flag. This feature request adds visual consistency by displaying country flags for external IPs using the same method as peer IPs. Very cool when you use a VPN

What it does

This PR adds country flag display for external IP addresses (both IPv4 and IPv6) in the status bar. The flags are shown next to the IP addresses, matching the behavior already implemented for peer IPs in the peers table.

Changes

Backend (C++ - WebUI):

  • Modified src/webui/api/synccontroller.cpp:
    • Added QHostAddress include
    • Added country code and country name keys for external IPs (IPv4 and IPv6)
    • Enhanced getTransferInfo() to resolve country codes using GeoIPManager when peer country resolution is enabled
    • Simplified IPv6 country lookup to match IPv4 pattern (removed redundant nesting and error handling)

Frontend (JavaScript - WebUI):

  • Modified src/webui/www/private/scripts/client.js:
    • Updated processServerState() to display flags for external IPs
    • Creates <span> elements with flags class and background images pointing to flag SVG files
    • Handles both IPv4 and IPv6 addresses with their respective flags
    • Falls back to plain text if country code is not available

CSS (WebUI):

  • Modified src/webui/www/private/css/style.css:
    • Added global span.flags style for status bar (matching the style used in dynamic tables)

Desktop GUI:

  • Modified src/gui/statusbar.h:
    • Replaced QLabel *m_lastExternalIPsLbl with QWidget *m_externalIPsContainer to support a richer layout
  • Modified src/gui/statusbar.cpp:
    • Added QHostAddress and GeoIPManager includes
    • Replaced the single QLabel with a QWidget container using QHBoxLayout for flexible content
    • updateExternalAddressesLabel() now dynamically builds the IP display: clears existing widgets, adds a prefix label, then for each IP adds an optional flag icon (UIThemeManager::getFlagIcon()) with country name tooltip followed by the IP address
    • Handles IPv4 only, IPv6 only, both (with comma separator), or N/A
    • Country resolution is conditional on Preferences::resolvePeerCountries() (same as peers)

Behavior

  • Country flags are only displayed when "Resolve peer countries" is enabled in preferences (same as for peers)
  • Works with IPv4-only, IPv6-only, or both addresses simultaneously
  • Displays appropriate flag for each IP address
  • Shows country name in tooltip on hover
  • Gracefully falls back to plain IP display if country resolution fails or is disabled

Testing

To test this feature:

  1. Enable "Resolve peer countries" in Options → Behavior → BitTorrent
  2. Enable "Show external IP in status bar" in Options → Interface → Interface
  3. Access the WebUI and check the status bar at the bottom
  4. Verify that flags appear next to external IP addresses
  5. Verify tooltip shows country name on hover

Screenshots

WebUI :
Capture d’écran 2026-01-11 à 19 27 50
(Ip Hidden)

Desktop GUI (Mac) :
image
(Ip Hidden)

Related

This feature uses the same GeoIP resolution system and flag display method as the existing peer country feature, ensuring consistency across the application.

@devIlluSioN devIlluSioN changed the title Add country flags for external IP in webui WebUI: Add country flags for external IP in webui Jan 11, 2026
@glassez glassez changed the title WebUI: Add country flags for external IP in webui WebUI: Add country flags for external IP Jan 12, 2026
@devIlluSioN
Copy link
Author

I will update the code format error today

@devIlluSioN
Copy link
Author

Updated !

@devIlluSioN
Copy link
Author

devIlluSioN commented Jan 12, 2026

Can we rerun the workflow, or do I need to do other things ? @glassez 🤗

Display country flags next to external IPv4 and IPv6 addresses
in the webui status bar, using the same method as peer flags.

The flag is shown only when peer country resolution is enabled
in preferences, consistent with peer flag display behavior.
@devIlluSioN
Copy link
Author

Sorry @glassez about the workflow that didn’t pass.
This time it should be good, I ran npm run format.

@devIlluSioN
Copy link
Author

Hi

Could you clarify the next steps for this PR? Specifically:
1. Does this feature need additional validation before merging?
2. If everything is approved, roughly when would it be expected to be included in a release?

Thanks in advance for the guidance!

@xavier2k6 xavier2k6 requested review from a team January 14, 2026 09:35
@xavier2k6 xavier2k6 added the WebUI WebUI-related issues/changes label Jan 14, 2026
@xavier2k6 xavier2k6 added this to the 5.2 milestone Jan 14, 2026
@xavier2k6
Copy link
Member

  1. Does this feature need additional validation before merging?

Requires relevant team review & approval.

  1. If everything is approved, roughly when would it be expected to be included in a release?

qBittorrent 5.2.0 Beta 2/RC/General Release.

stalkerok
stalkerok previously approved these changes Feb 7, 2026
Copy link
Contributor

@stalkerok stalkerok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flag is displayed correctly with both ipv4 and ipv6.

@glassez
Copy link
Member

glassez commented Feb 8, 2026

Desktop app UI doesn't have such a feature, am I right?

@stalkerok
Copy link
Contributor

stalkerok commented Feb 8, 2026

Desktop app UI doesn't have such a feature, am I right?

Yes
#20118 (comment)

@Ryu481
Copy link
Contributor

Ryu481 commented Feb 8, 2026

Desktop app UI doesn't have such a feature, am I right?

The external IP can be shown in the desktop ui but you have to enable it. It isn't enabled by default. It would be nice if the flag could be added to the desktop ui too.

@devIlluSioN
Copy link
Author

Hello everyone, thanks for your reviews on my PR.

I have two questions:

First: for the changes requested by @glassez, should I amend my last commit or create a new refactor commit?

Second: for the flag on desktop, would it be better if I open an additional PR?

@glassez
Copy link
Member

glassez commented Feb 11, 2026

First: for the changes requested by @glassez, should I amend my last commit or create a new refactor commit?

You can add new commits. Either way all they will be squashed into single one while merging the PR.

@glassez
Copy link
Member

glassez commented Feb 11, 2026

for the flag on desktop, would it be better if I open an additional PR?

As you wish. Personally, I don't even insist that you do it at all, if you suddenly don't want to.

@devIlluSioN devIlluSioN changed the title WebUI: Add country flags for external IP Add country flags for external IP Feb 11, 2026
@devIlluSioN
Copy link
Author

Everything is done

@devIlluSioN
Copy link
Author

Sorry, I forgot to run the linter.

@stalkerok stalkerok added the GUI GUI-related issues/changes label Feb 11, 2026
@stalkerok
Copy link
Contributor

In the GUI, there is an unnecessary space before the flags and after the ipv4 address.

@devIlluSioN
Copy link
Author

devIlluSioN commented Feb 11, 2026

@stalkerok like this is ok for you ?
image

@devIlluSioN
Copy link
Author

Updated !

@stalkerok
Copy link
Contributor

When hovering over the flag in the GUI, N/A appears briefly and then disappears.

@devIlluSioN
Copy link
Author

I won’t have time to look at this today.
Is the next version not imminent?

@stalkerok
Copy link
Contributor

No, not anytime soon, there are no deadlines.

countryCode = geoIP->lookup(hostAddr);
if (!countryCode.isEmpty())
{
countryCode = countryCode.toLower();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When hovering over the flag in the GUI, N/A appears briefly and then disappears.

The "N/A" part is because of this.
The duration of the tooltip appears to be affected by Refresh interval in advanced settings or when some item in the toolbar is updated e.g. DHT nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GUI GUI-related issues/changes WebUI WebUI-related issues/changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants