Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Windows: Update Library now fully working, all that's left is to rede…
…sign the window with the new theme colors.

Related to issue #422.
  • Loading branch information
ycastonguay committed Aug 18, 2013
1 parent bbafa06 commit 8f5cf2d
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 324 deletions.
25 changes: 25 additions & 0 deletions MPfm/MPfm.MVP/Navigation/NavigationManager.cs
Expand Up @@ -17,6 +17,7 @@

using System;
using System.Collections.Generic;
using MPfm.Library.UpdateLibrary;
using MPfm.MVP.Bootstrap;
using TinyIoC;
using MPfm.MVP.Views;
Expand Down Expand Up @@ -254,5 +255,29 @@ public virtual IPlaylistView CreatePlaylistView()
};
return _playlistView;
}

public virtual IUpdateLibraryView CreateUpdateLibraryView(UpdateLibraryMode mode, List<string> filePaths, string folderPath)
{
if (_updateLibraryView != null)
{
_updateLibraryView.ShowView(true);
return _updateLibraryView;
}

Action<IBaseView> onViewReady = (view) =>
{
_updateLibraryPresenter = Bootstrapper.GetContainer().Resolve<IUpdateLibraryPresenter>();
_updateLibraryPresenter.BindView((IUpdateLibraryView)view);
_updateLibraryPresenter.UpdateLibrary(mode, filePaths, folderPath);
};

_updateLibraryView = Bootstrapper.GetContainer().Resolve<IUpdateLibraryView>(new NamedParameterOverloads() { { "onViewReady", onViewReady } });
_updateLibraryView.OnViewDestroy = (view) =>
{
_updateLibraryView = null;
_updateLibraryPresenter = null;
};
return _updateLibraryView;
}
}
}
71 changes: 45 additions & 26 deletions MPfm/MPfm.MVP/Presenters/MainPresenter.cs
Expand Up @@ -15,10 +15,11 @@
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System.Collections.Generic;
using MPfm.Library.UpdateLibrary;
using MPfm.MVP.Navigation;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Views;
using System;

namespace MPfm.MVP.Presenters
{
Expand All @@ -27,42 +28,60 @@ namespace MPfm.MVP.Presenters
/// </summary>
public class MainPresenter : BasePresenter<IMainView>, IMainPresenter
{
readonly NavigationManager _navigationManager;
readonly NavigationManager _navigationManager;
public MainPresenter(NavigationManager navigationManager)
{
_navigationManager = navigationManager;
_navigationManager = navigationManager;
}

public override void BindView(IMainView view)
{
view.OnOpenPlaylistWindow = OpenPlaylistWindow;
view.OnOpenEffectsWindow = OpenEffectsWindow;
view.OnOpenPreferencesWindow = OpenPreferencesWindow;
view.OnOpenSyncWindow = OpenSyncWindow;

public override void BindView(IMainView view)
{
view.OnOpenPlaylistWindow = OpenPlaylistWindow;
view.OnOpenEffectsWindow = OpenEffectsWindow;
view.OnOpenPreferencesWindow = OpenPreferencesWindow;
view.OnOpenSyncWindow = OpenSyncWindow;
view.OnAddFilesToLibrary = AddFilesToLibrary;
view.OnAddFolderToLibrary = AddFolderToLibrary;
view.OnUpdateLibrary = UpdateLibrary;

base.BindView(view);
}

void OpenPlaylistWindow()
{
_navigationManager.CreatePlaylistView();
}
base.BindView(view);
}

void OpenEffectsWindow()
void OpenPlaylistWindow()
{
_navigationManager.CreatePlaylistView();
}

void OpenEffectsWindow()
{
_navigationManager.CreateEffectsView();
}

void OpenPreferencesWindow()
{
_navigationManager.CreatePreferencesView();
}

void OpenSyncWindow()
{
_navigationManager.CreateSyncView();
}

void AddFolderToLibrary(string folderPath)
{
_navigationManager.CreateEffectsView();
_navigationManager.CreateUpdateLibraryView(UpdateLibraryMode.SpecificFolder, null, folderPath);
}

void OpenPreferencesWindow()
void AddFilesToLibrary(List<string> filePaths)
{
_navigationManager.CreatePreferencesView();
_navigationManager.CreateUpdateLibraryView(UpdateLibraryMode.SpecificFiles, filePaths, null);
}

void OpenSyncWindow()
void UpdateLibrary()
{
_navigationManager.CreateSyncView();
}
}
_navigationManager.CreateUpdateLibraryView(UpdateLibraryMode.WholeLibrary, null, null);
}
}
}

5 changes: 5 additions & 0 deletions MPfm/MPfm.MVP/Views/IMainView.cs
Expand Up @@ -16,6 +16,7 @@
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;

