-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
64 lines (54 loc) · 1.54 KB
/
Copy pathconfig.cpp
File metadata and controls
64 lines (54 loc) · 1.54 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
#include "config.h"
void Config::load()
{
QFile file(config_file);
if (!file.open(QIODevice::ReadOnly)) {
qWarning("Could not open config file.");
return;
}
QByteArray json_content = file.readAll();
QJsonDocument json = QJsonDocument::fromJson(json_content);
QJsonObject object = json.object();
this->m_recentAudioFile = QUrl::fromLocalFile(object["audio_file"].toString());
this->m_recentLrcFile = QUrl::fromLocalFile(object["lrc_file"].toString());
}
void Config::write()
{
QFile file(config_file);
if (!file.open(QIODevice::WriteOnly)) {
qWarning("Could not open config file.");
return;
}
QJsonDocument document(this->toJsonObject());
QByteArray json_content = document.toJson();
file.write(json_content);
}
QJsonObject Config::toJsonObject()
{
QJsonObject object;
object["audio_file"] = this->m_recentAudioFile.toLocalFile();
object["lrc_file"] = this->m_recentLrcFile.toLocalFile();
return object;
}
const QUrl& Config::recentLrcFile() const
{
return m_recentLrcFile;
}
void Config::setRecentLrcFile(const QUrl& newRecentLrcFile)
{
if (m_recentLrcFile == newRecentLrcFile)
return;
m_recentLrcFile = newRecentLrcFile;
emit recentLrcFileChanged();
}
const QUrl& Config::recentAudioFile() const
{
return m_recentAudioFile;
}
void Config::setRecentAudioFile(const QUrl& newRecentAudioFile)
{
if (m_recentAudioFile == newRecentAudioFile)
return;
m_recentAudioFile = newRecentAudioFile;
emit recentAudioFileChanged();
}