[haiku-commits] r35253 - haiku/trunk/src/apps/mediaplayer

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 23 Jan 2010 11:52:36 +0100 (CET)

Author: stippi
Date: 2010-01-23 11:52:36 +0100 (Sat, 23 Jan 2010)
New Revision: 35253
Changeset: http://dev.haiku-os.org/changeset/35253/haiku
Ticket: http://dev.haiku-os.org/ticket/5061

Modified:
   haiku/trunk/src/apps/mediaplayer/MainApp.cpp
   haiku/trunk/src/apps/mediaplayer/MainWin.cpp
   haiku/trunk/src/apps/mediaplayer/MainWin.h
Log:
 * Refactored storing the playlist archive in the quit message.
 * Added looping all windows on quit and store the current playlist if
   applicable.

Fixes #5061.


Modified: haiku/trunk/src/apps/mediaplayer/MainApp.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/MainApp.cpp        2010-01-23 10:34:30 UTC 
(rev 35252)
+++ haiku/trunk/src/apps/mediaplayer/MainApp.cpp        2010-01-23 10:52:36 UTC 
(rev 35253)
@@ -106,6 +106,26 @@
 bool
 MainApp::QuitRequested()
 {
+       // Make sure we store the current playlist, if applicable.
+       for (int32 i = 0; BWindow* window = WindowAt(i); i++) {
+               MainWin* playerWindow = dynamic_cast<MainWin*>(window);
+               if (playerWindow == NULL)
+                       continue;
+
+               BAutolock _(playerWindow);
+
+               BMessage quitMessage;
+               playerWindow->GetQuitMessage(&quitMessage);
+               
+               // Store the playlist if there is one. If the user has multiple
+               // instances playing audio at the this time, the first instance 
wins.
+               BMessage playlistArchive;
+               if (quitMessage.FindMessage("playlist", &playlistArchive) == 
B_OK) {
+                       _StoreCurrentPlaylist(&playlistArchive);
+                       break;
+               }
+       }
+
        // Note: This needs to be done here, SettingsWindow::QuitRequested()
        // returns "false" always. (Standard BApplication quit procedure will
        // hang otherwise.)

Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp
===================================================================
--- haiku/trunk/src/apps/mediaplayer/MainWin.cpp        2010-01-23 10:34:30 UTC 
(rev 35252)
+++ haiku/trunk/src/apps/mediaplayer/MainWin.cpp        2010-01-23 10:52:36 UTC 
(rev 35253)
@@ -737,26 +737,7 @@
 MainWin::QuitRequested()
 {
        BMessage message(M_PLAYER_QUIT);
-       message.AddPointer("instance", this);
-       message.AddRect("window frame", Frame());
-       message.AddBool("audio only", !fHasVideo);
-       message.AddInt64("creation time", fCreationTime);
-       if (!fHasVideo && fHasAudio) {
-               // store playlist, current index and position if this is audio
-               BMessage playlistArchive;
-
-               BAutolock controllerLocker(fController);
-               playlistArchive.AddInt64("position", 
fController->TimePosition());
-               controllerLocker.Unlock();
-
-               BAutolock playlistLocker(fPlaylist);
-               if (fPlaylist->Archive(&playlistArchive) != B_OK
-                       || playlistArchive.AddInt32("index",
-                               fPlaylist->CurrentItemIndex()) != B_OK
-                       || message.AddMessage("playlist", &playlistArchive) != 
B_OK) {
-                       fprintf(stderr, "Failed to store current playlist.\n");
-               }
-       }
+       GetQuitMessage(&message);
        be_app->PostMessage(&message);
        return true;
 }
@@ -927,6 +908,32 @@
 }
 
 
+void
+MainWin::GetQuitMessage(BMessage* message)
+{
+       message->AddPointer("instance", this);
+       message->AddRect("window frame", Frame());
+       message->AddBool("audio only", !fHasVideo);
+       message->AddInt64("creation time", fCreationTime);
+       if (!fHasVideo && fHasAudio) {
+               // store playlist, current index and position if this is audio
+               BMessage playlistArchive;
+
+               BAutolock controllerLocker(fController);
+               playlistArchive.AddInt64("position", 
fController->TimePosition());
+               controllerLocker.Unlock();
+
+               BAutolock playlistLocker(fPlaylist);
+               if (fPlaylist->Archive(&playlistArchive) != B_OK
+                       || playlistArchive.AddInt32("index",
+                               fPlaylist->CurrentItemIndex()) != B_OK
+                       || message->AddMessage("playlist", &playlistArchive) != 
B_OK) {
+                       fprintf(stderr, "Failed to store current playlist.\n");
+               }
+       }
+}
+
+
 // #pragma mark -
 
 

Modified: haiku/trunk/src/apps/mediaplayer/MainWin.h
===================================================================
--- haiku/trunk/src/apps/mediaplayer/MainWin.h  2010-01-23 10:34:30 UTC (rev 
35252)
+++ haiku/trunk/src/apps/mediaplayer/MainWin.h  2010-01-23 10:52:36 UTC (rev 
35253)
@@ -72,6 +72,8 @@
                        void                            VideoFormatChange(int 
width, int height,
                                                                        int 
widthAspect, int heightAspect);
 
+                       void                            
GetQuitMessage(BMessage* message);
+
 private:
                        void                            _RefsReceived(BMessage* 
message);
                        void                            _PlaylistItemOpened(


Other related posts:

  • » [haiku-commits] r35253 - haiku/trunk/src/apps/mediaplayer - superstippi