Skip to content

Commit

Permalink
Mac: Update Library now opens through MainPresenter (like the last co…
Browse files Browse the repository at this point in the history
…mmit on Windows).

Related to issue #381.
  • Loading branch information
ycastonguay committed Aug 18, 2013
1 parent 8f5cf2d commit c62da08
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 96 deletions.
129 changes: 58 additions & 71 deletions MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs
Expand Up @@ -46,55 +46,21 @@ namespace MPfm.Mac
/// </summary>
public partial class MainWindowController : BaseWindowController, IMainView
{
public System.Action OnOpenPreferencesWindow { get; set; }
public System.Action OnOpenEffectsWindow { get; set; }
public System.Action OnOpenPlaylistWindow { get; set; }
public System.Action OnOpenSyncWindow { get; set; }
public System.Action OnPlayerPlay { get; set; }
public System.Action<IEnumerable<string>> OnPlayerPlayFiles { get; set; }
public System.Action OnPlayerPause { get; set; }
public System.Action OnPlayerStop { get; set; }
public System.Action OnPlayerPrevious { get; set; }
public System.Action OnPlayerNext { get; set; }
public System.Action<float> OnPlayerSetPitchShifting { get; set; }
public System.Action<float> OnPlayerSetTimeShifting { get; set; }
public System.Action<float> OnPlayerSetVolume { get; set; }
public System.Action<float> OnPlayerSetPosition { get; set; }
public Func<float, PlayerPositionEntity> OnPlayerRequestPosition { get; set; }

public System.Action<AudioFileFormat> OnAudioFileFormatFilterChanged { get; set; }
public System.Action<LibraryBrowserEntity> OnTreeNodeSelected { get; set; }
public System.Action<LibraryBrowserEntity, object> OnTreeNodeExpanded { get; set; }
public System.Action<LibraryBrowserEntity> OnTreeNodeDoubleClicked { get; set; }
public Func<LibraryBrowserEntity, IEnumerable<LibraryBrowserEntity>> OnTreeNodeExpandable { get; set; }

public System.Action<AudioFile> OnTableRowDoubleClicked { get; set; }

UpdateLibraryWindowController updateLibraryWindowController = null;
LibraryBrowserOutlineViewDelegate libraryBrowserOutlineViewDelegate = null;
LibraryBrowserDataSource libraryBrowserDataSource = null;
SongBrowserTableViewDelegate songBrowserOutlineViewDelegate = null;
SongBrowserSource songBrowserSource = null;
AlbumCoverSource albumCoverSource = null;
AlbumCoverCacheService albumCoverCacheService = null;

//strongly typed window accessor00
public new MainWindow Window {
get {
return (MainWindow)base.Window;
}
}

// Called when created from unmanaged code
LibraryBrowserOutlineViewDelegate _libraryBrowserOutlineViewDelegate = null;
LibraryBrowserDataSource _libraryBrowserDataSource = null;
SongBrowserTableViewDelegate _songBrowserOutlineViewDelegate = null;
SongBrowserSource _songBrowserSource = null;
AlbumCoverSource _albumCoverSource = null;
AlbumCoverCacheService _albumCoverCacheService = null;

public MainWindowController(IntPtr handle)
: base (handle)
{
}

// Call to load from the XIB/NIB file
public MainWindowController(Action<IBaseView> onViewReady) : base ("MainWindow", onViewReady)
{
this.albumCoverCacheService = new AlbumCoverCacheService();
this._albumCoverCacheService = new AlbumCoverCacheService();
this.Window.AlphaValue = 0;
this.Window.MakeKeyAndOrderFront(this);

Expand Down Expand Up @@ -125,13 +91,13 @@ public override void WindowDidLoad()
cboSoundFormat.AddItem("WAV");
cboSoundFormat.AddItem("WV");

libraryBrowserOutlineViewDelegate = new LibraryBrowserOutlineViewDelegate((entity) => { OnTreeNodeSelected(entity); });
outlineLibraryBrowser.Delegate = libraryBrowserOutlineViewDelegate;
_libraryBrowserOutlineViewDelegate = new LibraryBrowserOutlineViewDelegate((entity) => { OnTreeNodeSelected(entity); });
outlineLibraryBrowser.Delegate = _libraryBrowserOutlineViewDelegate;
outlineLibraryBrowser.AllowsMultipleSelection = false;
outlineLibraryBrowser.DoubleClick += HandleLibraryBrowserDoubleClick;

songBrowserOutlineViewDelegate = new SongBrowserTableViewDelegate();
tableSongBrowser.Delegate = songBrowserOutlineViewDelegate;
_songBrowserOutlineViewDelegate = new SongBrowserTableViewDelegate();
tableSongBrowser.Delegate = _songBrowserOutlineViewDelegate;
tableSongBrowser.AllowsMultipleSelection = true;
tableSongBrowser.DoubleClick += HandleSongBrowserDoubleClick;

Expand Down Expand Up @@ -348,7 +314,6 @@ private void LoadImages()

partial void actionAddFilesToLibrary(NSObject sender)
{
// Open panel to choose audio files
IEnumerable<string> filePaths = null;
using(NSOpenPanel openPanel = new NSOpenPanel())
{
Expand All @@ -358,13 +323,13 @@ private void LoadImages()
openPanel.AllowsMultipleSelection = true;
openPanel.AllowedFileTypes = new string[]{ "FLAC", "MP3", "OGG", "WAV", "MPC", "WV" };
openPanel.Title = "Please select audio files to add to the library";
openPanel.Prompt = "Add to library";
openPanel.Prompt = "Add files to library";
openPanel.RunModal();
filePaths = openPanel.Urls.Select(x => x.Path);
}

if(filePaths != null && filePaths.Count() > 0)
StartUpdateLibrary(UpdateLibraryMode.SpecificFiles, filePaths.ToList(), null);
OnAddFilesToLibrary(filePaths.ToList());
}

partial void actionAddFolderLibrary(NSObject sender)
Expand All @@ -377,13 +342,13 @@ private void LoadImages()
openPanel.ReleasedWhenClosed = true;
openPanel.AllowsMultipleSelection = false;
openPanel.Title = "Please select a folder to add to the library";
openPanel.Prompt = "Add to library";
openPanel.Prompt = "Add folder to library";
openPanel.RunModal();
folderPath = openPanel.Url.Path;
}

if(!String.IsNullOrEmpty(folderPath))
StartUpdateLibrary(UpdateLibraryMode.SpecificFolder, null, folderPath);
OnAddFolderToLibrary(folderPath);
}

