This repository was archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcddatabase.cpp
More file actions
202 lines (157 loc) · 4.65 KB
/
Copy pathcddatabase.cpp
File metadata and controls
202 lines (157 loc) · 4.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "cddatabase.h"
cdDatabase::cdDatabase(QObject *parent) : QObject(parent)
{
QString inCDname;
QString inAutor;
QString inYear;
QString inGenre;
QString inpictureAddres;
QString inSong;
int id = 0;
QMessageBox warning;
warning.setText(tr("Can't find data.txt"));
warning.setInformativeText(tr("Couldn't find data.txt. If you have such file please move it into same directory as this program. If not, new file data.txt will be created."));
QDir imageFolder("thumbs");
if(!imageFolder.exists())imageFolder.mkpath(".");
QFile inputFile("data.txt");
if (inputFile.open(QIODevice::ReadOnly)){
if(inputFile.readLine().contains("#cdDatabase")){
QTextStream in(&inputFile);
while (!in.atEnd())
{
inCDname = in.readLine();
inAutor = in.readLine();
inYear = in.readLine();
inGenre = in.readLine();
inpictureAddres = in.readLine();
fillDb(inCDname,inAutor,inYear.toInt(),inGenre,inpictureAddres);
inSong = in.readLine();
while(!inSong.contains("#####"))
{
addSong(id,inSong);
inSong = in.readLine();
}
id++;
}
inputFile.close();
}else{
warning.setText(tr("Incompatible data.txt file"));
warning.setInformativeText(tr("You might have provided wrong data.txt file. Please check program directory if included file is the right one."));
warning.exec();
inputFile.close();
}
}else {
warning.exec();
inputFile.close();
}
}
cdDatabase::~cdDatabase()
{
QFile outputFile("data.txt");
outputFile.remove();
if(outputFile.open(QIODevice::WriteOnly)){
QTextStream stream(&outputFile);
stream << "#cdDatabase manual edits not recommended" << endl;
for(int i = 0; i < getCount();i++){
stream << getCDName(i) << endl;
stream << getAutorName(i) << endl;
stream << getYear(i) << endl;
stream << getType(i) << endl;
stream << getPicture(i) << endl;
int songsAmount = getNumberOfSongs(i);
if(songsAmount > 0){
for(int j = 0;j < songsAmount;j++){
stream << getSongs(i,j) << endl;
}
}
stream << "#####" << endl;
}
}
outputFile.close();
CD.clear();
}
QList<QString> cdDatabase::getAllSongs(int id) //const
{
return CD.at(id)->getSongs();
}
QString cdDatabase::getCDName(int id) const
{
return CD.at(id)->getCDName();
}
QString cdDatabase::getAutorName(int id) const
{
return CD.at(id)->getAutorName();
}
QString cdDatabase::getYear(int id) const
{
QString str = QString::number(CD.at(id)->getYear());
return str;
}
QString cdDatabase::getType(int id) const
{
return CD.at(id)->getType();
}
QString cdDatabase::getSongs(int id,int songID) const
{
return CD.at(id)->getSong(songID);
}
QString cdDatabase::getPicture(int id) const
{
return CD.at(id)->getPicture();
}
int cdDatabase::getNumberOfSongs(int id) const
{
return CD.at(id)->getNumberOfSongs();
}
int cdDatabase::getCount() const
{
return CD.count();
}
void cdDatabase::fillDb(QString CDName, QString Autor, int Year, QString Genre, QString Picture)
{
cdData *newCD = new cdData;
if(CDName.isEmpty())CDName.append("---");
if(Autor.isEmpty())Autor.append("---");
if(Genre.isEmpty())Genre.append("---");
newCD->setAutorName(Autor);
newCD->setCDName(CDName);
newCD->setType(Genre);
newCD->setYear(Year);
if(QFileInfo(Picture).exists())newCD->setPicture(Picture);
else newCD->setPicture(":/images/none.png");
CD.append(newCD);
}
void cdDatabase::fillDb(QString CDName, QString Autor, int Year, QString Genre)
{
cdData *newCD = new cdData;
newCD->setAutorName(Autor);
newCD->setCDName(CDName);
newCD->setType(Genre);
newCD->setYear(Year);
newCD->setPicture(":/images/none.png");
CD.append(newCD);
}
void cdDatabase::editDB(int id,QString CDName, QString Autor, int Year, QString Genre, QString Picture)
{
CD.at(id)->setCDName(CDName);
CD.at(id)->setAutorName(Autor);
CD.at(id)->setYear(Year);
CD.at(id)->setType(Genre);
CD.at(id)->setPicture(Picture);
}
void cdDatabase::addSong(int id, QString songName)
{
CD.at(id)->addSong(songName);
}
void cdDatabase::removeCD(int id)
{
CD.removeAt(id);
}
void cdDatabase::clearSongs(int id)
{
CD.at(id)->clearSongs();
}
void cdDatabase::dbClear()
{
CD.clear();
}