Debian Codegraph @

src/timers.cpp

raw
1 /*
2 * Copyright (C) 2005-2021 Team Kodi (https://kodi.tv)
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 * See LICENSE.md for more information.
6 */
7
8 #include <vector>
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 using namespace std;
13
14 #include "timers.h"
15 #include "settings.h"
16 #include "utils.h"
17 #include "DateTime.h"
18 #include "epg.h"
19
20 #include <kodi/General.h>
21
22 using namespace MPTV;
23
24 cTimer::cTimer() :
25 m_keepDate(cUndefinedDate),
26 m_canceled(cUndefinedDate)
27 {
28 m_index = PVR_TIMER_NO_CLIENT_INDEX;
29 m_active = true;
30 m_channel = PVR_CHANNEL_INVALID_UID;
31 m_schedtype = TvDatabase::Once;
32 m_priority = 0;
33 m_keepmethod = TvDatabase::UntilSpaceNeeded;
34 m_prerecordinterval = -1; // Use MediaPortal setting instead
35 m_postrecordinterval = -1; // Use MediaPortal setting instead
36 m_series = false;
37 m_done = false;
38 m_ismanual = false;
39 m_isrecording = false;
40 m_progid = (EPG_TAG_INVALID_UID - cKodiEpgIndexOffset);
41 m_genretable = NULL;
42 m_parentScheduleID = MPTV_NO_PARENT_SCHEDULE;
43 }
44
45
46 cTimer::cTimer(const kodi::addon::PVRTimer& timerinfo):
47 m_genretable(NULL)
48 {
49
50 m_index = timerinfo.GetClientIndex() - cKodiTimerIndexOffset;
51 m_progid = timerinfo.GetEPGUid() - cKodiEpgIndexOffset;
52
53 m_parentScheduleID = timerinfo.GetParentClientIndex() - cKodiTimerIndexOffset;
54
55 if (m_index >= MPTV_REPEAT_NO_SERIES_OFFSET)
56 {
57 m_index = m_parentScheduleID;
58 }
59
60 m_done = (timerinfo.GetState() == PVR_TIMER_STATE_COMPLETED);
61 m_active = (timerinfo.GetState() == PVR_TIMER_STATE_SCHEDULED || timerinfo.GetState() == PVR_TIMER_STATE_RECORDING
62 || timerinfo.GetState() == PVR_TIMER_STATE_CONFLICT_OK || timerinfo.GetState() == PVR_TIMER_STATE_CONFLICT_NOK);
63
64 if (!m_active)
65 {
66 // Don't know when it was cancelled, so assume that it was canceled now...
67 // backend (TVServerKodi) will only update the canceled date time when
68 // this schedule was just canceled
69 m_canceled = CDateTime::Now();
70 }
71 else
72 {
73 m_canceled = cUndefinedDate;
74 }
75
76 m_title = timerinfo.GetTitle();
77 m_directory = timerinfo.GetDirectory();
78 m_channel = timerinfo.GetClientChannelUid();
79
80 if (timerinfo.GetStartTime() <= 0)
81 {
82 // Instant timer has starttime = 0, so set current time as starttime.
83 m_startTime = CDateTime::Now();
84 m_ismanual = true;
85 }
86 else
87 {
88 m_startTime = timerinfo.GetStartTime();
89 m_ismanual = false;
90 }
91
92 m_endTime = timerinfo.GetEndTime();
93 //m_firstday = timerinfo.firstday;
94 m_isrecording = (timerinfo.GetState() == PVR_TIMER_STATE_RECORDING);
95 m_priority = XBMC2MepoPriority(timerinfo.GetPriority());
96
97 SetKeepMethod(timerinfo.GetLifetime());
98
99 m_schedtype = static_cast<enum TvDatabase::ScheduleRecordingType>(timerinfo.GetTimerType() - cKodiTimerTypeOffset);
100 if (m_schedtype == TvDatabase::KodiManual)
101 {
102 m_schedtype = TvDatabase::Once;
103 }
104
105 if ((m_schedtype == TvDatabase::Once) && (timerinfo.GetWeekdays() != PVR_WEEKDAY_NONE)) // huh, still repeating?
106 {
107 // Select the correct schedule type
108 m_schedtype = RepeatFlags2SchedRecType(timerinfo.GetWeekdays());
109 }
110
111 m_series = (m_schedtype == TvDatabase::Once) ? false : true;
112
113 m_prerecordinterval = timerinfo.GetMarginStart();
114 m_postrecordinterval = timerinfo.GetMarginEnd();
115 }
116
117
118 cTimer::~cTimer()
119 {
120 }
121
122 /**
123 * @brief Fills the PVR_TIMER struct with information from this timer
124 * @param tag A reference to the PVR_TIMER struct
125 */
126 void cTimer::GetPVRtimerinfo(kodi::addon::PVRTimer &tag)
127 {
128 if (m_parentScheduleID != MPTV_NO_PARENT_SCHEDULE)
129 {
130 /* Hack: use a different client index for Kodi since it does not accept multiple times the same schedule id
131 * This means that all programs scheduled via a series schedule in MediaPortal will get a different client
132 * index in Kodi. The iParentClientIndex will still point to the original id_Schedule in MediaPortal
133 */
134 tag.SetClientIndex(cKodiTimerIndexOffset + MPTV_REPEAT_NO_SERIES_OFFSET + cKodiEpgIndexOffset + m_progid);
135 }
136 else
137 {
138 tag.SetClientIndex(cKodiTimerIndexOffset + m_index);
139 }
140 tag.SetEPGUid(cKodiEpgIndexOffset + m_progid);
141
142 if (IsRecording())
143 tag.SetState(PVR_TIMER_STATE_RECORDING);
144 else if (m_active)
145 tag.SetState(PVR_TIMER_STATE_SCHEDULED);
146 else
147 tag.SetState(PVR_TIMER_STATE_DISABLED);
148
149 if (m_schedtype == TvDatabase::EveryTimeOnEveryChannel)
150 {
151 tag.SetClientChannelUid(PVR_TIMER_ANY_CHANNEL);
152 }
153 else
154 {
155 tag.SetClientChannelUid(m_channel);
156 }
157 tag.SetTitle(m_title);
158 tag.SetStartTime(m_startTime.GetAsTime());
159 tag.SetEndTime(m_endTime.GetAsTime());
160 // From the VDR manual
161 // firstday: The date of the first day when this timer shall start recording
162 // (only available for repeating timers).
163 if(Repeat())
164 {
165 if (m_parentScheduleID != MPTV_NO_PARENT_SCHEDULE)
166 {
167 tag.SetFirstDay(0);
168 tag.SetParentClientIndex((unsigned int)(cKodiTimerIndexOffset + m_parentScheduleID));
169 tag.SetWeekdays(PVR_WEEKDAY_NONE);
170 tag.SetTimerType(cKodiTimerTypeOffset + (int) TvDatabase::Once);
171 tag.SetClientChannelUid(m_channel);
172 }
173 else
174 {
175 tag.SetFirstDay(m_startTime.GetAsTime());
176 tag.SetParentClientIndex(PVR_TIMER_NO_PARENT);
177 tag.SetWeekdays(RepeatFlags());
178 tag.SetTimerType(cKodiTimerTypeOffset + (int) m_schedtype);
179 }
180 }
181 else
182 {
183 tag.SetFirstDay(0);
184 tag.SetParentClientIndex(PVR_TIMER_NO_PARENT);
185 tag.SetWeekdays(RepeatFlags());
186 tag.SetTimerType(cKodiTimerTypeOffset + (int) m_schedtype);
187 }
188 tag.SetPriority(Priority());
189 tag.SetLifetime(GetLifetime());
190 tag.SetMarginStart(m_prerecordinterval);
191 tag.SetMarginEnd(m_postrecordinterval);
192 if (m_genretable)
193 {
194 // genre string to genre type/subtype mapping
195 int genreType;
196 int genreSubType;
197 m_genretable->GenreToTypes(m_genre, genreType, genreSubType);
198 tag.SetGenreType(genreType);
199 tag.SetGenreSubType(genreSubType);
200 }
201 else
202 {
203 tag.SetGenreType(0);
204 tag.SetGenreSubType(0);
205 }
206 tag.SetDirectory(m_directory);
207 tag.SetSummary(m_description);
208 }
209
210 time_t cTimer::StartTime(void) const
211 {
212 time_t retVal = m_startTime.GetAsTime();
213 return retVal;
214 }
215
216 time_t cTimer::EndTime(void) const
217 {
218 time_t retVal = m_endTime.GetAsTime();
219 return retVal;
220 }
221
222 bool cTimer::ParseLine(const char *s)
223 {
224 vector<string> schedulefields;
225 string data = s;
226 uri::decode(data);
227
228 Tokenize(data, schedulefields, "|");
229
230 if (schedulefields.size() >= 10)
231 {
232 // field 0 = index
233 // field 1 = start date + time
234 // field 2 = end date + time
235 // field 3 = channel nr
236 // field 4 = channel name
237 // field 5 = program name
238 // field 6 = schedule recording type
239 // field 7 = priority
240 // field 8 = isdone (finished)
241 // field 9 = ismanual
242 // field 10 = directory
243 // field 11 = keepmethod (0=until space needed, 1=until watched, 2=until keepdate, 3=forever) (TVServerKodi build >= 100)
244 // field 12 = keepdate (2000-01-01 00:00:00 = infinite) (TVServerKodi build >= 100)
245 // field 13 = preRecordInterval (TVServerKodi build >= 100)
246 // field 14 = postRecordInterval (TVServerKodi build >= 100)
247 // field 15 = canceled (TVServerKodi build >= 100)
248 // field 16 = series (True/False) (TVServerKodi build >= 100)
249 // field 17 = isrecording (True/False)
250 // field 18 = program id (EPG)
251 // field 19 = parent schedule id (TVServerKodi build >= 130)
252 // field 20 = genre of the program (TVServerKodi build >= 130)
253 // field 21 = program description (EPG) (TVServerKodi build >= 130)
254 m_index = atoi(schedulefields[0].c_str());
255
256 if ( m_startTime.SetFromDateTime(schedulefields[1]) == false )
257 return false;
258
259 if ( m_endTime.SetFromDateTime(schedulefields[2]) == false )
260 return false;
261
262 m_channel = atoi(schedulefields[3].c_str());
263 m_title = schedulefields[5];
264
265 m_schedtype = (TvDatabase::ScheduleRecordingType) atoi(schedulefields[6].c_str());
266
267 m_priority = atoi(schedulefields[7].c_str());
268 m_done = stringtobool(schedulefields[8]);
269 m_ismanual = stringtobool(schedulefields[9]);
270 m_directory = schedulefields[10];
271
272 if(schedulefields.size() >= 18)
273 {
274 //TVServerKodi build >= 100
275 m_keepmethod = (TvDatabase::KeepMethodType) atoi(schedulefields[11].c_str());
276 if ( m_keepDate.SetFromDateTime(schedulefields[12]) == false )
277 return false;
278
279 m_prerecordinterval = atoi(schedulefields[13].c_str());
280 m_postrecordinterval = atoi(schedulefields[14].c_str());
281
282 // The DateTime value 2000-01-01 00:00:00 means: active in MediaPortal
283 if(schedulefields[15].compare("2000-01-01 00:00:00Z")==0)
284 {
285 m_canceled.SetFromTime(MPTV::cUndefinedDate);
286 m_active = true;
287 }
288 else
289 {
290 if (m_canceled.SetFromDateTime(schedulefields[15]) == false)
291 {
292 m_canceled.SetFromTime(MPTV::cUndefinedDate);
293 }
294 m_active = false;
295 }
296
297 m_series = stringtobool(schedulefields[16]);
298 m_isrecording = stringtobool(schedulefields[17]);
299
300 }
301 else
302 {
303 m_keepmethod = TvDatabase::UntilSpaceNeeded;
304 m_keepDate = cUndefinedDate;
305 m_prerecordinterval = -1;
306 m_postrecordinterval = -1;
307 m_canceled = cUndefinedDate;
308 m_active = true;
309 m_series = false;
310 m_isrecording = false;
311 }
312
313 if(schedulefields.size() >= 19)
314 m_progid = atoi(schedulefields[18].c_str());
315 else
316 m_progid = (EPG_TAG_INVALID_UID - cKodiEpgIndexOffset);
317
318 if (schedulefields.size() >= 22)
319 {
320 m_parentScheduleID = atoi(schedulefields[19].c_str());
321 m_genre = schedulefields[20];
322 m_description = schedulefields[21];
323 }
324 else
325 {
326 m_parentScheduleID = MPTV_NO_PARENT_SCHEDULE;
327 m_genre.clear();
328 m_description.clear();
329 }
330
331 return true;
332 }
333 return false;
334 }
335
336 int cTimer::SchedRecType2RepeatFlags(TvDatabase::ScheduleRecordingType schedtype)
337 {
338 // This field contains a bitmask that corresponds to the days of the week at which this timer runs
339 // It is based on the VDR Day field format "MTWTF--"
340 // The format is a 1 bit for every enabled day and a 0 bit for a disabled day
341 // Thus: WeekDays = "0000 0001" = "M------" (monday only)
342 // "0110 0000" = "-----SS" (saturday and sunday)
343 // "0001 1111" = "MTWTF--" (all weekdays)
344
345 int weekdays = 0;
346
347 switch (schedtype)
348 {
349 case TvDatabase::Once:
350 case TvDatabase::KodiManual:
351 weekdays = PVR_WEEKDAY_NONE;
352 break;
353 case TvDatabase::Daily:
354 weekdays = PVR_WEEKDAY_ALLDAYS; // 0111 1111
355 break;
356 case TvDatabase::Weekly:
357 case TvDatabase::WeeklyEveryTimeOnThisChannel:
358 {
359 // Not sure what to do with these MediaPortal options...
360 // Assumption: record once a week, on the same day and time
361 // => determine weekday and set the corresponding bit
362 int weekday = m_startTime.GetDayOfWeek(); //days since Sunday [0-6]
363 // bit 0 = monday, need to convert weekday value to bitnumber:
364 if (weekday == 0)
365 weekday = 6; // sunday 0100 0000
366 else
367 weekday--;
368
369 weekdays = 1 << weekday;
370 break;
371 }
372 case TvDatabase::EveryTimeOnThisChannel:
373 // Don't know what to do with this MediaPortal option?
374 weekdays = PVR_WEEKDAY_ALLDAYS; // 0111 1111 (daily)
375 break;
376 case TvDatabase::EveryTimeOnEveryChannel:
377 // Don't know what to do with this MediaPortal option?
378 weekdays = PVR_WEEKDAY_ALLDAYS; // 0111 1111 (daily)
379 break;
380 case TvDatabase::Weekends:
381 // 0110 0000
382 weekdays = PVR_WEEKDAY_SATURDAY | PVR_WEEKDAY_SUNDAY;
383 break;
384 case TvDatabase::WorkingDays:
385 // 0001 1111
386 weekdays = PVR_WEEKDAY_MONDAY | PVR_WEEKDAY_TUESDAY | PVR_WEEKDAY_WEDNESDAY | PVR_WEEKDAY_THURSDAY | PVR_WEEKDAY_FRIDAY;
387 break;
388 default:
389 weekdays = PVR_WEEKDAY_NONE;
390 }
391
392 return weekdays;
393 }
394
395 TvDatabase::ScheduleRecordingType cTimer::RepeatFlags2SchedRecType(int repeatflags)
396 {
397 // margro: the meaning of the XBMC-PVR Weekdays field is undocumented.
398 // Assuming that VDR is the source for this field:
399 // This field contains a bitmask that corresponds to the days of the week at which this timer runs
400 // It is based on the VDR Day field format "MTWTF--"
401 // The format is a 1 bit for every enabled day and a 0 bit for a disabled day
402 // Thus: WeekDays = "0000 0001" = "M------" (monday only)
403 // "0110 0000" = "-----SS" (saturday and sunday)
404 // "0001 1111" = "MTWTF--" (all weekdays)
405
406 switch (repeatflags)
407 {
408 case PVR_WEEKDAY_NONE:
409 return TvDatabase::Once;
410 break;
411 case PVR_WEEKDAY_MONDAY:
412 case PVR_WEEKDAY_TUESDAY:
413 case PVR_WEEKDAY_WEDNESDAY:
414 case PVR_WEEKDAY_THURSDAY:
415 case PVR_WEEKDAY_FRIDAY:
416 case PVR_WEEKDAY_SATURDAY:
417 case PVR_WEEKDAY_SUNDAY:
418 return TvDatabase::Weekly;
419 break;
420 case (PVR_WEEKDAY_MONDAY | PVR_WEEKDAY_TUESDAY | PVR_WEEKDAY_WEDNESDAY | PVR_WEEKDAY_THURSDAY | PVR_WEEKDAY_FRIDAY): // 0001 1111
421 return TvDatabase::WorkingDays;
422 case (PVR_WEEKDAY_SATURDAY | PVR_WEEKDAY_SUNDAY): // 0110 0000
423 return TvDatabase::Weekends;
424 break;
425 case PVR_WEEKDAY_ALLDAYS: // 0111 1111
426 return TvDatabase::Daily;
427 break;
428 default:
429 break;
430 }
431
432 return TvDatabase::Once;
433 }
434
435 std::string cTimer::AddScheduleCommand()
436 {
437 char command[1024];
438 string startTime;
439 string endTime;
440
441 m_startTime.GetAsLocalizedTime(startTime);
442 m_endTime.GetAsLocalizedTime(endTime);
443 kodi::Log(ADDON_LOG_DEBUG, "Start time: %s, marginstart: %i min earlier", startTime.c_str(), m_prerecordinterval);
444 kodi::Log(ADDON_LOG_DEBUG, "End time: %s, marginstop: %i min later", endTime.c_str(), m_postrecordinterval);
445
446 snprintf(command, 1023, "AddSchedule:%i|%s|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i\n",
447 m_channel, //Channel number [0]
448 uri::encode(uri::PATH_TRAITS, m_title).c_str(), //Program title [1]
449 m_startTime.GetYear(), m_startTime.GetMonth(), m_startTime.GetDay(), //Start date [2..4]
450 m_startTime.GetHour(), m_startTime.GetMinute(), m_startTime.GetSecond(), //Start time [5..7]
451 m_endTime.GetYear(), m_endTime.GetMonth(), m_endTime.GetDay(), //End date [8..10]
452 m_endTime.GetHour(), m_endTime.GetMinute(), m_endTime.GetSecond(), //End time [11..13]
453 (int) m_schedtype, m_priority, (int) m_keepmethod, //SchedType, Priority, keepMethod [14..16]
454 m_keepDate.GetYear(), m_keepDate.GetMonth(), m_keepDate.GetDay(), //Keepdate [17..19]
455 m_keepDate.GetHour(), m_keepDate.GetMinute(), m_keepDate.GetSecond(), //Keeptime [20..22]
456 m_prerecordinterval, m_postrecordinterval); //Prerecord,postrecord [23,24]
457
458 return command;
459 }
460
461 std::string cTimer::UpdateScheduleCommand()
462 {
463 char command[1024];
464 string startTime;
465 string endTime;
466
467 m_startTime.GetAsLocalizedTime(startTime);
468 m_endTime.GetAsLocalizedTime(endTime);
469 kodi::Log(ADDON_LOG_DEBUG, "Start time: %s, marginstart: %i min earlier", startTime.c_str(), m_prerecordinterval);
470 kodi::Log(ADDON_LOG_DEBUG, "End time: %s, marginstop: %i min later", endTime.c_str(), m_postrecordinterval);
471
472 snprintf(command, 1024, "UpdateSchedule:%i|%i|%i|%s|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i|%i\n",
473 m_index, //Schedule index [0]
474 m_active, //Active [1]
475 m_channel, //Channel number [2]
476 uri::encode(uri::PATH_TRAITS,m_title).c_str(), //Program title [3]
477 m_startTime.GetYear(), m_startTime.GetMonth(), m_startTime.GetDay(), //Start date [4..6]
478 m_startTime.GetHour(), m_startTime.GetMinute(), m_startTime.GetSecond(), //Start time [7..9]
479 m_endTime.GetYear(), m_endTime.GetMonth(), m_endTime.GetDay(), //End date [10..12]
480 m_endTime.GetHour(), m_endTime.GetMinute(), m_endTime.GetSecond(), //End time [13..15]
481 (int) m_schedtype, m_priority, (int) m_keepmethod, //SchedType, Priority, keepMethod [16..18]
482 m_keepDate.GetYear(), m_keepDate.GetMonth(), m_keepDate.GetDay(), //Keepdate [19..21]
483 m_keepDate.GetHour(), m_keepDate.GetMinute(), m_keepDate.GetSecond(), //Keeptime [22..24]
484 m_prerecordinterval, m_postrecordinterval, m_progid); //Prerecord,postrecord,program_id [25,26,27]
485
486 return command;
487 }
488
489
490 int cTimer::XBMC2MepoPriority(int UNUSED(xbmcprio))
491 {
492 // From XBMC side: 0.99 where 0=lowest and 99=highest priority (like VDR). Default value: 50
493 // Meaning of the MediaPortal field is unknown to me. Default seems to be 0.
494 // TODO: figure out the mapping
495 return 0;
496 }
497
498 int cTimer::Mepo2XBMCPriority(int UNUSED(mepoprio))
499 {
500 return 50; //Default value
501 }
502
503
504 /*
505 * @brief Convert a Kodi Lifetime value to MediaPortals keepMethod+keepDate settings
506 * @param lifetime the Kodi lifetime value (in days)
507 * Should be called after setting m_starttime !!
508 */
509 void cTimer::SetKeepMethod(int lifetime)
510 {
511 // Kodi keep methods:
512 // negative values: => special methods like Until Space Needed, Always, Until Watched
513 // positive values: days to keep the recording
514 if (lifetime == 0)
515 {
516 m_keepmethod = TvDatabase::UntilSpaceNeeded;
517 m_keepDate = cUndefinedDate;
518 }
519 else if (lifetime < 0)
520 {
521 m_keepmethod = (TvDatabase::KeepMethodType) -lifetime;
522 m_keepDate = cUndefinedDate;
523 }
524 else
525 {
526 m_keepmethod = TvDatabase::TillDate;
527 m_keepDate = m_startTime;
528 m_keepDate += (lifetime * cSecsInDay);
529 }
530 }
531
532 int cTimer::GetLifetime(void)
533 {
534 // lifetime of recordings created by this timer.
535 // value > 0 = days after which recordings will be deleted by the backend,
536 // value < 0 addon defined integer list reference,
537 // value == 0 disabled
538 switch (m_keepmethod)
539 {
540 case TvDatabase::UntilSpaceNeeded: //until space needed
541 return -MPTV_KEEP_UNTIL_SPACE_NEEDED;
542 break;
543 case TvDatabase::UntilWatched: //until watched
544 return -MPTV_KEEP_UNTIL_WATCHED;
545 break;
546 case TvDatabase::TillDate: //until keepdate
547 {
548 int diffseconds = m_keepDate - m_startTime;
549 int daysremaining = (int)(diffseconds / cSecsInDay);
550 // Calculate value in the range 1...98, based on m_keepdate
551 return daysremaining;
552 }
553 break;
554 case TvDatabase::Always: //forever
555 return -MPTV_KEEP_ALWAYS;
556 default:
557 return 0;
558 }
559 }
560
561 void cTimer::SetScheduleRecordingType(TvDatabase::ScheduleRecordingType schedType)
562 {
563 m_schedtype = schedType;
564 }
565
566 void cTimer::SetKeepMethod(TvDatabase::KeepMethodType keepmethod)
567 {
568 m_keepmethod = keepmethod;
569 }
570
571 void cTimer::SetPreRecordInterval(int minutes)
572 {
573 m_prerecordinterval = minutes;
574 }
575
576 void cTimer::SetPostRecordInterval(int minutes)
577 {
578 m_postrecordinterval = minutes;
579 }
580
581 void cTimer::SetGenreTable(CGenreTable* genretable)
582 {
583 m_genretable = genretable;
584 }
585
586 cLifeTimeValues::cLifeTimeValues()
587 {
588 /* Prepare the list with Lifetime values and descriptions */
589 // MediaPortal keep methods:
590 m_lifetimeValues.emplace_back(-MPTV_KEEP_ALWAYS, kodi::addon::GetLocalizedString(30133));
591 m_lifetimeValues.emplace_back(-MPTV_KEEP_UNTIL_SPACE_NEEDED, kodi::addon::GetLocalizedString(30130));
592 m_lifetimeValues.emplace_back(-MPTV_KEEP_UNTIL_WATCHED, kodi::addon::GetLocalizedString(30131));
593
594 //Not directly supported by Kodi. I can add this, but there is no way to select the date
595 //m_lifetimeValues.emplace_back(TvDatabase::TillDate, kodi::addon::GetLocalizedString(30132));
596
597 // MediaPortal Until date replacements:
598 const std::string strWeeks = kodi::addon::GetLocalizedString(30137); // %d weeks
599 const std::string strMonths = kodi::addon::GetLocalizedString(30139); // %d months
600 const size_t cKeepStringLength = 255;
601 char strKeepString[cKeepStringLength];
602
603 m_lifetimeValues.emplace_back(MPTV_KEEP_ONE_WEEK, kodi::addon::GetLocalizedString(30134));
604
605 snprintf(strKeepString, cKeepStringLength, strWeeks.c_str(), 2);
606 m_lifetimeValues.emplace_back(MPTV_KEEP_TWO_WEEKS, strKeepString);
607
608 snprintf(strKeepString, cKeepStringLength, strWeeks.c_str(), 3);
609 m_lifetimeValues.emplace_back(MPTV_KEEP_THREE_WEEKS, strKeepString);
610
611 m_lifetimeValues.emplace_back(MPTV_KEEP_ONE_MONTH, kodi::addon::GetLocalizedString(30138));
612
613 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 2);
614 m_lifetimeValues.emplace_back(MPTV_KEEP_TWO_MONTHS, strKeepString);
615
616 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 3);
617 m_lifetimeValues.emplace_back(MPTV_KEEP_THREE_MONTHS, strKeepString);
618
619 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 4);
620 m_lifetimeValues.emplace_back(MPTV_KEEP_FOUR_MONTHS, strKeepString);
621
622 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 5);
623 m_lifetimeValues.emplace_back(MPTV_KEEP_FIVE_MONTHS, strKeepString);
624
625 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 6);
626 m_lifetimeValues.emplace_back(MPTV_KEEP_SIX_MONTHS, strKeepString);
627
628 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 7);
629 m_lifetimeValues.emplace_back(MPTV_KEEP_SEVEN_MONTHS, strKeepString);
630
631 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 8);
632 m_lifetimeValues.emplace_back(MPTV_KEEP_EIGHT_MONTHS, strKeepString);
633
634 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 9);
635 m_lifetimeValues.emplace_back(MPTV_KEEP_NINE_MONTHS, strKeepString);
636
637 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 10);
638 m_lifetimeValues.emplace_back(MPTV_KEEP_TEN_MONTHS, strKeepString);
639
640 snprintf(strKeepString, cKeepStringLength, strMonths.c_str(), 11);
641 m_lifetimeValues.emplace_back(MPTV_KEEP_ELEVEN_MONTHS, strKeepString);
642
643 m_lifetimeValues.emplace_back(MPTV_KEEP_ONE_YEAR, kodi::addon::GetLocalizedString(30140));
644 }
645
646 void cLifeTimeValues::SetLifeTimeValues(kodi::addon::PVRTimerType& timertype)
647 {
648 timertype.SetLifetimes(m_lifetimeValues, -MPTV_KEEP_ALWAYS); //Negative = special types, positive values is days
649
650 //select default keep method
651 switch (CSettings::Get().GetKeepMethodType())
652 {
653 case TvDatabase::UntilSpaceNeeded: //until space needed
654 timertype.SetLifetimesDefault(-MPTV_KEEP_UNTIL_SPACE_NEEDED); //Negative = special types, positive values is days
655 break;
656
657 case TvDatabase::UntilWatched: //until watched
658 timertype.SetLifetimesDefault(-MPTV_KEEP_UNTIL_WATCHED); //Negative = special types, positive values is days
659 break;
660
661 case TvDatabase::TillDate: //until keepdate
662 //use defaultrecordinglifetime value from settings.xml
663 timertype.SetLifetimesDefault(CSettings::Get().GetDefaultRecordingLifeTime());
664 break;
665
666 case TvDatabase::Always: //forever
667 default:
668 break;
669 }
670 }
671
672 namespace Timer
673 {
674 // Life time values for the recordings
675 cLifeTimeValues* lifetimeValues = NULL;
676 };