summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dvd.c41
-rw-r--r--dvd.h11
-rw-r--r--menu.c10
-rw-r--r--vdr.c6
4 files changed, 46 insertions, 22 deletions
diff --git a/dvd.c b/dvd.c
index 8daa926c..025361ab 100644
--- a/dvd.c
+++ b/dvd.c
@@ -6,7 +6,7 @@
*
* Initially written by Andreas Schultz <aschultz@warp10.net>
*
- * $Id: dvd.c 1.1 2001/08/03 12:35:38 kls Exp $
+ * $Id: dvd.c 1.2 2001/08/05 15:00:45 kls Exp $
*/
//XXX //#define DVDDEBUG 1
@@ -46,6 +46,17 @@ cDVD::~cDVD()
Close();
}
+int cDVD::Command(int Cmd)
+{
+ int result = -1;
+ int f;
+ if ((f = open(deviceName, O_RDONLY | O_NONBLOCK)) > 0) {
+ result = ioctl(f, Cmd, 0);
+ close(f);
+ }
+ return result;
+}
+
void cDVD::SetDeviceName(const char *DeviceName)
{
deviceName = strdup(DeviceName);
@@ -56,6 +67,23 @@ const char *cDVD::DeviceName(void)
return deviceName;
}
+bool cDVD::DriveExists(void)
+{
+ return access(deviceName, F_OK) == 0;
+}
+
+bool cDVD::DiscOk(void)
+{
+ return Command(CDROM_DRIVE_STATUS) == CDS_DISC_OK;
+}
+
+void cDVD::Eject(void)
+{
+ if (dvdInstance)
+ dvdInstance->Close();
+ Command(CDROMEJECT);
+}
+
void cDVD::Open(void)
{
if (!dvd)
@@ -81,17 +109,6 @@ void cDVD::Close(void)
dvd = NULL;
}
-void cDVD::Eject(void)
-{
- int fd;
- Close();
- // ignore all errors try our best :-)
- if ((fd = open(deviceName, O_RDONLY)) > 0) {
- ioctl(fd, CDROMEJECT, 0);
- close(fd);
- }
-}
-
ifo_handle_t *cDVD::openVMG(void)
{
if (!isValid())
diff --git a/dvd.h b/dvd.h
index 39094c5a..ae9f3067 100644
--- a/dvd.h
+++ b/dvd.h
@@ -6,7 +6,7 @@
*
* Initially written by Andreas Schultz <aschultz@warp10.net>
*
- * $Id: dvd.h 1.1 2001/08/03 12:35:42 kls Exp $
+ * $Id: dvd.h 1.2 2001/08/05 15:00:23 kls Exp $
*/
#ifndef __DVD_H
@@ -28,19 +28,22 @@ private:
ifo_handle_t *vmg_file;
ifo_handle_t *vts_file;
int titleset;
+ static int Command(int Cmd);
public:
cDVD(void);
~cDVD();
+ static void SetDeviceName(const char *DeviceName);
+ static const char *DeviceName(void);
+ static bool DriveExists(void);
+ static bool DiscOk(void);
+ static void Eject(void);
void Open(void);
void Close(void);
- void Eject(void);
bool isValid(void) { return (dvd != NULL); }
ifo_handle_t *openVMG(void);
ifo_handle_t *openVTS(int TitleSet);
dvd_file_t *openTitle(int Title, dvd_read_domain_t domain);
static cDVD *getDVD(void);
- static void SetDeviceName(const char *DeviceName);
- static const char *DeviceName(void);
};
#endif //__DVD_H
diff --git a/menu.c b/menu.c
index b8d5f9d2..f7714215 100644
--- a/menu.c
+++ b/menu.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: menu.c 1.93 2001/08/05 12:47:14 kls Exp $
+ * $Id: menu.c 1.94 2001/08/05 15:11:35 kls Exp $
*/
#include "menu.h"
@@ -1794,6 +1794,7 @@ cMenuMain::cMenuMain(bool Replaying)
Add(new cOsdItem(hk(tr("Channels")), osChannels));
Add(new cOsdItem(hk(tr("Timers")), osTimers));
Add(new cOsdItem(hk(tr("Recordings")), osRecordings));
+ if (cDVD::DriveExists())
Add(new cOsdItem(hk(tr("DVD")), osDVD));
Add(new cOsdItem(hk(tr("Setup")), osSetup));
if (Commands.Count())
@@ -1809,7 +1810,7 @@ cMenuMain::cMenuMain(bool Replaying)
}
if (cVideoCutter::Active())
Add(new cOsdItem(hk(tr(" Cancel editing")), osCancelEdit));
- SetHelp(tr("Record"), cDvbApi::PrimaryDvbApi->CanToggleAudioTrack() ? tr("Language") : NULL, /*XXX only if DVD loaded?*/tr("Eject DVD"), cReplayControl::LastReplayed() ? tr("Resume") : NULL);
+ SetHelp(tr("Record"), cDvbApi::PrimaryDvbApi->CanToggleAudioTrack() ? tr("Language") : NULL, cDVD::DiscOk() ? tr("Eject DVD") : NULL, cReplayControl::LastReplayed() ? tr("Resume") : NULL);
Display();
lastActivity = time(NULL);
SetHasHotkeys();
@@ -1865,9 +1866,8 @@ eOSState cMenuMain::ProcessKey(eKeys Key)
}
break;
case kYellow: if (!HasSubMenu()) {
- cDVD *dvd;
- if ((dvd = cDVD::getDVD())) {
- dvd->Eject();
+ if (cDVD::DiscOk()) {
+ cDVD::Eject();
state = osEnd;
}
}
diff --git a/vdr.c b/vdr.c
index 765eb29b..787f9cf8 100644
--- a/vdr.c
+++ b/vdr.c
@@ -22,7 +22,7 @@
*
* The project's page is at http://www.cadsoft.de/people/kls/vdr
*
- * $Id: vdr.c 1.59 2001/08/02 13:48:51 kls Exp $
+ * $Id: vdr.c 1.60 2001/08/05 12:58:12 kls Exp $
*/
#include <getopt.h>
@@ -163,6 +163,10 @@ int main(int argc, char *argv[])
optarg[strlen(optarg) - 1] = 0;
break;
case 'V': cDVD::SetDeviceName(optarg);
+ if (!cDVD::DriveExists()) {
+ fprintf(stderr, "vdr: DVD drive not found: %s\n", optarg);
+ return 2;
+ }
break;
case 'w': if (isnumber(optarg)) {
int t = atoi(optarg);