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