Skip to content

Commit

Permalink
Mac: Implemented SyncDownload view; the whole sync process now works …
Browse files Browse the repository at this point in the history
…on Mac! There are a lot of stats missing though, and canceling doesn't work yet. Added Retina/non-Retina icons for Sync and SyncMenu list views. More layout bug fixes. Fixed alert view title/message.

Related to issue #381.
  • Loading branch information
ycastonguay committed Aug 16, 2013
1 parent 2fea9ab commit 1a2696c
Show file tree
Hide file tree
Showing 28 changed files with 565 additions and 94 deletions.
7 changes: 3 additions & 4 deletions MPfm/MPfm.Mac/Classes/Helpers/CocoaHelper.cs
Expand Up @@ -33,13 +33,12 @@ namespace MPfm.Mac.Classes.Helpers
/// </summary>
public static class CocoaHelper
{
public static void ShowCriticalAlert(string text)
public static void ShowCriticalAlert(string title, string text)
{
// Display error in a message box
using(NSAlert alert = new NSAlert())
{
// Display alert
alert.MessageText = text;
alert.MessageText = title;
alert.InformativeText = text;
alert.AlertStyle = NSAlertStyle.Critical;
alert.RunModal();
}
Expand Down
10 changes: 9 additions & 1 deletion MPfm/MPfm.Mac/Classes/Objects/ImageResources.cs
Expand Up @@ -117,7 +117,15 @@ static ImageResources()
NSImage.ImageNamed("icon_button_cancel"),
NSImage.ImageNamed("icon_button_connect"),
NSImage.ImageNamed("icon_button_download"),
NSImage.ImageNamed("icon_button_refresh")
NSImage.ImageNamed("icon_button_refresh"),
NSImage.ImageNamed("icon_android"),
NSImage.ImageNamed("icon_linux"),
NSImage.ImageNamed("icon_osx"),
NSImage.ImageNamed("icon_phone"),
NSImage.ImageNamed("icon_tablet"),
NSImage.ImageNamed("icon_user"),
NSImage.ImageNamed("icon_vinyl"),
NSImage.ImageNamed("icon_windows")
};

imageSplash = new NSImage(NSBundle.MainBundle.PathForResource("Splash", "png", "Resources", string.Empty));
Expand Down
16 changes: 16 additions & 0 deletions MPfm/MPfm.Mac/MPfm.Mac.csproj
Expand Up @@ -420,5 +420,21 @@
<BundleResource Include="Resources\icon_button_download%402x.png" />
<BundleResource Include="Resources\icon_button_refresh.png" />
<BundleResource Include="Resources\icon_button_refresh%402x.png" />
<BundleResource Include="Resources\icon_linux.png" />
<BundleResource Include="Resources\icon_linux%402x.png" />
<BundleResource Include="Resources\icon_osx.png" />
<BundleResource Include="Resources\icon_osx%402x.png" />
<BundleResource Include="Resources\icon_phone.png" />
<BundleResource Include="Resources\icon_phone%402x.png" />
<BundleResource Include="Resources\icon_tablet.png" />
<BundleResource Include="Resources\icon_tablet%402x.png" />
<BundleResource Include="Resources\icon_user.png" />
<BundleResource Include="Resources\icon_user%402x.png" />
<BundleResource Include="Resources\icon_vinyl.png" />
<BundleResource Include="Resources\icon_vinyl%402x.png" />
<BundleResource Include="Resources\icon_windows.png" />
<BundleResource Include="Resources\icon_windows%402x.png" />
<BundleResource Include="Resources\icon_android.png" />
<BundleResource Include="Resources\icon_android%402x.png" />
</ItemGroup>
</Project>
Binary file added MPfm/MPfm.Mac/Resources/icon_android.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_android@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_linux@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_osx.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_osx@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_phone.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_phone@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_tablet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_tablet@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_user.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_user@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_vinyl.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_vinyl@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_windows.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MPfm/MPfm.Mac/Resources/icon_windows@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs
Expand Up @@ -557,7 +557,7 @@ protected void HandleLibraryBrowserDoubleClick(object sender, EventArgs e)

// Show alert
Tracing.Log(sb.ToString());
CocoaHelper.ShowCriticalAlert(sb.ToString());
CocoaHelper.ShowCriticalAlert("Error", sb.ToString());
}
}

Expand All @@ -582,7 +582,7 @@ protected void HandleSongBrowserDoubleClick(object sender, EventArgs e)
sb.AppendLine(ex.StackTrace);

Tracing.Log(sb.ToString());
CocoaHelper.ShowCriticalAlert(sb.ToString());
CocoaHelper.ShowCriticalAlert("Error", sb.ToString());
}
}

Expand Down Expand Up @@ -705,7 +705,7 @@ public void PlayerError(Exception ex)
sb.AppendLine(ex.StackTrace);

