[haiku-commits] r34132 - in haiku/trunk/src/apps/mediaplayer: . interface playlist

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 19 Nov 2009 13:27:26 +0100 (CET)

Author: stippi
Date: 2009-11-19 13:27:25 +0100 (Thu, 19 Nov 2009)
New Revision: 34132
Changeset: http://dev.haiku-os.org/changeset/34132/haiku

Modified:
   haiku/trunk/src/apps/mediaplayer/Controller.cpp
   haiku/trunk/src/apps/mediaplayer/Controller.h
   haiku/trunk/src/apps/mediaplayer/ControllerObserver.cpp
   haiku/trunk/src/apps/mediaplayer/ControllerObserver.h
   haiku/trunk/src/apps/mediaplayer/MainApp.cpp
   haiku/trunk/src/apps/mediaplayer/MainApp.h
   haiku/trunk/src/apps/mediaplayer/MainWin.cpp
   haiku/trunk/src/apps/mediaplayer/MainWin.h
   haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp
   haiku/trunk/src/apps/mediaplayer/TransportControlGroup.h
   haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.cpp
   haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.h
   haiku/trunk/src/apps/mediaplayer/playlist/PlaylistItem.cpp
   haiku/trunk/src/apps/mediaplayer/playlist/PlaylistItem.h
Log:
* 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.".


Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/Controller.cpp     2009-11-19 11:53:38 UTC 
(rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/Controller.cpp     2009-11-19 12:27:25 UTC 
(rev 34132)
@@ -70,7 +70,7 @@
 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 @@
 // #pragma mark - Controller
 
 
+enum {
+       MSG_SET_TO = 'stto'
+};
+
+
 Controller::Controller()
        :
        NodeManager(),
@@ -139,6 +144,20 @@
                        // 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);
        }
@@ -182,6 +201,27 @@
 
 
 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)
 {
        BAutolock _(this);
@@ -230,14 +270,14 @@
        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 @@
        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 @@
                        useOverlays);
        }
 
-       _NotifyFileChanged();
+       _NotifyFileChanged(item.Get(), B_OK);
 
        SetPosition(0.0);
        if (fAutoplay)
@@ -342,7 +382,8 @@
 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 @@
                                        break;
                        }
        }
+
+       Unlock();
 }
 
 
@@ -870,13 +913,13 @@
 
 
 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);
        }
 }
 

Modified: haiku/trunk/src/apps/mediaplayer/Controller.h
===================================================================
--- haiku/trunk/src/apps/mediaplayer/Controller.h       2009-11-19 11:53:38 UTC 
(rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/Controller.h       2009-11-19 12:27:25 UTC 
(rev 34132)
@@ -55,7 +55,8 @@
                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 @@
        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 @@
 
                        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;

Modified: haiku/trunk/src/apps/mediaplayer/ControllerObserver.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/ControllerObserver.cpp     2009-11-19 
11:53:38 UTC (rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/ControllerObserver.cpp     2009-11-19 
12:27:25 UTC (rev 34132)
@@ -11,7 +11,9 @@
 
 #include <Message.h>
 
+#include "PlaylistItem.h"
 
+
 ControllerObserver::ControllerObserver(BHandler* target, uint32 observeFlags)
        :
        AbstractLOAdapter(target),
@@ -38,12 +40,18 @@
 
 
 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);
 }

