Skip to content

feat(gui): port CFriendListCtrl to CMuleVirtualDataViewCtrl (#180, #801) - #830

Merged
got3nks merged 3 commits into
amule-org:masterfrom
LSalami:friend-dataview-port
Aug 7, 2026
Merged

feat(gui): port CFriendListCtrl to CMuleVirtualDataViewCtrl (#180, #801)#830
got3nks merged 3 commits into
amule-org:masterfrom
LSalami:friend-dataview-port

Conversation

@LSalami

@LSalami LSalami commented Aug 6, 2026

Copy link
Copy Markdown

Context

Continues #180/#801's wxListCtrl -> wxDataViewCtrl migration, on top of the shared base CMuleDataViewCtrl/CMuleVirtualDataViewCtrl from #811. Search (#796) and Servers (#807, absorbed into #811) are done; this ports CFriendListCtrl.

Picked after reading all the remaining candidates (Friends, FileDetail, Downloads, SharedFiles, Sources/Peers) directly rather than by line count:

  • No CBarShader rendering — unlike Downloads/SharedFiles/Sources-Peers, which additionally need a wxDataViewCustomRenderer that doesn't exist anywhere in the tree yet (confirmed by grep), so those are correctly a separate, dedicated piece of work.
  • Already pointer-identity addressed: UpdateFriend(CFriend*)/RemoveFriend(CFriend*) map directly onto AddItemData/RefreshItemData/RemoveItemData, the exact shape CServerListCtrl already uses.
  • Tiny blast radius: only ChatWnd.cpp (2 call sites) and muuli_wdr.cpp (construction) reference the class externally.

CFileDetailListCtrl looked smaller by line count but its caller (FileDetailDialog.cpp) drives it with raw position-indexed CRUD (FindItem by name, SetItem by column index, DeleteItem) plus a pre-existing duplicate-type quirk (two unrelated SourcenameItem structs relying on compatible memory layout) — porting it cleanly means refactoring the caller too, which felt like its own separate pass rather than "the small one to bundle in."

What changed

src/ServerListCtrl.h/.cpp (current, post-#811) is the template mirrored here: same AppendTextColumn/AppendSpacerColumn/AssociateVirtualModel/LoadColumnSettings/InitColumnState ctor sequence, same GetItemColumnText/GetItemAttr/CompareItemData/OnListKey hook shape, same EVT_DATAVIEW_ITEM_CONTEXT_MENU/EVT_DATAVIEW_ITEM_ACTIVATED event handling using GetSelectedItemData().

Public API (UpdateFriend, RemoveFriend) and the constructor signature are unchanged, so ChatWnd.cpp and muuli_wdr.cpp needed no edits at all.

Two small behavioural deltas, both flagged in the commit message:

  • Added a real CompareItemData so header-click sort now actually works — the old list never called SetSortFunc at all.
  • GetItemAttr replaces the old SetItemTextColour call with the same visible result (blue for linked friends, default text colour otherwise).

Verification

  • Builds clean.
  • clang-format v18 (pinned Docker image) applied.
  • clang-tidy Tier-1 (whole-tree) and Tier-2 (changed-lines, .clang-tidy-new-code) both clean via a local CI replica — Tier-2 caught one real modernize-use-nullptr hit, fixed.
  • Grepped ChatWnd.cpp/.h and muuli_wdr.cpp to confirm no other call sites exist.
  • Not yet verified interactively: sort behaviour, right-click menu states (empty selection / single / multi), Delete-key removal with confirmation, double-click to open a chat session, and a VoiceOver spot-check confirming rows are now announced — same as feat(search): port CSearchListCtrl to wxDataViewCtrl #796/feat(gui): port CServerListCtrl to wxDataViewCtrl (#180, #801) #807, happy to have this checked before or after merge.

…g#180, amule-org#801)

Continues the wxListCtrl -> wxDataViewCtrl migration (amule-org#180/amule-org#801) onto
the shared base PR amule-org#811 extracted after the Servers port (amule-org#807, now
absorbed into amule-org#811). CFriendListCtrl was picked next after reading all
the remaining candidates directly rather than going by line count
alone: it has no CBarShader rendering (unlike Downloads/SharedFiles/
Sources-Peers, which additionally need a still-nonexistent
wxDataViewCustomRenderer), it's already pointer-identity addressed
(UpdateFriend(CFriend*)/RemoveFriend(CFriend*) map directly onto
AddItemData/RefreshItemData/RemoveItemData), and its blast radius is
tiny (ChatWnd.cpp, muuli_wdr.cpp construction only).

CFileDetailListCtrl looked smaller by line count but its caller
(FileDetailDialog.cpp) drives it with raw position-indexed CRUD
(FindItem by name, SetItem by column index, DeleteItem) plus a
pre-existing duplicate-type quirk (two unrelated SourcenameItem
structs relying on compatible layout) -- porting it cleanly means
refactoring the caller too, which is a separate, more invasive piece
of work than this one.

CServerListCtrl (current, post-amule-org#811) is the template mirrored here:
same AppendTextColumn/AppendSpacerColumn/AssociateVirtualModel/
LoadColumnSettings/InitColumnState ctor sequence, same GetItemColumnText/
GetItemAttr/CompareItemData/OnListKey hook shape. Public API
(UpdateFriend, RemoveFriend) and the constructor signature are
unchanged, so ChatWnd.cpp and muuli_wdr.cpp needed no edits.

Notable deltas from the pre-port behaviour: added a real CompareItemData
so header-click sort now works (the old list never called SetSortFunc
at all); GetItemAttr replaces the old SetItemTextColour call with the
same visible result (blue for linked friends, default text colour
otherwise).

Verified: builds clean; clang-format v18 (pinned Docker image) applied;
clang-tidy Tier-1 (whole-tree) and Tier-2 (changed-lines,
.clang-tidy-new-code) both clean via the ~/aMuleTest/ci-local replica
-- Tier-2 caught one real modernize-use-nullptr hit, fixed. Grepped
ChatWnd.cpp/.h and muuli_wdr.cpp to confirm no other call sites exist.
Interactive verification (sort, right-click menu states, Delete-key
removal, chat-session activation, VoiceOver) left for manual testing
per project convention, same as PR amule-org#796/amule-org#807.
@got3nks

got3nks commented Aug 6, 2026

Copy link
Copy Markdown

Verified locally against origin/master: hook signatures, the ctor sequence, no remaining call sites beyond ChatWnd.cpp/muuli_wdr.cpp, and CI green across all 15 checks.

1. OnItemActivated() casts a row index to CFriend * — double-click crashes.

CMuleVirtualDataViewCtrl is backed by a wxDataViewIndexListModel, so a wxDataViewItem's ID is the row number + 1, not the item data — the "item identity is not row identity" note at the top of MuleVirtualDataViewCtrl.h. Probed against wx 3.3:

row 0 -> GetID()=0x1  GetRow(item)=0
row 1 -> GetID()=0x2  GetRow(item)=1

So reinterpret_cast<CFriend *>(event.GetItem().GetID()) gives 0x1 for the first row, the nullptr guard passes it through, and CChatWnd::StartSession() dereferences it immediately (friend_client->GetName()). Every double-click or Enter on a friend segfaults. This is why CServerListCtrl::OnItemActivated() resolves through GetSelectedItemData() instead.

Fix:

void CFriendListCtrl::OnItemActivated(wxDataViewEvent &event)
{
	// Open a session with the activated row alone, whatever else was selected.
	if (event.GetItem().IsOk()) {
		UnselectAll();
		Select(event.GetItem());
	}

	const std::vector<wxUIntPtr> selected = GetSelectedItemData();
	if (selected.empty()) {
		return;
	}

	theApp->amuledlg->m_chatwnd->StartSession(reinterpret_cast<CFriend *>(selected.front()));
}

2. UpdateFriend()'s comment promises a re-sort that can't happen.

The comment says the refresh is "a repaint (plus a re-sort if the name changed under a name-sorted list)", but RefreshItemData() only schedules a reorder when IsLiveSortColumn() returns true, and the base default is false. In amulegui the name does arrive after insertion — CFriendListRem::ProcessItemUpdate() writes tag->Name(Friend->m_strName) and then notifies — so a renamed friend keeps its old position until something else re-sorts the list.

Fix: the name is the only sortable column here, so bool IsLiveSortColumn() const override { return true; } — or drop the parenthetical from the comment.

3. Nit: static_cast<int>(GetSelectedItemsCount())wxDataViewCtrl::GetSelectedItemsCount() already returns int, so the cast is a no-op.

One behavioural note for the interactive pass: right-clicking empty space used to get -1 from CheckSelection() and offer only "Add a friend"; now the existing selection survives and its entries are offered. That matches CServerListCtrl post-#811, so it looks intentional — worth confirming while testing.

LSalami added 2 commits August 6, 2026 18:04
got3nks's review on amule-org#830 found a real crash: OnItemActivated() cast
event.GetItem()'s ID directly to CFriend* on the assumption it was the
item's data pointer, but CMuleVirtualDataViewCtrl's row-addressed
model returns the row index (+1) as that ID -- the "item identity is
not row identity" case MuleVirtualDataViewCtrl.h itself documents.
Every double-click/Enter on a friend dereferenced a bogus pointer.
Fixed by selecting the activated row and resolving it through
GetSelectedItemData(), matching CServerListCtrl::OnItemActivated.

Also from the same review: IsLiveSortColumn() now returns true, since
the name (the only sortable column) can change after a friend is
already listed and the UpdateFriend() comment claimed a re-sort that
the base's default-false hook never actually triggered; and dropped a
no-op static_cast<int>() around a call that already returns int.

Verified: builds clean, clang-format v18 applied, clang-tidy Tier-2
(changed lines, .clang-tidy-new-code) clean via the local CI replica.
The previous run hit a GitHub Actions infrastructure outage (job not
acquired by any runner, "Failed to resolve action download info" /
"Service Unavailable" on clang-format, Translation checks, mingw-w64
Debug and clang-tidy Tier-1) unrelated to this branch's code -- every
job that did run passed. No admin rights to rerun the failed jobs
directly, so retriggering with an empty commit instead.
@got3nks

got3nks commented Aug 7, 2026

Copy link
Copy Markdown

Thanks @LSalami - all three review points addressed cleanly, and the double-click fix is exactly right.

Verified locally: builds clean with no warnings, and I checked the sort against the base specifically, since #832 landed after this branch was cut. That fix is entirely base-level, and this port inherits it correctly - the ctor sequence matches CServerListCtrl, and CompareItemData applies the direction modifier in the callee, which is where the base expects it. Had it not, descending sort would have silently done nothing.

Merging.

@got3nks
got3nks merged commit 34ff05b into amule-org:master Aug 7, 2026
14 checks passed
@LSalami
LSalami deleted the friend-dataview-port branch August 7, 2026 09:08
got3nks added a commit that referenced this pull request Aug 7, 2026
…#801) (#839)

* feat(gui): port CFileDetailListCtrl to CMuleVirtualDataViewCtrl (#180, #801)

Continues the wxListCtrl -> wxDataViewCtrl migration (#180/#801) onto
the shared base from #811, after Search (#796), Servers (#807/#811)
and Friends (#830). CFileDetailListCtrl was next because it has no
CBarShader rendering (unlike Downloads/SharedFiles/Sources-Peers,
which additionally need a still-nonexistent wxDataViewCustomRenderer).

Its caller, CFileDetailDialog::FillSourcenameList(), drove the old
list with raw position-indexed CRUD (FindItem by name, SetItemPtrData,
SetItem by column index, DeleteItem) rather than the pointer-identity
style CServerListCtrl/CFriendListCtrl already use, so porting the
control cleanly meant refactoring the caller too:

- CFileDetailDialog gained a std::map<wxString, SourcenameItem *>
  m_sourcenames member, replacing "search the list widget by name"
  with a map lookup. FillSourcenameList()'s reset/update/prune shape
  is otherwise unchanged, just re-keyed to the map and driven through
  the control's new AddSource/RefreshSource/RemoveSource API.
- OnBnClickedTakeOver()/OnListClickedTakeOver() resolve the selected
  row through GetSelectedItemData() (inherited from
  CMuleVirtualDataViewCtrl) instead of GetNextItem+GetItemText.
- The dialog's EVT_LIST_ITEM_ACTIVATED binding on IDC_LISTCTRLFILENAMES
  becomes EVT_DATAVIEW_ITEM_ACTIVATED; wxDataViewEvent is a
  wxNotifyEvent/wxCommandEvent descendant so it still propagates from
  the child control to the dialog-level handler the same way.
- Fixed a latent leak: nothing in ~CFileDetailDialog() freed the
  SourcenameItem objects still referenced by open rows -- only the
  "not a partfile" and "pruned to zero" paths in FillSourcenameList()
  ever deleted them. Now freed in the destructor via m_sourcenames.

CMuleDataViewCtrl always ORs in wxDV_MULTIPLE (no single-selection
mode exists on the shared base), but this list's "take over filename"
actions assume exactly one selection, same as the old list did (it
never actually requested wxLC_SINGLE_SEL either -- checked
muuli_wdr.cpp -- it enforced single-selection itself via OnSelect()
deselecting every other row). CFileDetailListCtrl::OnSelectionChanged()
does the equivalent: collapses to the just-clicked row whenever more
than one ends up selected.

Also deleted a vestigial nested SourcenameItem struct in
FileDetailListCtrl.h that duplicated (by accident of matching layout)
the real one in PartFile.h, and dropped a per-row background-colour
set that reproduced the default and carried its own "do we still need
this?" comment.

Verified: builds clean; clang-format v18 (pinned Docker image) applied;
clang-tidy Tier-1 (whole-tree) and Tier-2 (changed-lines,
.clang-tidy-new-code) both clean via the ~/aMuleTest/ci-local replica.
Grepped for other CFileDetailListCtrl/IDC_LISTCTRLFILENAMES references
to confirm muuli_wdr.cpp's construction call needed no changes.
Interactive verification (source list populate/re-tally, take-over via
button and double-click, single-selection enforcement, sort, VoiceOver)
left for manual testing per project convention.

* fix(gui): keep the source-name list sorted, and drop rows before freeing them

Review follow-up to the port.

FillSourcenameList() zeroes every count and then rewrites them in place, so
while it runs the list is not ordered by the column it is sorted on -- and
AddSource() places a new row with a binary search, which needs that ordering
to hold. An insertion therefore leaves rows in arbitrary positions, and the
repair has to happen here, exactly as the pre-port code did.

Only on insertion, though. A count that merely changed is what the live-sort
preference governs: RefreshSource() re-sorts when it is on, and when it is
off the row is meant to stay put rather than move under the user. Sorting
unconditionally would quietly override that setting for this list.

The destructor and the not-a-partfile path also freed the SourcenameItem
objects while the list control still held pointers to them. Nothing can
paint or sort in either window today -- both dialog call sites are stack
temporaries, so destruction is synchronous -- but that rests on wx's teardown
order rather than on anything guaranteed, and the base states the rule
plainly: it has to be told before the caller frees the item data. Both now
clear the rows first, as the prune loop already did.

* fix(gui): decide the source list's live re-sort per column

IsLiveSortColumn() answered true for every column, so a refresh tick
scheduled a re-sort even when the list was sorted by File Name -- a value
that never changes, since the name is the key each row was created under.

Answer per column instead, the shape CServerListCtrl already uses, so only a
sources-sorted list re-sorts on its own. The header comment already
described it this way; only the implementation did not.

* chore: drop a duplicated paragraph from the file header

FileDetailDialog.cpp carried the "Any parts of this program derived from
the xMule, lMule or eMule project" paragraph twice. It is the only file in
src/ that does, and the file is already being touched here.

---------

Co-authored-by: got3nks <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants