using System; using Mono.Unix; using Gtk; using Banshee.Collection; using Banshee.Gui.TrackEditor; namespace ThirdParty.TrackEditor { public class HistoryPage : FieldPage, ITrackEditorPage { private Gdk.Color error_color; private Gdk.Color base_color; public int Order { get { return 30; } } public string Title { get { return Catalog.GetString ("History"); } } protected override void AddFields () { // Make a box for horizontal layout of the skip/plays fields HBox box = new HBox (); box.Spacing = 10; box.Show (); PackStart (box, false, false, 0); // Pack a new field of type ClearableSpinButtonEntry into our box AddField (box, new ClearableSpinButtonEntry (), // Set the tooltip for this field's sync action Catalog.GetString ("Set all play counts to this value"), // Set the label for this field (track, widget) => Catalog.GetString ("Number of Plays:"), // Implement value reading and writing handlers (track, widget) => ((ClearableSpinButtonEntry)widget).Value = track.PlayCount, (track, widget) => track.PlayCount = (int)((ClearableSpinButtonEntry)widget).Value, // Tell the field to be shrunk when packing FieldOptions.Shrink ); // Now add one for number of skips AddField (box, new ClearableSpinButtonEntry (), Catalog.GetString ("Set all skip counts to this value"), (track, widget) => Catalog.GetString ("Number of Skips:"), (track, widget) => ((ClearableSpinButtonEntry)widget).Value = track.SkipCount, (track, widget) => track.SkipCount = (int)((ClearableSpinButtonEntry)widget).Value, FieldOptions.Shrink ); // And add a date field for last played AddField (this, new DateEntry (), Catalog.GetString ("Set all last played dates to this value"), (track, widget) => Catalog.GetString ("Last Played:"), (track, widget) => ((DateEntry)widget).Text = track.LastPlayed.ToString (), (track, widget) => { var date = ((DateEntry)widget).Text; try { track.LastPlayed = DateTime.Parse (date); widget.ModifyBase (StateType.Normal, base_color); } catch { widget.ModifyBase (StateType.Normal, error_color); } }, FieldOptions.Shrink ); // TODO: Add fields for last skipped and imported on dates } protected override void OnStyleSet (Style previous) { base.OnStyleSet (previous); base_color = Style.Base (StateType.Normal); error_color = new Gdk.Color (0xf6, 0x7b, 0x7b); Gdk.Colormap.System.AllocColor (ref error_color, true, true); } // Interface for querying and resetting all history fields // Create a wrapper widget that is an editor field, adding // a clear button to the existing SpinButtonEntry field private class ClearableSpinButtonEntry : HBox, IEditorField { private SpinButtonEntry entry; // Chain the IEditorField.Changed event to the real edit widget public event EventHandler Changed { add { entry.Changed += value; } remove { entry.Changed -= value; } } // Chain the SpinButtonEntry Value property public double Value { get { return entry.Value; } set { entry.Value = value; } } // A helper constructor for some default settings public ClearableSpinButtonEntry () : this (0, Double.MaxValue, 1) { } // Create the wrapper widget, packing the real // editing widget and our new clear button public ClearableSpinButtonEntry (double min, double max, double step) { entry = new SpinButtonEntry (min, max, step); Button clear_button = new Button (new Image (Stock.Clear, IconSize.Menu)); clear_button.Relief = ReliefStyle.None; clear_button.Clicked += (o, e) => Value = 0; Spacing = 2; entry.Show (); clear_button.Show (); PackStart (entry, false, false, 0); PackStart (clear_button, false, false, 0); } } // A wrapper class so we have a type to reflect/query private class DateEntry : TextEntry { } } }