[banshee] [Dap.MassStorage] Read .is_audio_player (bgo#611991)
- From: Alexander Kojevnikov <alexk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] [Dap.MassStorage] Read .is_audio_player (bgo#611991)
- Date: Sun, 28 Mar 2010 02:34:39 +0000 (UTC)
commit 0628224f2b813ce12552f58faedea69a382c181b
Author: Jeroen Budts <jeroen lightyear be>
Date: Sun Mar 28 13:29:47 2010 +1100
[Dap.MassStorage] Read .is_audio_player (bgo#611991)
If the file exists, use custom settings for Android, Maemo
and WebOS devices.
Signed-off-by: Alexander Kojevnikov <alexander kojevnikov com>
.../Banshee.Dap.MassStorage/AndroidDevice.cs | 19 ++--
.../CustomMassStorageDevice.cs | 2 +-
.../Banshee.Dap.MassStorage/MaemoDevice.cs | 19 ++--
.../Banshee.Dap.MassStorage/MassStorageDevice.cs | 143 ++++++++++++++------
.../Banshee.Dap.MassStorage/WebOSDevice.cs | 17 ++-
5 files changed, 131 insertions(+), 69 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs
index 2e3d6be..155a9cd 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AndroidDevice.cs
@@ -82,26 +82,27 @@ namespace Banshee.Dap.MassStorage
public override bool LoadDeviceConfiguration ()
{
+ LoadConfig ();
return true;
}
- public override string [] AudioFolders {
+ protected override string [] DefaultAudioFolders {
get { return audio_folders; }
}
- public override string [] VideoFolders {
+ protected override string [] DefaultVideoFolders {
get { return video_folders; }
}
- public override string [] PlaylistFormats {
+ protected override string [] DefaultPlaylistFormats {
get { return playlist_formats; }
}
- public override string PlaylistPath {
+ protected override string DefaultPlaylistPath {
get { return playlists_path; }
}
- public override string [] PlaybackMimeTypes {
+ protected override string [] DefaultPlaybackMimeTypes {
get { return playback_mime_types; }
}
@@ -109,19 +110,19 @@ namespace Banshee.Dap.MassStorage
// packages/apps/Music/src/com/android/music/MusicUtils.java
// <3 open source
- public override int FolderDepth {
+ protected override int DefaultFolderDepth {
get { return 2; }
}
- public override string CoverArtFileName {
+ protected override string DefaultCoverArtFileName {
get { return "AlbumArt.jpg"; }
}
- public override string CoverArtFileType {
+ protected override string DefaultCoverArtFileType {
get { return "jpeg"; }
}
- public override int CoverArtSize {
+ protected override int DefaultCoverArtSize {
get { return 320; }
}
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs
index 1eb1df3..93ae1f4 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/CustomMassStorageDevice.cs
@@ -40,7 +40,7 @@ namespace Banshee.Dap.MassStorage
set { vendor_product_info = value; }
}
- public override string Name {
+ protected override string DefaultName {
get { return vendor_product_info.ProductName; }
}
}
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MaemoDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MaemoDevice.cs
index 587efe3..11871ac 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MaemoDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MaemoDevice.cs
@@ -99,42 +99,43 @@ namespace Banshee.Dap.MassStorage
public override bool LoadDeviceConfiguration ()
{
+ LoadConfig ();
return true;
}
- public override string Name {
+ protected override string DefaultName {
get { return VendorProductInfo.ProductName; }
}
- public override string [] AudioFolders {
+ protected override string[] DefaultAudioFolders {
get { return audio_folders; }
}
- public override string [] VideoFolders {
+ protected override string [] DefaultVideoFolders {
get { return video_folders; }
}
- public override string [] PlaybackMimeTypes {
+ protected override string [] DefaultPlaybackMimeTypes {
get { return playback_mime_types; }
}
- public override int FolderDepth {
+ protected override int DefaultFolderDepth {
get { return 2; }
}
- public override string CoverArtFileName {
+ protected override string DefaultCoverArtFileName {
get { return "cover.jpg"; }
}
- public override string CoverArtFileType {
+ protected override string DefaultCoverArtFileType {
get { return "jpeg"; }
}
- public override int CoverArtSize {
+ protected override int DefaultCoverArtSize {
get { return 200; }
}
- public override string [] PlaylistFormats {
+ protected override string [] DefaultPlaylistFormats {
get { return playlist_formats; }
}
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
index 3eb4911..515f57d 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageDevice.cs
@@ -28,6 +28,7 @@
using System;
using System.IO;
+using System.Linq;
using System.Collections.Generic;
using Mono.Unix;
@@ -71,7 +72,6 @@ namespace Banshee.Dap.MassStorage
{
string path = IsAudioPlayerPath;
string path_rockbox = System.IO.Path.Combine (source.Volume.MountPoint, ".rockbox/config.cfg");
- StreamReader reader = null;
if (!File.Exists (path) && !File.Exists (path_rockbox) ) {
return false;
@@ -89,48 +89,67 @@ namespace Banshee.Dap.MassStorage
cover_art_file_name = "cover.jpg";
cover_art_file_type = "jpeg";
cover_art_size = 320;
+
+ } else {
+ LoadConfig ();
}
- if (File.Exists (path)) {
+ return true;
+ }
+
+ protected void LoadConfig ()
+ {
+ var config = new Dictionary<string, string[]> ();
+
+ if (File.Exists (IsAudioPlayerPath)) {
+
try {
- foreach (KeyValuePair<string, string []> item in new KeyValueParser (reader = new StreamReader (path))) {
- try {
- switch (item.Key) {
- case "name": name = item.Value[0]; break;
-
- case "cover_art_file_type": cover_art_file_type = item.Value[0].ToLower (); break;
- case "cover_art_file_name": cover_art_file_name = item.Value[0]; break;
- case "cover_art_size": Int32.TryParse (item.Value[0], out cover_art_size); break;
- case "audio_folders": audio_folders = item.Value; break;
- case "video_folders": video_folders = item.Value; break;
- case "output_formats": playback_mime_types = item.Value; break;
- case "playlist_format": playlist_formats = item.Value; break;
- case "playlist_path": playlist_path = item.Value[0]; break;
- case "folder_depth":
- if (!Int32.TryParse (item.Value[0], out folder_depth)) {
- folder_depth = -1;
- }
- Hyena.Log.DebugFormat ("MassStorageDevice.LoadDeviceConfiguration {0}", folder_depth);
- break;
- default:
- throw new ApplicationException ("unsupported key");
- }
- } catch (Exception e) {
- Log.Exception ("Invalid .is_audio_player item " + item.Key, e);
- }
+ using (var reader = new StreamReader (IsAudioPlayerPath)) {
+ config = new KeyValueParser (reader);
+ has_is_audio_player_file = true;
}
+
} catch (Exception e) {
- Log.Exception ("Error parsing " + path, e);
- } finally {
- if (reader != null) {
- reader.Dispose ();
- }
+ Log.Exception ("Error parsing " + IsAudioPlayerPath, e);
}
}
- has_is_audio_player_file = true;
+ name = GetPreferredValue ("name", config, DefaultName);
+ cover_art_file_type = GetPreferredValue ("cover_art_file_type", config, DefaultCoverArtFileType);
+ cover_art_file_name = GetPreferredValue ("cover_art_file_name", config, DefaultCoverArtFileName);
+ cover_art_size = GetPreferredValue ("cover_art_size", config, DefaultCoverArtSize);
+ audio_folders = MergeValues ("audio_folders", config, DefaultAudioFolders);
+ video_folders = MergeValues ("video_folders", config, DefaultVideoFolders);
+ playback_mime_types = MergeValues ("output_formats", config, DefaultPlaybackMimeTypes);
+ playlist_formats = MergeValues ("playlist_formats", config, DefaultPlaylistFormats);
+ playlist_path = GetPreferredValue ("playlist_path", config, DefaultPlaylistPath);
+ folder_depth = GetPreferredValue ("folder_depth", config, DefaultFolderDepth);
+ }
- return true;
+ private string[] MergeValues (string key, IDictionary<string, string[]> config, string[] defaultValues)
+ {
+ if (config.ContainsKey (key)) {
+ return config[key].Union (defaultValues).ToArray ();
+ }
+ return defaultValues;
+ }
+
+ private int GetPreferredValue (string key, IDictionary<string, string[]> config, int defaultValue)
+ {
+ int parsedValue;
+ if (config.ContainsKey (key) && config[key].Length > 0
+ && int.TryParse (config[key][0], out parsedValue)) {
+ return parsedValue;
+ }
+ return defaultValue;
+ }
+
+ private string GetPreferredValue (string key, IDictionary<string, string[]> config, string defaultValue)
+ {
+ if (config.ContainsKey (key)) {
+ return config[key][0];
+ }
+ return defaultValue;
}
public virtual bool GetTrackPath (TrackInfo track, out string path)
@@ -148,53 +167,93 @@ namespace Banshee.Dap.MassStorage
get { return System.IO.Path.Combine (source.Volume.MountPoint, ".is_audio_player"); }
}
+ protected virtual string DefaultName {
+ get { return source.Volume.Name; }
+ }
+
private string name;
public virtual string Name {
get { return name ?? source.Volume.Name; }
}
+ protected virtual int DefaultCoverArtSize {
+ get { return 200; }
+ }
+
private int cover_art_size;
public virtual int CoverArtSize {
get { return cover_art_size; }
}
+ protected virtual int DefaultFolderDepth {
+ get { return -1; }
+ }
+
private int folder_depth = -1;
public virtual int FolderDepth {
get { return folder_depth; }
}
- private string [] audio_folders = new string[0];
- public virtual string [] AudioFolders {
+ protected virtual string [] DefaultAudioFolders {
+ get { return new string[0]; }
+ }
+
+ private string[] audio_folders = new string[0];
+ public virtual string[] AudioFolders {
get { return audio_folders; }
}
- private string [] video_folders = new string[0];
- public virtual string [] VideoFolders {
+ protected virtual string[] DefaultVideoFolders {
+ get { return new string[0]; }
+ }
+
+ private string[] video_folders = new string[0];
+ public virtual string[] VideoFolders {
get { return video_folders; }
}
+ protected virtual string DefaultCoverArtFileType {
+ get { return ""; }
+ }
+
private string cover_art_file_type;
public virtual string CoverArtFileType {
get { return cover_art_file_type; }
}
+ protected virtual string DefaultCoverArtFileName {
+ get { return "cover.jpg"; }
+ }
+
private string cover_art_file_name;
public virtual string CoverArtFileName {
get { return cover_art_file_name; }
}
- private string [] playlist_formats;
- public virtual string [] PlaylistFormats {
+ protected virtual string[] DefaultPlaylistFormats {
+ get { return new string[0]; }
+ }
+
+ private string[] playlist_formats;
+ public virtual string[] PlaylistFormats {
get { return playlist_formats; }
}
+ protected virtual string DefaultPlaylistPath {
+ get { return null; }
+ }
+
private string playlist_path;
public virtual string PlaylistPath {
get { return playlist_path; }
}
- private string [] playback_mime_types;
- public virtual string [] PlaybackMimeTypes {
+ protected virtual string[] DefaultPlaybackMimeTypes {
+ get { return new string[0]; }
+ }
+
+ private string[] playback_mime_types;
+ public virtual string[] PlaybackMimeTypes {
get { return playback_mime_types; }
}
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs
index ea42a51..5501c9c 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs
@@ -114,38 +114,39 @@ namespace Banshee.Dap.MassStorage
public override bool LoadDeviceConfiguration ()
{
+ LoadConfig ();
return true;
}
- public override string Name {
+ protected override string DefaultName {
get { return VendorProductInfo.ProductName; }
}
- public override string [] AudioFolders {
+ protected override string [] DefaultAudioFolders {
get { return audio_folders; }
}
- public override string [] VideoFolders {
+ protected override string [] DefaultVideoFolders {
get { return video_folders; }
}
- public override string [] PlaybackMimeTypes {
+ protected override string [] DefaultPlaybackMimeTypes {
get { return playback_mime_types; }
}
- public override int FolderDepth {
+ protected override int DefaultFolderDepth {
get { return 2; }
}
- public override string CoverArtFileType {
+ protected override string DefaultCoverArtFileType {
get { return "jpeg"; }
}
- public override int CoverArtSize {
+ protected override int DefaultCoverArtSize {
get { return 320; }
}
- public override string [] PlaylistFormats {
+ protected override string [] DefaultPlaylistFormats {
get { return playlist_formats; }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]