Update of /cvsroot/beepmp/bmp/beep In directory sc8-pr-cvs1:/tmp/cvs-serv12963 Modified Files: dirbrowser.c playlist.c playlist.h playlist_list.c playlist_list.h pluginenum.c skinwin.c util.c util.h Log Message: - plugged all (I hope) memory leaks in playlist_list.c - more cleanups Index: dirbrowser.c =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/dirbrowser.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dirbrowser.c 25 Dec 2003 23:26:13 -0000 1.14 --- dirbrowser.c 26 Dec 2003 03:33:06 -0000 1.15 *************** *** 15,19 **** static GtkTreePath *current; - static gchar *playlist_current_name = NULL; static GtkItemFactory *bmp_db_popup; --- 15,18 ---- *************** *** 101,107 **** static void bmp_db_mdb_add_track(gchar * arg_artist_p, ! gchar * arg_album_p, gchar * arg_track_p, ! guint arg_tracknum, gchar * arg_path, ! GtkTreeModel * model_sort) { --- 100,106 ---- static void bmp_db_mdb_add_track(gchar * arg_artist_p, ! gchar * arg_album_p, gchar * arg_track_p, ! guint arg_tracknum, gchar * arg_path, ! GtkTreeModel * model_sort) { *************** *** 230,236 **** { ! /* If this isn't a directory or regular file return failure */ ! if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR)) { ! return FALSE; } --- 229,236 ---- { ! /* If this isn't a directory or regular file return failure */ ! if (!g_file_test ! (filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR)) { ! return FALSE; } *************** *** 316,320 **** static gchar *bmp_db_get_path_real(gchar * path, GtkTreeModel * model, ! GtkTreeIter * iter) { --- 316,320 ---- static gchar *bmp_db_get_path_real(gchar * path, GtkTreeModel * model, ! GtkTreeIter * iter) { *************** *** 333,337 **** static void bmp_db_create_dirtree(GtkTreeModel * model, gchar * from, ! GtkTreeIter parent_iter) { --- 333,337 ---- static void bmp_db_create_dirtree(GtkTreeModel * model, gchar * from, ! GtkTreeIter parent_iter) { *************** *** 351,355 **** from_real = bmp_db_get_path_real(from, model, &parent_iter); g_free(from); ! /* It's not really a waste creating both beforehand since we will * certainly need the folder one at least once, and most probably --- 351,355 ---- from_real = bmp_db_get_path_real(from, model, &parent_iter); g_free(from); ! /* It's not really a waste creating both beforehand since we will * certainly need the folder one at least once, and most probably *************** *** 522,526 **** /* caveat, the root in bmp_db_create_dirtree is relative */ bmp_db_create_dirtree(GTK_TREE_MODEL(model), ! /* starting at */ "/", iter); g_strfreev(frags); } --- 522,526 ---- /* caveat, the root in bmp_db_create_dirtree is relative */ bmp_db_create_dirtree(GTK_TREE_MODEL(model), ! /* starting at */ "/", iter); g_strfreev(frags); } *************** *** 559,564 **** static gchar *bmp_db_path_get_full(GtkTreeModel * model, ! const gchar * path, ! GtkTreeIter iter_current) { --- 559,564 ---- static gchar *bmp_db_path_get_full(GtkTreeModel * model, ! const gchar * path, ! GtkTreeIter iter_current) { *************** *** 597,602 **** static void bmp_db_row_expanded(GtkTreeView * treeview, ! GtkTreeIter * arg1, ! GtkTreePath * arg2, gpointer user_data) { GtkTreeIter iter_current; --- 597,602 ---- static void bmp_db_row_expanded(GtkTreeView * treeview, ! GtkTreeIter * arg1, ! GtkTreePath * arg2, gpointer user_data) { GtkTreeIter iter_current; *************** *** 627,633 **** path = bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, ! iter_current); bmp_db_create_dirtree(GTK_TREE_MODEL(model), path, ! iter_current); } --- 627,633 ---- path = bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, ! iter_current); bmp_db_create_dirtree(GTK_TREE_MODEL(model), path, ! iter_current); } *************** *** 643,647 **** static void bmp_db_row_activated(GtkTreeSelection * sel, ! gpointer user_data) { GtkTreeIter iter; --- 643,647 ---- static void bmp_db_row_activated(GtkTreeSelection * sel, ! gpointer user_data) { GtkTreeIter iter; *************** *** 669,674 **** -1); path = ! bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, ! iter); /* FIXME: path is not freed */ --- 669,673 ---- -1); path = ! bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, iter); /* FIXME: path is not freed */ *************** *** 782,787 **** path = ! bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, ! iter); path = g_locale_from_utf8(path, -1, NULL, NULL, NULL); path_real = bmp_db_get_path_real(path, model, &iter); --- 781,785 ---- path = ! bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, iter); path = g_locale_from_utf8(path, -1, NULL, NULL, NULL); path_real = bmp_db_get_path_real(path, model, &iter); *************** *** 816,820 **** static void bmp_db_detatch_selected_entry_kp(GtkWidget * w, ! GtkDialog * dialog) { gtk_dialog_response(dialog, GTK_RESPONSE_ACCEPT); --- 814,818 ---- static void bmp_db_detatch_selected_entry_kp(GtkWidget * w, ! GtkDialog * dialog) { gtk_dialog_response(dialog, GTK_RESPONSE_ACCEPT); *************** *** 877,882 **** entry = gtk_entry_new(); g_signal_connect(entry, "activate", ! G_CALLBACK(bmp_db_detatch_selected_entry_kp), ! dialog); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, TRUE, TRUE, 8); --- 875,879 ---- entry = gtk_entry_new(); g_signal_connect(entry, "activate", ! G_CALLBACK(bmp_db_detatch_selected_entry_kp), dialog); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, TRUE, TRUE, 8); *************** *** 892,897 **** path = ! bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, ! iter); path_real = bmp_db_get_path_real(path, model, &iter); --- 889,893 ---- path = ! bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, iter); path_real = bmp_db_get_path_real(path, model, &iter); *************** *** 924,928 **** 0, node->image, 1, node->name, -1); bmp_db_create_dirtree(GTK_TREE_MODEL(model), ! /* starting at */ "/", iter); } else { /* FIXME: response to failed to get iter */ --- 920,924 ---- 0, node->image, 1, node->name, -1); bmp_db_create_dirtree(GTK_TREE_MODEL(model), ! /* starting at */ "/", iter); } else { /* FIXME: response to failed to get iter */ *************** *** 1041,1046 **** path = ! bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, ! iter); path_real = bmp_db_get_path_real(path, model, &iter); --- 1037,1041 ---- path = ! bmp_db_path_get_full(GTK_TREE_MODEL(model), node_name, iter); path_real = bmp_db_get_path_real(path, model, &iter); *************** *** 1072,1076 **** static void bmp_db_add_expanded_paths(GtkWidget * treeview, ! GtkTreePath * path, gpointer data) { data = g_list_append(data, gtk_tree_path_to_string(path)); --- 1067,1071 ---- static void bmp_db_add_expanded_paths(GtkWidget * treeview, ! GtkTreePath * path, gpointer data) { data = g_list_append(data, gtk_tree_path_to_string(path)); *************** *** 1198,1202 **** static gint bmp_db_keypress(GtkWidget * grab_widget, ! GdkEventKey * event, gpointer data) { if (event && (event->keyval == GDK_Escape)) { --- 1193,1197 ---- static gint bmp_db_keypress(GtkWidget * grab_widget, ! GdkEventKey * event, gpointer data) { if (event && (event->keyval == GDK_Escape)) { *************** *** 1212,1217 **** static gint bmp_db_mdb_sort_func(GtkTreeModel * model, ! GtkTreeIter * a, GtkTreeIter * b, ! gpointer user_data) { --- 1207,1212 ---- static gint bmp_db_mdb_sort_func(GtkTreeModel * model, ! GtkTreeIter * a, GtkTreeIter * b, ! gpointer user_data) { *************** *** 1319,1323 **** gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(sort_model), ! bmp_db_mdb_sort_func, NULL, NULL); --- 1314,1319 ---- gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(sort_model), ! bmp_db_mdb_sort_func, NULL, ! NULL); *************** *** 1352,1356 **** bmp_db_mdb_add_track(artist, album, title, tracknumber, ! files->data, sort_model); files = files->next; --- 1348,1352 ---- bmp_db_mdb_add_track(artist, album, title, tracknumber, ! files->data, sort_model); files = files->next; *************** *** 1518,1523 **** db_accel = gtk_accel_group_new(); ! bmp_db_popup = gtk_item_factory_new(GTK_TYPE_MENU, ! "<Main>", db_accel); gtk_item_factory_create_items(GTK_ITEM_FACTORY(bmp_db_popup), --- 1514,1518 ---- db_accel = gtk_accel_group_new(); ! bmp_db_popup = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", db_accel); gtk_item_factory_create_items(GTK_ITEM_FACTORY(bmp_db_popup), *************** *** 1555,1560 **** static gboolean bmp_db_popup_menu(GtkWidget * widget, ! GdkEventButton * event, ! gpointer user_data) { --- 1550,1555 ---- static gboolean bmp_db_popup_menu(GtkWidget * widget, ! GdkEventButton * event, ! gpointer user_data) { *************** *** 1575,1579 **** static void bmp_db_menu_callback(gpointer data, guint action, ! GtkWidget * widget) { --- 1570,1574 ---- static void bmp_db_menu_callback(gpointer data, guint action, ! GtkWidget * widget) { Index: playlist.c =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/playlist.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** playlist.c 25 Dec 2003 23:26:13 -0000 1.23 --- playlist.c 26 Dec 2003 03:33:06 -0000 1.24 *************** *** 953,957 **** if (cfg.show_numbers_in_pl) ! numbers = g_strdup_printf("%d. ", __playlist_get_position() + 1); else numbers = g_strdup(""); --- 953,958 ---- if (cfg.show_numbers_in_pl) ! numbers = ! g_strdup_printf("%d. ", playlist_get_position_nolock() + 1); else numbers = g_strdup(""); *************** *** 976,980 **** if (cfg.convert_twenty) while ((tmp = strstr(text, "%20")) != NULL) { ! char *tmp2; tmp2 = tmp + 3; *(tmp++) = ' '; --- 977,981 ---- if (cfg.convert_twenty) while ((tmp = strstr(text, "%20")) != NULL) { ! gchar *tmp2; tmp2 = tmp + 3; *(tmp++) = ' '; *************** *** 1230,1234 **** } ! gint __playlist_get_position(void) { /* Caller should hold playlist_mutex */ --- 1231,1235 ---- } ! gint playlist_get_position_nolock(void) { /* Caller should hold playlist_mutex */ *************** *** 1243,1247 **** PLAYLIST_LOCK(); ! retval = __playlist_get_position(); PLAYLIST_UNLOCK(); --- 1244,1248 ---- PLAYLIST_LOCK(); ! retval = playlist_get_position_nolock(); PLAYLIST_UNLOCK(); Index: playlist.h =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/playlist.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** playlist.h 25 Dec 2003 23:26:13 -0000 1.10 --- playlist.h 26 Dec 2003 03:33:06 -0000 1.11 *************** *** 22,27 **** #include <glib.h> - #include <pthread.h> typedef struct { gchar *filename; --- 22,27 ---- #include <glib.h> + #define PLAYLIST_ENTRY(x) ((PlaylistEntry*)(x)) typedef struct { gchar *filename; *************** *** 38,42 **** /* void playlist_add_dir(gchar * dir); */ #define playlist_add_dir(directory) playlist_ins_dir(directory, -1, TRUE) ! guint playlist_ins_dir(gchar *dir, glong pos, gboolean background); /* void playlist_add_url_string(gchar * string); */ #define playlist_add_url_string(string) playlist_ins_url_string(string, -1) --- 38,42 ---- /* void playlist_add_dir(gchar * dir); */ #define playlist_add_dir(directory) playlist_ins_dir(directory, -1, TRUE) ! guint playlist_ins_dir(gchar * dir, glong pos, gboolean background); /* void playlist_add_url_string(gchar * string); */ #define playlist_add_url_string(string) playlist_ins_url_string(string, -1) *************** *** 58,65 **** gint playlist_get_length_nolock(void); gint playlist_get_position(void); ! gint __playlist_get_position(void); gchar *playlist_get_info_text(void); int playlist_get_current_length(void); ! gboolean playlist_save(const gchar *filename, gboolean is_pls); gboolean playlist_load(gchar * filename); GList *playlist_get(void); --- 58,65 ---- gint playlist_get_length_nolock(void); gint playlist_get_position(void); ! gint playlist_get_position_nolock(void); gchar *playlist_get_info_text(void); int playlist_get_current_length(void); ! gboolean playlist_save(const gchar * filename, gboolean is_pls); gboolean playlist_load(gchar * filename); GList *playlist_get(void); Index: playlist_list.c =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/playlist_list.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** playlist_list.c 25 Dec 2003 23:26:13 -0000 1.12 --- playlist_list.c 26 Dec 2003 03:33:06 -0000 1.13 *************** *** 37,52 **** /* FIXME: This is all still too slow. */ ! #include "beep.h" - #ifdef HAVE_WCHAR_H - #include <wchar.h> - #endif #include <X11/Xatom.h> ! ! #include <ft2build.h> ! #include FT_FREETYPE_H ! #include <pango/pangoft2.h> PangoFontDescription *playlist_list_font = NULL; guint ascent, descent, width_delta_digit_one; --- 37,52 ---- /* FIXME: This is all still too slow. */ ! #include "playlist_list.h" #include <X11/Xatom.h> ! #include <freetype/freetype.h> #include <pango/pangoft2.h> + #include "main.h" + #include "input.h" + #include "playlist.h" + #include "playlistwin.h" + #include "util.h" + PangoFontDescription *playlist_list_font = NULL; guint ascent, descent, width_delta_digit_one; *************** *** 63,67 **** guint width_approx_digits, width_approx_digits_half; ! static int playlist_list_auto_drag_down_func(gpointer data) { PlayList_List *pl = data; --- 63,67 ---- guint width_approx_digits, width_approx_digits_half; ! static gint playlist_list_auto_drag_down_func(gpointer data) { PlayList_List *pl = data; *************** *** 77,81 **** } ! static int playlist_list_auto_drag_up_func(gpointer data) { PlayList_List *pl = data; --- 77,81 ---- } ! static gint playlist_list_auto_drag_up_func(gpointer data) { PlayList_List *pl = data; *************** *** 100,104 **** return; } ! if (((PlaylistEntry *) list->data)->selected) { /* We are at the top */ PLAYLIST_UNLOCK(); --- 100,104 ---- return; } ! if (PLAYLIST_ENTRY(list->data)->selected) { /* We are at the top */ PLAYLIST_UNLOCK(); *************** *** 106,110 **** } while (list) { ! if (((PlaylistEntry *) list->data)->selected) glist_moveup(list); list = g_list_next(list); --- 106,110 ---- } while (list) { ! if (PLAYLIST_ENTRY(list->data)->selected) glist_moveup(list); list = g_list_next(list); *************** *** 128,132 **** return; } ! if (((PlaylistEntry *) list->data)->selected) { /* We are at the bottom */ PLAYLIST_UNLOCK(); --- 128,132 ---- return; } ! if (PLAYLIST_ENTRY(list->data)->selected) { /* We are at the bottom */ PLAYLIST_UNLOCK(); *************** *** 134,138 **** } while (list) { ! if (((PlaylistEntry *) list->data)->selected) glist_movedown(list); list = g_list_previous(list); --- 134,138 ---- } while (list) { ! if (PLAYLIST_ENTRY(list->data)->selected) glist_movedown(list); list = g_list_previous(list); *************** *** 147,158 **** } ! void playlist_list_button_press_cb(GtkWidget * widget, ! GdkEventButton * event, ! PlayList_List * pl) { if (event->button == 1 && pl->pl_fheight && inside_widget(event->x, event->y, &pl->pl_widget)) { - int nr, y; - y = event->y - pl->pl_widget.y; nr = (y / pl->pl_fheight) + pl->pl_first; --- 147,158 ---- } ! static void playlist_list_button_press_cb(GtkWidget * widget, ! GdkEventButton * event, ! PlayList_List * pl) { + gint nr, y; + if (event->button == 1 && pl->pl_fheight && inside_widget(event->x, event->y, &pl->pl_widget)) { y = event->y - pl->pl_widget.y; nr = (y / pl->pl_fheight) + pl->pl_first; *************** *** 203,209 **** } ! int playlist_list_get_playlist_position(PlayList_List * pl, int x, int y) { ! int iy, length; if (!inside_widget(x, y, pl) || !pl->pl_fheight) --- 203,210 ---- } ! gint playlist_list_get_playlist_position(PlayList_List * pl, gint x, ! gint y) { ! gint iy, length; if (!inside_widget(x, y, pl) || !pl->pl_fheight) *************** *** 217,222 **** } ! void playlist_list_motion_cb(GtkWidget * widget, GdkEventMotion * event, ! PlayList_List * pl) { gint nr, y, off, i; --- 218,224 ---- } ! static void playlist_list_motion_cb(GtkWidget * widget, ! GdkEventMotion * event, ! PlayList_List * pl) { gint nr, y, off, i; *************** *** 262,268 **** } ! void playlist_list_button_release_cb(GtkWidget * widget, ! GdkEventButton * event, ! PlayList_List * pl) { pl->pl_dragging = FALSE; --- 264,270 ---- } ! static void playlist_list_button_release_cb(GtkWidget * widget, ! GdkEventButton * event, ! PlayList_List * pl) { pl->pl_dragging = FALSE; *************** *** 271,301 **** } ! #define playlist_list_draw_string_wc playlist_list_draw_string ! ! void playlist_list_draw_string(PlayList_List * pl, ! PangoFontDescription * font, gint line, ! gint width, gchar * text, guint ppos) { ! int len; ! int pix_len; ! char *tmp; guint padding, plist_length_int; PangoLayout *layout; ! ! if (cfg.convert_underscore) ! while ((tmp = strchr(text, '_')) != NULL) ! *tmp = ' '; ! ! if (cfg.convert_twenty) ! while ((tmp = strstr(text, "%20")) != NULL) { ! char *tmp2 = tmp + 3; ! *(tmp++) = ' '; ! while (*tmp2) ! *(tmp++) = *(tmp2++); ! *tmp = '\0'; ! } len = strlen(text); - pix_len = (width_approx_letters * len); --- 273,289 ---- } ! static void playlist_list_draw_string(PlayList_List * pl, ! PangoFontDescription * font, ! gint line, gint width, gchar * text, ! guint ppos) { ! /* caller must hold playlist mutex */ ! gint len; ! gint pix_len; guint padding, plist_length_int; PangoLayout *layout; ! gchar *text_utf8; len = strlen(text); pix_len = (width_approx_letters * len); *************** *** 307,316 **** if (cfg.show_numbers_in_pl) { - - gchar *pos_string = g_strdup_printf("%d", ppos); plist_length_int = ! strlen(g_strdup_printf("%d", playlist_get_length_nolock())) + ! 1; padding = plist_length_int; --- 295,301 ---- if (cfg.show_numbers_in_pl) { gchar *pos_string = g_strdup_printf("%d", ppos); plist_length_int = ! gint_count_digits(playlist_get_length_nolock()) + 1; padding = plist_length_int; *************** *** 319,329 **** layout = gtk_widget_create_pango_layout(GTK_WIDGET(playlistwin), ! g_locale_to_utf8(pos_string, -1, ! NULL, NULL, ! NULL)); pango_layout_set_font_description(layout, playlist_list_font); pango_layout_set_width(layout, plist_length_int * 100); ! if (atoi(pos_string) == 1) { pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, --- 304,312 ---- layout = gtk_widget_create_pango_layout(GTK_WIDGET(playlistwin), ! pos_string); pango_layout_set_font_description(layout, playlist_list_font); pango_layout_set_width(layout, plist_length_int * 100); ! if (ppos == 1) { pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, *************** *** 342,345 **** --- 325,329 ---- ascent + abs(descent), layout); } + g_free(pos_string); g_object_unref(layout); } else { *************** *** 347,354 **** } layout = ! gtk_widget_create_pango_layout(GTK_WIDGET(playlistwin), ! g_locale_to_utf8(text, -1, NULL, ! NULL, NULL)); pango_layout_set_font_description(layout, playlist_list_font); --- 331,337 ---- } + text_utf8 = g_locale_to_utf8(text, -1, NULL, NULL, NULL); layout = ! gtk_widget_create_pango_layout(GTK_WIDGET(playlistwin), text_utf8); pango_layout_set_font_description(layout, playlist_list_font); *************** *** 359,367 **** g_object_unref(layout); } ! void playlist_list_draw(Widget * w) { ! PlayList_List *pl = (PlayList_List *) w; GList *list; GdkGC *gc; --- 342,369 ---- g_object_unref(layout); + g_free(text_utf8); } ! static void convert_title_text(gchar * text) { ! gchar *match, *tmp; ! ! if (cfg.convert_underscore) ! while ((match = strchr(text, '_'))) ! *match = ' '; ! ! if (cfg.convert_twenty) ! while ((match = strstr(text, "%20"))) { ! tmp = match + 3; ! *match++ = ' '; ! while (*tmp) ! *match++ = *tmp++; ! *match = '\0'; ! } ! } ! ! static void playlist_list_draw(Widget * w) ! { ! PlayList_List *pl = PLAYLIST_LIST(w); GList *list; GdkGC *gc; *************** *** 370,377 **** gchar *title; gint width, height; ! gint i, tw, max_first; guint padding; guint max_time_len = 0; gc = pl->pl_widget.gc; width = pl->pl_widget.width; --- 372,382 ---- gchar *title; gint width, height; ! gint i, max_first; guint padding; guint max_time_len = 0; + gchar tail[100]; + gchar length[40]; + gc = pl->pl_widget.gc; width = pl->pl_widget.width; *************** *** 384,393 **** width, height); ! if (playlist_list_font == NULL) { ! g_log(NULL, G_LOG_LEVEL_CRITICAL, "Couldn't open playlist font"); return; } - PLAYLIST_LOCK(); list = playlist_get(); --- 389,397 ---- width, height); ! if (!playlist_list_font) { ! g_critical("Couldn't open playlist font"); return; } PLAYLIST_LOCK(); list = playlist_get(); *************** *** 396,406 **** pl->pl_num_visible = height / pl->pl_fheight; ! max_first = g_list_length(list) - pl->pl_num_visible; ! if (max_first < 0) ! max_first = 0; ! if (pl->pl_first >= max_first) ! pl->pl_first = max_first; ! if (pl->pl_first < 0) ! pl->pl_first = 0; for (i = 0; i < pl->pl_first; i++) list = g_list_next(list); --- 400,406 ---- pl->pl_num_visible = height / pl->pl_fheight; ! max_first = MAX(g_list_length(list) - pl->pl_num_visible, 0); ! pl->pl_first = CLAMP(pl->pl_first, 0, max_first); ! for (i = 0; i < pl->pl_first; i++) list = g_list_next(list); *************** *** 409,416 **** list && i < pl->pl_first + pl->pl_num_visible; list = list->next, i++) { ! char qstr[20] = "", length[40] = ""; ! int pos; ! PlaylistEntry *entry = (PlaylistEntry *) list->data; if (entry->selected) { gdk_gc_set_foreground(gc, --- 409,415 ---- list && i < pl->pl_first + pl->pl_num_visible; list = list->next, i++) { ! gint pos; ! PlaylistEntry *entry = PLAYLIST_ENTRY(list->data); if (entry->selected) { gdk_gc_set_foreground(gc, *************** *** 421,471 **** width, pl->pl_fheight); } ! if (i == __playlist_get_position()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); else gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_NORMAL)); ! if (entry->title) title = g_strdup(entry->title); else title = g_path_get_basename(entry->filename); ! if (!g_locale_to_utf8(title, -1, NULL, NULL, NULL)) ! title = g_path_get_basename(entry->filename); pos = playlist_get_queue_position(entry); if (pos != -1) ! sprintf(qstr, "|%d|%s", pos + 1, ! entry->length != -1 ? " " : ""); if (entry->length != -1) ! sprintf(length, "%d:%-2.2d", entry->length / 60000, ! (entry->length / 1000) % 60); if (pos != -1 || entry->length != -1) { ! int x, y; ! gchar *tail; ! guint t_width; ! guint len_tail; ! guint len; ! tail = g_strdup_printf("%s%s", qstr, length); ! if (strlen(tail) > max_time_len) ! max_time_len = strlen(tail); /* FIXME: This is just an approximate alignment, maybe something still fast, but exact could be done */ ! len_tail = strlen(tail); ! len_tail -= 4; ! ! t_width = ! ((4 + len_tail) * width_approx_digits) + ! (width_approx_digits_half) + 2; ! tw = width - t_width - 5; ! if (i == __playlist_get_position()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); --- 420,465 ---- width, pl->pl_fheight); } ! if (i == playlist_get_position_nolock()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); else gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_NORMAL)); ! if (g_utf8_validate(entry->title, -1, NULL)) title = g_strdup(entry->title); else title = g_path_get_basename(entry->filename); ! convert_title_text(title); pos = playlist_get_queue_position(entry); + tail[0] = 0; + length[0] = 0; + if (pos != -1) ! g_snprintf(tail, 100, "|%d|%s", pos + 1, ! entry->length != -1 ? " " : ""); if (entry->length != -1) ! g_snprintf(length, 40, "%d:%-2.2d", entry->length / 60000, ! (entry->length / 1000) % 60); if (pos != -1 || entry->length != -1) { ! gint x, y; ! guint tail_width; ! guint tail_len; ! strncat(tail, length, sizeof(tail)); ! tail_len = strlen(tail); ! max_time_len = MAX(max_time_len, tail_len); /* FIXME: This is just an approximate alignment, maybe something still fast, but exact could be done */ ! tail_width = width - (tail_len * width_approx_digits) + ! (width_approx_digits_half) - 3; ! if (i == playlist_get_position_nolock()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); *************** *** 474,478 **** get_skin_color(SKIN_PLEDIT_NORMAL)); playlist_list_draw_string(pl, playlist_list_font, ! i - pl->pl_first, tw, title, i + 1); x = pl->pl_widget.x + width - width_approx_digits * 2; --- 468,473 ---- get_skin_color(SKIN_PLEDIT_NORMAL)); playlist_list_draw_string(pl, playlist_list_font, ! i - pl->pl_first, tail_width, title, ! i + 1); x = pl->pl_widget.x + width - width_approx_digits * 2; *************** *** 490,494 **** } ! /* This isn't very cool, but i don't see a way to calculate row widths with Pango fast enough here */ gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x + pl->pl_widget.width - --- 485,490 ---- } ! /* This isn't very cool, but i don't see a way to ! * calculate row widths with Pango fast enough here */ gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x + pl->pl_widget.width - *************** *** 497,501 **** pl->pl_fheight - 1); ! if (i == __playlist_get_position()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); --- 493,497 ---- pl->pl_fheight - 1); ! if (i == playlist_get_position_nolock()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); *************** *** 504,521 **** get_skin_color(SKIN_PLEDIT_NORMAL)); - len = strlen(tail); - - - gchar **frags = g_strsplit(tail, ":", 0); layout = gtk_widget_create_pango_layout(GTK_WIDGET(playlistwin), ! g_locale_to_utf8(frags[1], ! -1, NULL, ! NULL, ! NULL)); pango_layout_set_font_description(layout, playlist_list_font); ! pango_layout_set_width(layout, strlen(tail) * 100); pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); gdk_draw_layout(obj, gc, x - (0.25 * width_approx_digits), --- 500,511 ---- get_skin_color(SKIN_PLEDIT_NORMAL)); gchar **frags = g_strsplit(tail, ":", 0); + gchar *frag0 = g_strconcat(frags[0], ":", NULL); layout = gtk_widget_create_pango_layout(GTK_WIDGET(playlistwin), ! frags[1]); pango_layout_set_font_description(layout, playlist_list_font); ! pango_layout_set_width(layout, tail_len * 100); pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); gdk_draw_layout(obj, gc, x - (0.25 * width_approx_digits), *************** *** 525,536 **** layout = gtk_widget_create_pango_layout(GTK_WIDGET(playlistwin), ! g_locale_to_utf8(g_strconcat ! (frags[0], ! ":", ! NULL), -1, ! NULL, NULL, ! NULL)); pango_layout_set_font_description(layout, playlist_list_font); ! pango_layout_set_width(layout, strlen(tail) * 100); pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); gdk_draw_layout(obj, gc, x - (0.5 * width_approx_digits), --- 515,521 ---- layout = gtk_widget_create_pango_layout(GTK_WIDGET(playlistwin), ! frag0); pango_layout_set_font_description(layout, playlist_list_font); ! pango_layout_set_width(layout, tail_len * 100); pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT); gdk_draw_layout(obj, gc, x - (0.5 * width_approx_digits), *************** *** 538,547 **** g_object_unref(layout); ! } else { ! tw = width; ! ! if (i == __playlist_get_position()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); --- 523,531 ---- g_object_unref(layout); ! g_free(frag0); ! g_strfreev(frags); } else { ! if (i == playlist_get_position_nolock()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); *************** *** 551,555 **** playlist_list_draw_string(pl, playlist_list_font, ! i - pl->pl_first, tw, title, i + 1); } --- 535,540 ---- playlist_list_draw_string(pl, playlist_list_font, ! i - pl->pl_first, width, title, ! i + 1); } *************** *** 568,572 **** if (pl->pl_drag_motion) { ! unsigned int pos, x, y, plx, ply, plength; /* We already hold the mutex and have the playlist locked, so call --- 553,557 ---- if (pl->pl_drag_motion) { ! guint pos, x, y, plx, ply, plength; /* We already hold the mutex and have the playlist locked, so call *************** *** 585,590 **** && !(y > (pl->pl_widget.height + ply))) { ! pos = ! ((y - ((Widget *) pl)->y) / pl->pl_fheight) + pl->pl_first; if (pos > (plength)) { --- 570,574 ---- && !(y > (pl->pl_widget.height + ply))) { ! pos = ((y - ((Widget *) pl)->y) / pl->pl_fheight) + pl->pl_first; if (pos > (plength)) { *************** *** 633,645 **** if (cfg.show_numbers_in_pl) { padding = ! -1 + ! strlen(g_strdup_printf("%d", playlist_get_length_nolock())) + ! 1; ! padding = ! (padding * width_approx_digits) + (width_approx_digits / 1.3); ! if (playlist_get_length_nolock() <= 0) ! padding = 3; ! // For italic or oblique fonts we add another half of the approximate width if (has_slant) padding += width_approx_digits_half; --- 617,625 ---- if (cfg.show_numbers_in_pl) { padding = ! (gint_count_digits(playlist_get_length_nolock()) * ! width_approx_digits) + (width_approx_digits / 1.3); ! /* For italic or oblique fonts we add another half of the ! * approximate width */ if (has_slant) padding += width_approx_digits_half; *************** *** 649,667 **** pl->pl_widget.y, pl->pl_widget.x + padding, ! (pl->pl_widget.y + pl->pl_widget.height - 1) ! ); ! } - - /* guint xpos = pl->pl_widget.x + width - (width_approx_digits*max_time_len)+width_colon_third-8-width_approx_digits_half; - gdk_draw_line(obj, gc, - xpos, - pl->pl_widget.y, - xpos, - (pl->pl_widget.y + pl->pl_widget.height-1) - ); - */ - PLAYLIST_UNLOCK(); } --- 629,635 ---- pl->pl_widget.y, pl->pl_widget.x + padding, ! (pl->pl_widget.y + pl->pl_widget.height - 1)); } PLAYLIST_UNLOCK(); } *************** *** 698,702 **** } ! void playlist_list_set_font(char *font) { --- 666,670 ---- } ! void playlist_list_set_font(const gchar * font) { *************** *** 741,743 **** --- 709,712 ---- || g_strstr_len(font_lower, strlen(font_lower), "italic"); + g_free(font_lower); } Index: playlist_list.h =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/playlist_list.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** playlist_list.h 24 Dec 2003 14:03:17 -0000 1.2 --- playlist_list.h 26 Dec 2003 03:33:06 -0000 1.3 *************** *** 21,28 **** #define PLAYLIST_LIST_H typedef struct { Widget pl_widget; ! gint pl_fheight, pl_prev_selected, pl_prev_min, pl_prev_max; ! gint pl_first, pl_num_visible, pl_drag_pos; gboolean pl_dragging, pl_auto_drag_down, pl_auto_drag_up; gint pl_auto_drag_up_tag, pl_auto_drag_down_tag; --- 21,35 ---- #define PLAYLIST_LIST_H + #include <glib.h> + #include <gtk/gtk.h> + #include <gdk/gdk.h> + + #include "widget.h" + + #define PLAYLIST_LIST(x) ((PlayList_List*)(x)) typedef struct { Widget pl_widget; ! gint pl_first, pl_fheight, pl_prev_selected, pl_prev_min, pl_prev_max; ! gint pl_num_visible, pl_drag_pos; gboolean pl_dragging, pl_auto_drag_down, pl_auto_drag_up; gint pl_auto_drag_up_tag, pl_auto_drag_down_tag; *************** *** 36,41 **** void playlist_list_move_up(PlayList_List * pl); void playlist_list_move_down(PlayList_List * pl); ! int playlist_list_get_playlist_position(PlayList_List * pl, int x, int y); ! void playlist_list_set_font(char *font); #endif --- 43,49 ---- void playlist_list_move_up(PlayList_List * pl); void playlist_list_move_down(PlayList_List * pl); ! int playlist_list_get_playlist_position(PlayList_List * pl, gint x, ! gint y); ! void playlist_list_set_font(const gchar * font); #endif Index: pluginenum.c =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/pluginenum.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** pluginenum.c 24 Dec 2003 14:03:17 -0000 1.13 --- pluginenum.c 26 Dec 2003 03:33:06 -0000 1.14 *************** *** 155,159 **** p->add_vis_pcm = input_add_vis_pcm; p->set_info = playlist_set_info; ! p->set_info_text = (void (*)(char *)) input_set_info_text; ip_data->input_list = g_list_prepend(ip_data->input_list, p); --- 155,159 ---- p->add_vis_pcm = input_add_vis_pcm; p->set_info = playlist_set_info; ! p->set_info_text = (void (*)(gchar *)) input_set_info_text; ip_data->input_list = g_list_prepend(ip_data->input_list, p); Index: skinwin.c =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/skinwin.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** skinwin.c 24 Dec 2003 14:03:17 -0000 1.9 --- skinwin.c 26 Dec 2003 03:33:06 -0000 1.10 *************** *** 161,165 **** } ! static void scan_skindir(char *path) { GDir *dir2; --- 161,165 ---- } ! static void scan_skindir(const gchar * path) { GDir *dir2; Index: util.c =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/util.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** util.c 24 Dec 2003 14:03:17 -0000 1.10 --- util.c 26 Dec 2003 03:33:06 -0000 1.11 *************** *** 1137,1140 **** --- 1137,1152 ---- } + /* counts number of digits in a gint */ + guint gint_count_digits(gint n) + { + guint count = 0; + + do { + count++; + n /= 10; + } while (n > 0); + + return count; + } #if defined(USE_DMALLOC) Index: util.h =================================================================== RCS file: /cvsroot/beepmp/bmp/beep/util.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** util.h 24 Dec 2003 14:03:17 -0000 1.6 --- util.h 26 Dec 2003 03:33:06 -0000 1.7 *************** *** 60,63 **** --- 60,65 ---- gchar *archive_basename(const gchar * str); + guint gint_count_digits(gint n); + #if ENABLE_NLS gchar *util_menu_translate(const gchar * path, gpointer func_data); |