changeset 4297:40a991213507

check if playlistwin_list is UiSkinnedPlaylist before accessing it contents
author Tomasz Mon <desowin@gmail.com>
date Fri, 22 Feb 2008 22:18:20 +0100
parents f0b9b3c82e01
children b9b25160647b
files src/audacious/playlist.c src/audacious/ui_playlist.c src/audacious/ui_playlist.h src/audacious/ui_preferences.c
diffstat 4 files changed, 39 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playlist.c	Fri Feb 22 18:08:35 2008 +0200
+++ b/src/audacious/playlist.c	Fri Feb 22 22:18:20 2008 +0100
@@ -77,7 +77,6 @@
 
 #include "playlist_evmessages.h"
 #include "playlist_evlisteners.h"
-#include "ui_skinned_playlist.h"
 
 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b);
 typedef void (*PlaylistSaveFunc) (FILE * file);
@@ -1190,7 +1189,7 @@
         return;
 
     PLAYLIST_LOCK(playlist);
-    if (!playlist->position || !playlistwin_list) {
+    if (!playlist->position) {
         PLAYLIST_UNLOCK(playlist);
         return;
     }
@@ -1202,9 +1201,8 @@
         return;
     }
 
-    bottom = MAX(0, playlist_get_length(playlist) -
-                 UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible);
-    row = CLAMP(pos - UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible / 2, 0, bottom);
+    bottom = MAX(0, playlist_get_length(playlist) - playlistwin_list_get_visible_count());
+    row = CLAMP(pos - playlistwin_list_get_visible_count() / 2, 0, bottom);
     PLAYLIST_UNLOCK(playlist);
     playlistwin_set_toprow(row);
     g_cond_signal(cond_scan);
--- a/src/audacious/ui_playlist.c	Fri Feb 22 18:08:35 2008 +0200
+++ b/src/audacious/ui_playlist.c	Fri Feb 22 22:18:20 2008 +0100
@@ -70,7 +70,7 @@
 
 static GMutex *resize_mutex = NULL;
 
-GtkWidget *playlistwin_list = NULL;
+static GtkWidget *playlistwin_list = NULL;
 GtkWidget *playlistwin_shade, *playlistwin_close;
 
 static gboolean playlistwin_hint_flag = FALSE;
@@ -213,6 +213,8 @@
 gboolean
 playlistwin_item_visible(gint index)
 {
+    g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), FALSE);
+
     if (index >= UI_SKINNED_PLAYLIST(playlistwin_list)->first &&
         index < (UI_SKINNED_PLAYLIST(playlistwin_list)->first + UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible) ) {
         return TRUE;
@@ -223,31 +225,31 @@
 gint
 playlistwin_list_get_visible_count(void)
 {
-    if (playlistwin_list)
+    g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), -1);
+
     return UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible;
-    return (-1);
 }
 
 gint
 playlistwin_list_get_first(void)
 {
-    if (playlistwin_list)
+    g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), -1);
+
     return UI_SKINNED_PLAYLIST(playlistwin_list)->first;
-    return (-1);
 }
 
 gint
 playlistwin_get_toprow(void)
 {
-    if (playlistwin_list)
-        return (UI_SKINNED_PLAYLIST(playlistwin_list)->first);
-    return (-1);
+    g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), -1);
+
+    return (UI_SKINNED_PLAYLIST(playlistwin_list)->first);
 }
 
 void
 playlistwin_set_toprow(gint toprow)
 {
-    if (playlistwin_list)
+    if (UI_SKINNED_IS_PLAYLIST(playlistwin_list))
         UI_SKINNED_PLAYLIST(playlistwin_list)->first = toprow;
     playlistwin_update_list(playlist_get_active());
 }
@@ -382,7 +384,8 @@
 void
 playlistwin_scroll(gint num)
 {
-    UI_SKINNED_PLAYLIST(playlistwin_list)->first += num;
+    if (UI_SKINNED_IS_PLAYLIST(playlistwin_list))
+        UI_SKINNED_PLAYLIST(playlistwin_list)->first += num;
     playlistwin_update_list(playlist_get_active());
 }
 
@@ -404,9 +407,11 @@
     Playlist *playlist = playlist_get_active();
 
     playlist_select_all(playlist, TRUE);
