Mercurial > audlegacy
annotate src/audacious/ui_playlist_manager.c @ 3335:63d7947d7376 trunk
simplified the tuple formatter a bit
author | Giacomo Lozito <james@develia.org> |
---|---|
date | Sat, 11 Aug 2007 20:32:13 +0200 |
parents | f1c756f39e6c |
children | 0dd74d0da472 440877c9360e |
rev | line source |
---|---|
2894
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
1 /* Audacious - Cross-platform multimedia player |
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
2 * Copyright (C) 2005-2007 Audacious development team. |
2313 | 3 * |
2894
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2894
diff
changeset
|
6 * the Free Software Foundation; under version 3 of the License. |
2313 | 7 * |
2894
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
11 * GNU General Public License for more details. |
2313 | 12 * |
2894
062324422c40
Backed out changeset 7dad846ec69940e4e905c357ae8dff81240b579b
William Pitcock <nenolod@atheme.org>
parents:
2862
diff
changeset
|
13 * You should have received a copy of the GNU General Public License |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2894
diff
changeset
|
14 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
15 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
16 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
17 * Audacious or using our public API to be a derived work. |
2313 | 18 */ |
19 | |
2499
15a1f5ee4d1c
[svn] - playlist_manager -> ui_playlist_manager, since it's a UI component.
nenolod
parents:
2313
diff
changeset
|
20 #include "ui_playlist_manager.h" |
2313 | 21 #include "ui_playlist.h" |
22 #include "playlist.h" | |
23 #include "ui_main.h" | |
24 | |
25 #include <glib.h> | |
26 #include <glib/gi18n.h> | |
27 #include <gtk/gtk.h> | |
28 #include <gdk/gdkkeysyms.h> | |
29 | |
30 | |
31 #define DISABLE_MANAGER_UPDATE() g_object_set_data(G_OBJECT(listview),"opt1",GINT_TO_POINTER(1)) | |
32 #define ENABLE_MANAGER_UPDATE() g_object_set_data(G_OBJECT(listview),"opt1",GINT_TO_POINTER(0)) | |
33 | |
34 | |
35 static GtkWidget *playman_win = NULL; | |
36 | |
37 | |
38 /* in this enum, place the columns according to visualization order | |
39 (information not displayed in columns should be placed right before PLLIST_NUMCOLS) */ | |
40 enum | |
41 { | |
2808 | 42 PLLIST_COL_NAME = 0, |
43 PLLIST_COL_ENTRIESNUM, | |
44 PLLIST_COL_PLPOINTER, | |
45 PLLIST_NUMCOLS | |
2313 | 46 }; |
47 | |
48 | |
49 static void | |
50 playlist_manager_populate ( GtkListStore * store ) | |
51 { | |
2808 | 52 GList *playlists = NULL; |
53 GtkTreeIter iter; | |
2313 | 54 |
2808 | 55 playlists = playlist_get_playlists(); |
56 while ( playlists != NULL ) | |
57 { | |
58 GList *entries = NULL; | |
59 gint entriesnum = 0; | |
60 gchar *pl_name = NULL; | |
61 Playlist *playlist = (Playlist*)playlists->data; | |
2313 | 62 |
2808 | 63 PLAYLIST_LOCK(playlist->mutex); |
64 /* for each playlist, pick name and number of entries */ | |
65 pl_name = (gchar*)playlist_get_current_name( playlist ); | |
66 for (entries = playlist->entries; entries; entries = g_list_next(entries)) | |
67 entriesnum++; | |
68 PLAYLIST_UNLOCK(playlist->mutex); | |
2313 | 69 |
2808 | 70 gtk_list_store_append( store , &iter ); |
71 gtk_list_store_set( store, &iter, | |
72 PLLIST_COL_NAME , pl_name , | |
73 PLLIST_COL_ENTRIESNUM , entriesnum , | |
74 PLLIST_COL_PLPOINTER , playlist , -1 ); | |
75 playlists = g_list_next(playlists); | |
76 } | |
77 return; | |
2313 | 78 } |
79 | |
80 | |
81 static void | |
82 playlist_manager_cb_new ( gpointer listview ) | |
83 { | |
2808 | 84 GList *playlists = NULL; |
85 Playlist *newpl = NULL; | |
86 GtkTreeIter iter; | |
87 GtkListStore *store; | |
88 gchar *pl_name = NULL; | |
2313 | 89 |
2808 | 90 /* this ensures that playlist_manager_update() will |
91 not perform update, since we're already doing it here */ | |
92 DISABLE_MANAGER_UPDATE(); | |
2313 | 93 |
2808 | 94 newpl = playlist_new(); |
95 pl_name = (gchar*)playlist_get_current_name( newpl ); | |
96 playlists = playlist_get_playlists(); | |
97 playlist_add_playlist( newpl ); | |
2313 | 98 |
2808 | 99 store = (GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(listview) ); |
100 gtk_list_store_append( store , &iter ); | |
101 gtk_list_store_set( store, &iter, | |
102 PLLIST_COL_NAME , pl_name , | |
103 PLLIST_COL_ENTRIESNUM , 0 , | |
104 PLLIST_COL_PLPOINTER , newpl , -1 ); | |
2313 | 105 |
2808 | 106 ENABLE_MANAGER_UPDATE(); |
2313 | 107 |
2808 | 108 return; |
2313 | 109 } |
110 | |
111 | |
112 static void | |
113 playlist_manager_cb_del ( gpointer listview ) | |
114 { | |
2808 | 115 GtkTreeSelection *listsel = gtk_tree_view_get_selection( GTK_TREE_VIEW(listview) ); |
116 GtkTreeModel *store; | |
117 GtkTreeIter iter; | |
2313 | 118 |
2808 | 119 if ( gtk_tree_selection_get_selected( listsel , &store , &iter ) == TRUE ) |
2313 | 120 { |
2808 | 121 Playlist *playlist = NULL; |
122 gtk_tree_model_get( store, &iter, PLLIST_COL_PLPOINTER , &playlist , -1 ); | |
123 | |
124 if ( gtk_tree_model_iter_n_children( store , NULL ) < 2 ) | |
125 { | |
126 /* let playlist_manager_update() handle the deletion of the last playlist */ | |
127 playlist_remove_playlist( playlist ); | |
128 } | |
129 else | |
130 { | |
131 gtk_list_store_remove( (GtkListStore*)store , &iter ); | |
132 /* this ensures that playlist_manager_update() will | |
133 not perform update, since we're already doing it here */ | |
134 DISABLE_MANAGER_UPDATE(); | |
135 playlist_remove_playlist( playlist ); | |
136 ENABLE_MANAGER_UPDATE(); | |
137 } | |
2313 | 138 } |
139 | |
2808 | 140 return; |
2313 | 141 } |
142 | |
143 | |
144 static void | |
145 playlist_manager_cb_lv_dclick ( GtkTreeView * lv , GtkTreePath * path , | |
146 GtkTreeViewColumn * col , gpointer userdata ) | |
147 { | |
2808 | 148 GtkTreeModel *store; |
149 GtkTreeIter iter; | |
2313 | 150 |
2808 | 151 store = gtk_tree_view_get_model( GTK_TREE_VIEW(lv) ); |
152 if ( gtk_tree_model_get_iter( store , &iter , path ) == TRUE ) | |
153 { | |
154 Playlist *playlist = NULL; | |
155 gtk_tree_model_get( store , &iter , PLLIST_COL_PLPOINTER , &playlist , -1 ); | |
156 playlist_select_playlist( playlist ); | |
157 } | |
2313 | 158 |
2808 | 159 return; |
2313 | 160 } |
161 | |
162 | |
163 static void | |
164 playlist_manager_cb_lv_pmenu_rename ( GtkMenuItem *menuitem , gpointer lv ) | |
165 { | |
2808 | 166 GtkTreeSelection *listsel = gtk_tree_view_get_selection( GTK_TREE_VIEW(lv) ); |
167 GtkTreeModel *store; | |
168 GtkTreeIter iter; | |
2313 | 169 |
2808 | 170 if ( gtk_tree_selection_get_selected( listsel , &store , &iter ) == TRUE ) |
171 { | |
172 GtkTreePath *path = gtk_tree_model_get_path( GTK_TREE_MODEL(store) , &iter ); | |
173 GtkCellRenderer *rndrname = g_object_get_data( G_OBJECT(lv) , "rn" ); | |
174 /* set the name renderer to editable and start editing */ | |
175 g_object_set( G_OBJECT(rndrname) , "editable" , TRUE , NULL ); | |
176 gtk_tree_view_set_cursor_on_cell( GTK_TREE_VIEW(lv) , path , | |
177 gtk_tree_view_get_column( GTK_TREE_VIEW(lv) , PLLIST_COL_NAME ) , rndrname , TRUE ); | |
178 gtk_tree_path_free( path ); | |
179 } | |
2313 | 180 } |
181 | |
182 static void | |
183 playlist_manager_cb_lv_name_edited ( GtkCellRendererText *cell , gchar *path_string , | |
184 gchar *new_text , gpointer lv ) | |
185 { | |
2808 | 186 /* this is currently used to change playlist names */ |
187 GtkTreeModel *store = gtk_tree_view_get_model( GTK_TREE_VIEW(lv) ); | |
188 GtkTreeIter iter; | |
2313 | 189 |
2808 | 190 if ( gtk_tree_model_get_iter_from_string( store , &iter , path_string ) == TRUE ) |
191 { | |
192 Playlist *playlist = NULL; | |
193 gtk_tree_model_get( GTK_TREE_MODEL(store), &iter, PLLIST_COL_PLPOINTER , &playlist , -1 ); | |
194 playlist_set_current_name( playlist , new_text ); | |
195 gtk_list_store_set( GTK_LIST_STORE(store), &iter, PLLIST_COL_NAME , new_text , -1 ); | |
196 } | |
197 /* set the renderer uneditable again */ | |
198 g_object_set( G_OBJECT(cell) , "editable" , FALSE , NULL ); | |
2313 | 199 } |
200 | |
201 | |
202 static gboolean | |
203 playlist_manager_cb_lv_btpress ( GtkWidget *lv , GdkEventButton *event ) | |
204 { | |
2808 | 205 if (( event->type == GDK_BUTTON_PRESS ) && ( event->button == 3 )) |
206 { | |
207 GtkWidget *pmenu = (GtkWidget*)g_object_get_data( G_OBJECT(lv) , "menu" ); | |
208 gtk_menu_popup( GTK_MENU(pmenu) , NULL , NULL , NULL , NULL , | |
209 (event != NULL) ? event->button : 0, | |
210 gdk_event_get_time((GdkEvent*)event)); | |
211 return TRUE; | |
212 } | |
2313 | 213 |
2808 | 214 return FALSE; |
2313 | 215 } |
216 | |
217 | |
218 static gboolean | |
219 playlist_manager_cb_keypress ( GtkWidget *win , GdkEventKey *event ) | |
220 { | |
221 switch (event->keyval) | |
222 { | |
223 case GDK_Escape: | |
224 gtk_widget_destroy( playman_win ); | |
225 return TRUE; | |
226 default: | |
227 return FALSE; | |
228 } | |
229 } | |
230 | |
231 | |
232 void | |
233 playlist_manager_ui_show ( void ) | |
234 { | |
2808 | 235 GtkWidget *playman_vbox; |
236 GtkWidget *playman_pl_lv, *playman_pl_lv_frame, *playman_pl_lv_sw; | |
237 GtkCellRenderer *playman_pl_lv_textrndr_name, *playman_pl_lv_textrndr_entriesnum; | |
238 GtkTreeViewColumn *playman_pl_lv_col_name, *playman_pl_lv_col_entriesnum; | |
239 GtkListStore *pl_store; | |
240 GtkWidget *playman_pl_lv_pmenu, *playman_pl_lv_pmenu_rename; | |
241 GtkWidget *playman_bbar_hbbox; | |
242 GtkWidget *playman_bbar_bt_new, *playman_bbar_bt_del, *playman_bbar_bt_close; | |
243 GdkGeometry playman_win_hints; | |
2313 | 244 |
2808 | 245 if ( playman_win != NULL ) |
246 { | |
247 gtk_window_present( GTK_WINDOW(playman_win) ); | |
248 return; | |
249 } | |
2313 | 250 |
2808 | 251 playman_win = gtk_window_new( GTK_WINDOW_TOPLEVEL ); |
252 gtk_window_set_type_hint( GTK_WINDOW(playman_win), GDK_WINDOW_TYPE_HINT_DIALOG ); | |
253 gtk_window_set_transient_for( GTK_WINDOW(playman_win) , GTK_WINDOW(mainwin) ); | |
254 gtk_window_set_position( GTK_WINDOW(playman_win), GTK_WIN_POS_CENTER ); | |
255 gtk_window_set_title( GTK_WINDOW(playman_win), _("Playlist Manager") ); | |
256 gtk_container_set_border_width( GTK_CONTAINER(playman_win), 10 ); | |
257 g_signal_connect( G_OBJECT(playman_win) , "destroy" , | |
258 G_CALLBACK(gtk_widget_destroyed) , &playman_win ); | |
259 g_signal_connect( G_OBJECT(playman_win) , "key-press-event" , | |
260 G_CALLBACK(playlist_manager_cb_keypress) , NULL ); | |
261 playman_win_hints.min_width = 400; | |
262 playman_win_hints.min_height = 250; | |
263 gtk_window_set_geometry_hints( GTK_WINDOW(playman_win) , GTK_WIDGET(playman_win) , | |
264 &playman_win_hints , GDK_HINT_MIN_SIZE ); | |
2313 | 265 |
2809 | 266 playman_vbox = gtk_vbox_new( FALSE , 10 ); |
2808 | 267 gtk_container_add( GTK_CONTAINER(playman_win) , playman_vbox ); |
2313 | 268 |
2808 | 269 /* current liststore model |
270 ---------------------------------------------- | |
271 G_TYPE_STRING -> playlist name | |
272 G_TYPE_UINT -> number of entries in playlist | |
273 G_TYPE_POINTER -> playlist pointer (Playlist*) | |
274 ---------------------------------------------- | |
275 */ | |
276 pl_store = gtk_list_store_new( PLLIST_NUMCOLS , G_TYPE_STRING , G_TYPE_UINT , G_TYPE_POINTER ); | |
277 playlist_manager_populate( pl_store ); | |
2313 | 278 |
2808 | 279 playman_pl_lv_frame = gtk_frame_new( NULL ); |
280 playman_pl_lv = gtk_tree_view_new_with_model( GTK_TREE_MODEL(pl_store) ); | |
281 g_object_unref( pl_store ); | |
282 g_object_set_data( G_OBJECT(playman_win) , "lv" , playman_pl_lv ); | |
283 g_object_set_data( G_OBJECT(playman_pl_lv) , "opt1" , GINT_TO_POINTER(0) ); | |
284 playman_pl_lv_textrndr_entriesnum = gtk_cell_renderer_text_new(); /* uneditable */ | |
285 playman_pl_lv_textrndr_name = gtk_cell_renderer_text_new(); /* can become editable */ | |
286 g_signal_connect( G_OBJECT(playman_pl_lv_textrndr_name) , "edited" , | |
287 G_CALLBACK(playlist_manager_cb_lv_name_edited) , playman_pl_lv ); | |
288 g_object_set_data( G_OBJECT(playman_pl_lv) , "rn" , playman_pl_lv_textrndr_name ); | |
289 playman_pl_lv_col_name = gtk_tree_view_column_new_with_attributes( | |
290 _("Playlist") , playman_pl_lv_textrndr_name , "text" , PLLIST_COL_NAME , NULL ); | |
291 gtk_tree_view_column_set_expand( GTK_TREE_VIEW_COLUMN(playman_pl_lv_col_name) , TRUE ); | |
292 gtk_tree_view_append_column( GTK_TREE_VIEW(playman_pl_lv), playman_pl_lv_col_name ); | |
293 playman_pl_lv_col_entriesnum = gtk_tree_view_column_new_with_attributes( | |
294 _("Entries") , playman_pl_lv_textrndr_entriesnum , "text" , PLLIST_COL_ENTRIESNUM , NULL ); | |
295 gtk_tree_view_column_set_expand( GTK_TREE_VIEW_COLUMN(playman_pl_lv_col_entriesnum) , FALSE ); | |
296 gtk_tree_view_append_column( GTK_TREE_VIEW(playman_pl_lv), playman_pl_lv_col_entriesnum ); | |
297 playman_pl_lv_sw = gtk_scrolled_window_new( NULL , NULL ); | |
298 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(playman_pl_lv_sw) , | |
299 GTK_POLICY_NEVER , GTK_POLICY_ALWAYS ); | |
300 gtk_container_add( GTK_CONTAINER(playman_pl_lv_sw) , playman_pl_lv ); | |
301 gtk_container_add( GTK_CONTAINER(playman_pl_lv_frame) , playman_pl_lv_sw ); | |
302 gtk_box_pack_start( GTK_BOX(playman_vbox) , playman_pl_lv_frame , TRUE , TRUE , 0 ); | |
2313 | 303 |
2808 | 304 /* listview popup menu */ |
305 playman_pl_lv_pmenu = gtk_menu_new(); | |
306 playman_pl_lv_pmenu_rename = gtk_menu_item_new_with_mnemonic( _( "_Rename" ) ); | |
307 g_signal_connect( G_OBJECT(playman_pl_lv_pmenu_rename) , "activate" , | |
308 G_CALLBACK(playlist_manager_cb_lv_pmenu_rename) , playman_pl_lv ); | |
309 gtk_menu_shell_append( GTK_MENU_SHELL(playman_pl_lv_pmenu) , playman_pl_lv_pmenu_rename ); | |
310 gtk_widget_show_all( playman_pl_lv_pmenu ); | |
311 g_object_set_data( G_OBJECT(playman_pl_lv) , "menu" , playman_pl_lv_pmenu ); | |
312 g_signal_connect_swapped( G_OBJECT(playman_win) , "destroy" , | |
313 G_CALLBACK(gtk_widget_destroy) , playman_pl_lv_pmenu ); | |
2313 | 314 |
2808 | 315 /* button bar */ |
316 playman_bbar_hbbox = gtk_hbutton_box_new(); | |
317 gtk_button_box_set_layout( GTK_BUTTON_BOX(playman_bbar_hbbox) , GTK_BUTTONBOX_END ); | |
2809 | 318 gtk_button_box_set_spacing(GTK_BUTTON_BOX(playman_bbar_hbbox), 5); |
2808 | 319 playman_bbar_bt_close = gtk_button_new_from_stock( GTK_STOCK_CLOSE ); |
320 playman_bbar_bt_del = gtk_button_new_from_stock( GTK_STOCK_DELETE ); | |
321 playman_bbar_bt_new = gtk_button_new_from_stock( GTK_STOCK_NEW ); | |
322 gtk_container_add( GTK_CONTAINER(playman_bbar_hbbox) , playman_bbar_bt_close ); | |
323 gtk_container_add( GTK_CONTAINER(playman_bbar_hbbox) , playman_bbar_bt_del ); | |
324 gtk_container_add( GTK_CONTAINER(playman_bbar_hbbox) , playman_bbar_bt_new ); | |
325 gtk_button_box_set_child_secondary( GTK_BUTTON_BOX(playman_bbar_hbbox) , | |
326 playman_bbar_bt_close , TRUE ); | |
327 gtk_box_pack_start( GTK_BOX(playman_vbox) , playman_bbar_hbbox , FALSE , FALSE , 0 ); | |
2313 | 328 |
2808 | 329 g_signal_connect( G_OBJECT(playman_pl_lv) , "button-press-event" , |
330 G_CALLBACK(playlist_manager_cb_lv_btpress) , NULL ); | |
331 g_signal_connect( G_OBJECT(playman_pl_lv) , "row-activated" , | |
332 G_CALLBACK(playlist_manager_cb_lv_dclick) , NULL ); | |
333 g_signal_connect_swapped( G_OBJECT(playman_bbar_bt_new) , "clicked" , | |
334 G_CALLBACK(playlist_manager_cb_new) , playman_pl_lv ); | |
335 g_signal_connect_swapped( G_OBJECT(playman_bbar_bt_del) , "clicked" , | |
336 G_CALLBACK(playlist_manager_cb_del) , playman_pl_lv ); | |
337 g_signal_connect_swapped( G_OBJECT(playman_bbar_bt_close) , "clicked" , | |
338 G_CALLBACK(gtk_widget_destroy) , playman_win ); | |
2313 | 339 |
2808 | 340 gtk_widget_show_all( playman_win ); |
2313 | 341 } |
342 | |
343 | |
344 void | |
345 playlist_manager_update ( void ) | |
346 { | |
2808 | 347 /* this function is called whenever there is a change in playlist, such as |
348 playlist created/deleted or entry added/deleted in a playlist; if the playlist | |
349 manager is active, it should be updated to keep consistency of information */ | |
2313 | 350 |
2808 | 351 /* CAREFUL! this currently locks/unlocks all the playlists */ |
2313 | 352 |
2808 | 353 if ( playman_win != NULL ) |
2313 | 354 { |
2808 | 355 GtkWidget *lv = (GtkWidget*)g_object_get_data( G_OBJECT(playman_win) , "lv" ); |
356 if ( GPOINTER_TO_INT(g_object_get_data(G_OBJECT(lv),"opt1")) == 0 ) | |
357 { | |
358 GtkListStore *store = (GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(lv) ); | |
359 /* TODO: this re-populates everything... there's definitely room for optimization */ | |
360 gtk_list_store_clear( store ); | |
361 playlist_manager_populate( store ); | |
362 } | |
363 return; | |
2313 | 364 } |
2808 | 365 else |
366 return; /* if the playlist manager is not active, simply return */ | |
2313 | 367 } |