Skip to content

Commit

Permalink
gtkui: Use focus stored in playlist, and get rid of the messy "follow…
Browse files Browse the repository at this point in the history
… queue" business.
  • Loading branch information
jlindgren90 committed Dec 8, 2012
1 parent a425296 commit 0d4d959
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 81 deletions.
34 changes: 6 additions & 28 deletions src/gtkui/playlist_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,10 @@ gint playlist_count_selected_in_range (gint list, gint top, gint length)
return selected;
}

gint playlist_get_focus (gint list)
{
GtkWidget * tree = playlist_get_treeview (list);
g_return_val_if_fail (tree, -1);

return audgui_list_get_focus (tree);
}

void playlist_song_info (void)
{
gint list = aud_playlist_get_active ();
gint focus = playlist_get_focus (list);
gint focus = aud_playlist_get_focus (list);

if (focus < 0)
return;
Expand All @@ -73,7 +65,7 @@ void playlist_song_info (void)
void playlist_queue_toggle (void)
{
gint list = aud_playlist_get_active ();
gint focus = playlist_get_focus (list);
gint focus = aud_playlist_get_focus (list);

if (focus < 0)
return;
Expand All @@ -89,21 +81,8 @@ void playlist_queue_toggle (void)
void playlist_delete_selected (void)
{
gint list = aud_playlist_get_active ();
gint focus = playlist_get_focus (list);
focus -= playlist_count_selected_in_range (list, 0, focus);

aud_drct_pl_delete_selected (list);

if (aud_playlist_selected_count (list)) /* song changed? */
return;

if (focus == aud_playlist_entry_count (list))
focus --;
if (focus >= 0)
{
aud_playlist_entry_set_selected (list, focus, TRUE);
playlist_set_focus (list, focus);
}
aud_playlist_entry_set_selected (list, aud_playlist_get_focus (list), TRUE);
}

void playlist_copy (void)
Expand All @@ -130,18 +109,17 @@ void playlist_paste (void)
return;

gint list = aud_playlist_get_active ();
audgui_urilist_insert (list, playlist_get_focus (list), text);
audgui_urilist_insert (list, aud_playlist_get_focus (list), text);
g_free (text);
}

void playlist_shift (gint offset)
{
gint list = aud_playlist_get_active ();
gint focus = playlist_get_focus (list);
gint focus = aud_playlist_get_focus (list);

if (focus < 0 || ! aud_playlist_entry_get_selected (list, focus))
return;

focus += aud_playlist_shift (list, focus, offset);
playlist_set_focus (list, focus);
aud_playlist_shift (list, focus, offset);
}
4 changes: 0 additions & 4 deletions src/gtkui/playlist_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
GtkWidget * playlist_get_treeview (gint playlist);

gint playlist_count_selected_in_range (gint list, gint top, gint length);
gint playlist_get_focus (gint list);
void playlist_song_info (void);
void playlist_queue_toggle (void);
void playlist_delete_selected (void);
Expand All @@ -32,7 +31,4 @@ void playlist_cut (void);
void playlist_paste (void);
void playlist_shift (gint offset);

/* ui_playlist_notebook.c */
void playlist_set_focus (gint list, gint row);

#endif
58 changes: 11 additions & 47 deletions src/gtkui/ui_playlist_notebook.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
#include "ui_playlist_widget.h"
#include "playlist_util.h"

#define CURRENT_POS (-2)

static GtkWidget * notebook = NULL;
static GQueue follow_queue = G_QUEUE_INIT;
static gint highlighted = -1;

static gint switch_handler = 0;
Expand Down Expand Up @@ -274,6 +271,7 @@ void ui_playlist_notebook_create_tab(gint playlist)
{
aud_playlist_select_all (playlist, FALSE);
aud_playlist_entry_set_selected (playlist, position, TRUE);
aud_playlist_set_focus (playlist, position);
audgui_list_set_highlight (treeview, position);
audgui_list_set_focus (treeview, position);
}
Expand Down Expand Up @@ -320,32 +318,6 @@ void ui_playlist_notebook_empty (void)
gtk_notebook_remove_page ((GtkNotebook *) notebook, -- n_pages);
}

