[gnome-music] Replace Clickable Label with gd.mainview
- From: Seif Lotfy <seiflotfy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] Replace Clickable Label with gd.mainview
- Date: Sat, 6 Apr 2013 14:14:31 +0000 (UTC)
commit 637104752a42a64a670e5bcd4b45e96bb5684c40
Author: Seif Lotfy <seif lotfy com>
Date: Sat Apr 6 16:12:40 2013 +0200
Replace Clickable Label with gd.mainview
src/widgets.js | 154 +++++++++++++++++++++++++++++++-------------------------
1 files changed, 85 insertions(+), 69 deletions(-)
---
diff --git a/src/widgets.js b/src/widgets.js
index 2634d92..3d0ada2 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -20,8 +20,10 @@
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
+const Gd = imports.gi.Gd;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Gio = imports.gi.Gio;
+const GObject = imports.gi.GObject;
const Lang = imports.lang;
const Grl = imports.gi.Grl;
const Query = imports.query;
@@ -31,46 +33,6 @@ const grilo = Grilo.grilo;
const AlbumArtCache = imports.albumArtCache;
const albumArtCache = AlbumArtCache.AlbumArtCache.getDefault();
-const ClickableLabel = new Lang.Class({
- Name: "ClickableLabel",
- Extends: Gtk.Box,
-
- _init: function (track) {
- this.parent();
- this.track = track
- var text = track.get_title()
- var duration = track.get_duration()
- let box = new Gtk.HBox();
- let label = new Gtk.Label({ label : text });
- label.ellipsize = 2;
- label.set_alignment(0.0, 0.5)
-
- var minutes = parseInt(duration / 60);
- var seconds = duration % 60;
- var time = null
- if (seconds < 10)
- time = minutes + ":0" + seconds;
- else
- time = minutes + ":" + seconds;
- let length_label = new Gtk.Label({ label : time });
- length_label.set_alignment(1.0, 0.5)
-
- box.pack_start(label, true, true, 0);
- box.pack_end(length_label, true, true, 0);
- box.set_spacing(15)
- this.button = new Gtk.Button ();
- this.button.add(box);
- this.pack_start(this.button, true, true, 0);
- this.pack_start(new Gtk.Box (), true, true, 0);
- this.homogeneous = true;
- //this.add(box);
- this.button.set_relief(Gtk.ReliefStyle.NONE);
- this.button.set_can_focus(false);
- this.show_all();
- },
-});
-
-
const AlbumWidget = new Lang.Class({
Name: "AlbumWidget",
Extends: Gtk.EventBox,
@@ -78,9 +40,24 @@ const AlbumWidget = new Lang.Class({
_init: function (player) {
this.player = player;
this.hbox = new Gtk.HBox ();
- this.box = new Gtk.VBox();
this.scrolledWindow = new Gtk.ScrolledWindow();
- this.songsList = new Gtk.VBox();
+
+ this.model = Gtk.ListStore.new([
+ GObject.TYPE_STRING,
+ GObject.TYPE_STRING,
+ GObject.TYPE_STRING,
+ GObject.TYPE_STRING,
+ GdkPixbuf.Pixbuf,
+ GObject.TYPE_OBJECT,
+ GObject.TYPE_BOOLEAN
+ ]);
+
+ this.view = new Gd.MainView({
+ shadow_type: Gtk.ShadowType.NONE
+ });
+ this.view.set_view_type(Gd.MainViewType.LIST);
+ this.view.set_model(this.model);
+
this.cover = new Gtk.Image();
this.vbox = new Gtk.VBox();
this.title_label = new Gtk.Label({label : ""});
@@ -99,15 +76,22 @@ const AlbumWidget = new Lang.Class({
this.parent();
this.hbox.set_homogeneous(true);
- this.box.set_homogeneous (false);
- this.songsList.pack_start(new Gtk.Label(), false, false, 24)
- this.songsList.pack_end(new Gtk.Label(), true, true, 24)
this.vbox.set_homogeneous(false);
this.scrolledWindow.set_policy(
Gtk.PolicyType.NEVER,
Gtk.PolicyType.AUTOMATIC);
- this.scrolledWindow.add(this.songsList);
+ var vbox = new Gtk.VBox()
+ var hbox = new Gtk.Box()
+ hbox.homogeneous = true
+ var child_view = this.view.get_children()[0];
+ this.view.remove(child_view)
+ hbox.pack_start(child_view, true, true, 0)
+ hbox.pack_start(new Gtk.Label(), true, true, 0)
+
+ vbox.pack_start(new Gtk.Label(), false, false, 24)
+ vbox.pack_start(hbox, true, true, 0)
+ this.scrolledWindow.add(vbox);
this.infobox = new Gtk.Box()
this.infobox.homogeneous = true;
@@ -130,43 +114,75 @@ const AlbumWidget = new Lang.Class({
artistBox.pack_start (this.artist_label, false, false, 0);
this.vbox.pack_start (artistBox, false, false, 24);
- this.vbox.pack_start(this.infobox, false, false, 0)
- this.box.pack_end (this.scrolledWindow, true, true, 0);
+ this.vbox.pack_start(this.infobox, false, false, 0);
- let hbox = new Gtk.Box()
- hbox.pack_start (new Gtk.Label({label: ""}), true, true, 0)
- hbox.pack_start (this.vbox, false, false, 0)
- this.hbox.pack_start (hbox, true, true, 64);
- this.hbox.pack_start (this.box, true, true, 0);
+ let hbox = new Gtk.Box();
+ hbox.pack_start(new Gtk.Label(), true, true, 0);
+ hbox.pack_end(this.vbox, false, false, 0);
+ this.hbox.pack_start (hbox, true, true, 32);
+ this.hbox.pack_start (this.scrolledWindow, true, true, 0);
this.get_style_context ().add_class ("view");
this.get_style_context ().add_class ("content-view");
- this.add(this.hbox)
- this.show_all ()
+ this.add(this.hbox);
+ this._addListRenderers();
+ this.show_all ();
+ },
+
+ _addListRenderers: function() {
+ let listWidget = this.view.get_generic_view();
+
+ var cols = listWidget.get_columns()
+ var cells = cols[0].get_cells()
+ cells[2].visible = false
+
+ let typeRenderer =
+ new Gd.StyledTextRenderer({ xpad: 0 });
+ typeRenderer.set_property("ellipsize", 3);
+ typeRenderer.set_property("xalign", 0.0);
+ typeRenderer.set_property("expand", true);
+ listWidget.add_renderer(typeRenderer, Lang.bind(this,
+ function(col, cell, model, iter) {
+ let item = model.get_value(iter, 5);
+ typeRenderer.text = item.get_title();
+ }));
+
+ let durationRenderer =
+ new Gd.StyledTextRenderer({ xpad: 16 });
+ durationRenderer.add_class('dim-label');
+ durationRenderer.set_property("ellipsize", 3);
+ durationRenderer.set_property("xalign", 1.0);
+ durationRenderer.set_property("expand", true);
+ listWidget.add_renderer(durationRenderer, Lang.bind(this,
+ function(col, cell, model, iter) {
+ let item = model.get_value(iter, 5);
+ let duration = item.get_duration ();
+ var minutes = parseInt(duration / 60);
+ var seconds = duration % 60;
+ var time = null
+ if (seconds < 10)
+ time = minutes + ":0" + seconds;
+ else
+ time = minutes + ":" + seconds;
+ durationRenderer.text = time;
+ }));
+
},
update: function (artist, album, item) {
var pixbuf = albumArtCache.lookup (256, artist, item.get_string(Grl.METADATA_KEY_ALBUM));
let duration = 0;
- var children = this.songsList.get_children();
- for (let i in children) {
- if (i > 0 && i < children.length - 1)
- this.songsList.remove(children[i]);
- }
- this.tracks_labels = {};
+ this.model.clear()
var tracks = [];
grilo.getAlbumSongs(item.get_id(), Lang.bind(this, function (source, prefs, track) {
if (track != null) {
tracks.push(track);
duration = duration + track.get_duration();
- let clickableLabel = new ClickableLabel (track);
- this.tracks_labels[track.get_title()] = clickableLabel;
- this.songsList.pack_start(clickableLabel, false, false, 0);
- this.running_length_label_info.set_text(Math.ceil(duration/60) + " min");
- this.tracks_labels[track.get_title()].button.connect("clicked", Lang.bind(this, function () {
- this.player.setCurrentTrack(track);
- this.player.play_btn.set_active(true);
- }));
+ let iter = this.model.append();
+ this.model.set(iter,
+ [0, 1, 2, 3, 4, 5],
+ [ "", "", "", "", null, track]);
+ this.running_length_label_info.set_text((parseInt(duration/60) + 1) + " min");
}
}));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]