Modified: haiku/trunk/src/apps/mediaplayer/ControllerObserver.h
===================================================================
--- haiku/trunk/src/apps/mediaplayer/ControllerObserver.h       2009-11-19 
11:53:38 UTC (rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/ControllerObserver.h       2009-11-19 
12:27:25 UTC (rev 34132)
@@ -50,7 +50,7 @@
 
        // 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);

Modified: haiku/trunk/src/apps/mediaplayer/MainApp.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/MainApp.cpp        2009-11-19 11:53:38 UTC 
(rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/MainApp.cpp        2009-11-19 12:27:25 UTC 
(rev 34132)
@@ -120,11 +120,11 @@
 
 
 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 @@
        // 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);
 }
 
 

Modified: haiku/trunk/src/apps/mediaplayer/MainApp.h
===================================================================
--- haiku/trunk/src/apps/mediaplayer/MainApp.h  2009-11-19 11:53:38 UTC (rev 
34131)
+++ haiku/trunk/src/apps/mediaplayer/MainApp.h  2009-11-19 12:27:25 UTC (rev 
34132)
@@ -64,7 +64,7 @@
                                                                MainApp();
        virtual                                         ~MainApp();
 
-                       MainWin*                        NewWindow();
+                       MainWin*                        NewWindow(BMessage* 
message = NULL);
                        int32                           PlayerCount() const;
 
 private:

Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/MainWin.cpp        2009-11-19 11:53:38 UTC 
(rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/MainWin.cpp        2009-11-19 12:27:25 UTC 
(rev 34132)
@@ -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 @@
 
        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 @@
        fSourceHeight(-1),
        fWidthAspect(0),
        fHeightAspect(0),
+       fSavedFrame(),
+       fNoVideoFrame(),
        fMouseDownTracking(false),
        fGlobalSettingsListener(this),
        fInitialSeekPosition(0)
@@ -142,8 +147,14 @@
                .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 @@
 
        Hide();
        Show();
+
+       if (message != NULL)
+               PostMessage(message);
 }
 
 
@@ -462,11 +476,22 @@
                        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 @@
                        _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 @@
 void
 MainWin::OpenPlaylistItem(const PlaylistItemRef& item)
 {
-       printf("MainWin::OpenPlaylistItem\n");
+       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 {
+               BString string;
+               string << "Opening '" << item->Name() << "'.";
+               fControls->SetDisabledString(string.String());
 
-       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);
+               if (IsHidden()) {
+                       BMessage showMessage(M_SHOW_IF_NEEDED);
+                       BMessageRunner::StartSending(BMessenger(this), 
&showMessage,
+                               150000, 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();
 }
 
 
@@ -923,7 +931,7 @@
 
 
 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,15 +939,77 @@
        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();
+}
+
+
+void
 MainWin::_SetupWindow()
 {
 //     printf("MainWin::_SetupWindow\n");
@@ -966,6 +1036,13 @@
        }
        _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 @@
 }
 
 
+void
+MainWin::_ShowIfNeeded()
+{
+       if (find_thread(NULL) != Thread())
+               return;
+
+       if (IsHidden()) {
+               Show();
+               UpdateIfNeeded();
+       }
+}
+
+
 // #pragma mark -
 
 
@@ -1751,6 +1841,8 @@
 {
        const FilePlaylistItem* item
                = dynamic_cast<const FilePlaylistItem*>(fController->Item());
+       if (item == NULL)
+               return;
 
        if (!fHasVideo && fHasAudio) {
                BNode node(&item->Ref());

Modified: haiku/trunk/src/apps/mediaplayer/MainWin.h
===================================================================
--- haiku/trunk/src/apps/mediaplayer/MainWin.h  2009-11-19 11:53:38 UTC (rev 
34131)
+++ haiku/trunk/src/apps/mediaplayer/MainWin.h  2009-11-19 12:27:25 UTC (rev 
34132)
@@ -43,7 +43,8 @@
 
 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 @@
 
 private:
                        void                            _RefsReceived(BMessage* 
message);
+                       void                            _PlaylistItemOpened(
+                                                                       const 
PlaylistItemRef& item,
+                                                                       
status_t result);
 
                        void                            _SetupWindow();
                        void                            _CreateMenu();
@@ -103,6 +107,7 @@
                        void                            _ToggleFullscreen();
                        void                            _ToggleAlwaysOnTop();
                        void                            _ToggleNoInterface();
+                       void                            _ShowIfNeeded();
 
                        void                            _SetFileAttributes();
                        void                            
_UpdateControlsEnabledStatus();
@@ -156,6 +161,7 @@
                        int                                     fControlsWidth;
                        int                                     fNoVideoWidth;
                        BRect                           fSavedFrame;
+                       BRect                           fNoVideoFrame;
                        bool                            fMouseDownTracking;
                        BPoint                          fMouseDownMousePos;
                        BPoint                          fMouseDownWindowPos;

Modified: haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp  2009-11-19 
11:53:38 UTC (rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp  2009-11-19 
12:27:25 UTC (rev 34132)
@@ -464,6 +464,13 @@
 }
 
 
+void
+TransportControlGroup::SetDisabledString(const char* string)
+{
+       fSeekSlider->SetDisabledString(string);
+}
+
+
 // #pragma mark -
 
 

Modified: haiku/trunk/src/apps/mediaplayer/TransportControlGroup.h
===================================================================
--- haiku/trunk/src/apps/mediaplayer/TransportControlGroup.h    2009-11-19 
11:53:38 UTC (rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/TransportControlGroup.h    2009-11-19 
12:27:25 UTC (rev 34132)
@@ -72,6 +72,8 @@
                        PeakView*                       GetPeakView() const
                                                                        { 
return fPeakView; }
 
+                       void                            SetDisabledString(const 
char* string);
+
 private:
                        void                            _LayoutControls(BRect 
frame) const;
                        BRect                           _MinFrame() const;

Modified: haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.cpp   2009-11-19 
11:53:38 UTC (rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.cpp   2009-11-19 
12:27:25 UTC (rev 34132)
@@ -28,13 +28,16 @@
 
 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);
@@ -78,7 +81,7 @@
 void
 SeekSlider::Draw(BRect updateRect)
 {
-       BRect r(Bounds());      
+       BRect r(Bounds());
 
        // draw both sides (the original from Be doesn't seem
        // to make a difference for enabled/disabled state)
@@ -217,7 +220,7 @@
                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 @@
                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 @@
 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 @@
 }
 
 
+void
+SeekSlider::SetDisabledString(const char* string)
+{
+       if (string == NULL)
+               string = kDisabledSeekMessage;
+
+       if (fDisabledString == string)
+               return;
+
+       fDisabledString = string;
+
+       if (!IsEnabled())
+               Invalidate();
+}
+
+
 // #pragma mark -
 
 

Modified: haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.h
===================================================================
--- haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.h     2009-11-19 
11:53:38 UTC (rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.h     2009-11-19 
12:27:25 UTC (rev 34132)
@@ -1,16 +1,18 @@
 /*
- * Copyright © 2006-2008 Stephan Aßmus <superstippi@xxxxxx>
+ * Copyright © 2006-2009 Stephan Aßmus <superstippi@xxxxxx>
  * 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 @@
        // SeekSlider
                        void                            SetPosition(float 
position);
                        bool                            IsTracking() const;
+                       void                            SetDisabledString(const 
char* string);
 
 private:
                        int32                           _ValueFor(float x) 
const;
@@ -41,12 +44,14 @@
                                                                        
rgb_color right, rgb_color bottom);
                        void                            _SetKnobPosition(int32 
knobPos);
 
-
+private:
                        bool                            fTracking;
                        bigtime_t                       fLastTrackTime;
                        int32                           fKnobPos;
                        int32                           fMinValue;
                        int32                           fMaxValue;
+
+                       BString                         fDisabledString;
 };
 
 

Modified: haiku/trunk/src/apps/mediaplayer/playlist/PlaylistItem.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/playlist/PlaylistItem.cpp  2009-11-19 
11:53:38 UTC (rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/playlist/PlaylistItem.cpp  2009-11-19 
12:27:25 UTC (rev 34132)
@@ -31,6 +31,8 @@
 
 
 PlaylistItem::PlaylistItem()
+       :
+       fPlaybackFailed(false)
 {
 #ifdef DEBUG_INSTANCE_COUNT
        atomic_add(&sInstanceCount, 1);
@@ -118,6 +120,13 @@
 }
 
 
+void
+PlaylistItem::SetPlaybackFailed()
+{
+       fPlaybackFailed = true;
+}
+
+
 //! You must hold the Playlist lock.
 bool
 PlaylistItem::AddListener(Listener* listener)

Modified: haiku/trunk/src/apps/mediaplayer/playlist/PlaylistItem.h
===================================================================
--- haiku/trunk/src/apps/mediaplayer/playlist/PlaylistItem.h    2009-11-19 
11:53:38 UTC (rev 34131)
+++ haiku/trunk/src/apps/mediaplayer/playlist/PlaylistItem.h    2009-11-19 
12:27:25 UTC (rev 34132)
@@ -90,6 +90,10 @@
        // 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 @@
 
 private:
                        BList                           fListeners;
+                       bool                            fPlaybackFailed;
 };
 
 typedef Reference<PlaylistItem> PlaylistItemRef;


Other related posts:

  • » [haiku-commits] r34132 - in haiku/trunk/src/apps/mediaplayer: . interface playlist - superstippi