Merge branch 'feature/update_gtk_and_appindicator'

This commit is contained in:
Kenneth Skovhede
2016-10-27 11:15:41 +02:00
11 changed files with 239 additions and 71 deletions
@@ -54,32 +54,29 @@ namespace Duplicati.GUI.TrayIcon
{
set
{
m_appIndicator.IconName = GetTrayIconFilename(value);
switch(value)
{
case TrayIcons.Paused:
m_appIndicator.IconName = "normal-pause";
m_appIndicator.IconDesc = "Paused";
break;
case TrayIcons.Running:
m_appIndicator.IconName = "normal-running";
m_appIndicator.IconDesc = "Running";
break;
case TrayIcons.IdleError:
m_appIndicator.IconName = "normal-error";
m_appIndicator.IconDesc = "Error";
break;
case TrayIcons.RunningError:
m_appIndicator.IconName = "normal-running";
break;
case TrayIcons.PausedError:
m_appIndicator.IconName = "normal-pause";
m_appIndicator.IconDesc = "Paused";
break;
case TrayIcons.Idle:
default:
m_appIndicator.IconName = "normal";
m_appIndicator.IconDesc = "Ready";
break;
case TrayIcons.Paused:
m_appIndicator.IconDesc = "Paused";
break;
case TrayIcons.Running:
m_appIndicator.IconDesc = "Running";
break;
case TrayIcons.IdleError:
m_appIndicator.IconDesc = "Error";
break;
case TrayIcons.RunningError:
m_appIndicator.IconDesc = "Running";
break;
case TrayIcons.PausedError:
m_appIndicator.IconDesc = "Paused";
break;
case TrayIcons.Idle:
default:
m_appIndicator.IconDesc = "Ready";
break;
}
}
}
@@ -372,5 +372,29 @@
<Link>OSXTrayHost\rumps.py</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SVGIcons\dark\context_menu_open.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SVGIcons\dark\context_menu_pause.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SVGIcons\dark\context_menu_quit.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SVGIcons\dark\context_menu_resume.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SVGIcons\light\context_menu_open.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SVGIcons\light\context_menu_pause.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SVGIcons\light\context_menu_quit.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="SVGIcons\light\context_menu_resume.svg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
@@ -24,11 +24,16 @@ namespace Duplicati.GUI.TrayIcon
{
public class GtkRunner : TrayIconBase
{
private static string m_svgfolder;
/// <summary>
/// Static constructor that ensures the Gtk environment is initialized
/// </summary>
static GtkRunner()
{
m_svgfolder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "SVGIcons");
m_svgfolder = System.IO.Path.Combine(m_svgfolder, "dark");
Gtk.Application.Init();
}
@@ -45,34 +50,36 @@ namespace Duplicati.GUI.TrayIcon
private static Dictionary<MenuIcons, Gtk.Image> _icons = new Dictionary<MenuIcons, Gtk.Image>();
public MenuItem MenuItem { get { return m_item; } }
private string GetFilenameForIcon(MenuIcons icon)
{
switch (icon)
{
case MenuIcons.Pause:
return "context_menu_pause";
case MenuIcons.Quit:
return "context_menu_quit";
case MenuIcons.Resume:
return "context_menu_resume";
case MenuIcons.Status:
return "context_menu_open";
default:
return null;
}
}
private Gtk.Image GetIcon(MenuIcons icon)
{
if (Duplicati.Library.Utility.Utility.IsClientOSX)
return null;
if (!_icons.ContainsKey(icon))
{
switch(icon)
_icons[icon] = null;
var filename = GetFilenameForIcon(icon);
if (filename != null)
{
case MenuIcons.None:
_icons[icon] = null;
break;
case MenuIcons.Pause:
_icons[icon] = ImageToGtk(ImageLoader.Pause);
break;
case MenuIcons.Quit:
_icons[icon] = ImageToGtk(ImageLoader.CloseMenuIcon);
break;
case MenuIcons.Resume:
_icons[icon] = ImageToGtk(ImageLoader.Play);
break;
case MenuIcons.Status:
_icons[icon] = ImageToGtk(ImageLoader.StatusMenuIcon);
break;
default:
_icons[icon] = null;
break;
filename = System.IO.Path.Combine(m_svgfolder, System.IO.Path.ChangeExtension(filename, ".svg"));
if (System.IO.File.Exists(filename))
_icons[icon] = new Gtk.Image(filename);
}
}
@@ -89,9 +96,9 @@ namespace Duplicati.GUI.TrayIcon
if (!Duplicati.Library.Utility.Utility.IsClientOSX)
if (icon != MenuIcons.None) {
((ImageMenuItem)m_item).Image = GetIcon(icon);
//TODO: Not sure we should do this, it overrides policy?
m_item.ExposeEvent += DrawImageMenuItemImage;
// On some (older versions) of GDK, this hack is required
//m_item.ExposeEvent += DrawImageMenuItemImage;
}
if (subitems != null && subitems.Count > 0)
@@ -116,6 +123,7 @@ namespace Duplicati.GUI.TrayIcon
m_callback();
}
/*
/// <summary> Draw the image to the image menu item. Taken from: http://mono.1490590.n4.nabble.com/ImageMenuItem-does-not-display-the-image-Linux-platform-tp3510861p3511376.html </summary>
/// The event source. <see cref="System.Object"/>
/// The event args. <see cref="Gtk.ExposeEventArgs"/>
@@ -133,7 +141,8 @@ namespace Duplicati.GUI.TrayIcon
args.Event.Window.DrawPixbuf(mainGC, image.Pixbuf, 0, 0, r.Left + 2,
r.Top + (r.Height - image.Pixbuf.Height) / 2, -1, -1, Gdk.RgbDither.None, 0, 0);
}
}
*/
public string Text
{
@@ -176,7 +185,9 @@ namespace Duplicati.GUI.TrayIcon
protected virtual void CreateTrayInstance()
{
m_trayIcon = new StatusIcon();
// Sometimes the tray icon will not display
// if it is not created with an icon
m_trayIcon = StatusIcon.NewFromStock(Stock.About);
}
protected override void Run (string[] args)
@@ -231,33 +242,63 @@ namespace Duplicati.GUI.TrayIcon
Gtk.Image img = new Gtk.Image(stream);
return img;
}
}
}
protected static string GetTrayIconFilename(TrayIcons icon)
{
switch (icon)
{
case TrayIcons.Paused:
return "normal-pause";
case TrayIcons.Running:
return "normal-running";
case TrayIcons.IdleError:
return "normal-error";
case TrayIcons.RunningError:
return "normal-running";
case TrayIcons.PausedError:
return "normal-pause";
case TrayIcons.Idle:
default:
return "normal";
}
}
protected static Pixbuf GetIcon(TrayIcons icon)
{
if (!_images.ContainsKey(icon))
{
switch(icon)
if (Duplicati.Library.Utility.Utility.IsClientOSX)
{
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:
switch (icon)
{
case TrayIcons.Paused:
_images[icon] = ImageToPixbuf(ImageLoader.LoadIcon(ImageLoader.PauseIcon).ToBitmap());
break;
case TrayIcons.Idle:
default:
_images[icon] = ImageToPixbuf(ImageLoader.LoadIcon(ImageLoader.NormalIcon).ToBitmap());
break;
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;
}
}
else
{
_images[icon] = null;
var filename = System.IO.Path.Combine(m_svgfolder, System.IO.Path.ChangeExtension(GetTrayIconFilename(icon), ".svg"));
if (System.IO.File.Exists(filename))
_images[icon] = new Pixbuf(filename);
}
}
@@ -0,0 +1,13 @@
<svg id="tray_menu_icons" data-name="tray menu icons" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<defs>
<style>
.cls-1 {
fill: #65b1dd;
}
</style>
</defs>
<title>tray context menu icons</title>
<g id="show_Kopie" data-name="show Kopie">
<polygon class="cls-1" points="8 4.001 2 10.301 3.5 11.876 8 7.072 12.5 11.876 14 10.301 8 4.001"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 427 B

@@ -0,0 +1,14 @@
<svg id="tray_menu_icons" data-name="tray menu icons" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<defs>
<style>
.cls-1 {
fill: #65b1dd;
}
</style>
</defs>
<title>tray context menu icons</title>
<g id="pause_Kopie" data-name="pause Kopie">
<rect class="cls-1" x="4" y="2" width="3" height="12"/>
<rect class="cls-1" x="9" y="2" width="3" height="12"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 445 B

@@ -0,0 +1,13 @@
<svg id="tray_menu_icons" data-name="tray menu icons" xmlns="http://www.w3.org/2000/svg" width="15.997" height="16" viewBox="0 0 15.997 16">
<defs>
<style>
.cls-1 {
fill: #65b1dd;
}
</style>
</defs>
<title>tray context menu icons</title>
<g id="stop_Kopie" data-name="stop Kopie">
<polygon id="stop" class="cls-1" points="13.998 3.95 12.048 2 7.998 6.05 3.948 2 1.998 3.95 6.049 8 1.998 12.05 3.948 14 7.998 9.95 12.048 14 13.998 12.05 9.949 8 13.998 3.95"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 513 B

@@ -0,0 +1,13 @@
<svg id="tray_menu_icons" data-name="tray menu icons" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<defs>
<style>
.cls-1 {
fill: #65b1dd;
}
</style>
</defs>
<title>tray context menu icons</title>
<g id="resume_Kopie" data-name="resume Kopie">
<polygon class="cls-1" points="5 14 13 8 5 2 5 14"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 384 B

@@ -0,0 +1,13 @@
<svg id="tray_menu_icons" data-name="tray menu icons" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<defs>
<style>
.cls-1 {
fill: #65b1dd;
}
</style>
</defs>
<title>tray context menu icons</title>
<g id="show_Kopie" data-name="show Kopie">
<polygon class="cls-1" points="8 4.001 2 10.301 3.5 11.876 8 7.072 12.5 11.876 14 10.301 8 4.001"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 427 B

@@ -0,0 +1,14 @@
<svg id="tray_menu_icons" data-name="tray menu icons" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<defs>
<style>
.cls-1 {
fill: #65b1dd;
}
</style>
</defs>
<title>tray context menu icons</title>
<g id="pause_Kopie" data-name="pause Kopie">
<rect class="cls-1" x="4" y="2" width="3" height="12"/>
<rect class="cls-1" x="9" y="2" width="3" height="12"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 445 B

@@ -0,0 +1,13 @@
<svg id="tray_menu_icons" data-name="tray menu icons" xmlns="http://www.w3.org/2000/svg" width="15.997" height="16" viewBox="0 0 15.997 16">
<defs>
<style>
.cls-1 {
fill: #65b1dd;
}
</style>
</defs>
<title>tray context menu icons</title>
<g id="stop_Kopie" data-name="stop Kopie">
<polygon id="stop" class="cls-1" points="13.998 3.95 12.048 2 7.998 6.05 3.948 2 1.998 3.95 6.049 8 1.998 12.05 3.948 14 7.998 9.95 12.048 14 13.998 12.05 9.949 8 13.998 3.95"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 513 B

@@ -0,0 +1,13 @@
<svg id="tray_menu_icons" data-name="tray menu icons" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<defs>
<style>
.cls-1 {
fill: #65b1dd;
}
</style>
</defs>
<title>tray context menu icons</title>
<g id="resume_Kopie" data-name="resume Kopie">
<polygon class="cls-1" points="5 14 13 8 5 2 5 14"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 384 B