-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSongLoader.cpp
More file actions
51 lines (42 loc) · 1.65 KB
/
SongLoader.cpp
File metadata and controls
51 lines (42 loc) · 1.65 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
#include "SongLoader.h"
#include <QStandardPaths>
#include <QDir>
#include <QFile>
#include <QTextStream>
SongLoader::SongLoader(QObject* parent) : QObject(parent) {}
QVariantList SongLoader::loadSongs() {
QVariantList songs;
QString docPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
QDir rootDir(docPath + "/PhiTone Files");
if (!rootDir.exists()) {
rootDir.mkpath(".");
}
for (const QString& entry : rootDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
QDir songDir(rootDir.absoluteFilePath(entry));
QFile infoFile(songDir.absoluteFilePath("info.txt"));
if (infoFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&infoFile);
QVariantMap songInfo;
while (!in.atEnd()) {
QString line = in.readLine().trimmed();
if (line.isEmpty() || line.startsWith("#"))
continue;
const int sepIndex = line.indexOf(':');
if (sepIndex > 0) {
QString key = line.left(sepIndex).trimmed();
QString value = line.mid(sepIndex + 1).trimmed();
songInfo.insert(key, value);
}
}
if (!songInfo.isEmpty()) {
if (songInfo.contains("Picture")) {
QString picName = songInfo["Picture"].toString();
QString picFullPath = songDir.absoluteFilePath(picName);
songInfo["Picture"] = "file://" + picFullPath;
}
songs.append(songInfo);
}
}
}
return songs;
}