changeset 2202:d1804718c5cc trunk

[svn] - playlist manager, work done for data consistency; now it should react and update when it is active and playlists are created/modified/deleted outside the manager (i.e. with keyboard shortcuts)
author giacomo
date Fri, 22 Dec 2006 17:35:11 -0800
parents 39e9c8e2745d
children 60bd49189fde
files ChangeLog audacious/playlist.c audacious/playlist_manager.c audacious/playlist_manager.h
diffstat 4 files changed, 77 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Dec 22 16:29:35 2006 -0800
+++ b/ChangeLog	Fri Dec 22 17:35:11 2006 -0800
@@ -1,3 +1,14 @@
+2006-12-23 00:29:35 +0000  Giacomo Lozito <james@develia.org>
+  revision [3407]
+  - added initial code for playlist manager, that allows to create, delete and switch playlists
+  trunk/audacious/Makefile           |    2 
+  trunk/audacious/playlist_manager.c |  235 +++++++++++++++++++++++++++++++++++++
+  trunk/audacious/playlist_manager.h |   26 ++++
+  trunk/audacious/ui/playlist.ui     |    2 
+  trunk/audacious/ui_playlist.c      |   12 +
+  5 files changed, 277 insertions(+)
+
+
 2006-12-22 22:58:16 +0000  William Pitcock <nenolod@nenolod.net>
   revision [3405]
   - fix equalizer motion response in doublesize
--- a/audacious/playlist.c	Fri Dec 22 16:29:35 2006 -0800
+++ b/audacious/playlist.c	Fri Dec 22 17:35:11 2006 -0800
@@ -58,6 +58,7 @@
 #include "playback.h"
 #include "playlist.h"
 #include "playlist_container.h"
+#include "playlist_manager.h"
 #include "ui_playlist.h"
 #include "util.h"
 #include "ui_fileinfo.h"
@@ -242,6 +243,8 @@
 
     if (playlists_iter == NULL)
         playlists_iter = playlists;
+
+    playlist_manager_update();
 }
 
 void
@@ -254,6 +257,8 @@
 
     if (playlists_iter == NULL)
         playlists_iter = playlists;
+
+    playlist_manager_update();
 }
 
 GList *
@@ -375,6 +380,7 @@
     playlist_generate_shuffle_list(playlist);
     playlistwin_update_list(playlist);
     playlist_recalc_total_time(playlist);
+    playlist_manager_update();
 }
 
 static void
@@ -470,6 +476,8 @@
     else if (set_info_text) {
         mainwin_set_info_text();
     }
+
+    playlist_manager_update();
 }
 
 void
@@ -511,6 +519,7 @@
         mainwin_set_info_text();
     }
 
+    playlist_manager_update();
 }
 
 void
@@ -556,6 +565,7 @@
     }
 
     playlistwin_update_list(playlist);
+    playlist_manager_update();
 }
 
 static void
@@ -623,6 +633,7 @@
 {
     __playlist_ins_with_info(playlist, filename, pos, NULL, -1, dec);
     playlist_recalc_total_time(playlist);
+    playlist_manager_update();
 }
 
 gboolean
@@ -857,6 +868,7 @@
     playlist_recalc_total_time(playlist);
     playlist_generate_shuffle_list(playlist);
     playlistwin_update_list(playlist);
+    playlist_manager_update();
     return entries;
 }
 
@@ -925,6 +937,8 @@
     playlist_generate_shuffle_list(playlist);
     playlistwin_update_list(playlist);
 
+    playlist_manager_update();
+
     return entries;
 }
 
@@ -2172,6 +2186,7 @@
     }
     PLAYLIST_UNLOCK(playlist->mutex);
     playlist_recalc_total_time(playlist);
+    playlist_manager_update();
 }
 
 gint
@@ -2527,6 +2542,7 @@
     playlist_generate_shuffle_list(playlist);
     playlistwin_update_list(playlist);
     playlist_recalc_total_time(playlist);
+    playlist_manager_update();
 }
 
 
@@ -2660,6 +2676,8 @@
 
     playlistwin_update_list(playlist);
     playlist_recalc_total_time(playlist);
+
+    playlist_manager_update();
 }
 
 void
@@ -3072,6 +3090,8 @@
 
     playlist_recalc_total_time(newpl);
     playlistwin_update_list(playlist);
+
+    return newpl;
 }
 
 const gchar *
--- a/audacious/playlist_manager.c	Fri Dec 22 16:29:35 2006 -0800
+++ b/audacious/playlist_manager.c	Fri Dec 22 17:35:11 2006 -0800
@@ -25,9 +25,11 @@
 #include <gtk/gtk.h>
 
 
