diff gui/interface.c @ 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 cee07c3dbff5
children 62c0471bcf8c
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);
         }
 
         {