[MPlayer-cvslog] r33830 - in trunk/gui: cfg.c interface.c interface.h ui/actions.c ui/gtk/playlist.c ui/gtk/url.c ui/main.c util/list.c util/list.h

ib subversion at mplayerhq.hu
Thu Jul 7 13:50:33 CEST 2011


Author: ib
Date: Thu Jul  7 13:50:32 2011
New Revision: 33830

Log:
Move purely list related parts of gtkSet() from interface.c to list.c.

Rename that part listSet() and remove now unused parameter fparam.
Remove needless casts in listSet() calls.
Remove needless explicit initialization of global list variables.

Additionally, remove disabled debug code list().

Modified:
   trunk/gui/cfg.c
   trunk/gui/interface.c
   trunk/gui/interface.h
   trunk/gui/ui/actions.c
   trunk/gui/ui/gtk/playlist.c
   trunk/gui/ui/gtk/url.c
   trunk/gui/ui/main.c
   trunk/gui/util/list.c
   trunk/gui/util/list.h

Modified: trunk/gui/cfg.c
==============================================================================
--- trunk/gui/cfg.c	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/cfg.c	Thu Jul  7 13:50:32 2011	(r33830)
@@ -22,6 +22,7 @@
 
 #include "cfg.h"
 #include "interface.h"
+#include "util/list.h"
 #include "util/string.h"
 
 #include "config.h"
@@ -300,7 +301,7 @@ int cfg_read(void)
             item->path = strdup(tmp);
             gfgets(tmp, 512, f);
             item->name = strdup(tmp);
-            gtkSet(gtkAddPlItem, 0, (void *)item);
+            listSet(gtkAddPlItem, item);
         }
 
         fclose(f);
@@ -323,7 +324,7 @@ int cfg_read(void)
 
             item      = calloc(1, sizeof(urlItem));
             item->url = strdup(tmp);
-            gtkSet(gtkAddURLItem, 0, (void *)item);
+            listSet(gtkAddURLItem, item);
         }
 
         fclose(f);

Modified: trunk/gui/interface.c
==============================================================================
--- trunk/gui/interface.c	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/interface.c	Thu Jul  7 13:50:32 2011	(r33830)
@@ -66,12 +66,6 @@ char *skinName;
 char *skinDirInHome;
 char *skinMPlayerDir;
 
-plItem *plCurrent    = NULL;
-plItem *plList       = NULL;
-plItem *plLastPlayed = NULL;
-
-urlItem *URLList = NULL;
-
 char *fsHistory[fsPersistant_MaxPos] = { NULL, NULL, NULL, NULL, NULL };
 
 float gtkEquChannels[6][10];
@@ -907,7 +901,7 @@ int gui(int what, void *arg)
             break;
         }
 
