MediaPlayer: add eject button
Fixes #11492 Change-Id: I06631ddcef354f4cf8a10e8ccbb6eba03c1ca7dd
This commit is contained in:
committed by
JackBurton79
parent
1aa97652e0
commit
31acddc00e
@@ -20,6 +20,8 @@
|
|||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <Drivers.h>
|
||||||
#include <fs_attr.h>
|
#include <fs_attr.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <Language.h>
|
#include <Language.h>
|
||||||
@@ -67,6 +69,7 @@ enum {
|
|||||||
M_DUMMY = 0x100,
|
M_DUMMY = 0x100,
|
||||||
M_FILE_OPEN = 0x1000,
|
M_FILE_OPEN = 0x1000,
|
||||||
M_NETWORK_STREAM_OPEN,
|
M_NETWORK_STREAM_OPEN,
|
||||||
|
M_EJECT_DEVICE,
|
||||||
M_FILE_INFO,
|
M_FILE_INFO,
|
||||||
M_FILE_PLAYLIST,
|
M_FILE_PLAYLIST,
|
||||||
M_FILE_CLOSE,
|
M_FILE_CLOSE,
|
||||||
@@ -887,6 +890,10 @@ MainWin::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case M_EJECT_DEVICE:
|
||||||
|
Eject();
|
||||||
|
break;
|
||||||
|
|
||||||
case M_FILE_INFO:
|
case M_FILE_INFO:
|
||||||
ShowFileInfo();
|
ShowFileInfo();
|
||||||
break;
|
break;
|
||||||
@@ -1202,6 +1209,62 @@ MainWin::OpenPlaylistItem(const PlaylistItemRef& item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
FindCdPlayerDevice(const char* directory)
|
||||||
|
{
|
||||||
|
BDirectory dir;
|
||||||
|
dir.SetTo(directory);
|
||||||
|
if (dir.InitCheck() != B_NO_ERROR)
|
||||||
|
return false;
|
||||||
|
dir.Rewind();
|
||||||
|
BEntry entry;
|
||||||
|
while (dir.GetNextEntry(&entry) >= 0) {
|
||||||
|
BPath path;
|
||||||
|
if (entry.GetPath(&path) != B_NO_ERROR)
|
||||||
|
continue;
|
||||||
|
const char* name = path.Path();
|
||||||
|
entry_ref e;
|
||||||
|
if (entry.GetRef(&e) != B_NO_ERROR)
|
||||||
|
continue;
|
||||||
|
if (entry.IsDirectory()) {
|
||||||
|
if (strcmp(e.name, "floppy") == 0)
|
||||||
|
continue; // ignore floppy
|
||||||
|
int deviceFD = FindCdPlayerDevice(name);
|
||||||
|
if (deviceFD >= 0)
|
||||||
|
return deviceFD;
|
||||||
|
} else {
|
||||||
|
if (strcmp(e.name, "raw") != 0)
|
||||||
|
continue;
|
||||||
|
int deviceFD = open(name, O_RDONLY);
|
||||||
|
if (deviceFD < 0)
|
||||||
|
continue;
|
||||||
|
device_geometry geometry;
|
||||||
|
if (ioctl(deviceFD, B_GET_GEOMETRY, &geometry, sizeof(geometry)) >= 0
|
||||||
|
&& geometry.device_type == B_CD)
|
||||||
|
return deviceFD;
|
||||||
|
close(deviceFD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWin::Eject()
|
||||||
|
{
|
||||||
|
status_t mediaStatus = B_DEV_NO_MEDIA;
|
||||||
|
// find the cd player device
|
||||||
|
fDevice = FindCdPlayerDevice("/dev/disk");
|
||||||
|
// get the status first
|
||||||
|
ioctl(fDevice, B_GET_MEDIA_STATUS, &mediaStatus, sizeof(mediaStatus));
|
||||||
|
// if door open, load the media, else eject the cd
|
||||||
|
status_t result = ioctl(fDevice,
|
||||||
|
mediaStatus == B_DEV_DOOR_OPEN ? B_LOAD_MEDIA : B_EJECT_DEVICE);
|
||||||
|
if (result != B_NO_ERROR)
|
||||||
|
printf("Error ejecting device");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWin::ShowFileInfo()
|
MainWin::ShowFileInfo()
|
||||||
{
|
{
|
||||||
@@ -1550,6 +1613,10 @@ MainWin::_CreateMenu()
|
|||||||
new BMessage(M_NETWORK_STREAM_OPEN));
|
new BMessage(M_NETWORK_STREAM_OPEN));
|
||||||
fFileMenu->AddItem(item);
|
fFileMenu->AddItem(item);
|
||||||
|
|
||||||
|
item = new BMenuItem(B_TRANSLATE("Eject Device"),
|
||||||
|
new BMessage(M_EJECT_DEVICE));
|
||||||
|
fFileMenu->AddItem(item);
|
||||||
|
|
||||||
fFileMenu->AddSeparatorItem();
|
fFileMenu->AddSeparatorItem();
|
||||||
|
|
||||||
fFileMenu->AddItem(new BMenuItem(B_TRANSLATE("File info" B_UTF8_ELLIPSIS),
|
fFileMenu->AddItem(new BMenuItem(B_TRANSLATE("File info" B_UTF8_ELLIPSIS),
|
||||||
@@ -2745,5 +2812,3 @@ MainWin::_AdoptGlobalSettings()
|
|||||||
fLoopSounds = settings.loopSound;
|
fLoopSounds = settings.loopSound;
|
||||||
fScaleFullscreenControls = settings.scaleFullscreenControls;
|
fScaleFullscreenControls = settings.scaleFullscreenControls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
|
|
||||||
void OpenPlaylist(const BMessage* playlistArchive);
|
void OpenPlaylist(const BMessage* playlistArchive);
|
||||||
void OpenPlaylistItem(const PlaylistItemRef& item);
|
void OpenPlaylistItem(const PlaylistItemRef& item);
|
||||||
|
void Eject();
|
||||||
void ShowFileInfo();
|
void ShowFileInfo();
|
||||||
void ShowPlaylistWindow();
|
void ShowPlaylistWindow();
|
||||||
void ShowSettingsWindow();
|
void ShowSettingsWindow();
|
||||||
@@ -189,6 +189,7 @@ private:
|
|||||||
bool fScaleFullscreenControls;
|
bool fScaleFullscreenControls;
|
||||||
bigtime_t fInitialSeekPosition;
|
bigtime_t fInitialSeekPosition;
|
||||||
bool fAllowWinding;
|
bool fAllowWinding;
|
||||||
|
int fDevice;
|
||||||
|
|
||||||
static int sNoVideoWidth;
|
static int sNoVideoWidth;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user