-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtTv.h
159 lines (140 loc) · 5.16 KB
/
tTv.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
155
156
157
158
159
#ifndef TTV_H
#define TTV_H
#include "tEvent.h"
#include "tBackground.h"
#include "tScheduler.h"
#include <QList>
#include <QString>
#include <QDomDocument>
#include <QDomElement>
class tTv
{
public:
tTv()
: isModify(false) {}
tTv(QString _name)
: name(_name), isModify(false) {
numHDMI=0; useCEC=false;
}
tTv(QString _name, QString _url)
: name(_name), url(_url), isModify(false) {}
tTv(QDomElement &node) {
this->fromXml(node);
this->isModify = false;
}
/** Set Attribut */
void setName(QString _name) { name = _name; this->isModify = true; }
void setUrl(QString _url) { url = _url; this->isModify = true; }
void setNumHDMI(int _num) { numHDMI = _num; this->isModify = true; }
void setUseCEC(bool _enable) { useCEC = _enable; this->isModify = true; }
/** Get Attribut */
QString getName() { return name; }
QString getUrl() { return url; }
int getNumHDMI() { return numHDMI; }
bool getUseCEC() { return useCEC; }
/** Convert Data to Xml */
QDomElement toXml(QDomDocument &parent, QDomElement &child) {
QDomElement tv = parent.createElement("TV");
tv.setAttribute("name", name);
tv.setAttribute("url", url);
tv.setAttribute("numHDMI", numHDMI);
tv.setAttribute("useCEC", useCEC);
child.appendChild(tv);
for (QList<tScheduler>::iterator i=this->listScheduler.begin() ; i!=this->listScheduler.end() ; ++i) {
(*i).toXml(parent, tv);
}
for (QList<tEvent>::iterator i=this->listEvent.begin() ; i!=this->listEvent.end() ; ++i) {
(*i).toXml(parent, tv);
}
for (QList<tBackground>::iterator i=this->listBackground.begin() ; i!=this->listBackground.end() ; ++i) {
(*i).toXml(parent, tv);
}
return tv;
}
/** Convert Xml to Data */
void fromXml(QDomElement &node) {
if (node.tagName() == "TV") {
name = node.attribute("name");
url = node.attribute("url");
numHDMI = node.attribute("numHDMI", "0").toInt();
useCEC = node.attribute("useCEC", "0").toInt() > 0;
QDomElement child = node.firstChildElement();
while(!child.isNull())
{
/** On récupere les planning */
if (child.tagName() == "Scheduler")
{
/** On ajoute le Media dans la liste des Media */
this->listScheduler.append(tScheduler(child));
}
/** On récupere les événements */
if (child.tagName() == "Event")
{
/** On ajoute le Media dans la liste des Media */
this->listEvent.append(tEvent(child));
}
/** On récupere les arriéres plan */
if (child.tagName() == "Background")
{
/** On ajoute l'arriére plan dans la liste des arriére plan */
this->listBackground.append(tBackground(child));
}
child = child.nextSiblingElement();
}
}
}
void clearAll() {
listEvent.clear();
listBackground.clear();
listScheduler.clear();
}
bool maybeSave() {
bool res = false;
for (QList<tEvent>::iterator i=this->listEvent.begin() ; i!=this->listEvent.end() ; ++i) {
res |= (*i).maybeSave();
}
for (QList<tBackground>::iterator i=this->listBackground.begin() ; i!=this->listBackground.end() ; ++i) {
res |= (*i).maybeSave();
}
return (res | isModify);
}
void saveDone() {
for (QList<tEvent>::iterator i=this->listEvent.begin() ; i!=this->listEvent.end() ; ++i) {
(*i).saveDone();
}
for (QList<tBackground>::iterator i=this->listBackground.begin() ; i!=this->listBackground.end() ; ++i) {
(*i).saveDone();
}
isModify = false;
}
/** Debug */
QString toString() {
QString res;
res = "tTv => \t name: " + name + ",\n";
res += "\t\t url: " + url + "\n";
res += "\t\t numHDMI: " + QString("%1").arg(numHDMI) + "\n";
res += "\t\t useCEC: " + QString("%1").arg(useCEC) + "\n";
for (QList<tScheduler>::iterator i=this->listScheduler.begin() ; i!=this->listScheduler.end() ; ++i) {
res += " " + (*i).toString();
}
for (QList<tEvent>::iterator i=this->listEvent.begin() ; i!=this->listEvent.end() ; ++i) {
res += " " + (*i).toString();
}
for (QList<tBackground>::iterator i=this->listBackground.begin() ; i!=this->listBackground.end() ; ++i) {
res += " " + (*i).toString();
}
return res;
}
virtual ~tTv() {}
QList<tEvent> listEvent;
QList<tBackground> listBackground;
QList<tScheduler> listScheduler;
protected:
private:
QString name;
QString url;
int numHDMI;
bool useCEC;
bool isModify;
};
#endif // TTV_H