From 4464c3bd6f0551861abeee42fca516b03ba84b67 Mon Sep 17 00:00:00 2001 From: QC Date: Mon, 29 Dec 2014 15:51:29 +0100 Subject: [PATCH] Fix rating menu. --- src/Tools/mpdinteraction.c | 12 +++++++++++- src/Widgets/gmpc-menu-item-rating.vala | 36 +++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/Tools/mpdinteraction.c b/src/Tools/mpdinteraction.c index d1ebfe7d..bfdaff21 100644 --- a/src/Tools/mpdinteraction.c +++ b/src/Tools/mpdinteraction.c @@ -1420,7 +1420,17 @@ void submenu_for_song(GtkWidget * menu, mpd_Song * song) gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); gtk_widget_show(item); - sitem = (GtkWidget *) gmpc_menu_item_rating_new(connection, song); + sitem = (GtkWidget *) gmpc_menu_item_rating_new(connection, song,0); + gtk_menu_shell_append(GTK_MENU_SHELL(smenu), sitem); + sitem = (GtkWidget *) gmpc_menu_item_rating_new(connection, song,2); + gtk_menu_shell_append(GTK_MENU_SHELL(smenu), sitem); + sitem = (GtkWidget *) gmpc_menu_item_rating_new(connection, song,4); + gtk_menu_shell_append(GTK_MENU_SHELL(smenu), sitem); + sitem = (GtkWidget *) gmpc_menu_item_rating_new(connection, song,6); + gtk_menu_shell_append(GTK_MENU_SHELL(smenu), sitem); + sitem = (GtkWidget *) gmpc_menu_item_rating_new(connection, song,8); + gtk_menu_shell_append(GTK_MENU_SHELL(smenu), sitem); + sitem = (GtkWidget *) gmpc_menu_item_rating_new(connection, song,10); gtk_menu_shell_append(GTK_MENU_SHELL(smenu), sitem); } diff --git a/src/Widgets/gmpc-menu-item-rating.vala b/src/Widgets/gmpc-menu-item-rating.vala index 6df10620..4add201f 100644 --- a/src/Widgets/gmpc-menu-item-rating.vala +++ b/src/Widgets/gmpc-menu-item-rating.vala @@ -33,6 +33,9 @@ public class Gmpc.MenuItem.Rating : Gtk.MenuItem private const string some_unique_name = Config.VERSION; public Gtk.VBox hbox = null; public Gmpc.Rating rating = null; + private int value = 0; + private MPD.Song song = null; + private unowned MPD.Server server = null; public int get_rating () { @@ -40,29 +43,30 @@ public class Gmpc.MenuItem.Rating : Gtk.MenuItem } bool button_press_event_callback(Gdk.EventButton event, void *userdata) { - this.rating.button_press_event_callback(this.rating.event_box, event); return true; } - bool button_release_event_callback(Gdk.EventButton event, void *userdata) - { - return true; - } - - public Rating (MPD.Server server, MPD.Song song) + public Rating (MPD.Server server, MPD.Song song, int value) { + this.server = server; + this.song = song.copy(); + this.value = value; /* this fixes vala bitching */ - GLib.Signal.connect_swapped(this, "button-press-event", - (GLib.Callback)button_press_event_callback,this); - GLib.Signal.connect_swapped(this, "button-release-event", - (GLib.Callback)button_release_event_callback,this); + this.activate.connect(() => { + MPD.Sticker.Song.set(this.server, this.song.file, "rating", (value).to_string()); + }); + - this.hbox = new Gtk.VBox(false,6); - this.rating = new Gmpc.Rating(server,song); + var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,6); + for (int i =0; i < 5; i++ ){ + var image = new Gtk.Image.from_icon_name("rating", Gtk.IconSize.MENU); + hbox.pack_start(image, false, false, 0); + if(i > (value/2.0 -0.01)) { + image.set_sensitive(false); + } + } - this.hbox.pack_start(new Gtk.Label(_("Rating:")),false,true,0); - this.hbox.pack_start(this.rating,false,true,0); - this.add(this.hbox); + this.add(hbox); this.show_all(); } } -- 2.11.4.GIT