From 0f95bf371655ed2c743d024bc2dfab51402f7d3a Mon Sep 17 00:00:00 2001 From: Viktor Semykin Date: Thu, 24 Dec 2009 03:24:29 +0200 Subject: playlist header context menu implementation --- plugins/gtkui/callbacks.c | 71 +++++++++++++-- plugins/gtkui/callbacks.h | 8 ++ plugins/gtkui/deadbeef.glade | 208 +++++++++++++++++++++++++++++++++++++++++++ plugins/gtkui/gtkplaylist.c | 25 +++--- plugins/gtkui/gtkplaylist.h | 3 +- plugins/gtkui/interface.c | 95 ++++++++++++++++++++ plugins/gtkui/interface.h | 1 + 7 files changed, 391 insertions(+), 20 deletions(-) (limited to 'plugins') diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index 4150e3fc..ebc13484 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -44,6 +44,8 @@ #define VSELECT(it, sel) {deadbeef->pl_set_selected(it,sel);gtk_pl_redraw_item_everywhere (it);} #define PL_NEXT(it, iter) (deadbeef->pl_get_next(it, iter)) +GtkWidget *formatwin = NULL; +gtkplaylist_t *last_playlist; extern GtkWidget *mainwin; extern gtkplaylist_t main_playlist; extern gtkplaylist_t search_playlist; @@ -1703,12 +1705,33 @@ on_prefwin_delete_event (GtkWidget *widget, return FALSE; } +void +pl_add_column (const char *title, int width, int id, const char *format, int align_right) +{ + gtkplaylist_t *ps = last_playlist; + + gtkpl_column_append (ps, gtkpl_column_alloc (title, width, id, format, align_right)); + + gtkpl_header_draw (ps); + gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height); + + gtkpl_draw_playlist (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height); + gtkpl_expose (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height); + + gtkpl_column_rewrite_config (ps); +} void on_artist_activate (GtkMenuItem *menuitem, gpointer user_data) { - + GtkWidget *parent = GTK_WIDGET (menuitem); + do + { + parent = gtk_widget_get_parent (parent); + printf ("parent: %x\n", parent); + } while (parent); + pl_add_column ("Artist", 100, DB_COLUMN_ARTIST, NULL, 0); } @@ -1716,7 +1739,7 @@ void on_album_activate (GtkMenuItem *menuitem, gpointer user_data) { - + pl_add_column ("Album", 100, DB_COLUMN_ALBUM, NULL, 0); } @@ -1724,7 +1747,7 @@ void on_tracknum_activate (GtkMenuItem *menuitem, gpointer user_data) { - + pl_add_column ("Track №", 50, DB_COLUMN_TRACK, NULL, 0); } @@ -1732,7 +1755,7 @@ void on_duration_activate (GtkMenuItem *menuitem, gpointer user_data) { - + pl_add_column ("Duration", 50, DB_COLUMN_DURATION, NULL, 0); } @@ -1740,7 +1763,7 @@ void on_playing_activate (GtkMenuItem *menuitem, gpointer user_data) { - + pl_add_column ("Playing", 50, DB_COLUMN_PLAYING, NULL, 0); } @@ -1748,7 +1771,7 @@ void on_title_activate (GtkMenuItem *menuitem, gpointer user_data) { - + pl_add_column ("Title", 150, DB_COLUMN_TITLE, NULL, 0); } @@ -1756,7 +1779,9 @@ void on_custom_activate (GtkMenuItem *menuitem, gpointer user_data) { - + if (!formatwin) + formatwin = create_inputformat (); + gtk_widget_show (formatwin); } @@ -1764,7 +1789,20 @@ void on_remove_column_activate (GtkMenuItem *menuitem, gpointer user_data) { + gtkplaylist_t *ps = last_playlist; + + if (!ps->active_column) + return; + + gtkpl_column_remove (ps, ps->active_column); + + gtkpl_header_draw (ps); + gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height); + + gtkpl_draw_playlist (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height); + gtkpl_expose (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height); + gtkpl_column_rewrite_config (ps); } @@ -2212,3 +2250,22 @@ on_properties1_activate (GtkMenuItem *menuitem, } + +void +on_format_cancel_clicked (GtkButton *button, + gpointer user_data) +{ + gtk_widget_hide (formatwin); +} + + +void +on_format_ok_clicked (GtkButton *button, + gpointer user_data) +{ + const gchar *title = gtk_entry_get_text (GTK_ENTRY (lookup_widget (formatwin, "titleentry"))); + const gchar *format = gtk_entry_get_text (GTK_ENTRY (lookup_widget (formatwin, "formatentry"))); + pl_add_column (title, 100, -1, format, 0); + gtk_widget_hide (formatwin); +} + diff --git a/plugins/gtkui/callbacks.h b/plugins/gtkui/callbacks.h index f9c5c8a6..1f5c71ac 100644 --- a/plugins/gtkui/callbacks.h +++ b/plugins/gtkui/callbacks.h @@ -747,3 +747,11 @@ gboolean on_prefwin_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data); + +void +on_format_cancel_clicked (GtkButton *button, + gpointer user_data); + +void +on_format_ok_clicked (GtkButton *button, + gpointer user_data); diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index 34076262..2746872a 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -2602,4 +2602,212 @@ SOCKS5_HOSTNAME + + True + Column Format + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER_ALWAYS + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + + + + True + False + 0 + + + + True + False + 0 + + + + True + Title: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + True + True + 0 + Custom + True + + False + + + 0 + True + True + + + + + 0 + False + False + + + + + + True + False + 0 + + + + True + Format: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + + False + + + 0 + True + True + + + + + 0 + False + False + + + + + + True + Format fields: +%a - artist +%t - title +%b - album +%n - track +%l - duration + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + True + True + + + + + + True + GTK_BUTTONBOX_DEFAULT_STYLE + 0 + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + + + + + + 0 + False + False + + + + + + diff --git a/plugins/gtkui/gtkplaylist.c b/plugins/gtkui/gtkplaylist.c index 272246d6..0ae46f9a 100644 --- a/plugins/gtkui/gtkplaylist.c +++ b/plugins/gtkui/gtkplaylist.c @@ -54,8 +54,8 @@ extern DB_functions_t *deadbeef; // defined in gtkui.c -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(fmt,...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) // debug function for gdk_draw_drawable static inline void @@ -69,6 +69,8 @@ extern GtkWidget *mainwin; extern GtkStatusIcon *trayicon; extern gtkplaylist_t main_playlist; +extern gtkplaylist_t *last_playlist; + static GtkWidget *theme_treeview; // orange on dark color scheme @@ -1476,18 +1478,18 @@ on_header_motion_notify_event (GtkWidget *widget, return FALSE; } -int +gtkpl_column_t* gtkpl_get_column_for_click (gtkplaylist_t *pl, int click_x) { int x = -pl->hscrollpos; - int i = 0; gtkpl_column_t *c; - for (c = pl->columns; c; c = c->next, i++) { + for (c = pl->columns; c; c = c->next) { int w = c->width; if (click_x >= x && click_x < x + w) { - return i; + return c; } + x += w; } - return -1; + return NULL; } gboolean @@ -1525,8 +1527,10 @@ on_header_button_press_event (GtkWidget *widget, } } else if (event->button == 3) { + ps->active_column = gtkpl_get_column_for_click (ps, event->x); GtkWidget *menu = create_headermenu (); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, widget, 0, gtk_get_current_event_time()); + last_playlist = ps; + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, widget, 3, gtk_get_current_event_time()); } prev_header_x = -1; last_header_motion_ev = -1; @@ -1792,16 +1796,13 @@ gtkpl_column_update_config (gtkplaylist_t *pl, gtkpl_column_t *c, int idx) { void gtkpl_column_rewrite_config (gtkplaylist_t *pl) { char key[128]; - char value[128]; snprintf (key, sizeof (key), "%s.column.", pl->title); deadbeef->conf_remove_items (key); gtkpl_column_t *c; int i = 0; for (c = pl->columns; c; c = c->next, i++) { - snprintf (key, sizeof (key), "%s.column.%d", pl->title, i); - snprintf (value, sizeof (value), "\"%s\" \"%s\" %d %d %d", c->title, c->format ? c->format : "", c->id, c->width, c->align_right); - deadbeef->conf_set_str (key, value); + gtkpl_column_update_config (pl, c, i); } } diff --git a/plugins/gtkui/gtkplaylist.h b/plugins/gtkui/gtkplaylist.h index 07c1dd94..ebf27f99 100644 --- a/plugins/gtkui/gtkplaylist.h +++ b/plugins/gtkui/gtkplaylist.h @@ -84,6 +84,7 @@ typedef struct { int nvisiblerows; int nvisiblefullrows; gtkpl_column_t *columns; + gtkpl_column_t *active_column; } gtkplaylist_t; extern gtkplaylist_t main_playlist; @@ -254,7 +255,7 @@ gtk_pl_redraw_item_everywhere (DB_playItem_t *it); void gtkpl_set_cursor (int iter, int cursor); -int +gtkpl_column_t* gtkpl_get_column_for_click (gtkplaylist_t *pl, int click_x); #endif // __GTKPLAYLIST_H diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index fefd4c10..d93c556a 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -1809,3 +1809,98 @@ create_addlocation (void) return addlocation; } +GtkWidget* +create_inputformat (void) +{ + GtkWidget *inputformat; + GtkWidget *vbox8; + GtkWidget *hbox10; + GtkWidget *label26; + GtkWidget *titleentry; + GtkWidget *hbox9; + GtkWidget *format; + GtkWidget *formatentry; + GtkWidget *label25; + GtkWidget *hbuttonbox1; + GtkWidget *button2; + GtkWidget *button3; + + inputformat = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (inputformat), "Column Format"); + gtk_window_set_position (GTK_WINDOW (inputformat), GTK_WIN_POS_CENTER_ALWAYS); + gtk_window_set_modal (GTK_WINDOW (inputformat), TRUE); + gtk_window_set_type_hint (GTK_WINDOW (inputformat), GDK_WINDOW_TYPE_HINT_DIALOG); + + vbox8 = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox8); + gtk_container_add (GTK_CONTAINER (inputformat), vbox8); + + hbox10 = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox10); + gtk_box_pack_start (GTK_BOX (vbox8), hbox10, FALSE, FALSE, 0); + + label26 = gtk_label_new ("Title:"); + gtk_widget_show (label26); + gtk_box_pack_start (GTK_BOX (hbox10), label26, FALSE, FALSE, 0); + + titleentry = gtk_entry_new (); + gtk_widget_show (titleentry); + gtk_box_pack_start (GTK_BOX (hbox10), titleentry, TRUE, TRUE, 0); + gtk_entry_set_text (GTK_ENTRY (titleentry), "Custom"); + gtk_entry_set_invisible_char (GTK_ENTRY (titleentry), 9679); + + hbox9 = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox9); + gtk_box_pack_start (GTK_BOX (vbox8), hbox9, FALSE, FALSE, 0); + + format = gtk_label_new ("Format:"); + gtk_widget_show (format); + gtk_box_pack_start (GTK_BOX (hbox9), format, FALSE, FALSE, 0); + + formatentry = gtk_entry_new (); + gtk_widget_show (formatentry); + gtk_box_pack_start (GTK_BOX (hbox9), formatentry, TRUE, TRUE, 0); + gtk_entry_set_invisible_char (GTK_ENTRY (formatentry), 9679); + + label25 = gtk_label_new ("Format fields:\n%a - artist\n%t - title\n%b - album\n%n - track\n%l - duration"); + gtk_widget_show (label25); + gtk_box_pack_start (GTK_BOX (vbox8), label25, TRUE, TRUE, 0); + + hbuttonbox1 = gtk_hbutton_box_new (); + gtk_widget_show (hbuttonbox1); + gtk_box_pack_start (GTK_BOX (vbox8), hbuttonbox1, FALSE, FALSE, 0); + + button2 = gtk_button_new_from_stock ("gtk-cancel"); + gtk_widget_show (button2); + gtk_container_add (GTK_CONTAINER (hbuttonbox1), button2); + GTK_WIDGET_SET_FLAGS (button2, GTK_CAN_DEFAULT); + + button3 = gtk_button_new_from_stock ("gtk-ok"); + gtk_widget_show (button3); + gtk_container_add (GTK_CONTAINER (hbuttonbox1), button3); + GTK_WIDGET_SET_FLAGS (button3, GTK_CAN_DEFAULT); + + g_signal_connect ((gpointer) button2, "clicked", + G_CALLBACK (on_format_cancel_clicked), + NULL); + g_signal_connect ((gpointer) button3, "clicked", + G_CALLBACK (on_format_ok_clicked), + NULL); + + /* Store pointers to all widgets, for use by lookup_widget(). */ + GLADE_HOOKUP_OBJECT_NO_REF (inputformat, inputformat, "inputformat"); + GLADE_HOOKUP_OBJECT (inputformat, vbox8, "vbox8"); + GLADE_HOOKUP_OBJECT (inputformat, hbox10, "hbox10"); + GLADE_HOOKUP_OBJECT (inputformat, label26, "label26"); + GLADE_HOOKUP_OBJECT (inputformat, titleentry, "titleentry"); + GLADE_HOOKUP_OBJECT (inputformat, hbox9, "hbox9"); + GLADE_HOOKUP_OBJECT (inputformat, format, "format"); + GLADE_HOOKUP_OBJECT (inputformat, formatentry, "formatentry"); + GLADE_HOOKUP_OBJECT (inputformat, label25, "label25"); + GLADE_HOOKUP_OBJECT (inputformat, hbuttonbox1, "hbuttonbox1"); + GLADE_HOOKUP_OBJECT (inputformat, button2, "button2"); + GLADE_HOOKUP_OBJECT (inputformat, button3, "button3"); + + return inputformat; +} + diff --git a/plugins/gtkui/interface.h b/plugins/gtkui/interface.h index f9b470ff..431e5e12 100644 --- a/plugins/gtkui/interface.h +++ b/plugins/gtkui/interface.h @@ -10,3 +10,4 @@ GtkWidget* create_helpwindow (void); GtkWidget* create_prefwin (void); GtkWidget* create_headermenu (void); GtkWidget* create_addlocation (void); +GtkWidget* create_inputformat (void); -- cgit v1.2.3