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_PRESS
)
57 this
.event_box
.get_allocation(out ns
);
59 int button
= (int)((((event
.x
)/(double)width
)+0.15)*10);
60 MPD
.Sticker
.Song
.set(this
.server
, this
.song
.file
, "rating", button
.to_string());
61 this
.set_rating(button
/2);
68 private void status_changed ( MPD
.Server server
, MPD
.Status
.Changed what
,Gmpc
.Connection conn
)
70 if(((what
&MPD
.Status
.Changed
.STICKER
) != 0))
76 public Rating (MPD
.Server server
, MPD
.Song song
) {
78 this
.song
= song
.copy();
80 this
.status_changed_id
= GLib
.Signal
.connect_swapped(gmpcconn
, "status_changed",
81 (GLib
.Callback
)status_changed
, this
);
86 this
.shadow_type
= Gtk
.ShadowType
.NONE
;
88 this
.box
= new Gtk
.HBox(true,6);
89 this
.rat
= new Gtk
.Image
[5];
90 this
.event_box
= new Gtk
.EventBox();
91 this
.event_box
.visible_window
= false;
96 this
.rat
[i
] = new Gtk
.Image
.from_icon_name("rating", Gtk
.IconSize
.MENU
);
97 this
.box
.pack_start(this
.rat
[i
], false, false, 0);
100 this
.event_box
.add(this
.box
);
101 this
.event_box
.button_press_event
.connect(button_press_event_callback
);
102 this
.add(this
.event_box
);
107 public void set_rating(int rating
)
110 if(rating
!= this
.rating
)
114 this
.rat
[i
].sensitive
= i
<rating
;
116 this
.rating
= rating
;
121 var value
= MPD
.Sticker
.Song
.get(this
.server
,this
.song
.file
, "rating");
125 this
.set_rating(value
.to_int()/2);