Mercurial > audlegacy
comparison src/audacious/ui_fileinfopopup.c @ 3755:2ca446f02d97
export the fileinfopopup API.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 14 Oct 2007 21:04:46 -0500 |
parents | 602ec8c40d0d |
children | e794ae16017e |
comparison
equal
deleted
inserted
replaced
3754:74bed6b35161 | 3755:2ca446f02d97 |
---|---|
85 gtk_image_set_from_pixbuf(GTK_IMAGE(widget), GDK_PIXBUF(pixbuf)); | 85 gtk_image_set_from_pixbuf(GTK_IMAGE(widget), GDK_PIXBUF(pixbuf)); |
86 g_object_unref(G_OBJECT(pixbuf)); | 86 g_object_unref(G_OBJECT(pixbuf)); |
87 } | 87 } |
88 | 88 |
89 static gboolean | 89 static gboolean |
90 audacious_fileinfopopup_progress_cb(gpointer filepopup_win) | 90 fileinfopopup_progress_cb(gpointer filepopup_win) |
91 { | 91 { |
92 GtkWidget *progressbar = | 92 GtkWidget *progressbar = |
93 g_object_get_data(G_OBJECT(filepopup_win), "progressbar"); | 93 g_object_get_data(G_OBJECT(filepopup_win), "progressbar"); |
94 gchar *tooltip_file = g_object_get_data(G_OBJECT(filepopup_win), "file"); | 94 gchar *tooltip_file = g_object_get_data(G_OBJECT(filepopup_win), "file"); |
95 gchar *current_file_u, *current_file; | 95 gchar *current_file_u, *current_file; |
136 g_free( current_file ); | 136 g_free( current_file ); |
137 return TRUE; | 137 return TRUE; |
138 } | 138 } |
139 | 139 |
140 static gboolean | 140 static gboolean |
141 audacious_fileinfopopup_progress_check_active(GtkWidget *filepopup_win) | 141 fileinfopopup_progress_check_active(GtkWidget *filepopup_win) |
142 { | 142 { |
143 if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(filepopup_win),"progress_sid")) == 0) | 143 if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(filepopup_win),"progress_sid")) == 0) |
144 return FALSE; | 144 return FALSE; |
145 return TRUE; | 145 return TRUE; |
146 } | 146 } |
147 | 147 |
148 static void | 148 static void |
149 audacious_fileinfopopup_progress_init(GtkWidget *filepopup_win) | 149 fileinfopopup_progress_init(GtkWidget *filepopup_win) |
150 { | 150 { |
151 g_object_set_data( G_OBJECT(filepopup_win) , "progress_sid" , GINT_TO_POINTER(0) ); | 151 g_object_set_data( G_OBJECT(filepopup_win) , "progress_sid" , GINT_TO_POINTER(0) ); |
152 } | 152 } |
153 | 153 |
154 static void | 154 static void |
155 audacious_fileinfopopup_progress_start(GtkWidget *filepopup_win) | 155 fileinfopopup_progress_start(GtkWidget *filepopup_win) |
156 { | 156 { |
157 gint sid = | 157 gint sid = |
158 g_timeout_add(500, (GSourceFunc)audacious_fileinfopopup_progress_cb, | 158 g_timeout_add(500, (GSourceFunc)fileinfopopup_progress_cb, |
159 filepopup_win); | 159 filepopup_win); |
160 g_object_set_data(G_OBJECT(filepopup_win), "progress_sid", | 160 g_object_set_data(G_OBJECT(filepopup_win), "progress_sid", |
161 GINT_TO_POINTER(sid)); | 161 GINT_TO_POINTER(sid)); |
162 } | 162 } |
163 | 163 |
164 static void | 164 static void |
165 audacious_fileinfopopup_progress_stop(GtkWidget *filepopup_win) | 165 fileinfopopup_progress_stop(GtkWidget *filepopup_win) |
166 { | 166 { |
167 gint sid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(filepopup_win), | 167 gint sid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(filepopup_win), |
168 "progress_sid")); | 168 "progress_sid")); |
169 if (sid != 0) | 169 if (sid != 0) |
170 { | 170 { |
172 g_object_set_data(G_OBJECT(filepopup_win),"progress_sid",GINT_TO_POINTER(0)); | 172 g_object_set_data(G_OBJECT(filepopup_win),"progress_sid",GINT_TO_POINTER(0)); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 static void | 176 static void |
177 audacious_fileinfopopup_add_category(GtkWidget *filepopup_win, | 177 fileinfopopup_add_category(GtkWidget *filepopup_win, |
178 GtkWidget *filepopup_data_table, | 178 GtkWidget *filepopup_data_table, |
179 const gchar *category, | 179 const gchar *category, |
180 const gchar *header_data, | 180 const gchar *header_data, |
181 const gchar *label_data, | 181 const gchar *label_data, |
182 const gint position) | 182 const gint position) |
209 } | 209 } |
210 | 210 |
211 | 211 |
212 | 212 |
213 GtkWidget * | 213 GtkWidget * |
214 audacious_fileinfopopup_create(void) | 214 fileinfopopup_create(void) |
215 { | 215 { |
216 GtkWidget *filepopup_win; | 216 GtkWidget *filepopup_win; |
217 GtkWidget *filepopup_hbox; | 217 GtkWidget *filepopup_hbox; |
218 GtkWidget *filepopup_data_image; | 218 GtkWidget *filepopup_data_image; |
219 GtkWidget *filepopup_data_table; | 219 GtkWidget *filepopup_data_table; |
246 gtk_table_set_row_spacings(GTK_TABLE(filepopup_data_table), 0); | 246 gtk_table_set_row_spacings(GTK_TABLE(filepopup_data_table), 0); |
247 gtk_table_set_col_spacings(GTK_TABLE(filepopup_data_table), 6); | 247 gtk_table_set_col_spacings(GTK_TABLE(filepopup_data_table), 6); |
248 gtk_box_pack_start(GTK_BOX(filepopup_hbox), filepopup_data_table, | 248 gtk_box_pack_start(GTK_BOX(filepopup_hbox), filepopup_data_table, |
249 TRUE, TRUE, 0); | 249 TRUE, TRUE, 0); |
250 | 250 |
251 audacious_fileinfopopup_add_category(filepopup_win, filepopup_data_table, | 251 fileinfopopup_add_category(filepopup_win, filepopup_data_table, |
252 _("Title"), | 252 _("Title"), |
253 "header_title", "label_title", 0); | 253 "header_title", "label_title", 0); |
254 audacious_fileinfopopup_add_category(filepopup_win, filepopup_data_table, | 254 fileinfopopup_add_category(filepopup_win, filepopup_data_table, |
255 _("Artist"), | 255 _("Artist"), |
256 "header_artist", "label_artist", 1); | 256 "header_artist", "label_artist", 1); |
257 audacious_fileinfopopup_add_category(filepopup_win, filepopup_data_table, | 257 fileinfopopup_add_category(filepopup_win, filepopup_data_table, |
258 _("Album"), | 258 _("Album"), |
259 "header_album", "label_album", 2); | 259 "header_album", "label_album", 2); |
260 audacious_fileinfopopup_add_category(filepopup_win, filepopup_data_table, | 260 fileinfopopup_add_category(filepopup_win, filepopup_data_table, |
261 _("Genre"), | 261 _("Genre"), |
262 "header_genre", "label_genre", 3); | 262 "header_genre", "label_genre", 3); |
263 audacious_fileinfopopup_add_category(filepopup_win, filepopup_data_table, | 263 fileinfopopup_add_category(filepopup_win, filepopup_data_table, |
264 _("Year"), | 264 _("Year"), |
265 "header_year", "label_year", 4); | 265 "header_year", "label_year", 4); |
266 audacious_fileinfopopup_add_category(filepopup_win, filepopup_data_table, | 266 fileinfopopup_add_category(filepopup_win, filepopup_data_table, |
267 _("Track Number"), | 267 _("Track Number"), |
268 "header_tracknum", "label_tracknum", | 268 "header_tracknum", "label_tracknum", |
269 5); | 269 5); |
270 audacious_fileinfopopup_add_category(filepopup_win, filepopup_data_table, | 270 fileinfopopup_add_category(filepopup_win, filepopup_data_table, |
271 _("Track Length"), | 271 _("Track Length"), |
272 "header_tracklen", "label_tracklen", | 272 "header_tracklen", "label_tracklen", |
273 6); | 273 6); |
274 | 274 |
275 gtk_table_set_row_spacing(GTK_TABLE(filepopup_data_table), 6, 6); | 275 gtk_table_set_row_spacing(GTK_TABLE(filepopup_data_table), 6, 6); |
282 gtk_table_attach(GTK_TABLE(filepopup_data_table), filepopup_progress, | 282 gtk_table_attach(GTK_TABLE(filepopup_data_table), filepopup_progress, |
283 0, 2, 7, 8, GTK_FILL, 0, 0, 0); | 283 0, 2, 7, 8, GTK_FILL, 0, 0, 0); |
284 g_object_set_data(G_OBJECT(filepopup_win), "file", NULL); | 284 g_object_set_data(G_OBJECT(filepopup_win), "file", NULL); |
285 g_object_set_data(G_OBJECT(filepopup_win), "progressbar", | 285 g_object_set_data(G_OBJECT(filepopup_win), "progressbar", |
286 filepopup_progress); | 286 filepopup_progress); |
287 audacious_fileinfopopup_progress_init(filepopup_win); | 287 fileinfopopup_progress_init(filepopup_win); |
288 | 288 |
289 /* this will realize all widgets contained in filepopup_hbox */ | 289 /* this will realize all widgets contained in filepopup_hbox */ |
290 gtk_widget_show_all(filepopup_hbox); | 290 gtk_widget_show_all(filepopup_hbox); |
291 | 291 |
292 /* do not show the track progress */ | 292 /* do not show the track progress */ |
294 | 294 |
295 return filepopup_win; | 295 return filepopup_win; |
296 } | 296 } |
297 | 297 |
298 void | 298 void |
299 audacious_fileinfopopup_destroy(GtkWidget *filepopup_win) | 299 fileinfopopup_destroy(GtkWidget *filepopup_win) |
300 { | 300 { |
301 gchar *last_artwork; | 301 gchar *last_artwork; |
302 audacious_fileinfopopup_progress_stop(filepopup_win); | 302 fileinfopopup_progress_stop(filepopup_win); |
303 | 303 |
304 last_artwork = | 304 last_artwork = |
305 g_object_get_data(G_OBJECT(filepopup_win), "last_artwork"); | 305 g_object_get_data(G_OBJECT(filepopup_win), "last_artwork"); |
306 if (last_artwork != NULL) | 306 if (last_artwork != NULL) |
307 g_free(last_artwork); | 307 g_free(last_artwork); |
308 | 308 |
309 gtk_widget_destroy(filepopup_win); | 309 gtk_widget_destroy(filepopup_win); |
310 } | 310 } |
311 | 311 |
312 static void | 312 static void |
313 audacious_fileinfopupup_update_data(GtkWidget *filepopup_win, | 313 fileinfopupup_update_data(GtkWidget *filepopup_win, |
314 const gchar *text, | 314 const gchar *text, |
315 const gchar *label_data, | 315 const gchar *label_data, |
316 const gchar *header_data) | 316 const gchar *header_data) |
317 { | 317 { |
318 if (text != NULL) | 318 if (text != NULL) |
327 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win), label_data))); | 327 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win), label_data))); |
328 } | 328 } |
329 } | 329 } |
330 | 330 |
331 void | 331 void |
332 audacious_fileinfopopup_show_from_tuple(GtkWidget *filepopup_win, | 332 fileinfopopup_show_from_tuple(GtkWidget *filepopup_win, |
333 Tuple *tuple) | 333 Tuple *tuple) |
334 { | 334 { |
335 gchar *tmp = NULL; | 335 gchar *tmp = NULL; |
336 gint x, y, x_off = 3, y_off = 3, h, w; | 336 gint x, y, x_off = 3, y_off = 3, h, w; |
337 gchar *length_string, *year_string, *track_string; | 337 gchar *length_string, *year_string, *track_string; |
376 g_free(markup); | 376 g_free(markup); |
377 filepopup_entry_set_text(filepopup_win, "label_title", utf_filename); | 377 filepopup_entry_set_text(filepopup_win, "label_title", utf_filename); |
378 g_free(utf_filename); | 378 g_free(utf_filename); |
379 } | 379 } |
380 | 380 |
381 audacious_fileinfopupup_update_data(filepopup_win, tuple_get_string(tuple, FIELD_ARTIST, NULL), | 381 fileinfopupup_update_data(filepopup_win, tuple_get_string(tuple, FIELD_ARTIST, NULL), |
382 "label_artist", "header_artist"); | 382 "label_artist", "header_artist"); |
383 audacious_fileinfopupup_update_data(filepopup_win, tuple_get_string(tuple, FIELD_ALBUM, NULL), | 383 fileinfopupup_update_data(filepopup_win, tuple_get_string(tuple, FIELD_ALBUM, NULL), |
384 "label_album", "header_album"); | 384 "label_album", "header_album"); |
385 audacious_fileinfopupup_update_data(filepopup_win, tuple_get_string(tuple, FIELD_GENRE, NULL), | 385 fileinfopupup_update_data(filepopup_win, tuple_get_string(tuple, FIELD_GENRE, NULL), |
386 "label_genre", "header_genre"); | 386 "label_genre", "header_genre"); |
387 | 387 |
388 length = tuple_get_int(tuple, FIELD_LENGTH, NULL); | 388 length = tuple_get_int(tuple, FIELD_LENGTH, NULL); |
389 length_string = (length > 0) ? | 389 length_string = (length > 0) ? |
390 g_strdup_printf("%d:%02d", length / 60000, (length / 1000) % 60) : NULL; | 390 g_strdup_printf("%d:%02d", length / 60000, (length / 1000) % 60) : NULL; |
391 audacious_fileinfopupup_update_data(filepopup_win, length_string, | 391 fileinfopupup_update_data(filepopup_win, length_string, |
392 "label_tracklen", "header_tracklen"); | 392 "label_tracklen", "header_tracklen"); |
393 g_free(length_string); | 393 g_free(length_string); |
394 | 394 |
395 if ( length > 0 ) | 395 if ( length > 0 ) |
396 g_object_set_data( G_OBJECT(filepopup_win), "length" , GINT_TO_POINTER(length) ); | 396 g_object_set_data( G_OBJECT(filepopup_win), "length" , GINT_TO_POINTER(length) ); |
397 else | 397 else |
398 g_object_set_data( G_OBJECT(filepopup_win), "length" , GINT_TO_POINTER(-1) ); | 398 g_object_set_data( G_OBJECT(filepopup_win), "length" , GINT_TO_POINTER(-1) ); |
399 | 399 |
400 year_string = (tuple_get_int(tuple, FIELD_YEAR, NULL) == 0) ? NULL : g_strdup_printf("%d", tuple_get_int(tuple, FIELD_YEAR, NULL)); | 400 year_string = (tuple_get_int(tuple, FIELD_YEAR, NULL) == 0) ? NULL : g_strdup_printf("%d", tuple_get_int(tuple, FIELD_YEAR, NULL)); |
401 audacious_fileinfopupup_update_data(filepopup_win, year_string, | 401 fileinfopupup_update_data(filepopup_win, year_string, |
402 "label_year", "header_year"); | 402 "label_year", "header_year"); |
403 g_free(year_string); | 403 g_free(year_string); |
404 | 404 |
405 track_string = (tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL) == 0) ? NULL : g_strdup_printf("%d", tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL)); | 405 track_string = (tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL) == 0) ? NULL : g_strdup_printf("%d", tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL)); |
406 audacious_fileinfopupup_update_data(filepopup_win, track_string, | 406 fileinfopupup_update_data(filepopup_win, track_string, |
407 "label_tracknum", "header_tracknum"); | 407 "label_tracknum", "header_tracknum"); |
408 g_free(track_string); | 408 g_free(track_string); |
409 | 409 |
410 if (tuple_get_string(tuple, FIELD_FILE_NAME, NULL) && tuple_get_string(tuple, FIELD_FILE_PATH, NULL)) { | 410 if (tuple_get_string(tuple, FIELD_FILE_NAME, NULL) && tuple_get_string(tuple, FIELD_FILE_PATH, NULL)) { |
411 tmp = fileinfo_recursive_get_image(tuple_get_string(tuple, FIELD_FILE_PATH, NULL), tuple_get_string(tuple, FIELD_FILE_NAME, NULL), 0); | 411 tmp = fileinfo_recursive_get_image(tuple_get_string(tuple, FIELD_FILE_PATH, NULL), tuple_get_string(tuple, FIELD_FILE_NAME, NULL), 0); |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 /* start a timer that updates a progress bar if the tooltip | 434 /* start a timer that updates a progress bar if the tooltip |
435 is shown for the song that is being currently played */ | 435 is shown for the song that is being currently played */ |
436 if (audacious_fileinfopopup_progress_check_active(filepopup_win) == FALSE) | 436 if (fileinfopopup_progress_check_active(filepopup_win) == FALSE) |
437 { | 437 { |
438 audacious_fileinfopopup_progress_start(filepopup_win); | 438 fileinfopopup_progress_start(filepopup_win); |
439 /* immediately run the callback once to update progressbar status */ | 439 /* immediately run the callback once to update progressbar status */ |
440 audacious_fileinfopopup_progress_cb(filepopup_win); | 440 fileinfopopup_progress_cb(filepopup_win); |
441 } | 441 } |
442 | 442 |
443 gdk_window_get_pointer(gdk_get_default_root_window(), &x, &y, NULL); | 443 gdk_window_get_pointer(gdk_get_default_root_window(), &x, &y, NULL); |
444 gtk_window_get_size(GTK_WINDOW(filepopup_win), &w, &h); | 444 gtk_window_get_size(GTK_WINDOW(filepopup_win), &w, &h); |
445 if (gdk_screen_width()-(w+3) < x) x_off = (w*-1)-3; | 445 if (gdk_screen_width()-(w+3) < x) x_off = (w*-1)-3; |
448 | 448 |
449 gtk_widget_show(filepopup_win); | 449 gtk_widget_show(filepopup_win); |
450 } | 450 } |
451 | 451 |
452 void | 452 void |
453 audacious_fileinfopopup_show_from_title(GtkWidget *filepopup_win, gchar *title) | 453 fileinfopopup_show_from_title(GtkWidget *filepopup_win, gchar *title) |
454 { | 454 { |
455 Tuple * tuple = tuple_new(); | 455 Tuple * tuple = tuple_new(); |
456 tuple_associate_string(tuple, FIELD_TITLE, NULL, title); | 456 tuple_associate_string(tuple, FIELD_TITLE, NULL, title); |
457 audacious_fileinfopopup_show_from_tuple(filepopup_win, tuple); | 457 fileinfopopup_show_from_tuple(filepopup_win, tuple); |
458 mowgli_object_unref(tuple); | 458 mowgli_object_unref(tuple); |
459 return; | 459 return; |
460 } | 460 } |
461 | 461 |
462 void | 462 void |
463 audacious_fileinfopopup_hide(GtkWidget *filepopup_win, gpointer unused) | 463 fileinfopopup_hide(GtkWidget *filepopup_win, gpointer unused) |
464 { | 464 { |
465 if (GTK_WIDGET_VISIBLE(filepopup_win)) | 465 if (GTK_WIDGET_VISIBLE(filepopup_win)) |
466 { | 466 { |
467 audacious_fileinfopopup_progress_stop(filepopup_win); | 467 fileinfopopup_progress_stop(filepopup_win); |
468 | 468 |
469 gtk_widget_hide(filepopup_win); | 469 gtk_widget_hide(filepopup_win); |
470 | 470 |
471 filepopup_entry_set_text(GTK_WIDGET(filepopup_win), "label_title", ""); | 471 filepopup_entry_set_text(GTK_WIDGET(filepopup_win), "label_title", ""); |
472 filepopup_entry_set_text(GTK_WIDGET(filepopup_win), "label_artist", ""); | 472 filepopup_entry_set_text(GTK_WIDGET(filepopup_win), "label_artist", ""); |