-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilesystemmodel.cpp
More file actions
76 lines (63 loc) · 1.57 KB
/
filesystemmodel.cpp
File metadata and controls
76 lines (63 loc) · 1.57 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "filesystemmodel.h"
#include <filesystem>
void FileSystemModel::setConfiguration(Configuration configuration)
{
setRootDir(configuration.dir());
}
int FileSystemModel::count() const
{
return mListFilePathes.size();
}
std::string FileSystemModel::name(int index) const
{
return mListFilePathes.at(index);
}
int FileSystemModel::size(int index) const
{
return index;
}
bool FileSystemModel::isDir(int index) const
{
std::filesystem::path fsPath = mListFilePathes.at(index);
return std::filesystem::is_directory(fsPath);
}
void FileSystemModel::enter(int index)
{
enterDirectory(mListFilePathes.at(index));
}
void FileSystemModel::up()
{
if (mCurrentDir != mRootDir)
{
std::filesystem::path fsPath{mCurrentDir};
std::filesystem::path parentPath = fsPath.parent_path().string();
if (parentPath.string() != mRootDir)
{
enterDirectory(parentPath.string());
}
}
}
std::string FileSystemModel::rootDir() const
{
return mRootDir;
}
void FileSystemModel::setRootDir(const std::string &rootDir)
{
mRootDir = rootDir;
mCurrentDir = rootDir;
enterDirectory(mRootDir);
}
void FileSystemModel::enterDirectory(const std::string &path)
{
std::filesystem::path fsPath{path};
if (std::filesystem::is_directory(fsPath))
{
mListFilePathes.clear();
std::filesystem::path fsPath = path;
for(auto& entry: std::filesystem::directory_iterator(fsPath))
{
mListFilePathes.push_back(entry.path().string());
}
mCurrentDir = path;
}
}