changeset 33742:e1539e14d60f

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().
author ib
date Thu, 07 Jul 2011 11:50:32 +0000
parents 962dc701989d
children 99562e7c8b27
files gui/cfg.c gui/interface.c gui/interface.h gui/ui/actions.c gui/ui/gtk/playlist.c gui/ui/gtk/url.c gui/ui/main.c gui/util/list.c gui/util/list.h
diffstat 9 files changed, 226 insertions(+), 245 deletions(-) [+]
line wrap: on
line diff
--- a/gui/cfg.c	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/cfg.c	Thu Jul 07 11:50:32 2011 +0000
@@ -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 @@
             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 @@
 
             item      = calloc(1, sizeof(urlItem));
             item->url = strdup(tmp);
-            gtkSet(gtkAddURLItem, 0, (void *)item);
+            listSet(gtkAddURLItem, item);
         }
 
         fclose(f);
--- a/gui/interface.c	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/interface.c	Thu Jul 07 11:50:32 2011 +0000
@@ -66,12 +66,6 @@
 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 @@
             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 @@
     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 @@
             nfree(guiInfo.Filename);
             nfree(guiInfo.Subtitlename);
             nfree(guiInfo.AudioFile);
-            gtkSet(gtkDelPl, 0, NULL);
+            listSet(gtkDelPl, NULL);
         }
 
 #ifdef CONFIG_DVDREAD
@@ -1316,9 +1120,9 @@
     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 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 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 @@
     }
 
     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;
--- a/gui/interface.h	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/interface.h	Thu Jul 07 11:50:32 2011 +0000
@@ -65,17 +65,11 @@
 #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 @@
 #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 @@
     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 *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];
--- a/gui/ui/actions.c	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/ui/actions.c	Thu Jul 07 11:50:32 2011 +0000
@@ -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 @@
 
     default:
 
-        curr = gtkSet(gtkGetCurrPlItem, 0, NULL);
+        curr = listSet(gtkGetCurrPlItem, NULL);
 
         if (curr) {
             uiSetFileName(curr->path, curr->name, STREAMTYPE_FILE);
@@ -341,7 +342,7 @@
 
     default:
 
-        prev = gtkSet(gtkGetPrevPlItem, 0, NULL);
+        prev = listSet(gtkGetPrevPlItem, NULL);
 
         if (prev) {
             uiSetFileName(prev->path, prev->name, STREAMTYPE_FILE);
@@ -401,7 +402,7 @@
 
     default:
 
-        next = gtkSet(gtkGetNextPlItem, 0, NULL);
+        next = listSet(gtkGetNextPlItem, NULL);
 
         if (next) {
             uiSetFileName(next->path, next->name, STREAMTYPE_FILE);
--- a/gui/ui/gtk/playlist.c	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/ui/gtk/playlist.c	Thu Jul 07 11:50:32 2011 +0000
@@ -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 @@
   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 @@
 	  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 )
 	 {
--- a/gui/ui/gtk/url.c	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/ui/gtk/url.c	Thu Jul 07 11:50:32 2011 +0000
@@ -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 @@
 
      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 );
--- a/gui/ui/main.c	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/ui/main.c	Thu Jul 07 11:50:32 2011 +0000
@@ -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 @@
 
         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 @@
         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 @@
       /* clear playlist */
       if (filename == NULL) {
 	filename = files[f];
-	gtkSet(gtkDelPl,0,NULL);
+	listSet(gtkDelPl,NULL);
       }
 
       item = calloc(1,sizeof(plItem));
@@ -620,7 +621,7 @@
 	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 );
     }
--- a/gui/util/list.c	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/util/list.c	Thu Jul 07 11:50:32 2011 +0000
@@ -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...
  */
--- a/gui/util/list.h	Thu Jul 07 10:37:58 2011 +0000
+++ b/gui/util/list.h	Thu Jul 07 11:50:32 2011 +0000
@@ -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 */