[gnome-music/playlists] fix list view and add list renderers
- From: Eslam Mostafa <cseslam src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/playlists] fix list view and add list renderers
- Date: Sun, 16 Jun 2013 22:41:53 +0000 (UTC)
commit 11f08e9afd21e64e96f1d2e2fa1819eba22a578f
Author: Eslam Mostafa <me eslammostafa com>
Date: Mon Jun 17 00:41:36 2013 +0200
fix list view and add list renderers
src/view.js | 12 ++------
src/widgets.js | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 85 insertions(+), 16 deletions(-)
---
diff --git a/src/view.js b/src/view.js
index 925a499..39c28f3 100644
--- a/src/view.js
+++ b/src/view.js
@@ -497,22 +497,16 @@ const Playlists = new Lang.Class({
_init: function(header_bar, player) {
this.parent("Playlists", header_bar);
this._playlists = {};
+ this.player = player;
//this.countQuery = Query.playlist_count;
-/* this._playlistSongsWidget = new Gtk.Frame({
- shadow_type: Gtk.ShadowType.NONE
- });
- this.playlistSongs = new Widgets.PlaylistSongs(playlist, this.player);
- this._playlistSongsWidget.add(this.playlistSongs);
-*/
this.view.set_view_type(Gd.MainViewType.LIST);
this.view.set_hexpand(false);
-// this._playlistSongsWidget.set_hexpand(true);
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/music/PlaylistSongs.ui');
this._playlistSongsWidget = builder.get_object('frame');
let container = builder.get_object('container');
this._playlistLabel = builder.get_object("playlist");
- this._songsListWidget = new Widgets.SongsList();
+ this._songsListWidget = new Widgets.SongsList(this.player);
container.pack_end(this._songsListWidget, true, true, 0);
this.view.get_style_context().add_class("artist-panel");
this.view.get_generic_view().get_selection().set_mode(Gtk.SelectionMode.SINGLE);
@@ -558,7 +552,7 @@ const Playlists = new Lang.Class({
let playlist = this._model.get_value (iter, 0);
this._playlistLabel.set_text(playlist);
let url = this._playlists[playlist.toLowerCase()]['url'];
- this._songsListWidget.update(url);
+ this._songsListWidget.update(this._playlists[playlist.toLowerCase()]);
},
_addItem: function (source, param, item) {
diff --git a/src/widgets.js b/src/widgets.js
index 9cd4295..35ea51c 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -326,8 +326,9 @@ const SongsList = new Lang.Class({
Name: "SongsList",
Extends: Gd.MainView,
- _init: function(){
+ _init: function(player){
this.parent();
+ this.player = player;
this.playlist = null;
this._model = Gtk.ListStore.new([
GObject.TYPE_STRING,
@@ -341,21 +342,31 @@ const SongsList = new Lang.Class({
GObject.TYPE_BOOLEAN,
GObject.TYPE_BOOLEAN
]);
- this.set_view_type(Gd.MainViewType.ICON);
+ this.set_view_type(Gd.MainViewType.LIST);
+ this.get_generic_view().get_style_context().add_class("songs-list")
this.set_model(this._model);
+ this._addListRenderers();
this.show_all();
+ this.connect('item-activated', Lang.bind(this, this._onItemActivated));
},
- update: function(playlistUrl) {
- this.playlist = playlistUrl;
+ update: function(playlist) {
+ this.playlist = playlist;
this._model.clear();
this._populate();
this.show_all();
},
+ _onItemActivated: function (widget, id, path) {
+ var iter = this._model.get_iter(path)[1]
+ if (this._model.get_value(iter, 7) != errorIconName) {
+ this.player.setPlaylist(this.playlist, null, this._model, iter, 5);
+ this.player.setPlaying(true);
+ }
+ },
+
_addItem: function(source, param, item) {
this._offset += 1;
- log("addItem Song: "+item.get_title());
if (item == null)
return;
var iter = this._model.append();
@@ -365,12 +376,76 @@ const SongsList = new Lang.Class({
if ((item.get_title() == null) && (item.get_url() != null)) {
song.set_title (extractFileName(item.get_url()));
}
- this._model.set(iter, [0, 1, 2, 3], [song, song, song, song]);
+ this._model.set(iter, [0, 1, 2, 3, 5], [song, song, song, song, item]);
+ try {
+ if(item.get_url())
+ this.player.discoverer.discover_uri(item.get_url());
+ this._model.set(iter, [7, 8, 9], [nowPlayingIconName, false, false]);
+ } catch (err) {
+ log(err.message);
+ log("failed to discover url " + item.get_url());
+ this._model.set(iter, [7, 8, 9], [errorIconName, false, true]);
+ }
+ },
+
+ _addListRenderers: function() {
+ let listWidget = this.get_generic_view();
+ let cols = listWidget.get_columns();
+ let cells = cols[0].get_cells();
+ cells[2].visible = false;
+ let nowPlayingSymbolRenderer = new Gtk.CellRendererPixbuf();
+ var columnNowPlaying = new Gtk.TreeViewColumn();
+ nowPlayingSymbolRenderer.xalign = 1.0;
+ columnNowPlaying.pack_start(nowPlayingSymbolRenderer, false);
+ columnNowPlaying.fixed_width = 24;
+ columnNowPlaying.add_attribute(nowPlayingSymbolRenderer, "visible", 9);
+ columnNowPlaying.add_attribute(nowPlayingSymbolRenderer, "icon_name", 7);
+ listWidget.insert_column(columnNowPlaying, 0);
+
+ let titleRenderer = new Gtk.CellRendererText({ xpad: 0 });
+ listWidget.add_renderer(titleRenderer,Lang.bind(this,function (col,cell,model,iter) {
+ let item = model.get_value(iter,5);
+ titleRenderer.xalign = 0.0;
+ titleRenderer.yalign = 0.5;
+ titleRenderer.height = 48;
+ titleRenderer.ellipsize = Pango.EllipsizeMode.END;
+ titleRenderer.text = item.get_title();
+ }))
+ let starRenderer = new Gtk.CellRendererPixbuf({xpad: 32});
+ listWidget.add_renderer(starRenderer,Lang.bind(this,function (col,cell,model,iter) {
+ let showstar = model.get_value(iter,8);
+ if(showstar){
+ starRenderer.icon_name = starIconName;
+
+ }
+ else
+ starRenderer.pixbuf = null;
+ }))
+
+ let durationRenderer =
+ new Gd.StyledTextRenderer({ xpad: 32 });
+ durationRenderer.add_class('dim-label');
+ listWidget.add_renderer(durationRenderer, Lang.bind(this,
+ function(col, cell, model, iter) {
+ let item = model.get_value(iter, 5);
+ if (item) {
+ 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.xalign = 1.0;
+ durationRenderer.text = time;
+ }
+ }));
},
_populate: function() {
if(grilo.filesystem != null) {
- grilo.getPlaylistSongs(this.playlist, Lang.bind(this, this._addItem, null));
+ grilo.getPlaylistSongs(this.playlist['url'], Lang.bind(this, this._addItem, null));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]