partial void actionOpenAudioFiles(NSObject sender)
Expand All @@ -408,7 +373,7 @@ private void LoadImages()

partial void actionUpdateLibrary(NSObject sender)
{
StartUpdateLibrary(UpdateLibraryMode.WholeLibrary, null, null);
OnUpdateLibrary();
}

partial void actionSoundFormatChanged(NSObject sender)
Expand Down Expand Up @@ -587,7 +552,7 @@ protected void HandleSongBrowserDoubleClick(object sender, EventArgs e)
try
{
// Get selected item and start playback
AudioFile audioFile = songBrowserSource.Items[tableSongBrowser.SelectedRow].AudioFile;
AudioFile audioFile = _songBrowserSource.Items[tableSongBrowser.SelectedRow].AudioFile;
if(OnTableRowDoubleClicked != null)
OnTableRowDoubleClicked.Invoke(audioFile);
}
Expand All @@ -604,23 +569,25 @@ protected void HandleSongBrowserDoubleClick(object sender, EventArgs e)
}
}

void StartUpdateLibrary(UpdateLibraryMode mode, List<string> filePaths, string folderPath)
{
if(updateLibraryWindowController != null)
updateLibraryWindowController.Dispose();

updateLibraryWindowController = new UpdateLibraryWindowController(this, null);
updateLibraryWindowController.Window.MakeKeyAndOrderFront(this);
updateLibraryWindowController.StartProcess(mode, filePaths, folderPath);
}

public void RefreshAll()
{
OnAudioFileFormatFilterChanged(AudioFileFormat.All);
}

#region IPlayerView implementation

public System.Action OnPlayerPlay { get; set; }
public System.Action<IEnumerable<string>> OnPlayerPlayFiles { get; set; }
public System.Action OnPlayerPause { get; set; }
public System.Action OnPlayerStop { get; set; }
public System.Action OnPlayerPrevious { get; set; }
public System.Action OnPlayerNext { get; set; }
public System.Action<float> OnPlayerSetPitchShifting { get; set; }
public System.Action<float> OnPlayerSetTimeShifting { get; set; }
public System.Action<float> OnPlayerSetVolume { get; set; }
public System.Action<float> OnPlayerSetPosition { get; set; }
public Func<float, PlayerPositionEntity> OnPlayerRequestPosition { get; set; }

public void RefreshPlayerStatus(PlayerStatusType status)
{
InvokeOnMainThread(() => {
Expand Down Expand Up @@ -682,8 +649,8 @@ public void RefreshSongInformation(AudioFile audioFile, long lengthBytes, int pl
imageAlbumCover.Image = new NSImage();
}
if(songBrowserSource != null)
songBrowserSource.RefreshIsPlaying(tableSongBrowser, audioFile.FilePath);
if(_songBrowserSource != null)
_songBrowserSource.RefreshIsPlaying(tableSongBrowser, audioFile.FilePath);
});
}

Expand Down Expand Up @@ -731,25 +698,33 @@ public void PlayerError(Exception ex)

#region ISongBrowserView implementation

