/*
* Copyright (C) 2006-2007 Eskil Bylund
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections.Generic;
using Gtk;
namespace DCSharp.GUI{
public class IconManager
{
private static Widget widget;
private static Dictionary<string, Gdk.Pixbuf> iconCache;
static IconManager()
{
widget = new Invisible();
iconCache = new Dictionary<string, Gdk.Pixbuf>();
}
#region Properties
private static Gdk.Pixbuf userOnline;
public static Gdk.Pixbuf UserOnline
{
get
{
return userOnline;
}
}
private static Gdk.Pixbuf userOffline;
public static Gdk.Pixbuf UserOffline
{
get
{
return userOffline;
}
}
private static Gdk.Pixbuf userPassive;
public static Gdk.Pixbuf UserPassive
{
get
{
return userPassive;
}
}
private static Gdk.Pixbuf userOp;
public static Gdk.Pixbuf UserOp
{
get
{
return userOp;
}
}
#endregion
#region Methods
public static void Init()
{
//Window.DefaultIcon = Gdk.Pixbuf.LoadFromResource("Logo.png");
Window.DefaultIconName = "gtk-network";
// Load icons
string[] icons = {"user-online", "user-offline", "user-passive"};
foreach (string icon in icons)
{
IconTheme.AddBuiltinIcon(icon, 16,
Gdk.Pixbuf.LoadFromResource(icon + ".png"));
}
// Update
UpdateIcons();
IconTheme.Default.Changed += OnIconThemeChanged;
}
public static Gdk.Pixbuf GetIcon(string iconName, int size)
{
// The icons are cached because a new pixbuf might be created every
// time an icon is loaded.
string iconId = iconName + size;
if (iconCache.ContainsKey(iconId))
{
return iconCache[iconId];
}
else
{
Gdk.Pixbuf pixbuf = null;
if (IconTheme.Default.HasIcon(iconName))
{
pixbuf = IconTheme.Default.LoadIcon(iconName, size,
IconLookupFlags.UseBuiltin);
}
iconCache.Add(iconId, pixbuf);
return pixbuf;
}
}
private static void UpdateIcons()
{
userOnline = GetIcon("user-online", 16);
userOffline = GetIcon("user-offline", 16);
userPassive = GetIcon("user-passive", 16);
userOp = widget.RenderIcon(Stock.Help, IconSize.Menu, String.Empty);
}
private static void OnIconThemeChanged(object obj, EventArgs args)
{
iconCache.Clear();
UpdateIcons();
}
#endregion
}
}
|