-
Notifications
You must be signed in to change notification settings - Fork 1
/
qhtspeventdata.cpp
210 lines (166 loc) · 4.71 KB
/
qhtspeventdata.cpp
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
203
204
205
206
207
208
209
210
/*
* Copyright (C) 2012 Robert Meijers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qhtspevent.h"
#include "qhtsp.h"
QHtspEventData::QHtspEventData(QHtsp *htsp, int id) :
id(id), channelId(-1), htsp(htsp), nextEventId(-1), m_channel(0), m_loaded(false), m_nextEvent(0),
m_previousEventSearched(false)
{
}
QHtspEventData::QHtspEventData(const QHtspEventData &other) :
QObject(0), QSharedData(other), id(other.id), channelId(other.channelId), description(other.description),
htsp(other.htsp), nextEventId(other.nextEventId), start(other.start), stop(other.stop), title(other.title),
m_channel(other.m_channel), m_loaded(other.m_loaded), m_nextEvent(other.m_nextEvent), m_previousEventSearched(false)
{
}
QHtspChannel *QHtspEventData::channel()
{
if(!m_channel)
m_channel = htsp->channels()->find(channelId);
return m_channel;
}
QHtspEvent *QHtspEventData::nextEvent()
{
if(!m_nextEvent && nextEventId >= 0)
{
m_nextEvent = htsp->events()->find(nextEventId);
if(!m_nextEvent)
{
m_nextEvent = new QHtspEvent(htsp, nextEventId, htsp);
htsp->events()->add(m_nextEvent);
htsp->getEvent(nextEventId);
}
}
return m_nextEvent;
}
QHtspEvent *QHtspEventData::previousEvent()
{
if(id < 0)
return 0;
if(!m_previousEventSearched)
{
m_previousEvent = channel()->events()->findPreviousEvent(id);
if(m_previousEvent)
connect(m_previousEvent, SIGNAL(destroyed()), SLOT(_previousEventDestroyed()));
m_previousEventSearched = true;
}
return m_previousEvent;
}
void QHtspEventData::setId(qint64 id)
{
if(this->id == id)
return;
this->id = id;
emit idChanged();
}
void QHtspEventData::setChannelId(qint64 channelId)
{
if(this->channelId == channelId)
return;
m_channel = 0;
this->channelId = channelId;
emit channelIdChanged();
}
void QHtspEventData::setDescription(QString description)
{
if(this->description == description)
return;
this->description = description;
emit descriptionChanged();
}
void QHtspEventData::setLongDescription(QString description)
{
if(longDescription == description)
return;
longDescription = description;
emit longDescriptionChanged();
}
void QHtspEventData::setNextEventId(qint64 nextEventId)
{
if(this->nextEventId == nextEventId)
return;
this->nextEventId = nextEventId;
m_nextEvent = 0;
emit nextEventIdChanged();
}
void QHtspEventData::setStart(QDateTime start)
{
if(this->start == start)
return;
this->start = start;
emit startChanged();
}
void QHtspEventData::setStop(QDateTime stop)
{
if(this->stop == stop)
return;
this->stop = stop;
emit stopChanged();
}
void QHtspEventData::setTitle(QString title)
{
if(this->title == title)
return;
this->title = title;
emit titleChanged();
}
void QHtspEventData::parseMessage(QHtspMessage &message)
{
qint64 id;
qint64 channelId;
QString description;
QString longDescription;
qint64 nextEventId;
qint64 start;
qint64 stop;
QString title;
bool ok;
id = message.getInt64("eventId", &ok);
if(ok)
setId(id);
channelId = message.getInt64("channelId", &ok);
if(ok)
setChannelId(channelId);
description = message.getString("description", &ok);
if(ok)
setDescription(description);
longDescription = message.getString("ext_text", &ok);
if(ok)
setLongDescription(longDescription);
nextEventId = message.getInt64("nextEventId", &ok);
if(ok)
setNextEventId(nextEventId);
start = message.getInt64("start", &ok);
if(ok)
setStart(QDateTime::fromTime_t(start));
stop = message.getInt64("stop", &ok);
if(ok)
setStop(QDateTime::fromTime_t(stop));
title = message.getString("title", &ok);
if(ok)
setTitle(title);
if(!m_loaded)
{
m_loaded = true;
emit loaded();
}
}
void QHtspEventData::_previousEventDestroyed()
{
m_previousEvent = 0;
emit previousEventChanged();
}