diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-20 20:33:05 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-20 20:33:05 -0500 |
| commit | 767cdc1f6f6a63ce997fc9476911e2c361f9d402 (patch) | |
| tree | 49add55976f895441167c66cfa95e5c7688d18ce /MediaBrowser.ServerApplication/Controls | |
| parent | 845554722efaed872948a9e0f7202e3ef52f1b6e (diff) | |
Pushing missing changes
Diffstat (limited to 'MediaBrowser.ServerApplication/Controls')
4 files changed, 493 insertions, 0 deletions
diff --git a/MediaBrowser.ServerApplication/Controls/ItemUpdateNotification.xaml b/MediaBrowser.ServerApplication/Controls/ItemUpdateNotification.xaml new file mode 100644 index 000000000..22a3ea696 --- /dev/null +++ b/MediaBrowser.ServerApplication/Controls/ItemUpdateNotification.xaml @@ -0,0 +1,63 @@ +<UserControl x:Class="MediaBrowser.ServerApplication.Controls.ItemUpdateNotification" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="300"> + + <Grid MaxHeight="280" MaxWidth="600" Margin="20"> + <Border BorderThickness="0" Background="#333333"> + <Border.Effect> + <DropShadowEffect BlurRadius="25" ShadowDepth="0"> + + </DropShadowEffect> + </Border.Effect> + </Border> + <Grid> + <Grid.Background> + <LinearGradientBrush SpreadMethod="Reflect" ColorInterpolationMode="SRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1" > + <GradientStop Color="#ff222222" Offset="0" /> + <GradientStop Color="#ffbbbbbb" Offset="1.0" /> + </LinearGradientBrush> + </Grid.Background> + + <Grid Margin="20"> + <Grid.RowDefinitions> + <RowDefinition Height="auto"></RowDefinition> + <RowDefinition Height="*"></RowDefinition> + </Grid.RowDefinitions> + + <StackPanel Orientation="Vertical" Grid.Row="0"> + <Image x:Name="imgParentLogo" Stretch="Uniform" Height="40" RenderOptions.BitmapScalingMode="Fant" HorizontalAlignment="Left"></Image> + <TextBlock x:Name="txtParentName" FontSize="26" Foreground="White"></TextBlock> + <TextBlock x:Name="txtName" FontSize="26" Foreground="White"></TextBlock> + </StackPanel> + + <Grid Grid.Row="1" Margin="0 20 0 0"> + + <Grid.ColumnDefinitions> + <ColumnDefinition Width="auto"></ColumnDefinition> + <ColumnDefinition Width="*"></ColumnDefinition> + </Grid.ColumnDefinitions> + + <Grid.RowDefinitions> + <RowDefinition Height="auto"></RowDefinition> + <RowDefinition Height="auto"></RowDefinition> + <RowDefinition Height="*"></RowDefinition> + <RowDefinition Height="auto"></RowDefinition> + </Grid.RowDefinitions> + + <StackPanel Orientation="Vertical" Grid.Column="0" Grid.RowSpan="4" Margin="0 0 20 0" VerticalAlignment="Top"> + <Image x:Name="img" Stretch="Uniform" RenderOptions.BitmapScalingMode="Fant" Height="150"></Image> + </StackPanel> + + <TextBlock x:Name="txtTagline" Foreground="White" Grid.Column="1" Grid.Row="0" Margin="0 0 0 20" TextWrapping="Wrap" FontStyle="Italic"></TextBlock> + <StackPanel x:Name="pnlRating" Orientation="Horizontal" Margin="0 2 0 20" Grid.Column="1" Grid.Row="1"></StackPanel> + <TextBlock x:Name="txtOverview" Foreground="White" Grid.Column="1" Grid.Row="2" TextWrapping="Wrap" Margin="0 0 0 20"></TextBlock> + <TextBlock x:Name="txtPremeireDate" Foreground="White" Grid.Column="1" Grid.Row="3"></TextBlock> + </Grid> + </Grid> + </Grid> + </Grid> +</UserControl> 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 +{ + /// <summary> + /// Interaction logic for ItemUpdateNotification.xaml + /// </summary> + public partial class ItemUpdateNotification : 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 BaseItem Item + { + get { return DataContext as BaseItem; } + } + + /// <summary> + /// Initializes a new instance of the <see cref="ItemUpdateNotification" /> class. + /// </summary> + public ItemUpdateNotification() + { + InitializeComponent(); + + Loaded += ItemUpdateNotification_Loaded; + } + + /// <summary> + /// Handles the Loaded event of the ItemUpdateNotification 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 ItemUpdateNotification_Loaded(object sender, RoutedEventArgs e) + { + DisplayItem(Item); + } + + /// <summary> + /// Gets the display name. + /// </summary> + /// <param name="item">The item.</param> + /// <param name="includeParentName">if set to <c>true</c> [include parent name].</param> + /// <returns>System.String.</returns> + 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<int>(); + + 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; + } + + /// <summary> + /// Displays the parent title. + /// </summary> + /// <param name="item">The item.</param> + 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; + } + + /// <summary> + /// Displays the title. + /// </summary> + /// <param name="item">The item.</param> + private void DisplayTitle(BaseItem item) + { + txtName.Text = GetDisplayName(item, false); + } + + /// <summary> + /// Displays the item. + /// </summary> + /// <param name="item">The item.</param> + 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(); + } + } + + /// <summary> + /// Displays the rating. + /// </summary> + /// <param name="item">The item.</param> + 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); + } + } + } +} diff --git a/MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml b/MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml new file mode 100644 index 000000000..5d3fb785c --- /dev/null +++ b/MediaBrowser.ServerApplication/Controls/MultiItemUpdateNotification.xaml @@ -0,0 +1,37 @@ +<UserControl x:Class="MediaBrowser.ServerApplication.Controls.MultiItemUpdateNotification" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="300"> + + <Grid MaxHeight="400" MaxWidth="600" Margin="20"> + <Border BorderThickness="0" Background="#333333"> + <Border.Effect> + <DropShadowEffect BlurRadius="25" ShadowDepth="0"> + + </DropShadowEffect> + </Border.Effect> + </Border> + <Grid> + <Grid.Background> + <LinearGradientBrush SpreadMethod="Reflect" ColorInterpolationMode="SRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1" > + <GradientStop Color="#ff222222" Offset="0" /> + <GradientStop Color="#ffbbbbbb" Offset="1" /> + </LinearGradientBrush> + </Grid.Background> + + <Grid Margin="20"> + <Grid.RowDefinitions> + <RowDefinition Height="auto"></RowDefinition> + <RowDefinition Height="*"></RowDefinition> + </Grid.RowDefinitions> + + <TextBlock x:Name="header" FontSize="26" Foreground="White" Grid.Row="0"></TextBlock> + + <UniformGrid x:Name="itemsPanel" Columns="4" Margin="0 20 0 0" Grid.Row="1"></UniformGrid> + </Grid> + </Grid> + </Grid> +</UserControl> 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; + } + } +} |
