blob: bab1958fd4292509d72172bb81887e0860abc920 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
using MediaBrowser.Common.Logging;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MediaBrowser.ServerApplication.Controls
{
/// <summary>
/// Interaction logic for MultiItemUpdateNotification.xaml
/// </summary>
public partial class MultiItemUpdateNotification : UserControl
{
/// <summary>
/// The logger
/// </summary>
private readonly ILogger Logger;
/// <summary>
/// Gets the children changed event args.
/// </summary>
/// <value>The children changed event args.</value>
private List<BaseItem> Items
{
get { return DataContext as List<BaseItem>; }
}
/// <summary>
/// Initializes a new instance of the <see cref="MultiItemUpdateNotification" /> class.
/// </summary>
public MultiItemUpdateNotification(ILogger logger)
{
if (logger == null)
{
throw new ArgumentNullException("logger");
}
Logger = logger;
InitializeComponent();
Loaded += MultiItemUpdateNotification_Loaded;
}
/// <summary>
/// Handles the Loaded event of the MultiItemUpdateNotification control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
void MultiItemUpdateNotification_Loaded(object sender, RoutedEventArgs e)
{
header.Text = string.Format("{0} New Items!", Items.Count);
PopulateItems();
}
/// <summary>
/// Populates the items.
/// </summary>
private void PopulateItems()
{
itemsPanel.Children.Clear();
var items = Items;
const int maxItemsToDisplay = 8;
var index = 0;
foreach (var item in items)
{
if (index >= maxItemsToDisplay)
{
break;
}
// Try our best to find an image
var path = GetImagePath(item);
if (string.IsNullOrEmpty(path))
{
continue;
}
Image img;
try
{
img = App.Instance.GetImage(path);
}
catch (FileNotFoundException)
{
Logger.Error("Image file not found {0}", path);
continue;
}
img.Stretch = Stretch.Uniform;
img.Margin = new Thickness(0, 0, 5, 5);
img.ToolTip = ItemUpdateNotification.GetDisplayName(item, true);
RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.Fant);
itemsPanel.Children.Add(img);
index++;
}
}
/// <summary>
/// Gets the image path.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
internal static string GetImagePath(BaseItem item)
{
// Try our best to find an image
var path = item.PrimaryImagePath;
if (string.IsNullOrEmpty(path) && item.BackdropImagePaths != null)
{
path = item.BackdropImagePaths.FirstOrDefault();
}
if (string.IsNullOrEmpty(path))
{
path = item.GetImage(ImageType.Thumb);
}
if (string.IsNullOrEmpty(path))
{
path = item.GetImage(ImageType.Art);
}
if (string.IsNullOrEmpty(path))
{
path = item.GetImage(ImageType.Logo);
}
if (string.IsNullOrEmpty(path))
{
path = item.GetImage(ImageType.Disc);
}
return path;
}
}
}
|