-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtParametreGlobal.h
154 lines (134 loc) · 4.99 KB
/
tParametreGlobal.h
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
#ifndef TPARAMETREGLOBAL_H
#define TPARAMETREGLOBAL_H
#include "tMedia.h"
#include "tTv.h"
#include <QList>
#include <QString>
#include <QSettings>
#include <QDomDocument>
#include <QDomElement>
class tParametreGlobal
{
public:
tParametreGlobal() {}
tParametreGlobal(QDomElement &node)
{
this->fromXml(node);
}
/** Convert Data to Xml */
QDomDocument toXml(QDomDocument &parent, QDomElement &child) {
QSettings setting;
// Logo
QDomElement logo = parent.createElement("Logo");
logo.setAttribute("enable", setting.value("Logo/Enable").toBool());
logo.setAttribute("url", setting.value("Logo/Url").toString());
logo.setAttribute("posX", setting.value("Logo/PosX").toInt());
logo.setAttribute("posY", setting.value("Logo/PosY").toInt());
child.appendChild(logo);
// Background
QDomElement background = parent.createElement("Background");
background.setAttribute("url", setting.value("Background").toString());
child.appendChild(background);
QDomElement media_list = parent.createElement("Media_List");
child.appendChild(media_list);
for (QList<tMedia>::iterator i=this->listMedia.begin() ; i!=this->listMedia.end() ; ++i) {
(*i).toXml(parent, media_list);
}
QDomElement tv_list = parent.createElement("TV_List");
child.appendChild(tv_list);
for (QList<tTv>::iterator i=this->listTv.begin() ; i!=this->listTv.end() ; ++i) {
(*i).toXml(parent, tv_list);
}
return parent;
}
/** Convert Xml to Data */
void fromXml(QDomElement &node) {
QSettings setting;
/** On verifie que le fichier soit bien celui que nous avons creer */
if (node.tagName() == "TV_Controller")
{
QDomElement child = node.firstChildElement();
while(!child.isNull())
{
// Logo
if (child.tagName() == "Logo")
{
setting.setValue("Logo/Url", child.attribute("url"));
setting.setValue("Logo/Enable", child.attribute("enable").toInt() > 0);
setting.setValue("Logo/PosX", child.attribute("posX").toInt());
setting.setValue("Logo/PosY", child.attribute("posY").toInt());
}
// Background
if (child.tagName() == "Background")
{
setting.setValue("Background", child.attribute("url"));
}
/** On récupere la liste des Media */
if (child.tagName() == "Media_List")
{
QDomElement smallChild = child.firstChildElement();
while(!smallChild.isNull()) {
/** On ajoute le Media dans la liste des Media */
this->listMedia.append(tMedia(smallChild));
smallChild = smallChild.nextSiblingElement();
}
}
/** On récupere la liste des TV */
if (child.tagName() == "TV_List")
{
QDomElement smallChild = child.firstChildElement();
while(!smallChild.isNull()) {
/** On ajoute la TV dans la liste des TV */
this->listTv.append(tTv(smallChild));
smallChild = smallChild.nextSiblingElement();
}
}
child = child.nextSiblingElement();
}
}
}
void clearAll() {
listMedia.clear();
for (QList<tTv>::iterator i=this->listTv.begin() ; i!=this->listTv.end() ; ++i) {
(*i).clearAll();
}
listTv.clear();
}
bool maybeSave() {
bool res = false;
for (QList<tMedia>::iterator i=this->listMedia.begin() ; i!=this->listMedia.end() ; ++i) {
res |= (*i).maybeSave();
}
for (QList<tTv>::iterator i=this->listTv.begin() ; i!=this->listTv.end() ; ++i) {
res |= (*i).maybeSave();
}
return res;
}
void saveDone() {
for (QList<tMedia>::iterator i=this->listMedia.begin() ; i!=this->listMedia.end() ; ++i) {
(*i).saveDone();
}
for (QList<tTv>::iterator i=this->listTv.begin() ; i!=this->listTv.end() ; ++i) {
(*i).saveDone();
}
}
/** Debug */
QString toString() {
QString res;
res = "tParametreGlobal => \n ";
for (QList<tMedia>::iterator i=this->listMedia.begin() ; i!=this->listMedia.end() ; ++i) {
res += " " + (*i).toString();
}
for (QList<tTv>::iterator i=this->listTv.begin() ; i!=this->listTv.end() ; ++i) {
res += " " + (*i).toString();
}
return res;
}
virtual ~tParametreGlobal() {}
// protected:
//
// private:
QList<tMedia> listMedia;
QList<tTv> listTv;
};
#endif // TPARAMETREGLOBAL_H