diff options
author | Aaron Bockover <abock@gnome.org> | 2008-02-06 23:49:53 +0000 |
---|---|---|
committer | Aaron Bockover <abock@src.gnome.org> | 2008-02-06 23:49:53 +0000 |
commit | 5ed9ace84c661e5bdf6e1a6ffcbad7e22c7a55b9 (patch) | |
tree | 07d1df59ca5cb15907dd540b2c288f4da083d988 | |
parent | 245f3f93303620d6cd07511f07bc180a635a297a (diff) |
Okay, so this is a big one. Probably nasty. This commit temporarily breaks
2008-02-06 Aaron Bockover <abock@gnome.org>
Okay, so this is a big one. Probably nasty. This commit temporarily breaks
settings saving/loading from GConf and the POSIX IO layer is disabled
for now as well; these features will be reimplemented as platform
extensions in my next commit;
This commit puts us very close to being able to run the managed Banshee
core out of the box on Windows and probably OS X.
* src/Core/Banshee.Services/Banshee.AudioProfiles/ProfileConfiguration.cs:
Applied Scott's from SoC that makes this configuration layer just use
the standard configuration APIs in Banshee, so profile configuration
is stored using whatever provider is active (GConf, XML); Scott rules.
* src/Backends/Banshee.Gnome: Moved out GNOME specific code (GConf,
GnomeVFS) into this new platform extension, but it's not complete
* src/Core/Banshee.Core/Banshee.Base/RateLimiter.cs:
* src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs: Moved to
the service layer since these depend on Application
* src/Core/Banshee.Core/Banshee.Base/Resource.cs:
* src/Core/Banshee.Core/Banshee.Base/NamingUtil.cs: Moved/fixed these
classes out of the old Utilities.cs dumping grounds
* src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs:
Do not reference the GConfConfigurationClient; for now the Xml one
is hard coded to use until I finish turning the GConf support into
a provider - no complaining - the next commit will address it
* src/Core/Banshee.Core/Banshee.I18n/AssemblyCatalogAttribute.cs:
* src/Core/Banshee.Core/Banshee.I18n/Catalog.cs: Moved/cleaned up the
internal Banshee gettext wrapper
* src/Core/Banshee.Core/Banshee.IO: Redesigned the IO layer to be easier
to extend (soon) through extensions and it now provides a cleaner API
to use (no more IOProxy)
* src/Core/Banshee.Core/Banshee.IO.SystemIO: Fixed up System.IO provider
to implement the new Banshee.IO design changes
* src/Core/Banshee.Core/Banshee.Base/FileNamePattern.cs:
* src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs:
* src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs:
* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs:
* src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs:
* src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs:
* src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs:
Updated to consume the nicer Banshee.IO APIs
* src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs: Added a class that
makes doing some common stream operations (currently, just saving one
stream to another) easier
* src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs:
* src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs:
Updated to use the new Banshee.IO APIs and also StreamAssist.Save to
reduce so much duplication of stream code
* src/Core/Banshee.Services/Banshee.ServiceStack/Application.cs: Added
another Inovke method that takes an EventHandler delegate to stay
compatible with Gtk.Application.Invoke
* src/Core/Banshee.Services/Banshee.Services.addin.xml: Added a few
platform extension points
* src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs:
Removed unnecessary Gnome.Vfs call
* src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs: Removed
default Gnome.Open implementation; users must set a handle at all times
so the widget is not bound to a platform
* src/Core/Nereid/Nereid/Client.cs: Removed crappy Gnome.Program stuff
since it really doesn't provide anything for us
* src/Extensions/Template/Makefile.am: Small fix
* src/Core/Banshee.Core/Banshee.Base/Utilities.cs:
* src/Core/Banshee.Services/Banshee.AudioProfiles/GConfProfileConfiguration.cs:
Nuked, finally
* build/build.environment.mk:
* build/m4/banshee/gtk-sharp.m4: Removed gnome-sharp and gconf-sharp
dependencies
svn path=/trunk/banshee/; revision=3157
63 files changed, 1536 insertions, 1225 deletions
@@ -1,3 +1,90 @@ +2008-02-06 Aaron Bockover <abock@gnome.org> + + Okay, so this is a big one. Probably nasty. This commit temporarily breaks + settings saving/loading from GConf and the POSIX IO layer is disabled + for now as well; these features will be reimplemented as platform + extensions in my next commit; + + This commit puts us very close to being able to run the managed Banshee + core out of the box on Windows and probably OS X. + + * src/Core/Banshee.Services/Banshee.AudioProfiles/ProfileConfiguration.cs: + Applied Scott's from SoC that makes this configuration layer just use + the standard configuration APIs in Banshee, so profile configuration + is stored using whatever provider is active (GConf, XML); Scott rules. + + * src/Backends/Banshee.Gnome: Moved out GNOME specific code (GConf, + GnomeVFS) into this new platform extension, but it's not complete + + * src/Core/Banshee.Core/Banshee.Base/RateLimiter.cs: + * src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs: Moved to + the service layer since these depend on Application + + * src/Core/Banshee.Core/Banshee.Base/Resource.cs: + * src/Core/Banshee.Core/Banshee.Base/NamingUtil.cs: Moved/fixed these + classes out of the old Utilities.cs dumping grounds + + * src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs: + Do not reference the GConfConfigurationClient; for now the Xml one + is hard coded to use until I finish turning the GConf support into + a provider - no complaining - the next commit will address it + + * src/Core/Banshee.Core/Banshee.I18n/AssemblyCatalogAttribute.cs: + * src/Core/Banshee.Core/Banshee.I18n/Catalog.cs: Moved/cleaned up the + internal Banshee gettext wrapper + + * src/Core/Banshee.Core/Banshee.IO: Redesigned the IO layer to be easier + to extend (soon) through extensions and it now provides a cleaner API + to use (no more IOProxy) + + * src/Core/Banshee.Core/Banshee.IO.SystemIO: Fixed up System.IO provider + to implement the new Banshee.IO design changes + + * src/Core/Banshee.Core/Banshee.Base/FileNamePattern.cs: + * src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs: + * src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs: + * src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs: + * src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs: + * src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs: + * src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs: + Updated to consume the nicer Banshee.IO APIs + + * src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs: Added a class that + makes doing some common stream operations (currently, just saving one + stream to another) easier + + * src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs: + * src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs: + Updated to use the new Banshee.IO APIs and also StreamAssist.Save to + reduce so much duplication of stream code + + * src/Core/Banshee.Services/Banshee.ServiceStack/Application.cs: Added + another Inovke method that takes an EventHandler delegate to stay + compatible with Gtk.Application.Invoke + + * src/Core/Banshee.Services/Banshee.Services.addin.xml: Added a few + platform extension points + + * src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs: + Removed unnecessary Gnome.Vfs call + + * src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs: Removed + default Gnome.Open implementation; users must set a handle at all times + so the widget is not bound to a platform + + * src/Core/Nereid/Nereid/Client.cs: Removed crappy Gnome.Program stuff + since it really doesn't provide anything for us + + * src/Extensions/Template/Makefile.am: Small fix + + * src/Core/Banshee.Core/Banshee.Base/Utilities.cs: + * src/Core/Banshee.Services/Banshee.AudioProfiles/GConfProfileConfiguration.cs: + Nuked, finally + + * build/build.environment.mk: + * build/m4/banshee/gtk-sharp.m4: Removed gnome-sharp and gconf-sharp + dependencies + 2008-02-06 Gabriel Burt <gabriel.burt@gmail.com> * src/Core/Banshee.ThickClient/Banshee.Gui/BansheeActionGroup.cs: diff --git a/Makefile.am b/Makefile.am index 26be7e1de..8e2f889ec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,3 +57,10 @@ uninstall-hook: rmdir $(pkglibdir); \ fi +dist-windows: all + rm -rf banshee-windows; \ + mkdir banshee-windows; \ + cp -rf bin/*.{dll,exe} banshee-windows; \ + zip banshee-windows.zip -r banshee-windows; \ + rm -rf banshee-windows + diff --git a/build/build.environment.mk b/build/build.environment.mk index 655e09100..534c693d8 100644 --- a/build/build.environment.mk +++ b/build/build.environment.mk @@ -71,8 +71,8 @@ REF_HYENA_GUI = $(LINK_HYENA_DEPS) $(LINK_MONO_POSIX) $(LINK_CAIRO) $(LINK_GTK) LINK_HYENA_GUI = -r:$(DIR_BIN)/Hyena.Gui.dll LINK_HYENA_GUI_DEPS = $(REF_HYENA_GUI) $(LINK_HYENA_GUI) -REF_BANSHEE_CORE = $(LINK_HYENA_DEPS) $(LINK_MONO_POSIX) \ - $(LINK_DBUS) $(LINK_TAGLIB) $(LINK_GCONF) +REF_BANSHEE_CORE = $(LINK_HYENA_DEPS) $(LINK_MONO_POSIX) $(LINK_GLIB) \ + $(LINK_DBUS) $(LINK_TAGLIB) LINK_BANSHEE_CORE = -r:$(DIR_BIN)/Banshee.Core.dll LINK_BANSHEE_CORE_DEPS = $(REF_BANSHEE_CORE) $(LINK_BANSHEE_CORE) diff --git a/build/m4/banshee/gtk-sharp.m4 b/build/m4/banshee/gtk-sharp.m4 index 4bef78d51..270f634a2 100644 --- a/build/m4/banshee/gtk-sharp.m4 +++ b/build/m4/banshee/gtk-sharp.m4 @@ -3,10 +3,7 @@ AC_DEFUN([BANSHEE_CHECK_GTK_SHARP], GTKSHARP_REQUIRED=2.7 PKG_CHECK_MODULES(GTKSHARP, gtk-sharp-2.0 >= $GTKSHARP_REQUIRED \ - gnome-sharp-2.0 >= $GTKSHARP_REQUIRED \ - gnome-vfs-sharp-2.0 >= $GTKSHARP_REQUIRED \ - glade-sharp-2.0 >= $GTKSHARP_REQUIRED \ - gconf-sharp-2.0 >= $GTKSHARP_REQUIRED) + glade-sharp-2.0 >= $GTKSHARP_REQUIRED) AC_SUBST(GTKSHARP_LIBS) PKG_CHECK_MODULES(GLIBSHARP, diff --git a/configure.ac b/configure.ac index 4c5a1341a..51c1617bc 100644 --- a/configure.ac +++ b/configure.ac @@ -132,6 +132,7 @@ src/Core/Nereid/Makefile src/Core/Nereid/banshee2 src/Backends/Makefile +src/Backends/Banshee.Gnome/Makefile src/Backends/Banshee.GStreamer/Makefile src/Extensions/Makefile diff --git a/src/Backends/Backends.mds b/src/Backends/Backends.mds index edfe5f9aa..740c75799 100644 --- a/src/Backends/Backends.mds +++ b/src/Backends/Backends.mds @@ -2,12 +2,15 @@ <Configurations active="Debug"> <Configuration name="Debug" ctype="CombineConfiguration"> <Entry build="True" name="Banshee.GStreamer" configuration="Debug" /> + <Entry build="True" name="Banshee.Gnome" configuration="Debug" /> </Configuration> </Configurations> <StartMode startupentry="Banshee.GStreamer" single="True"> <Execute type="None" entry="Banshee.GStreamer" /> + <Execute type="None" entry="Banshee.Gnome" /> </StartMode> <Entries> <Entry filename="Banshee.GStreamer/Banshee.GStreamer.mdp" /> + <Entry filename="Banshee.Gnome/Banshee.Gnome.mdp" /> </Entries> </Combine>
\ No newline at end of file diff --git a/src/Backends/Banshee.Gnome/Banshee.Gnome.addin.xml b/src/Backends/Banshee.Gnome/Banshee.Gnome.addin.xml new file mode 100644 index 000000000..55d2a6981 --- /dev/null +++ b/src/Backends/Banshee.Gnome/Banshee.Gnome.addin.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<Addin + id="Banshee.Gnome" + version="1.0" + compatVersion="1.0" + copyright="© 2008 Novell Inc. Licensed under the MIT X11 license." + name="GNOME Providers" + category="Platform" + description="Backend providers for the GNOME platform. Includes GConf and GNOME-VFS support." + author="Aaron Bockover" + url="http://banshee-project.org/" + defaultEnabled="true"> + + <Dependencies> + <Addin id="Banshee.Services" version="1.0"/> + </Dependencies> + + <Extension path="/Banshee/Platform/IOProvider"> + <IOProvider class=""/> + </Extension> + + <Extension path="/Banshee/Platform/ConfigurationProvider"> + <ConfigurationProvider class=""/> + </Extension> + +</Addin> diff --git a/src/Backends/Banshee.Gnome/Banshee.Gnome.mdp b/src/Backends/Banshee.Gnome/Banshee.Gnome.mdp new file mode 100644 index 000000000..99a2f1497 --- /dev/null +++ b/src/Backends/Banshee.Gnome/Banshee.Gnome.mdp @@ -0,0 +1,31 @@ +<Project name="Banshee.Gnome" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject"> + <Configurations active="Debug"> + <Configuration name="Debug" ctype="DotNetProjectConfiguration"> + <Output directory="../../../bin" assemblyKeyFile="." assembly="Banshee.Gnome" /> + <Build debugmode="True" target="Library" /> + <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" /> + <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" /> + </Configuration> + </Configurations> + <Contents> + <File name="Banshee.Gnome.addin.xml" subtype="Code" buildaction="EmbedAsResource" /> + <File name="Banshee.Gnome" subtype="Directory" buildaction="Compile" /> + <File name="Banshee.Gnome/GnomeVfs.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.Gnome/GConfConfigurationClient.cs" subtype="Code" buildaction="Compile" /> + </Contents> + <References> + <ProjectReference type="Project" localcopy="True" refto="Banshee.Core" /> + <ProjectReference type="Project" localcopy="True" refto="Banshee.Services" /> + <ProjectReference type="Project" localcopy="True" refto="Hyena" /> + <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> + </References> + <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="./Makefile.am"> + <BuildFilesVar Sync="True" Name="SOURCES" /> + <DeployFilesVar /> + <ResourcesVar Sync="True" Name="RESOURCES" /> + <OthersVar /> + <GacRefVar /> + <AsmRefVar /> + <ProjectRefVar /> + </MonoDevelop.Autotools.MakefileInfo> +</Project>
\ No newline at end of file diff --git a/src/Core/Banshee.Core/Banshee.Configuration/GConfConfigurationClient.cs b/src/Backends/Banshee.Gnome/Banshee.Gnome/GConfConfigurationClient.cs index d6b1ec31c..d6b1ec31c 100644 --- a/src/Core/Banshee.Core/Banshee.Configuration/GConfConfigurationClient.cs +++ b/src/Backends/Banshee.Gnome/Banshee.Gnome/GConfConfigurationClient.cs diff --git a/src/Core/Banshee.Core/Banshee.IO/GnomeVfs.cs b/src/Backends/Banshee.Gnome/Banshee.Gnome/GnomeVfs.cs index c6601e2cb..c6601e2cb 100644 --- a/src/Core/Banshee.Core/Banshee.IO/GnomeVfs.cs +++ b/src/Backends/Banshee.Gnome/Banshee.Gnome/GnomeVfs.cs diff --git a/src/Backends/Banshee.Gnome/Makefile.am b/src/Backends/Banshee.Gnome/Makefile.am new file mode 100644 index 000000000..4b789d3c4 --- /dev/null +++ b/src/Backends/Banshee.Gnome/Makefile.am @@ -0,0 +1,12 @@ +ASSEMBLY = Banshee.Gnome +TARGET = library +LINK = $(REF_FIXME) + +SOURCES = \ + Banshee.Gnome/GConfConfigurationClient.cs \ + Banshee.Gnome/GnomeVfs.cs + +RESOURCES = Banshee.Gnome.addin.xml + +#include $(top_srcdir)/build/build.mk + diff --git a/src/Backends/Makefile.am b/src/Backends/Makefile.am index 300dd48cd..6393589fe 100644 --- a/src/Backends/Makefile.am +++ b/src/Backends/Makefile.am @@ -1,3 +1,6 @@ -SUBDIRS = Banshee.GStreamer +SUBDIRS = \ + Banshee.Gnome \ + Banshee.GStreamer + MAINTAINERCLEANFILES = Makefile.in diff --git a/src/Core/Banshee.Core/Banshee.Base/FileNamePattern.cs b/src/Core/Banshee.Core/Banshee.Base/FileNamePattern.cs index 062ad65b7..c8ef3ab49 100644 --- a/src/Core/Banshee.Core/Banshee.Base/FileNamePattern.cs +++ b/src/Core/Banshee.Core/Banshee.Base/FileNamePattern.cs @@ -1,31 +1,31 @@ -/*************************************************************************** - * FileNamePattern.cs - * - * Copyright (C) 2005-2006 Novell, Inc. - * Written by Aaron Bockover <aaron@abock.org> - ****************************************************************************/ +// +// FileNamePattern.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2005-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// -/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - using System; using System.Text.RegularExpressions; using System.Collections.Generic; @@ -240,8 +240,8 @@ namespace Banshee.Base string filename = dir + Path.DirectorySeparatorChar + Path.GetFileName (songpath); - if (!Banshee.IO.IOProxy.Directory.Exists (dir)) { - Banshee.IO.IOProxy.Directory.Create (dir); + if (!Banshee.IO.Directory.Exists (dir)) { + Banshee.IO.Directory.Create (dir); } return filename; diff --git a/src/Core/Banshee.Core/Banshee.Base/NamingUtil.cs b/src/Core/Banshee.Core/Banshee.Base/NamingUtil.cs new file mode 100644 index 000000000..d61494207 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.Base/NamingUtil.cs @@ -0,0 +1,124 @@ +// +// NamingUtil.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; +using System.Collections.Generic; + +using Banshee.Collection; + +namespace Banshee.Base +{ + public static class NamingUtil + { + public delegate bool PostfixDuplicateIncrementHandler (string check); + + public static string GenerateTrackCollectionName (IEnumerable tracks, string fallback) + { + Dictionary<string, int> weight_map = new Dictionary<string, int> (); + + if (tracks == null) { + return fallback; + } + + foreach (TrackInfo track in tracks) { + string artist = null; + string album = null; + + if (track.ArtistName != null) { + artist = track.ArtistName.Trim (); + if (artist == String.Empty) { + artist = null; + } + } + + if (track.AlbumTitle != null) { + album = track.AlbumTitle.Trim (); + if (album == String.Empty) { + album = null; + } + } + + if (artist != null && album != null) { + IncrementCandidate (weight_map, "\0" + artist + " - " + album); + IncrementCandidate (weight_map, artist); + IncrementCandidate (weight_map, album); + } else if (artist != null) { + IncrementCandidate (weight_map, artist); + } else if (album != null) { + IncrementCandidate (weight_map, album); + } + } + + int max_hit_count = 0; + string max_candidate = fallback; + + List<string> sorted_keys = new List<string> (weight_map.Keys); + sorted_keys.Sort (); + + foreach (string candidate in sorted_keys) { + int current_hit_count = weight_map[candidate]; + if (current_hit_count > max_hit_count) { + max_hit_count = current_hit_count; + max_candidate = candidate; + } + } + + if (max_candidate[0] == '\0') { + return max_candidate.Substring (1); + } + + return max_candidate; + } + + private static void IncrementCandidate (Dictionary<string, int> map, string hit) + { + if (map.ContainsKey (hit)) { + map[hit]++; + } else { + map.Add (hit, 1); + } + } + + public static string PostfixDuplicate (string prefix, PostfixDuplicateIncrementHandler duplicateHandler) + { + if (duplicateHandler == null) { + throw new ArgumentNullException ("A PostfixDuplicateIncrementHandler delegate must be given"); + } + + string name = prefix; + for (int i = 1; true; i++) { + if (!duplicateHandler (name)) { + return name; + } + + name = prefix + " " + i; + } + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.Base/Resource.cs b/src/Core/Banshee.Core/Banshee.Base/Resource.cs new file mode 100644 index 000000000..f01c9dded --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.Base/Resource.cs @@ -0,0 +1,49 @@ +// +// Resource.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2005-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; +using System.Reflection; + +namespace Banshee.Base +{ + public static class Resource + { + public static string GetFileContents (string name) + { + return GetFileContents (Assembly.GetCallingAssembly (), name); + } + + public static string GetFileContents (Assembly assembly, string name) + { + using (StreamReader reader = new StreamReader (assembly.GetManifestResourceStream (name))) { + return reader.ReadToEnd (); + } + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.Base/Utilities.cs b/src/Core/Banshee.Core/Banshee.Base/Utilities.cs deleted file mode 100644 index 7ad7d527b..000000000 --- a/src/Core/Banshee.Core/Banshee.Base/Utilities.cs +++ /dev/null @@ -1,285 +0,0 @@ -/*************************************************************************** - * Utilities.cs - * - * Copyright (C) 2005-2006 Novell, Inc. - * Written by Aaron Bockover <aaron@abock.org> - ****************************************************************************/ - -/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -using System; -using System.Threading; -using System.Runtime.InteropServices; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Text; -using System.Text.RegularExpressions; -using System.Diagnostics; -using System.Globalization; -using Mono.Unix; - -using Banshee.Collection; - -namespace Banshee.Base -{ - public static class UidGenerator - { - private static int uid = 0; - - public static int Next - { - get { - return ++uid; - } - } - } - - public static class Utilities - { - [DllImport ("libglib-2.0.so")] - private static extern IntPtr g_get_real_name (); - - public static string GetRealName () - { - try { - string name = GLib.Marshaller.Utf8PtrToString (g_get_real_name ()); - string [] parts = name.Split (' '); - return parts[0].Replace (',', ' ').Trim (); - } catch (Exception) { - return null; - } - } - - public static string BytesToString (ulong bytes) - { - double mb = (double)bytes / 1048576.0; - return mb > 1024.0 - ? String.Format (Catalog.GetString ("{0:0.00} GB"), mb / 1024.0) - : String.Format (Catalog.GetString ("{0} MB"), Math.Round (mb)); - } - - - public static int ExecProcess (string command, string args) - { - Process process = Process.Start (command, args == null ? "" : args); - process.WaitForExit (); - return process.ExitCode; - } - } - - public static class ReflectionUtil - { - public static bool IsVirtualMethodImplemented (Type type, string methodName) - { - MethodInfo methodInfo = type.GetMethod (methodName, - BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - - if (methodInfo == null) { - return false; - } - - return methodInfo.IsVirtual ? methodInfo != methodInfo.GetBaseDefinition () : true; - } - - public static object InvokeMethod (Assembly assembly, string typeName, string methodName) - { - if (assembly == null) { - throw new ArgumentNullException ("assembly"); - } - - Type type = assembly.GetType (typeName, true); - MethodInfo method = type.GetMethod (methodName); - return method.Invoke (null, null); - } - - public static Type [] ModuleGetTypes (Assembly assembly, string typeName) - { - return (Type [])InvokeMethod (assembly, typeName, "GetTypes"); - } - } - - public static class ThreadAssist - { - private static Thread main_thread; - - static ThreadAssist () - { - main_thread = Thread.CurrentThread; - } - - public static bool InMainThread { - get { - return main_thread.Equals (Thread.CurrentThread); - } - } - - public static void ProxyToMain (EventHandler handler) - { - if (!InMainThread) { - Gtk.Application.Invoke (handler); - } else { - handler (null, new EventArgs ()); - } - } - - public static Thread Spawn (ThreadStart threadedMethod, bool autoStart) - { - Thread thread = new Thread (threadedMethod); - thread.IsBackground = true; - if (autoStart) { - thread.Start (); - } - return thread; - } - - public static Thread Spawn (ThreadStart threadedMethod) - { - return Spawn (threadedMethod, true); - } - } - - public static class PathUtil - { - public static string MakeFileNameKey (SafeUri uri) - { - string path = uri.LocalPath; - return Path.GetDirectoryName (path) + - Path.DirectorySeparatorChar + - Path.GetFileNameWithoutExtension (path); - } - - public static long GetDirectoryAvailableSpace (string path) - { - try { - Mono.Unix.Native.Statvfs statvfs_info; - if (Mono.Unix.Native.Syscall.statvfs (path, out statvfs_info) == 0) { - return (long) (statvfs_info.f_bavail * statvfs_info.f_bsize); - } - - return -1; - } catch { - return -1; - } - } - } - - public class Resource - { - public static string GetFileContents (string name) - { - Assembly asm = Assembly.GetCallingAssembly (); - Stream stream = asm.GetManifestResourceStream (name); - StreamReader reader = new StreamReader (stream); - return reader.ReadToEnd (); - } - } - - public static class NamingUtil - { - public delegate bool PostfixDuplicateIncrementHandler (string check); - - public static string GenerateTrackCollectionName (IEnumerable tracks, string fallback) - { - Dictionary<string, int> weight_map = new Dictionary<string, int> (); - - if (tracks == null) { - return fallback; - } - - foreach (TrackInfo track in tracks) { - string artist = null; - string album = null; - - if (track.ArtistName != null) { - artist = track.ArtistName.Trim (); - if (artist == String.Empty) { - artist = null; - } - } - - if (track.AlbumTitle != null) { - album = track.AlbumTitle.Trim (); - if (album == String.Empty) { - album = null; - } - } - - if (artist != null && album != null) { - IncrementCandidate (weight_map, "\0" + artist + " - " + album); - IncrementCandidate (weight_map, artist); - IncrementCandidate (weight_map, album); - } else if (artist != null) { - IncrementCandidate (weight_map, artist); - } else if (album != null) { - IncrementCandidate (weight_map, album); - } - } - - int max_hit_count = 0; - string max_candidate = fallback; - - List<string> sorted_keys = new List<string> (weight_map.Keys); - sorted_keys.Sort (); - - foreach (string candidate in sorted_keys) { - int current_hit_count = weight_map[candidate]; - if (current_hit_count > max_hit_count) { - max_hit_count = current_hit_count; - max_candidate = candidate; - } - } - - if (max_candidate[0] == '\0') { - return max_candidate.Substring (1); - } - - return max_candidate; - } - - private static void IncrementCandidate (Dictionary<string, int> map, string hit) - { - if (map.ContainsKey (hit)) { - map[hit]++; - } else { - map.Add (hit, 1); - } - } - - public static string PostfixDuplicate (string prefix, PostfixDuplicateIncrementHandler duplicateHandler) - { - if (duplicateHandler == null) { - throw new ArgumentNullException ("A PostfixDuplicateIncrementHandler delegate must be given"); - } - - string name = prefix; - for (int i = 1; true; i++) { - if (!duplicateHandler (name)) { - return name; - } - - name = prefix + " " + i; - } - } - } -} diff --git a/src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs b/src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs index 7185c9385..2933afa2a 100644 --- a/src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs +++ b/src/Core/Banshee.Core/Banshee.Collection/FileTrackInfo.cs @@ -38,22 +38,22 @@ namespace Banshee.Collection { public class FileTrackInfo : TrackInfo { - public FileTrackInfo(SafeUri uri) + public FileTrackInfo (SafeUri uri) { LoadFromUri(uri); Uri = uri; } - private void LoadFromUri(SafeUri uri) + private void LoadFromUri (SafeUri uri) { - ParsePath(uri.LocalPath); + ParsePath (uri.LocalPath); - TagLib.File file = Banshee.IO.IOProxy.OpenFile(uri.LocalPath); + TagLib.File file = Banshee.IO.DemuxVfs.OpenFile (uri.LocalPath); - ArtistName = Choose(file.Tag.JoinedAlbumArtists, ArtistName); - AlbumTitle = Choose(file.Tag.Album, AlbumTitle); - TrackTitle = Choose(file.Tag.Title, TrackTitle); - Genre = Choose(file.Tag.FirstGenre, Genre); + ArtistName = Choose (file.Tag.JoinedAlbumArtists, ArtistName); + AlbumTitle = Choose (file.Tag.Album, AlbumTitle); + TrackTitle = Choose (file.Tag.Title, TrackTitle); + Genre = Choose (file.Tag.FirstGenre, Genre); Disc = file.Tag.Disc == 0 ? (int)Disc : (int)file.Tag.Disc; TrackNumber = file.Tag.Track == 0 ? (int)TrackNumber : (int)file.Tag.Track; TrackCount = file.Tag.TrackCount == 0 ? (int)TrackCount : (int)file.Tag.TrackCount; @@ -63,7 +63,7 @@ namespace Banshee.Collection DateAdded = DateTime.Now; } - private void ParsePath(string path) + private void ParsePath (string path) { ArtistName = String.Empty; AlbumTitle = String.Empty; @@ -71,71 +71,72 @@ namespace Banshee.Collection TrackNumber = 0; Match match; - SafeUri uri = new SafeUri(path); - string fileName = path; - if(uri.IsLocalPath) { - fileName = uri.AbsolutePath; + SafeUri uri = new SafeUri (path); + string filename = path; + if (uri.IsLocalPath) { + filename = uri.AbsolutePath; } - match = Regex.Match(fileName, @"(\d+)\.? *(.*)$"); - if(match.Success) { - TrackNumber = Convert.ToInt32(match.Groups[1].ToString()); - fileName = match.Groups[2].ToString().Trim(); + match = Regex.Match (filename, @"(\d+)\.? *(.*)$"); + if (match.Success) { + TrackNumber = Convert.ToInt32 (match.Groups[1].ToString ()); + filename = match.Groups[2].ToString ().Trim (); } - /* Artist - Album - Title */ - match = Regex.Match(fileName, @"\s*(.*)-\s*(.*)-\s*(.*)$"); - if(match.Success) { - ArtistName = match.Groups[1].ToString(); - AlbumTitle = match.Groups[2].ToString(); - TrackTitle = match.Groups[3].ToString(); + // Artist - Album - Title + match = Regex.Match (filename, @"\s*(.*)-\s*(.*)-\s*(.*)$"); + if (match.Success) { + ArtistName = match.Groups[1].ToString (); + AlbumTitle = match.Groups[2].ToString (); + TrackTitle = match.Groups[3].ToString (); } else { - /* Artist - Title */ - match = Regex.Match(fileName, @"\s*(.*)-\s*(.*)$"); - if(match.Success) { - ArtistName = match.Groups[1].ToString(); - TrackTitle = match.Groups[2].ToString(); + // Artist - Title + match = Regex.Match (filename, @"\s*(.*)-\s*(.*)$"); + if (match.Success) { + ArtistName = match.Groups[1].ToString (); + TrackTitle = match.Groups[2].ToString (); } else { - /* Title */ - TrackTitle = fileName; + // Title + TrackTitle = filename; } } - while(!String.IsNullOrEmpty(path)) { - fileName = Path.GetFileName(path); - path = Path.GetDirectoryName(path); - if(AlbumTitle == String.Empty) { - AlbumTitle = fileName; + while (!String.IsNullOrEmpty (path)) { + filename = Path.GetFileName (path); + path = Path.GetDirectoryName (path); + if (AlbumTitle == String.Empty) { + AlbumTitle = filename; continue; } - if(ArtistName == String.Empty) { - ArtistName = fileName; + if (ArtistName == String.Empty) { + ArtistName = filename; continue; } + break; } - ArtistName = ArtistName.Trim(); - AlbumTitle = AlbumTitle.Trim(); - TrackTitle = TrackTitle.Trim(); + ArtistName = ArtistName.Trim (); + AlbumTitle = AlbumTitle.Trim (); + TrackTitle = TrackTitle.Trim (); - if(ArtistName.Length == 0) { + if (ArtistName.Length == 0) { ArtistName = /*"Unknown Artist"*/ null; } - if(AlbumTitle.Length == 0) { + if (AlbumTitle.Length == 0) { AlbumTitle = /*"Unknown Album"*/ null; } - if(TrackTitle.Length == 0) { + if (TrackTitle.Length == 0) { TrackTitle = /*"Unknown Title"*/ null; } } - private static string Choose(string priority, string fallback) + private static string Choose (string priority, string fallback) { - return (priority == null || priority.Length == 0) ? fallback : priority; + return String.IsNullOrEmpty (priority) ? fallback : priority; } } } diff --git a/src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs b/src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs index 712569976..8162f2194 100644 --- a/src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs +++ b/src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs @@ -36,9 +36,7 @@ namespace Banshee.Configuration private static IConfigurationClient Client { get { if(client == null) { - client = Environment.OSVersion.Platform == PlatformID.Unix - ? (IConfigurationClient) new GConfConfigurationClient() - : new XmlConfigurationClient(); + client = new XmlConfigurationClient(); } return client; } diff --git a/src/Core/Banshee.Core/Banshee.Core.mdp b/src/Core/Banshee.Core/Banshee.Core.mdp index 335d7a1b1..2c4fcd239 100644 --- a/src/Core/Banshee.Core/Banshee.Core.mdp +++ b/src/Core/Banshee.Core/Banshee.Core.mdp @@ -14,7 +14,6 @@ <File name="Banshee.Kernel/JobPriority.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Kernel/Scheduler.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Configuration/ConfigurationClient.cs" subtype="Code" buildaction="Compile" /> - <File name="Banshee.Configuration/GConfConfigurationClient.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Configuration/IConfigurationClient.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Configuration/SchemaEntry.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Base/FileNamePattern.cs" subtype="Code" buildaction="Compile" /> @@ -26,11 +25,9 @@ <File name="Banshee.Collection/ArtistInfo.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Collection/ITrackInfo.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Collection/TrackInfo.cs" subtype="Code" buildaction="Compile" /> - <File name="Banshee.IO/GnomeVfs.cs" subtype="Code" buildaction="Compile" /> - <File name="Banshee.IO/Interfaces.cs" subtype="Code" buildaction="Compile" /> - <File name="Banshee.IO/IOProxy.cs" subtype="Code" buildaction="Compile" /> - <File name="Banshee.IO/SystemIO.cs" subtype="Code" buildaction="Compile" /> - <File name="Banshee.IO/Unix.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/IProvider.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/Provider.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/UnixIOProvider.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.IO/Utilities.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Base/ApplicationContext.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Collection/FileTrackInfo.cs" subtype="Code" buildaction="Compile" /> @@ -56,7 +53,22 @@ <File name="Banshee.Base/Localization.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Configuration/XmlConfigurationClient.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Base/CoverArtSpec.cs" subtype="Code" buildaction="Compile" /> - <File name="Banshee.Base/RateLimiter.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.I18n/AssemblyCatalogAttribute.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.I18n/Catalog.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/IFile.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/IDirectory.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/Directory.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO.SystemIO" subtype="Directory" buildaction="Compile" /> + <File name="Banshee.IO.SystemIO/Directory.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO.SystemIO/File.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO.SystemIO/Provider.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/IDemuxVfs.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/File.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO.SystemIO/DemuxVfs.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.Base/Resource.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/DemuxVfs.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.IO/StreamAssist.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.Base/NamingUtil.cs" subtype="Code" buildaction="Compile" /> </Contents> <References> <ProjectReference type="Project" localcopy="False" refto="Hyena" /> diff --git a/src/Core/Banshee.Core/Banshee.I18n/AssemblyCatalogAttribute.cs b/src/Core/Banshee.Core/Banshee.I18n/AssemblyCatalogAttribute.cs new file mode 100644 index 000000000..fc3058b52 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.I18n/AssemblyCatalogAttribute.cs @@ -0,0 +1,53 @@ +// +// AssemblyCatalogAttribute.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; + +namespace Banshee.I18n +{ + [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = false, Inherited = true)] + public class AssemblyCatalogAttribute : Attribute + { + private string domain; + private string localedir; + + public AssemblyCatalogAttribute (string domain, string localedir) + { + this.domain = domain; + this.localedir = localedir; + } + + public string Domain { + get { return domain; } + } + + public string LocaleDir { + get { return localedir; } + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.I18n/Catalog.cs b/src/Core/Banshee.Core/Banshee.I18n/Catalog.cs index 309209a41..1e180b133 100644 --- a/src/Core/Banshee.Core/Banshee.I18n/Catalog.cs +++ b/src/Core/Banshee.Core/Banshee.I18n/Catalog.cs @@ -1,205 +1,199 @@ // -// Catalog.cs: Bindings for libintl +// Catalog.cs // -// Authors: -// Aaron Bockover (abockover@novell.com) +// Author: +// Aaron Bockover <abockover@novell.com> // -// (C) 2006 Novell, Inc. +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Reflection; -using System.Collections; +using System.Collections.Generic; using System.Runtime.InteropServices; using Mono.Unix; -namespace Mono.Gettext +namespace Banshee.I18n { - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false, Inherited=true)] - public class AssemblyCatalogAttribute : Attribute + public static class Catalog { - private string domain; - private string localedir; - - public AssemblyCatalogAttribute(string domain, string localedir) - { - this.domain = domain; - this.localedir = localedir; - } - - public string Domain { - get { return domain; } - } - - public string LocaleDir { - get { return localedir; } - } - } - - public sealed /* static */ class Catalog - { - private Catalog() - { - } - - private static Hashtable domain_assembly_map = new Hashtable(); - private static ArrayList default_domain_assemblies = new ArrayList(); + private static Dictionary<Assembly, string> domain_assembly_map = new Dictionary<Assembly, string> (); + private static List<Assembly> default_domain_assemblies = new List<Assembly> (); - public static void Init(string domain, string localeDir) + public static void Init (string domain, string localeDir) { - if(domain == null || domain.Length == 0) { - throw new ArgumentException("No text domain specified"); + if (String.IsNullOrEmpty (domain)) { + throw new ArgumentException ("No text domain specified"); } - IntPtr domain_ptr = UnixMarshal.StringToHeap(domain); + IntPtr domain_ptr = UnixMarshal.StringToHeap (domain); IntPtr localedir_ptr = IntPtr.Zero; try { - BindTextDomainCodeset(domain_ptr); + BindTextDomainCodeset (domain_ptr); - if(localeDir != null && localeDir.Length > 0) { - localedir_ptr = UnixMarshal.StringToHeap(localeDir); - BindTextDomain(domain_ptr, localedir_ptr); + if (localeDir != null && localeDir.Length > 0) { + localedir_ptr = UnixMarshal.StringToHeap (localeDir); + BindTextDomain (domain_ptr, localedir_ptr); } } finally { - UnixMarshal.FreeHeap(domain_ptr); - if(localedir_ptr != IntPtr.Zero) { - UnixMarshal.FreeHeap(localedir_ptr); + UnixMarshal.FreeHeap (domain_ptr); + if (localedir_ptr != IntPtr.Zero) { + UnixMarshal.FreeHeap (localedir_ptr); } } } - public static string GetString(string msgid) + public static string GetString (string msgid) { - return GetString(GetDomainForAssembly(Assembly.GetCallingAssembly()), msgid); + return GetString (GetDomainForAssembly (Assembly.GetCallingAssembly ()), msgid); } - public static string GetString(string domain, string msgid) + public static string GetString (string domain, string msgid) { - IntPtr msgid_ptr = UnixMarshal.StringToHeap(msgid); - IntPtr domain_ptr = domain == null ? IntPtr.Zero : UnixMarshal.StringToHeap(domain); + IntPtr msgid_ptr = UnixMarshal.StringToHeap (msgid); + IntPtr domain_ptr = domain == null ? IntPtr.Zero : UnixMarshal.StringToHeap (domain); - if(domain == null) { - IntPtr ptr = UnixMarshal.StringToHeap("banshee"); - UnixMarshal.FreeHeap(ptr); + if (domain == null) { + IntPtr ptr = UnixMarshal.StringToHeap ("banshee"); + UnixMarshal.FreeHeap (ptr); } try { IntPtr ret_ptr = domain_ptr == IntPtr.Zero ? - gettext(msgid_ptr) : - dgettext(domain_ptr, msgid_ptr); + gettext (msgid_ptr) : + dgettext (domain_ptr, msgid_ptr); - if(msgid_ptr != ret_ptr) { - return UnixMarshal.PtrToStringUnix(ret_ptr); + if (msgid_ptr != ret_ptr) { + return UnixMarshal.PtrToStringUnix (ret_ptr); } return msgid; } finally { - UnixMarshal.FreeHeap(msgid_ptr); - if(domain_ptr != IntPtr.Zero) { - UnixMarshal.FreeHeap(domain_ptr); + UnixMarshal.FreeHeap (msgid_ptr); + if (domain_ptr != IntPtr.Zero) { + UnixMarshal.FreeHeap (domain_ptr); } } } - public static string GetString(string msgid, string msgidPlural, int n) + public static string GetString (string msgid, string msgidPlural, int n) { - return GetString(GetDomainForAssembly(Assembly.GetCallingAssembly()), msgid, msgidPlural, n); + return GetString (GetDomainForAssembly (Assembly.GetCallingAssembly ()), msgid, msgidPlural, n); } - public static string GetPluralString(string msgid, string msgidPlural, int n) + public static string GetPluralString (string msgid, string msgidPlural, int n) { - return GetString(GetDomainForAssembly(Assembly.GetCallingAssembly()), msgid, msgidPlural, n); + return GetString (msgid, msgidPlural, n); } - public static string GetString(string domain, string msgid, string msgidPlural, int n) + public static string GetString (string domain, string msgid, string msgidPlural, int n) { - IntPtr msgid_ptr = UnixMarshal.StringToHeap(msgid); - IntPtr msgid_plural_ptr = UnixMarshal.StringToHeap(msgidPlural); - IntPtr domain_ptr = domain == null ? IntPtr.Zero : UnixMarshal.StringToHeap(domain); + IntPtr msgid_ptr = UnixMarshal.StringToHeap (msgid); + IntPtr msgid_plural_ptr = UnixMarshal.StringToHeap (msgidPlural); + IntPtr domain_ptr = domain == null ? IntPtr.Zero : UnixMarshal.StringToHeap (domain); try { IntPtr ret_ptr = domain_ptr == IntPtr.Zero ? - ngettext(msgid_ptr, msgid_plural_ptr, n) : - dngettext(domain_ptr, msgid_ptr, msgid_plural_ptr, n); + ngettext (msgid_ptr, msgid_plural_ptr, n) : + dngettext (domain_ptr, msgid_ptr, msgid_plural_ptr, n); - if(ret_ptr == msgid_ptr) { + if (ret_ptr == msgid_ptr) { return msgid; - } else if(ret_ptr == msgid_plural_ptr) { + } else if (ret_ptr == msgid_plural_ptr) { return msgidPlural; } - return UnixMarshal.PtrToStringUnix(ret_ptr); + return UnixMarshal.PtrToStringUnix (ret_ptr); } finally { - UnixMarshal.FreeHeap(msgid_ptr); - UnixMarshal.FreeHeap(msgid_plural_ptr); - if(domain_ptr != IntPtr.Zero) { - UnixMarshal.FreeHeap(domain_ptr); + UnixMarshal.FreeHeap (msgid_ptr); + UnixMarshal.FreeHeap (msgid_plural_ptr); + if (domain_ptr != IntPtr.Zero) { + UnixMarshal.FreeHeap (domain_ptr); } } } - private static string GetDomainForAssembly(Assembly assembly) + private static string GetDomainForAssembly (Assembly assembly) { - if(default_domain_assemblies.Contains(assembly)) { + if (default_domain_assemblies.Contains (assembly)) { return null; - } else if(domain_assembly_map.ContainsKey(assembly)) { - return domain_assembly_map[assembly] as string; + } else if (domain_assembly_map.ContainsKey (assembly)) { + return domain_assembly_map[assembly]; } - AssemblyCatalogAttribute [] attributes = assembly.GetCustomAttributes( + AssemblyCatalogAttribute [] attributes = assembly.GetCustomAttributes ( typeof(AssemblyCatalogAttribute), true) as AssemblyCatalogAttribute []; - if(attributes == null || attributes.Length == 0) { - default_domain_assemblies.Add(assembly); + if (attributes == null || attributes.Length == 0) { + default_domain_assemblies.Add (assembly); return null; } string domain = attributes[0].Domain; - Init(domain, attributes[0].LocaleDir); - domain_assembly_map.Add(assembly, domain); + Init (domain, attributes[0].LocaleDir); + domain_assembly_map.Add (assembly, domain); return domain; } - private static void BindTextDomainCodeset(IntPtr domain) + private static void BindTextDomainCodeset (IntPtr domain) { IntPtr codeset = UnixMarshal.StringToHeap("UTF-8"); try { - if(bind_textdomain_codeset(domain, codeset) == IntPtr.Zero) { - throw new UnixIOException(Mono.Unix.Native.Errno.ENOMEM); + if (bind_textdomain_codeset (domain, codeset) == IntPtr.Zero) { + throw new UnixIOException (Mono.Unix.Native.Errno.ENOMEM); } } finally { - UnixMarshal.FreeHeap(codeset); + UnixMarshal.FreeHeap (codeset); } } - private static void BindTextDomain(IntPtr domain, IntPtr localedir) + private static void BindTextDomain (IntPtr domain, IntPtr localedir) { - if(bindtextdomain(domain, localedir) == IntPtr.Zero) { - throw new UnixIOException(Mono.Unix.Native.Errno.ENOMEM); + if (bindtextdomain (domain, localedir) == IntPtr.Zero) { + throw new UnixIOException (Mono.Unix.Native.Errno.ENOMEM); } } - [DllImport("intl")] - private static extern IntPtr bind_textdomain_codeset(IntPtr domain, IntPtr codeset); + [DllImport ("intl")] + private static extern IntPtr bind_textdomain_codeset (IntPtr domain, IntPtr codeset); - [DllImport("intl")] - private static extern IntPtr bindtextdomain(IntPtr domain, IntPtr locale_dir); + [DllImport ("intl")] + private static extern IntPtr bindtextdomain (IntPtr domain, IntPtr locale_dir); - [DllImport("intl")] - private static extern IntPtr dgettext(IntPtr domain, IntPtr msgid); + [DllImport ("intl")] + private static extern IntPtr dgettext (IntPtr domain, IntPtr msgid); - [DllImport("intl")] - private static extern IntPtr dngettext(IntPtr domain, IntPtr msgid_singular, IntPtr msgid_plural, Int32 n); + [DllImport ("intl")] + private static extern IntPtr dngettext (IntPtr domain, IntPtr msgid_singular, IntPtr msgid_plural, Int32 n); - [DllImport("intl")] - private static extern IntPtr gettext(IntPtr msgid); + [DllImport ("intl")] + private static extern IntPtr gettext (IntPtr msgid); - [DllImport("intl")] - private static extern IntPtr ngettext(IntPtr msgid_singular, IntPtr msgid_plural, Int32 n); + [DllImport ("intl")] + private static extern IntPtr ngettext (IntPtr msgid_singular, IntPtr msgid_plural, Int32 n); } } diff --git a/src/Core/Banshee.Core/Banshee.IO.SystemIO/DemuxVfs.cs b/src/Core/Banshee.Core/Banshee.IO.SystemIO/DemuxVfs.cs new file mode 100644 index 000000000..99bc98aa5 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO.SystemIO/DemuxVfs.cs @@ -0,0 +1,84 @@ +// +// DemuxVfs.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; + +using Banshee.Base; + +namespace Banshee.IO.SystemIO +{ + public class DemuxVfs : Banshee.IO.IDemuxVfs + { + private FileInfo file_info; + + public DemuxVfs (string path) + { + file_info = new FileInfo (path); + } + + public void CloseStream (Stream stream) + { + stream.Close (); + } + + public string Name { + get { return file_info.FullName; } + } + + public Stream ReadStream { + get { return file_info.Open (FileMode.Open, FileAccess.Read); } + } + + public Stream WriteStream { + get { return file_info.Open (FileMode.Open, FileAccess.ReadWrite); } + } + + public bool IsReadable { + get { + try { + ReadStream.Close (); + return true; + } catch { + return false; + } + } + } + + public bool IsWritable { + get { + try { + WriteStream.Close (); + return true; + } catch { + return false; + } + } + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO.SystemIO/Directory.cs b/src/Core/Banshee.Core/Banshee.IO.SystemIO/Directory.cs new file mode 100644 index 000000000..8251f2942 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO.SystemIO/Directory.cs @@ -0,0 +1,73 @@ +// +// Directory.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Generic; + +using Banshee.Base; + +namespace Banshee.IO.SystemIO +{ + public class Directory : Banshee.IO.IDirectory + { + public void Create (string directory) + { + System.IO.Directory.CreateDirectory (directory); + } + + public void Delete (string directory) + { + Delete (directory, false); + } + + public void Delete (string directory, bool recursive) + { + System.IO.Directory.Delete (directory, recursive); + } + + public bool Exists (string directory) + { + return System.IO.Directory.Exists (directory); + } + + public IEnumerable<string> GetFiles (string directory) + { + return System.IO.Directory.GetFiles (directory); + } + + public IEnumerable<string> GetDirectories (string directory) + { + return System.IO.Directory.GetDirectories (directory); + } + + public void Move (SafeUri from, SafeUri to) + { + System.IO.Directory.Move (from.LocalPath, to.LocalPath); + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO.SystemIO/File.cs b/src/Core/Banshee.Core/Banshee.IO.SystemIO/File.cs new file mode 100644 index 000000000..9476f1c1b --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO.SystemIO/File.cs @@ -0,0 +1,74 @@ +// +// File.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; + +using Banshee.Base; + +namespace Banshee.IO.SystemIO +{ + public class File : Banshee.IO.IFile + { + public void Delete (SafeUri uri) + { + System.IO.File.Delete (uri.LocalPath); + } + + public bool Exists (SafeUri uri) + { + return System.IO.File.Exists (uri.LocalPath); + } + + public void Move (SafeUri from, SafeUri to) + { + System.IO.File.Move (from.LocalPath, to.LocalPath); + } + + public long GetSize (SafeUri uri) + { + try { + return new System.IO.FileInfo (uri.LocalPath).Length; + } catch { + return -1; + } + } + + public System.IO.Stream OpenRead (SafeUri uri) + { + return System.IO.File.OpenRead (uri.LocalPath); + } + + public System.IO.Stream OpenWrite (SafeUri uri, bool overwrite) + { + return overwrite + ? System.IO.File.Open (uri.LocalPath, FileMode.Create, FileAccess.ReadWrite) + : System.IO.File.OpenWrite (uri.LocalPath); + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO.SystemIO/Provider.cs b/src/Core/Banshee.Core/Banshee.IO.SystemIO/Provider.cs new file mode 100644 index 000000000..409e3e173 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO.SystemIO/Provider.cs @@ -0,0 +1,47 @@ +// +// Provider.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; + +namespace Banshee.IO.SystemIO +{ + public class Provider : Banshee.IO.IProvider + { + public Type FileProvider { + get { return typeof (File); } + } + + public Type DirectoryProvider { + get { return typeof (Directory); } + } + + public Type DemuxVfsProvider { + get { return typeof (DemuxVfs); } + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/DemuxVfs.cs b/src/Core/Banshee.Core/Banshee.IO/DemuxVfs.cs new file mode 100644 index 000000000..64e722b4c --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/DemuxVfs.cs @@ -0,0 +1,46 @@ +// +// DemuxVfs.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using TagLib; + +namespace Banshee.IO +{ + public static class DemuxVfs + { + public static TagLib.File OpenFile (string file, string mimetype, TagLib.ReadStyle readStyle) + { + return TagLib.File.Create (Provider.CreateDemuxVfs (file), mimetype, readStyle); + } + + public static TagLib.File OpenFile (string file) + { + return TagLib.File.Create (Provider.CreateDemuxVfs (file)); + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/Directory.cs b/src/Core/Banshee.Core/Banshee.IO/Directory.cs new file mode 100644 index 000000000..ee34bcb6c --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/Directory.cs @@ -0,0 +1,73 @@ +// +// Directory.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Generic; + +using Banshee.Base; + +namespace Banshee.IO +{ + public static class Directory + { + public static bool Exists (string directory) + { + return Provider.Directory.Exists (directory); + } + + public static void Create (string directory) + { + Provider.Directory.Create (directory); + } + + public static void Move (SafeUri from, SafeUri to) + { + Provider.Directory.Move (from, to); + } + + public static void Delete (string directory) + { + Provider.Directory.Delete (directory); + } + + public static void Delete (string directory, bool recursive) + { + Provider.Directory.Delete (directory, recursive); + } + + public static IEnumerable<string> GetFiles (string directory) + { + return Provider.Directory.GetFiles (directory); + } + + public static IEnumerable<string> GetDirectories (string directory) + { + return Provider.Directory.GetDirectories (directory); + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/File.cs b/src/Core/Banshee.Core/Banshee.IO/File.cs new file mode 100644 index 000000000..d2f7f21f1 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/File.cs @@ -0,0 +1,67 @@ +// +// File.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; + +using Banshee.Base; + +namespace Banshee.IO +{ + public static class File + { + public static void Delete (SafeUri uri) + { + Provider.File.Delete (uri); + } + + public static bool Exists (SafeUri uri) + { + return Provider.File.Exists (uri); + } + + public static void Move (SafeUri from, SafeUri to) + { + Provider.File.Move (from, to); + } + + public static long GetSize (SafeUri uri) + { + return Provider.File.GetSize (uri); + } + + public static System.IO.Stream OpenRead (SafeUri uri) + { + return Provider.File.OpenRead (uri); + } + + public static System.IO.Stream OpenWrite (SafeUri uri, bool overwrite) + { + return Provider.File.OpenWrite (uri, overwrite); + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/IDemuxVfs.cs b/src/Core/Banshee.Core/Banshee.IO/IDemuxVfs.cs new file mode 100644 index 000000000..f8d58d40d --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/IDemuxVfs.cs @@ -0,0 +1,34 @@ +// +// IDemuxVfs.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Banshee.IO +{ + public interface IDemuxVfs : TagLib.File.IFileAbstraction + { + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/IDirectory.cs b/src/Core/Banshee.Core/Banshee.IO/IDirectory.cs new file mode 100644 index 000000000..b1134be08 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/IDirectory.cs @@ -0,0 +1,50 @@ +// +// IDirectory.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Generic; + +using Banshee.Base; + +namespace Banshee.IO +{ + public interface IDirectory + { + bool Exists (string directory); + + void Create (string directory); + void Move (SafeUri from, SafeUri to); + + void Delete (string directory); + void Delete (string directory, bool recursive); + + // FIXME: These probably need to normalize to SafeUri + IEnumerable<string> GetFiles (string directory); + IEnumerable<string> GetDirectories (string directory); + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/IFile.cs b/src/Core/Banshee.Core/Banshee.IO/IFile.cs new file mode 100644 index 000000000..6143b4d88 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/IFile.cs @@ -0,0 +1,45 @@ +// +// IFile.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; + +using Banshee.Base; + +namespace Banshee.IO +{ + public interface IFile + { + void Delete (SafeUri uri); + bool Exists (SafeUri uri); + void Move (SafeUri from, SafeUri to); + long GetSize (SafeUri uri); + + System.IO.Stream OpenRead (SafeUri uri); + System.IO.Stream OpenWrite (SafeUri uri, bool overwrite); + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/IOProxy.cs b/src/Core/Banshee.Core/Banshee.IO/IOProxy.cs deleted file mode 100644 index 332d070aa..000000000 --- a/src/Core/Banshee.Core/Banshee.IO/IOProxy.cs +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************** - * IOProxy.cs - * - * Copyright (C) 2006 Novell, Inc. - * Written by Aaron Bockover <aaron@abock.org> - ****************************************************************************/ - -/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -using System; -using System.Reflection; - -using Banshee.Base; -using Banshee.Configuration; - -namespace Banshee.IO -{ - public static class IOProxy - { - private static IDirectory directory; - private static IFile file; - private static IIOConfig config; - - private static Type [] available_config_types = new Type [] { - typeof(Banshee.IO.SystemIO.IOConfig), - typeof(Banshee.IO.Unix.IOConfig), - typeof(Banshee.IO.GnomeVfs.IOConfig) - }; - - static IOProxy() - { - Reload(); - } - - public static void SetFromConfig(IIOConfig _config) - { - config = _config; - Log.DebugFormat("Setting IO Backend to {0} ({1})", config.GetType(), config.Name); - - file = (IFile)Activator.CreateInstance(config.FileBackend); - directory = (IDirectory)Activator.CreateInstance(config.DirectoryBackend); - } - - public static TagLib.File OpenFile(string file, string mimetype, TagLib.ReadStyle readStyle) - { - return TagLib.File.Create(TagLibVfsCreator (file), mimetype, readStyle); - } - - public static TagLib.File OpenFile(string file) - { - return TagLib.File.Create(TagLibVfsCreator (file)); - } - - private static TagLib.File.IFileAbstraction TagLibVfsCreator(string file) - { - return (IDemuxVfs)Activator.CreateInstance(config.DemuxVfsBackend, new object [] { file }); - } - - public static void Reload() - { - string name = IOBackendSchema.Get(); - - foreach(Type type in available_config_types) { - try { - IIOConfig config = (IIOConfig)Activator.CreateInstance(type); - if(config.Name == name) { - SetFromConfig(config); - return; - } - } catch { - } - } - } - - public static IDirectory Directory { - get { return directory; } - } - - public static IFile File { - get { return file; } - } - - public static string DetectMimeType(SafeUri uri) - { - return config.DetectMimeType(uri); - } - - public static readonly SchemaEntry<string> IOBackendSchema = new SchemaEntry<string>( - "core", "io_backend", - "unix", - "Set the IO backend in Banshee", - "Can be either \"systemio\" (.NET System.IO), \"unix\" (Native Unix), or " + - "\"gnomevfs\" (GNOME VFS); takes effect on Banshee start (restart necessary)" - ); - - } -} diff --git a/src/Core/Banshee.Core/Banshee.IO/IProvider.cs b/src/Core/Banshee.Core/Banshee.IO/IProvider.cs new file mode 100644 index 000000000..2010f19d6 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/IProvider.cs @@ -0,0 +1,39 @@ +// +// IProvider.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; + +namespace Banshee.IO +{ + public interface IProvider + { + Type FileProvider { get; } + Type DirectoryProvider { get; } + Type DemuxVfsProvider { get; } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/Interfaces.cs b/src/Core/Banshee.Core/Banshee.IO/Interfaces.cs deleted file mode 100644 index 0f918c93a..000000000 --- a/src/Core/Banshee.Core/Banshee.IO/Interfaces.cs +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** - * Interfaces.cs - * - * Copyright (C) 2006 Novell, Inc. - * Written by Aaron Bockover <aaron@abock.org> - ****************************************************************************/ - -/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -using System; -using System.Collections; - -using Banshee.Base; - -namespace Banshee.IO -{ - public interface IIOConfig - { - string Name { get; } - Type FileBackend { get; } - Type DirectoryBackend { get; } - Type DemuxVfsBackend { get; } - - string DetectMimeType(SafeUri uri); - } - - public interface IFile - { - void Delete(SafeUri uri); - bool Exists(SafeUri uri); - void Move(SafeUri from, SafeUri to); - System.IO.Stream OpenRead(SafeUri uri); - System.IO.Stream OpenWrite(SafeUri uri, bool overwrite); - long GetSize (SafeUri uri); - } - - public interface IDirectory - { - void Create(string directory); - void Delete(string directory); - void Delete(string directory, bool recursive); - bool Exists(string directory); - IEnumerable GetFiles(string directory); - IEnumerable GetDirectories(string directory); - void Move(SafeUri from, SafeUri to); - } - - public interface IDemuxVfs : TagLib.File.IFileAbstraction - { - } -} diff --git a/src/Core/Banshee.Core/Banshee.IO/Provider.cs b/src/Core/Banshee.Core/Banshee.IO/Provider.cs new file mode 100644 index 000000000..c92877220 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/Provider.cs @@ -0,0 +1,69 @@ +// +// Provider.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2006-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Reflection; + +using Banshee.Base; +using Banshee.Configuration; + +namespace Banshee.IO +{ + internal static class Provider + { + private static IProvider provider; + private static IDirectory directory; + private static IFile file; + + private static void LoadProvider () + { + lock (typeof (Provider)) { + if (provider != null) { + return; + } + + provider = new Banshee.IO.SystemIO.Provider (); + directory = (IDirectory)Activator.CreateInstance (provider.DirectoryProvider); + file = (IFile)Activator.CreateInstance (provider.FileProvider); + } + } + + public static IDirectory Directory { + get { LoadProvider (); return directory; } + } + + public static IFile File { + get { LoadProvider (); return file; } + } + + public static IDemuxVfs CreateDemuxVfs (string file) + { + return (IDemuxVfs)Activator.CreateInstance (provider.DemuxVfsProvider, new object [] { file }); + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs b/src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs new file mode 100644 index 000000000..551141f71 --- /dev/null +++ b/src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs @@ -0,0 +1,57 @@ +// +// StreamAssist.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; + +namespace Banshee.IO +{ + public static class StreamAssist + { + public static void Save (Stream from, Stream to) + { + Save (from, to, 8192); + } + + public static void Save (Stream from, Stream to, int bufferSize) + { + using (from) { + long bytes_read = 0; + using (to) { + byte [] buffer = new byte[bufferSize]; + int chunk_bytes_read = 0; + + while ((chunk_bytes_read = from.Read (buffer, 0, buffer.Length)) > 0) { + to.Write (buffer, 0, chunk_bytes_read); + bytes_read += chunk_bytes_read; + } + } + } + } + } +} diff --git a/src/Core/Banshee.Core/Banshee.IO/SystemIO.cs b/src/Core/Banshee.Core/Banshee.IO/SystemIO.cs deleted file mode 100644 index acdf5b2fc..000000000 --- a/src/Core/Banshee.Core/Banshee.IO/SystemIO.cs +++ /dev/null @@ -1,175 +0,0 @@ -/*************************************************************************** - * SystemIO.cs - * - * Copyright (C) 2006 Novell, Inc. - * Written by Aaron Bockover <aaron@abock.org> - ****************************************************************************/ - -/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -using System; -using System.IO; -using System.Collections; - -using Banshee.Base; - -namespace Banshee.IO.SystemIO -{ - public class IOConfig : IIOConfig - { - public string Name { get { return "systemio"; } } - public Type FileBackend { get { return typeof(File); } } - public Type DirectoryBackend { get { return typeof(Directory); } } - public Type DemuxVfsBackend { get { return typeof(DemuxVfs); } } - - public string DetectMimeType(SafeUri uri) - { - return Banshee.IO.GnomeVfs.IOConfig._DetectMimeType(uri); - } - } - - public class File : IFile - { - public void Delete(SafeUri uri) - { - System.IO.File.Delete(uri.LocalPath); - } - - public bool Exists(SafeUri uri) - { - return System.IO.File.Exists(uri.LocalPath); - } - - public void Move(SafeUri from, SafeUri to) - { - System.IO.File.Move(from.LocalPath, to.LocalPath); - } - - public System.IO.Stream OpenRead(SafeUri uri) - { - return System.IO.File.OpenRead(uri.LocalPath); - } - - public System.IO.Stream OpenWrite(SafeUri uri, bool overwrite) - { - return overwrite - ? System.IO.File.Open(uri.LocalPath, FileMode.Create, FileAccess.ReadWrite) - : System.IO.File.OpenWrite(uri.LocalPath); - } - - public long GetSize (SafeUri uri) - { - try { - return new System.IO.FileInfo (uri.LocalPath).Length; - } catch { - return -1; - } - } - } - - public class Directory : IDirectory - { - public void Create(string directory) - { - System.IO.Directory.CreateDirectory(directory); - } - - public void Delete(string directory) - { - Delete(directory, false); - } - - public void Delete(string directory, bool recursive) - { - System.IO.Directory.Delete(directory, recursive); - } - - public bool Exists(string directory) - { - return System.IO.Directory.Exists(directory); - } - - public IEnumerable GetFiles(string directory) - { - return System.IO.Directory.GetFiles(directory); - } - - public IEnumerable GetDirectories(string directory) - { - return System.IO.Directory.GetDirectories(directory); - } - - public void Move(SafeUri from, SafeUri to) - { - System.IO.Directory.Move(from.LocalPath, to.LocalPath); - } - } - - public class DemuxVfs: IDemuxVfs - { - private FileInfo file_info; - - public DemuxVfs(string path) - { - file_info = new FileInfo(path); - } - - public void CloseStream(Stream stream) - { - stream.Close(); - } - - public string Name { - get { return file_info.FullName; } - } - - public Stream ReadStream { - get { return file_info.Open(FileMode.Open, FileAccess.Read); } - } - - public Stream WriteStream { - get { return file_info.Open(FileMode.Open, FileAccess.ReadWrite); } - } - - public bool IsReadable { - get { - try { - ReadStream.Close(); - return true; - } catch { - return false; - } - } - } - - public bool IsWritable { - get { - try { - WriteStream.Close(); - return true; - } catch { - return false; - } - } - } - } -} diff --git a/src/Core/Banshee.Core/Banshee.IO/Unix.cs b/src/Core/Banshee.Core/Banshee.IO/UnixIOProvider.cs index 18efb48d8..696a8118f 100644 --- a/src/Core/Banshee.Core/Banshee.IO/Unix.cs +++ b/src/Core/Banshee.Core/Banshee.IO/UnixIOProvider.cs @@ -25,7 +25,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ - +/* using System; using System.IO; using System.Collections; @@ -134,7 +134,7 @@ namespace Banshee.IO.Unix throw new Exception("Failed to allocate native directory string"); } - if(g_mkdir_with_parents(path_ptr, 493 /*0755 - C# doesn't do octal literals*/) == -1) { + if(g_mkdir_with_parents(path_ptr, 493 /*0755 - C# doesn't do octal literals*//*) == -1) { Mono.Unix.UnixMarshal.ThrowExceptionForLastError(); } } catch(EntryPointNotFoundException) { @@ -229,3 +229,4 @@ namespace Banshee.IO.Unix } } } +*/ diff --git a/src/Core/Banshee.Core/Banshee.IO/Utilities.cs b/src/Core/Banshee.Core/Banshee.IO/Utilities.cs index 99f7901c0..5cc2a00ff 100644 --- a/src/Core/Banshee.Core/Banshee.IO/Utilities.cs +++ b/src/Core/Banshee.Core/Banshee.IO/Utilities.cs @@ -36,7 +36,7 @@ namespace Banshee.IO { public static void DeleteFileTrimmingParentDirectories(SafeUri uri) { - Banshee.IO.IOProxy.File.Delete(uri); + /*Banshee.IO.IOProxy.File.Delete(uri); try { string old_dir = System.IO.Path.GetDirectoryName(uri.LocalPath); @@ -45,7 +45,7 @@ namespace Banshee.IO old_dir = System.IO.Path.GetDirectoryName(old_dir); } } catch { - } + }*/ } } } diff --git a/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs b/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs index bd7af4f80..25bc3552e 100644 --- a/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs +++ b/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs @@ -4,7 +4,7 @@ // Author: // Aaron Bockover <abockover@novell.com> // -// Copyright (C) 2006-2007 Novell, Inc. +// Copyright (C) 2006-2008 Novell, Inc. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -37,7 +37,7 @@ namespace Banshee.Streaming { public static TagLib.File ProcessUri (SafeUri uri) { - TagLib.File file = Banshee.IO.IOProxy.OpenFile (uri.IsLocalPath ? uri.LocalPath : uri.AbsoluteUri, + TagLib.File file = Banshee.IO.DemuxVfs.OpenFile (uri.IsLocalPath ? uri.LocalPath : uri.AbsoluteUri, null, TagLib.ReadStyle.Average); if (file.Properties.MediaTypes != TagLib.MediaTypes.Audio) { @@ -65,7 +65,7 @@ namespace Banshee.Streaming track.TrackCount = file.Tag.TrackCount == 0 ? track.TrackCount : (int)file.Tag.TrackCount; track.Year = (int)file.Tag.Year; track.Duration = file.Properties.Duration; - track.FileSize = Banshee.IO.IOProxy.File.GetSize (track.Uri); + track.FileSize = Banshee.IO.File.GetSize (track.Uri); } public static void TrackInfoMerge(TrackInfo track, StreamTag tag) diff --git a/src/Core/Banshee.Core/Makefile.am b/src/Core/Banshee.Core/Makefile.am index 1442cb5f4..3d04bbc6d 100644 --- a/src/Core/Banshee.Core/Makefile.am +++ b/src/Core/Banshee.Core/Makefile.am @@ -7,10 +7,11 @@ SOURCES = \ Banshee.Base/FileNamePattern.cs \ Banshee.Base/Localization.cs \ Banshee.Base/Log.cs \ + Banshee.Base/NamingUtil.cs \ Banshee.Base/Paths.cs \ Banshee.Base/PlatformHacks.cs \ Banshee.Base/ProductInformation.cs \ - Banshee.Base/RateLimiter.cs \ + Banshee.Base/Resource.cs \ Banshee.Base/SafeUri.cs \ Banshee.Base/StringUtil.cs \ Banshee.Base/UriList.cs \ @@ -28,15 +29,25 @@ SOURCES = \ Banshee.Configuration.Schema/ImportSchema.cs \ Banshee.Configuration.Schema/LibrarySchema.cs \ Banshee.Configuration/ConfigurationClient.cs \ - Banshee.Configuration/GConfConfigurationClient.cs \ Banshee.Configuration/IConfigurationClient.cs \ Banshee.Configuration/SchemaEntry.cs \ Banshee.Configuration/XmlConfigurationClient.cs \ - Banshee.IO/GnomeVfs.cs \ - Banshee.IO/Interfaces.cs \ - Banshee.IO/IOProxy.cs \ - Banshee.IO/SystemIO.cs \ - Banshee.IO/Unix.cs \ + Banshee.I18n/AssemblyCatalogAttribute.cs \ + Banshee.I18n/Catalog.cs \ + Banshee.IO.SystemIO/DemuxVfs.cs \ + Banshee.IO.SystemIO/Directory.cs \ + Banshee.IO.SystemIO/File.cs \ + Banshee.IO.SystemIO/Provider.cs \ + Banshee.IO/DemuxVfs.cs \ + Banshee.IO/Directory.cs \ + Banshee.IO/File.cs \ + Banshee.IO/IDemuxVfs.cs \ + Banshee.IO/IDirectory.cs \ + Banshee.IO/IFile.cs \ + Banshee.IO/IProvider.cs \ + Banshee.IO/Provider.cs \ + Banshee.IO/StreamAssist.cs \ + Banshee.IO/UnixIOProvider.cs \ Banshee.IO/Utilities.cs \ Banshee.Kernel/IInstanceCriticalJob.cs \ Banshee.Kernel/IJob.cs \ diff --git a/src/Core/Banshee.Services/Banshee.AudioProfiles/GConfProfileConfiguration.cs b/src/Core/Banshee.Services/Banshee.AudioProfiles/GConfProfileConfiguration.cs deleted file mode 100644 index cc8cfc222..000000000 --- a/src/Core/Banshee.Services/Banshee.AudioProfiles/GConfProfileConfiguration.cs +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * GConfProfileConfiguration.cs - * - * Copyright (C) 2006 Novell, Inc. - * Written by Aaron Bockover <aaron@abock.org> - ****************************************************************************/ - -/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -using System; -using System.Text; -using System.Xml; -using System.Collections; -using System.Collections.Generic; - -using GConf; - -namespace Banshee.AudioProfiles -{ - public class GConfProfileConfiguration : ProfileConfiguration - { - private string gconf_root; - private GConf.Client client; - - public GConfProfileConfiguration(Profile profile, string gconfRoot, string id) : base(profile, id) - { - client = new GConf.Client(); - this.gconf_root = gconfRoot; - } - - internal static string LoadActiveProfile(string gconfRoot, string id) - { - GConf.Client client = new GConf.Client(); - return (string)client.Get(gconfRoot + id + "/active_profile"); - } - - internal static void SaveActiveProfile(Profile profile, string gconfRoot, string id) - { - GConf.Client client = new GConf.Client(); - client.Set(gconfRoot + id + "/active_profile", profile.ID); - } - - protected override void Load() - { - try { - foreach(string variable in (string [])client.Get(gconf_root + "variables")) { - Add(variable, (string)client.Get(gconf_root + variable)); - } - } catch { - } - } - - public override void Save() - { - List<string> variable_names = new List<string>(); - foreach(KeyValuePair<string, string> variable in this) { - variable_names.Add(variable.Key); - client.Set(gconf_root + variable.Key, variable.Value); - } - client.Set(gconf_root + "variables", variable_names.ToArray()); - } - } -} diff --git a/src/Core/Banshee.Services/Banshee.AudioProfiles/ProfileConfiguration.cs b/src/Core/Banshee.Services/Banshee.AudioProfiles/ProfileConfiguration.cs index ab21d0fa0..af6949101 100644 --- a/src/Core/Banshee.Services/Banshee.AudioProfiles/ProfileConfiguration.cs +++ b/src/Core/Banshee.Services/Banshee.AudioProfiles/ProfileConfiguration.cs @@ -32,9 +32,11 @@ using System.Xml; using System.Collections; using System.Collections.Generic; +using Banshee.Configuration; + namespace Banshee.AudioProfiles { - public abstract class ProfileConfiguration : IEnumerable<KeyValuePair<string, string>> + public class ProfileConfiguration : IEnumerable<KeyValuePair<string, string>> { private Dictionary<string, string> variable_values = new Dictionary<string, string>(); private string id; @@ -42,38 +44,31 @@ namespace Banshee.AudioProfiles public static ProfileConfiguration Load(Profile profile, string id) { - ProfileConfiguration configuration = new GConfProfileConfiguration(profile, - Banshee.Configuration.GConfConfigurationClient.BaseKey + - "audio_profiles/" + id + "/" + profile.ID + "/", id); + ProfileConfiguration configuration = new ProfileConfiguration(profile, id); configuration.Load(); return configuration; } - + public static Profile LoadActiveProfile(ProfileManager manager, string id) { - try { - string profile_id = GConfProfileConfiguration.LoadActiveProfile( - Banshee.Configuration.GConfConfigurationClient.BaseKey + "audio_profiles/", id); - - if(profile_id == null) { - return null; - } - - foreach(Profile profile in manager.GetAvailableProfiles()) { - if(profile.ID == profile_id) { - return profile; - } + string profile_id = ConfigurationClient.Get<string>(MakeConfNamespace(id), "active_profile", string.Empty); + + if(profile_id == string.Empty) { + return null; + } + + foreach(Profile profile in manager.GetAvailableProfiles()) { + if(profile.ID == profile_id) { + return profile; } - } catch { } - + return null; } public static void SaveActiveProfile(Profile profile, string id) { - GConfProfileConfiguration.SaveActiveProfile(profile, - Banshee.Configuration.GConfConfigurationClient.BaseKey + "audio_profiles/", id); + ConfigurationClient.Set<string>(MakeConfNamespace(id), "active_profile", profile.ID); } public ProfileConfiguration(Profile profile, string id) @@ -82,8 +77,22 @@ namespace Banshee.AudioProfiles this.id = id; } - protected abstract void Load(); - public abstract void Save(); + protected virtual void Load() + { + foreach(string variable in ConfigurationClient.Get<string[]>(ConfNamespace, "variables", new string[0])) { + Add(variable, ConfigurationClient.Get<string>(ConfNamespace, variable, string.Empty)); + } + } + + public virtual void Save() + { + List<string> variable_names = new List<string>(Count); + foreach(KeyValuePair<string, string> variable in this) { + variable_names.Add(variable.Key); + ConfigurationClient.Set<string>(ConfNamespace, variable.Key, variable.Value); + } + ConfigurationClient.Set<string[]>(ConfNamespace, "variables", variable_names.ToArray()); + } public void Add(string variable, string value) { @@ -118,5 +127,18 @@ namespace Banshee.AudioProfiles public string ID { get { return id; } } + + public int Count { + get { return variable_values.Count; } + } + + protected string ConfNamespace { + get { return MakeConfNamespace(id); } + } + + protected static string MakeConfNamespace(string id) + { + return String.Format("audio_profiles.{0}", id); + } } -} +}
\ No newline at end of file diff --git a/src/Core/Banshee.Core/Banshee.Base/RateLimiter.cs b/src/Core/Banshee.Services/Banshee.Base/RateLimiter.cs index d36a9c573..d36a9c573 100644 --- a/src/Core/Banshee.Core/Banshee.Base/RateLimiter.cs +++ b/src/Core/Banshee.Services/Banshee.Base/RateLimiter.cs diff --git a/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs b/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs new file mode 100644 index 000000000..11d7bbe09 --- /dev/null +++ b/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs @@ -0,0 +1,71 @@ +// +// ThreadAssist.cs +// +// Author: +// Aaron Bockover <abockover@novell.com> +// +// Copyright (C) 2005-2008 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Threading; + +namespace Banshee.Base +{ + public static class ThreadAssist + { + private static Thread main_thread; + + static ThreadAssist () + { + main_thread = Thread.CurrentThread; + } + + public static bool InMainThread { + get { return main_thread.Equals (Thread.CurrentThread); } + } + + public static void ProxyToMain (EventHandler handler) + { + if (!InMainThread) { + Banshee.ServiceStack.Application.Invoke (handler); + } else { + handler (null, new EventArgs ()); + } + } + + public static Thread Spawn (ThreadStart threadedMethod, bool autoStart) + { + Thread thread = new Thread (threadedMethod); + thread.IsBackground = true; + if (autoStart) { + thread.Start (); + } + return thread; + } + + public static Thread Spawn (ThreadStart threadedMethod) + { + return Spawn (threadedMethod, true); + } + } +} diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs index 8de084608..824926604 100644 --- a/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs +++ b/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs @@ -266,12 +266,12 @@ namespace Banshee.Collection.Database SafeUri new_uri = new SafeUri (new_filename); try { - if (IOProxy.File.Exists (new_uri)) { + if (Banshee.IO.File.Exists (new_uri)) { return null; } // TODO: Once GnomeVfs and Unix have proper Copy providers, use IOProxy.File.Copy instead. - File.Copy (old_uri.LocalPath, new_uri.LocalPath); + System.IO.File.Copy (old_uri.LocalPath, new_uri.LocalPath); // Return new SafeUri after copy return new_uri; diff --git a/src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs b/src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs index 59eb290ce..068dc74aa 100644 --- a/src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs +++ b/src/Core/Banshee.Services/Banshee.Collection/ImportManager.cs @@ -191,8 +191,8 @@ namespace Banshee.Collection SafeUri source_uri = new SafeUri (source); try { - is_regular_file = IOProxy.File.Exists (source_uri); - is_directory = !is_regular_file && IOProxy.Directory.Exists (source); + is_regular_file = Banshee.IO.File.Exists (source_uri); + is_directory = !is_regular_file && Banshee.IO.Directory.Exists (source); } catch { Interlocked.Decrement (ref scan_ref_count); return; @@ -210,11 +210,11 @@ namespace Banshee.Collection try { if (!Path.GetFileName (Path.GetDirectoryName (source)).StartsWith (".")) { try { - foreach (string file in IOProxy.Directory.GetFiles (source)) { + foreach (string file in Banshee.IO.Directory.GetFiles (source)) { ScanForFiles (file); } - foreach (string directory in IOProxy.Directory.GetDirectories (source)) { + foreach (string directory in Banshee.IO.Directory.GetDirectories (source)) { ScanForFiles (directory); } } catch { diff --git a/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs b/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs index 7f5630413..847f286c7 100644 --- a/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs +++ b/src/Core/Banshee.Services/Banshee.Metadata.Embedded/EmbeddedQueryJob.cs @@ -27,6 +27,7 @@ // using System; +using System.IO; using System.Collections.Generic; using TagLib; @@ -108,17 +109,16 @@ namespace Banshee.Metadata.Embedded return preferred_index; } - protected bool SavePicture(IPicture picture, string image_path) + protected bool SavePicture (IPicture picture, string image_path) { - if(picture == null || picture.Data == null || picture.Data.Count == 0) { + if (picture == null || picture.Data == null || picture.Data.Count == 0) { return false; } - using(System.IO.MemoryStream stream = new System.IO.MemoryStream(picture.Data.Data)) { - Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(stream); - pixbuf.Save(image_path, "jpeg"); - } - + Banshee.IO.StreamAssist.Save (new MemoryStream (picture.Data.Data), + new FileStream (Path.ChangeExtension (image_path, "cover"), + FileMode.Create, FileAccess.ReadWrite)); + return true; } } diff --git a/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs b/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs index b6e02f192..3ec68c9e5 100644 --- a/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs +++ b/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs @@ -139,20 +139,9 @@ namespace Banshee.Metadata return false; } - using(from_stream) { - long bytes_read = 0; - - using(FileStream to_stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite)) { - byte [] buffer = new byte[8192]; - int chunk_bytes_read = 0; - - while((chunk_bytes_read = from_stream.Read(buffer, 0, buffer.Length)) > 0) { - to_stream.Write(buffer, 0, chunk_bytes_read); - bytes_read += chunk_bytes_read; - } - } - } - + Banshee.IO.StreamAssist.Save (from_stream, new FileStream (path, + FileMode.Create, FileAccess.ReadWrite)); + return true; } diff --git a/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs b/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs index 9f1333f28..798ada12a 100644 --- a/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs +++ b/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs @@ -131,7 +131,7 @@ namespace Banshee.Playlist foreach (PlaylistFormatDescription format in formats) { try { IPlaylistFormat playlist = (IPlaylistFormat)Activator.CreateInstance (format.Type); - playlist.Load (Banshee.IO.IOProxy.File.OpenRead (new SafeUri (playlistUri)), true); + playlist.Load (Banshee.IO.File.OpenRead (new SafeUri (playlistUri)), true); foreach (Dictionary<string, object> element in playlist.Elements) { uris.Add (((Uri)element["uri"]).AbsoluteUri); } diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs index d9cd42d1e..e48bf8339 100644 --- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs +++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs @@ -58,7 +58,7 @@ namespace Banshee.Playlists.Formats Stream stream = null; if(uri.Scheme == "file") { - stream = Banshee.IO.IOProxy.File.OpenRead(uri); + stream = Banshee.IO.File.OpenRead(uri); } else if(uri.Scheme == "http") { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.AbsoluteUri); request.UserAgent = Banshee.Web.Browser.UserAgent; diff --git a/src/Core/Banshee.Services/Banshee.ServiceStack/Application.cs b/src/Core/Banshee.Services/Banshee.ServiceStack/Application.cs index e0a013655..fb2cec8fb 100644 --- a/src/Core/Banshee.Services/Banshee.ServiceStack/Application.cs +++ b/src/Core/Banshee.Services/Banshee.ServiceStack/Application.cs @@ -101,6 +101,11 @@ namespace Banshee.ServiceStack RunIdle (delegate { handler (); return false; }); } + public static void Invoke (EventHandler handler) + { + RunIdle (delegate { handler (null, EventArgs.Empty); return false; }); + } + public static uint RunIdle (IdleHandler handler) { if (idle_handler == null) { diff --git a/src/Core/Banshee.Services/Banshee.Services.addin.xml b/src/Core/Banshee.Services/Banshee.Services.addin.xml index 7cf2b054a..c19195335 100644 --- a/src/Core/Banshee.Services/Banshee.Services.addin.xml +++ b/src/Core/Banshee.Services/Banshee.Services.addin.xml @@ -16,4 +16,12 @@ <ExtensionNode name="PlayerEngine"/> </ExtensionPoint> + <ExtensionPoint path="/Banshee/Platform/IOProvider"> + <ExtensionNode name="IOProvider"/> + </ExtensionPoint> + + <ExtensionPoint path="/Banshee/Platform/ConfigurationProvider"> + <ExtensionNode name="ConfigurationProvider"/> + </ExtensionPoint> + </Addin> diff --git a/src/Core/Banshee.Services/Banshee.Services.mdp b/src/Core/Banshee.Services/Banshee.Services.mdp index 701f8fe1d..ba3710ddb 100644 --- a/src/Core/Banshee.Services/Banshee.Services.mdp +++ b/src/Core/Banshee.Services/Banshee.Services.mdp @@ -78,7 +78,6 @@ <File name="Banshee.Sources/ErrorSource.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.MediaEngine/IPlayerEngineService.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Collection/BansheeListModel.cs" subtype="Code" buildaction="Compile" /> - <File name="Banshee.AudioProfiles/GConfProfileConfiguration.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.AudioProfiles/Pipeline.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.AudioProfiles/PipelineVariable.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.AudioProfiles/Profile.cs" subtype="Code" buildaction="Compile" /> @@ -120,6 +119,9 @@ <File name="Banshee.ServiceStack/IExtensionService.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Configuration/DatabaseConfigurationClient.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Sources/SourceMergeType.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.Base" subtype="Directory" buildaction="Compile" /> + <File name="Banshee.Base/RateLimiter.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.Base/ThreadAssist.cs" subtype="Code" buildaction="Compile" /> </Contents> <References> <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> diff --git a/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs b/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs index 20be44240..1fef7b643 100644 --- a/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs +++ b/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs @@ -44,8 +44,6 @@ namespace Banshee.SmartPlaylist public SmartPlaylistCore() { - Gnome.Vfs.Vfs.Initialize(); - Migrator.MigrateAll (); // Listen for added/removed sources and added/changed songs diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am index 191260a55..d043bef82 100644 --- a/src/Core/Banshee.Services/Makefile.am +++ b/src/Core/Banshee.Services/Makefile.am @@ -3,12 +3,13 @@ TARGET = library LINK = $(REF_BANSHEE_SERVICES) SOURCES = \ - Banshee.AudioProfiles/GConfProfileConfiguration.cs \ Banshee.AudioProfiles/Pipeline.cs \ Banshee.AudioProfiles/PipelineVariable.cs \ Banshee.AudioProfiles/Profile.cs \ Banshee.AudioProfiles/ProfileConfiguration.cs \ Banshee.AudioProfiles/ProfileManager.cs \ + Banshee.Base/RateLimiter.cs \ + Banshee.Base/ThreadAssist.cs \ Banshee.Collection.Database/AlbumListDatabaseModel.cs \ Banshee.Collection.Database/ArtistListDatabaseModel.cs \ Banshee.Collection.Database/LibraryAlbumInfo.cs \ diff --git a/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp b/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp index f49891a11..945fa4322 100644 --- a/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp +++ b/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp @@ -80,6 +80,7 @@ <File name="Banshee.Sources.Gui/SourceRowRenderer.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Sources.Gui/SourceView_DragAndDrop.cs" subtype="Code" buildaction="Compile" /> <File name="Banshee.Gui.Dialogs/PreferencesDialog.cs" subtype="Code" buildaction="Compile" /> + <File name="Banshee.Collection.Gui/ColumnCellTrackNumber.cs" subtype="Code" buildaction="Compile" /> </Contents> <References> <ProjectReference type="Project" localcopy="False" refto="Hyena.Gui" /> diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs index 334a81c73..aadec7ccb 100644 --- a/src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs +++ b/src/Core/Banshee.Widgets/Banshee.Widgets/LinkLabel.cs @@ -72,7 +72,7 @@ namespace Banshee.Widgets protected virtual void OnClicked() { - if(uri != null) { + if(uri != null && Open != null) { Open(uri.AbsoluteUri); } @@ -230,14 +230,7 @@ namespace Banshee.Widgets } public static UriOpenHandler DefaultOpen { - get { - if(default_open_handler == null) { - default_open_handler = new UriOpenHandler(Gnome.Url.Show); - } - - return default_open_handler; - } - + get { return default_open_handler; } set { default_open_handler = value; } } } diff --git a/src/Core/Hyena/Hyena.mdp b/src/Core/Hyena/Hyena.mdp index 6eee0e346..5c4caaf91 100644 --- a/src/Core/Hyena/Hyena.mdp +++ b/src/Core/Hyena/Hyena.mdp @@ -89,4 +89,4 @@ <AsmRefVar /> <ProjectRefVar /> </MonoDevelop.Autotools.MakefileInfo> -</Project> +</Project>
\ No newline at end of file diff --git a/src/Core/Nereid/Nereid/Client.cs b/src/Core/Nereid/Nereid/Client.cs index 95aaee58b..513494c0b 100644 --- a/src/Core/Nereid/Nereid/Client.cs +++ b/src/Core/Nereid/Nereid/Client.cs @@ -37,20 +37,10 @@ namespace Nereid Banshee.Gui.GtkBaseClient.Entry<Client> (); } - private Gnome.Program program; - protected override void OnRegisterServices () { - program = new Gnome.Program ("Banshee", Banshee.ServiceStack.Application.Version, - Gnome.Modules.UI, System.Environment.GetCommandLineArgs ()); - Banshee.ServiceStack.ServiceManager.RegisterService <PlayerInterface> (); } - - public override void Run () - { - program.Run (); - } } } diff --git a/src/Extensions/Template/Makefile.am b/src/Extensions/Template/Makefile.am index 82490bca5..51be950de 100644 --- a/src/Extensions/Template/Makefile.am +++ b/src/Extensions/Template/Makefile.am @@ -4,7 +4,7 @@ LINK = $(REF_FIXME) SOURCES = -RESOURCES = +RESOURCES = @EXTENSION_NAME@.addin.xml include $(top_srcdir)/build/build.mk diff --git a/win32-patches/audio-profile-configuration.changes b/win32-patches/audio-profile-configuration.changes deleted file mode 100644 index 931fb203a..000000000 --- a/win32-patches/audio-profile-configuration.changes +++ /dev/null @@ -1,7 +0,0 @@ -This patch changes the audio profile configuration to use the Banshee configuration API
-rather than GConf. All file paths are reletive to banshee/src/Core/Banshee.Base
-
-* Removed Banshee.AudioProfiles/GConfProfileConfiguration.cs: Obsolete.
-
-* Modified Banshee.AudioProfiles/ProfileConfiguration.cs: Made to use the Banshee
- Configuration system.
\ No newline at end of file diff --git a/win32-patches/audio-profile-configuration.patch b/win32-patches/audio-profile-configuration.patch deleted file mode 100644 index dee8fd796..000000000 --- a/win32-patches/audio-profile-configuration.patch +++ /dev/null @@ -1,202 +0,0 @@ -Index: banshee/src/Core/Banshee.Base/Banshee.AudioProfiles/GConfProfileConfiguration.cs
-===================================================================
---- banshee/src/Core/Banshee.Base/Banshee.AudioProfiles/GConfProfileConfiguration.cs (revision 2588)
-+++ banshee/src/Core/Banshee.Base/Banshee.AudioProfiles/GConfProfileConfiguration.cs (working copy)
-@@ -1,82 +0,0 @@
--/*************************************************************************** -- * GConfProfileConfiguration.cs -- * -- * Copyright (C) 2006 Novell, Inc. -- * Written by Aaron Bockover <aaron@abock.org> -- ****************************************************************************/ -- --/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: -- * -- * Permission is hereby granted, free of charge, to any person obtaining a -- * copy of this software and associated documentation files (the "Software"), -- * to deal in the Software without restriction, including without limitation -- * the rights to use, copy, modify, merge, publish, distribute, sublicense, -- * and/or sell copies of the Software, and to permit persons to whom the -- * Software is furnished to do so, subject to the following conditions: -- * -- * The above copyright notice and this permission notice shall be included in -- * all copies or substantial portions of the Software. -- * -- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -- * DEALINGS IN THE SOFTWARE. -- */ -- --using System; --using System.Text; --using System.Xml; --using System.Collections; --using System.Collections.Generic; -- --using GConf; -- --namespace Banshee.AudioProfiles --{ -- public class GConfProfileConfiguration : ProfileConfiguration -- { -- private string gconf_root; -- private GConf.Client client; -- -- public GConfProfileConfiguration(Profile profile, string gconfRoot, string id) : base(profile, id) -- { -- client = new GConf.Client(); -- this.gconf_root = gconfRoot; -- } -- -- internal static string LoadActiveProfile(string gconfRoot, string id) -- { -- GConf.Client client = new GConf.Client(); -- return (string)client.Get(gconfRoot + id + "/active_profile"); -- } -- -- internal static void SaveActiveProfile(Profile profile, string gconfRoot, string id) -- { -- GConf.Client client = new GConf.Client(); -- client.Set(gconfRoot + id + "/active_profile", profile.ID); -- } -- -- protected override void Load() -- { -- try { -- foreach(string variable in (string [])client.Get(gconf_root + "variables")) { -- Add(variable, (string)client.Get(gconf_root + variable)); -- } -- } catch { -- } -- } -- -- public override void Save() -- { -- List<string> variable_names = new List<string>(); -- foreach(KeyValuePair<string, string> variable in this) { -- variable_names.Add(variable.Key); -- client.Set(gconf_root + variable.Key, variable.Value); -- } -- client.Set(gconf_root + "variables", variable_names.ToArray()); -- } -- } --} -Index: banshee/src/Core/Banshee.Base/Banshee.AudioProfiles/ProfileConfiguration.cs
-===================================================================
---- banshee/src/Core/Banshee.Base/Banshee.AudioProfiles/ProfileConfiguration.cs (revision 2588)
-+++ banshee/src/Core/Banshee.Base/Banshee.AudioProfiles/ProfileConfiguration.cs (working copy)
-@@ -32,9 +32,11 @@
- using System.Collections; - using System.Collections.Generic; - -+using Banshee.Configuration; -+ - namespace Banshee.AudioProfiles - { -- public abstract class ProfileConfiguration : IEnumerable<KeyValuePair<string, string>> -+ public class ProfileConfiguration : IEnumerable<KeyValuePair<string, string>> - { - private Dictionary<string, string> variable_values = new Dictionary<string, string>(); - private string id; -@@ -42,38 +44,31 @@
- - public static ProfileConfiguration Load(Profile profile, string id) - { -- ProfileConfiguration configuration = new GConfProfileConfiguration(profile, -- Banshee.Configuration.GConfConfigurationClient.BaseKey + -- "audio_profiles/" + id + "/" + profile.ID + "/", id); -+ ProfileConfiguration configuration = new ProfileConfiguration(profile, id); - configuration.Load(); - return configuration; - } -- -+ - public static Profile LoadActiveProfile(ProfileManager manager, string id) - { -- try { -- string profile_id = GConfProfileConfiguration.LoadActiveProfile( -- Banshee.Configuration.GConfConfigurationClient.BaseKey + "audio_profiles/", id); -- -- if(profile_id == null) { -- return null; -+ string profile_id = ConfigurationClient.Get<string>(MakeConfNamespace(id), "active_profile", string.Empty); -+ -+ if(profile_id == string.Empty) { -+ return null; -+ } -+ -+ foreach(Profile profile in manager.GetAvailableProfiles()) { -+ if(profile.ID == profile_id) { -+ return profile; - } -- -- foreach(Profile profile in manager.GetAvailableProfiles()) { -- if(profile.ID == profile_id) { -- return profile; -- } -- } -- } catch { - } -- -+ - return null; - } - - public static void SaveActiveProfile(Profile profile, string id) - { -- GConfProfileConfiguration.SaveActiveProfile(profile, -- Banshee.Configuration.GConfConfigurationClient.BaseKey + "audio_profiles/", id); -+ ConfigurationClient.Set<string>(MakeConfNamespace(id), "active_profile", profile.ID); - } - - public ProfileConfiguration(Profile profile, string id) -@@ -82,8 +77,22 @@
- this.id = id; - } - -- protected abstract void Load(); -- public abstract void Save(); -+ protected virtual void Load() -+ { -+ foreach(string variable in ConfigurationClient.Get<string[]>(ConfNamespace, "variables", new string[0])) { -+ Add(variable, ConfigurationClient.Get<string>(ConfNamespace, variable, string.Empty)); -+ } -+ } -+ -+ public virtual void Save() -+ { -+ List<string> variable_names = new List<string>(Count); -+ foreach(KeyValuePair<string, string> variable in this) { -+ variable_names.Add(variable.Key); -+ ConfigurationClient.Set<string>(ConfNamespace, variable.Key, variable.Value); -+ } -+ ConfigurationClient.Set<string[]>(ConfNamespace, "variables", variable_names.ToArray()); -+ } - - public void Add(string variable, string value) - { -@@ -118,5 +127,18 @@
- public string ID { - get { return id; } - } -+ -+ public int Count { -+ get { return variable_values.Count; } -+ } -+ -+ protected string ConfNamespace { -+ get { return MakeConfNamespace(id); } -+ } -+ -+ protected static string MakeConfNamespace(string id) -+ { -+ return String.Format("audio_profiles.{0}", id); -+ } - } --} -+}
-\ No newline at end of file
|