From 767cdc1f6f6a63ce997fc9476911e2c361f9d402 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Wed, 20 Feb 2013 20:33:05 -0500 Subject: Pushing missing changes --- .../Controls/ItemUpdateNotification.xaml.cs | 249 +++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 MediaBrowser.ServerApplication/Controls/ItemUpdateNotification.xaml.cs (limited to 'MediaBrowser.ServerApplication/Controls/ItemUpdateNotification.xaml.cs') diff --git a/MediaBrowser.ServerApplication/Controls/ItemUpdateNotification.xaml.cs b/MediaBrowser.ServerApplication/Controls/ItemUpdateNotification.xaml.cs new file mode 100644 index 000000000..8cb42f0e5 --- /dev/null +++ b/MediaBrowser.ServerApplication/Controls/ItemUpdateNotification.xaml.cs @@ -0,0 +1,249 @@ +using MediaBrowser.Common.Logging; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Logging; +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace MediaBrowser.ServerApplication.Controls +{ + /// + /// Interaction logic for ItemUpdateNotification.xaml + /// + public partial class ItemUpdateNotification : UserControl + { + /// + /// The logger + /// + private static readonly ILogger Logger = LogManager.GetLogger("MultiItemUpdateNotification"); + + /// + /// Gets the children changed event args. + /// + /// The children changed event args. + private BaseItem Item + { + get { return DataContext as BaseItem; } + } + + /// + /// Initializes a new instance of the class. + /// + public ItemUpdateNotification() + { + InitializeComponent(); + + Loaded += ItemUpdateNotification_Loaded; + } + + /// + /// Handles the Loaded event of the ItemUpdateNotification control. + /// + /// The source of the event. + /// The instance containing the event data. + void ItemUpdateNotification_Loaded(object sender, RoutedEventArgs e) + { + DisplayItem(Item); + } + + /// + /// Gets the display name. + /// + /// The item. + /// if set to true [include parent name]. + /// System.String. + internal static string GetDisplayName(BaseItem item, bool includeParentName) + { + var name = item.Name; + + if (item.ProductionYear.HasValue && !(item is Episode)) + { + name += string.Format(" ({0})", item.ProductionYear); + } + + var episode = item as Episode; + if (episode != null) + { + var indexNumbers = new List(); + + if (episode.Season.IndexNumber.HasValue) + { + indexNumbers.Add(episode.Season.IndexNumber.Value); + } + if (episode.IndexNumber.HasValue) + { + indexNumbers.Add(episode.IndexNumber.Value); + } + var indexNumber = string.Join(".", indexNumbers.ToArray()); + + name = string.Format("{0} - {1}", indexNumber, name); + + if (includeParentName) + { + name = episode.Series.Name + " - " + name; + } + } + + if (includeParentName) + { + var season = item as Season; + + if (season != null) + { + name = season.Series.Name + " - " + name; + } + } + + return name; + } + + /// + /// Displays the parent title. + /// + /// The item. + private void DisplayParentTitle(BaseItem item) + { + if (!(item is Episode || item is Season)) + { + txtParentName.Visibility = Visibility.Collapsed; + imgParentLogo.Visibility = Visibility.Collapsed; + return; + } + + var series = item is Episode ? (item as Episode).Series : (item as Season).Series; + + var logo = series.GetImage(ImageType.Logo); + + if (string.IsNullOrEmpty(logo)) + { + imgParentLogo.Visibility = Visibility.Collapsed; + txtParentName.Visibility = Visibility.Visible; + } + else + { + imgParentLogo.Visibility = Visibility.Visible; + txtParentName.Visibility = Visibility.Collapsed; + imgParentLogo.Source = App.Instance.GetBitmapImage(logo); + } + + txtParentName.Text = series.Name; + } + + /// + /// Displays the title. + /// + /// The item. + private void DisplayTitle(BaseItem item) + { + txtName.Text = GetDisplayName(item, false); + } + + /// + /// Displays the item. + /// + /// The item. + private void DisplayItem(BaseItem item) + { + DisplayParentTitle(item); + DisplayTitle(item); + DisplayRating(item); + + var path = MultiItemUpdateNotification.GetImagePath(item); + + if (string.IsNullOrEmpty(path)) + { + img.Visibility = Visibility.Collapsed; + } + else + { + img.Visibility = Visibility.Visible; + + try + { + img.Source = App.Instance.GetBitmapImage(path); + } + catch (FileNotFoundException) + { + Logger.Error("Image file not found {0}", path); + } + } + + if (string.IsNullOrEmpty(item.Overview)) + { + txtOverview.Visibility = Visibility.Collapsed; + } + else + { + txtOverview.Visibility = Visibility.Visible; + txtOverview.Text = item.Overview; + } + + if (item.Taglines == null || item.Taglines.Count == 0) + { + txtTagline.Visibility = Visibility.Collapsed; + } + else + { + txtTagline.Visibility = Visibility.Visible; + txtTagline.Text = item.Taglines[0]; + } + + if (!item.PremiereDate.HasValue) + { + txtPremeireDate.Visibility = Visibility.Collapsed; + } + else + { + txtPremeireDate.Visibility = Visibility.Visible; + txtPremeireDate.Text = "Premiered " + item.PremiereDate.Value.ToShortDateString(); + } + } + + /// + /// Displays the rating. + /// + /// The item. + private void DisplayRating(BaseItem item) + { + if (!item.CommunityRating.HasValue) + { + pnlRating.Visibility = Visibility.Collapsed; + return; + } + + pnlRating.Children.Clear(); + pnlRating.Visibility = Visibility.Visible; + + var rating = item.CommunityRating.Value; + + for (var i = 0; i < 10; i++) + { + Image image; + if (rating < i - 1) + { + image = App.Instance.GetImage(new Uri("../Resources/Images/starEmpty.png", UriKind.Relative)); + } + else if (rating < i) + { + image = App.Instance.GetImage(new Uri("../Resources/Images/starHalf.png", UriKind.Relative)); + } + else + { + image = App.Instance.GetImage(new Uri("../Resources/Images/starFull.png", UriKind.Relative)); + } + + RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.Fant); + + image.Stretch = Stretch.Uniform; + image.Height = 16; + + pnlRating.Children.Add(image); + } + } + } +} -- cgit v1.2.3