Refactor Utils::Gui::openFolderSelect to use switch-case #16910

Open
opened 2026-02-22 03:31:36 -05:00 by deekerman · 4 comments
Owner

Originally created by @fkobi on GitHub (May 25, 2025).

Suggestion

Right now the title's function uses 5 ifs and one default behaviour:
github.com/qbittorrent/qBittorrent@6418033cc8/src/gui/utils.cpp (L182-L210)
Maybe it just grew overtime.

I think it is worth it to rewrite it using switch-case.
It improves readability (and efficiency).

Extra info

I am not sure if this is a feature but this is not a bug.
I would call it an improvement idea.

I came upon this by reading commit github.com/qbittorrent/qBittorrent@6418033cc8 from patch notes.

Originally created by @fkobi on GitHub (May 25, 2025). ### Suggestion Right now the title's function uses 5 `if`s and one default behaviour: https://github.com/qbittorrent/qBittorrent/blob/6418033cc8d4ec2f31679418cb480af498dafb2c/src/gui/utils.cpp#L182-L210 Maybe it just grew overtime. I think it is worth it to rewrite it using `switch-case`. It improves readability (and efficiency). ### Extra info I am not sure if this is a feature but this is not a bug. I would call it an improvement idea. I came upon this by reading commit https://github.com/qbittorrent/qBittorrent/commit/6418033cc8d4ec2f31679418cb480af498dafb2c from patch notes.
Author
Owner

@HanabishiRecca commented on GitHub (May 26, 2025):

I am not sure if this is a feature but this is not a bug.
I would call it an improvement idea.

PRs are welcome.

@HanabishiRecca commented on GitHub (May 26, 2025): > I am not sure if this is a feature but this is not a bug. > I would call it an improvement idea. PRs are welcome.
Author
Owner

@glassez commented on GitHub (May 26, 2025):

What are you guys talking about? It's C++. switch supports only integral types and enumerations.

@glassez commented on GitHub (May 26, 2025): What are you guys talking about? It's C++. `switch` supports only integral types and enumerations.
Author
Owner

@HanabishiRecca commented on GitHub (May 26, 2025):

That's why I said to send a PR. For the reporter to just try to implement it, instead of weird suggestions.
And maybe would come up with a better idea in process, who knows.

@HanabishiRecca commented on GitHub (May 26, 2025): That's why I said to send a PR. For the reporter to just try to implement it, instead of weird suggestions. And maybe would come up with a better idea in process, who knows.
Author
Owner

@fkobi commented on GitHub (May 26, 2025):

We are comparing output to a compile-time-known UTF strings -- I think enum can be used.

When I finally get some spare time I'll make a PR but it does not seem like that will happen soon.

@fkobi commented on GitHub (May 26, 2025): We are comparing `output` to a compile-time-known UTF strings -- I think `enum` can be used. When I finally get some spare time I'll make a PR but it does not seem like that will happen soon.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/qBittorrent#16910
No description provided.