Merge branch 'feature/fix_windows_icon_sizes'
This commit is contained in:
@@ -239,24 +239,24 @@ namespace Duplicati.GUI.TrayIcon
|
||||
{
|
||||
switch(icon)
|
||||
{
|
||||
case TrayIcons.Paused:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.TrayNormalPause.ToBitmap());
|
||||
break;
|
||||
case TrayIcons.Running:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.TrayWorking.ToBitmap());
|
||||
break;
|
||||
case TrayIcons.IdleError:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.TrayNormalError.ToBitmap());
|
||||
break;
|
||||
case TrayIcons.RunningError:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.TrayWorking.ToBitmap());
|
||||
break;
|
||||
case TrayIcons.PausedError:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.TrayNormalPause.ToBitmap());
|
||||
break;
|
||||
case TrayIcons.Idle:
|
||||
default:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.TrayNormal.ToBitmap());
|
||||
case TrayIcons.Paused:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.LoadIcon(ImageLoader.PauseIcon).ToBitmap());
|
||||
break;
|
||||
case TrayIcons.Running:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.LoadIcon(ImageLoader.WorkingIcon).ToBitmap());
|
||||
break;
|
||||
case TrayIcons.IdleError:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.LoadIcon(ImageLoader.ErrorIcon).ToBitmap());
|
||||
break;
|
||||
case TrayIcons.RunningError:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.LoadIcon(ImageLoader.WorkingIcon).ToBitmap());
|
||||
break;
|
||||
case TrayIcons.PausedError:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.LoadIcon(ImageLoader.PauseIcon).ToBitmap());
|
||||
break;
|
||||
case TrayIcons.Idle:
|
||||
default:
|
||||
_images[icon] = ImageToPixbuf(ImageLoader.LoadIcon(ImageLoader.NormalIcon).ToBitmap());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,6 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Duplicati.GUI.TrayIcon
|
||||
{
|
||||
public static class ImageLoaderMac
|
||||
{
|
||||
public static Icon LoadFromStream(System.IO.Stream s)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ImageLoader
|
||||
{
|
||||
private static readonly System.Reflection.Assembly ASSEMBLY = System.Reflection.Assembly.GetExecutingAssembly();
|
||||
@@ -37,18 +29,6 @@ namespace Duplicati.GUI.TrayIcon
|
||||
private static readonly Dictionary<string, Icon> ICONS = new Dictionary<string, Icon>();
|
||||
private static readonly object LOCK = new object();
|
||||
|
||||
private static Size m_trayIconSize = Size.Empty;
|
||||
|
||||
/// <summary> Set size of icons to return. </summary>
|
||||
public static void SetTrayIconSize(Size useTrayIconSize)
|
||||
{
|
||||
lock (LOCK)
|
||||
{
|
||||
ICONS.Clear();
|
||||
m_trayIconSize = useTrayIconSize;
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap LoadImage(string filename)
|
||||
{
|
||||
Bitmap bmp;
|
||||
@@ -62,10 +42,18 @@ namespace Duplicati.GUI.TrayIcon
|
||||
return BITMAPS[filename];
|
||||
}
|
||||
|
||||
private static Icon LoadIcon(string filename)
|
||||
public static Icon LoadIcon(string filename)
|
||||
{
|
||||
return LoadIcon(filename, new Size(32, 32));
|
||||
}
|
||||
|
||||
public static Icon LoadIcon(string filename, Size size)
|
||||
{
|
||||
Icon ico;
|
||||
if (ICONS.TryGetValue(filename, out ico))
|
||||
|
||||
var cachename = string.Format("{0};{1}x{2}", filename, size.Width, size.Height);
|
||||
|
||||
if (ICONS.TryGetValue(cachename, out ico))
|
||||
return ico;
|
||||
|
||||
if (!filename.EndsWith(".ico", StringComparison.InvariantCultureIgnoreCase))
|
||||
@@ -77,29 +65,22 @@ namespace Duplicati.GUI.TrayIcon
|
||||
|
||||
ms.Position = 0;
|
||||
lock(LOCK)
|
||||
if (!ICONS.TryGetValue(filename, out ico))
|
||||
return ICONS[filename] = ic;
|
||||
if (!ICONS.TryGetValue(cachename, out ico))
|
||||
return ICONS[cachename] = ic;
|
||||
}
|
||||
|
||||
lock(LOCK)
|
||||
if (!ICONS.TryGetValue(filename, out ico))
|
||||
{
|
||||
if (!m_trayIconSize.IsEmpty)
|
||||
return ICONS[filename] = new Icon(ASSEMBLY.GetManifestResourceStream(PREFIX + filename), m_trayIconSize);
|
||||
else
|
||||
return ICONS[filename] = new Icon(ASSEMBLY.GetManifestResourceStream(PREFIX + filename));
|
||||
}
|
||||
if (!ICONS.TryGetValue(cachename, out ico))
|
||||
return ICONS[cachename] = new Icon(ASSEMBLY.GetManifestResourceStream(PREFIX + filename), size);
|
||||
|
||||
return ICONS[filename];
|
||||
return ICONS[cachename];
|
||||
}
|
||||
|
||||
public static Icon TrayNormal { get { return LoadIcon(Duplicati.Library.Utility.Utility.IsClientOSX ? "OSX_Icons.normal.png" : "Resources.TrayNormal.ico"); } }
|
||||
public static Icon TrayNormalError { get { return LoadIcon(Duplicati.Library.Utility.Utility.IsClientOSX ? "OSX_Icons.normal-error.png" : "Resources.TrayNormalError.ico"); } }
|
||||
public static Icon TrayNormalPause { get { return LoadIcon(Duplicati.Library.Utility.Utility.IsClientOSX ? "OSX_Icons.normal-pause.png" : "Resources.TrayNormalPause.ico"); } }
|
||||
public static Icon TrayNormalWarning { get { return LoadIcon(Duplicati.Library.Utility.Utility.IsClientOSX ? "OSX_Icons.normal-error.png" : "Resources.TrayNormalError.ico"); } }
|
||||
public static Icon TrayWorking { get { return LoadIcon(Duplicati.Library.Utility.Utility.IsClientOSX ? "OSX_Icons.normal-running.png" : "Resources.TrayWorking.ico"); } }
|
||||
public static Icon TrayWorkingPause { get { return LoadIcon(Duplicati.Library.Utility.Utility.IsClientOSX ? "OSX_Icons.normal-pause.png" : "Resources.TrayWorkingPause.ico"); } }
|
||||
|
||||
public const string NormalIcon = "Resources.TrayNormal.ico";
|
||||
public const string ErrorIcon = "Resources.TrayNormalError.ico";
|
||||
public const string PauseIcon = "Resources.TrayNormalPause.ico";
|
||||
public const string WorkingIcon = "Resources.TrayWorking";
|
||||
|
||||
public static Bitmap Pause { get { return LoadImage("Resources.Pause.png"); } }
|
||||
public static Bitmap Play { get { return LoadImage("Resources.Play.png"); } }
|
||||
public static Bitmap CloseMenuIcon { get { return LoadImage("Resources.CloseMenuIcon.png"); } }
|
||||
|
||||
@@ -116,8 +116,6 @@ namespace Duplicati.GUI.TrayIcon.Windows
|
||||
|
||||
WinFormsRunner.Instance = this;
|
||||
|
||||
ImageLoader.SetTrayIconSize(System.Windows.Forms.SystemInformation.SmallIconSize);
|
||||
|
||||
//We need this ugly hack to get a handle that we can call Invoke on,
|
||||
// and sadly the TrayIcon does not expose one, and forcing the context menu
|
||||
// to create one causes weird "lost clicks"
|
||||
@@ -174,23 +172,23 @@ namespace Duplicati.GUI.TrayIcon.Windows
|
||||
switch (value)
|
||||
{
|
||||
case TrayIcons.IdleError:
|
||||
m_trayIcon.Icon = ImageLoader.TrayNormalError;
|
||||
m_trayIcon.Icon = ImageLoader.LoadIcon(ImageLoader.ErrorIcon, System.Windows.Forms.SystemInformation.SmallIconSize);
|
||||
break;
|
||||
case TrayIcons.Paused:
|
||||
m_trayIcon.Icon = ImageLoader.TrayNormalPause;
|
||||
m_trayIcon.Icon = ImageLoader.LoadIcon(ImageLoader.PauseIcon, System.Windows.Forms.SystemInformation.SmallIconSize);
|
||||
break;
|
||||
case TrayIcons.PausedError:
|
||||
m_trayIcon.Icon = ImageLoader.TrayNormalPause;
|
||||
m_trayIcon.Icon = ImageLoader.LoadIcon(ImageLoader.PauseIcon, System.Windows.Forms.SystemInformation.SmallIconSize);
|
||||
break;
|
||||
case TrayIcons.Running:
|
||||
m_trayIcon.Icon = ImageLoader.TrayWorking;
|
||||
m_trayIcon.Icon = ImageLoader.LoadIcon(ImageLoader.WorkingIcon, System.Windows.Forms.SystemInformation.SmallIconSize);
|
||||
break;
|
||||
case TrayIcons.RunningError:
|
||||
m_trayIcon.Icon = ImageLoader.TrayWorking;
|
||||
m_trayIcon.Icon = ImageLoader.LoadIcon(ImageLoader.WorkingIcon, System.Windows.Forms.SystemInformation.SmallIconSize);
|
||||
break;
|
||||
case TrayIcons.Idle:
|
||||
default:
|
||||
m_trayIcon.Icon = ImageLoader.TrayNormal;
|
||||
m_trayIcon.Icon = ImageLoader.LoadIcon(ImageLoader.NormalIcon, System.Windows.Forms.SystemInformation.SmallIconSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user