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