Skip to content

Commit

Permalink
Linux: Added method in BaseWindow to center the window. Added ISyncVi…
Browse files Browse the repository at this point in the history
…ew implementation; updated UI for Sync window. The Sync window actually works now.

General code cleanup in MainWindow.

Related to issue #382.
  • Loading branch information
ycastonguay committed Aug 13, 2013
1 parent f564855 commit 5fb1383
Show file tree
Hide file tree
Showing 19 changed files with 3,209 additions and 3,225 deletions.
1 change: 1 addition & 0 deletions MPfm/MPfm.GTK/Classes/LinuxSyncDeviceSpecifications.cs
Expand Up @@ -37,6 +37,7 @@ public SyncDeviceType GetDeviceType()
string _deviceName = string.Empty;
public string GetDeviceName()
{
_deviceName = System.Environment.MachineName;
return _deviceName;
}

Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.GTK/Classes/Main.cs
Expand Up @@ -42,7 +42,7 @@ public static void Main (string[] args)
Bootstrapper.GetContainer().Register<ISplashView, SplashWindow>().AsMultiInstance();
Bootstrapper.GetContainer().Register<IMainView, MainWindow>().AsMultiInstance();
Bootstrapper.GetContainer().Register<IUpdateLibraryView, UpdateLibraryWindow>().AsMultiInstance();
Bootstrapper.GetContainer().Register<IPreferencesView, PreferencesWindow>().AsMultiInstance();
Bootstrapper.GetContainer().Register<IDesktopPreferencesView, PreferencesWindow>().AsMultiInstance();
//Bootstrapper.GetContainer().Register<IEffectsView, EffectsWindow>().AsMultiInstance();
Bootstrapper.GetContainer().Register<IPlaylistView, PlaylistWindow>().AsMultiInstance();
Bootstrapper.GetContainer().Register<ISyncView, SyncWindow>().AsMultiInstance();
Expand Down
5 changes: 5 additions & 0 deletions MPfm/MPfm.GTK/Windows/BaseWindow.cs
Expand Up @@ -36,6 +36,11 @@ public BaseWindow(Gtk.WindowType windowType, Action<IBaseView> onViewReady)
{
this.OnViewReady = onViewReady;
}

protected void Center()
{
Move((Screen.Width - DefaultSize.Width) / 2, (Screen.Height - DefaultSize.Height) / 2);
}

