summaryrefslogtreecommitdiff
path: root/src/qdirfiletree.cpp
blob: e80c71271ce2fd3e70a26f526e666ea10c748d7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "qdirfiletree.h"

#include <QDirIterator>

using namespace MOBase;

/**
 *
 */
std::shared_ptr<const QDirFileTree> QDirFileTree::makeTree(QDir directory) {
  return std::shared_ptr<const QDirFileTree>(new QDirFileTree(nullptr, directory));
}

/**
 *
 */
QDirFileTree::QDirFileTree(std::shared_ptr<const IFileTree> parent, QDir directory) : FileTreeEntry(parent, directory.dirName()), IFileTree(), qDir(directory) { }

/**
 * No mutable operations allowed.
 */
bool QDirFileTree::beforeReplace(IFileTree const* dstTree, FileTreeEntry const* destination, FileTreeEntry const* source) { return false; }
bool QDirFileTree::beforeInsert(IFileTree const* entry, FileTreeEntry const* name) { return false; }
bool QDirFileTree::beforeRemove(IFileTree const* entry, FileTreeEntry const* name) { return false; }
std::shared_ptr<FileTreeEntry> QDirFileTree::makeFile(std::shared_ptr<const IFileTree> parent, QString name) const { return nullptr; }
std::shared_ptr<IFileTree> QDirFileTree::makeDirectory(std::shared_ptr<const IFileTree> parent, QString name) const { return nullptr; }

bool QDirFileTree::doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const {
  auto infoList = qDir.entryInfoList(qDir.filter() | QDir::NoDotAndDotDot, QDir::Name | QDir::DirsFirst | QDir::IgnoreCase);
  for (auto& info : infoList) {
    if (info.isDir()) {
      entries.push_back(std::shared_ptr<QDirFileTree>(new QDirFileTree(parent, QDir(info.absoluteFilePath()))));
    }
    else {
      entries.push_back(createFileEntry(parent, info.fileName()));
    }
  }

  // Vector is already sorted:
  return true;
}

std::shared_ptr<IFileTree> QDirFileTree::doClone() const {
  return std::shared_ptr<QDirFileTree>(new QDirFileTree(nullptr, qDir));
}