Skip to content

Commit

Permalink
Linux: Updated Main Window after changes on other platforms. Markers …
Browse files Browse the repository at this point in the history
…can now be added and selected. Related to issue #382.
  • Loading branch information
ycastonguay committed Aug 19, 2013
1 parent b07731e commit 4d5961e
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 81 deletions.
237 changes: 201 additions & 36 deletions MPfm/MPfm.GTK/Windows/MainWindow.cs
Expand Up @@ -33,6 +33,7 @@
using MPfm.GTK.Helpers;
using MPfm.MVP.Messages;
using MPfm.Player.Objects;
using MPfm.MVP.Presenters;

namespace MPfm.GTK.Windows
{
Expand All @@ -44,6 +45,7 @@ public partial class MainWindow: BaseWindow, IMainView
private bool _isSongPositionChanging = false;
private Gtk.TreeStore _storeLibraryBrowser = null;
private Gtk.ListStore _storeSongBrowser = null;
private Gtk.ListStore _storeMarkers = null;
private Gtk.ListStore _storeAudioFileFormat = null;

#region Application Init/Destroy
Expand All @@ -64,10 +66,10 @@ public MainWindow(Action<IBaseView> onViewReady): base (Gtk.WindowType.Toplevel,
SetFontProperties();
InitializeSongBrowser();
InitializeLibraryBrowser();
InitializeMarkers();

// Force refresh song browser to create columns
RefreshSongBrowser(new List<AudioFile>());
RefreshRepeatButton();
RefreshSongInformation(null, 0, 0, 0);

// Fill sound format combo box
Expand Down Expand Up @@ -259,32 +261,71 @@ private void RenderLibraryBrowserCell(Gtk.TreeViewColumn column, Gtk.CellRendere
object propertyValue = propertyInfo.GetValue(entity, null);
(cell as Gtk.CellRendererText).Text = propertyValue.ToString();
}

/// <summary>
/// Refreshes the "Repeat" button in the main window toolbar.
/// </summary>
public void RefreshRepeatButton()
{
string repeatOff = "Off";
string repeatPlaylist = "Playlist";
string repeatSong = "Song";

// Display the repeat type
// if (playerPresenter.Player.RepeatType == RepeatType.Playlist)
// {
// actionRepeatType.Label = actionRepeatType.ShortLabel = "Repeat Type (" + repeatPlaylist + ")";
// }
// else if (playerPresenter.Player.RepeatType == RepeatType.Song)
// {
// actionRepeatType.Label = actionRepeatType.ShortLabel = "Repeat Type (" + repeatSong + ")";
// }
// else
// {
// actionRepeatType.Label = actionRepeatType.ShortLabel = "Repeat Type (" + repeatOff + ")";
// }
}

#endregion

#region Markers Methods

protected void InitializeMarkers()
{
_storeMarkers = new Gtk.ListStore(typeof(Marker));

Gtk.TreeViewColumn colTitle = new Gtk.TreeViewColumn();
Gtk.CellRendererText cellTitle = new Gtk.CellRendererText();
colTitle.Title = "Name";
colTitle.Resizable = true;
colTitle.Data.Add("Property", "Name");
colTitle.PackStart(cellTitle, true);
colTitle.SetCellDataFunc(cellTitle, new Gtk.TreeCellDataFunc(RenderMarkerCell));
treeMarkers.AppendColumn(colTitle);

Gtk.TreeViewColumn colPosition = new Gtk.TreeViewColumn();
Gtk.CellRendererText cellPosition = new Gtk.CellRendererText();
colPosition.Title = "Position";
colPosition.Resizable = true;
colPosition.Data.Add("Property", "Position");
colPosition.PackStart(cellPosition, true);
colPosition.SetCellDataFunc(cellPosition, new Gtk.TreeCellDataFunc(RenderMarkerCell));
treeMarkers.AppendColumn(colPosition);
}

/// <summary>
/// Renders a cell from the Song Browser.
/// </summary>
/// <param name='column'>Column</param>
/// <param name='cell'>Cell</param>
/// <param name='model'>Model</param>
/// <param name='iter'>Iter</param>
private void RenderMarkerCell(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
// Get model data
//Console.WriteLine("MainWindow - RenderMarkerCell");
Marker marker = (Marker)model.GetValue(iter, 0);

// Get property name
string property = (string)column.Data["Property"];
if(String.IsNullOrEmpty(property))
return;

// Get value and set cell text
PropertyInfo propertyInfo = typeof(Marker).GetProperty(property);
object propertyValue = propertyInfo.GetValue(marker, null);
(cell as Gtk.CellRendererText).Text = propertyValue.ToString();

}

protected void OnTreeMarkersRowActivated(object o, RowActivatedArgs args)
{
TreeModel model;
TreeIter iter;
if((o as TreeView).Selection.GetSelected(out model, out iter))
{
Marker marker = (Marker)_storeMarkers.GetValue(iter, 0);
OnSelectMarker(marker);
}
}

#endregion

#region Other Methods

Expand Down Expand Up @@ -478,8 +519,6 @@ protected void OnActionRepeatTypeActivated(object sender, System.EventArgs e)
// playerPresenter.Player.RepeatType = RepeatType.Off;
// }

// Update repeat button
RefreshRepeatButton();
}

protected void OnActionPlaylistActivated(object sender, System.EventArgs e)
Expand Down Expand Up @@ -614,6 +653,34 @@ protected void OnTreeSongBrowserRowActivated(object sender, Gtk.RowActivatedArgs
OnTableRowDoubleClicked(audioFile);
}
}