protected override bool OnDeleteEvent(Gdk.Event evnt)
{
Expand Down
273 changes: 98 additions & 175 deletions MPfm/MPfm.GTK/Windows/MainWindow.cs

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions MPfm/MPfm.GTK/Windows/PreferencesWindow.cs
Expand Up @@ -25,7 +25,7 @@ namespace MPfm.GTK.Windows
/// <summary>
/// Settings window.
/// </summary>
public partial class PreferencesWindow : BaseWindow, IPreferencesView
public partial class PreferencesWindow : BaseWindow, IDesktopPreferencesView
{
/// <summary>
/// Initializes a new instance of the <see cref="MPfm.GTK.PreferencesWindow"/> class.
Expand All @@ -36,6 +36,7 @@ public partial class PreferencesWindow : BaseWindow, IPreferencesView
{
this.Build();
onViewReady(this);
this.Center();
this.Show();
}

Expand All @@ -55,11 +56,14 @@ protected void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
Console.WriteLine("PreferencesWindow - OnDeleteEvent");
}

#region IPreferencesView implementation
#region ILibraryPreferencesView implementation

public Action<string> OnSelectItem { get; set; }

public void RefreshItems (List<string> items)
public System.Action OnResetLibrary { get; set; }
public System.Action OnUpdateLibrary { get; set; }
public System.Action OnEnableSyncListener { get; set; }
public Action<int> OnSetSyncListenerPort { get; set; }

public void LibraryPreferencesError(Exception ex)
{
}

Expand Down
101 changes: 81 additions & 20 deletions MPfm/MPfm.GTK/Windows/SyncWindow.cs
Expand Up @@ -21,67 +21,128 @@
using MPfm.MVP.Models;
using MPfm.GTK.Windows;
using MPfm.Library.Objects;
using System.Reflection;
using System.Text;
using Gtk;

namespace MPfm.GTK
{
public partial class SyncWindow : BaseWindow, ISyncView
{
Gtk.TreeStore _storeDevices;

public SyncWindow(Action<IBaseView> onViewReady) :
base(Gtk.WindowType.Toplevel, onViewReady)
{
this.Build();

Title = "Sync Library With Other Devices";
btnRefreshDeviceList.Label = "Cancel refresh";
InitializeDeviceTreeView();

onViewReady(this);
btnRefreshDeviceList.GrabFocus(); // the list view changes color when focused by default. it annoys me!
this.Center();
this.Show();
}

/// <summary>
/// Raises the delete event (when the form is closing).
/// Prevents the form from closing by hiding it instead.
/// </summary>
/// <param name='o'>Object</param>
/// <param name='args'>Event arguments</param>
protected void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
protected override bool OnDeleteEvent(Gdk.Event evnt)
{
// Prevent window from closing
args.RetVal = true;

// Hide window instead
this.HideAll();
OnCancelDiscovery();
return base.OnDeleteEvent(evnt);
}

protected void OnSyncRefreshDeviceList(object sender, EventArgs e)
{
OnStartDiscovery();
}

private void InitializeDeviceTreeView()
{
_storeDevices = new Gtk.TreeStore(typeof(SyncDevice));
treeViewDevices.HeadersVisible = false;

// Create title column
Gtk.TreeViewColumn colTitle = new Gtk.TreeViewColumn();
Gtk.CellRendererText cellTitle = new Gtk.CellRendererText();
colTitle.Data.Add("Property", "Name");
colTitle.PackStart(cellTitle, true);
colTitle.SetCellDataFunc(cellTitle, new Gtk.TreeCellDataFunc(RenderDeviceCell));
treeViewDevices.AppendColumn(colTitle);
}

private void RenderDeviceCell(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
Console.WriteLine("SyncWindow - RenderDeviceCell");
SyncDevice device = (SyncDevice)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(SyncDevice).GetProperty(property);
object propertyValue = propertyInfo.GetValue(device, null);
(cell as Gtk.CellRendererText).Text = propertyValue.ToString();
}

#region ISyncView implementation

public Action<SyncDevice> OnConnectDevice { get; set; }
public Action<string> OnConnectDeviceManually { get; set; }
public Action OnStartDiscovery { get; set; }
public Action OnCancelDiscovery { get; set; }
public System.Action OnStartDiscovery { get; set; }
public System.Action OnCancelDiscovery { get; set; }

public void SyncError (Exception ex)
public void SyncError(Exception ex)
{
Gtk.Application.Invoke(delegate{
StringBuilder sb = new StringBuilder();
sb.AppendLine("An error occured in the Sync component:");
sb.AppendLine(ex.Message);
sb.AppendLine();
sb.AppendLine(ex.StackTrace);
MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
md.Run();
md.Destroy();
});
}

public void RefreshIPAddress (string address)
public void RefreshIPAddress(string address)
{
Gtk.Application.Invoke(delegate{
lblSubtitle.Text = address;
});
}

public void RefreshDiscoveryProgress (float percentageDone, string status)
public void RefreshDiscoveryProgress(float percentageDone, string status)
{
Gtk.Application.Invoke(delegate{
progressBar.Fraction = percentageDone / 100f;
});
}

public void RefreshDevices (IEnumerable<SyncDevice> devices)
public void RefreshDevices(IEnumerable<SyncDevice> devices)
{
Gtk.Application.Invoke(delegate{
Console.WriteLine("SyncWindow - RefreshDevices");
_storeDevices.Clear();

foreach(SyncDevice device in devices)
_storeDevices.AppendValues(device);

treeViewDevices.Model = _storeDevices;
});
}

public void RefreshDevicesEnded ()
public void RefreshDevicesEnded()
{
Gtk.Application.Invoke(delegate{
btnRefreshDeviceList.Label = "Refresh devices";
});
}

public void SyncDevice (SyncDevice device)
public void SyncDevice(SyncDevice device)
{
}

Expand Down

0 comments on commit 5fb1383

Please sign in to comment.