From a99d5456e981a6116167a644f78ddda91362eec7 Mon Sep 17 00:00:00 2001 From: QC Date: Sun, 5 Oct 2014 14:04:10 +0200 Subject: [PATCH] Re-add rating. --- src/Makefile.am | 2 + src/Tools/mpdinteraction.c | 14 ++++ src/Widgets/gmpc-menu-item-rating.vala | 68 ++++++++++++++++ src/Widgets/gmpc-rating.vala | 128 +++++++++++++++++++++++++++++++ src/browsers/gmpc-metadata-browser2.vala | 9 +++ src/browsers/gmpc-nowplaying2.vala | 8 ++ 6 files changed, 229 insertions(+) create mode 100644 src/Widgets/gmpc-menu-item-rating.vala create mode 100644 src/Widgets/gmpc-rating.vala diff --git a/src/Makefile.am b/src/Makefile.am index c7296459..5001e6fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,6 +30,8 @@ PLUGIN_FILES=\ gmpc_WIDGETS_FILES=\ Widgets/gmpc-progress.vala\ Widgets/mpd-async-request.c\ + Widgets/gmpc-menu-item-rating.vala\ + Widgets/gmpc-rating.vala\ Widgets/gmpc-song-list.vala\ Widgets/gmpc-clicklabel.vala\ Widgets/playlist3-messages.c\ diff --git a/src/Tools/mpdinteraction.c b/src/Tools/mpdinteraction.c index 0e362053..d1ebfe7d 100644 --- a/src/Tools/mpdinteraction.c +++ b/src/Tools/mpdinteraction.c @@ -1410,6 +1410,20 @@ void submenu_for_song(GtkWidget * menu, mpd_Song * song) gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); gtk_widget_show(item); + + if (mpd_sticker_supported(connection) && song->file) + { + smenu = gtk_menu_new(); + + item = gtk_menu_item_new_with_label(_("Set Rating")); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), smenu); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + gtk_widget_show(item); + + sitem = (GtkWidget *) gmpc_menu_item_rating_new(connection, song); + gtk_menu_shell_append(GTK_MENU_SHELL(smenu), sitem); + } + gtk_widget_show(smenu); } diff --git a/src/Widgets/gmpc-menu-item-rating.vala b/src/Widgets/gmpc-menu-item-rating.vala new file mode 100644 index 00000000..6df10620 --- /dev/null +++ b/src/Widgets/gmpc-menu-item-rating.vala @@ -0,0 +1,68 @@ +/* Gnome Music Player Client (GMPC) + * Copyright (C) 2004-2014 Qball Cow + * Project homepage: http://gmpc.wikia.com/ + + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +using GLib; +using Config; +using Gtk; +using Gdk; +using Cairo; +using MPD; +using Gmpc; + + +private const bool use_transition_mir = Gmpc.use_transition; + +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; + + public int get_rating () + { + return 0; + } + 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) + { + /* 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.hbox = new Gtk.VBox(false,6); + this.rating = new Gmpc.Rating(server,song); + + 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.show_all(); + } +} diff --git a/src/Widgets/gmpc-rating.vala b/src/Widgets/gmpc-rating.vala new file mode 100644 index 00000000..7d43ff8c --- /dev/null +++ b/src/Widgets/gmpc-rating.vala @@ -0,0 +1,128 @@ +/* Gnome Music Player Client (GMPC) + * Copyright (C) 2004-2014 Qball Cow + * Project homepage: http://gmpc.wikia.com/ + + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +using GLib; +using Gtk; +using Gdk; +using Cairo; +using MPD; +using Gmpc; + + + +public class Gmpc.Rating : Gtk.Frame +{ + private const bool use_transition = Gmpc.use_transition; + private unowned MPD.Server server = null; + private MPD.Song song = null; + private Gtk.Image[] rat; + private Gtk.HBox box; + public Gtk.EventBox event_box; + private int rating = -1; + static int id = id+1; + + private ulong status_changed_id = 0; + + ~Rating() { + if (this.status_changed_id > 0 && GLib.SignalHandler.is_connected(gmpcconn, + this.status_changed_id)) { + GLib.SignalHandler.disconnect(gmpcconn, this.status_changed_id); + this.status_changed_id = 0; + } + + } + public bool button_press_event_callback(Gtk.Widget wid, Gdk.EventButton event) + { + if(event.type == Gdk.EventType.BUTTON_PRESS) + { + if(event.button == 1) + { + Gtk.Allocation ns; + this.event_box.get_allocation(out ns); + int width = ns.width; + int button = (int)((((event.x)/(double)width)+0.15)*10); + MPD.Sticker.Song.set(this.server, this.song.file, "rating", button.to_string()); + this.set_rating(button/2); + } + } + + return false; + } + + private void status_changed ( MPD.Server server, MPD.Status.Changed what,Gmpc.Connection conn) + { + if(((what&MPD.Status.Changed.STICKER) != 0)) + { + this.update(); + } + } + + public Rating (MPD.Server server, MPD.Song song) { + this.server = server; + this.song = song.copy(); + this.update(); + this.status_changed_id = GLib.Signal.connect_swapped(gmpcconn, "status_changed", + (GLib.Callback)status_changed, this); + } + + construct { + int i; + this.shadow_type = Gtk.ShadowType.NONE; + + this.box = new Gtk.HBox(true,6); + this.rat = new Gtk.Image[5]; + this.event_box = new Gtk.EventBox(); + this.event_box.visible_window = false; + + for(i=0;i<5;i++) { + // Copy value. + var curr_entry = i+1; + this.rat[i] = new Gtk.Image.from_icon_name("rating", Gtk.IconSize.MENU); + this.box.pack_start(this.rat[i], false, false, 0); + } + + this.event_box.add(this.box); + this.event_box.button_press_event.connect(button_press_event_callback); + this.add(this.event_box); + this.show_all(); + } + + + public void set_rating(int rating) + { + int i=0; + if(rating != this.rating) + { + for(i=0;i<5;i++) + { + this.rat[i].sensitive = i