vdr-plugin-softhddevice-drm-gles 1.5.9-20e15de
softhdmenu.cpp
Go to the documentation of this file.
1
21#include <string>
22
23#include <vdr/interface.h>
24#include <vdr/osdbase.h>
25#include <vdr/plugin.h>
26#include <vdr/videodir.h>
27
28#include "logger.h"
29#include "mediaplayer.h"
30#include "softhddevice.h"
31#include "softhdmenu.h"
32
33/*****************************************************************************
34 * cSoftHdMenu
35 ****************************************************************************/
36
40cSoftHdMenu::cSoftHdMenu(const char *title, cSoftHdDevice *device,
41 int c0, int c1, int c2, int c3, int c4)
42 : cOsdMenu(title, c0, c1, c2, c3, c4),
43 m_pDevice(device)
44{
45 pSoftHdMenu = this;
46 m_playlist.clear();
47
48 if (cSoftHdControl::Control() && cSoftHdControl::Control()->Player()->GetFirstPlaylistEntry()) {
49 LOGDEBUG2(L_MEDIA, "mediaplayer: %s: pointer to cSoftHdControl exist.", __FUNCTION__);
50 PlayListMenu(); // Test if PL!!!
51 } else {
52 MainMenu();
53 }
54}
55
63
69static inline cOsdItem *SeparatorName(const char *label)
70{
71 return new cOsdItem(cString::sprintf("%s:", label), osUnknown, false);
72}
73
79static inline cOsdItem *SeparatorSpace(void)
80{
81 return new cOsdItem(" ", osUnknown, false);
82}
83
88{
89 int current;
90
91 current = Current(); // get current menu item index
92 Clear(); // clear the menu
93
94 // pip
95 if (m_pDevice->UsePip()) {
96 Add(SeparatorName("PIP"));
97 Add(new cOsdItem(hk(tr(" Toggle")), osUser1));
98 Add(new cOsdItem(hk(tr(" Channel +")), osUser2));
99 Add(new cOsdItem(hk(tr(" Channel -")), osUser3));
100 Add(new cOsdItem(hk(tr(" Swap channels")), osUser4));
101 Add(new cOsdItem(hk(tr(" Swap position")), osUser5));
102 Add(new cOsdItem(hk(tr(" Switch to pip channel")), osUser6));
103 }
104
105 Add(SeparatorSpace());
106
107 // detach
108 Add(SeparatorName("Detach"));
109 Add(new cOsdItem(hk(tr(" Detach device")), osUser7));
110
111 Add(SeparatorSpace());
112
113 // mediaplayer
114 Add(SeparatorName("Mediaplayer"));
115 Add(new cOsdItem(hk(tr(" play file / make play list")), osUser8));
116 Add(new cOsdItem(hk(tr(" select play list")), osUser9));
117
118 SetCurrent(Get(current)); // restore selected menu entry
119 Display();
120}
121
134
139 switch (code) {
140 // pip
141 case PIPTOGGLEONOFF:
143 break;
144 case PIPCHANNELUP:
146 break;
147 case PIPCHANNELDOWN:
149 break;
150 case PIPCHANNELSWAP:
152 break;
153 case PIPPOSITIONSWAP:
155 break;
158 break;
159 // detach/ attach
160 case DETACHDEVICE:
161 m_pDevice->Detach();
162 break;
163 case ATTACHDEVICE:
164 m_pDevice->Attach();
165 break;
166 default:
167 break;
168 }
169}
170
176eOSState cSoftHdMenu::ProcessKey(eKeys key)
177{
178 eOSState state;
179 cOsdItem *item;
180
181 switch (m_hotkeyState) {
183 if (key == kBlue) {
184 if (!m_pDevice->UsePip())
185 return osEnd;
186
188 return osContinue;
189 }
190 if (key == kRed) {
192 return osContinue;
193 }
194 break;
195 case HotkeyState::Blue: // pip
196 if (k0 <= key && key <= k9) {
197 int hotkeyCode = PIPKEYBASE + key - k0;
199 HandleHotKey(hotkeyCode);
200 return osEnd;
201 }
203 break;
204 case HotkeyState::Red: // detach/ attach
205 if (k0 <= key && key <= k9) {
206 int hotkeyCode = DETACHKEYBASE + key - k0;
208 HandleHotKey(hotkeyCode);
209 return osEnd;
210 }
212 break;
213 }
214
215 item = (cOsdItem *) Get(Current());
216 state = cOsdMenu::ProcessKey(key);
217
218 switch (state) {
219 // pip
220 case osUser1: // toggle pip
222 return osEnd;
223 case osUser2: // pip channel +
225 return osEnd;
226 case osUser3: // pip channel -
228 return osEnd;
229 case osUser4: // pip channel swap
231 return osEnd;
232 case osUser5: // pip position swap
234 return osEnd;
235 case osUser6: // pip switch main stream back to pip stream and close pip
237 return osEnd;
238
239 // detach
240 case osUser7: // detach device
241 m_pDevice->Detach();
242 return osEnd;
243
244 // mediaplayer
245 case osUser8: // play file / make play list
246 m_path = cVideoDirectory::Name();
247 FindFileMenu(m_path, NULL);
248 return osContinue;
249 case osUser9: // select play list
250 m_path = cPlugin::ConfigDirectory("softhddevice-drm-gles");
252 return osContinue;
253 default:
254 break;
255 }
256
257 switch (key) {
258 case kOk:
259 if (strcasestr(item->Text(), "[..]")) {
260 std::string newPath = m_path.substr(0 ,m_path.find_last_of("/"));
261
262 if (!m_lastItem.empty())
263 m_lastItem.clear();
264 m_lastItem = m_path.substr(m_path.find_last_of("/") + 1);
265
266 m_path = newPath;
267 FindFileMenu(m_path.c_str(), NULL);
268 break;
269 }
270 if (cSoftHdControl::Control() && cSoftHdControl::Control()->Player()->GetCurrentPlaylistEntry()) {
271 cSoftHdControl::Control()->Player()->SetEntry(Current());
272// PlayListMenu();
273 break;
274 }
275 if (IsValidMediaFile(item->Text())) {
276 PlayMedia(item->Text());
277 return osEnd;
278 } else {
279 std::string newPath = m_path + "/" + item->Text();
280 struct stat sb;
281 if (stat(newPath.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
282 m_path = newPath;
283 FindFileMenu(newPath.c_str(), NULL);
284 }
285 }
286 break;
287 case kRed:
288 if (cSoftHdControl::Control() && cSoftHdControl::Control()->Player()->GetCurrentPlaylistEntry()) {
290 PlayListMenu();
291 break;
292 }
293 if (m_playlist.empty()) {
294 if (IsValidMediaFile(item->Text())) {
295 PlayMedia(item->Text());
296 return osEnd;
297 }
298 } else {
299 m_path = cPlugin::ConfigDirectory("softhddevice-drm-gles");
300 PlayMedia(m_playlist.c_str());
301 return osEnd;
302 }
303 break;
304 case kGreen:
307 } else {
308 MakePlayList(item->Text(), "w");
309 Interface->Confirm(tr("New Playlist"), 1, true);
310 if (!m_lastItem.empty())
311 m_lastItem.clear();
312 m_lastItem = item->Text();
313 FindFileMenu(m_path.c_str(), NULL);
314 }
315 break;
316 case kYellow:
319 } else {
320 MakePlayList(item->Text(), "a");
321 Interface->Confirm(tr("Added to Playlist"), 1, true);
322 }
323 break;
324 case kBlue:
325 state = osStopReplay;
326 break;
327 case kPlay:
328 if (IsValidMediaFile(item->Text())) {
329 PlayMedia(item->Text());
330 return osEnd;
331 }
332 break;
333 case kNext:
336 break;
337 default:
338 break;
339 }
340
341 return state;
342}
343
344/*****************************************************************************
345 * Mediaplayer sub menus
346 ****************************************************************************/
347
352{
354 Clear();
355 while (1) {
356 std::string p_string = entry->OsdItemString();
357 Add(new cOsdItem(p_string.c_str()), (entry == cSoftHdControl::Control()->Player()->GetCurrentPlaylistEntry()));
358
359 if (!entry->GetNextEntry())
360 break;
361
362 entry = entry->GetNextEntry();
363 }
364 SetHelp(cSoftHdControl::Control()->Player()->IsRandomPlayActive() ? "Random Play" : " No Random Play",
365 "Jump -1 min", "Jump +1 min", "End player");
366 Display();
367}
368
373{
374 struct dirent **dirList;
375 int n, i;
376
377 if ((n = scandir(cPlugin::ConfigDirectory("softhddevice-drm-gles"), &dirList, NULL, alphasort)) == -1) {
378 LOGERROR("mediaplayer: %s: searching PL in %s failed (%d): %m", __FUNCTION__,
379 cPlugin::ConfigDirectory("softhddevice-drm-gles"), errno);
380 return;
381 }
382
383 Clear();
384 for (i = 0; i < n; i++) {
385 if (dirList[i]->d_name[0] != '.' && (strcasestr(dirList[i]->d_name, ".M3U"))) {
386 Add(new cOsdItem(dirList[i]->d_name));
387 }
388 }
389 SetHelp("Play PL", NULL, NULL, NULL);
390 Display();
391}
392
399void cSoftHdMenu::FindFileMenu(std::string searchPath, FILE *playlist)
400{
401 struct dirent **dirList;
402 int n, i;
403 const char * sp;
404
405 if (!searchPath.size())
406 sp = "/";
407 else
408 sp = searchPath.c_str();
409
410 if (!playlist) {
411 Clear();
412 if (searchPath.size())
413 Add(new cOsdItem("[..]"));
414 }
415
416 if ((n = scandir(sp, &dirList, NULL, alphasort)) == -1) {
417 LOGERROR("mediaplayer: %s: scanning directory %s failed (%d): %m", __FUNCTION__, sp, errno);
418 } else {
419 struct stat fileAttributs;
420 for (i = 0; i < n; i++) {
421 std::string str = searchPath + "/" + dirList[i]->d_name;
422 if (stat(str.c_str(), &fileAttributs) == -1) {
423 LOGERROR("mediaplayer: %s: stat on %s failed (%d): %m", __FUNCTION__, str.c_str(), errno);
424 } else {
425 if (S_ISDIR(fileAttributs.st_mode) && dirList[i]->d_name[0] != '.') {
426 if (playlist) {
427 FindFileMenu(str.c_str(), playlist);
428 } else {
429 Add(new cOsdItem(dirList[i]->d_name),
430 !m_lastItem.compare(0, m_lastItem.length(), dirList[i]->d_name));
431 }
432 }
433 }
434 }
435 for (i = 0; i < n; i++) {
436 std::string str = searchPath + "/" + dirList[i]->d_name;
437 if (stat(str.c_str(), &fileAttributs) == -1) {
438 LOGERROR("mediaplayer: %s: stat on %s failed (%d): %m", __FUNCTION__, str.c_str(), errno);
439 } else {
440 if (S_ISREG(fileAttributs.st_mode) && dirList[i]->d_name[0] != '.') {
441 if (playlist) {
442 if (IsValidMediaFile(dirList[i]->d_name))
443 fprintf(playlist, "%s/%s\n", searchPath.c_str(),
444 dirList[i]->d_name);
445 } else {
446 Add(new cOsdItem(dirList[i]->d_name));
447 }
448 }
449 }
450 }
451 }
452
453 if (!playlist) {
454 SetHelp( m_playlist.empty() ? "Play File" : "Play PL", "New PL", "Add to PL", NULL);
455// SetHelp(Control->Player->Running ? NULL : "Set new PL",
456// Control->Player->Running ? "Play Menu" : "Select PL");
457 Display();
458 }
459}
460
467void cSoftHdMenu::MakePlayList(const char * target, const char * mode)
468{
469 if (m_playlist.empty())
470 m_playlist = "/default.m3u";
471
472 std::string plPath = cPlugin::ConfigDirectory("softhddevice-drm-gles");
473 plPath.append(m_playlist.c_str());
474 FILE *playlist = fopen(plPath.c_str(), mode);
475
476 if (!playlist)
477 return;
478
479 if (IsValidMediaFile(target)) {
480 fprintf(playlist, "%s/%s\n", m_path.c_str(), target);
481 } else {
482 std::string str = m_path + "/" + target;
483 FindFileMenu(str.c_str(), playlist);
484 }
485
486 fclose (playlist);
487}
488
494void cSoftHdMenu::PlayMedia(const char *name)
495{
496 std::string aim = m_path + "/" + name;
498 cControl::Launch(new cSoftHdControl(aim.c_str(), m_pDevice));
499 } else {
500 LOGERROR("mediaplayer: %s: can't start %s", __FUNCTION__, aim.c_str());
501 }
502}
503
510int cSoftHdMenu::IsValidMediaFile(const char *name)
511{
512 if (strcasestr(name, ".MP3") ||
513 strcasestr(name, ".MP4") ||
514 strcasestr(name, ".MKV") ||
515 strcasestr(name, ".MPG") ||
516 strcasestr(name, ".AVI") ||
517 strcasestr(name, ".M2TS") ||
518 strcasestr(name, ".MPEG") ||
519 strcasestr(name, ".M3U") ||
520 strcasestr(name, ".TS")) {
521
522 return 1;
523 }
524
525 return 0;
526}
std::string OsdItemString(void)
Compose a full-path-string for the OSD entry.
cPlaylistEntry * GetNextEntry(void)
Definition mediaplayer.h:43
static cSoftHdControl * Control()
static cSoftHdPlayer * Player()
void PipChannelSwap(bool)
void PipSwapPosition(void)
bool UsePip(void)
void Detach(void)
Detach the device.
void PipToggle(void)
void PipChannelChange(int)
void Attach(void)
Attach the device again.
int IsValidMediaFile(const char *)
Test if it's a media file - at least if it has the right file extension...
static cSoftHdMenu * pSoftHdMenu
Definition softhdmenu.h:45
void MainMenu(void)
Create main menu.
void PlayListMenu(void)
Create mediaplayer playlist menu.
std::string m_lastItem
Definition softhdmenu.h:66
cSoftHdMenu(const char *, cSoftHdDevice *, int=0, int=0, int=0, int=0, int=0)
Softhddevice menu constructor.
virtual ~cSoftHdMenu()
Softhddevice menu destructor.
virtual eOSState ProcessKey(eKeys)
Handle key event.
std::string m_playlist
Definition softhdmenu.h:67
void PlayMedia(const char *)
Play media file.
HotkeyState m_hotkeyState
Definition softhdmenu.h:55
void MakePlayList(const char *, const char *)
Make a play list.
void FindFileMenu(std::string, FILE *)
Create mediaplayer sub menu find file or make a play list.
void HandleHotKey(int)
Handle a key code which was compose by hotkey handling in ProcessKey()
cSoftHdDevice * m_pDevice
Definition softhdmenu.h:53
void SelectPlaylistMenu(void)
Create mediaplayer select playlist menu.
std::string m_path
Definition softhdmenu.h:65
void JumpSec(int seconds)
Definition mediaplayer.h:68
void ToggleRandomPlay(void)
Definition mediaplayer.h:72
void Stop(void)
Definition mediaplayer.h:71
cPlaylistEntry * GetFirstPlaylistEntry(void)
Definition mediaplayer.h:76
cPlaylistEntry * GetCurrentPlaylistEntry(void)
Definition mediaplayer.h:77
void SetEntry(int)
Set the current entry to play.
Logger class header file.
#define LOGDEBUG2
Definition logger.h:45
#define LOGERROR
Definition logger.h:41
#define L_MEDIA
Definition logger.h:61
Mediaplayer class header file.
int code
Definition openglosd.h:39
Device class header file.
static cOsdItem * SeparatorName(const char *label)
Create a seperator item.
Hotkeys
@ PIPCHANNELSWAP
@ PIPCHANNELDOWN
@ DETACHKEYBASE
@ PIPPOSITIONSWAP
@ PIPCHANNELSWITCHBACK
@ DETACHDEVICE
@ ATTACHDEVICE
@ PIPTOGGLEONOFF
@ PIPCHANNELUP
@ PIPKEYBASE
static cOsdItem * SeparatorSpace(void)
Create a seperator item.
Softhddevice menu class header file.
@ Initial
Definition softhdmenu.h:35
@ Red
Definition softhdmenu.h:37
@ Blue
Definition softhdmenu.h:36