-        if (guiInfo.Playing && (next = gtkSet(gtkGetNextPlItem, 0, NULL)) && (plLastPlayed != next)) {
+        if (guiInfo.Playing && (next = listSet(gtkGetNextPlItem, NULL)) && (plLastPlayed != next)) {
             plLastPlayed = next;
             setddup(&guiInfo.Filename, next->path, next->name);
             guiInfo.StreamType      = STREAMTYPE_FILE;
@@ -948,201 +942,11 @@ int gui(int what, void *arg)
     return True;
 }
 
-// ---
-#if defined(MP_DEBUG) && 0
-void list(void)
-{
-    plItem *next = plList;
-
-    printf("--- list ---\n");
-
-    while (next || next->next) {
-        printf("item: %s/%s\n", next->path, next->name);
-
-        if (next->next)
-            next = next->next;
-        else
-            break;
-    }
-
-    printf("--- end of list ---\n");
-}
-#else
-#define list();
-#endif
-
 void *gtkSet(int cmd, float fparam, void *vparam)
 {
-    equalizer_t *eq   = (equalizer_t *)vparam;
-    plItem *item      = (plItem *)vparam;
-    urlItem *url_item = (urlItem *)vparam;
-    int is_added      = True;
+    equalizer_t *eq = (equalizer_t *)vparam;
 
     switch (cmd) {
-    // handle playlist
-
-    // add item to playlist
-    case gtkAddPlItem:
-
-        if (plList) {
-            plItem *next = plList;
-
-            while (next->next)
-// {
-// printf( "%s\n",next->name );
-                next = next->next;
-// }
-
-            next->next = item;
-            item->prev = next;
-            item->next = NULL;
-        } else {
-            item->prev = item->next = NULL;
-            plCurrent  = plList = item;
-        }
-
-        list();
-
-        return NULL;
-
-    // add item into playlist after current
-    case gtkInsertPlItem:
-        if (plCurrent) {
-            plItem *curr = plCurrent;
-            item->next = curr->next;
-
-            if (item->next)
-                item->next->prev = item;
-
-            item->prev = curr;
-            curr->next = item;
-            plCurrent  = plCurrent->next;
-
-            return plCurrent;
-        } else
-            return gtkSet(gtkAddPlItem, 0, (void *)item);
-        return NULL;   // NOTE TO MYSELF: remove this
-
-    // get next item from playlist
-    case gtkGetNextPlItem:
-        if (plCurrent && plCurrent->next) {
-            plCurrent = plCurrent->next;
-// if (!plCurrent && plList)
-// {
-// plItem *next = plList;
-//
-// while (next->next)
-// {
-// if (!next->next) break;
-// next = next->next;
-// }
-//
-// plCurrent = next;
-// }
-            return plCurrent;
-        }
-
-        return NULL;
-
-    // get previous item from playlist
-    case gtkGetPrevPlItem:
-        if (plCurrent && plCurrent->prev) {
-            plCurrent = plCurrent->prev;
-// if ( !plCurrent && plList ) plCurrent=plList;
-            return plCurrent;
-        }
-
-        return NULL;
-
-    // set current item
-    case gtkSetCurrPlItem:
-        plCurrent = item;
-        return plCurrent;
-
-    // get current item
-    case gtkGetCurrPlItem:
-        return plCurrent;
-
-    // delete current item
-    case gtkDelCurrPlItem:
-    {
-        plItem *curr = plCurrent;
-
-        if (!curr)
-            return NULL;
-
-        if (curr->prev)
-            curr->prev->next = curr->next;
-        if (curr->next)
-            curr->next->prev = curr->prev;
-        if (curr == plList)
-            plList = curr->next;
-
-        plCurrent = curr->next;
-
-        // free it
-        free(curr->path);
-        free(curr->name);
-        free(curr);
-    }
-
-        uiCurr();   // instead of using uiNext && uiPrev
-
-        return plCurrent;
-
-    // delete list
-    case gtkDelPl:
-    {
-        plItem *curr = plList;
-        plItem *next;
-
-        if (!plList)
-            return NULL;
-
-        if (!curr->next) {
-            free(curr->path);
-            free(curr->name);
-            free(curr);
-        } else {
-            while (curr->next) {
-                next = curr->next;
-                free(curr->path);
-                free(curr->name);
-                free(curr);
-                curr = next;
-            }
-        }
-
-        plList    = NULL;
-        plCurrent = NULL;
-    }
-
-        return NULL;
-
-    // handle url
-    case gtkAddURLItem:
-        if (URLList) {
-            urlItem *next_url = URLList;
-            is_added = False;
-
-            while (next_url->next) {
-                if (!gstrcmp(next_url->url, url_item->url)) {
-                    is_added = True;
-                    break;
-                }
-
-                next_url = next_url->next;
-            }
-
-            if (!is_added && gstrcmp(next_url->url, url_item->url))
-                next_url->next = url_item;
-        } else {
-            url_item->next = NULL;
-            URLList = url_item;
-        }
-
-        return NULL;
-
         // subtitle
 
 #ifndef CONFIG_FREETYPE
@@ -1198,7 +1002,7 @@ void *gtkSet(int cmd, float fparam, void
             nfree(guiInfo.Filename);
             nfree(guiInfo.Subtitlename);
             nfree(guiInfo.AudioFile);
-            gtkSet(gtkDelPl, 0, NULL);
+            listSet(gtkDelPl, NULL);
         }
 
 #ifdef CONFIG_DVDREAD
@@ -1316,9 +1120,9 @@ static int import_file_into_gui(char *te
     item->path = pathname;
 
     if (insert)
-        gtkSet(gtkInsertPlItem, 0, (void *)item);            // inserts the item after current, and makes current=item
+        listSet(gtkInsertPlItem, item);           // inserts the item after current, and makes current=item
     else
-        gtkSet(gtkAddPlItem, 0, (void *)item);
+        listSet(gtkAddPlItem, item);
 
     return 1;
 }
@@ -1333,7 +1137,7 @@ int guiInitializePlaylist(play_tree_t *m
     int result = 0;
 
     if (!enqueue)
-        gtkSet(gtkDelPl, 0, 0);             // delete playlist before "appending"
+        listSet(gtkDelPl, NULL);             // delete playlist before "appending"
 
     if ((my_pt_iter = pt_iter_create(&my_playtree, config))) {
         while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
@@ -1364,7 +1168,7 @@ int guiAddPlaylist(play_tree_t *my_playt
     int result = 0;
     plItem *save;
 
-    save = (plItem *)gtkSet(gtkGetCurrPlItem, 0, 0);    // save current item
+    save = (plItem *)listSet(gtkGetCurrPlItem, NULL);    // save current item
 
     if ((my_pt_iter = pt_iter_create(&my_playtree, config))) {
         while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
@@ -1376,12 +1180,12 @@ int guiAddPlaylist(play_tree_t *my_playt
     }
 
     if (save)
-        gtkSet(gtkSetCurrPlItem, 0, (void *)save);
+        listSet(gtkSetCurrPlItem, save);
     else
-        gtkSet(gtkSetCurrPlItem, 0, (void *)plList);     // go to head, if plList was empty before
+        listSet(gtkSetCurrPlItem, plList);    // go to head, if plList was empty before
 
     if (save && result)
-        gtkSet(gtkDelCurrPlItem, 0, 0);
+        listSet(gtkDelCurrPlItem, NULL);
 
     uiCurr();   // update filename
     filename = NULL;

Modified: trunk/gui/interface.h
==============================================================================
--- trunk/gui/interface.h	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/interface.h	Thu Jul  7 13:50:32 2011	(r33830)
@@ -65,17 +65,11 @@ extern int use_gui;             // this 
 #define gtkSetHue           2
 #define gtkSetSaturation    3
 #define gtkSetEqualizer     4
-#define gtkAddPlItem        5
-#define gtkGetNextPlItem    6
-#define gtkGetPrevPlItem    7
-#define gtkGetCurrPlItem    8
-#define gtkDelPl            9
 #define gtkSetExtraStereo   10
 #define gtkSetPanscan       11
 #define gtkSetFontFactor    12
 #define gtkSetAutoq         13
 #define gtkClearStruct      14
-#define gtkAddURLItem       15
 #define gtkSetFontOutLine   16
 #define gtkSetFontBlur      17
 #define gtkSetFontTextScale 18
@@ -83,9 +77,6 @@ extern int use_gui;             // this 
 #define gtkSetFontEncoding  20
 #define gtkSetFontAutoScale 21
 #define gtkSetSubEncoding   22
-#define gtkDelCurrPlItem    23
-#define gtkInsertPlItem     24
-#define gtkSetCurrPlItem    25
 
 #define fsPersistant_MaxPos 5
 
@@ -182,17 +173,6 @@ typedef struct {
     int SkinChange;
 } guiInterface_t;
 
-typedef struct plItem {
-    struct plItem *prev, *next;
-    char *path;
-    char *name;
-} plItem;
-
-typedef struct urlItem {
-    struct urlItem *next;
-    char *url;
-} urlItem;
-
 extern guiInterface_t guiInfo;
 
 extern int guiWinID;
@@ -201,12 +181,6 @@ extern char *skinName;
 extern char *skinDirInHome;
 extern char *skinMPlayerDir;
 
-extern plItem *plList;
-extern plItem *plCurrent;
-extern plItem *plLastPlayed;
-
-extern urlItem *URLList;
-
 extern char *fsHistory[fsPersistant_MaxPos];
 
 extern float gtkEquChannels[6][10];

Modified: trunk/gui/ui/actions.c
==============================================================================
--- trunk/gui/ui/actions.c	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/ui/actions.c	Thu Jul  7 13:50:32 2011	(r33830)
@@ -25,6 +25,7 @@
 #include "gui/interface.h"
 #include "gui/skin/font.h"
 #include "gui/skin/skin.h"
+#include "gui/util/list.h"
 #include "gui/util/mem.h"
 #include "gui/util/string.h"
 #include "gui/wm/wsxdnd.h"
@@ -287,7 +288,7 @@ void uiCurr(void)
 
     default:
 
-        curr = gtkSet(gtkGetCurrPlItem, 0, NULL);
+        curr = listSet(gtkGetCurrPlItem, NULL);
 
         if (curr) {
             uiSetFileName(curr->path, curr->name, STREAMTYPE_FILE);
@@ -341,7 +342,7 @@ void uiPrev(void)
 
     default:
 
-        prev = gtkSet(gtkGetPrevPlItem, 0, NULL);
+        prev = listSet(gtkGetPrevPlItem, NULL);
 
         if (prev) {
             uiSetFileName(prev->path, prev->name, STREAMTYPE_FILE);
@@ -401,7 +402,7 @@ void uiNext(void)
 
     default:
 
-        next = gtkSet(gtkGetNextPlItem, 0, NULL);
+        next = listSet(gtkGetNextPlItem, NULL);
 
         if (next) {
             uiSetFileName(next->path, next->name, STREAMTYPE_FILE);

Modified: trunk/gui/ui/gtk/playlist.c
==============================================================================
--- trunk/gui/ui/gtk/playlist.c	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/ui/gtk/playlist.c	Thu Jul  7 13:50:32 2011	(r33830)
@@ -33,6 +33,7 @@
 
 #include "gui/interface.h"
 #include "gui/ui/widgets.h"
+#include "gui/util/list.h"
 #include "gui/util/mem.h"
 #include "playlist.h"
 #include "tools.h"
@@ -190,7 +191,7 @@ static void plButtonReleased( GtkButton 
   case 1: // ok
        {
         int i;
-	if ( plList ) gtkSet( gtkDelPl,0,NULL );
+	if ( plList ) listSet( gtkDelPl,NULL );
 	for ( i=0;i<NrOfSelected;i++ )
 	 {
 	  plItem * item;
@@ -202,7 +203,7 @@ static void plButtonReleased( GtkButton 
 	  if ( !item->name ) item->name = strdup( text[0] );
 	  item->path=g_filename_from_utf8( text[1], -1, NULL, NULL, NULL );
 	  if ( !item->path ) item->path = strdup( text[1] );
-	  gtkSet( gtkAddPlItem,0,(void*)item );
+	  listSet( gtkAddPlItem,item );
 	 }
 	if ( plCurrent )
 	 {

Modified: trunk/gui/ui/gtk/url.c
==============================================================================
--- trunk/gui/ui/gtk/url.c	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/ui/gtk/url.c	Thu Jul  7 13:50:32 2011	(r33830)
@@ -32,6 +32,7 @@
 #include "gui/app.h"
 #include "gui/ui/gmplayer.h"
 #include "gui/ui/widgets.h"
+#include "gui/util/list.h"
 #include "gui/util/string.h"
 #include "help_mp.h"
 
@@ -100,7 +101,7 @@ static void on_Button_pressed( GtkButton
 
      item=calloc( 1,sizeof( urlItem ) );
      item->url=gstrdup( str );
-     gtkSet( gtkAddURLItem,0,(void *)item );
+     listSet( gtkAddURLItem,item );
 
      setdup( &guiInfo.Filename,str ); guiInfo.FilenameChanged=1;
      uiEventHandling( evPlayNetwork,0 );

Modified: trunk/gui/ui/main.c
==============================================================================
--- trunk/gui/ui/main.c	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/ui/main.c	Thu Jul  7 13:50:32 2011	(r33830)
@@ -30,6 +30,7 @@
 #include "gui/interface.h"
 #include "gui/skin/font.h"
 #include "gui/skin/skin.h"
+#include "gui/util/list.h"
 #include "gui/util/mem.h"
 #include "gui/util/string.h"
 #include "gui/wm/ws.h"
@@ -158,9 +159,9 @@ play:
 
         if ( ( msg == evPlaySwitchToPause )&&( guiInfo.Playing == GUI_PAUSE ) ) goto NoPause;
 
-	if ( gtkSet( gtkGetCurrPlItem,0,NULL ) &&( guiInfo.StreamType == STREAMTYPE_FILE ) )
+	if ( listSet( gtkGetCurrPlItem,NULL ) &&( guiInfo.StreamType == STREAMTYPE_FILE ) )
 	 {
-	  plItem * next = gtkSet( gtkGetCurrPlItem,0,NULL );
+	  plItem * next = listSet( gtkGetCurrPlItem,NULL );
 	  plLastPlayed=next;
 	  uiSetFileName( next->path,next->name,STREAMTYPE_FILE );
 	 }
@@ -239,7 +240,7 @@ NoPause:
         uiMainAutoPlay=1;
 //	guiInfo.StreamType=STREAMTYPE_FILE;
    case evLoad:
-	gtkSet( gtkDelPl,0,NULL );
+	listSet( gtkDelPl,NULL );
         gtkShow( evLoad,NULL );
         break;
    case evLoadSubtitle:  gtkShow( evLoadSubtitle,NULL );  break;
@@ -605,7 +606,7 @@ void uiDandDHandler(int num,char** files
       /* clear playlist */
       if (filename == NULL) {
 	filename = files[f];
-	gtkSet(gtkDelPl,0,NULL);
+	listSet(gtkDelPl,NULL);
       }
 
       item = calloc(1,sizeof(plItem));
@@ -620,7 +621,7 @@ void uiDandDHandler(int num,char** files
 	item->name = strdup(str);
 	item->path = strdup("");
       }
-      gtkSet(gtkAddPlItem,0,(void*)item);
+      listSet(gtkAddPlItem,item);
     } else {
       mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_NotAFile,str );
     }

Modified: trunk/gui/util/list.c
==============================================================================
--- trunk/gui/util/list.c	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/util/list.c	Thu Jul  7 13:50:32 2011	(r33830)
@@ -22,6 +22,176 @@
 #include "list.h"
 #include "string.h"
 
+plItem *plList;
+plItem *plCurrent;
+plItem *plLastPlayed;
+
+urlItem *URLList;
+
+void *listSet(int cmd, void *vparam)
+{
+    plItem *item      = (plItem *)vparam;
+    urlItem *url_item = (urlItem *)vparam;
+    int is_added      = 1;
+
+    switch (cmd) {
+    // handle playlist
+
+    // add item to playlist
+    case gtkAddPlItem:
+        if (plList) {
+            plItem *next = plList;
+
+            while (next->next)
+// {
+// printf( "%s\n",next->name );
+                next = next->next;
+// }
+
+            next->next = item;
+            item->prev = next;
+            item->next = NULL;
+        } else {
+            item->prev = item->next = NULL;
+            plCurrent  = plList = item;
+        }
+        return NULL;
+
+    // add item into playlist after current
+    case gtkInsertPlItem:
+        if (plCurrent) {
+            plItem *curr = plCurrent;
+            item->next = curr->next;
+
+            if (item->next)
+                item->next->prev = item;
+
+            item->prev = curr;
+            curr->next = item;
+            plCurrent  = plCurrent->next;
+
+            return plCurrent;
+        } else
+            return listSet(gtkAddPlItem, item);
+
+    // get next item from playlist
+    case gtkGetNextPlItem:
+        if (plCurrent && plCurrent->next) {
+            plCurrent = plCurrent->next;
+// if (!plCurrent && plList)
+// {
+// plItem *next = plList;
+//
+// while (next->next)
+// {
+// if (!next->next) break;
+// next = next->next;
+// }
+//
+// plCurrent = next;
+// }
+            return plCurrent;
+        }
+        return NULL;
+
+    // get previous item from playlist
+    case gtkGetPrevPlItem:
+        if (plCurrent && plCurrent->prev) {
+            plCurrent = plCurrent->prev;
+// if ( !plCurrent && plList ) plCurrent=plList;
+            return plCurrent;
+        }
+        return NULL;
+
+    // set current item
+    case gtkSetCurrPlItem:
+        plCurrent = item;
+        return plCurrent;
+
+    // get current item
+    case gtkGetCurrPlItem:
+        return plCurrent;
+
+    // delete current item
+    case gtkDelCurrPlItem:
+    {
+        plItem *curr = plCurrent;
+
+        if (!curr)
+            return NULL;
+
+        if (curr->prev)
+            curr->prev->next = curr->next;
+        if (curr->next)
+            curr->next->prev = curr->prev;
+        if (curr == plList)
+            plList = curr->next;
+
+        plCurrent = curr->next;
+
+        // free it
+        free(curr->path);
+        free(curr->name);
+        free(curr);
+    }
+        //uiCurr();     // instead of using uiNext && uiPrev
+        return plCurrent;
+
+    // delete list
+    case gtkDelPl:
+    {
+        plItem *curr = plList;
+        plItem *next;
+
+        if (!plList)
+            return NULL;
+
+        if (!curr->next) {
+            free(curr->path);
+            free(curr->name);
+            free(curr);
+        } else {
+            while (curr->next) {
+                next = curr->next;
+                free(curr->path);
+                free(curr->name);
+                free(curr);
+                curr = next;
+            }
+        }
+
+        plList    = NULL;
+        plCurrent = NULL;
+    }
+        return NULL;
+
+    // handle url
+    case gtkAddURLItem:
+        if (URLList) {
+            urlItem *next_url = URLList;
+            is_added = 0;
+
+            while (next_url->next) {
+                if (!gstrcmp(next_url->url, url_item->url)) {
+                    is_added = 1;
+                    break;
+                }
+
+                next_url = next_url->next;
+            }
+
+            if (!is_added && gstrcmp(next_url->url, url_item->url))
+                next_url->next = url_item;
+        } else {
+            url_item->next = NULL;
+            URLList = url_item;
+        }
+        return NULL;
+    }
+
+    return NULL;
+}
+
 /**
  * \brief This actually creates a new list containing only one element...
  */

Modified: trunk/gui/util/list.h
==============================================================================
--- trunk/gui/util/list.h	Thu Jul  7 12:37:58 2011	(r33829)
+++ trunk/gui/util/list.h	Thu Jul  7 13:50:32 2011	(r33830)
@@ -19,7 +19,35 @@
 #ifndef MPLAYER_GUI_LIST_H
 #define MPLAYER_GUI_LIST_H
 
+#define gtkAddPlItem     5
+#define gtkGetNextPlItem 6
+#define gtkGetPrevPlItem 7
+#define gtkGetCurrPlItem 8
+#define gtkDelPl         9
+#define gtkDelCurrPlItem 23
+#define gtkInsertPlItem  24
+#define gtkSetCurrPlItem 25
+#define gtkAddURLItem    15
+
+typedef struct plItem {
+    struct plItem *prev, *next;
+    char *path;
+    char *name;
+} plItem;
+
+typedef struct urlItem {
+    struct urlItem *next;
+    char *url;
+} urlItem;
+
+extern plItem *plList;
+extern plItem *plCurrent;
+extern plItem *plLastPlayed;
+
+extern urlItem *URLList;
+
 void gaddlist(char ***list, const char *entry);
 void greplace(char ***list, const char *search, const char *replace);
+void *listSet(int cmd, void *vparam);
 
 #endif /* MPLAYER_GUI_LIST_H */


More information about the MPlayer-cvslog mailing list