* Made opening playlist items asynchronous (in the Controller thread).
* Resolved TODO: Use the existing "FileChanged" notification in the main window to adopt the UI to the currently playing item. * When opening a file takes some time, the window is now free to start hidden and setup a message runner to unhide it after 150 msecs. * When launching MediaPlayer with files, the 150 msecs delay is used to start the window hidden and pop up right at the correct location for audio. If opening the first audio file takes less than 150 msecs, the window will already show as soon as possible. * While opening a file in the Controller, the window will say so in the disabled seek slider instead of showing the message "Drop media files here.". git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34132 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
1221df2dd8
commit
e663610e84
@ -70,7 +70,7 @@ HandleError(const char *text, status_t err)
|
||||
Controller::Listener::Listener() {}
|
||||
Controller::Listener::~Listener() {}
|
||||
void Controller::Listener::FileFinished() {}
|
||||
void Controller::Listener::FileChanged() {}
|
||||
void Controller::Listener::FileChanged(PlaylistItem* item, status_t result) {}
|
||||
void Controller::Listener::VideoTrackChanged(int32) {}
|
||||
void Controller::Listener::AudioTrackChanged(int32) {}
|
||||
void Controller::Listener::VideoStatsChanged() {}
|
||||
@ -84,6 +84,11 @@ void Controller::Listener::MutedChanged(bool) {}
|
||||
// #pragma mark - Controller
|
||||
|
||||
|
||||
enum {
|
||||
MSG_SET_TO = 'stto'
|
||||
};
|
||||
|
||||
|
||||
Controller::Controller()
|
||||
:
|
||||
NodeManager(),
|
||||
@ -139,6 +144,20 @@ Controller::MessageReceived(BMessage* message)
|
||||
// the global settings instance...
|
||||
_AdoptGlobalSettings();
|
||||
break;
|
||||
|
||||
case MSG_SET_TO:
|
||||
{
|
||||
PlaylistItem* item;
|
||||
if (message->FindPointer("item", (void**)&item) == B_OK) {
|
||||
PlaylistItemRef itemRef(item, true);
|
||||
// The reference was passed with the message.
|
||||
SetTo(itemRef);
|
||||
} else
|
||||
_NotifyFileChanged(NULL, B_BAD_VALUE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
NodeManager::MessageReceived(message);
|
||||
}
|
||||
@ -181,6 +200,27 @@ Controller::CreateAudioSupplier()
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
status_t
|
||||
Controller::SetToAsync(const PlaylistItemRef& item)
|
||||
{
|
||||
PlaylistItemRef additionalReference(item);
|
||||
|
||||
BMessage message(MSG_SET_TO);
|
||||
status_t ret = message.AddPointer("item", item.Get());
|
||||
if (ret != B_OK)
|
||||
return ret;
|
||||
|
||||
ret = PostMessage(&message);
|
||||
if (ret != B_OK)
|
||||
return ret;
|
||||
|
||||
// The additional reference is now passed along with the message...
|
||||
additionalReference.Detach();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Controller::SetTo(const PlaylistItemRef& item)
|
||||
{
|
||||
@ -230,14 +270,14 @@ Controller::SetTo(const PlaylistItemRef& item)
|
||||
status_t err = mf->InitCheck();
|
||||
if (err != B_OK) {
|
||||
printf("Controller::SetTo: initcheck failed\n");
|
||||
_NotifyFileChanged();
|
||||
_NotifyFileChanged(item.Get(), err);
|
||||
return err;
|
||||
}
|
||||
|
||||
int trackcount = mf->CountTracks();
|
||||
if (trackcount <= 0) {
|
||||
printf("Controller::SetTo: trackcount %d\n", trackcount);
|
||||
_NotifyFileChanged();
|
||||
_NotifyFileChanged(item.Get(), B_MEDIA_NO_HANDLER);
|
||||
return B_MEDIA_NO_HANDLER;
|
||||
}
|
||||
|
||||
@ -280,7 +320,7 @@ Controller::SetTo(const PlaylistItemRef& item)
|
||||
if (fAudioTrackSupplier == NULL && fVideoTrackSupplier == NULL) {
|
||||
printf("Controller::SetTo: no audio or video tracks found or "
|
||||
"no decoders\n");
|
||||
_NotifyFileChanged();
|
||||
_NotifyFileChanged(item.Get(), B_MEDIA_NO_HANDLER);
|
||||
delete fMediaFile;
|
||||
fMediaFile = NULL;
|
||||
return B_MEDIA_NO_HANDLER;
|
||||
@ -329,7 +369,7 @@ Controller::SetTo(const PlaylistItemRef& item)
|
||||
useOverlays);
|
||||
}
|
||||
|
||||
_NotifyFileChanged();
|
||||
_NotifyFileChanged(item.Get(), B_OK);
|
||||
|
||||
SetPosition(0.0);
|
||||
if (fAutoplay)
|
||||
@ -342,7 +382,8 @@ Controller::SetTo(const PlaylistItemRef& item)
|
||||
void
|
||||
Controller::PlayerActivated(bool active)
|
||||
{
|
||||
BAutolock _(this);
|
||||
if (LockWithTimeout(5000) != B_OK)
|
||||
return;
|
||||
|
||||
if (active && gMainApp->PlayerCount() > 1) {
|
||||
if (fActiveVolume != fVolume)
|
||||
@ -362,6 +403,8 @@ Controller::PlayerActivated(bool active)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
@ -870,13 +913,13 @@ Controller::_PlaybackState(int32 playingMode) const
|
||||
|
||||
|
||||
void
|
||||
Controller::_NotifyFileChanged() const
|
||||
Controller::_NotifyFileChanged(PlaylistItem* item, status_t result) const
|
||||
{
|
||||
BList listeners(fListeners);
|
||||
int32 count = listeners.CountItems();
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
Listener* listener = (Listener*)listeners.ItemAtFast(i);
|
||||
listener->FileChanged();
|
||||
listener->FileChanged(item, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,8 @@ public:
|
||||
virtual ~Listener();
|
||||
|
||||
virtual void FileFinished();
|
||||
virtual void FileChanged();
|
||||
virtual void FileChanged(PlaylistItem* item,
|
||||
status_t result);
|
||||
|
||||
virtual void VideoTrackChanged(int32 index);
|
||||
virtual void AudioTrackChanged(int32 index);
|
||||
@ -82,6 +83,7 @@ public:
|
||||
virtual AudioSupplier* CreateAudioSupplier();
|
||||
|
||||
// Controller
|
||||
status_t SetToAsync(const PlaylistItemRef& item);
|
||||
status_t SetTo(const PlaylistItemRef& item);
|
||||
const PlaylistItem* Item() const
|
||||
{ return fItem.Get(); }
|
||||
@ -143,7 +145,8 @@ private:
|
||||
|
||||
uint32 _PlaybackState(int32 playingMode) const;
|
||||
|
||||
void _NotifyFileChanged() const;
|
||||
void _NotifyFileChanged(PlaylistItem* item,
|
||||
status_t result) const;
|
||||
void _NotifyFileFinished() const;
|
||||
void _NotifyVideoTrackChanged(int32 index) const;
|
||||
void _NotifyAudioTrackChanged(int32 index) const;
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include <Message.h>
|
||||
|
||||
#include "PlaylistItem.h"
|
||||
|
||||
|
||||
ControllerObserver::ControllerObserver(BHandler* target, uint32 observeFlags)
|
||||
:
|
||||
@ -38,12 +40,18 @@ ControllerObserver::FileFinished()
|
||||
|
||||
|
||||
void
|
||||
ControllerObserver::FileChanged()
|
||||
ControllerObserver::FileChanged(PlaylistItem* item, status_t result)
|
||||
{
|
||||
if (!(fObserveFlags & OBSERVE_FILE_CHANGES))
|
||||
return;
|
||||
|
||||
PlaylistItemRef reference(item);
|
||||
// pass the reference along with the message
|
||||
|
||||
BMessage message(MSG_CONTROLLER_FILE_CHANGED);
|
||||
message.AddInt32("result", result);
|
||||
if (message.AddPointer("item", item) == B_OK)
|
||||
reference.Detach();
|
||||
|
||||
DeliverMessage(message);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
|
||||
// Controller::Listener interface
|
||||
virtual void FileFinished();
|
||||
virtual void FileChanged();
|
||||
virtual void FileChanged(PlaylistItem* item, status_t result);
|
||||
|
||||
virtual void VideoTrackChanged(int32 index);
|
||||
virtual void AudioTrackChanged(int32 index);
|
||||
|
@ -120,11 +120,11 @@ MainApp::QuitRequested()
|
||||
|
||||
|
||||
MainWin*
|
||||
MainApp::NewWindow()
|
||||
MainApp::NewWindow(BMessage* message)
|
||||
{
|
||||
BAutolock _(this);
|
||||
fPlayerCount++;
|
||||
return new(std::nothrow) MainWin(fPlayerCount == 1);
|
||||
return new(std::nothrow) MainWin(fPlayerCount == 1, message);
|
||||
}
|
||||
|
||||
|
||||
@ -173,11 +173,7 @@ MainApp::RefsReceived(BMessage* message)
|
||||
// ArgvReceived() but without MIME type check.
|
||||
// For each file we create a new window and send it a
|
||||
// B_REFS_RECEIVED message with a single file.
|
||||
BWindow* window = NewWindow();
|
||||
if (window != NULL) {
|
||||
window->Show();
|
||||
window->PostMessage(message);
|
||||
}
|
||||
NewWindow(message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,7 +64,7 @@ public:
|
||||
MainApp();
|
||||
virtual ~MainApp();
|
||||
|
||||
MainWin* NewWindow();
|
||||
MainWin* NewWindow(BMessage* message = NULL);
|
||||
int32 PlayerCount() const;
|
||||
|
||||
private:
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <Menu.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <Messenger.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <RecentItems.h>
|
||||
@ -97,13 +98,15 @@ enum {
|
||||
|
||||
M_SET_PLAYLIST_POSITION,
|
||||
|
||||
M_FILE_DELETE
|
||||
M_FILE_DELETE,
|
||||
|
||||
M_SHOW_IF_NEEDED
|
||||
};
|
||||
|
||||
//#define printf(a...)
|
||||
|
||||
|
||||
MainWin::MainWin(bool isFirstWindow)
|
||||
MainWin::MainWin(bool isFirstWindow, BMessage* message)
|
||||
:
|
||||
BWindow(BRect(100, 100, 400, 300), NAME, B_TITLED_WINDOW,
|
||||
B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */),
|
||||
@ -127,6 +130,8 @@ MainWin::MainWin(bool isFirstWindow)
|
||||
fSourceHeight(-1),
|
||||
fWidthAspect(0),
|
||||
fHeightAspect(0),
|
||||
fSavedFrame(),
|
||||
fNoVideoFrame(),
|
||||
fMouseDownTracking(false),
|
||||
fGlobalSettingsListener(this),
|
||||
fInitialSeekPosition(0)
|
||||
@ -142,8 +147,14 @@ MainWin::MainWin(bool isFirstWindow)
|
||||
.audioPlayerWindowFrame;
|
||||
if (frame.IsValid()) {
|
||||
if (isFirstWindow) {
|
||||
MoveTo(frame.LeftTop());
|
||||
ResizeTo(frame.Width(), frame.Height());
|
||||
if (message == NULL) {
|
||||
MoveTo(frame.LeftTop());
|
||||
ResizeTo(frame.Width(), frame.Height());
|
||||
} else {
|
||||
// Delay moving to the initial position, since we don't
|
||||
// know if we will be playing audio at all.
|
||||
message->AddRect("window frame", frame);
|
||||
}
|
||||
}
|
||||
if (sNoVideoWidth == MIN_WIDTH)
|
||||
sNoVideoWidth = frame.IntegerWidth();
|
||||
@ -213,6 +224,9 @@ MainWin::MainWin(bool isFirstWindow)
|
||||
|
||||
Hide();
|
||||
Show();
|
||||
|
||||
if (message != NULL)
|
||||
PostMessage(message);
|
||||
}
|
||||
|
||||
|
||||
@ -462,11 +476,22 @@ MainWin::MessageReceived(BMessage* msg)
|
||||
break;
|
||||
}
|
||||
case MSG_CONTROLLER_FILE_CHANGED:
|
||||
// TODO: move all other GUI changes as a reaction to this
|
||||
// notification
|
||||
// _UpdatePlaylistMenu();
|
||||
_SetFileAttributes();
|
||||
{
|
||||
status_t result = B_ERROR;
|
||||
msg->FindInt32("result", &result);
|
||||
PlaylistItemRef itemRef;
|
||||
PlaylistItem* item;
|
||||
if (msg->FindPointer("item", (void**)&item) == B_OK) {
|
||||
itemRef.SetTo(item, true);
|
||||
// The reference was passed along with the message.
|
||||
} else {
|
||||
BAutolock _(fPlaylist);
|
||||
itemRef.SetTo(fPlaylist->ItemAt(
|
||||
fPlaylist->CurrentItemIndex()));
|
||||
}
|
||||
_PlaylistItemOpened(itemRef, result);
|
||||
break;
|
||||
}
|
||||
case MSG_CONTROLLER_VIDEO_TRACK_CHANGED:
|
||||
{
|
||||
int32 index;
|
||||
@ -680,6 +705,10 @@ MainWin::MessageReceived(BMessage* msg)
|
||||
_AdoptGlobalSettings();
|
||||
break;
|
||||
|
||||
case M_SHOW_IF_NEEDED:
|
||||
_ShowIfNeeded();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (msg->what >= M_SELECT_AUDIO_TRACK
|
||||
&& msg->what <= M_SELECT_AUDIO_TRACK_END) {
|
||||
@ -772,45 +801,24 @@ MainWin::OpenPlaylist(const BMessage* playlistArchive)
|
||||
void
|
||||
MainWin::OpenPlaylistItem(const PlaylistItemRef& item)
|
||||
{
|
||||
printf("MainWin::OpenPlaylistItem\n");
|
||||
|
||||
status_t err = fController->SetTo(item);
|
||||
if (err != B_OK) {
|
||||
BAutolock _(fPlaylist);
|
||||
if (fPlaylist->CountItems() == 1) {
|
||||
// display error if this is the only file we're supposed to play
|
||||
BString message;
|
||||
message << "The file '";
|
||||
message << item->Name();
|
||||
message << "' could not be opened.\n\n";
|
||||
|
||||
if (err == B_MEDIA_NO_HANDLER) {
|
||||
// give a more detailed message for the most likely of all
|
||||
// errors
|
||||
message << "There is no decoder installed to handle the "
|
||||
"file format, or the decoder has trouble with the specific "
|
||||
"version of the format.";
|
||||
} else {
|
||||
message << "Error: " << strerror(err);
|
||||
}
|
||||
(new BAlert("error", message.String(), "OK"))->Go();
|
||||
} else {
|
||||
// just go to the next file and don't bother user
|
||||
fPlaylist->SetCurrentItemIndex(fPlaylist->CurrentItemIndex() + 1);
|
||||
}
|
||||
fHasFile = false;
|
||||
fHasVideo = false;
|
||||
fHasAudio = false;
|
||||
SetTitle(NAME);
|
||||
status_t ret = fController->SetToAsync(item);
|
||||
if (ret != B_OK) {
|
||||
fprintf(stderr, "MainWin::OpenPlaylistItem() - Failed to send message "
|
||||
"to Controller.\n");
|
||||
(new BAlert("error", NAME" encountered an internal error. "
|
||||
"The file could not be opened.", "OK"))->Go();
|
||||
_PlaylistItemOpened(item, ret);
|
||||
} else {
|
||||
fHasFile = true;
|
||||
fHasVideo = fController->VideoTrackCount() != 0;
|
||||
fHasAudio = fController->AudioTrackCount() != 0;
|
||||
SetTitle(item->Name().String());
|
||||
fController->SetTimePosition(fInitialSeekPosition);
|
||||
fInitialSeekPosition = 0;
|
||||
BString string;
|
||||
string << "Opening '" << item->Name() << "'.";
|
||||
fControls->SetDisabledString(string.String());
|
||||
|
||||
if (IsHidden()) {
|
||||
BMessage showMessage(M_SHOW_IF_NEEDED);
|
||||
BMessageRunner::StartSending(BMessenger(this), &showMessage,
|
||||
150000, 1);
|
||||
}
|
||||
}
|
||||
_SetupWindow();
|
||||
}
|
||||
|
||||
|
||||
@ -923,7 +931,7 @@ MainWin::VideoFormatChange(int width, int height, int widthAspect,
|
||||
|
||||
|
||||
void
|
||||
MainWin::_RefsReceived(BMessage* msg)
|
||||
MainWin::_RefsReceived(BMessage* message)
|
||||
{
|
||||
// the playlist is replaced by dropped files
|
||||
// or the dropped files are appended to the end
|
||||
@ -931,11 +939,73 @@ MainWin::_RefsReceived(BMessage* msg)
|
||||
BAutolock _(fPlaylist);
|
||||
int32 appendIndex = modifiers() & B_SHIFT_KEY ?
|
||||
fPlaylist->CountItems() : -1;
|
||||
msg->AddInt32("append_index", appendIndex);
|
||||
message->AddInt32("append_index", appendIndex);
|
||||
|
||||
// forward the message to the playlist window,
|
||||
// so that undo/redo is used for modifying the playlist
|
||||
fPlaylistWindow->PostMessage(msg);
|
||||
fPlaylistWindow->PostMessage(message);
|
||||
|
||||
if (message->FindRect("window frame", &fNoVideoFrame) != B_OK) {
|
||||
fNoVideoFrame = BRect();
|
||||
_ShowIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWin::_PlaylistItemOpened(const PlaylistItemRef& item, status_t result)
|
||||
{
|
||||
if (result != B_OK) {
|
||||
BAutolock _(fPlaylist);
|
||||
|
||||
item->SetPlaybackFailed();
|
||||
bool allItemsFailed = true;
|
||||
int32 count = fPlaylist->CountItems();
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
if (!fPlaylist->ItemAtFast(i)->PlaybackFailed()) {
|
||||
allItemsFailed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allItemsFailed) {
|
||||
// Display error if all files failed to play.
|
||||
BString message;
|
||||
message << "The file '";
|
||||
message << item->Name();
|
||||
message << "' could not be opened.\n\n";
|
||||
|
||||
if (result == B_MEDIA_NO_HANDLER) {
|
||||
// give a more detailed message for the most likely of all
|
||||
// errors
|
||||
message << "There is no decoder installed to handle the "
|
||||
"file format, or the decoder has trouble with the "
|
||||
"specific version of the format.";
|
||||
} else {
|
||||
message << "Error: " << strerror(result);
|
||||
}
|
||||
(new BAlert("error", message.String(), "OK"))->Go();
|
||||
} else {
|
||||
// Just go to the next file and don't bother user (yet)
|
||||
fPlaylist->SetCurrentItemIndex(fPlaylist->CurrentItemIndex() + 1);
|
||||
}
|
||||
|
||||
fHasFile = false;
|
||||
fHasVideo = false;
|
||||
fHasAudio = false;
|
||||
SetTitle(NAME);
|
||||
} else {
|
||||
fHasFile = true;
|
||||
fHasVideo = fController->VideoTrackCount() != 0;
|
||||
fHasAudio = fController->AudioTrackCount() != 0;
|
||||
SetTitle(item->Name().String());
|
||||
fController->SetTimePosition(fInitialSeekPosition);
|
||||
fInitialSeekPosition = 0;
|
||||
}
|
||||
_SetupWindow();
|
||||
|
||||
if (result == B_OK)
|
||||
_SetFileAttributes();
|
||||
}
|
||||
|
||||
|
||||
@ -966,6 +1036,13 @@ MainWin::_SetupWindow()
|
||||
}
|
||||
_UpdateControlsEnabledStatus();
|
||||
|
||||
if (!fHasVideo && fNoVideoFrame.IsValid()) {
|
||||
MoveTo(fNoVideoFrame.LeftTop());
|
||||
ResizeTo(fNoVideoFrame.Width(), fNoVideoFrame.Height());
|
||||
}
|
||||
fNoVideoFrame = BRect();
|
||||
_ShowIfNeeded();
|
||||
|
||||
// Adopt the size and window layout if necessary
|
||||
if (previousSourceWidth != fSourceWidth
|
||||
|| previousSourceHeight != fSourceHeight
|
||||
@ -1740,6 +1817,19 @@ MainWin::_ToggleNoInterface()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWin::_ShowIfNeeded()
|
||||
{
|
||||
if (find_thread(NULL) != Thread())
|
||||
return;
|
||||
|
||||
if (IsHidden()) {
|
||||
Show();
|
||||
UpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
@ -1751,6 +1841,8 @@ MainWin::_SetFileAttributes()
|
||||
{
|
||||
const FilePlaylistItem* item
|
||||
= dynamic_cast<const FilePlaylistItem*>(fController->Item());
|
||||
if (item == NULL)
|
||||
return;
|
||||
|
||||
if (!fHasVideo && fHasAudio) {
|
||||
BNode node(&item->Ref());
|
||||
|
@ -43,7 +43,8 @@ class PlaylistWindow;
|
||||
|
||||
class MainWin : public BWindow {
|
||||
public:
|
||||
MainWin(bool isFirstWindow);
|
||||
MainWin(bool isFirstWindow,
|
||||
BMessage* message = NULL);
|
||||
virtual ~MainWin();
|
||||
|
||||
virtual void FrameResized(float newWidth, float newHeight);
|
||||
@ -73,6 +74,9 @@ public:
|
||||
|
||||
private:
|
||||
void _RefsReceived(BMessage* message);
|
||||
void _PlaylistItemOpened(
|
||||
const PlaylistItemRef& item,
|
||||
status_t result);
|
||||
|
||||
void _SetupWindow();
|
||||
void _CreateMenu();
|
||||
@ -103,6 +107,7 @@ private:
|
||||
void _ToggleFullscreen();
|
||||
void _ToggleAlwaysOnTop();
|
||||
void _ToggleNoInterface();
|
||||
void _ShowIfNeeded();
|
||||
|
||||
void _SetFileAttributes();
|
||||
void _UpdateControlsEnabledStatus();
|
||||
@ -156,6 +161,7 @@ private:
|
||||
int fControlsWidth;
|
||||
int fNoVideoWidth;
|
||||
BRect fSavedFrame;
|
||||
BRect fNoVideoFrame;
|
||||
bool fMouseDownTracking;
|
||||
BPoint fMouseDownMousePos;
|
||||
BPoint fMouseDownWindowPos;
|
||||
|
@ -464,6 +464,13 @@ TransportControlGroup::SetPosition(float value, bigtime_t position,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TransportControlGroup::SetDisabledString(const char* string)
|
||||
{
|
||||
fSeekSlider->SetDisabledString(string);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
PeakView* GetPeakView() const
|
||||
{ return fPeakView; }
|
||||
|
||||
void SetDisabledString(const char* string);
|
||||
|
||||
private:
|
||||
void _LayoutControls(BRect frame) const;
|
||||
BRect _MinFrame() const;
|
||||
|
@ -28,13 +28,16 @@ const char* kDisabledSeekMessage = "Drop files to play";
|
||||
|
||||
SeekSlider::SeekSlider(BRect frame, const char* name, BMessage* message,
|
||||
int32 minValue, int32 maxValue)
|
||||
: BControl(frame, name, NULL, message, B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS)
|
||||
, fTracking(false)
|
||||
, fLastTrackTime(0)
|
||||
, fKnobPos(_KnobPosFor(Bounds(), Value()))
|
||||
, fMinValue(minValue)
|
||||
, fMaxValue(maxValue)
|
||||
:
|
||||
BControl(frame, name, NULL, message, B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
|
||||
fTracking(false),
|
||||
fLastTrackTime(0),
|
||||
fKnobPos(_KnobPosFor(Bounds(), Value())),
|
||||
fMinValue(minValue),
|
||||
fMaxValue(maxValue),
|
||||
|
||||
fDisabledString(kDisabledSeekMessage)
|
||||
{
|
||||
BFont font(be_plain_font);
|
||||
font.SetSize(9.0);
|
||||
@ -217,7 +220,7 @@ SeekSlider::Draw(BRect updateRect)
|
||||
SetHighColor(darkShadow);
|
||||
SetLowColor(shadow);
|
||||
// stripes
|
||||
float width = floorf(StringWidth(kDisabledSeekMessage));
|
||||
float width = floorf(StringWidth(fDisabledString.String()));
|
||||
float textPos = r.left + r.Width() / 2.0 - width / 2.0;
|
||||
pattern stripes = { { 0xc7, 0x8f, 0x1f, 0x3e, 0x7c, 0xf8, 0xf1, 0xe3 } };
|
||||
BRect stripesRect(r);
|
||||
@ -234,7 +237,8 @@ SeekSlider::Draw(BRect updateRect)
|
||||
SetLowColor(darkShadow);
|
||||
font_height fh;
|
||||
GetFontHeight(&fh);
|
||||
DrawString(kDisabledSeekMessage, BPoint(textPos, r.top + ceilf(fh.ascent) - 1.0));
|
||||
DrawString(fDisabledString.String(),
|
||||
BPoint(textPos, r.top + ceilf(fh.ascent) - 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,7 +276,7 @@ SeekSlider::MouseUp(BPoint where)
|
||||
void
|
||||
SeekSlider::ResizeToPreferred()
|
||||
{
|
||||
float width = 15.0 + StringWidth(kDisabledSeekMessage) + 15.0;
|
||||
float width = 15.0 + StringWidth(fDisabledString.String()) + 15.0;
|
||||
ResizeTo(width, 17.0);
|
||||
}
|
||||
|
||||
@ -304,6 +308,22 @@ SeekSlider::IsTracking() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SeekSlider::SetDisabledString(const char* string)
|
||||
{
|
||||
if (string == NULL)
|
||||
string = kDisabledSeekMessage;
|
||||
|
||||
if (fDisabledString == string)
|
||||
return;
|
||||
|
||||
fDisabledString = string;
|
||||
|
||||
if (!IsEnabled())
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
@ -1,16 +1,18 @@
|
||||
/*
|
||||
* Copyright © 2006-2008 Stephan Aßmus <superstippi@gmx.de>
|
||||
* Copyright © 2006-2009 Stephan Aßmus <superstippi@gmx.de>
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef SEEK_SLIDER_H
|
||||
#define SEEK_SLIDER_H
|
||||
|
||||
|
||||
#include <Box.h>
|
||||
#include <Control.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class SeekSlider : public BControl {
|
||||
public:
|
||||
public:
|
||||
SeekSlider(BRect frame,
|
||||
const char* name, BMessage* message,
|
||||
int32 minValue, int32 maxValue);
|
||||
@ -31,6 +33,7 @@ class SeekSlider : public BControl {
|
||||
// SeekSlider
|
||||
void SetPosition(float position);
|
||||
bool IsTracking() const;
|
||||
void SetDisabledString(const char* string);
|
||||
|
||||
private:
|
||||
int32 _ValueFor(float x) const;
|
||||
@ -41,12 +44,14 @@ private:
|
||||
rgb_color right, rgb_color bottom);
|
||||
void _SetKnobPosition(int32 knobPos);
|
||||
|
||||
|
||||
private:
|
||||
bool fTracking;
|
||||
bigtime_t fLastTrackTime;
|
||||
int32 fKnobPos;
|
||||
int32 fMinValue;
|
||||
int32 fMaxValue;
|
||||
|
||||
BString fDisabledString;
|
||||
};
|
||||
|
||||
|
||||
|
@ -31,6 +31,8 @@ static vint32 sInstanceCount = 0;
|
||||
|
||||
|
||||
PlaylistItem::PlaylistItem()
|
||||
:
|
||||
fPlaybackFailed(false)
|
||||
{
|
||||
#ifdef DEBUG_INSTANCE_COUNT
|
||||
atomic_add(&sInstanceCount, 1);
|
||||
@ -118,6 +120,13 @@ PlaylistItem::Duration() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistItem::SetPlaybackFailed()
|
||||
{
|
||||
fPlaybackFailed = true;
|
||||
}
|
||||
|
||||
|
||||
//! You must hold the Playlist lock.
|
||||
bool
|
||||
PlaylistItem::AddListener(Listener* listener)
|
||||
|
@ -90,6 +90,10 @@ public:
|
||||
// playback
|
||||
virtual BMediaFile* CreateMediaFile() const = 0;
|
||||
|
||||
void SetPlaybackFailed();
|
||||
bool PlaybackFailed() const
|
||||
{ return fPlaybackFailed; }
|
||||
|
||||
// listener support
|
||||
bool AddListener(Listener* listener);
|
||||
void RemoveListener(Listener* listener);
|
||||
@ -99,6 +103,7 @@ protected:
|
||||
|
||||
private:
|
||||
BList fListeners;
|
||||
bool fPlaybackFailed;
|
||||
};
|
||||
|
||||
typedef Reference<PlaylistItem> PlaylistItemRef;
|
||||
|
Loading…
Reference in New Issue
Block a user