FileSystemModel.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/LexicalPath.h>
  8. #include <AK/NumberFormat.h>
  9. #include <AK/QuickSort.h>
  10. #include <AK/StringBuilder.h>
  11. #include <LibCore/DirIterator.h>
  12. #include <LibCore/File.h>
  13. #include <LibCore/StandardPaths.h>
  14. #include <LibGUI/FileIconProvider.h>
  15. #include <LibGUI/FileSystemModel.h>
  16. #include <LibGUI/Painter.h>
  17. #include <LibGfx/Bitmap.h>
  18. #include <LibThreading/BackgroundAction.h>
  19. #include <grp.h>
  20. #include <pwd.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <sys/stat.h>
  24. #include <unistd.h>
  25. namespace GUI {
  26. ModelIndex FileSystemModel::Node::index(int column) const
  27. {
  28. if (!parent)
  29. return {};
  30. for (size_t row = 0; row < parent->children.size(); ++row) {
  31. if (&parent->children[row] == this)
  32. return m_model.create_index(row, column, const_cast<Node*>(this));
  33. }
  34. VERIFY_NOT_REACHED();
  35. }
  36. bool FileSystemModel::Node::fetch_data(const String& full_path, bool is_root)
  37. {
  38. struct stat st;
  39. int rc;
  40. if (is_root)
  41. rc = stat(full_path.characters(), &st);
  42. else
  43. rc = lstat(full_path.characters(), &st);
  44. if (rc < 0) {
  45. m_error = errno;
  46. perror("stat/lstat");
  47. return false;
  48. }
  49. size = st.st_size;
  50. mode = st.st_mode;
  51. uid = st.st_uid;
  52. gid = st.st_gid;
  53. inode = st.st_ino;
  54. mtime = st.st_mtime;
  55. if (S_ISLNK(mode)) {
  56. symlink_target = Core::File::read_link(full_path);
  57. if (symlink_target.is_null())
  58. perror("readlink");
  59. }
  60. if (S_ISDIR(mode)) {
  61. is_accessible_directory = access(full_path.characters(), R_OK | X_OK) == 0;
  62. }
  63. return true;
  64. }
  65. void FileSystemModel::Node::traverse_if_needed()
  66. {
  67. if (!is_directory() || has_traversed)
  68. return;
  69. has_traversed = true;
  70. if (m_parent_of_root) {
  71. auto root = adopt_own(*new Node(m_model));
  72. root->fetch_data("/", true);
  73. root->name = "/";
  74. root->parent = this;
  75. children.append(move(root));
  76. return;
  77. }
  78. total_size = 0;
  79. auto full_path = this->full_path();
  80. Core::DirIterator di(full_path, m_model.should_show_dotfiles() ? Core::DirIterator::SkipParentAndBaseDir : Core::DirIterator::SkipDots);
  81. if (di.has_error()) {
  82. m_error = di.error();
  83. warnln("DirIterator: {}", di.error_string());
  84. return;
  85. }
  86. Vector<String> child_names;
  87. while (di.has_next()) {
  88. child_names.append(di.next_path());
  89. }
  90. quick_sort(child_names);
  91. NonnullOwnPtrVector<Node> directory_children;
  92. NonnullOwnPtrVector<Node> file_children;
  93. for (auto& child_name : child_names) {
  94. String child_path = String::formatted("{}/{}", full_path, child_name);
  95. auto child = adopt_own(*new Node(m_model));
  96. bool ok = child->fetch_data(child_path, false);
  97. if (!ok)
  98. continue;
  99. if (m_model.m_mode == DirectoriesOnly && !S_ISDIR(child->mode))
  100. continue;
  101. child->name = child_name;
  102. child->parent = this;
  103. total_size += child->size;
  104. if (S_ISDIR(child->mode))
  105. directory_children.append(move(child));
  106. else
  107. file_children.append(move(child));
  108. }
  109. children.extend(move(directory_children));
  110. children.extend(move(file_children));
  111. if (!m_model.m_file_watcher->is_watching(full_path)) {
  112. // We are not already watching this file, watch it
  113. auto result = m_model.m_file_watcher->add_watch(full_path,
  114. Core::FileWatcherEvent::Type::MetadataModified
  115. | Core::FileWatcherEvent::Type::ChildCreated
  116. | Core::FileWatcherEvent::Type::ChildDeleted
  117. | Core::FileWatcherEvent::Type::Deleted);
  118. if (result.is_error()) {
  119. dbgln("Couldn't watch '{}': {}", full_path, result.error());
  120. } else if (result.value() == false) {
  121. dbgln("Couldn't watch '{}', probably already watching", full_path);
  122. }
  123. }
  124. }
  125. void FileSystemModel::Node::reify_if_needed()
  126. {
  127. traverse_if_needed();
  128. if (mode != 0)
  129. return;
  130. fetch_data(full_path(), parent == nullptr || parent->m_parent_of_root);
  131. }
  132. bool FileSystemModel::Node::is_symlink_to_directory() const
  133. {
  134. if (!S_ISLNK(mode))
  135. return false;
  136. struct stat st;
  137. if (lstat(symlink_target.characters(), &st) < 0)
  138. return false;
  139. return S_ISDIR(st.st_mode);
  140. }
  141. String FileSystemModel::Node::full_path() const
  142. {
  143. Vector<String, 32> lineage;
  144. for (auto* ancestor = parent; ancestor; ancestor = ancestor->parent) {
  145. lineage.append(ancestor->name);
  146. }
  147. StringBuilder builder;
  148. builder.append(m_model.root_path());
  149. for (int i = lineage.size() - 1; i >= 0; --i) {
  150. builder.append('/');
  151. builder.append(lineage[i]);
  152. }
  153. builder.append('/');
  154. builder.append(name);
  155. return LexicalPath::canonicalized_path(builder.to_string());
  156. }
  157. ModelIndex FileSystemModel::index(String path, int column) const
  158. {
  159. Node const* node = node_for_path(move(path));
  160. if (node != nullptr) {
  161. return node->index(column);
  162. }
  163. return {};
  164. }
  165. FileSystemModel::Node const* FileSystemModel::node_for_path(String const& path) const
  166. {
  167. String resolved_path;
  168. if (path == m_root_path)
  169. resolved_path = "/";
  170. else if (!m_root_path.is_empty() && path.starts_with(m_root_path))
  171. resolved_path = LexicalPath::relative_path(path, m_root_path);
  172. else
  173. resolved_path = path;
  174. LexicalPath lexical_path(resolved_path);
  175. const Node* node = m_root->m_parent_of_root ? &m_root->children.first() : m_root;
  176. if (lexical_path.string() == "/")
  177. return node;
  178. auto& parts = lexical_path.parts_view();
  179. for (size_t i = 0; i < parts.size(); ++i) {
  180. auto& part = parts[i];
  181. bool found = false;
  182. for (auto& child : node->children) {
  183. if (child.name == part) {
  184. const_cast<Node&>(child).reify_if_needed();
  185. node = &child;
  186. found = true;
  187. if (i == parts.size() - 1)
  188. return node;
  189. break;
  190. }
  191. }
  192. if (!found)
  193. return nullptr;
  194. }
  195. return nullptr;
  196. }
  197. String FileSystemModel::full_path(const ModelIndex& index) const
  198. {
  199. auto& node = this->node(index);
  200. const_cast<Node&>(node).reify_if_needed();
  201. return node.full_path();
  202. }
  203. FileSystemModel::FileSystemModel(String root_path, Mode mode)
  204. : m_root_path(LexicalPath::canonicalized_path(move(root_path)))
  205. , m_mode(mode)
  206. {
  207. setpwent();
  208. while (auto* passwd = getpwent())
  209. m_user_names.set(passwd->pw_uid, passwd->pw_name);
  210. endpwent();
  211. setgrent();
  212. while (auto* group = getgrent())
  213. m_group_names.set(group->gr_gid, group->gr_name);
  214. endgrent();
  215. auto result = Core::FileWatcher::create();
  216. if (result.is_error()) {
  217. dbgln("{}", result.error());
  218. VERIFY_NOT_REACHED();
  219. }
  220. m_file_watcher = result.release_value();
  221. m_file_watcher->on_change = [this](Core::FileWatcherEvent const& event) {
  222. Node const* maybe_node = node_for_path(event.event_path);
  223. if (maybe_node == nullptr) {
  224. dbgln("Received event at \"{}\" but we don't have that node", event.event_path);
  225. return;
  226. }
  227. auto& node = *const_cast<Node*>(maybe_node);
  228. dbgln("Event at \"{}\" on Node {}: {}", node.full_path(), &node, event);
  229. // FIXME: Your time is coming, un-granular updates.
  230. auto refresh_node = [](Node& node) {
  231. node.has_traversed = false;
  232. node.mode = 0;
  233. node.children.clear();
  234. node.reify_if_needed();
  235. };
  236. if (event.type == Core::FileWatcherEvent::Type::Deleted) {
  237. auto canonical_event_path = LexicalPath::canonicalized_path(event.event_path);
  238. if (m_root_path.starts_with(canonical_event_path)) {
  239. // Deleted directory contains our root, so navigate to our nearest parent.
  240. auto new_path = LexicalPath(m_root_path).parent();
  241. while (!Core::File::is_directory(new_path.string()))
  242. new_path = new_path.parent();
  243. set_root_path(new_path.string());
  244. } else if (node.parent) {
  245. refresh_node(*node.parent);
  246. }
  247. } else {
  248. refresh_node(node);
  249. }
  250. did_update();
  251. };
  252. invalidate();
  253. }
  254. FileSystemModel::~FileSystemModel()
  255. {
  256. }
  257. String FileSystemModel::name_for_uid(uid_t uid) const
  258. {
  259. auto it = m_user_names.find(uid);
  260. if (it == m_user_names.end())
  261. return String::number(uid);
  262. return (*it).value;
  263. }
  264. String FileSystemModel::name_for_gid(gid_t gid) const
  265. {
  266. auto it = m_group_names.find(gid);
  267. if (it == m_group_names.end())
  268. return String::number(gid);
  269. return (*it).value;
  270. }
  271. static String permission_string(mode_t mode)
  272. {
  273. StringBuilder builder;
  274. if (S_ISDIR(mode))
  275. builder.append("d");
  276. else if (S_ISLNK(mode))
  277. builder.append("l");
  278. else if (S_ISBLK(mode))
  279. builder.append("b");
  280. else if (S_ISCHR(mode))
  281. builder.append("c");
  282. else if (S_ISFIFO(mode))
  283. builder.append("f");
  284. else if (S_ISSOCK(mode))
  285. builder.append("s");
  286. else if (S_ISREG(mode))
  287. builder.append("-");
  288. else
  289. builder.append("?");
  290. builder.append(mode & S_IRUSR ? 'r' : '-');
  291. builder.append(mode & S_IWUSR ? 'w' : '-');
  292. builder.append(mode & S_ISUID ? 's' : (mode & S_IXUSR ? 'x' : '-'));
  293. builder.append(mode & S_IRGRP ? 'r' : '-');
  294. builder.append(mode & S_IWGRP ? 'w' : '-');
  295. builder.append(mode & S_ISGID ? 's' : (mode & S_IXGRP ? 'x' : '-'));
  296. builder.append(mode & S_IROTH ? 'r' : '-');
  297. builder.append(mode & S_IWOTH ? 'w' : '-');
  298. if (mode & S_ISVTX)
  299. builder.append('t');
  300. else
  301. builder.append(mode & S_IXOTH ? 'x' : '-');
  302. return builder.to_string();
  303. }
  304. void FileSystemModel::Node::set_selected(bool selected)
  305. {
  306. if (m_selected == selected)
  307. return;
  308. m_selected = selected;
  309. }
  310. void FileSystemModel::update_node_on_selection(const ModelIndex& index, const bool selected)
  311. {
  312. Node& node = const_cast<Node&>(this->node(index));
  313. node.set_selected(selected);
  314. }
  315. void FileSystemModel::set_root_path(String root_path)
  316. {
  317. if (root_path.is_null())
  318. m_root_path = {};
  319. else
  320. m_root_path = LexicalPath::canonicalized_path(move(root_path));
  321. invalidate();
  322. if (m_root->has_error()) {
  323. if (on_directory_change_error)
  324. on_directory_change_error(m_root->error(), m_root->error_string());
  325. } else if (on_complete) {
  326. on_complete();
  327. }
  328. }
  329. void FileSystemModel::invalidate()
  330. {
  331. m_root = adopt_own(*new Node(*this));
  332. if (m_root_path.is_null())
  333. m_root->m_parent_of_root = true;
  334. m_root->reify_if_needed();
  335. Model::invalidate();
  336. }
  337. int FileSystemModel::row_count(const ModelIndex& index) const
  338. {
  339. Node& node = const_cast<Node&>(this->node(index));
  340. node.reify_if_needed();
  341. if (node.is_directory())
  342. return node.children.size();
  343. return 0;
  344. }
  345. const FileSystemModel::Node& FileSystemModel::node(const ModelIndex& index) const
  346. {
  347. if (!index.is_valid())
  348. return *m_root;
  349. VERIFY(index.internal_data());
  350. return *(Node*)index.internal_data();
  351. }
  352. ModelIndex FileSystemModel::index(int row, int column, const ModelIndex& parent) const
  353. {
  354. if (row < 0 || column < 0)
  355. return {};
  356. auto& node = this->node(parent);
  357. const_cast<Node&>(node).reify_if_needed();
  358. if (static_cast<size_t>(row) >= node.children.size())
  359. return {};
  360. return create_index(row, column, &node.children[row]);
  361. }
  362. ModelIndex FileSystemModel::parent_index(const ModelIndex& index) const
  363. {
  364. if (!index.is_valid())
  365. return {};
  366. auto& node = this->node(index);
  367. if (!node.parent) {
  368. VERIFY(&node == m_root);
  369. return {};
  370. }
  371. return node.parent->index(index.column());
  372. }
  373. Variant FileSystemModel::data(const ModelIndex& index, ModelRole role) const
  374. {
  375. VERIFY(index.is_valid());
  376. if (role == ModelRole::TextAlignment) {
  377. switch (index.column()) {
  378. case Column::Icon:
  379. return Gfx::TextAlignment::Center;
  380. case Column::Size:
  381. case Column::Inode:
  382. return Gfx::TextAlignment::CenterRight;
  383. case Column::Name:
  384. case Column::Owner:
  385. case Column::Group:
  386. case Column::ModificationTime:
  387. case Column::Permissions:
  388. case Column::SymlinkTarget:
  389. return Gfx::TextAlignment::CenterLeft;
  390. default:
  391. VERIFY_NOT_REACHED();
  392. }
  393. }
  394. auto& node = this->node(index);
  395. if (role == ModelRole::Custom) {
  396. // For GUI::FileSystemModel, custom role means the full path.
  397. VERIFY(index.column() == Column::Name);
  398. return node.full_path();
  399. }
  400. if (role == ModelRole::MimeData) {
  401. if (index.column() == Column::Name)
  402. return URL::create_with_file_scheme(node.full_path()).serialize();
  403. return {};
  404. }
  405. if (role == ModelRole::Sort) {
  406. switch (index.column()) {
  407. case Column::Icon:
  408. return node.is_directory() ? 0 : 1;
  409. case Column::Name:
  410. // NOTE: The children of a Node are grouped by directory-or-file and then sorted alphabetically.
  411. // Hence, the sort value for the name column is simply the index row. :^)
  412. return index.row();
  413. case Column::Size:
  414. return (int)node.size;
  415. case Column::Owner:
  416. return name_for_uid(node.uid);
  417. case Column::Group:
  418. return name_for_gid(node.gid);
  419. case Column::Permissions:
  420. return permission_string(node.mode);
  421. case Column::ModificationTime:
  422. return node.mtime;
  423. case Column::Inode:
  424. return (int)node.inode;
  425. case Column::SymlinkTarget:
  426. return node.symlink_target;
  427. }
  428. VERIFY_NOT_REACHED();
  429. }
  430. if (role == ModelRole::Display) {
  431. switch (index.column()) {
  432. case Column::Icon:
  433. return icon_for(node);
  434. case Column::Name:
  435. return node.name;
  436. case Column::Size:
  437. return human_readable_size(node.size);
  438. case Column::Owner:
  439. return name_for_uid(node.uid);
  440. case Column::Group:
  441. return name_for_gid(node.gid);
  442. case Column::Permissions:
  443. return permission_string(node.mode);
  444. case Column::ModificationTime:
  445. return timestamp_string(node.mtime);
  446. case Column::Inode:
  447. return (int)node.inode;
  448. case Column::SymlinkTarget:
  449. return node.symlink_target;
  450. }
  451. }
  452. if (role == ModelRole::Icon) {
  453. return icon_for(node);
  454. }
  455. if (role == ModelRole::IconOpacity) {
  456. if (node.name.starts_with('.'))
  457. return 0.5f;
  458. return {};
  459. }
  460. return {};
  461. }
  462. Icon FileSystemModel::icon_for(const Node& node) const
  463. {
  464. if (node.full_path() == "/")
  465. return FileIconProvider::icon_for_path("/");
  466. if (Gfx::Bitmap::is_path_a_supported_image_format(node.name)) {
  467. if (!node.thumbnail) {
  468. if (!const_cast<FileSystemModel*>(this)->fetch_thumbnail_for(node))
  469. return FileIconProvider::filetype_image_icon();
  470. }
  471. return GUI::Icon(FileIconProvider::filetype_image_icon().bitmap_for_size(16), *node.thumbnail);
  472. }
  473. if (node.is_directory()) {
  474. if (node.full_path() == Core::StandardPaths::home_directory()) {
  475. if (node.is_selected())
  476. return FileIconProvider::home_directory_open_icon();
  477. return FileIconProvider::home_directory_icon();
  478. }
  479. if (node.full_path() == Core::StandardPaths::desktop_directory())
  480. return FileIconProvider::desktop_directory_icon();
  481. if (node.is_selected() && node.is_accessible_directory)
  482. return FileIconProvider::directory_open_icon();
  483. }
  484. return FileIconProvider::icon_for_path(node.full_path(), node.mode);
  485. }
  486. static HashMap<String, RefPtr<Gfx::Bitmap>> s_thumbnail_cache;
  487. static RefPtr<Gfx::Bitmap> render_thumbnail(const StringView& path)
  488. {
  489. auto png_bitmap = Gfx::Bitmap::try_load_from_file(path);
  490. if (!png_bitmap)
  491. return nullptr;
  492. double scale = min(32 / (double)png_bitmap->width(), 32 / (double)png_bitmap->height());
  493. auto thumbnail = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { 32, 32 });
  494. Gfx::IntRect destination = Gfx::IntRect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale));
  495. destination.center_within(thumbnail->rect());
  496. Painter painter(*thumbnail);
  497. painter.draw_scaled_bitmap(destination, *png_bitmap, png_bitmap->rect());
  498. return thumbnail;
  499. }
  500. bool FileSystemModel::fetch_thumbnail_for(const Node& node)
  501. {
  502. // See if we already have the thumbnail
  503. // we're looking for in the cache.
  504. auto path = node.full_path();
  505. auto it = s_thumbnail_cache.find(path);
  506. if (it != s_thumbnail_cache.end()) {
  507. if (!(*it).value)
  508. return false;
  509. node.thumbnail = (*it).value;
  510. return true;
  511. }
  512. // Otherwise, arrange to render the thumbnail
  513. // in background and make it available later.
  514. s_thumbnail_cache.set(path, nullptr);
  515. m_thumbnail_progress_total++;
  516. auto weak_this = make_weak_ptr();
  517. Threading::BackgroundAction<RefPtr<Gfx::Bitmap>>::create(
  518. [path](auto&) {
  519. return render_thumbnail(path);
  520. },
  521. [this, path, weak_this](auto thumbnail) {
  522. s_thumbnail_cache.set(path, move(thumbnail));
  523. // The model was destroyed, no need to update
  524. // progress or call any event handlers.
  525. if (weak_this.is_null())
  526. return;
  527. m_thumbnail_progress++;
  528. if (on_thumbnail_progress)
  529. on_thumbnail_progress(m_thumbnail_progress, m_thumbnail_progress_total);
  530. if (m_thumbnail_progress == m_thumbnail_progress_total) {
  531. m_thumbnail_progress = 0;
  532. m_thumbnail_progress_total = 0;
  533. }
  534. did_update(UpdateFlag::DontInvalidateIndices);
  535. });
  536. return false;
  537. }
  538. int FileSystemModel::column_count(const ModelIndex&) const
  539. {
  540. return Column::__Count;
  541. }
  542. String FileSystemModel::column_name(int column) const
  543. {
  544. switch (column) {
  545. case Column::Icon:
  546. return "";
  547. case Column::Name:
  548. return "Name";
  549. case Column::Size:
  550. return "Size";
  551. case Column::Owner:
  552. return "Owner";
  553. case Column::Group:
  554. return "Group";
  555. case Column::Permissions:
  556. return "Mode";
  557. case Column::ModificationTime:
  558. return "Modified";
  559. case Column::Inode:
  560. return "Inode";
  561. case Column::SymlinkTarget:
  562. return "Symlink target";
  563. }
  564. VERIFY_NOT_REACHED();
  565. }
  566. bool FileSystemModel::accepts_drag(const ModelIndex& index, const Vector<String>& mime_types) const
  567. {
  568. if (!index.is_valid())
  569. return false;
  570. if (!mime_types.contains_slow("text/uri-list"))
  571. return false;
  572. auto& node = this->node(index);
  573. return node.is_directory();
  574. }
  575. void FileSystemModel::set_should_show_dotfiles(bool show)
  576. {
  577. if (m_should_show_dotfiles == show)
  578. return;
  579. m_should_show_dotfiles = show;
  580. // FIXME: add a way to granularly update in this case.
  581. invalidate();
  582. }
  583. bool FileSystemModel::is_editable(const ModelIndex& index) const
  584. {
  585. if (!index.is_valid())
  586. return false;
  587. return index.column() == Column::Name;
  588. }
  589. void FileSystemModel::set_data(const ModelIndex& index, const Variant& data)
  590. {
  591. VERIFY(is_editable(index));
  592. Node& node = const_cast<Node&>(this->node(index));
  593. auto dirname = LexicalPath::dirname(node.full_path());
  594. auto new_full_path = String::formatted("{}/{}", dirname, data.to_string());
  595. int rc = rename(node.full_path().characters(), new_full_path.characters());
  596. if (rc < 0) {
  597. if (on_rename_error)
  598. on_rename_error(errno, strerror(errno));
  599. }
  600. }
  601. Vector<ModelIndex, 1> FileSystemModel::matches(const StringView& searching, unsigned flags, const ModelIndex& index)
  602. {
  603. Node& node = const_cast<Node&>(this->node(index));
  604. node.reify_if_needed();
  605. Vector<ModelIndex, 1> found_indices;
  606. for (auto& child : node.children) {
  607. if (string_matches(child.name, searching, flags)) {
  608. const_cast<Node&>(child).reify_if_needed();
  609. found_indices.append(child.index(Column::Name));
  610. if (flags & FirstMatchOnly)
  611. break;
  612. }
  613. }
  614. return found_indices;
  615. }
  616. }