Skip to content

Commit

Permalink
Linux: Fixed all bugs in Sync and SyncMenu; these screens are as func…
Browse files Browse the repository at this point in the history
…tional as on Windows and Mac! Added a Resource folder with embedded images; ResourceHelper extracts these images and turn them into Gdk.PIxbuf to load into buttons, tree views, etc. Added icons from other desktop platforms.

Related to issue #382.
  • Loading branch information
ycastonguay committed Aug 18, 2013
1 parent b8b5a9d commit 0abbdc3
Show file tree
Hide file tree
Showing 24 changed files with 606 additions and 182 deletions.
48 changes: 48 additions & 0 deletions MPfm/MPfm.GTK/Classes/Helpers/ResourceHelper.cs
@@ -0,0 +1,48 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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;
using System.Reflection;

namespace MPfm.GTK.Helpers
{
public static class ResourceHelper
{
// public static void TestLoadResources()
// {
// var names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
// foreach(var name in names)
// {
// var info = Assembly.GetExecutingAssembly().GetManifestResourceInfo(name);
// Console.WriteLine("Assembly Resource - name: {0} fileName: {1}", name, info.FileName);
// }
// }
/// <summary>
/// Gets an embedded image resource in the current executing assembly.
/// </summary>
/// <returns>
/// Embedded image
/// </returns>
/// <param name='name'>
/// Image name (example: 'icon_linux.png' will load 'MPfm.GTK.Resources.icon_linux.png')
/// </param>
public static Gdk.Pixbuf GetEmbeddedImageResource(string name)
{
return new Gdk.Pixbuf(Assembly.GetExecutingAssembly().GetManifestResourceStream("MPfm.GTK.Resources." + name));
}
}
}
Expand Up @@ -22,9 +22,9 @@
namespace MPfm.GTK.Helpers
{
/// <summary>
/// The ImageManipulation class contains static functions for manipulating images.
/// The SystemDrawingHelper class contains static functions for manipulating images with System.Drawing.
/// </summary>
public class ImageManipulation
public class SystemDrawingHelper
{
/// <summary>
/// The ResizeImage static function resizes images to a desired width and height, with the highest quality possible.
Expand Down
37 changes: 23 additions & 14 deletions MPfm/MPfm.GTK/MPfm.GTK.csproj
Expand Up @@ -78,6 +78,26 @@
<EmbeddedResource Include="gtk-gui\gui.stetic">
<LogicalName>gui.stetic</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Resources\icon_android.png" />
<EmbeddedResource Include="Resources\icon_artists.png" />
<EmbeddedResource Include="Resources\icon_linux.png" />
<EmbeddedResource Include="Resources\icon_osx.png" />
<EmbeddedResource Include="Resources\icon_phone.png" />
<EmbeddedResource Include="Resources\icon_song.png" />
<EmbeddedResource Include="Resources\icon_tablet.png" />
<EmbeddedResource Include="Resources\icon_user.png" />
<EmbeddedResource Include="Resources\icon_vinyl.png" />
<EmbeddedResource Include="Resources\icon_windows.png" />
<EmbeddedResource Include="Resources\black.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Resources\icon48.png">
<DeployService-UseProjectRelativePath>true</DeployService-UseProjectRelativePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Resources\splash.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Include="gtk-gui\generated.cs" />
Expand All @@ -90,7 +110,6 @@
<Compile Include="Windows\SplashWindow.cs" />
<Compile Include="Windows\BaseWindow.cs" />
<Compile Include="Classes\Navigation\GtkNavigationManager.cs" />
<Compile Include="Classes\Helpers\ImageManipulation.cs" />
<Compile Include="gtk-gui\MPfm.GTK.Windows.EffectsWindow.cs" />
<Compile Include="gtk-gui\MPfm.GTK.Windows.MainWindow.cs" />
<Compile Include="gtk-gui\MPfm.GTK.Windows.PlaylistWindow.cs" />
Expand All @@ -105,6 +124,8 @@
<Compile Include="Classes\LinuxSyncDeviceSpecifications.cs" />
<Compile Include="Windows\SyncMenuWindow.cs" />
<Compile Include="gtk-gui\MPfm.GTK.SyncMenuWindow.cs" />
<Compile Include="Classes\Helpers\SystemDrawingHelper.cs" />
<Compile Include="Classes\Helpers\ResourceHelper.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down Expand Up @@ -165,18 +186,6 @@
<Folder Include="Classes\" />
<Folder Include="Classes\Navigation\" />
<Folder Include="Classes\Helpers\" />
</ItemGroup>
<ItemGroup>
<Content Include="icon48.png">
<DeployService-UseProjectRelativePath>true</DeployService-UseProjectRelativePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Splash.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="android.png" />
<Content Include="black.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Folder Include="Resources\" />
</ItemGroup>
</Project>
File renamed without changes
File renamed without changes
Binary file added MPfm/MPfm.GTK/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.GTK/Resources/icon_artists.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.GTK/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.GTK/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.GTK/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.GTK/Resources/icon_song.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.GTK/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.GTK/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.GTK/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.GTK/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.
File renamed without changes
7 changes: 4 additions & 3 deletions MPfm/MPfm.GTK/Windows/MainWindow.cs
Expand Up @@ -58,7 +58,8 @@ public MainWindow(Action<IBaseView> onViewReady): base (Gtk.WindowType.Toplevel,
Title = "MPfm: Music Player for Musicians - " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + " ALPHA";

// Set application icon (for some reason it is not visible on Unity)
SetIconFromFile("icon48.png");
//SetIconFromFile(ResourceHelper.GetEmbeddedImageResource("icon48.png"));
Icon = ResourceHelper.GetEmbeddedImageResource("icon48.png");

SetFontProperties();
InitializeSongBrowser();
Expand Down Expand Up @@ -715,7 +716,7 @@ public void RefreshSongInformation(AudioFile audioFile, long lengthBytes, int pl
if(drawingImage != null)
{
// Resize image and set cover
drawingImage = ImageManipulation.ResizeImage(drawingImage, 150, 150);
drawingImage = SystemDrawingHelper.ResizeImage(drawingImage, 150, 150);
imageAlbumCover.Pixbuf = ImageToPixbuf(drawingImage);
}
else
Expand Down Expand Up @@ -769,7 +770,7 @@ public void RefreshSongInformation(AudioFile audioFile, long lengthBytes, int pl
// Check if image cover is still empty
if(imageAlbumCover.Pixbuf == null)
{
Pixbuf imageCover = new Pixbuf("black.png");
Pixbuf imageCover = ResourceHelper.GetEmbeddedImageResource("black.png");
imageCover = imageCover.ScaleSimple(150, 150, InterpType.Bilinear);
imageAlbumCover.Pixbuf = imageCover;
}
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.GTK/Windows/SplashWindow.cs
Expand Up @@ -19,6 +19,7 @@
using Gdk;
using MPfm.MVP;
using MPfm.MVP.Views;
using MPfm.GTK.Helpers;

namespace MPfm.GTK.Windows
{
Expand All @@ -39,7 +40,7 @@ private void Initialize()
this.lblStatus.ModifyFg(Gtk.StateType.Normal, new Color(255, 255, 255));

// Set image background
Pixbuf imageCover = new Pixbuf("Splash.png");
Pixbuf imageCover = ResourceHelper.GetEmbeddedImageResource("splash.png");
imageBackground.Pixbuf = imageCover;

//splashPresenter.BindView(this);
Expand Down
130 changes: 104 additions & 26 deletions MPfm/MPfm.GTK/Windows/SyncMenuWindow.cs
Expand Up @@ -25,12 +25,14 @@
using System.Text;
using Gtk;
using MPfm.Sound.AudioFiles;
using MPfm.GTK.Helpers;

namespace MPfm.GTK
{
public partial class SyncMenuWindow : BaseWindow, ISyncMenuView
{
Gtk.TreeStore _storeItems;
Gtk.TreeStore _storeSelection;

public SyncMenuWindow(Action<IBaseView> onViewReady) :
base(Gtk.WindowType.Toplevel, onViewReady)
Expand All @@ -39,8 +41,9 @@ public partial class SyncMenuWindow : BaseWindow, ISyncMenuView

Title = "Sync Library With";
InitializeTreeView();
InitializeSelectionTreeView();

btnSelectAll.GrabFocus(); // the list view changes color when focused by default. it annoys me!
btnSync.GrabFocus(); // the list view changes color when focused by default. it annoys me!
this.Center();
this.Show();
onViewReady(this);
Expand All @@ -50,27 +53,31 @@ private void InitializeTreeView()
{
_storeItems = new Gtk.TreeStore(typeof(SyncMenuItemEntity));
treeView.HeadersVisible = false;

// Create title column
treeView.Selection.Mode = SelectionMode.Multiple;
Gtk.TreeViewColumn colTitle = new Gtk.TreeViewColumn();
Gtk.CellRendererText cellTitle = new Gtk.CellRendererText();
Gtk.CellRendererPixbuf cellPixbuf = new Gtk.CellRendererPixbuf();
Gtk.CellRendererToggle cellToggle = new Gtk.CellRendererToggle();
cellToggle.Activatable = true;
cellToggle.Toggled += (o, args) => {
var cellRendererToggle = (Gtk.CellRendererToggle)o;
//cellRendererToggle.Active = !cellRendererToggle.Active;
Console.WriteLine("******* Toggle {0}", cellRendererToggle.Data["itemType"]);
};
colTitle.PackStart(cellPixbuf, false);
colTitle.PackStart(cellTitle, true);
colTitle.PackStart(cellToggle, false);
colTitle.SetCellDataFunc(cellPixbuf, new Gtk.TreeCellDataFunc(RenderCell));
colTitle.SetCellDataFunc(cellTitle, new Gtk.TreeCellDataFunc(RenderCell));
colTitle.SetCellDataFunc(cellToggle, new Gtk.TreeCellDataFunc(RenderCell));
treeView.AppendColumn(colTitle);
}

private void InitializeSelectionTreeView()
{
_storeSelection = new Gtk.TreeStore(typeof(AudioFile));
treeViewSelection.ShowExpanders = false;
treeViewSelection.HeadersVisible = false;
treeViewSelection.Selection.Mode = SelectionMode.Multiple;

Gtk.TreeViewColumn colTitle = new Gtk.TreeViewColumn();
Gtk.CellRendererText cellTitle = new Gtk.CellRendererText();
colTitle.PackStart(cellTitle, true);
colTitle.SetCellDataFunc(cellTitle, new Gtk.TreeCellDataFunc(RenderSelectionCell));
treeViewSelection.AppendColumn(colTitle);
}

private void RenderCell(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
//Console.WriteLine("SyncMenuWindow - RenderCell");
Expand Down Expand Up @@ -98,17 +105,34 @@ private void RenderCell(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.Tr
else if (cell is Gtk.CellRendererPixbuf)
{
var cellPixbuf = (Gtk.CellRendererPixbuf)cell;
var pixbuf = new Gdk.Pixbuf("android.png");
cellPixbuf.Pixbuf = pixbuf;
}
else if (cell is Gtk.CellRendererToggle)
{
var cellToggle = (Gtk.CellRendererToggle)cell;
cellToggle.Data.Clear();
cellToggle.Data.Add("itemType", entity.ItemType.ToString());

Gdk.Pixbuf pixbuf = null;
switch (entity.ItemType)
{
case SyncMenuItemEntityType.Artist:
pixbuf = ResourceHelper.GetEmbeddedImageResource("icon_user.png");
break;
case SyncMenuItemEntityType.Album:
pixbuf = ResourceHelper.GetEmbeddedImageResource("icon_vinyl.png");
break;
case SyncMenuItemEntityType.Song:
pixbuf = ResourceHelper.GetEmbeddedImageResource("icon_song.png");
break;
}

if(pixbuf != null)
cellPixbuf.Pixbuf = pixbuf;
}
}

private void RenderSelectionCell(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
//Console.WriteLine("SyncMenuWindow - RenderSelectionCell");
AudioFile audioFile = (AudioFile)model.GetValue(iter, 0);
string title = string.Format("{0} / {1} / {2}. {3}", audioFile.ArtistName, audioFile.AlbumTitle, audioFile.TrackNumber, audioFile.Title);
(cell as Gtk.CellRendererText).Text = title;
}

protected void OnTreeViewRowExpanded(object o, RowExpandedArgs args)
{
Console.WriteLine(">>>>> SyncMenuWindow - OnTreeViewRowExpanded");
Expand All @@ -121,10 +145,55 @@ protected void OnTreeViewRowExpanded(object o, RowExpandedArgs args)
if (entityChild.ArtistName == "dummy" && entityChild.AlbumTitle == "dummy")
{
Console.WriteLine("SyncMenuWindow - OnTreeViewRowExpanded -- Expanding node...");
OnExpandItem(entity, null);
OnExpandItem(entity, args.Iter);
}
}

protected void OnClickSync(object sender, EventArgs e)
{
OnSync();
}

protected void OnClickAdd(object sender, EventArgs e)
{
TreeIter iter;
var treePaths = treeView.Selection.GetSelectedRows();
List<SyncMenuItemEntity> items = new List<SyncMenuItemEntity>();
foreach (var treePath in treePaths)
{
_storeItems.GetIter(out iter, treePath);
var entity = (SyncMenuItemEntity)_storeItems.GetValue(iter, 0);
items.Add(entity);
}

OnSelectItems(items);
}

protected void OnClickRemove(object sender, EventArgs e)
{
TreeIter iter;
var treePaths = treeViewSelection.Selection.GetSelectedRows();
List<AudioFile> audioFiles = new List<AudioFile>();
foreach (var treePath in treePaths)
{
_storeSelection.GetIter(out iter, treePath);
var audioFile = (AudioFile)_storeSelection.GetValue(iter, 0);
audioFiles.Add(audioFile);
}

OnRemoveItems(audioFiles);
}

protected void OnClickAddAll(object sender, EventArgs e)
{
OnSelectAll();
}

protected void OnClickRemoveAll(object sender, EventArgs e)
{
OnRemoveAll();
}

#region ISyncMenuView implementation

public System.Action<SyncMenuItemEntity, object> OnExpandItem { get; set; }
Expand Down Expand Up @@ -209,6 +278,15 @@ public void RefreshItems(List<SyncMenuItemEntity> items)

public void RefreshSelection(List<AudioFile> audioFiles)
{
Gtk.Application.Invoke(delegate{
Console.WriteLine("SyncMenuWindow - RefreshSelection");

_storeSelection.Clear();
foreach(AudioFile audioFile in audioFiles)
_storeSelection.AppendValues(audioFile);

treeViewSelection.Model = _storeSelection;
});
}

public void RefreshSyncTotal(string title, string subtitle, bool enoughFreeSpace)
Expand All @@ -223,14 +301,14 @@ public void InsertItems(int index, SyncMenuItemEntity parentItem, List<SyncMenuI
{
Gtk.Application.Invoke(delegate{
Console.WriteLine("SyncMenuWindow - InsertItems - index {0}", index);
TreeIter treeIter;
Gtk.TreePath treePath = new TreePath((index-1).ToString());
_storeItems.GetIter(out treeIter, treePath);
object stuff = _storeItems.GetValue(treeIter, 0);
TreeIter treeIter = (TreeIter)userData;
//Gtk.TreePath treePath = new TreePath((index-1).ToString());
//_storeItems.GetIter(out treeIter, treePath);
//object stuff = _storeItems.GetValue(treeIter, 0);
//_storeItems.IterNthChild(out treeIter, index-1);
TreeIter treeIterDummy;
_storeItems.IterNthChild(out treeIterDummy, treeIter, 0);
object stuff2 = _storeItems.GetValue(treeIterDummy, 0);
//object stuff2 = _storeItems.GetValue(treeIterDummy, 0);

// Add new children
foreach(var item in items)
Expand Down

0 comments on commit 0abbdc3

Please sign in to comment.