banshee r4090 - in trunk/banshee: . src/Clients/Halie/Halie src/Clients/Nereid/Nereid src/Core/Banshee.ThickClient/Banshee.Gui src/Libraries/Hyena/Hyena.Collections src/Libraries/Hyena/Hyena.CommandLine
- From: abock svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4090 - in trunk/banshee: . src/Clients/Halie/Halie src/Clients/Nereid/Nereid src/Core/Banshee.ThickClient/Banshee.Gui src/Libraries/Hyena/Hyena.Collections src/Libraries/Hyena/Hyena.CommandLine
- Date: Tue, 3 Jun 2008 18:57:08 +0000 (UTC)
Author: abock
Date: Tue Jun 3 18:57:07 2008
New Revision: 4090
URL: http://svn.gnome.org/viewvc/banshee?rev=4090&view=rev
Log:
2008-06-03 Aaron Bockover <abock gnome org>
* src/Clients/Halie/Halie/Client.cs: Translate a few query fields to be
more familiar, allow setting volume and seeking, support window hiding
* src/Clients/Nereid/Nereid/Client.cs: Added --help and --version displays
* src/Core/Banshee.ThickClient/Banshee.Gui/IClientWindow.cs: Added Hide ()
* src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs: Added
some Join methods
* src/Libraries/Hyena/Hyena.CommandLine/Layout.cs: Support displaying
specific sets of groups
* src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs: Added a
ContainsStart method
* src/Libraries/Hyena/Hyena.CommandLine/LayoutGroup.cs: Added index support
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Clients/Halie/Halie/Client.cs
trunk/banshee/src/Clients/Nereid/Nereid/Client.cs
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/IClientWindow.cs
trunk/banshee/src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs
trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs
trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/Layout.cs
trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/LayoutGroup.cs
Modified: trunk/banshee/src/Clients/Halie/Halie/Client.cs
==============================================================================
--- trunk/banshee/src/Clients/Halie/Halie/Client.cs (original)
+++ trunk/banshee/src/Clients/Halie/Halie/Client.cs Tue Jun 3 18:57:07 2008
@@ -49,6 +49,7 @@
public interface IClientWindow
{
void Present ();
+ void Hide ();
}
private static bool hide_field;
@@ -87,10 +88,12 @@
switch (arg.Key) {
case "show":
case "present": present = true; break;
+ case "hide": window.Hide (); break;
+
}
}
- if (present) {
+ if (present && !ApplicationContext.CommandLine.Contains ("no-present")) {
window.Present ();
}
}
@@ -99,7 +102,6 @@
{
foreach (string file in ApplicationContext.CommandLine.Files) {
// If it looks like a URI with a protocol, leave it as is
- Console.WriteLine ("got file '{0}'", file);
if (System.Text.RegularExpressions.Regex.IsMatch (file, "^\\w+\\:\\/")) {
command.PushFile (file);
} else {
@@ -131,6 +133,12 @@
case "stop-when-finished":
controller.StopWhenFinished = !ParseBool (arg.Value);
break;
+ case "set-position":
+ player.Position = (uint)Math.Round (Double.Parse (arg.Value) * 1000);
+ break;
+ case "set-volume":
+ player.Volume = UInt16.Parse (arg.Value);
+ break;
default:
if (arg.Key.StartsWith ("query-")) {
if (track == null) {
@@ -212,6 +220,10 @@
{
if (field == String.Empty) {
return;
+ } else if (field == "name") {
+ field = "title";
+ } else if (field == "length") {
+ field = "duration";
}
string result = null;
@@ -224,7 +236,7 @@
if (hide_field) {
Console.WriteLine (result);
} else {
- Console.WriteLine ("{0}: {1}", field, result);
+ Console.WriteLine ("{0}: {1}", field.ToLower (), result);
}
}
Modified: trunk/banshee/src/Clients/Nereid/Nereid/Client.cs
==============================================================================
--- trunk/banshee/src/Clients/Nereid/Nereid/Client.cs (original)
+++ trunk/banshee/src/Clients/Nereid/Nereid/Client.cs Tue Jun 3 18:57:07 2008
@@ -30,6 +30,11 @@
using System.IO;
using System.Diagnostics;
using System.Reflection;
+using System.Collections.Generic;
+using Mono.Unix;
+
+using Hyena;
+using Hyena.CommandLine;
using Banshee.Base;
using Banshee.ServiceStack;
@@ -38,29 +43,34 @@
{
public class Client : Banshee.Gui.GtkBaseClient
{
- public static void Main ()
+ private static string user_gtkrc = Path.Combine (Paths.ApplicationData, "gtkrc");
+ public static void Main (string [] args)
{
+ if (CheckHelpVersion ()) {
+ return;
+ }
+
// Check for single instance
DBusConnection.Connect ();
if (DBusConnection.InstanceAlreadyRunning) {
// Try running our friend Halie, the DBus command line client
AppDomain.CurrentDomain.ExecuteAssembly (Path.Combine (Path.GetDirectoryName (
Assembly.GetEntryAssembly ().Location), "Halie.exe"));
+ Gdk.Global.InitCheck (ref args);
Gdk.Global.NotifyStartupComplete ();
return;
}
- Hyena.Log.InformationFormat ("Running Banshee {0}", Banshee.ServiceStack.Application.Version);
+ Hyena.Log.InformationFormat ("Running Banshee {0}", Application.Version);
// This could go into GtkBaseClient, but it's probably something we
// should really only support at each client level
- string user_gtkrc = Path.Combine (Paths.ApplicationData, "gtkrc");
if (File.Exists (user_gtkrc) && !ApplicationContext.CommandLine.Contains ("no-gtkrc")) {
Gtk.Rc.AddDefaultFile (user_gtkrc);
}
// Ugly hack to avoid stupid themes that set this to 0, causing a huge
- // bug when constructing the "add to playlist popup menu (BGO #524706)
+ // bug when constructing the "add to playlist" popup menu (BGO #524706)
Gtk.Rc.ParseString ("gtk-menu-popup-delay = 225");
// Boot the client
@@ -70,7 +80,131 @@
protected override void OnRegisterServices ()
{
// Register the main interface
- ServiceManager.RegisterService <PlayerInterface> ();
+ ServiceManager.RegisterService<PlayerInterface> ();
+ }
+
+ private static bool CheckHelpVersion ()
+ {
+ if (ApplicationContext.CommandLine.ContainsStart ("help")) {
+ ShowHelp ();
+ return true;
+ } else if (ApplicationContext.CommandLine.Contains ("version")) {
+ ShowVersion ();
+ return true;
+ }
+
+ return false;
+ }
+
+ private static void ShowHelp ()
+ {
+ Console.WriteLine ("Usage: {0} [options...] [files|URIs...]", "banshee-1");
+ Console.WriteLine ();
+
+ Layout commands = new Layout (
+ new LayoutGroup ("help", Catalog.GetString ("Help Options"),
+ new LayoutOption ("help", Catalog.GetString ("Show this help")),
+ new LayoutOption ("help-playback", Catalog.GetString ("Show options for controlling playback")),
+ new LayoutOption ("help-query-track", Catalog.GetString ("Show options for querying the playing track")),
+ new LayoutOption ("help-query-player", Catalog.GetString ("Show options for querying the playing engine")),
+ new LayoutOption ("help-ui", Catalog.GetString ("Show options for the user interface")),
+ new LayoutOption ("help-debug", Catalog.GetString ("Show options for developers and debugging")),
+ new LayoutOption ("help-all", Catalog.GetString ("Show all option groups")),
+ new LayoutOption ("version", Catalog.GetString ("Show version information"))
+ ),
+
+ new LayoutGroup ("playback", Catalog.GetString ("Playback Control Options"),
+ new LayoutOption ("next", Catalog.GetString ("Play the next track, optionally restarting if the 'restart' value is set")),
+ new LayoutOption ("previous", Catalog.GetString ("Play the previous track, optionally restarting if the 'restart value is set")),
+ new LayoutOption ("play-enqueued", Catalog.GetString ("Automatically start playing any tracks enqueued on the command line")),
+ new LayoutOption ("play", Catalog.GetString ("Start playback")),
+ new LayoutOption ("pause", Catalog.GetString ("Pause playback")),
+ new LayoutOption ("stop", Catalog.GetString ("Completely stop playback")),
+ new LayoutOption ("stop-when-finished", Catalog.GetString (
+ "Enable or disable playback stopping after the currently playing track (value should be either 'true' or 'false')")),
+ new LayoutOption ("set-volume=LEVEL", Catalog.GetString ("Set the playback volume (0-100)")),
+ new LayoutOption ("set-position=POS", Catalog.GetString ("Seek to a specific point (seconds, float)"))
+ ),
+
+ new LayoutGroup ("query-player", Catalog.GetString ("Player Engine Query Options"),
+ new LayoutOption ("query-current-state", Catalog.GetString ("Current player state")),
+ new LayoutOption ("query-last-state", Catalog.GetString ("Last player state")),
+ new LayoutOption ("query-can-pause", Catalog.GetString ("Query whether the player can be paused")),
+ new LayoutOption ("query-can-seek", Catalog.GetString ("Query whether the player can seek")),
+ new LayoutOption ("query-volume", Catalog.GetString ("Player volume")),
+ new LayoutOption ("query-position", Catalog.GetString ("Player position in currently playing track"))
+ ),
+
+ new LayoutGroup ("query-track", Catalog.GetString ("Playing Track Metadata Query Options"),
+ new LayoutOption ("query-uri", Catalog.GetString ("URI")),
+ new LayoutOption ("query-artist", Catalog.GetString ("Artist Name")),
+ new LayoutOption ("query-album", Catalog.GetString ("Album Title")),
+ new LayoutOption ("query-title", Catalog.GetString ("Track Title")),
+ new LayoutOption ("query-duration", Catalog.GetString ("Duration")),
+ new LayoutOption ("query-track-number", Catalog.GetString ("Track Number")),
+ new LayoutOption ("query-track-count", Catalog.GetString ("Track Count")),
+ new LayoutOption ("query-disc", Catalog.GetString ("Disc Number")),
+ new LayoutOption ("query-year", Catalog.GetString ("Year")),
+ new LayoutOption ("query-rating", Catalog.GetString ("Rating"))
+ ),
+
+ new LayoutGroup ("ui", Catalog.GetString ("User Interface Options"),
+ new LayoutOption ("show|--present", Catalog.GetString ("Present the user interface on the active workspace")),
+ new LayoutOption ("hide", Catalog.GetString ("Hide the user interface")),
+ new LayoutOption ("no-present", Catalog.GetString ("Do not present the user interface, regardless of any other options"))
+ ),
+
+ new LayoutGroup ("debugging", Catalog.GetString ("Debugging and Development Options"),
+ new LayoutOption ("debug", Catalog.GetString ("Enable general debugging features")),
+ new LayoutOption ("debug-sql", Catalog.GetString ("Enable debugging output of SQL queries")),
+ new LayoutOption ("debug-addins", Catalog.GetString ("Enable debugging output of Mono.Addins")),
+ new LayoutOption ("db=FILE", Catalog.GetString ("Specify an alternate database to use")),
+ new LayoutOption ("uninstalled", Catalog.GetString ("Optimize instance for running uninstalled; " +
+ "most notably, this will create an alternate Mono.Addins database in the working directory")),
+ new LayoutOption ("disable-dbus", Catalog.GetString ("Disable DBus support completely")),
+ new LayoutOption ("no-gtkrc", String.Format (Catalog.GetString (
+ "Skip loading a custom gtkrc file ({0}) if it exists"),
+ user_gtkrc.Replace (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "~")))
+ )
+ );
+
+ if (ApplicationContext.CommandLine.Contains ("help-all")) {
+ Console.WriteLine (commands);
+ return;
+ }
+
+ List<string> errors = null;
+
+ foreach (KeyValuePair<string, string> argument in ApplicationContext.CommandLine.Arguments) {
+ switch (argument.Key) {
+ case "help": Console.WriteLine (commands.ToString ("help")); break;
+ case "help-debug": Console.WriteLine (commands.ToString ("debugging")); break;
+ case "help-query-track": Console.WriteLine (commands.ToString ("query-track")); break;
+ case "help-control-player": Console.WriteLine (commands.ToString ("query-player")); break;
+ case "help-ui": Console.WriteLine (commands.ToString ("ui")); break;
+ case "help-playback": Console.WriteLine (commands.ToString ("playback")); break;
+ default:
+ if (argument.Key.StartsWith ("help")) {
+ if (errors == null) {
+ errors = new List<string> ();
+ }
+ errors.Add (argument.Key);
+ }
+ break;
+ }
+ }
+
+ if (errors != null) {
+ Console.WriteLine (commands.LayoutLine (String.Format (Catalog.GetString (
+ "The following help arguments are invalid: {0}"),
+ Hyena.Collections.CollectionExtensions.Join (errors, "--", null, ", "))));
+ }
+ }
+
+ private static void ShowVersion ()
+ {
+ Console.WriteLine ("Banshee {0} ({1}) http://banshee-project.org", Application.DisplayVersion, Application.Version);
+ Console.WriteLine ("Copyright 2005-{0} Novell, Inc. and Contributors.", DateTime.Now.Year);
}
public override string ClientId {
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/IClientWindow.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/IClientWindow.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/IClientWindow.cs Tue Jun 3 18:57:07 2008
@@ -37,5 +37,6 @@
public interface IClientWindow : IDBusExportable
{
void Present ();
+ void Hide ();
}
}
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs Tue Jun 3 18:57:07 2008
@@ -27,6 +27,7 @@
//
using System;
+using System.Text;
using System.Collections.Generic;
namespace Hyena.Collections
@@ -44,5 +45,43 @@
list.Insert (index < 0 ? ~index : index, value);
}
}
+
+ public static string Join<T> (IList<T> list)
+ {
+ return Join<T> (list, ", ");
+ }
+
+ public static string Join<T> (IList<T> list, string separator)
+ {
+ return Join<T> (list, null, null, separator);
+ }
+
+ public static string Join<T> (IList<T> list, string wrapper, string separator)
+ {
+ return Join<T> (list, wrapper, wrapper, separator);
+ }
+
+ public static string Join<T> (IList<T> list, string front, string back, string separator)
+ {
+ StringBuilder builder = new StringBuilder ();
+
+ for (int i = 0, n = list.Count; i < n; i++) {
+ if (front != null) {
+ builder.Append (front);
+ }
+
+ builder.Append (list[i]);
+
+ if (back != null) {
+ builder.Append (back);
+ }
+
+ if (i < n - 1) {
+ builder.Append (separator);
+ }
+ }
+
+ return builder.ToString ();
+ }
}
}
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/CommandLineParser.cs Tue Jun 3 18:57:07 2008
@@ -119,6 +119,16 @@
return parsed_arguments.ContainsKey (name);
}
+ public bool ContainsStart (string start)
+ {
+ foreach (string argument in parsed_arguments.Keys) {
+ if (argument.StartsWith (start)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public string this[string name] {
get { return Contains (name) ? parsed_arguments[name].Value : String.Empty; }
set {
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/Layout.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/Layout.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/Layout.cs Tue Jun 3 18:57:07 2008
@@ -45,14 +45,28 @@
{
}
+ private int TerminalWidth {
+ get { return Console.WindowWidth <= 0 ? 80 : Console.WindowWidth; }
+ }
+
+ public string ToString (params string [] groupIds)
+ {
+ return ToString (GroupIdsToGroups (groupIds));
+ }
+
public override string ToString ()
{
+ return ToString (groups);
+ }
+
+ public string ToString (IEnumerable<LayoutGroup> groups)
+ {
StringBuilder builder = new StringBuilder ();
- int terminal_width = Console.WindowWidth <= 0 ? 80 : Console.WindowWidth;
int min_spacing = 6;
int group_index = 0;
+ int group_count = 0;
int max_option_length = 0;
int max_description_length = 0;
int description_alignment = 0;
@@ -65,31 +79,44 @@
}
}
- max_description_length = terminal_width - max_option_length - min_spacing - 4;
+ max_description_length = TerminalWidth - max_option_length - min_spacing - 4;
description_alignment = max_option_length + min_spacing + 4;
+ IEnumerator<LayoutGroup> enumerator = groups.GetEnumerator ();
+ while (enumerator.MoveNext ()) {
+ group_count++;
+ }
+
foreach (LayoutGroup group in groups) {
if (group.Id != "default") {
builder.Append (group.Title);
- builder.Append ("\n\n");
+ builder.AppendLine ();
+ builder.AppendLine ();
}
- foreach (LayoutOption option in group) {
- int spacing = (max_option_length - option.Name.Length) + min_spacing;
- builder.AppendFormat (" --{0}{2}{1}\n", option.Name,
- WrapAlign (option.Description, max_description_length, description_alignment),
+ for (int i = 0, n = group.Count; i < n; i++) {
+ int spacing = (max_option_length - group[i].Name.Length) + min_spacing;
+ builder.AppendFormat (" --{0}{2}{1}", group[i].Name,
+ WrapAlign (group[i].Description, max_description_length,
+ description_alignment, i == n - 1),
String.Empty.PadRight (spacing));
+ builder.AppendLine ();
}
- if (group_index++ < groups.Count - 1) {
- builder.Append ("\n");
+ if (group_index++ < group_count - 1) {
+ builder.AppendLine ();
}
}
return builder.ToString ();
}
- private static string WrapAlign (string str, int width, int align)
+ public string LayoutLine (string str)
+ {
+ return WrapAlign (str, TerminalWidth, 0, true);
+ }
+
+ private static string WrapAlign (string str, int width, int align, bool last)
{
StringBuilder builder = new StringBuilder ();
bool did_wrap = false;
@@ -100,7 +127,8 @@
for (int j = i + 1; j < str.Length && str[j] != ' '; word_length++, j++);
if (b + word_length >= width) {
- builder.AppendFormat ("\n{0}", String.Empty.PadRight (align));
+ builder.AppendLine ();
+ builder.Append (String.Empty.PadRight (align));
b = 0;
did_wrap = true;
continue;
@@ -110,8 +138,8 @@
builder.Append (str[i]);
}
- if (did_wrap) {
- builder.Append ('\n');
+ if (did_wrap && !last) {
+ builder.AppendLine ();
}
return builder.ToString ();
@@ -146,6 +174,16 @@
return null;
}
+ private IEnumerable<LayoutGroup> GroupIdsToGroups (string [] groupIds)
+ {
+ foreach (string group_id in groupIds) {
+ LayoutGroup group = FindGroup (group_id);
+ if (group != null) {
+ yield return group;
+ }
+ }
+ }
+
public static LayoutOption Option (string name, string description)
{
return new LayoutOption (name, description);
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/LayoutGroup.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/LayoutGroup.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.CommandLine/LayoutGroup.cs Tue Jun 3 18:57:07 2008
@@ -93,6 +93,11 @@
return null;
}
+ public LayoutOption this[int index] {
+ get { return options[index]; }
+ set { options[index] = value; }
+ }
+
public int Count {
get { return options.Count; }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]