Merge branch 'master' of \\\pk2010\Pithos\
[pithos-ms-client] / trunk / Pithos.Client.WPF / Shell / BalloonIconConverter.cs
index 10ac7a8..371d5cf 100644 (file)
@@ -1,9 +1,43 @@
-// -----------------------------------------------------------------------\r
-// <copyright file="BalloonIconConverter.cs" company="Microsoft">\r
-// TODO: Update copyright text.\r
+// -----------------------------------------------------------------------\r
+// <copyright file="NetworkAgent.cs" company="GRNET">\r
+// Copyright 2011-2012 GRNET S.A. All rights reserved.\r
+// \r
+// Redistribution and use in source and binary forms, with or\r
+// without modification, are permitted provided that the following\r
+// conditions are met:\r
+// \r
+//   1. Redistributions of source code must retain the above\r
+//      copyright notice, this list of conditions and the following\r
+//      disclaimer.\r
+// \r
+//   2. Redistributions in binary form must reproduce the above\r
+//      copyright notice, this list of conditions and the following\r
+//      disclaimer in the documentation and/or other materials\r
+//      provided with the distribution.\r
+// \r
+// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
+// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+// POSSIBILITY OF SUCH DAMAGE.\r
+// \r
+// The views and conclusions contained in the software and\r
+// documentation are those of the authors and should not be\r
+// interpreted as representing official policies, either expressed\r
+// or implied, of GRNET S.A.\r
 // </copyright>\r
 // -----------------------------------------------------------------------\r
 \r
+\r
+using System;\r
+using System.Collections.Generic;\r
 using System.Globalization;\r
 using System.Windows.Data;\r
 using System.Windows.Media.Imaging;\r
@@ -11,23 +45,26 @@ using Hardcodet.Wpf.TaskbarNotification;
 \r
 namespace Pithos.Client.WPF.Shell\r
 {\r
-    using System;\r
-    using System.Collections.Generic;\r
-    using System.Linq;\r
-    using System.Text;\r
-\r
-    /// <summary>\r
-    /// Convert a BalloonIcon value to an Image\r
-    /// </summary>\r
-    public class BalloonIconConverter:IValueConverter\r
+    class BalloonIconConverter:IValueConverter\r
     {\r
+\r
+        Dictionary<BalloonIcon,BitmapImage> _iconCache=new Dictionary<BalloonIcon,BitmapImage>();\r
+\r
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)\r
         {\r
+            BitmapImage image;\r
+            \r
+            var icon = (BalloonIcon) value;\r
+            if (icon == BalloonIcon.None)\r
+                return null;\r
 \r
-            var balloon = (BalloonIcon) value;\r
-            var balloonName = Enum.GetName(typeof (BalloonIcon), balloon);\r
-            var imageUrl = new Uri(String.Format("/Pithos.Client.WPF;component:/{0}.png", balloonName),UriKind.Relative);\r
-            var image = new BitmapImage(imageUrl);\r
+            if (!_iconCache.TryGetValue(icon, out image))\r
+            {\r
+                var imagePath = String.Format("/Pithos.Client.WPF;component/Images/{0}.png", Enum.GetName(typeof(BalloonIcon), value));\r
+                var uri = new Uri(imagePath, UriKind.Relative);\r
+                image=new BitmapImage(uri);\r
+                _iconCache[icon] = image;\r
+            }\r
             return image;\r
         }\r
 \r