1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2014 Qball Cow <qball@sarine.nl>
3 * Project homepage: http://gmpc.wikia.com/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 public class Gmpc
.Rating
: Gtk
.Frame
31 private const bool use_transition
= Gmpc
.use_transition
;
32 private unowned MPD
.Server server
= null;
33 private MPD
.Song song
= null;
34 private Gtk
.Image
[] rat
;
36 public Gtk
.EventBox event_box
;
37 private int rating
= -1;
40 private ulong status_changed_id
= 0;
43 if (this
.status_changed_id
> 0 && GLib
.SignalHandler
.is_connected(gmpcconn
,
44 this
.status_changed_id
)) {
45 GLib
.SignalHandler
.disconnect(gmpcconn
, this
.status_changed_id
);
46 this
.status_changed_id
= 0;
50 public bool button_press_event_callback(Gtk
.Widget wid
, Gdk
.EventButton event
)
52 if(event
.type
== Gdk
.EventType
.BUTTON_RELEASE
)
57 this
.event_box
.get_allocation(out ns
);
59 int button
= (int)((((event
.x
)/(double)width
)+0.15)*5);
60 if(button
== rating
) { button
= 0; }
61 MPD
.Sticker
.Song
.set(this
.server
, this
.song
.file
, "rating", (button
*2).to_string());
62 this
.set_rating(button
);
69 private void status_changed ( MPD
.Server server
, MPD
.Status
.Changed what
,Gmpc
.Connection conn
)
71 if(((what
&MPD
.Status
.Changed
.STICKER
) != 0))
77 public Rating (MPD
.Server server
, MPD
.Song song
) {
79 this
.song
= song
.copy();
81 this
.status_changed_id
= GLib
.Signal
.connect_swapped(gmpcconn
, "status_changed",
82 (GLib
.Callback
)status_changed
, this
);
87 this
.shadow_type
= Gtk
.ShadowType
.NONE
;
89 this
.box
= new Gtk
.HBox(true,6);
90 this
.rat
= new Gtk
.Image
[5];
91 this
.event_box
= new Gtk
.EventBox();
92 this
.event_box
.visible_window
= false;
93 this
.event_box
.set_above_child(true);
98 this
.rat
[i
] = new Gtk
.Image
.from_icon_name("rating", Gtk
.IconSize
.MENU
);
99 this
.box
.pack_start(this
.rat
[i
], false, false, 0);
102 this
.event_box
.add(this
.box
);
103 this
.event_box
.button_release_event
.connect(button_press_event_callback
);
104 this
.add(this
.event_box
);
109 public void set_rating(int rating
)
112 if(rating
!= this
.rating
)
116 this
.rat
[i
].sensitive
= i
<rating
;
118 this
.rating
= rating
;
123 var value
= MPD
.Sticker
.Song
.get(this
.server
,this
.song
.file
, "rating");
127 this
.set_rating(value
.to_int()/2);