protected void OnActionPlayLoopActivated(object sender, EventArgs e)
{
}

protected void OnActionGoToMarkerActivated(object sender, EventArgs e)
{
TreeModel model;
TreeIter iter;
if(treeMarkers.Selection.GetSelected(out model, out iter))
{
Marker marker = (Marker)_storeMarkers.GetValue(iter, 0);
OnSelectMarker(marker);
}
}

protected void OnActionAddMarkerActivated(object sender, EventArgs e)
{
OnAddMarker(MarkerTemplateNameType.Verse);
}

protected void OnActionEditMarkerActivated(object sender, EventArgs e)
{
}

protected void OnActionDeleteMarkerActivated(object sender, EventArgs e)
{
}

#endregion

Expand Down Expand Up @@ -804,12 +871,7 @@ public void RefreshLoops(IEnumerable<Loop> loops)
public void PlayerError(Exception ex)
{
Gtk.Application.Invoke(delegate{
StringBuilder sb = new StringBuilder();
sb.AppendLine("An error occured in the Player component:");
sb.AppendLine(ex.Message);
sb.AppendLine();
sb.AppendLine(ex.StackTrace);
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, string.Format("An error occured in the Player component: {0}", ex));
md.Run();
md.Destroy();
});
Expand Down Expand Up @@ -910,13 +972,116 @@ public void RefreshSongBrowser(IEnumerable<AudioFile> audioFiles)
catch(Exception ex) {
Console.WriteLine("RefreshSongBrowser - Exception: " + ex.Message + "\n" + ex.StackTrace);
throw ex;
//MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "An error occured while refreshing the Song Browser: " + ex.Message + "\n" + ex.StackTrace);
//md.Run();
//md.Destroy();
}
});
}

#endregion

#region IMarkersView implementation

public Action<MarkerTemplateNameType> OnAddMarker { get; set; }
public Action<Marker> OnEditMarker { get; set; }
public Action<Marker> OnSelectMarker { get; set; }

public void MarkerError(Exception ex)
{
Gtk.Application.Invoke(delegate{
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, string.Format("An error occured in the Markers component: {0}", ex));
md.Run();
md.Destroy();
});
}

public void RefreshMarkers(List<Marker> markers)
{
Gtk.Application.Invoke(delegate{
try
{
Console.WriteLine("MainWindow - RefreshMarkers - markers.Count: {0}", markers.Count);
_storeMarkers.Clear();
foreach(var marker in markers)
_storeMarkers.AppendValues(marker);
treeMarkers.Model = _storeMarkers;
}
catch(Exception ex) {
Console.WriteLine("RefreshMarkers - Exception: " + ex.Message + "\n" + ex.StackTrace);
throw ex;
}
});
}

#endregion

#region ILoopsView implementation

public System.Action OnAddLoop { get; set; }
public Action<Loop> OnEditLoop { get; set; }

public void LoopError(Exception ex)
{
Gtk.Application.Invoke(delegate{
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, string.Format("An error occured in the Loops component: {0}", ex));
md.Run();
md.Destroy();
});
}

public void RefreshLoops(List<Loop> loops)
{
}

#endregion

#region ITimeShiftingView implementation

public Action<float> OnSetTimeShifting { get; set; }
public System.Action OnResetTimeShifting { get; set; }
public System.Action OnUseDetectedTempo { get; set; }
public System.Action OnIncrementTempo { get; set; }
public System.Action OnDecrementTempo { get; set; }

public void TimeShiftingError(Exception ex)
{
Gtk.Application.Invoke(delegate{
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, string.Format("An error occured in the TimeShifting component: {0}", ex));
md.Run();
md.Destroy();
});
}

public void RefreshTimeShifting(PlayerTimeShiftingEntity entity)
{
}

#endregion

#region IPitchShiftingView implementation

public Action<int> OnChangeKey { get; set; }
public Action<int> OnSetInterval { get; set; }
public System.Action OnResetInterval { get; set; }
public System.Action OnIncrementInterval { get; set; }
public System.Action OnDecrementInterval { get; set; }

public void PitchShiftingError(Exception ex)
{
Gtk.Application.Invoke(delegate{
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, string.Format("An error occured in the PitchShifting component: {0}", ex));
md.Run();
md.Destroy();
});
}

