Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
fix #27 by allowing to add tracks to new playlist named after search …
Browse files Browse the repository at this point in the history
…query text
  • Loading branch information
scorpp committed Apr 5, 2014
1 parent 1f2b1f6 commit 8b0fd7d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
59 changes: 36 additions & 23 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern ddb_gtkui_t *gtkui_plugin;


// vkontakte.c
void vk_add_tracks_from_tree_model_to_playlist (GtkTreeModel *treemodel, GList *gtk_tree_path_list);
void vk_add_tracks_from_tree_model_to_playlist (GtkTreeModel *treemodel, GList *gtk_tree_path_list, const char *plt_name);
void vk_search_music (const gchar *query_text, GtkListStore *liststore);
void vk_get_my_music (GtkTreeModel *liststore);
void vk_ddb_set_config_var (const char *key, GValue *value);
Expand Down Expand Up @@ -59,35 +59,35 @@ save_active_property_value_to_config (GtkWidget *widget, gpointer data) {
}

static void
on_search_results_row_activate (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer user_data) {
GtkTreeModel *model;
GList *list;

model = gtk_tree_view_get_model(tree_view);
add_to_playlist (GtkTreeView *tree_view, const char *playlist) {
GtkTreeSelection *selection;
GtkTreeModel *treemodel;
GList *selected_rows;

list = g_list_alloc ();
list = g_list_append (list, path);
selection = gtk_tree_view_get_selection (tree_view);
selected_rows = gtk_tree_selection_get_selected_rows (selection, &treemodel);

vk_add_tracks_from_tree_model_to_playlist (model, list);
vk_add_tracks_from_tree_model_to_playlist (treemodel, selected_rows, playlist);

g_list_free (list);
g_list_free (selected_rows);
}

static void
on_menu_item_add_to_playlist (GtkWidget *menu_item, GtkTreeView *treeview) {
GtkTreeSelection *selection;
GtkTreeModel *treemodel;
GList *selected_rows;

selection = gtk_tree_view_get_selection (treeview);
selected_rows = gtk_tree_selection_get_selected_rows (selection, &treemodel);
on_search_results_row_activate (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer user_data) {
add_to_playlist (tree_view, NULL);
}

vk_add_tracks_from_tree_model_to_playlist (treemodel, selected_rows);
static void
on_menu_item_add_to_playlist (GtkWidget *menu_item, GtkTreeView *tree_view) {
add_to_playlist (tree_view, NULL);
}

g_list_free (selected_rows);
static void
on_menu_item_add_to_new_playlist (GtkWidget *menu_item, GtkTreeView *tree_view) {
add_to_playlist (tree_view, last_search_query);
}

static void
Expand Down Expand Up @@ -126,11 +126,24 @@ on_menu_item_copy_url (GtkWidget *menu_item, GtkTreeView *treeview) {

static void
show_popup_menu (GtkTreeView *treeview, GdkEventButton *event) {
GtkTreeSelection *selection;
GtkWidget *menu, *item;
char label_buf[200];

selection = gtk_tree_view_get_selection (treeview);
if (!gtk_tree_selection_count_selected_rows (selection)) {
// don't show menu on empty tree view
return;
}

menu = gtk_menu_new ();

item = gtk_menu_item_new_with_label ("Add to playlist");
sprintf(label_buf, "Add to playlist '%s'", last_search_query);
item = gtk_menu_item_new_with_label (label_buf);
g_signal_connect (item, "activate", G_CALLBACK (on_menu_item_add_to_new_playlist), treeview);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);

item = gtk_menu_item_new_with_label ("Add to current playlist");
g_signal_connect (item, "activate", G_CALLBACK (on_menu_item_add_to_playlist), treeview);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);

Expand Down
10 changes: 8 additions & 2 deletions vkontakte.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,16 @@ parse_audio_resp (SearchQuery *query, const gchar *resp_str) {
}

void
vk_add_tracks_from_tree_model_to_playlist (GtkTreeModel *treemodel, GList *gtk_tree_path_list) {
vk_add_tracks_from_tree_model_to_playlist (GtkTreeModel *treemodel, GList *gtk_tree_path_list, const char *plt_name) {
ddb_playlist_t *plt;

plt = deadbeef->plt_get_curr ();
if (plt_name) {
int idx = deadbeef->plt_add (deadbeef->plt_get_count (), plt_name);
deadbeef->plt_set_curr_idx (idx);
plt = deadbeef->plt_get_for_idx (idx);
} else {
plt = deadbeef->plt_get_curr ();
}

if (!deadbeef->plt_add_files_begin (plt, 0)) {
DB_playItem_t *last = deadbeef->plt_get_last (plt, 0);
Expand Down

0 comments on commit 8b0fd7d

Please sign in to comment.