static void do_follow (void)
{
while (! g_queue_is_empty (& follow_queue))
{
gint list = aud_playlist_by_unique_id (GPOINTER_TO_INT (g_queue_pop_head
(& follow_queue)));
gint row = GPOINTER_TO_INT (g_queue_pop_head (& follow_queue));

if (list < 0)
continue;

GtkWidget * widget = playlist_get_treeview (list);

if (row == CURRENT_POS)
{
row = aud_playlist_get_position (list);
audgui_list_set_highlight (widget, row);

if (! aud_get_bool ("gtkui", "autoscroll"))
continue;
}

audgui_list_set_focus (widget, row);
}
}

static void add_remove_pages (void)
{
gint lists = aud_playlist_count ();
Expand Down Expand Up @@ -429,41 +401,34 @@ void ui_playlist_notebook_update (void * data, void * user)
if (global_level >= PLAYLIST_UPDATE_METADATA)
set_tab_label (list, get_tab_label (list));

GtkWidget * treeview = playlist_get_treeview (list);

gint at, count;
gint level = aud_playlist_updated_range (list, & at, & count);

if (level)
ui_playlist_widget_update (playlist_get_treeview (list), level, at, count);
ui_playlist_widget_update (treeview, level, at, count);

audgui_list_set_highlight (treeview, aud_playlist_get_position (list));
}

gtk_notebook_set_current_page ((GtkNotebook *) notebook, aud_playlist_get_active ());

do_follow ();
}

void playlist_set_focus (gint list, gint row)
{
g_queue_push_tail (& follow_queue, GINT_TO_POINTER
(aud_playlist_get_unique_id (list)));
g_queue_push_tail (& follow_queue, GINT_TO_POINTER (row));

if (! aud_playlist_update_pending ())
do_follow ();
}

void ui_playlist_notebook_position (void * data, void * user)
{
gint list = GPOINTER_TO_INT (data);
gint row = aud_playlist_get_position (list);

if (aud_get_bool ("gtkui", "autoscroll"))
{
aud_playlist_select_all (list, FALSE);

if (aud_playlist_get_position (list) >= 0)
aud_playlist_entry_set_selected (list, aud_playlist_get_position (list), TRUE);
aud_playlist_entry_set_selected (list, row, TRUE);
aud_playlist_set_focus (list, row);
}

playlist_set_focus (list, CURRENT_POS);
if (! aud_playlist_update_pending ())
audgui_list_set_highlight (playlist_get_treeview (list), row);
}

void ui_playlist_notebook_activate (void * data, void * user)
Expand Down Expand Up @@ -497,7 +462,6 @@ void ui_playlist_notebook_set_playing (void * data, void * user)
static void destroy_cb (void)
{
notebook = NULL;
g_queue_clear (& follow_queue);
switch_handler = 0;
reorder_handler = 0;
}
Expand Down
9 changes: 7 additions & 2 deletions src/gtkui/ui_playlist_widget.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ static void select_all (void * user, gboolean selected)
aud_playlist_select_all (((PlaylistWidgetData *) user)->list, selected);
}

static void focus_change (void * user, gint row)
{
aud_playlist_set_focus (((PlaylistWidgetData *) user)->list, row);
}

static void activate_row (void * user, gint row)
{
gint list = ((PlaylistWidgetData *) user)->list;
Expand Down Expand Up @@ -291,6 +296,7 @@ static const AudguiListCallbacks callbacks = {
.get_selected = get_selected,
.set_selected = set_selected,
.select_all = select_all,
.focus_change = focus_change,
.activate_row = activate_row,
.right_click = right_click,
.shift_rows = shift_rows,
Expand Down Expand Up @@ -438,15 +444,14 @@ void ui_playlist_widget_update (GtkWidget * widget, gint type, gint at,
else if (diff < 0)
audgui_list_delete_rows (widget, at, -diff);

audgui_list_set_highlight (widget, aud_playlist_get_position (data->list));

ui_playlist_widget_scroll (widget);
}

if (type >= PLAYLIST_UPDATE_METADATA)
audgui_list_update_rows (widget, at, count);

audgui_list_update_selection (widget, at, count);
audgui_list_set_focus (widget, aud_playlist_get_focus (data->list));
update_queue (widget, data);
}

Expand Down

0 comments on commit 0d4d959

Please sign in to comment.