[banshee/stable-2.6] Mtp: show tracks which are in subfolders from Music/ (bgo#724678)
- From: Andrés Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee/stable-2.6] Mtp: show tracks which are in subfolders from Music/ (bgo#724678)
- Date: Tue, 18 Feb 2014 18:30:33 +0000 (UTC)
commit fb1ca6bd37e0b29e4880b807d73f32238ac7ec45
Author: Nicholas Little <arealityfarbetween googlemail com>
Date: Tue Feb 18 19:19:46 2014 +0100
Mtp: show tracks which are in subfolders from Music/ (bgo#724678)
Files can happen to be in a hierarchy of folders inside the
Music/ folder in the device. To be able to see them we need
to do add them the proper MtpTrackInfo.MediaAttriubutes by
looking for them recursively.
Based on original patch by IBBoard <dev ibboard co uk> (his
patch included read-and-write support, this patch only
implements read support for now. Write support will need
more discussion. See BGO#539804 for the latter.)
.../Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs | 4 +-
.../Banshee.Dap.Mtp/MtpTrackInfo.cs | 6 +-
src/Libraries/Mtp/Mtp/Folder.cs | 50 +++++++++++++++++++-
src/Libraries/Mtp/Mtp/Track.cs | 24 ++++++++-
4 files changed, 75 insertions(+), 9 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
index cda0ae6..67afd98 100644
--- a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
+++ b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
@@ -273,7 +273,7 @@ namespace Banshee.Dap.Mtp
using (System.IO.TextWriter writer = new System.IO.StreamWriter
(Banshee.IO.File.OpenWrite (empty_file, true))) {
writer.Write ("foo");
}
- Track mtp_track = new Track (System.IO.Path.GetFileName (empty_file.LocalPath), 3);
+ Track mtp_track = new Track (System.IO.Path.GetFileName (empty_file.LocalPath), 3,
mtp_device);
mtp_device.UploadTrack (empty_file.AbsolutePath, mtp_track, mtp_device.MusicFolder);
mtp_device.Remove (mtp_track);
@@ -425,7 +425,7 @@ namespace Banshee.Dap.Mtp
public Track TrackInfoToMtpTrack (TrackInfo track, SafeUri fromUri)
{
- Track f = new Track (System.IO.Path.GetFileName (fromUri.LocalPath), (ulong)
Banshee.IO.File.GetSize (fromUri));
+ Track f = new Track (System.IO.Path.GetFileName (fromUri.LocalPath), (ulong)
Banshee.IO.File.GetSize (fromUri), mtp_device);
MtpTrackInfo.ToMtpTrack (track, f);
return f;
}
diff --git a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs
b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs
index 3128e61..3027af1 100644
--- a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs
+++ b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpTrackInfo.cs
@@ -73,9 +73,9 @@ namespace Banshee.Dap.Mtp
MediaAttributes = TrackMediaAttributes.AudioStream;
if (device != null) {
- SetAttributeIf (file.InFolder (device.PodcastFolder) || Genre == "Podcast",
TrackMediaAttributes.Podcast);
- SetAttributeIf (file.InFolder (device.MusicFolder), TrackMediaAttributes.Music);
- SetAttributeIf (file.InFolder (device.VideoFolder), TrackMediaAttributes.VideoStream);
+ SetAttributeIf (file.InFolder (device.PodcastFolder, true) || Genre == "Podcast",
TrackMediaAttributes.Podcast);
+ SetAttributeIf (file.InFolder (device.MusicFolder, true), TrackMediaAttributes.Music);
+ SetAttributeIf (file.InFolder (device.VideoFolder, true), TrackMediaAttributes.VideoStream);
}
// This can be implemented if there's enough people requesting it
diff --git a/src/Libraries/Mtp/Mtp/Folder.cs b/src/Libraries/Mtp/Mtp/Folder.cs
index 80eabbd..5e70b66 100644
--- a/src/Libraries/Mtp/Mtp/Folder.cs
+++ b/src/Libraries/Mtp/Mtp/Folder.cs
@@ -104,7 +104,35 @@ namespace Mtp
LIBMTP_destroy_folder_t (root);
return folders;
}
-
+
+ private Folder CreateParentFolder ()
+ {
+ return Find (device, parentId);
+ }
+
+ public bool HasAncestor (Folder ancestor)
+ {
+ if (ancestor == null) {
+ throw new ArgumentNullException ("ancestor");
+ }
+
+ if (device != ancestor.device) {
+ throw new ArgumentException ("Folders are on different devices");
+ }
+
+ bool hasAncestor = false;
+ if (parentId != 0) {
+ if (parentId == ancestor.FolderId) {
+ hasAncestor = true;
+ } else {
+ Folder parent = CreateParentFolder ();
+
+ hasAncestor = parent.HasAncestor (ancestor);
+ }
+ }
+ return hasAncestor;
+ }
+
public void Remove()
{
MtpDevice.DeleteObject(device.Handle, FolderId);
@@ -154,6 +182,26 @@ namespace Mtp
return LIBMTP_Find_Folder (folderList, folderId);
}
+ internal static Folder Find (MtpDevice device, uint folderId)
+ {
+ if (device == null) {
+ throw new ArgumentNullException ("device");
+ }
+
+ Folder folder = null;
+ IntPtr root = GetFolderList (device.Handle);
+ try {
+ IntPtr ptr = Find (root, folderId);
+ if (ptr != IntPtr.Zero) {
+ FolderStruct folderStruct = (FolderStruct)Marshal.PtrToStructure (ptr, typeof
(FolderStruct));
+ folder = new Folder (folderStruct, device);
+ }
+ } finally {
+ DestroyFolder (root);
+ }
+ return folder;
+ }
+
internal static IntPtr GetFolderList (MtpDeviceHandle handle)
{
return LIBMTP_Get_Folder_List (handle);
diff --git a/src/Libraries/Mtp/Mtp/Track.cs b/src/Libraries/Mtp/Mtp/Track.cs
index 22e15d3..506051d 100644
--- a/src/Libraries/Mtp/Mtp/Track.cs
+++ b/src/Libraries/Mtp/Mtp/Track.cs
@@ -139,7 +139,11 @@ namespace Mtp
set { trackStruct.composer = value; }
}
- public Track (string filename, ulong filesize) : this (new TrackStruct (), null)
+ public Track (string filename, ulong filesize) : this (filename, filesize, null)
+ {
+ }
+
+ public Track (string filename, ulong filesize, MtpDevice device) : this (new TrackStruct (), device)
{
this.trackStruct.filename = filename;
this.trackStruct.filesize = filesize;
@@ -154,9 +158,23 @@ namespace Mtp
public bool InFolder (Folder folder)
{
- return folder != null && trackStruct.parent_id == folder.FolderId;
+ return InFolder (folder, false);
}
-
+
+ public bool InFolder (Folder folder, bool recursive)
+ {
+ if (folder == null) {
+ return false;
+ }
+
+ bool is_parent = trackStruct.parent_id == folder.FolderId;
+ if (is_parent || !recursive) {
+ return is_parent;
+ }
+
+ return Folder.Find (device, trackStruct.parent_id).HasAncestor (folder);
+ }
+
public void Download (string path)
{
Download (path, null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]