Tracing.Log(sb.ToString());
CocoaHelper.ShowCriticalAlert(sb.ToString());
CocoaHelper.ShowCriticalAlert("Error", sb.ToString());
});
}

Expand Down
64 changes: 49 additions & 15 deletions MPfm/MPfm.Mac/Windows/Controllers/SyncDownloadWindowController.cs
Expand Up @@ -19,46 +19,56 @@
using System.Collections.Generic;
using MPfm.MVP.Views;
using MPfm.Library.Objects;
using MonoMac.AppKit;
using MPfm.Mac.Classes.Objects;
using System.Linq;
using MPfm.Mac.Classes.Helpers;
using MPfm.Core;
using MonoMac.Foundation;

namespace MPfm.Mac
{
public partial class SyncDownloadWindowController : BaseWindowController, ISyncDownloadView
{
#region Constructors

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

// Call to load from the XIB/NIB file
public SyncDownloadWindowController(Action<IBaseView> onViewReady)
: base ("SyncDownloadWindow", onViewReady)
{
Initialize();
}

// Shared initialization code
void Initialize()
private void Initialize()
{
this.Window.Center();
this.Window.MakeKeyAndOrderFront(this);
}

#endregion
public override void WindowDidLoad()
{
base.WindowDidLoad();
LoadFontsAndImages();
OnViewReady.Invoke(this);
}

//strongly typed window accessor
public new SyncDownloadWindow Window
private void LoadFontsAndImages()
{
get
{
return (SyncDownloadWindow)base.Window;
}
lblTitle.Font = NSFont.FromFontName("TitilliumText25L-800wt", 18);
lblSubtitle.Font = NSFont.FromFontName("Junction", 12);
lblStatus.Font = NSFont.FromFontName("Junction", 12);
lblDownloadSpeed.Font = NSFont.FromFontName("Junction", 12);
lblDownloadSpeedValue.Font = NSFont.FromFontName("Junction", 16);

btnCancel.Image = ImageResources.Icons.FirstOrDefault(x => x.Name == "icon_button_cancel");
}

public override void AwakeFromNib()
partial void actionCancel(NSObject sender)
{
base.AwakeFromNib();
OnCancelDownload();
}

#region ISyncDownloadView implementation
Expand All @@ -67,18 +77,42 @@ public override void AwakeFromNib()

public void SyncDownloadError(Exception ex)
{
InvokeOnMainThread(delegate {
CocoaHelper.ShowCriticalAlert("Error", string.Format("An error occured in SyncMenu: {0}", ex));
});
}

public void RefreshDevice(SyncDevice device)
{
InvokeOnMainThread(delegate {
lblTitle.StringValue = "Syncing Library With " + device.Name;
Window.Title = "Syncing Library With " + device.Name;
});
}

public void RefreshStatus(SyncClientDownloadAudioFileProgressEntity entity)
{
InvokeOnMainThread(delegate {
lblStatus.StringValue = entity.Status;
lblDownloadSpeedValue.StringValue = entity.DownloadSpeed;
progressIndicator.DoubleValue = entity.PercentageDone;
});
}

public void SyncCompleted()
{
InvokeOnMainThread(delegate {
lblStatus.StringValue = "Sync completed";
using(NSAlert alert = new NSAlert())
{
alert.MessageText = "Sync completed";
alert.InformativeText = "The sync has completed successfully.";
alert.AlertStyle = NSAlertStyle.Informational;
alert.BeginSheet(this.Window, () => {
this.Window.Close();
});
}
});
}

#endregion
Expand Down
45 changes: 11 additions & 34 deletions MPfm/MPfm.Mac/Windows/Controllers/SyncMenuWindowController.cs
Expand Up @@ -73,6 +73,7 @@ public override void WindowDidLoad()

public override void Close()
{
// TODO: Fix this, it doesn't work very well (i.e. not always called)
Console.WriteLine("SyncMenuWindowController - Close");
NSNotificationCenter.DefaultCenter.RemoveObserver(this);
base.Close();
Expand Down Expand Up @@ -128,6 +129,11 @@ private void LoadFontsAndImages()
OnRemoveAll();
}

partial void actionSync(NSObject sender)
{
OnSync();
}

#region NSTableView delegate / datasource

[Export ("numberOfRowsInTableView:")]
Expand All @@ -136,12 +142,6 @@ public int GetRowCount(NSTableView tableView)
return _selection.Count;
}

// [Export ("tableView:heightOfRow:")]
// public float GetRowHeight(NSTableView tableView, int row)
// {
// return 20;
// }

[Export ("tableView:dataCellForTableColumn:row:")]
public NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, int row)
{
Expand All @@ -159,12 +159,6 @@ public NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, i
return view;
}

