changeset 33263:5f527a9a9521

Add an exit function. This function will allow performing clean-up operations. (MPlayer calls guiDone() before exiting, but only if the GUI has been initialized, i.e. if guiInit() has been called successfully. Any exit_player()/exit_player_with_rc() after GUI's cfg_read() until guiInit(), or any exit_player() during guiInit() itself will end the GUI without calling guiDone(). This exit function will at least handle abortions during guiInit() itself. It will be called twice in case of an guiExit() after GUI initialization - first directly, next by guiDone() via MPlayer's exit_player_with_rc().)
author ib
date Tue, 03 May 2011 12:19:22 +0000
parents 9fb04a4269bb
children 284fc94290b9
files gui/interface.c gui/interface.h gui/mplayer/mw.c gui/mplayer/pb.c gui/mplayer/sw.c
diffstat 5 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/gui/interface.c	Tue May 03 09:51:59 2011 +0000
+++ b/gui/interface.c	Tue May 03 12:19:22 2011 +0000
@@ -52,6 +52,8 @@
 #include "stream/stream_dvd.h"
 #endif
 
+#define DONE -1
+
 guiInterface_t guiIntfStruct;
 
 int guiWinID = -1;
@@ -220,11 +222,11 @@
     switch (i) {
     case -1:
         gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_SKIN_SKINCFG_SkinNotFound, skinName);
-        exit_player(EXIT_ERROR);
+        guiExit(EXIT_ERROR);
 
     case -2:
         gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_SKIN_SKINCFG_SkinCfgError, skinName);
-        exit_player(EXIT_ERROR);
+        guiExit(EXIT_ERROR);
     }
 
     // initialize windows
@@ -233,7 +235,7 @@
 
     if (!mplDrawBuffer) {
         gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_NEMDB);
-        exit_player(EXIT_ERROR);
+        guiExit(EXIT_ERROR);
     }
 
     if (gui_save_pos) {
@@ -401,6 +403,22 @@
 
     cfg_write();
     wsXDone();
+
+    guiExit(DONE);
+}
+
+// NOTE TO MYSELF: Before calling guiInit(), MPlayer calls GUI functions
+// cfg_read() and import_initial_playtree_into_gui(). Only
+// after guiInit() has been called successfully, guiDone()
+// (and thus guiExit()) will be executed by MPlayer on exit.
+// In other words, any MPlayer's exit between cfg_read() and
+// guiInit() will not execute guiDone().
+// With this function it is at least possible to handle
+// GUI's own abortions during (and before) guiInit().
+void guiExit(int how)
+{
+    if (how != DONE)
+        exit_player(how);
 }
 
 void guiLoadFont(void)
@@ -852,7 +870,7 @@
 
         if (!video_driver_list && !video_driver_list[0]) {
             gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_IDFGCVD);
-            exit_player(EXIT_ERROR);
+            guiExit(EXIT_ERROR);
         }
 
         {
--- a/gui/interface.h	Tue May 03 09:51:59 2011 +0000
+++ b/gui/interface.h	Tue May 03 12:19:22 2011 +0000
@@ -239,6 +239,7 @@
 void *gtkSet(int cmd, float fparam, void *vparam);
 void guiDone(void);
 void guiEventHandling(void);
+void guiExit(int how);
 int guiGetEvent(int type, void *arg);
 void guiInit(void);
 void guiLoadFont(void);
--- a/gui/mplayer/mw.c	Tue May 03 09:51:59 2011 +0000
+++ b/gui/mplayer/mw.c	Tue May 03 12:19:22 2011 +0000
@@ -75,7 +75,7 @@
 void mplMainDraw( void )
 {
 
- if ( appMPlayer.mainWindow.State == wsWindowClosed ) exit_player( EXIT_QUIT );
+ if ( appMPlayer.mainWindow.State == wsWindowClosed ) guiExit( EXIT_QUIT );
 
  if ( appMPlayer.mainWindow.Visible == wsWindowNotVisible ||
       !mainVisible ) return;
@@ -105,7 +105,7 @@
   {
 // --- user events
    case evExit:
-        exit_player( EXIT_QUIT );
+        guiExit( EXIT_QUIT );
         break;
 
    case evPlayNetwork:
--- a/gui/mplayer/pb.c	Tue May 03 09:51:59 2011 +0000
+++ b/gui/mplayer/pb.c	Tue May 03 12:19:22 2011 +0000
@@ -247,7 +247,7 @@
  if ( ( mplPBDrawBuffer = malloc( appMPlayer.bar.Bitmap.ImageSize ) ) == NULL )
   {
    gmp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_NEMDB );
-   exit_player( EXIT_ERROR );
+   guiExit( EXIT_ERROR );
   }
 
  appMPlayer.barWindow.Parent=appMPlayer.subWindow.WindowID;
--- a/gui/mplayer/sw.c	Tue May 03 09:51:59 2011 +0000
+++ b/gui/mplayer/sw.c	Tue May 03 12:19:22 2011 +0000
@@ -35,7 +35,7 @@
 
 void mplSubDraw( void )
 {
- if ( appMPlayer.subWindow.State == wsWindowClosed ) exit_player( EXIT_QUIT );
+ if ( appMPlayer.subWindow.State == wsWindowClosed ) guiExit( EXIT_QUIT );
 
  if ( appMPlayer.subWindow.State == wsWindowFocusIn ) SubVisible++;
  if ( appMPlayer.subWindow.State == wsWindowFocusOut && metacity_hack != 3 ) SubVisible--;