summaryrefslogtreecommitdiff
path: root/extras
diff options
context:
space:
mode:
authorAaron Bockover <abock@gnome.org>2007-05-22 21:10:15 +0000
committerAaron Bockover <abock@src.gnome.org>2007-05-22 21:10:15 +0000
commitdacc70b7891319dd7f6de260c03d21349b7f5d69 (patch)
tree775327ad09a7c9a90d35d78e5fe72c950cb4f483 /extras
parent5f86b61f4f45b2ef5e432ca61eb106ab71544806 (diff)
Updated to reflect tools and extras directory changes
2007-05-22 Aaron Bockover <abock@gnome.org> * configure.ac: * Makefile.am: Updated to reflect tools and extras directory changes * tools/*: Moved to extras/tools * extras/scripts/*.boo: Added a safe place for some boo scriptlets which may be of use to some users svn path=/trunk/banshee/; revision=2272
Diffstat (limited to 'extras')
-rw-r--r--extras/scripts/auto-import.boo56
-rw-r--r--extras/scripts/filename-transform.boo4
-rw-r--r--extras/tools/BansheeDBusClient.cs245
-rw-r--r--extras/tools/BansheeImport.cs179
-rw-r--r--extras/tools/Makefile.am33
-rw-r--r--extras/tools/banshee-import.in17
6 files changed, 534 insertions, 0 deletions
diff --git a/extras/scripts/auto-import.boo b/extras/scripts/auto-import.boo
new file mode 100644
index 000000000..1a168f82d
--- /dev/null
+++ b/extras/scripts/auto-import.boo
@@ -0,0 +1,56 @@
+import System
+import System.IO
+import Gtk
+import Banshee.Gui
+import Banshee.Widgets
+import Banshee.Base
+import Banshee.Library
+
+class AutoImporter:
+ # Set to false if you always want to auto-import without asking
+ private ask_me = true
+
+ class AutoImportMessageDialog(HigMessageDialog):
+ def constructor():
+ super(InterfaceElements.MainWindow,
+ DialogFlags.Modal, MessageType.Info,
+ "Would you like to rescan your library?",
+ "Rescanning your library may take a long time.",
+ "Rescan")
+
+ def ImportFinished(o as object, args as EventArgs):
+ ImportManager.Instance.ImportFinished -= ImportFinished
+ Banshee.Sources.ImportErrorsSource.Instance.Unmap()
+
+ def Timeout() as bool:
+ location = Globals.Library.Location
+ if not Directory.Exists(location):
+ location = Paths.DefaultLibraryPath
+
+ ImportManager.Instance.ImportFinished += ImportFinished
+
+ if not ask_me:
+ Import.QueueSource(location)
+ return false
+
+ dialog = AutoImportMessageDialog()
+ try:
+ if dialog.Run() == ResponseType.Ok:
+ Import.QueueSource(location)
+ ensure:
+ dialog.Destroy()
+
+ return false
+
+ def AutoImport(o as object, args as EventArgs):
+ GLib.Timeout.Add(1500, Timeout)
+ Globals.Library.Reloaded -= AutoImport
+
+ def constructor():
+ if Globals.UIManager.IsInitialized:
+ AutoImport(null, EventArgs.Empty)
+ else:
+ Globals.UIManager.Initialized += AutoImport
+
+AutoImporter()
+
diff --git a/extras/scripts/filename-transform.boo b/extras/scripts/filename-transform.boo
new file mode 100644
index 000000000..f37a681ca
--- /dev/null
+++ b/extras/scripts/filename-transform.boo
@@ -0,0 +1,4 @@
+Banshee.Base.FileNamePattern.Filter = { songpath as string |
+ @/[ ]+/.Replace(@/[^0-9A-Za-z\/ ]+/.Replace(songpath, "").ToLower(), "_")
+}
+
diff --git a/extras/tools/BansheeDBusClient.cs b/extras/tools/BansheeDBusClient.cs
new file mode 100644
index 000000000..33b2cf879
--- /dev/null
+++ b/extras/tools/BansheeDBusClient.cs
@@ -0,0 +1,245 @@
+
+/***************************************************************************
+ * BansheeDbusClient.cs
+ *
+ * Copyright (C) 2005 Novell
+ * Written by Aaron Bockover (aaron@aaronbock.net)
+ ****************************************************************************/
+
+/* 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.
+ */
+
+// This example is a very basic D-Bus client implementation of the Banshee
+// D-Bus API. This API *will* change very soon. It will also be possible
+// to link against a Banshee assembly that will provide the implementation
+// of the BansheeCore class (or clients can continue to implement the
+// abstract methods like below).
+//
+// There is currently no event/signal support, which means the client
+// must poll the server in a loop or similar to get status updates, etc.
+
+using System;
+using NDesk.DBus;
+using org.freedesktop.DBus;
+using Gtk;
+
+[Interface("org.gnome.Banshee.Core")]
+public interface IPlayer
+{
+ void Shutdown();
+ void PresentWindow();
+ void ShowWindow();
+ void HideWindow();
+ void TogglePlaying();
+ void Play();
+ void Pause();
+ void Next();
+ void Previous();
+ void SelectAudioCd(string device);
+ void SelectDap(string device);
+ void EnqueueFiles(string [] files);
+ string GetPlayingArtist();
+ string GetPlayingAlbum();
+ string GetPlayingTitle();
+ string GetPlayingGenre();
+ string GetPlayingUri();
+ string GetPlayingCoverUri();
+ int GetPlayingDuration();
+ int GetPlayingPosition();
+ int GetPlayingRating();
+ int GetMaxRating();
+ int SetPlayingRating(int rating);
+ int GetPlayingStatus();
+ void SetVolume(int volume);
+ void IncreaseVolume();
+ void DecreaseVolume();
+ void SetPlayingPosition(int position);
+ void SkipForward();
+ void SkipBackward();
+}
+
+public class BansheeClient : Window
+{
+ const string BUS_NAME = "org.gnome.Banshee";
+ const string OBJECT_PATH = "/org/gnome/Banshee/Player";
+
+ private static IPlayer banshee = null;
+
+ static IPlayer FindInstance()
+ {
+ if (!Bus.Session.NameHasOwner(BUS_NAME))
+ throw new Exception(String.Format("Name {0} has no owner", BUS_NAME));
+
+ return Bus.Session.GetObject<IPlayer>(BUS_NAME, new ObjectPath (OBJECT_PATH));
+ }
+
+ public static void Main()
+ {
+ try {
+ banshee = FindInstance();
+ } catch(Exception) {
+ Console.Error.WriteLine("Could not locate Banshee on D-Bus. Perhaps it's not running?");
+ Environment.Exit(1);
+ }
+
+ BusG.Init();
+ Application.Init();
+ new BansheeClient();
+ Application.Run();
+ }
+
+ private Button previous_button;
+ private Button playpause_button;
+ private Button next_button;
+ private Label status_label;
+ private Label artist_label;
+ private Label album_label;
+ private Label title_label;
+
+ private BansheeClient() : base("Banshee D-Bus Client")
+ {
+ BorderWidth = 10;
+
+ VBox box = new VBox();
+ box.Spacing = 5;
+ Add(box);
+
+ HBox button_box = new HBox();
+ previous_button = new Button("<< Previous");
+ playpause_button = new Button("Play/Pause");
+ next_button = new Button("Next >>");
+
+ previous_button.Clicked += delegate(object o, EventArgs args) {
+ banshee.Previous();
+ QueryServer();
+ };
+
+ playpause_button.Clicked += delegate(object o, EventArgs args) {
+ if(banshee.GetPlayingStatus() == -1) {
+ return;
+ }
+
+ banshee.TogglePlaying();
+ QueryServer();
+ };
+
+ next_button.Clicked += delegate(object o, EventArgs args) {
+ banshee.Next();
+ QueryServer();
+ };
+
+ button_box.PackStart(previous_button, false, false, 0);
+ button_box.PackStart(playpause_button, true, true, 0);
+ button_box.PackStart(next_button, false, false, 0);
+
+ box.PackStart(button_box, false, false, 0);
+
+ status_label = new Label("Connecting...");
+ artist_label = new Label();
+ album_label = new Label();
+ title_label = new Label();
+
+ box.PackStart(status_label, false, false, 0);
+ box.PackStart(artist_label, false, false, 0);
+ box.PackStart(album_label, false, false, 0);
+ box.PackStart(title_label, false, false, 0);
+
+ ShowAll();
+
+ QueryServer();
+ //FIXME: this needs to go
+ GLib.Timeout.Add(500, QueryServer);
+ }
+
+ protected override bool OnDeleteEvent(Gdk.Event evnt)
+ {
+ Application.Quit();
+ return true;
+ }
+
+ private void SetStatus(string status)
+ {
+ TimeSpan position = new TimeSpan(banshee.GetPlayingPosition() * TimeSpan.TicksPerSecond);
+ TimeSpan duration = new TimeSpan(banshee.GetPlayingDuration() * TimeSpan.TicksPerSecond);
+
+ status_label.Markup = String.Format(
+ "<b>Status:</b> {0} ({1:00}:{2:00} / {3:00}:{4:00})", status,
+ position.Minutes, position.Seconds,
+ duration.Minutes, duration.Seconds);
+ }
+
+ private void SetField(string fieldName, string value, Label label)
+ {
+ if(value == null || value == String.Empty) {
+ label.Hide();
+ return;
+ }
+
+ label.Markup = String.Format("<b>{0}</b>: {1}", fieldName,
+ GLib.Markup.EscapeText(value));
+ label.Show();
+ }
+
+ private string last_uri = null;
+
+ private bool QueryServer()
+ {
+ int status = -1;
+
+ try {
+ status = banshee.GetPlayingStatus();
+ } catch(Exception) {
+ Console.Error.WriteLine("Lost connection to Banshee Server");
+ Application.Quit();
+ return false;
+ }
+
+ switch(status) {
+ case 0:
+ SetStatus("Paused");
+ break;
+ case 1:
+ SetStatus("Playing");
+ break;
+ case -1:
+ default:
+ status_label.Markup = "<b>Status:</b> No song loaded";
+ artist_label.Hide();
+ album_label.Hide();
+ title_label.Hide();
+ return true;
+ }
+
+ string uri = banshee.GetPlayingUri();
+
+ if(uri != last_uri) {
+ last_uri = uri;
+
+ Console.WriteLine("Song Changed: {0}", uri);
+
+ SetField("Artist", banshee.GetPlayingArtist(), artist_label);
+ SetField("Album", banshee.GetPlayingAlbum(), album_label);
+ SetField("Title", banshee.GetPlayingTitle(), title_label);
+ }
+
+ return true;
+ }
+}
diff --git a/extras/tools/BansheeImport.cs b/extras/tools/BansheeImport.cs
new file mode 100644
index 000000000..b0c3832da
--- /dev/null
+++ b/extras/tools/BansheeImport.cs
@@ -0,0 +1,179 @@
+/***************************************************************************
+ * BansheeImport.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 Mono.Unix;
+
+using Banshee.Base;
+
+public static class BansheeImport
+{
+ private static bool verbose = false;
+ private static Queue import_queue = new Queue();
+ private static BansheeDatabase database;
+ private static int import_success = 0;
+ private static int import_total = 0;
+
+ public static int Main(string [] args)
+ {
+ foreach(string arg in args) {
+ switch(arg) {
+ case "--version":
+// PrintVersion();
+ return 1;
+ case "--help":
+// PrintHelp();
+ return 1;
+ case "--verbose":
+ verbose = true;
+ break;
+ default:
+ import_queue.Enqueue(arg);
+ break;
+ }
+ }
+
+ if(!Directory.Exists(Paths.ApplicationData)) {
+ Directory.CreateDirectory(Paths.ApplicationData);
+ }
+
+ database = new BansheeDatabase(Path.Combine(Paths.ApplicationData, "banshee.db"));
+
+ while(import_queue.Count > 0) {
+ // ProcessInput(import_queue.Dequeue() as string);
+ }
+
+ // Debug("{0} / {1} files imported", import_success, import_total);
+
+ return 1;
+ }
+
+ /*private static void ProcessInput(string source)
+ {
+ bool is_regular_file = false;
+ bool is_directory = false;
+
+ // FIXME: for quick compat for pzb, not using Banshee.IO;
+ // need to change this to Banshee.IO in the future
+
+ try {
+ is_regular_file = File.Exists(source);
+ is_directory = !is_regular_file && Directory.Exists(source);
+ } catch {
+ return;
+ }
+
+ if(is_regular_file && !Path.GetFileName(source).StartsWith(".")) {
+ ImportFile(source);
+ } else if(is_directory && !Path.GetFileName(System.IO.Path.GetDirectoryName(source)).StartsWith(".")) {
+ try {
+ foreach(string file in Directory.GetFiles(source)) {
+ ProcessInput(file);
+ }
+
+ foreach(string directory in Directory.GetDirectories(source)) {
+ ProcessInput(directory);
+ }
+ } catch(System.UnauthorizedAccessException) {
+ }
+ }
+ }
+
+ private static void ImportFile(string path)
+ {
+ Debug("Importing: {0}", path);
+
+ import_total++;
+
+ try {
+ AudioFile af = new AudioFile(path);
+ Statement insert = new Insert("Tracks", true,
+ "TrackID", null,
+ "Uri", FilenameToUri(path),
+ "MimeType", af.MimeType,
+ "Artist", af.Artist,
+ "AlbumTitle", af.Album,
+ "Title", af.Title,
+ "Genre", af.Genre,
+ "Year", af.Year,
+ "DateAddedStamp", DateTimeUtil.FromDateTime(DateTime.Now),
+ "TrackNumber", af.TrackNumber,
+ "TrackCount", af.TrackCount,
+ "Duration", (int)af.Duration.TotalSeconds);
+ database.Execute(insert);
+ import_success++;
+ } catch(Exception e) {
+ Debug("** Could not import: {0}", path);
+ Debug(e.ToString());
+ }
+ }
+
+ public static string FilenameToUri(string localPath)
+ {
+ IntPtr path_ptr = UnixMarshal.StringToHeap(localPath);
+ IntPtr uri_ptr = g_filename_to_uri(path_ptr, IntPtr.Zero, IntPtr.Zero);
+ UnixMarshal.FreeHeap(path_ptr);
+
+ if(uri_ptr == IntPtr.Zero) {
+ throw new ApplicationException("Filename path must be absolute");
+ }
+
+ string uri = UnixMarshal.PtrToString(uri_ptr);
+ UnixMarshal.FreeHeap(uri_ptr);
+
+ return uri;
+ }
+
+ [System.Runtime.InteropServices.DllImport("libglib-2.0.so")]
+ private static extern IntPtr g_filename_to_uri(IntPtr filename, IntPtr hostname, IntPtr error);
+
+ private static void Debug(string message, params object [] args)
+ {
+ if(verbose) {
+ Console.WriteLine(message, args);
+ }
+ }
+
+ private static void PrintVersion()
+ {
+ Console.WriteLine("Banshee " + ConfigureDefines.VERSION);
+ }
+
+ private static void PrintHelp()
+ {
+ Console.WriteLine("Usage: banshee-import [ options ... ] <import_1> [ ... <import_N> ]");
+ Console.WriteLine(" where options include:\n");
+ Console.WriteLine(" --verbose print verbose messages");
+ Console.WriteLine(" --help show this help");
+ Console.WriteLine(" --version show version");
+ Console.WriteLine("");
+ } */
+}
diff --git a/extras/tools/Makefile.am b/extras/tools/Makefile.am
new file mode 100644
index 000000000..d231866f3
--- /dev/null
+++ b/extras/tools/Makefile.am
@@ -0,0 +1,33 @@
+include $(top_srcdir)/build/Common.Makefile
+
+BANSHEE_IMPORT = banshee-import
+BANSHEE_IMPORT_ASSEMBLY = $(BANSHEE_IMPORT).exe
+DBUS_CLIENT_ASSEMBLY = dbus-client.exe
+
+#toolsdir = $(pkglibdir)
+#tools_SCRIPTS = $(BANSHEE_IMPORT_ASSEMBLY)
+#bin_SCRIPTS = $(BANSHEE_IMPORT)
+
+BANSHEE_IMPORT_SOURCES = $(srcdir)/BansheeImport.cs
+DBUS_CLIENT_SOURCES = $(srcdir)/BansheeDBusClient.cs
+
+all: $(BANSHEE_IMPORT_ASSEMBLY) $(DBUS_CLIENT_ASSEMBLY)
+
+$(BANSHEE_IMPORT_ASSEMBLY): $(BANSHEE_IMPORT_SOURCES)
+ $(BUILD_BANSHEE_CORE) -out:$@ $(LINK_MONO_UNIX) $(BANSHEE_IMPORT_SOURCES)
+
+$(DBUS_CLIENT_ASSEMBLY): $(DBUS_CLIENT_SOURCES)
+ $(BUILD) -out:$@ $(LINK_DBUS) $(LINK_GTK) $(DBUS_CLIENT_SOURCES)
+
+run:
+ $(RUN_PATH) $(MONO) $(DBUS_CLIENT_ASSEMBLY)
+
+EXTRA_DIST = \
+ $(BANSHEE_IMPORT).in \
+ $(BANSHEE_IMPORT_SOURCES) \
+ $(DBUS_CLIENT_SOURCES)
+
+CLEANFILES = *.exe *.mdb
+DISTCLEANFILES = *.pidb
+MAINTAINERCLEANFILES = Makefile.in
+
diff --git a/extras/tools/banshee-import.in b/extras/tools/banshee-import.in
new file mode 100644
index 000000000..d3957b734
--- /dev/null
+++ b/extras/tools/banshee-import.in
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+prefix=@prefix@
+libdir=@expanded_libdir@
+exec_asm="banshee-import.exe"
+MONO_EXE="@expanded_libdir@/@PACKAGE@/$exec_asm"
+
+export DYLD_LIBRARY_PATH=@expanded_libdir@${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
+export LD_LIBRARY_PATH=@expanded_libdir@${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
+
+if [ "x$1" = "x--debug" ]; then
+ MONO_OPTIONS="--debug"
+ echo "** Running Banshee Import in Debug Mode **"
+fi
+
+exec -a banshee-import @MONO@ $MONO_OPTIONS $MONO_EXE "$@"
+