public void RefreshKeys(List<Tuple<int, string>> keys)
{
}

public void RefreshPitchShifting(PlayerPitchShiftingEntity entity)
{
}

#endregion

}
}
1 change: 1 addition & 0 deletions MPfm/MPfm.GTK/gtk-gui/MPfm.GTK.SyncMenuWindow.cs
Expand Up @@ -45,6 +45,7 @@ protected virtual void Build ()
this.vbox2.BorderWidth = ((uint)(8));
// Container child vbox2.Gtk.Box+BoxChild
this.hbox3 = new global::Gtk.HBox ();
this.hbox3.Name = "hbox3";
this.hbox3.Spacing = 6;
// Container child hbox3.Gtk.Box+BoxChild
this.vbox4 = new global::Gtk.VBox ();
Expand Down
9 changes: 8 additions & 1 deletion MPfm/MPfm.GTK/gtk-gui/MPfm.GTK.Windows.MainWindow.cs
Expand Up @@ -711,6 +711,7 @@ protected virtual void Build ()
w47.Fill = false;
// Container child vbox8.Gtk.Box+BoxChild
this.hbox3 = new global::Gtk.HBox ();
this.hbox3.Name = "hbox3";
this.hbox3.Spacing = 4;
// Container child hbox3.Gtk.Box+BoxChild
this.lblTimeShiftingReset = new global::Gtk.Label ();
Expand Down Expand Up @@ -879,7 +880,7 @@ protected virtual void Build ()
w66.Expand = false;
w66.Fill = false;
// Container child hbox9.Gtk.Box+BoxChild
this.UIManager.AddUiFromString ("<ui><toolbar name='toolbarMarkers'><toolitem name='actionGoToMarker' action='actionGoToMarker'/><toolitem name='actionAddMarker' action='actionAddMarker'/><toolitem name='actionRemoveMarker' action='actionRemoveMarker'/><toolitem name='actionEditMarker' action='actionEditMarker'/></toolbar></ui>");
this.UIManager.AddUiFromString ("<ui><toolbar name='toolbarMarkers'><toolitem name='actionGoToMarker' action='actionGoToMarker'/><toolitem name='actionAddMarker' action='actionAddMarker'/><toolitem name='actionEditMarker' action='actionEditMarker'/><toolitem name='actionRemoveMarker' action='actionRemoveMarker'/></toolbar></ui>");
this.toolbarMarkers = ((global::Gtk.Toolbar)(this.UIManager.GetWidget ("/toolbarMarkers")));
this.toolbarMarkers.Name = "toolbarMarkers";
this.toolbarMarkers.ShowArrow = false;
Expand Down Expand Up @@ -999,8 +1000,13 @@ protected virtual void Build ()
this.actionSettings.Activated += new global::System.EventHandler (this.OnActionSettingsActivated);
this.actionEffects.Activated += new global::System.EventHandler (this.OnActionEffectsActivated);
this.actionPlaylist.Activated += new global::System.EventHandler (this.OnActionPlaylistActivated);
this.actionAddMarker.Activated += new global::System.EventHandler (this.OnActionAddMarkerActivated);
this.actionRemoveMarker.Activated += new global::System.EventHandler (this.OnActionDeleteMarkerActivated);
this.actionEditMarker.Activated += new global::System.EventHandler (this.OnActionEditMarkerActivated);
this.actionGoToMarker.Activated += new global::System.EventHandler (this.OnActionGoToMarkerActivated);
this.actionAddFiles.Activated += new global::System.EventHandler (this.OnActionAddFilesActivated);
this.actionAddFolder.Activated += new global::System.EventHandler (this.OnActionAddFolderActivated);
this.actionPlayLoop.Activated += new global::System.EventHandler (this.OnActionPlayLoopActivated);
this.connectAction.Activated += new global::System.EventHandler (this.OnActionSyncLibrary);
this.cboSoundFormat.Changed += new global::System.EventHandler (this.OnSoundFormatChanged);
this.treeLibraryBrowser.RowActivated += new global::Gtk.RowActivatedHandler (this.OnTreeLibraryBrowserRowActivated);
Expand All @@ -1011,6 +1017,7 @@ protected virtual void Build ()
this.hscaleSongPosition.ButtonReleaseEvent += new global::Gtk.ButtonReleaseEventHandler (this.OnHscaleSongPositionButtonReleaseEvent);
this.hscaleTimeShifting.ValueChanged += new global::System.EventHandler (this.OnTimeShiftingValueChanged);
this.vscaleVolume.ValueChanged += new global::System.EventHandler (this.OnVolumeValueChanged);
this.treeMarkers.RowActivated += new global::Gtk.RowActivatedHandler (this.OnTreeMarkersRowActivated);
this.treeSongBrowser.RowActivated += new global::Gtk.RowActivatedHandler (this.OnTreeSongBrowserRowActivated);
}
}
Expand Down

0 comments on commit 4d5961e

Please sign in to comment.