Mercurial > audlegacy
comparison src/audacious/ui_fileinfopopup.c @ 2608:f4fa6b295b43 trunk
[svn] - Remove even more duplicate code
author | mf0102 |
---|---|
date | Mon, 05 Mar 2007 13:50:32 -0800 |
parents | 7c19bb5516db |
children | 2c41c0ef0c36 |
comparison
equal
deleted
inserted
replaced
2607:65543c999c7e | 2608:f4fa6b295b43 |
---|---|
84 | 84 |
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 void | |
90 filepopup_entry_set_text_free(GtkWidget *filepopup_win, const gchar *entry_name, | |
91 gchar *text) | |
92 | |
93 { | |
94 GtkWidget *widget = g_object_get_data(G_OBJECT(filepopup_win), entry_name); | |
95 g_return_if_fail(widget != NULL); | |
96 | |
97 gtk_label_set_text(GTK_LABEL(widget), text); | |
98 | |
99 g_free(text); | |
100 } | |
101 | |
102 static gboolean | 89 static gboolean |
103 audacious_fileinfopopup_progress_cb(gpointer filepopup_win) | 90 audacious_fileinfopopup_progress_cb(gpointer filepopup_win) |
104 { | 91 { |
105 GtkWidget *progressbar = | 92 GtkWidget *progressbar = |
106 g_object_get_data(G_OBJECT(filepopup_win), "progressbar"); | 93 g_object_get_data(G_OBJECT(filepopup_win), "progressbar"); |
318 g_free(last_artwork); | 305 g_free(last_artwork); |
319 | 306 |
320 gtk_widget_destroy(filepopup_win); | 307 gtk_widget_destroy(filepopup_win); |
321 } | 308 } |
322 | 309 |
310 static void | |
311 audacious_fileinfopupup_update_data(GtkWidget *filepopup_win, | |
312 const gchar *text, | |
313 const gchar *label_data, | |
314 const gchar *header_data) | |
315 { | |
316 if (text != NULL) | |
317 { | |
318 filepopup_entry_set_text(filepopup_win, label_data, text); | |
319 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win), header_data))); | |
320 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win), label_data))); | |
321 } | |
322 else | |
323 { | |
324 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win), header_data))); | |
325 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win), label_data))); | |
326 } | |
327 } | |
328 | |
323 void | 329 void |
324 audacious_fileinfopopup_show_from_tuple(GtkWidget *filepopup_win, | 330 audacious_fileinfopopup_show_from_tuple(GtkWidget *filepopup_win, |
325 TitleInput *tuple) | 331 TitleInput *tuple) |
326 { | 332 { |
327 gchar *tmp = NULL; | 333 gchar *tmp = NULL; |
347 gtk_widget_realize(filepopup_win); | 353 gtk_widget_realize(filepopup_win); |
348 | 354 |
349 if (tuple->track_name != NULL) | 355 if (tuple->track_name != NULL) |
350 { | 356 { |
351 gchar *markup = | 357 gchar *markup = |
352 g_markup_printf_escaped( "<span style=\"italic\">%s</span>" , _("Title") ); | 358 g_markup_printf_escaped("<span style=\"italic\">%s</span>", _("Title")); |
353 gtk_label_set_markup( GTK_LABEL(g_object_get_data(G_OBJECT(filepopup_win),"header_title")), markup ); | 359 gtk_label_set_markup(GTK_LABEL(g_object_get_data(G_OBJECT(filepopup_win), "header_title")), markup); |
354 g_free( markup ); | 360 g_free(markup); |
355 filepopup_entry_set_text(filepopup_win, "label_title", tuple->track_name); | 361 filepopup_entry_set_text(filepopup_win, "label_title", tuple->track_name); |
356 } | 362 } |
357 else | 363 else |
358 { | 364 { |
359 /* display the filename if track_name is not available */ | 365 /* display filename if track_name is not available */ |
360 gchar *markup = g_markup_printf_escaped( "<span style=\"italic\">%s</span>" , _("Filename") ); | 366 gchar *markup = |
361 gchar *utf_filename = filename_to_utf8(tuple->file_name); | 367 g_markup_printf_escaped("<span style=\"italic\">%s</span>", _("Filename")); |
362 gtk_label_set_markup( GTK_LABEL(g_object_get_data(G_OBJECT(filepopup_win),"header_title")), markup ); | 368 gchar *utf_filename = filename_to_utf8(tuple->file_name); |
363 g_free( markup ); | 369 gtk_label_set_markup(GTK_LABEL(g_object_get_data(G_OBJECT(filepopup_win), "header_title")), markup); |
364 filepopup_entry_set_text(filepopup_win, "label_title", utf_filename); | 370 g_free(markup); |
365 g_free( utf_filename ); | 371 filepopup_entry_set_text(filepopup_win, "label_title", utf_filename); |
366 } | 372 g_free(utf_filename); |
367 | 373 } |
368 if ( tuple->performer != NULL ) | 374 |
369 { | 375 audacious_fileinfopupup_update_data(filepopup_win, tuple->performer, |
370 filepopup_entry_set_text(filepopup_win, "label_artist", tuple->performer); | 376 "label_artist", "header_artist"); |
371 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_artist"))); | 377 audacious_fileinfopupup_update_data(filepopup_win, tuple->album_name, |
372 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_artist"))); | 378 "label_album", "header_album"); |
373 } | 379 audacious_fileinfopupup_update_data(filepopup_win, tuple->genre, |
374 else | 380 "label_genre", "header_genre"); |
375 { | 381 |
376 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_artist"))); | 382 gchar *length_string = (tuple->length > 0) ? |
377 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_artist"))); | 383 g_strdup_printf("%d:%02d", tuple->length / 60000, (tuple->length / 1000) % 60) : NULL; |
378 } | 384 audacious_fileinfopupup_update_data(filepopup_win, length_string, |
379 | 385 "label_tracklen", "header_tracklen"); |
380 if ( tuple->album_name != NULL ) | 386 g_free(length_string); |
381 { | 387 |
382 filepopup_entry_set_text(filepopup_win, "label_album", tuple->album_name); | 388 gchar *year_string = (tuple->year == 0) ? NULL : g_strdup_printf("%d", tuple->year); |
383 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_album"))); | 389 audacious_fileinfopupup_update_data(filepopup_win, year_string, |
384 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_album"))); | 390 "label_year", "header_year"); |
385 } | 391 g_free(year_string); |
386 else | 392 |
387 { | 393 gchar *track_string = (tuple->track_number == 0) ? NULL : g_strdup_printf("%d", tuple->track_number); |
388 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_album"))); | 394 audacious_fileinfopupup_update_data(filepopup_win, track_string, |
389 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_album"))); | 395 "label_tracknum", "header_tracknum"); |
390 } | 396 g_free(track_string); |
391 | 397 |
392 if ( tuple->genre != NULL ) | 398 if (tuple->file_path && tuple->file_name) |
393 { | |
394 filepopup_entry_set_text(filepopup_win, "label_genre", tuple->genre); | |
395 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_genre"))); | |
396 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_genre"))); | |
397 } | |
398 else | |
399 { | |
400 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_genre"))); | |
401 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_genre"))); | |
402 } | |
403 | |
404 if (tuple->length > 0) | |
405 { | |
406 filepopup_entry_set_text_free(filepopup_win, "label_tracklen", g_strdup_printf("%d:%02d", tuple->length / 60000, (tuple->length / 1000) % 60)); | |
407 g_object_set_data( G_OBJECT(filepopup_win), "length" , GINT_TO_POINTER(tuple->length) ); | |
408 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_tracklen"))); | |
409 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_tracklen"))); | |
410 } | |
411 else | |
412 { | |
413 filepopup_entry_set_text(filepopup_win, "label_tracklen", ""); | |
414 g_object_set_data( G_OBJECT(filepopup_win), "length" , GINT_TO_POINTER(-1) ); | |
415 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_tracklen"))); | |
416 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_tracklen"))); | |
417 } | |
418 | |
419 if (tuple->year != 0) | |
420 { | |
421 filepopup_entry_set_text_free(filepopup_win, "label_year", g_strdup_printf("%d", tuple->year)); | |
422 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_year"))); | |
423 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_year"))); | |
424 } | |
425 else | |
426 { | |
427 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_year"))); | |
428 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_year"))); | |
429 } | |
430 | |
431 if (tuple->track_number != 0) | |
432 { | |
433 filepopup_entry_set_text_free(filepopup_win, "label_tracknum", g_strdup_printf("%d", tuple->track_number)); | |
434 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_tracknum"))); | |
435 gtk_widget_show(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_tracknum"))); | |
436 } | |
437 else | |
438 { | |
439 filepopup_entry_set_text(filepopup_win, "label_tracknum", ""); | |
440 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"header_tracknum"))); | |
441 gtk_widget_hide(GTK_WIDGET(g_object_get_data(G_OBJECT(filepopup_win),"label_tracknum"))); | |
442 } | |
443 | |
444 if ( ( tuple->file_path ) && ( tuple->file_name ) ) | |
445 { | 399 { |
446 tmp = fileinfo_recursive_get_image(tuple->file_path, tuple->file_name, 0); | 400 tmp = fileinfo_recursive_get_image(tuple->file_path, tuple->file_name, 0); |
447 if (tmp) { // picture found | 401 if (tmp) { // picture found |
448 if (!last_artwork || strcmp(last_artwork, tmp)) { // new picture | 402 if (!last_artwork || strcmp(last_artwork, tmp)) { // new picture |
449 filepopup_entry_set_image(filepopup_win, "image_artwork", tmp); | 403 filepopup_entry_set_image(filepopup_win, "image_artwork", tmp); |
450 if (last_artwork) g_free(last_artwork); | 404 if (last_artwork) g_free(last_artwork); |
451 last_artwork = tmp; | 405 last_artwork = tmp; |
452 g_object_set_data( G_OBJECT(filepopup_win) , "last_artwork" , last_artwork ); | 406 g_object_set_data(G_OBJECT(filepopup_win), "last_artwork", last_artwork); |
453 } | 407 } |
454 else { // same picture | 408 else { // same picture |
455 } | 409 } |
456 } | 410 } |
457 else { // no picture found | 411 else { // no picture found |
458 if (!last_artwork || strcmp(last_artwork, default_artwork)) { | 412 if (!last_artwork || strcmp(last_artwork, default_artwork)) { |
459 filepopup_entry_set_image(filepopup_win, "image_artwork", default_artwork); | 413 filepopup_entry_set_image(filepopup_win, "image_artwork", default_artwork); |
460 if (last_artwork) g_free(last_artwork); | 414 if (last_artwork) g_free(last_artwork); |
461 last_artwork = g_strdup(default_artwork); | 415 last_artwork = g_strdup(default_artwork); |
462 g_object_set_data( G_OBJECT(filepopup_win) , "last_artwork" , last_artwork ); | 416 g_object_set_data(G_OBJECT(filepopup_win), "last_artwork", last_artwork); |
463 } | 417 } |
464 else { | 418 else { |
465 } | 419 } |
466 } | 420 } |
467 } | 421 } |
468 | 422 |
469 /* start a timer that updates a progress bar if the tooltip | 423 /* start a timer that updates a progress bar if the tooltip |
470 is shown for the song that is being currently played */ | 424 is shown for the song that is being currently played */ |
471 if ( audacious_fileinfopopup_progress_check_active( filepopup_win ) == FALSE ) | 425 if (audacious_fileinfopopup_progress_check_active(filepopup_win) == FALSE) |
472 { | 426 { |
473 audacious_fileinfopopup_progress_start( filepopup_win ); | 427 audacious_fileinfopopup_progress_start(filepopup_win); |
474 /* also run immediately the callback once, to update progressbar status */ | 428 /* immediately run the callback once to update progressbar status */ |
475 audacious_fileinfopopup_progress_cb( filepopup_win ); | 429 audacious_fileinfopopup_progress_cb(filepopup_win); |
476 } | 430 } |
477 | 431 |
478 gdk_window_get_pointer(NULL, &x, &y, NULL); | 432 gdk_window_get_pointer(NULL, &x, &y, NULL); |
479 gtk_window_get_size(GTK_WINDOW(filepopup_win), &w, &h); | 433 gtk_window_get_size(GTK_WINDOW(filepopup_win), &w, &h); |
480 if (gdk_screen_width()-(w+3) < x) x_off = (w*-1)-3; | 434 if (gdk_screen_width()-(w+3) < x) x_off = (w*-1)-3; |