Mercurial > audlegacy
comparison audacious/playlist_manager.c @ 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 | 76b040158f94 |
comparison
equal
deleted
inserted
replaced
2201:39e9c8e2745d | 2202:d1804718c5cc |
---|---|
23 #include <glib.h> | 23 #include <glib.h> |
24 #include <glib/gi18n.h> | 24 #include <glib/gi18n.h> |
25 #include <gtk/gtk.h> | 25 #include <gtk/gtk.h> |
26 | 26 |
27 | 27 |
28 /* TODO: we're accessing playlist_ stuff directly here, and storing a pointer to | 28 #define DISABLE_MANAGER_UPDATE() g_object_set_data(G_OBJECT(listview),"opt1",GINT_TO_POINTER(1)) |
29 each Playlist. Data consistency should be always checked, cause playlists could | 29 #define ENABLE_MANAGER_UPDATE() g_object_set_data(G_OBJECT(listview),"opt1",GINT_TO_POINTER(0)) |
30 be deleted by user without using the playlist manager, while the latter is active */ | 30 |
31 | |
32 static GtkWidget *playman_win = NULL; | |
31 | 33 |
32 | 34 |
33 enum | 35 enum |
34 { | 36 { |
35 PLLIST_COL_NAME = 0, | 37 PLLIST_COL_NAME = 0, |
78 Playlist *newpl = NULL; | 80 Playlist *newpl = NULL; |
79 GtkTreeIter iter; | 81 GtkTreeIter iter; |
80 GtkListStore *store; | 82 GtkListStore *store; |
81 gchar *pl_name = NULL; | 83 gchar *pl_name = NULL; |
82 | 84 |
85 /* this ensures that playlist_manager_update() will | |
86 not perform update, since we're already doing it here */ | |
87 DISABLE_MANAGER_UPDATE(); | |
88 | |
83 newpl = playlist_new(); | 89 newpl = playlist_new(); |
90 pl_name = (gchar*)playlist_get_current_name( newpl ); | |
84 playlists = playlist_get_playlists(); | 91 playlists = playlist_get_playlists(); |
85 playlist_add_playlist( newpl ); | 92 playlist_add_playlist( newpl ); |
86 pl_name = (gchar*)playlist_get_current_name( newpl ); | |
87 | 93 |
88 store = (GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(listview) ); | 94 store = (GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(listview) ); |
89 gtk_list_store_append( store , &iter ); | 95 gtk_list_store_append( store , &iter ); |
90 gtk_list_store_set( store, &iter, | 96 gtk_list_store_set( store, &iter, |
91 PLLIST_COL_NAME , pl_name , | 97 PLLIST_COL_NAME , pl_name , |
92 PLLIST_COL_ENTRIESNUM , 0 , | 98 PLLIST_COL_ENTRIESNUM , 0 , |
93 PLLIST_COL_PLPOINTER , newpl , -1 ); | 99 PLLIST_COL_PLPOINTER , newpl , -1 ); |
100 | |
101 ENABLE_MANAGER_UPDATE(); | |
102 | |
94 return; | 103 return; |
95 } | 104 } |
96 | 105 |
97 | 106 |
98 static void | 107 static void |
114 | 123 |
115 /* if the playlist removed is the active one, switch to the next */ | 124 /* if the playlist removed is the active one, switch to the next */ |
116 if ( playlist == playlist_get_active() ) | 125 if ( playlist == playlist_get_active() ) |
117 playlist_select_next(); | 126 playlist_select_next(); |
118 | 127 |
119 /* TODO: check that playlist has not been freed already!! */ | 128 /* this ensures that playlist_manager_update() will |
129 not perform update, since we're already doing it here */ | |
130 DISABLE_MANAGER_UPDATE(); | |
120 playlist_remove_playlist( playlist ); | 131 playlist_remove_playlist( playlist ); |
132 ENABLE_MANAGER_UPDATE(); | |
121 } | 133 } |
122 | 134 |
123 return; | 135 return; |
124 } | 136 } |
125 | 137 |
134 store = gtk_tree_view_get_model( GTK_TREE_VIEW(lv) ); | 146 store = gtk_tree_view_get_model( GTK_TREE_VIEW(lv) ); |
135 if ( gtk_tree_model_get_iter( store , &iter , path ) == TRUE ) | 147 if ( gtk_tree_model_get_iter( store , &iter , path ) == TRUE ) |
136 { | 148 { |
137 Playlist *playlist = NULL; | 149 Playlist *playlist = NULL; |
138 gtk_tree_model_get( store , &iter , PLLIST_COL_PLPOINTER , &playlist , -1 ); | 150 gtk_tree_model_get( store , &iter , PLLIST_COL_PLPOINTER , &playlist , -1 ); |
139 /* TODO: check that playlist has not been freed already!! */ | |
140 playlist_select_playlist( playlist ); | 151 playlist_select_playlist( playlist ); |
141 } | 152 } |
142 | 153 |
143 return; | 154 return; |
144 } | 155 } |
145 | 156 |
146 | 157 |
147 void | 158 void |
148 playlist_manager_ui_show ( void ) | 159 playlist_manager_ui_show ( void ) |
149 { | 160 { |
150 static GtkWidget *playman_win = NULL; | |
151 GtkWidget *playman_vbox; | 161 GtkWidget *playman_vbox; |
152 GtkWidget *playman_pl_lv, *playman_pl_lv_frame, *playman_pl_lv_sw; | 162 GtkWidget *playman_pl_lv, *playman_pl_lv_frame, *playman_pl_lv_sw; |
153 GtkCellRenderer *playman_pl_lv_textrndr; | 163 GtkCellRenderer *playman_pl_lv_textrndr; |
154 GtkTreeViewColumn *playman_pl_lv_col_name, *playman_pl_lv_col_entriesnum; | 164 GtkTreeViewColumn *playman_pl_lv_col_name, *playman_pl_lv_col_entriesnum; |
155 GtkListStore *pl_store; | 165 GtkListStore *pl_store; |
189 playlist_manager_populate( pl_store ); | 199 playlist_manager_populate( pl_store ); |
190 | 200 |
191 playman_pl_lv_frame = gtk_frame_new( NULL ); | 201 playman_pl_lv_frame = gtk_frame_new( NULL ); |
192 playman_pl_lv = gtk_tree_view_new_with_model( GTK_TREE_MODEL(pl_store) ); | 202 playman_pl_lv = gtk_tree_view_new_with_model( GTK_TREE_MODEL(pl_store) ); |
193 g_object_unref( pl_store ); | 203 g_object_unref( pl_store ); |
204 g_object_set_data( G_OBJECT(playman_win) , "lv" , playman_pl_lv ); | |
205 g_object_set_data( G_OBJECT(playman_pl_lv) , "opt1" , GINT_TO_POINTER(0) ); | |
194 playman_pl_lv_textrndr = gtk_cell_renderer_text_new(); | 206 playman_pl_lv_textrndr = gtk_cell_renderer_text_new(); |
195 playman_pl_lv_col_name = gtk_tree_view_column_new_with_attributes( | 207 playman_pl_lv_col_name = gtk_tree_view_column_new_with_attributes( |
196 _("Playlist") , playman_pl_lv_textrndr , "text" , PLLIST_COL_NAME , NULL ); | 208 _("Playlist") , playman_pl_lv_textrndr , "text" , PLLIST_COL_NAME , NULL ); |
197 gtk_tree_view_column_set_expand( GTK_TREE_VIEW_COLUMN(playman_pl_lv_col_name) , TRUE ); | 209 gtk_tree_view_column_set_expand( GTK_TREE_VIEW_COLUMN(playman_pl_lv_col_name) , TRUE ); |
198 gtk_tree_view_append_column( GTK_TREE_VIEW(playman_pl_lv), playman_pl_lv_col_name ); | 210 gtk_tree_view_append_column( GTK_TREE_VIEW(playman_pl_lv), playman_pl_lv_col_name ); |
231 g_signal_connect_swapped( G_OBJECT(playman_bbar_bt_close) , "clicked" , | 243 g_signal_connect_swapped( G_OBJECT(playman_bbar_bt_close) , "clicked" , |
232 G_CALLBACK(gtk_widget_destroy) , playman_win ); | 244 G_CALLBACK(gtk_widget_destroy) , playman_win ); |
233 | 245 |
234 gtk_widget_show_all( playman_win ); | 246 gtk_widget_show_all( playman_win ); |
235 } | 247 } |
248 | |
249 | |
250 void | |
251 playlist_manager_update ( void ) | |
252 { | |
253 /* this function is called whenever there is a change in playlist, such as | |
254 playlist created/deleted or entry added/deleted in a playlist; if the playlist | |
255 manager is active, it should be updated to keep consistency of information */ | |
256 | |
257 /* CAREFUL! this currently locks/unlocks all the playlists */ | |
258 | |
259 if ( playman_win != NULL ) | |
260 { | |
261 GtkWidget *lv = (GtkWidget*)g_object_get_data( G_OBJECT(playman_win) , "lv" ); | |
262 if ( GPOINTER_TO_INT(g_object_get_data(G_OBJECT(lv),"opt1")) == 0 ) | |
263 { | |
264 GtkListStore *store = (GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(lv) ); | |
265 /* TODO: this re-populates everything... there's definitely room for optimization */ | |
266 gtk_list_store_clear( store ); | |
267 playlist_manager_populate( store ); | |
268 } | |
269 return; | |
270 } | |
271 else | |
272 return; /* if the playlist manager is not active, simply return */ | |
273 } |