-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagfile.cpp
87 lines (69 loc) · 1.63 KB
/
tagfile.cpp
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
77
78
79
80
81
82
83
84
85
86
#include "tagfile.h"
#include <QDebug>
TagFile::TagFile(QString filePath)
: QObject() {
_filePath = filePath;
_name = filePath.split("/", QString::SkipEmptyParts).last();
if (getMimeType().name() == "inode/directory") {
_icon = QIcon(":icons/dir");
} else {
_icon = QIcon(":icons/file");
}
TagFile::newTagFile(this);
}
QString TagFile::getPath() {
return _filePath;
}
QMimeType TagFile::getMimeType() {
QMimeDatabase db;
QMimeType type = db.mimeTypeForFile(_filePath);
return type;
}
QString TagFile::getName() {
return _name;
}
QIcon TagFile::getIcon() {
return _icon;
}
QList<Tag *> *TagFile::getTags() {
return _parentTags;
}
/******
* Handshake with Tag so we can know for
* every file which tags contains the file
******/
void TagFile::addParentTag(Tag *tag) const {
_parentTags->append(tag);
}
void TagFile::removeParentTag(Tag *tag) {
_parentTags->removeOne(tag);
}
TagFile::~TagFile() {
TagFile::deleteTagFile(this);
delete _parentTags;
}
/******
* Static functions
*
* We keep track of created TagFile so each instance is unique
*
******/
QSet<TagFile *> *TagFile::instances = new QSet<TagFile *>;
void TagFile::newTagFile(TagFile *file) {
instances->insert(file);
}
void TagFile::deleteTagFile(TagFile *file) {
instances->remove(file);
}
TagFile *TagFile::find(QString path) {
// Searching for an existing file
for (TagFile *file : *instances) {
if (file->getPath() == path) {
return file;
}
}
return new TagFile(path);
}
QSet<TagFile *> *TagFile::getInstance() {
return instances;
}