-    UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = 0;
-    UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = 0;
-    UI_SKINNED_PLAYLIST(playlistwin_list)->prev_max = playlist_get_length(playlist) - 1;
+    if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) {
+        UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = 0;
+        UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = 0;
+        UI_SKINNED_PLAYLIST(playlistwin_list)->prev_max = playlist_get_length(playlist) - 1;
+    }
     playlistwin_update_list(playlist);
 }
 
@@ -414,8 +419,10 @@
 playlistwin_select_none(void)
 {
     playlist_select_all(playlist_get_active(), FALSE);
-    UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = -1;
-    UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = -1;
+    if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) {
+        UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = -1;
+        UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = -1;
+    }
     playlistwin_update_list(playlist_get_active());
 }
 
@@ -579,8 +586,10 @@
 playlistwin_inverse_selection(void)
 {
     playlist_select_invert_all(playlist_get_active());
-    UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = -1;
-    UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = -1;
+    if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) {
+        UI_SKINNED_PLAYLIST(playlistwin_list)->prev_selected = -1;
+        UI_SKINNED_PLAYLIST(playlistwin_list)->prev_min = -1;
+    }
     playlistwin_update_list(playlist_get_active());
 }
 
@@ -1141,6 +1150,7 @@
 static gboolean
 playlistwin_keypress(GtkWidget * w, GdkEventKey * event, gpointer data)
 {
+    g_return_val_if_fail(UI_SKINNED_IS_PLAYLIST(playlistwin_list), FALSE);
     Playlist *playlist = playlist_get_active();
 
     guint keyval;
@@ -1297,9 +1307,11 @@
                         GtkSelectionData * selection_data,
                         guint info, guint time, gpointer user_data)
 {
-    UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion = TRUE;
-    UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion_x = x;
-    UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion_y = y;
+    if (UI_SKINNED_IS_PLAYLIST(playlistwin_list)) {
+        UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion = TRUE;
+        UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion_x = x;
+        UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion_y = y;
+    }
     playlistwin_update_list(playlist_get_active());
     playlistwin_hint_flag = TRUE;
 }
@@ -1308,7 +1320,8 @@
 playlistwin_drag_end(GtkWidget * widget,
                      GdkDragContext * context, gpointer user_data)
 {
-    UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion = FALSE;
+    if (UI_SKINNED_IS_PLAYLIST(playlistwin_list))
+        UI_SKINNED_PLAYLIST(playlistwin_list)->drag_motion = FALSE;
     playlistwin_hint_flag = FALSE;
     playlistwin_update_list(playlist_get_active());
 }
@@ -1330,7 +1343,8 @@
         g_message("Received no DND data!");
         return;
     }
-    if (x < playlistwin_get_width() - 20 || y < cfg.playlist_height - 38) {
+    if (UI_SKINNED_IS_PLAYLIST(playlistwin_list) &&
+        (x < playlistwin_get_width() - 20 || y < cfg.playlist_height - 38)) {
         pos = y / UI_SKINNED_PLAYLIST(playlistwin_list)->fheight + UI_SKINNED_PLAYLIST(playlistwin_list)->first;
 
         pos = MIN(pos, playlist_get_length(playlist));
--- a/src/audacious/ui_playlist.h	Fri Feb 22 18:08:35 2008 +0200
+++ b/src/audacious/ui_playlist.h	Fri Feb 22 22:18:20 2008 +0100
@@ -74,7 +74,6 @@
 gint playlistwin_list_get_first(void);
 
 extern GtkWidget *playlistwin;
-extern GtkWidget *playlistwin_list;
 
 extern gboolean playlistwin_focus;
 
--- a/src/audacious/ui_preferences.c	Fri Feb 22 18:08:35 2008 +0200
+++ b/src/audacious/ui_preferences.c	Fri Feb 22 22:18:20 2008 +0100
@@ -676,14 +676,12 @@
     ui_skinned_playlist_set_font(cfg.playlist_font);
     playlistwin_set_sinfo_font(cfg.playlist_font);  /* propagate font setting to playlistwin_sinfo */
     playlistwin_update_list(playlist_get_active());
-    gtk_widget_queue_draw(playlistwin_list);
 }
 
 static void
 playlist_show_pl_separator_numbers_cb()
 {
     playlistwin_update_list(playlist_get_active());
-    gtk_widget_queue_draw(playlistwin_list);
 }
 
 /* proxy */