public System.Action<AudioFile> OnTableRowDoubleClicked { get; set; }

public void RefreshSongBrowser(IEnumerable<AudioFile> audioFiles)
{
InvokeOnMainThread(() => {
songBrowserSource = new SongBrowserSource(audioFiles);
tableSongBrowser.Source = songBrowserSource;
albumCoverSource = new AlbumCoverSource(albumCoverCacheService, audioFiles);
tableAlbumCovers.Source = albumCoverSource;
_songBrowserSource = new SongBrowserSource(audioFiles);
tableSongBrowser.Source = _songBrowserSource;
_albumCoverSource = new AlbumCoverSource(_albumCoverCacheService, audioFiles);
tableAlbumCovers.Source = _albumCoverSource;
});
}

#endregion

#region ILibraryBrowserView implementation

public System.Action<AudioFileFormat> OnAudioFileFormatFilterChanged { get; set; }
public System.Action<LibraryBrowserEntity> OnTreeNodeSelected { get; set; }
public System.Action<LibraryBrowserEntity, object> OnTreeNodeExpanded { get; set; }
public System.Action<LibraryBrowserEntity> OnTreeNodeDoubleClicked { get; set; }
public Func<LibraryBrowserEntity, IEnumerable<LibraryBrowserEntity>> OnTreeNodeExpandable { get; set; }

public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities)
{
InvokeOnMainThread(() => {
libraryBrowserDataSource = new LibraryBrowserDataSource(entities, (entity) => { return this.OnTreeNodeExpandable(entity); });
outlineLibraryBrowser.DataSource = libraryBrowserDataSource;
_libraryBrowserDataSource = new LibraryBrowserDataSource(entities, (entity) => { return this.OnTreeNodeExpandable(entity); });
outlineLibraryBrowser.DataSource = _libraryBrowserDataSource;
});
}

Expand All @@ -760,5 +735,17 @@ public void RefreshLibraryBrowserNode(LibraryBrowserEntity entity, IEnumerable<L

#endregion

#region IMainView implementation

public System.Action OnOpenPreferencesWindow { get; set; }
public System.Action OnOpenEffectsWindow { get; set; }
public System.Action OnOpenPlaylistWindow { get; set; }
public System.Action OnOpenSyncWindow { get; set; }
public Action<List<string>> OnAddFilesToLibrary { get; set; }
public Action<string> OnAddFolderToLibrary { get; set; }
public Action OnUpdateLibrary { get; set; }

#endregion

}
}
37 changes: 12 additions & 25 deletions MPfm/MPfm.Mac/Windows/Controllers/UpdateLibraryWindowController.cs
Expand Up @@ -39,36 +39,29 @@ namespace MPfm.Mac
/// </summary>
public partial class UpdateLibraryWindowController : BaseWindowController, IUpdateLibraryView
{
MainWindowController _mainWindowController = null;
IUpdateLibraryPresenter _presenter = null;

#region Constructors

// Called when created from unmanaged code
public UpdateLibraryWindowController(IntPtr handle)
: base (handle)
{
Initialize();

}

// Call to load from the XIB/NIB file
public UpdateLibraryWindowController(MainWindowController mainWindowController, Action<IBaseView> onViewReady)
public UpdateLibraryWindowController(Action<IBaseView> onViewReady)
: base ("UpdateLibraryWindow", onViewReady)
{
_mainWindowController = mainWindowController;
Initialize();
}

// Shared initialization code
void Initialize()
{
_presenter = Bootstrapper.GetContainer().Resolve<UpdateLibraryPresenter>();
_presenter.BindView(this);
Window.Center();
this.Window.Center();
this.Window.MakeKeyAndOrderFront(this);
}

public override void AwakeFromNib()
{
public override void WindowDidLoad()
{
base.WindowDidLoad();

lblTitle.Font = NSFont.FromFontName("TitilliumText25L-800wt", 16);
lblSubtitle.Font = NSFont.FromFontName("Junction", 11);
lblPercentageDone.Font = NSFont.FromFontName("Junction", 11);
Expand All @@ -79,24 +72,18 @@ public override void AwakeFromNib()
btnCancel.Enabled = true;
btnSaveLog.Enabled = false;
textViewErrorLog.Editable = false;

OnViewReady.Invoke(this);
}

#endregion

public void StartProcess(UpdateLibraryMode mode, List<string> filePaths, string folderPath)
{
_presenter.UpdateLibrary(mode, filePaths, folderPath);
}

partial void btnOK_Click(NSObject sender)
{
_mainWindowController.RefreshAll();
this.Close();
Close();
}

partial void btnCancel_Click(NSObject sender)
{
_presenter.Cancel();
OnCancelUpdateLibrary();
}

partial void btnSaveLog_Click(NSObject sender)
Expand Down

0 comments on commit c62da08

Please sign in to comment.