summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Hintukainen <phintuka@users.sourceforge.net>2013-01-09 21:11:27 +0200
committerPetri Hintukainen <phintuka@users.sourceforge.net>2013-01-09 21:16:07 +0200
commit1fe91e7362cc992d8375b7cb3de402ca61394bdf (patch)
treee3fb89222a397fb6cbd98adc707aa87536383358
parent30042f2bfcd7047bf19d507af862e952ffb9ae7b (diff)
downloadvdr-plugin-bluray-1fe91e7362cc992d8375b7cb3de402ca61394bdf.tar.gz
vdr-plugin-bluray-1fe91e7362cc992d8375b7cb3de402ca61394bdf.tar.bz2
Added simple disc library menu
-rw-r--r--Makefile2
-rw-r--r--README2
-rw-r--r--bluray.c14
-rw-r--r--discmenu.c161
-rw-r--r--discmenu.h27
-rw-r--r--discmgr.h4
6 files changed, 207 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 129abd1..a2a08b6 100644
--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,7 @@ DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
### The object files (add further files here):
-OBJS = $(PLUGIN).o bdplayer.o discmgr.o titlemenu.o
+OBJS = $(PLUGIN).o bdplayer.o discmgr.o titlemenu.o discmenu.o
### The main target:
diff --git a/README b/README
index e3abc6b..7256a18 100644
--- a/README
+++ b/README
@@ -28,6 +28,8 @@ Options:
-m, --mount Program/script used to mount BluRay disc (default /bin/mount)
-u, --unmount Program/script used to unmount BluRay disc (default /bin/umount)
-e, --eject Program/script used to eject / close BluRay drive (default /usr/bin/eject)
+ -l, --lib Path where to search BluRay discs from
All options except BluRay disc mount path are optional.
Helper scripts are used only if the disc is not automatically mounted.
+
diff --git a/bluray.c b/bluray.c
index f068127..2b64d74 100644
--- a/bluray.c
+++ b/bluray.c
@@ -9,6 +9,7 @@
#include <vdr/plugin.h>
#include "discmgr.h"
+#include "discmenu.h"
#include "bdplayer.h"
static const char *VERSION = "0.0.1";
@@ -20,6 +21,7 @@ class cPluginBluray : public cPlugin {
private:
// Add any member variables or functions you may need here.
cDiscMgr mgr;
+ cString DiscLib;
public:
cPluginBluray(void);
@@ -52,7 +54,8 @@ const char *cPluginBluray::CommandLineHelp(void)
" -p DIR, --path=DIR mount point for BluRay discs (default "DEFAULT_PATH")\n"
" -m CMD, --mount=CMD program used to mount BluRay disc (default "DEFAULT_MOUNTER")\n"
" -u CMD, --umount=CMD program used to unmount BluRay disc (default "DEFAULT_UNMOUNTER")\n"
- " -e CMD, --eject=CMD program used to eject BluRay disc (default "DEFAULT_EJECT")\n";
+ " -e CMD, --eject=CMD program used to eject BluRay disc (default "DEFAULT_EJECT")\n"
+ " -l DIR, --lib=DIR directory to search for multiple BluRay discs (default: none)n";
}
bool cPluginBluray::ProcessArgs(int argc, char *argv[])
@@ -65,6 +68,7 @@ bool cPluginBluray::ProcessArgs(int argc, char *argv[])
{ "mount", optional_argument, NULL, 'm' },
{ "umount", optional_argument, NULL, 'u' },
{ "eject", optional_argument, NULL, 'e' },
+ { "lib", optional_argument, NULL, 'l' },
{ NULL, no_argument, NULL, 0 }
};
@@ -86,6 +90,9 @@ bool cPluginBluray::ProcessArgs(int argc, char *argv[])
case 'e':
mgr.SetEjectCmd(optarg);
break;
+ case 'l':
+ DiscLib = optarg;
+ break;
default:
return false;
}
@@ -97,10 +104,15 @@ bool cPluginBluray::ProcessArgs(int argc, char *argv[])
cOsdObject *cPluginBluray::MainMenuAction(void)
{
// Perform the action when selected from the main VDR menu.
+
if (cBDControl::Active()) {
return NULL;
}
+ if (*DiscLib) {
+ return new cDiscMenu(mgr, DiscLib);
+ }
+
if (!mgr.CheckDisc()) {
return NULL;
}
diff --git a/discmenu.c b/discmenu.c
new file mode 100644
index 0000000..7ec8920
--- /dev/null
+++ b/discmenu.c
@@ -0,0 +1,161 @@
+/*
+ * discmenu.c: BluRay disc library menu
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ */
+
+#include <vdr/tools.h>
+#include <vdr/osdbase.h>
+
+#include "bdplayer.h"
+
+#include "discmenu.h"
+
+/*
+ *
+ */
+
+static bool IsBluRayFolder(const char *fname)
+{
+ struct stat st;
+
+ if (stat(cString::sprintf("%s/BDMV/index.bdmv", fname), &st) == 0)
+ return true;
+
+ return false;
+}
+
+/*
+ * cDiscItem
+ */
+
+class cDiscItem : public cOsdItem
+{
+ private:
+ cString Root;
+ public:
+ cDiscItem(const char *title, const char *root);
+ cDiscItem(const char *title);
+
+ const char *GetRoot() { return Root; }
+
+ virtual int Compare(const cListObject &ListObject) const {
+ const cDiscItem *o = (const cDiscItem *)&ListObject;
+ return strcmp(o->Root, Root);
+ }
+};
+
+cDiscItem::cDiscItem(const char *title, const char *root) :
+cOsdItem(title, osUser1)
+{
+ Root = root;
+}
+
+cDiscItem::cDiscItem(const char *title) :
+cOsdItem(title, osUser2)
+{
+}
+
+/*
+ * cDiscMenu
+ */
+
+cDiscMenu::cDiscMenu(cDiscMgr& Mgr, cString& Root) :
+ cOsdMenu("BluRay Discs"),
+ mgr(Mgr)
+{
+ Scan(Root);
+
+ Sort();
+
+ if (mgr.IsMounted()) {
+ Ins(new cDiscItem(cString::sprintf("BluRay disc (%s)", mgr.GetDev())));
+ //SetHelp("Eject");
+ } else {
+ Ins(new cDiscItem("(Disc not mounted)"));
+ //SetHelp("Mount");
+ }
+
+ Display();
+}
+
+void cDiscMenu::Scan(cString& Root)
+{
+ DIR *d = opendir(Root);
+ if (d) {
+ struct dirent *e;
+ while ((e = readdir(d)) != NULL) {
+ if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..") &&
+ e->d_name[0] != '.') {
+ cString buffer = cString::sprintf("%s/%s", *Root, e->d_name);
+ struct stat st;
+ if (stat(buffer, &st) == 0) {
+
+ // check symlink destination
+ if (S_ISLNK(st.st_mode)) {
+ buffer = ReadLink(buffer);
+ if (!*buffer || stat(buffer, &st))
+ continue;
+ }
+
+ // folders
+ if (S_ISDIR(st.st_mode)) {
+
+ if (IsBluRayFolder(buffer)) {
+ Add(new cDiscItem(e->d_name, buffer));
+
+ } else {
+ Scan(buffer);
+ }
+ }
+ }
+ }
+ }
+ closedir(d);
+ }
+}
+
+eOSState cDiscMenu::ProcessKey(eKeys Key)
+{
+ eOSState state = cOsdMenu::ProcessKey(Key);
+ switch (state) {
+ case osUser1: {
+ isyslog("disc select");
+ cDiscItem *di = (cDiscItem*)Get(Current());
+ if (di) {
+ isyslog("- root %s", di->GetRoot());
+
+ cControl::Shutdown();
+
+ cControl *control = cBDControl::Create(di->GetRoot());
+ if (control) {
+ cControl::Launch(control);
+ }
+
+ return osEnd;
+ }
+ break;
+ }
+
+ case osUser2: {
+ isyslog("device select");
+
+ if (!mgr.CheckDisc()) {
+ return osContinue;
+ }
+
+ cControl::Shutdown();
+
+ cControl *control = cBDControl::Create(mgr.GetPath());
+ if (control) {
+ cControl::Launch(control);
+ return osEnd;
+ }
+ break;
+ }
+
+ default: break;
+ }
+ return state;
+}
diff --git a/discmenu.h b/discmenu.h
new file mode 100644
index 0000000..8503c59
--- /dev/null
+++ b/discmenu.h
@@ -0,0 +1,27 @@
+/*
+ * titlemenu.h: BluRay disc library menu
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ */
+
+#ifndef _DISCMENU_H
+#define _DISCMENU_H
+
+#include <vdr/menuitems.h>
+
+#include "discmgr.h"
+
+class cDiscMenu : public cOsdMenu {
+ private:
+ void Scan(cString& Root);
+
+ cDiscMgr& mgr;
+
+ public:
+ cDiscMenu(cDiscMgr& Mgr, cString& Root);
+
+ virtual eOSState ProcessKey(eKeys Key);
+};
+
+#endif //_DISCMENU_H
diff --git a/discmgr.h b/discmgr.h
index ba85a84..e35950b 100644
--- a/discmgr.h
+++ b/discmgr.h
@@ -22,7 +22,6 @@ private:
cString Device, Path, MountCmd, UnMountCmd, EjectCmd;
- bool IsMounted(void);
void Mount(bool Retry = true);
void UnMount(void);
void CloseTray(void);
@@ -30,6 +29,7 @@ private:
public:
cDiscMgr();
+ const char *GetDev(void) { return Device; }
const char *GetPath(void) { return Path; }
void SetDevice(const char *D) { Device = D; }
@@ -38,6 +38,8 @@ private:
void SetUnMountCmd(const char *U) { UnMountCmd = U; }
void SetEjectCmd(const char *E) { EjectCmd = E; }
+ bool IsMounted(void);
+
bool CheckDisc(void);
void Eject(void);
};