namespace MPfm.MVP.Views
{
Expand All @@ -28,5 +29,9 @@ public interface IMainView : ILibraryBrowserView, ISongBrowserView, IPlayerView
Action OnOpenEffectsWindow { get; set; }
Action OnOpenPlaylistWindow { get; set; }
Action OnOpenSyncWindow { get; set; }

Action<List<string>> OnAddFilesToLibrary { get; set; }
Action<string> OnAddFolderToLibrary { get; set; }
Action OnUpdateLibrary { get; set; }
}
}
121 changes: 51 additions & 70 deletions MPfm/MPfm.Windows/Classes/Forms/frmMain.cs
Expand Up @@ -866,16 +866,10 @@ public void ExitApplication()
/// <param name="e">Event arguments</param>
private void miFileAddFiles_Click(object sender, EventArgs e)
{
// Display dialog
if (dialogAddFiles.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
{
// The user has cancelled the operation
return;
}

//// Update the library using the specified folder
//formUpdateLibraryStatus = new frmUpdateLibraryStatus(this, dialogAddFiles.FileNames.ToList());
//formUpdateLibraryStatus.ShowDialog(this);
OnAddFilesToLibrary(dialogAddFiles.FileNames.ToList());
}

/// <summary>
Expand All @@ -886,30 +880,10 @@ private void miFileAddFiles_Click(object sender, EventArgs e)
/// <param name="e">Event arguments</param>
private void miFileAddFolder_Click(object sender, EventArgs e)
{
// Display dialog
if (dialogAddFolder.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
{
// The user has cancelled the operation
return;
}

//// Update the library using the specified folder
//formUpdateLibraryStatus = new frmUpdateLibraryStatus(this, dialogAddFolder.SelectedPath);
//formUpdateLibraryStatus.ShowDialog(this);

//// Show panel
//ShowUpdateLibraryProgress(true);

//// Start update timer to display progress
//timerUpdateLibrary.Start();

//// Start new thread
//new Thread(delegate()
//{
// List<string> filePaths = AudioTools.SearchAudioFilesRecursive(dialogAddFolder.SelectedPath, "MP3;FLAC;OGG;MPC;APE;WV");
// updateLibrary = new Library.UpdateLibrary(1, library.Gateway.DatabaseFilePath);
// Task<List<AudioFile>> audioFiles = updateLibrary.LoadFiles(filePaths);
//}).Start();
OnAddFolderToLibrary(dialogAddFolder.SelectedPath);
}

/// <summary>
Expand Down Expand Up @@ -1221,12 +1195,7 @@ private void miHelpAbout_Click(object sender, EventArgs e)
/// <param name="e">Event arguments</param>
private void btnUpdateLibrary_Click(object sender, EventArgs e)
{
// Display contextual menu
//menuToolbarLibrary.Show(btnUpdateLibrary, new Point(0, btnUpdateLibrary.Height));
//toolStripMain.Height;

// Update the whole library
UpdateLibrary();
OnUpdateLibrary();
}

/// <summary>
Expand Down Expand Up @@ -3402,47 +3371,23 @@ public void EnableTooltips(bool enable)

#region IMainView implementation

public Action<IBaseView> OnViewDestroy { get; set; }
public Action<AudioFileFormat> OnAudioFileFormatFilterChanged { get; set; }
public Action<LibraryBrowserEntity> OnTreeNodeSelected { get; set; }
public Action<LibraryBrowserEntity> OnTreeNodeDoubleClicked { get; set; }
public Action<LibraryBrowserEntity, object> OnTreeNodeExpanded { get; set; }
public Func<LibraryBrowserEntity, IEnumerable<LibraryBrowserEntity>> OnTreeNodeExpandable { get; set; }
public Action<AudioFile> OnTableRowDoubleClicked { get; set; }

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

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

public void PlayerError(Exception ex)
{
MethodInvoker methodUIUpdate = delegate
{
MessageBox.Show(string.Format("An error occured in Player: {0}", ex), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
#region ILibraryBrowserView implementation

if (InvokeRequired)
BeginInvoke(methodUIUpdate);
else
methodUIUpdate.Invoke();
}

public void ShowView(bool shown)
{
}
public Action<AudioFileFormat> OnAudioFileFormatFilterChanged { get; set; }
public Action<LibraryBrowserEntity> OnTreeNodeSelected { get; set; }
public Action<LibraryBrowserEntity> OnTreeNodeDoubleClicked { get; set; }
public Action<LibraryBrowserEntity, object> OnTreeNodeExpanded { get; set; }
public Func<LibraryBrowserEntity, IEnumerable<LibraryBrowserEntity>> OnTreeNodeExpandable { get; set; }

public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities)
{
Expand Down Expand Up @@ -3489,8 +3434,9 @@ public void RefreshLibraryBrowser(IEnumerable<LibraryBrowserEntity> entities)
public void RefreshLibraryBrowserNode(LibraryBrowserEntity entity, IEnumerable<LibraryBrowserEntity> entities, object userData)
{
Console.WriteLine("frmMain - RefreshLibraryBrowserNode - entities.Count: {0}", entities.Count());
MethodInvoker methodUIUpdate = delegate {
var node = (TreeNode) userData;
MethodInvoker methodUIUpdate = delegate
{
var node = (TreeNode)userData;
treeLibraryBrowser.BeginUpdate();

foreach (var childEntity in entities)
Expand Down Expand Up @@ -3525,10 +3471,45 @@ public void RefreshLibraryBrowserNode(LibraryBrowserEntity entity, IEnumerable<L
methodUIUpdate.Invoke();
}

#endregion

#region ISongBrowserView implementation

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

public void RefreshSongBrowser(IEnumerable<AudioFile> audioFiles)
{
}

#endregion

#region IPlayerView implementation

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

public void PlayerError(Exception ex)
{
MethodInvoker methodUIUpdate = delegate
{
MessageBox.Show(string.Format("An error occured in Player: {0}", ex), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
};

if (InvokeRequired)
BeginInvoke(methodUIUpdate);
else
methodUIUpdate.Invoke();
}

public void RefreshPlayerStatus(PlayerStatusType status)
{
}
Expand Down

0 comments on commit 8f5cf2d

Please sign in to comment.