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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
/*
* menurec.c: EPG2VDR plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <vdr/menuitems.h>
#include <vdr/status.h>
#include <vdr/menu.h>
#include <vdr/videodir.h>
#include <vdr/interface.h>
#include "lib/xml.h"
#include "plgconfig.h"
#include "menu.h"
#include "ttools.h"
//***************************************************************************
// Class cMenuDbRecordingItem
//***************************************************************************
class cMenuDbRecordingItem : public cOsdItem
{
public:
cMenuDbRecordingItem(cMenuDb* db, const cRecording* Recording);
virtual ~cMenuDbRecordingItem();
const char* Name() const { return name; }
int Level() const { return level; }
const cRecording* Recording() const { return recording; }
bool IsDirectory() const { return false; }
void SetRecording(const cRecording* Recording) { recording = Recording; }
virtual void SetMenuItem(cSkinDisplayMenu* DisplayMenu, int Index, bool Current, bool Selectable);
private:
const cRecording* recording {nullptr};
int level {0};
char* name {nullptr};
cMenuDb* menuDb {nullptr};
};
cMenuDbRecordingItem::cMenuDbRecordingItem(cMenuDb* db, const cRecording* Recording)
{
menuDb = db;
recording = Recording;
name = nullptr;
for (const char* p = Recording->Title(); *p; p++)
if (*p == '~')
level++;
SetText(Recording->Title('\t', true, level));
tell(0, "Added recording for file '%s'", Recording->Title());
// SetText(menuDb->recordingListDb->getStrValue("TITLE"));
// a folder?
if (*Text() == '\t')
name = strdup(Text() + 2); // 'Text() + 2' to skip the two '\t'
}
cMenuDbRecordingItem::~cMenuDbRecordingItem()
{
free(name);
}
void cMenuDbRecordingItem::SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable)
{
if (!DisplayMenu->SetItemRecording(recording, Index, Current, Selectable, level, 0, 0))
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
}
//***************************************************************************
// Class cMenuDbRecordingItem
//***************************************************************************
class cMenuDbRecordingFolderItem : public cOsdItem
{
public:
cMenuDbRecordingFolderItem(cMenuDb* db, const char* title);
virtual ~cMenuDbRecordingFolderItem();
void IncrementCounter(bool New);
const char* Name() const { return name; }
bool IsDirectory() const { return true; }
virtual void SetMenuItem(cSkinDisplayMenu* DisplayMenu, int Index, bool Current, bool Selectable);
private:
cRecording* tmpRecording {nullptr};
char* name {nullptr};
int totalEntries {0}, newEntries {0};
cMenuDb* menuDb {nullptr};
};
cMenuDbRecordingFolderItem::cMenuDbRecordingFolderItem(cMenuDb* db, const char* title)
{
menuDb = db;
name = strdup(title);
if (tmpRecording)
{
delete tmpRecording;
tmpRecording = nullptr;
}
char* dummy;
asprintf(&dummy, "%s/%s", name, "2018-07-22.20.12.8-0.rec");
tmpRecording = new cRecording(dummy);
// tmpRecording->ChangeName(name);
SetText(tmpRecording->Title());
free(dummy);
}
cMenuDbRecordingFolderItem::~cMenuDbRecordingFolderItem()
{
free(name);
delete tmpRecording;
}
void cMenuDbRecordingFolderItem::SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable)
{
if (!DisplayMenu->SetItemRecording(tmpRecording, Index, Current, Selectable, 0, totalEntries, newEntries))
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
}
//***************************************************************************
// Class cMenuDbRecordings
//***************************************************************************
cString cMenuDbRecordings::path;
cString cMenuDbRecordings::fileName;
cMenuDbRecordings::cMenuDbRecordings(const char* Base, int Level, bool OpenSubMenus)
: cOsdMenu(Base ? Base : tr("Recordings"), 9, 6, 6)
{
menuDb = new cMenuDb;
SetMenuCategory(mcRecording);
base = Base ? strdup(Base) : nullptr;
level = Setup.RecordingDirs ? Level : -1;
Display(); // this keeps the higher level menus from showing up briefly when pressing 'Back' during replay
if (menuDb->dbConnected())
{
LoadGrouped(); // LoadPlain();
}
if (Current() < 0)
SetCurrent(First());
else if (OpenSubMenus && (cReplayControl::LastReplayed() || *path || *fileName))
{
if (!*path || Level < strcountchr(path, FOLDERDELIMCHAR))
{
if (Open(true))
return;
}
}
Display();
SetHelpKeys();
}
cMenuDbRecordings::~cMenuDbRecordings()
{
cMenuDbRecordingItem* ri = (cMenuDbRecordingItem*)Get(Current());
if (ri && !ri->IsDirectory())
SetRecording(ri->Recording()->FileName());
delete menuDb;
free(base);
}
//***************************************************************************
//
//***************************************************************************
void cMenuDbRecordings::SetHelpKeys(void)
{
cMenuDbRecordingItem* ri = (cMenuDbRecordingItem*)Get(Current());
int NewHelpKeys = 0;
if (ri)
{
if (ri->IsDirectory())
NewHelpKeys = 1;
else
NewHelpKeys = 2;
}
if (NewHelpKeys != helpKeys)
{
switch (NewHelpKeys)
{
case 0: SetHelp(NULL); break;
case 1: SetHelp(tr("Button$Open"), NULL, NULL, tr("Button$Edit")); break;
case 2: SetHelp(RecordingCommands.Count() ? tr("Commands") : tr("Button$Play"), tr("Button$Rewind"), tr("Button$Delete"), tr("Button$Info"));
default: ;
}
helpKeys = NewHelpKeys;
}
}
//***************************************************************************
// Load Grouped
//***************************************************************************
void cMenuDbRecordings::LoadGrouped(bool Refresh)
{
Clear();
menuDb->recordingListDb->clear();
for (int res = menuDb->selectRecordingsGrouped->find(); res; res = menuDb->selectRecordingsGrouped->fetch())
{
char* folderTitle {nullptr};
asprintf(&folderTitle, "%s / %s",
menuDb->recordingListDb->getValue("CATEGORY")->isNull() ? "unknown" : menuDb->recordingListDb->getStrValue("CATEGORY"),
menuDb->recordingListDb->getValue("GENRE")->isNull() ? "unknown" : menuDb->recordingListDb->getStrValue("GENRE"));
tell(0, "Added recording folder '%s'", folderTitle);
Add(new cMenuDbRecordingFolderItem(menuDb, folderTitle));
free(folderTitle);
}
menuDb->selectRecordingsGrouped->freeResult();
if (Refresh)
Display();
return ;
}
//***************************************************************************
// Load Plain
//***************************************************************************
void cMenuDbRecordings::LoadPlain(bool Refresh)
{
if (!cRecordings::GetRecordingsRead(recordingsStateKey))
return ;
recordingsStateKey.Remove();
cRecordings* Recordings = cRecordings::GetRecordingsWrite(recordingsStateKey);
if (!Recordings)
{
tell(0, "Fatal: Can't get recording lock");
return ;
}
Clear();
menuDb->recordingListDb->clear();
for (int res = menuDb->selectRecordings->find(); res; res = menuDb->selectRecordings->fetch())
{
char* fileName {nullptr};
asprintf(&fileName, "%s/%s", cVideoDirectory::Name(), menuDb->recordingListDb->getStrValue("PATH"));
const cRecording* recording = Recordings->GetByName(fileName);
if (recording)
{
// tell(0, "Added recording for file '%s'", fileName);
Add(new cMenuDbRecordingItem(menuDb, recording));
}
else
tell(0, "Fatal: Recording for file '%s' not found", fileName);
free(fileName);
}
menuDb->selectRecordings->freeResult();
recordingsStateKey.Remove(false);
if (Refresh)
Display();
return ;
/*
// ------------------------------------------------------
if (!cRecordings::GetRecordingsRead(recordingsStateKey))
return ;
recordingsStateKey.Remove();
const char* CurrentRecording = *fileName ? *fileName : cReplayControl::LastReplayed();
cRecordings* Recordings = cRecordings::GetRecordingsWrite(recordingsStateKey); // write access is necessary for sorting!
cMenuDbRecordingItem *LastItem = NULL;
if (!CurrentRecording)
{
if (cMenuDbRecordingItem *ri = (cMenuDbRecordingItem*)Get(Current()))
CurrentRecording = ri->Recording()->FileName();
}
int current = Current();
Clear();
GetRecordingsSortMode(DirectoryName());
Recordings->Sort();
for (const cRecording *Recording = Recordings->First(); Recording; Recording = Recordings->Next(Recording))
{
if ((!filter || filter->Filter(Recording)) && (!base || (strstr(Recording->Name(), base) == Recording->Name() && Recording->Name()[strlen(base)] == FOLDERDELIMCHAR)))
{
cMenuDbRecordingItem *Item = new cMenuDbRecordingItem(Recording, level);
cMenuDbRecordingItem *LastDir = NULL;
if (Item->IsDirectory())
{
// Sorting may ignore non-alphanumeric characters, so we need to explicitly handle directories in case they only differ in such characters:
for (cMenuDbRecordingItem* p = LastItem; p; p = dynamic_cast<cMenuDbRecordingItem*>(p->Prev()))
{
if (p->Name() && strcmp(p->Name(), Item->Name()) == 0)
{
LastDir = p;
break;
}
}
}
if (*Item->Text() && !LastDir)
{
Add(Item);
LastItem = Item;
if (Item->IsDirectory())
LastDir = Item;
}
else
delete Item;
if (LastItem || LastDir)
{
if (*path)
{
if (strcmp(path, Recording->Folder()) == 0)
SetCurrent(LastDir ? LastDir : LastItem);
}
else if (CurrentRecording && strcmp(CurrentRecording, Recording->FileName()) == 0)
SetCurrent(LastDir ? LastDir : LastItem);
}
if (LastDir)
LastDir->IncrementCounter(Recording->IsNew());
}
}
if (Current() < 0)
SetCurrent(Get(current)); // last resort, in case the recording was deleted
SetMenuSortMode(RecordingsSortMode == rsmName ? msmName : msmTime);
recordingsStateKey.Remove(false); // sorting doesn't count as a real modification
if (Refresh)
Display();
*/
}
//***************************************************************************
//
//***************************************************************************
void cMenuDbRecordings::SetPath(const char *Path)
{
path = Path;
}
void cMenuDbRecordings::SetRecording(const char *FileName)
{
fileName = FileName;
}
cString cMenuDbRecordings::DirectoryName(void)
{
cString d(cVideoDirectory::Name());
if (base)
{
char *s = ExchangeChars(strdup(base), true);
d = AddDirectory(d, s);
free(s);
}
return d;
}
bool cMenuDbRecordings::Open(bool OpenSubMenus)
{
cMenuDbRecordingItem* ri = (cMenuDbRecordingItem*)Get(Current());
if (ri && ri->IsDirectory() && (!*path || strcountchr(path, FOLDERDELIMCHAR) > 0))
{
const char* t = ri->Name();
cString buffer;
if (base)
{
buffer = cString::sprintf("%s%c%s", base, FOLDERDELIMCHAR, t);
t = buffer;
}
AddSubMenu(new cMenuDbRecordings(t, level + 1, OpenSubMenus));
return true;
}
return false;
}
eOSState cMenuDbRecordings::Play(void)
{
cMenuDbRecordingItem* ri = (cMenuDbRecordingItem*)Get(Current());
if (ri)
{
if (ri->IsDirectory())
Open();
else
{
cReplayControl::SetRecording(ri->Recording()->FileName());
return osReplay;
}
}
return osContinue;
}
eOSState cMenuDbRecordings::Rewind(void)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
cMenuDbRecordingItem *ri = (cMenuDbRecordingItem *)Get(Current());
if (ri && !ri->IsDirectory())
{
cDevice::PrimaryDevice()->StopReplay(); // must do this first to be able to rewind the currently replayed recording
cResumeFile ResumeFile(ri->Recording()->FileName(), ri->Recording()->IsPesRecording());
ResumeFile.Delete();
return Play();
}
return osContinue;
}
/*
eOSState cMenuDbRecordings::Delete(void)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
cMenuDbRecordingItem *ri = (cMenuDbRecordingItem *)Get(Current());
if (ri && !ri->IsDirectory()) {
if (Interface->Confirm(tr("Delete recording?"))) {
if (cRecordControl *rc = cRecordControls::GetRecordControl(ri->Recording()->FileName())) {
if (Interface->Confirm(tr("Timer still recording - really delete?"))) {
if (cTimer *Timer = rc->Timer()) {
LOCK_TIMERS_WRITE;
Timer->Skip();
cRecordControls::Process(Timers, time(NULL));
if (Timer->IsSingleEvent()) {
Timers->Del(Timer);
isyslog("deleted timer %s", *Timer->ToDescr());
}
}
}
else
return osContinue;
}
cString FileName;
{
LOCK_RECORDINGS_READ;
if (const cRecording *Recording = Recordings->GetByName(ri->Recording()->FileName())) {
FileName = Recording->FileName();
if (RecordingsHandler.GetUsage(FileName)) {
if (!Interface->Confirm(tr("Recording is being edited - really delete?")))
return osContinue;
}
}
}
RecordingsHandler.Del(FileName); // must do this w/o holding a lock, because the cleanup section in cDirCopier::Action() might request one!
if (cReplayControl::NowReplaying() && strcmp(cReplayControl::NowReplaying(), FileName) == 0)
cControl::Shutdown();
cRecordings *Recordings = cRecordings::GetRecordingsWrite(recordingsStateKey);
Recordings->SetExplicitModify();
cRecording *Recording = Recordings->GetByName(FileName);
if (!Recording || Recording->Delete()) {
cReplayControl::ClearLastReplayed(FileName);
Recordings->DelByName(FileName);
cOsdMenu::Del(Current());
SetHelpKeys();
cVideoDiskUsage::ForceCheck();
Recordings->SetModified();
recordingsStateKey.Remove();
Display();
if (!Count())
return osUserRecEmpty;
return osUserRecRemoved;
}
else
Skins.Message(mtError, tr("Error while deleting recording!"));
recordingsStateKey.Remove();
}
}
return osContinue;
}
*/
/*
eOSState cMenuDbRecordings::Info(void)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
if (cMenuDbRecordingItem *ri = (cMenuDbRecordingItem *)Get(Current())) {
if (ri->IsDirectory())
return AddSubMenu(new cMenuPathEdit(cString(ri->Recording()->Name(), strchrn(ri->Recording()->Name(), FOLDERDELIMCHAR, ri->Level() + 1))));
else
return AddSubMenu(new cMenuRecording(ri->Recording(), true));
}
return osContinue;
}
*/
eOSState cMenuDbRecordings::Commands(eKeys Key)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
cMenuDbRecordingItem *ri = (cMenuDbRecordingItem *)Get(Current());
if (ri && !ri->IsDirectory())
{
cMenuCommands *menu;
eOSState state = AddSubMenu(menu = new cMenuCommands(tr("Recording commands"), &RecordingCommands, cString::sprintf("\"%s\"", *strescape(ri->Recording()->FileName(), "\\\"$"))));
if (Key != kNone)
state = menu->ProcessKey(Key);
return state;
}
return osContinue;
}
eOSState cMenuDbRecordings::Sort()
{
LoadPlain();
return osContinue;
}
eOSState cMenuDbRecordings::ProcessKey(eKeys Key)
{
eOSState state = cOsdMenu::ProcessKey(Key);
if (state == osUnknown)
{
switch (Key)
{
case kPlayPause:
case kPlay:
case kOk: return Play();
case kRed: return (helpKeys > 1 && RecordingCommands.Count()) ? Commands() : Play();
case kGreen: return Rewind();
// case kYellow: return Delete();
case kInfo:
// case kBlue: return Info();
case k0: return Sort();
case k1:
case k2:
case k3:
case k4:
case k5:
case k6:
case k7:
case k8:
case k9: return Commands(Key);
default: break;
}
}
/*
else if (state == osUserRecRenamed) {
// a recording was renamed (within the same folder), so let's refresh the menu
CloseSubMenu(false); // this is the cMenuRecordingEdit/cMenuPathEdit
path = NULL;
fileName = NULL;
state = osContinue;
}
else if (state == osUserRecMoved) {
// a recording was moved to a different folder, so let's delete the old item
CloseSubMenu(false); // this is the cMenuRecordingEdit/cMenuPathEdit
path = NULL;
fileName = NULL;
cOsdMenu::Del(Current());
Set(); // the recording might have been moved into a new subfolder of this folder
if (!Count())
return osUserRecEmpty;
Display();
state = osUserRecRemoved;
}
else if (state == osUserRecRemoved) {
// a recording was removed from a sub folder, so update the current item
if (cOsdMenu *m = SubMenu()) {
if (cMenuDbRecordingItem *ri = (cMenuDbRecordingItem *)Get(Current())) {
if (cMenuDbRecordingItem *riSub = (cMenuDbRecordingItem *)m->Get(m->Current()))
ri->SetRecording(riSub->Recording());
}
}
// no state change here, this report goes upstream!
}
else if (state == osUserRecEmpty) {
// a subfolder became empty, so let's go back up
CloseSubMenu(false); // this is the now empty submenu
cOsdMenu::Del(Current()); // the menu entry of the now empty subfolder
Set(); // in case a recording was moved into a new subfolder of this folder
if (base && !Count()) // base: don't go up beyond the top level Recordings menu
return state;
Display();
state = osContinue;
}
*/
// if (!HasSubMenu())
// {
// Set(true);
// if (Key != kNone)
// SetHelpKeys();
// }
return state;
}
|