[Export ("tableViewSelectionDidChange:")]
public void SelectionDidChange(NSNotification notification)
{
//btnConnect.Enabled = (tableViewDevices.SelectedRow == -1) ? false : true;
}

#endregion

#region NSOutlineView delegate / datasource
Expand Down Expand Up @@ -217,7 +211,6 @@ public int GetChildrenCount(NSOutlineView outlineView, NSObject item)
[Export ("outlineView:objectValueForTableColumn:byItem:")]
public NSObject GetObjectValue(NSOutlineView outlineView, NSTableColumn forTableColumn, NSObject byItem)
{
//return byItem;
var item = (SyncMenuItem)byItem;
return item.StringValue;
}
Expand Down Expand Up @@ -253,11 +246,11 @@ public NSView GetViewForItem(NSOutlineView outlineView, NSTableColumn tableColum
{
case SyncMenuItemEntityType.Artist:
view.TextField.StringValue = syncMenuItem.Entity.ArtistName;
view.ImageView.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_icomoon_user");
view.ImageView.Image = ImageResources.Icons.FirstOrDefault(x => x.Name == "icon_user");
break;
case SyncMenuItemEntityType.Album:
view.TextField.StringValue = syncMenuItem.Entity.AlbumTitle;
view.ImageView.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == "16_custom_vinyl");
view.ImageView.Image = ImageResources.Icons.FirstOrDefault(x => x.Name == "icon_vinyl");
break;
case SyncMenuItemEntityType.Song:
view.ImageView.Image = null;
Expand All @@ -266,21 +259,6 @@ public NSView GetViewForItem(NSOutlineView outlineView, NSTableColumn tableColum
break;
}
}
else if (tableColumnIdentifier == "columnSelection")
{
// Create view
view = (NSTableCellView)outlineView.MakeView("cellSelection", this);

foreach (var subview in view.Subviews)
{
//Console.WriteLine("#####@$!@$@$ " + subview.GetType().FullName);// + " " + ((NSButton)subview).StringValue);
}
//view.TextField.Font = NSFont.FromFontName("Junction", 11);

//view.TextField.StringValue = "hello";
//string aaa = "string.";

}

return view;
}
Expand All @@ -300,16 +278,14 @@ public NSView GetViewForItem(NSOutlineView outlineView, NSTableColumn tableColum
public void SyncMenuError(Exception ex)
{
InvokeOnMainThread(delegate {
string message = string.Format("An error occured in SyncMenu: {0}", ex);
Tracing.Log(message);
CocoaHelper.ShowCriticalAlert(message);
CocoaHelper.ShowCriticalAlert("Error", string.Format("An error occured in SyncMenu: {0}", ex));
});
}

public void SyncEmptyError(Exception ex)
{
InvokeOnMainThread(delegate {
CocoaHelper.ShowCriticalAlert(ex.Message);
CocoaHelper.ShowCriticalAlert("Error", ex.Message);
});
}

Expand Down Expand Up @@ -338,6 +314,7 @@ public void RefreshLoading(bool isLoading, int progressPercentage)

public void RefreshSelectButton(string text)
{
// Not used on Mac.
}

public void RefreshItems(List<SyncMenuItemEntity> items)
Expand Down
22 changes: 13 additions & 9 deletions MPfm/MPfm.Mac/Windows/Controllers/SyncWindowController.cs
Expand Up @@ -139,17 +139,23 @@ public NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, i
string iconName = string.Empty;
switch (_items[row].DeviceType)
{
case SyncDeviceType.Linux:
iconName = "icon_linux";
break;
case SyncDeviceType.OSX:
iconName = "icon_osx";
break;
case SyncDeviceType.Windows:
iconName = "icon_windows";
break;
case SyncDeviceType.iOS:
iconName = "16_icomoon_apple";
iconName = "icon_phone";
break;
case SyncDeviceType.Android:
iconName = "16_icomoon_android";
break;
default:
iconName = "16_icomoon_laptop";
iconName = "icon_android";
break;
}
view.ImageView.Image = ImageResources.images16x16.FirstOrDefault(x => x.Name == iconName);
view.ImageView.Image = ImageResources.Icons.FirstOrDefault(x => x.Name == iconName);
}
return view;
}
Expand All @@ -170,9 +176,7 @@ public void SelectionDidChange(NSNotification notification)
public void SyncError(Exception ex)
{
InvokeOnMainThread(delegate {
string message = string.Format("An error occured in Sync: {0}", ex);
Tracing.Log(message);
CocoaHelper.ShowCriticalAlert(message);
CocoaHelper.ShowCriticalAlert("Error", string.Format("An error occured in Sync: {0}", ex));
});

}
Expand Down

0 comments on commit 1a2696c

Please sign in to comment.