MCPcopy Create free account
hub / github.com/KDE/krusader / buildMenu

Method buildMenu

app/BookMan/krbookmarkhandler.cpp:381–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379}
380
381void KrBookmarkHandler::buildMenu(KrBookmark *parent, QMenu *menu, int depth)
382{
383 // add search bar widget to the top of the menu
384 if (depth == 0) {
385 menu->addAction(_quickSearchAction);
386 }
387
388 // run the loop twice, in order to put the folders on top. stupid but easy :-)
389 // note: this code drops the separators put there by the user
390 QListIterator<KrBookmark *> it(parent->children());
391 while (it.hasNext()) {
392 KrBookmark *bm = it.next();
393
394 if (!bm->isFolder())
395 continue;
396 auto *newMenu = new QMenu(menu);
397 newMenu->setIcon(Icon(bm->iconName()));
398 newMenu->setTitle(bm->text());
399 QAction *menuAction = menu->addMenu(newMenu);
400 QVariant v;
401 v.setValue(bm);
402 menuAction->setData(v);
403
404 buildMenu(bm, newMenu, depth + 1);
405 }
406
407 it.toFront();
408 while (it.hasNext()) {
409 KrBookmark *bm = it.next();
410 if (bm->isFolder())
411 continue;
412 if (bm->isSeparator()) {
413 menu->addSeparator();
414 continue;
415 }
416
417 QUrl urlToSet = bm->url();
418 if (!urlToSet.isEmpty() && urlToSet.isRelative()) {
419 // Make it possible that the url can be used later by Krusader.
420 // This avoids users seeing the effects described in the "Editing a local path in Bookmark
421 // Manager breaks a bookmark" bug report (https://bugs.kde.org/show_bug.cgi?id=393320),
422 // though it would be better to solve that upstream frameworks-kbookmarks bug
423 bm->setURL(QUrl::fromUserInput(urlToSet.toString(), QString(), QUrl::AssumeLocalFile));
424 }
425
426 menu->addAction(bm);
427 CONNECT_BM(bm);
428 }
429
430 if (depth == 0) {
431 KConfigGroup group(krConfig, "Private");
432 bool hasPopularURLs = group.readEntry("BM Popular URLs", true);
433 bool hasTrash = group.readEntry("BM Trash", true);
434 bool hasLan = group.readEntry("BM Lan", true);
435 bool hasVirtualFS = group.readEntry("BM Virtual FS", true);
436 bool hasJumpback = group.readEntry("BM Jumpback", true);
437
438 if (hasPopularURLs) {

Callers

nothing calls this directly

Calls 15

IconClass · 0.85
addActionMethod · 0.80
nextMethod · 0.80
isFolderMethod · 0.80
setIconMethod · 0.80
iconNameMethod · 0.80
setValueMethod · 0.80
setDataMethod · 0.80
isSeparatorMethod · 0.80
isEmptyMethod · 0.80
setURLMethod · 0.80
getMostPopularUrlsMethod · 0.80

Tested by

no test coverage detected