Merge branch 'master' of \\\pk2010\Pithos\
[pithos-ms-client] / trunk / Pithos.Client.WPF / Shell / BalloonIconConverter.cs
1 // -----------------------------------------------------------------------\r
2 // <copyright file="NetworkAgent.cs" company="GRNET">\r
3 // Copyright 2011-2012 GRNET S.A. All rights reserved.\r
4 // \r
5 // Redistribution and use in source and binary forms, with or\r
6 // without modification, are permitted provided that the following\r
7 // conditions are met:\r
8 // \r
9 //   1. Redistributions of source code must retain the above\r
10 //      copyright notice, this list of conditions and the following\r
11 //      disclaimer.\r
12 // \r
13 //   2. Redistributions in binary form must reproduce the above\r
14 //      copyright notice, this list of conditions and the following\r
15 //      disclaimer in the documentation and/or other materials\r
16 //      provided with the distribution.\r
17 // \r
18 // THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
19 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
21 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
25 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
26 // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
28 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
29 // POSSIBILITY OF SUCH DAMAGE.\r
30 // \r
31 // The views and conclusions contained in the software and\r
32 // documentation are those of the authors and should not be\r
33 // interpreted as representing official policies, either expressed\r
34 // or implied, of GRNET S.A.\r
35 // </copyright>\r
36 // -----------------------------------------------------------------------\r
37 \r
38 \r
39 using System;\r
40 using System.Collections.Generic;\r
41 using System.Globalization;\r
42 using System.Windows.Data;\r
43 using System.Windows.Media.Imaging;\r
44 using Hardcodet.Wpf.TaskbarNotification;\r
45 \r
46 namespace Pithos.Client.WPF.Shell\r
47 {\r
48     class BalloonIconConverter:IValueConverter\r
49     {\r
50 \r
51         Dictionary<BalloonIcon,BitmapImage> _iconCache=new Dictionary<BalloonIcon,BitmapImage>();\r
52 \r
53         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)\r
54         {\r
55             BitmapImage image;\r
56             \r
57             var icon = (BalloonIcon) value;\r
58             if (icon == BalloonIcon.None)\r
59                 return null;\r
60 \r
61             if (!_iconCache.TryGetValue(icon, out image))\r
62             {\r
63                 var imagePath = String.Format("/Pithos.Client.WPF;component/Images/{0}.png", Enum.GetName(typeof(BalloonIcon), value));\r
64                 var uri = new Uri(imagePath, UriKind.Relative);\r
65                 image=new BitmapImage(uri);\r
66                 _iconCache[icon] = image;\r
67             }\r
68             return image;\r
69         }\r
70 \r
71         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)\r
72         {\r
73             throw new NotImplementedException();\r
74         }\r
75     }\r
76 }\r