-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaglist.cpp
More file actions
104 lines (83 loc) · 2.82 KB
/
taglist.cpp
File metadata and controls
104 lines (83 loc) · 2.82 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "taglist.h"
#include <QDebug>
TagList::TagList()
: QList<Tag *>()
{}
void TagList::fromXML(QXmlStreamReader *reader) {
Tag *currentTag;
TagFile *currentFile;
bool inFile = false;
while (!reader->atEnd()) {
reader->readNext();
if (reader->isWhitespace()) {
continue;
}
switch (reader->tokenType()) {
case QXmlStreamReader::StartElement:
if (reader->name() == "tag") {
QString name = reader->attributes().value("name").toString();
QStringList colorValues = reader->attributes().value("color")
.toString().split(" ");
QColor color(colorValues[0].toInt(), colorValues[1].toInt(),
colorValues[2].toInt(), colorValues[3].toInt());
currentTag = new Tag(name);
currentTag->setBulletColor(color);
} else if (reader->name() == "file") {
inFile = true;
}
break;
case QXmlStreamReader::EndElement:
if (reader->name() == "tag") {
this->append(currentTag);
currentTag = nullptr;
} else if (reader->name() == "file") {
currentTag->append(currentFile);
currentFile = nullptr;
inFile = false;
}
break;
case QXmlStreamReader::Characters:
if (inFile) {
QString path = reader->text().toString();
currentFile = TagFile::find(path);
}
break;
default:
break;
}
}
}
void TagList::toXML(QXmlStreamWriter *writer) {
writer->setAutoFormatting(true);
writer->writeStartDocument();
writer->writeStartElement("taglist");
for (Tag *tag : *this) {
QColor color = tag->getColor();
QString colorStr("%1 %2 %3 %4");
colorStr = colorStr.arg(color.red()).arg(color.green())
.arg(color.blue()).arg(color.alpha());
writer->writeStartElement("tag");
writer->writeAttribute("name", tag->getName());
writer->writeAttribute("color", colorStr);
for (TagFile *file : *tag) {
QString path = file->getPath();
writer->writeStartElement("file");
writer->writeCharacters(file->getPath());
writer->writeEndElement();
}
writer->writeEndElement();
}
writer->writeEndElement();
writer->writeEndDocument();
}
void TagList::init() {
Tag *tag = new Tag("Music");
tag->setBulletColor(QColor(252, 61, 57));
this->append(tag);
tag = new Tag("Film");
tag->setBulletColor(QColor(104, 216, 69));
this->append(tag);
tag = new Tag("Photos");
tag->setBulletColor(QColor(42, 174, 245));
this->append(tag);
}