[gnome-music/playlists: 1/2] apply arnels patch + implement basic desgin
- From: Eslam Mostafa <cseslam src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/playlists: 1/2] apply arnels patch + implement basic desgin
- Date: Sun, 16 Jun 2013 17:03:38 +0000 (UTC)
commit 0b400e4208d93075bcc58dc7189a18d03c445e2d
Author: Eslam Mostafa <me eslammostafa com>
Date: Sun Jun 16 18:54:25 2013 +0200
apply arnels patch + implement basic desgin
data/gnome-music.gresource.xml | 2 +
src/grilo.js | 42 ++++++++++++++++++
src/view.js | 90 ++++++++++++++++++++++++++++++++++++++
src/widgets.js | 94 ++++++++++++++++++++++++++++++++++++++-
4 files changed, 225 insertions(+), 3 deletions(-)
---
diff --git a/data/gnome-music.gresource.xml b/data/gnome-music.gresource.xml
index 6e6b91f..cd4259f 100644
--- a/data/gnome-music.gresource.xml
+++ b/data/gnome-music.gresource.xml
@@ -9,5 +9,7 @@
<file preprocess="xml-stripblanks">PlayerToolbar.ui</file>
<file preprocess="xml-stripblanks">TrackWidget.ui</file>
<file preprocess="xml-stripblanks">NoMusic.ui</file>
+ <file preprocess="xml-stripblanks">PlaylistControls.ui</file>
+ <file preprocess="xml-stripblanks">PlaylistSongs.ui</file>
</gresource>
</gresources>
diff --git a/src/grilo.js b/src/grilo.js
index e3b55fc..625bae2 100644
--- a/src/grilo.js
+++ b/src/grilo.js
@@ -18,6 +18,7 @@
*
*/
+const GLib = imports.gi.GLib;
const Grl = imports.gi.Grl;
const Lang = imports.lang;
const Signals = imports.signals;
@@ -30,12 +31,17 @@ const Grilo = new Lang.Class({
Name: 'Grilo',
_init: function() {
+ this.playlistPath = GLib.build_filenamev([GLib.get_user_data_dir(), "gnome-music", "playlists"]);
+ if (!GLib.file_test(this.playlistPath, GLib.FileTest.IS_DIR))
+ GLib.mkdir_with_parents(this.playlistPath, parseInt("0755", 8));
+
this.registry = Grl.Registry.get_default ();
this.registry.load_all_plugins();
let sources = {};
this.sources = sources;
this.tracker = null;
+ this.filesystem = this.registry.lookup_source("grl-filesystem");
this.registry.connect ("source_added",
Lang.bind(this, this._onSourceAdded));
@@ -77,6 +83,26 @@ const Grilo = new Lang.Class({
this.populateItems (Query.songs, offset, callback)
},
+ populatePlaylists: function (offset, callback, count=50) {
+ if (!GLib.file_test(this.playlistPath, GLib.FileTest.IS_DIR))
+ return;
+ var options = Grl.OperationOptions.new(null);
+ options.set_flags(Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY);
+ options.set_skip(offset);
+ options.set_count(count);
+ grilo.filesystem.get_media_from_uri(
+ GLib.filename_to_uri(this.playlistPath, null),
+ [Grl.METADATA_KEY_TITLE, Grl.METADATA_KEY_URL, Grl.METADATA_KEY_MIME],
+ options,
+ Lang.bind(this, function(source, id, media) {
+ grilo.filesystem.browse(
+ media,
+ [Grl.METADATA_KEY_TITLE, Grl.METADATA_KEY_URL, Grl.METADATA_KEY_MIME],
+ options,
+ Lang.bind(this, callback, null));
+ }));
+ },
+
populateItems: function (query, offset, callback, count=50) {
var options = Grl.OperationOptions.new(null);
options.set_flags (Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY);
@@ -100,6 +126,22 @@ const Grilo = new Lang.Class({
Lang.bind(this, callback, null));
},
+ getPlaylistSongs: function (playlist_url, callback) {
+ var options = Grl.OperationOptions.new(null);
+ options.set_flags(Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY);
+ grilo.filesystem.get_media_from_uri(
+ playlist_url,
+ [Grl.METADATA_KEY_TITLE, Grl.METADATA_KEY_URL, Grl.METADATA_KEY_MIME],
+ options,
+ Lang.bind(this, function(source, id, media) {
+ grilo.filesystem.browse(
+ media,
+ [Grl.METADATA_KEY_ID, Grl.METADATA_KEY_TITLE, Grl.METADATA_KEY_ARTIST,
Grl.METADATA_KEY_CREATION_DATE],
+ options,
+ Lang.bind(this, callback, null));
+ }));
+ },
+
_searchCallback: function search_cb () {
log ("yeah");
},
diff --git a/src/view.js b/src/view.js
index ee4a21d..925a499 100644
--- a/src/view.js
+++ b/src/view.js
@@ -496,6 +496,96 @@ const Playlists = new Lang.Class({
_init: function(header_bar, player) {
this.parent("Playlists", header_bar);
+ this._playlists = {};
+ //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();
+ 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);
+ builder.add_from_resource('/org/gnome/music/PlaylistControls.ui');
+ let controls = builder.get_object('playlistControls');
+ this._grid.attach(new Gtk.Separator(), 0, 1, 1, 1);
+ this._grid.attach(controls, 0, 2, 1, 1);
+ this._grid.attach(new Gtk.Separator({orientation: Gtk.Orientation.VERTICAL}), 1, 0, 1, 3);
+ this._grid.attach(this._playlistSongsWidget, 2, 0, 2, 2);
+ this._addListRenderers();
+ if(Gtk.Settings.get_default().gtk_application_prefer_dark_theme) {
+ this.view.get_generic_view().get_style_context().add_class("artist-panel-dark");
+ controls.get_style_context().add_class("playlist-controls-dark");
+ } else {
+ this.view.get_generic_view().get_style_context().add_class("artist-panel-white");
+ controls.get_style_context().add_class("playlist-controls-white");
+ }
+ 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.ellipsize = 3;
+ typeRenderer.xalign = 0.0;
+ typeRenderer.yalign = 0.5;
+ typeRenderer.height = 48;
+ typeRenderer.width = 220;
+ listWidget.add_renderer(typeRenderer, Lang.bind(this,
+ function(col, cell, model, iter) {
+ typeRenderer.text = model.get_value(iter, 0);
+ }));
+ },
+
+ _onItemActivated: function (widget, id, path) {
+ let iter = this._model.get_iter (path)[1];
+ let playlist = this._model.get_value (iter, 0);
+ this._playlistLabel.set_text(playlist);
+ let url = this._playlists[playlist.toLowerCase()]['url'];
+ this._songsListWidget.update(url);
+ },
+
+ _addItem: function (source, param, item) {
+ this._offset += 1;
+ if (item == null)
+ return
+ var playlist = "Unknown"
+ if (item.get_title() != null)
+ playlist = item.get_title();
+ if (item.get_string(Grl.METADATA_KEY_TITLE) != null)
+ playlist = item.get_string(Grl.METADATA_KEY_TITLE)
+ var url = item.get_string(Grl.METADATA_KEY_URL)
+ if (this._playlists[playlist.toLowerCase()] == undefined) {
+ var iter = this._model.append();
+ this._playlists[playlist.toLowerCase()] = {"iter": iter, "url": url}
+ this._model.set(
+ iter,
+ [0, 1, 2, 3],
+ [playlist, playlist, playlist, playlist]
+ );
+ }
+ },
+
+ populate: function () {
+ if(grilo.tracker != null) {
+ grilo.populatePlaylists(this._offset, Lang.bind(this, this._addItem, null));
+ }
},
});
diff --git a/src/widgets.js b/src/widgets.js
index 5c3b2ba..545b131 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -322,14 +322,102 @@ const AlbumWidget = new Lang.Class({
});
Signals.addSignalMethods(AlbumWidget.prototype);
+const SongsList = new Lang.Class({
+ Name: "SongsList",
+ Extends: Gd.MainView,
+
+ _init: function(){
+ this.parent();
+ this.playlist = null;
+ 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,
+ GObject.TYPE_STRING,
+ GObject.TYPE_BOOLEAN,
+ GObject.TYPE_BOOLEAN
+ ]);
+ this.set_view_type(Gd.MainViewType.ICON);
+ this.set_model(this._model);
+ this.show_all();
+ },
+
+ update: function(playlistUrl) {
+ this.playlist = playlistUrl;
+ this._populate();
+ this.show_all();
+ },
+
+ _addItem: function(source, param, item) {
+ this._offset += 1;
+ log("addItem Song: "+item);
+ if (item == null)
+ return;
+ var iter = this._model.append();
+ var song = "Unknown"
+ if (item.get_string(Grl.METADATA_KEY_ARTIST) != null)
+ song = item.get_string(Grl.METADATA_KEY_ARTIST)
+ 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]);
+ },
+
+ _populate: function() {
+ if(grilo.filesystem != null) {
+ grilo.getPlaylistSongs(this.playlist, Lang.bind(this, this._addItem, null));
+ }
+ }
+
+});
+
+/*const PlaylistSongs = new Lang.Class({
+ Name: "PlaylistSongs",
+ Extends: Gtk.VBox,
+
+ _init: function (playlist, player) {
+ this.player = player;
+ this.playlist = playlist;
+ this.parent();
+ this.ui = new Gtk.Builder();
+ this.ui.add_from_resource('/org/gnome/music/ArtistAlbumsWidget.ui');
+ this.set_border_width(0);
+ this.ui.get_object("artist").set_label(this.playlist);
+ this.widgets = [];
+ this._vbox = new Gtk.VBox();
+ this._songsBox = new SongsList(this.playlist);
+ this._scrolledWindow = new Gtk.ScrolledWindow();
+ this._scrolledWindow.set_policy(
+ Gtk.PolicyType.NEVER,
+ Gtk.PolicyType.AUTOMATIC
+ );
+ this._scrolledWindow.add(this._vbox);
+ this._vbox.pack_start(this.ui.get_object("ArtistAlbumsWidget"), false, false, 0);
+ this._vbox.pack_start(this._songsBox, false, false, 16);
+ this.pack_start(this._scrolledWindow, true, true, 0);
+
+ this.show_all();
+ },
+
+ update: function(playlist) {
+ this._songsBox = null;
+ this._songsBox = new SongsList(playlist);
+ },
+
+});*/
+
const ArtistAlbums = new Lang.Class({
Name: "ArtistAlbumsWidget",
Extends: Gtk.VBox,
_init: function (artist, albums, player) {
- this.player = player
- this.artist = artist
- this.albums = albums
+ this.player = player;
+ this.artist = artist;
+ this.albums = albums;
this.parent();
this.ui = new Gtk.Builder();
this.ui.add_from_resource('/org/gnome/music/ArtistAlbumsWidget.ui');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]