forked from flensrocker/vdr-plugin-recsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_recordings.c
411 lines (378 loc) · 12.6 KB
/
menu_recordings.c
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
#include "menu_recordings.h"
#if APIVERSNUM < 20103
#include <vdr/cutter.h>
#include <vdr/interface.h>
#include <vdr/menu.h>
#include <vdr/remote.h>
#include <vdr/status.h>
#include <vdr/videodir.h>
// --- cMenuRecording --------------------------------------------------------
namespace recsearch
{
class cMenuRecording : public cOsdMenu {
private:
const cRecording *recording;
bool withButtons;
public:
cMenuRecording(const cRecording *Recording, bool WithButtons = false);
virtual void Display(void);
virtual eOSState ProcessKey(eKeys Key);
};
}
recsearch::cMenuRecording::cMenuRecording(const cRecording *Recording, bool WithButtons)
:cOsdMenu(trVDR("Recording info"))
{
SetMenuCategory(mcRecordingInfo);
recording = Recording;
withButtons = WithButtons;
if (withButtons)
SetHelp(trVDR("Button$Play"), trVDR("Button$Rewind"));
}
void recsearch::cMenuRecording::Display(void)
{
cOsdMenu::Display();
DisplayMenu()->SetRecording(recording);
if (recording->Info()->Description())
cStatus::MsgOsdTextItem(recording->Info()->Description());
}
eOSState recsearch::cMenuRecording::ProcessKey(eKeys Key)
{
switch (int(Key)) {
case kUp|k_Repeat:
case kUp:
case kDown|k_Repeat:
case kDown:
case kLeft|k_Repeat:
case kLeft:
case kRight|k_Repeat:
case kRight:
DisplayMenu()->Scroll(NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft, NORMALKEY(Key) == kLeft || NORMALKEY(Key) == kRight);
cStatus::MsgOsdTextItem(NULL, NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft);
return osContinue;
case kInfo: return osBack;
default: break;
}
eOSState state = cOsdMenu::ProcessKey(Key);
if (state == osUnknown) {
switch (Key) {
case kRed: if (withButtons)
Key = kOk; // will play the recording, even if recording commands are defined
case kGreen: if (!withButtons)
break;
cRemote::Put(Key, true);
// continue with osBack to close the info menu and process the key
case kOk: return osBack;
default: break;
}
}
return state;
}
// --- cMenuRecordingItem ----------------------------------------------------
namespace recsearch
{
class cMenuRecordingItem : public cOsdItem {
private:
cRecording *recording;
int level;
char *name;
int totalEntries, newEntries;
public:
cMenuRecordingItem(cRecording *Recording, int Level);
~cMenuRecordingItem();
void IncrementCounter(bool New);
const char *Name(void) { return name; }
cRecording *Recording(void) { return recording; }
bool IsDirectory(void) { return name != NULL; }
virtual void SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable);
};
}
recsearch::cMenuRecordingItem::cMenuRecordingItem(cRecording *Recording, int Level)
{
recording = Recording;
level = Level;
name = NULL;
totalEntries = newEntries = 0;
SetText(Recording->Title('\t', true, Level));
if (*Text() == '\t')
name = strdup(Text() + 2); // 'Text() + 2' to skip the two '\t'
}
recsearch::cMenuRecordingItem::~cMenuRecordingItem()
{
free(name);
}
void recsearch::cMenuRecordingItem::IncrementCounter(bool New)
{
totalEntries++;
if (New)
newEntries++;
SetText(cString::sprintf("%d\t\t%d\t%s", totalEntries, newEntries, name));
}
void recsearch::cMenuRecordingItem::SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable)
{
if (!DisplayMenu->SetItemRecording(recording, Index, Current, Selectable, level, totalEntries, newEntries))
DisplayMenu->SetItem(Text(), Index, Current, Selectable);
}
// --- cMenuRecordings -------------------------------------------------------
recsearch::cMenuRecordings::cMenuRecordings(const char *Base, int Level, bool OpenSubMenus, const cRecordingFilter *Filter)
:cOsdMenu(Base ? Base : trVDR("Recordings"), 9, 6, 6)
,filter(Filter)
{
SetMenuCategory(mcRecording);
base = Base ? strdup(Base) : NULL;
level = Setup.RecordingDirs ? Level : -1;
Recordings.StateChanged(recordingsState); // just to get the current state
helpKeys = -1;
Display(); // this keeps the higher level menus from showing up briefly when pressing 'Back' during replay
Set();
if (Current() < 0)
SetCurrent(First());
else if (OpenSubMenus && cReplayControl::LastReplayed() && Open(true))
return;
Display();
SetHelpKeys();
}
recsearch::cMenuRecordings::~cMenuRecordings()
{
helpKeys = -1;
free(base);
}
void recsearch::cMenuRecordings::SetHelpKeys(void)
{
cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current());
int NewHelpKeys = 0;
if (ri) {
if (ri->IsDirectory())
NewHelpKeys = 1;
else {
NewHelpKeys = 2;
if (ri->Recording()->Info()->Title())
NewHelpKeys = 3;
}
}
if (NewHelpKeys != helpKeys) {
switch (NewHelpKeys) {
case 0: SetHelp(NULL); break;
case 1: SetHelp(trVDR("Button$Open")); break;
case 2:
case 3: SetHelp(RecordingCommands.Count() ? trVDR("Commands") : trVDR("Button$Play"), trVDR("Button$Rewind"), trVDR("Button$Delete"), NewHelpKeys == 3 ? trVDR("Button$Info") : NULL);
default: ;
}
helpKeys = NewHelpKeys;
}
}
void recsearch::cMenuRecordings::Set(bool Refresh)
{
const char *CurrentRecording = cReplayControl::LastReplayed();
cMenuRecordingItem *LastItem = NULL;
cThreadLock RecordingsLock(&Recordings);
if (Refresh) {
if (cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current()))
CurrentRecording = ri->Recording()->FileName();
}
Clear();
GetRecordingsSortMode(DirectoryName());
Recordings.Sort();
for (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))) {
cMenuRecordingItem *Item = new cMenuRecordingItem(recording, level);
cMenuRecordingItem *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 (cMenuRecordingItem *p = LastItem; p; p = dynamic_cast<cMenuRecordingItem *>(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 (CurrentRecording && strcmp(CurrentRecording, recording->FileName()) == 0)
SetCurrent(LastDir ? LastDir : LastItem);
}
if (LastDir)
LastDir->IncrementCounter(recording->IsNew());
}
}
if (Refresh)
Display();
}
cString recsearch::cMenuRecordings::DirectoryName(void)
{
cString d(VideoDirectory);
if (base) {
char *s = ExchangeChars(strdup(base), true);
d = AddDirectory(d, s);
free(s);
}
return d;
}
bool recsearch::cMenuRecordings::Open(bool OpenSubMenus)
{
cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current());
if (ri && ri->IsDirectory()) {
const char *t = ri->Name();
cString buffer;
if (base) {
buffer = cString::sprintf("%s~%s", base, t);
t = buffer;
}
AddSubMenu(new cMenuRecordings(t, level + 1, OpenSubMenus, filter));
return true;
}
return false;
}
eOSState recsearch::cMenuRecordings::Play(void)
{
cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current());
if (ri) {
if (ri->IsDirectory())
Open();
else {
cReplayControl::SetRecording(ri->Recording()->FileName());
return osReplay;
}
}
return osContinue;
}
eOSState recsearch::cMenuRecordings::Rewind(void)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
cMenuRecordingItem *ri = (cMenuRecordingItem *)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 recsearch::cMenuRecordings::Delete(void)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current());
if (ri && !ri->IsDirectory()) {
if (Interface->Confirm(trVDR("Delete recording?"))) {
cRecordControl *rc = cRecordControls::GetRecordControl(ri->Recording()->FileName());
if (rc) {
if (Interface->Confirm(trVDR("Timer still recording - really delete?"))) {
cTimer *timer = rc->Timer();
if (timer) {
timer->Skip();
cRecordControls::Process(time(NULL));
if (timer->IsSingleEvent()) {
isyslog("deleting timer %s", *timer->ToDescr());
Timers.Del(timer);
}
Timers.SetModified();
}
}
else
return osContinue;
}
cRecording *recording = ri->Recording();
cString FileName = recording->FileName();
if (cCutter::Active(ri->Recording()->FileName())) {
if (Interface->Confirm(trVDR("Recording is being edited - really delete?"))) {
cCutter::Stop();
recording = Recordings.GetByName(FileName); // cCutter::Stop() might have deleted it if it was the edited version
// we continue with the code below even if recording is NULL,
// in order to have the menu updated etc.
}
else
return osContinue;
}
if (cReplayControl::NowReplaying() && strcmp(cReplayControl::NowReplaying(), FileName) == 0)
cControl::Shutdown();
if (!recording || recording->Delete()) {
cReplayControl::ClearLastReplayed(FileName);
Recordings.DelByName(FileName);
cOsdMenu::Del(Current());
SetHelpKeys();
cVideoDiskUsage::ForceCheck();
Display();
if (!Count())
return osBack;
}
else
Skins.Message(mtError, trVDR("Error while deleting recording!"));
}
}
return osContinue;
}
eOSState recsearch::cMenuRecordings::Info(void)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current());
if (ri && !ri->IsDirectory() && ri->Recording()->Info()->Title())
return AddSubMenu(new cMenuRecording(ri->Recording(), true));
return osContinue;
}
eOSState recsearch::cMenuRecordings::Commands(eKeys Key)
{
if (HasSubMenu() || Count() == 0)
return osContinue;
cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current());
if (ri && !ri->IsDirectory()) {
cMenuCommands *menu;
eOSState state = AddSubMenu(menu = new cMenuCommands(trVDR("Recording commands"), &RecordingCommands, cString::sprintf("\"%s\"", *strescape(ri->Recording()->FileName(), "\\\"$"))));
if (Key != kNone)
state = menu->ProcessKey(Key);
return state;
}
return osContinue;
}
eOSState recsearch::cMenuRecordings::Sort(void)
{
if (HasSubMenu())
return osContinue;
IncRecordingsSortMode(DirectoryName());
Set(true);
return osContinue;
}
eOSState recsearch::cMenuRecordings::ProcessKey(eKeys Key)
{
bool HadSubMenu = HasSubMenu();
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...k9: return Commands(Key);
case kNone: if (Recordings.StateChanged(recordingsState))
Set(true);
break;
default: break;
}
}
if (Key == kYellow && HadSubMenu && !HasSubMenu()) {
// the last recording in a subdirectory was deleted, so let's go back up
cOsdMenu::Del(Current());
if (!Count())
return osBack;
Display();
}
if (!HasSubMenu()) {
if (Key != kNone)
SetHelpKeys();
}
return state;
}
#endif