-/* TODO: we're accessing playlist_ stuff directly here, and storing a pointer to
-     each Playlist. Data consistency should be always checked, cause playlists could
-     be deleted by user without using the playlist manager, while the latter is active */
+#define DISABLE_MANAGER_UPDATE() g_object_set_data(G_OBJECT(listview),"opt1",GINT_TO_POINTER(1))
+#define ENABLE_MANAGER_UPDATE() g_object_set_data(G_OBJECT(listview),"opt1",GINT_TO_POINTER(0))
+
+
+static GtkWidget *playman_win = NULL;
 
 
 enum
@@ -80,10 +82,14 @@
   GtkListStore *store;
   gchar *pl_name = NULL;
 
+  /* this ensures that playlist_manager_update() will
+     not perform update, since we're already doing it here */
+  DISABLE_MANAGER_UPDATE();
+
   newpl = playlist_new();
+  pl_name = (gchar*)playlist_get_current_name( newpl );
   playlists = playlist_get_playlists();
   playlist_add_playlist( newpl );
-  pl_name = (gchar*)playlist_get_current_name( newpl );
 
   store = (GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(listview) );
   gtk_list_store_append( store , &iter );
@@ -91,6 +97,9 @@
                       PLLIST_COL_NAME , pl_name ,
                       PLLIST_COL_ENTRIESNUM , 0 ,
                       PLLIST_COL_PLPOINTER , newpl , -1 );
+
+  ENABLE_MANAGER_UPDATE();
+
   return;
 }
 
@@ -116,8 +125,11 @@
     if ( playlist == playlist_get_active() )
       playlist_select_next();
 
-    /* TODO: check that playlist has not been freed already!! */
+    /* this ensures that playlist_manager_update() will
+       not perform update, since we're already doing it here */
+    DISABLE_MANAGER_UPDATE();
     playlist_remove_playlist( playlist );
+    ENABLE_MANAGER_UPDATE();
   }
 
   return;
@@ -136,7 +148,6 @@
   {
     Playlist *playlist = NULL;
     gtk_tree_model_get( store , &iter , PLLIST_COL_PLPOINTER , &playlist , -1 );
-    /* TODO: check that playlist has not been freed already!! */
     playlist_select_playlist( playlist );
   }
 
@@ -147,7 +158,6 @@
 void
 playlist_manager_ui_show ( void )
 {
-  static GtkWidget *playman_win = NULL;
   GtkWidget *playman_vbox;
   GtkWidget *playman_pl_lv, *playman_pl_lv_frame, *playman_pl_lv_sw;
   GtkCellRenderer *playman_pl_lv_textrndr;
@@ -191,6 +201,8 @@
   playman_pl_lv_frame = gtk_frame_new( NULL );
   playman_pl_lv = gtk_tree_view_new_with_model( GTK_TREE_MODEL(pl_store) );
   g_object_unref( pl_store );
+  g_object_set_data( G_OBJECT(playman_win) , "lv" , playman_pl_lv );
+  g_object_set_data( G_OBJECT(playman_pl_lv) , "opt1" , GINT_TO_POINTER(0) );
   playman_pl_lv_textrndr = gtk_cell_renderer_text_new();
   playman_pl_lv_col_name = gtk_tree_view_column_new_with_attributes(
     _("Playlist") , playman_pl_lv_textrndr , "text" , PLLIST_COL_NAME , NULL );
@@ -233,3 +245,29 @@
 
   gtk_widget_show_all( playman_win );
 }
+
+
+void
+playlist_manager_update ( void )
+{
+  /* this function is called whenever there is a change in playlist, such as
+     playlist created/deleted or entry added/deleted in a playlist; if the playlist
+     manager is active, it should be updated to keep consistency of information */
+
+  /* CAREFUL! this currently locks/unlocks all the playlists */
+
+  if ( playman_win != NULL )
+  {
+    GtkWidget *lv = (GtkWidget*)g_object_get_data( G_OBJECT(playman_win) , "lv" );
+    if ( GPOINTER_TO_INT(g_object_get_data(G_OBJECT(lv),"opt1")) == 0 )
+    {
+      GtkListStore *store = (GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(lv) );
+      /* TODO: this re-populates everything... there's definitely room for optimization */
+      gtk_list_store_clear( store );
+      playlist_manager_populate( store );
+    }
+    return;
+  }
+  else
+    return; /* if the playlist manager is not active, simply return */
+}
--- a/audacious/playlist_manager.h	Fri Dec 22 16:29:35 2006 -0800
+++ b/audacious/playlist_manager.h	Fri Dec 22 17:35:11 2006 -0800
@@ -21,6 +21,7 @@
 #ifndef PLAYLISTMANAGER_H
 #define PLAYLISTMANAGER_H
 
+void playlist_manager_update ( void );
 void playlist_manager_ui_show ( void );
 
 #endif