aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml.cs
diff options
context:
space:
mode:
authorLukePulverenti <luke.pulverenti@gmail.com>2013-02-20 20:33:05 -0500
committerLukePulverenti <luke.pulverenti@gmail.com>2013-02-20 20:33:05 -0500
commit767cdc1f6f6a63ce997fc9476911e2c361f9d402 (patch)
tree49add55976f895441167c66cfa95e5c7688d18ce /MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml.cs
parent845554722efaed872948a9e0f7202e3ef52f1b6e (diff)
Pushing missing changes
Diffstat (limited to 'MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml.cs')
-rw-r--r--MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml.cs144
1 files changed, 144 insertions, 0 deletions
diff --git a/MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml.cs b/MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml.cs
new file mode 100644
index 000000000..383e4ccbe
--- /dev/null
+++ b/MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml.cs
@@ -0,0 +1,144 @@
+using MediaBrowser.Common.Logging;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Logging;
+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 static readonly ILogger Logger = LogManager.GetLogger("MultiItemUpdateNotification");
+
+ /// <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()
+ {
+ 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;
+ }
+ }
+}