diff options
author | 2009-12-24 03:24:29 +0200 | |
---|---|---|
committer | 2009-12-24 12:15:53 +0100 | |
commit | 0f95bf371655ed2c743d024bc2dfab51402f7d3a (patch) | |
tree | e26a0e56484090e2b3e936d81b08addad37dd60c /plugins/gtkui | |
parent | 5f008bc7ad0770ca920a9340839510c46c3dcd3b (diff) |
playlist header context menu implementation
Diffstat (limited to 'plugins/gtkui')
-rw-r--r-- | plugins/gtkui/callbacks.c | 71 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.h | 8 | ||||
-rw-r--r-- | plugins/gtkui/deadbeef.glade | 208 | ||||
-rw-r--r-- | plugins/gtkui/gtkplaylist.c | 25 | ||||
-rw-r--r-- | plugins/gtkui/gtkplaylist.h | 3 | ||||
-rw-r--r-- | plugins/gtkui/interface.c | 95 | ||||
-rw-r--r-- | plugins/gtkui/interface.h | 1 |
7 files changed, 391 insertions, 20 deletions
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</property> </child> </widget> +<widget class="GtkWindow" id="inputformat"> + <property name="visible">True</property> + <property name="title" translatable="yes">Column Format</property> + <property name="type">GTK_WINDOW_TOPLEVEL</property> + <property name="window_position">GTK_WIN_POS_CENTER_ALWAYS</property> + <property name="modal">True</property> + <property name="resizable">True</property> + <property name="destroy_with_parent">False</property> + <property name="decorated">True</property> + <property name="skip_taskbar_hint">False</property> + <property name="skip_pager_hint">False</property> + <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> + <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> + <property name="focus_on_map">True</property> + <property name="urgency_hint">False</property> + + <child> + <widget class="GtkVBox" id="vbox8"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">0</property> + + <child> + <widget class="GtkHBox" id="hbox10"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">0</property> + + <child> + <widget class="GtkLabel" id="label26"> + <property name="visible">True</property> + <property name="label" translatable="yes">Title:</property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkEntry" id="titleentry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes">Custom</property> + <property name="has_frame">True</property> + <property name="invisible_char">●</property> + <property name="activates_default">False</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkHBox" id="hbox9"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">0</property> + + <child> + <widget class="GtkLabel" id="format"> + <property name="visible">True</property> + <property name="label" translatable="yes">Format:</property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkEntry" id="formatentry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes"></property> + <property name="has_frame">True</property> + <property name="invisible_char">●</property> + <property name="activates_default">False</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label25"> + <property name="visible">True</property> + <property name="label" translatable="yes">Format fields: +%a - artist +%t - title +%b - album +%n - track +%l - duration</property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + + <child> + <widget class="GtkHButtonBox" id="hbuttonbox1"> + <property name="visible">True</property> + <property name="layout_style">GTK_BUTTONBOX_DEFAULT_STYLE</property> + <property name="spacing">0</property> + + <child> + <widget class="GtkButton" id="button2"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-cancel</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <signal name="clicked" handler="on_format_cancel_clicked" last_modification_time="Wed, 23 Dec 2009 21:28:57 GMT"/> + </widget> + </child> + + <child> + <widget class="GtkButton" id="button3"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-ok</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <signal name="clicked" handler="on_format_ok_clicked" last_modification_time="Wed, 23 Dec 2009 21:28:38 GMT"/> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + </child> +</widget> + </glade-interface> 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); |