Пример #1
0
 void PopulateControls(PluginConfigurationOptions pluginConfigurationOptions)
 {
     foreach (var item in _controlBindings.Keys)
     {
         if (item is CheckBox)
         {
             (item as CheckBox).IsChecked = (bool)_controlBindings[item].Read(pluginConfigurationOptions);
         }
         else if (item is TextBox)
         {
             (item as TextBox).Text = (string)_controlBindings[item].Read(pluginConfigurationOptions);
         }
         else if (item is ComboBox)
         {
             (item as ComboBox).Text = (string)_controlBindings[item].Read(pluginConfigurationOptions);
         }
     }
 }
Пример #2
0
        void BuildControl(Grid grid, AbstractMember member, PluginConfigurationOptions pluginConfigurationOptions)
        {
            Control control = null;

            object[] attributes = member.GetAttributes();

            if (attributes == null || attributes.Length == 0)
            {
                return;
            }

            LabelAttribute labelAttribute = attributes.Select(x => x as LabelAttribute).Where(i => i != null).First();

            bool isBool   = member.Type == typeof(bool);
            bool isString = member.Type == typeof(string);
            bool isChoice = attributes.FirstOrDefault(x => x is ItemsAttribute) != null;

            if (isBool)
            {
                control = new CheckBox()
                {
                    VerticalAlignment = VerticalAlignment.Center, IsChecked = (bool)member.Read(pluginConfigurationOptions), Name = member.Name
                };
                (control as CheckBox).Checked   += new RoutedEventHandler(PluginConfigureView_Checked);
                (control as CheckBox).Unchecked += new RoutedEventHandler(PluginConfigureView_Checked);
            }
            else if (isChoice)
            {
                control = new ComboBox()
                {
                    Margin = new Thickness(0, 2, 0, 2), Name = member.Name, Width = 200
                };
                (control as ComboBox).SelectionChanged += new SelectionChangedEventHandler(PluginConfigureView_SelectionChanged);
                ItemsAttribute itemsAttribute = attributes.Select(x => x as ItemsAttribute).Where(i => i != null).First();
                foreach (var item in itemsAttribute.Items.Split(','))
                {
                    (control as ComboBox).Items.Add(item);
                }
                (control as ComboBox).Text = (string)member.Read(pluginConfigurationOptions);
            }
            else if (isString)
            {
                control = new TextBox()
                {
                    Margin = new Thickness(0, 2, 0, 2), Text = (string)member.Read(pluginConfigurationOptions), Name = member.Name, Width = 200
                };
                (control as TextBox).TextChanged += new TextChangedEventHandler(PluginConfigureView_TextChanged);
            }
            else
            {
                return;
            }

            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(30)
            });
            Label label = new Label()
            {
                Margin = new Thickness(0, 0, 10, 0), HorizontalAlignment = HorizontalAlignment.Right, Content = labelAttribute.Label
            };

            grid.Children.Add(label);
            Grid.SetColumn(label, 0);
            Grid.SetRow(label, grid.RowDefinitions.Count - 1);
            grid.Children.Add(control);
            Grid.SetColumn(control, 1);
            Grid.SetRow(control, grid.RowDefinitions.Count - 1);
            _controlBindings.Add(control, member);
        }
Пример #3
0
        private static void UpdateItem(Item item, Item FetchedItem, PluginFieldsOptions UpdatedOptions, PluginConfigurationOptions options)
        {
            if (FetchedItem == null) return;
            if (options.UseTitle && !string.IsNullOrEmpty(FetchedItem.Title) && !UpdatedOptions.UseTitle)
            {
                item.Title = FetchedItem.Title;
                UpdatedOptions.UseTitle = true;
            }
            if (options.UseOriginalTitle && !string.IsNullOrEmpty(FetchedItem.OriginalTitle) && !UpdatedOptions.UseOriginalTitle)
            {
                item.OriginalTitle = FetchedItem.OriginalTitle;
                UpdatedOptions.UseOriginalTitle = true;
            }
            if (options.UseSortTitle && !string.IsNullOrEmpty(FetchedItem.SortTitle) && !UpdatedOptions.UseSortTitle)
            {
                item.SortTitle = FetchedItem.SortTitle;
                UpdatedOptions.UseSortTitle = true;
            }
            if (options.UseTagLines)
            {
                if (item.TagLines == null) item.TagLines = new List<string>();
                item.TagLines.AddDistinct(FetchedItem.TagLines);
            }
            if (options.UseProductionYear && FetchedItem.Year.IsValidYear() && !UpdatedOptions.UseProductionYear)
            {
                item.Year = FetchedItem.Year;
                UpdatedOptions.UseProductionYear = true;
            }
            if (options.UseRuntime && FetchedItem.RunningTime.IsValidRunningTime() && !UpdatedOptions.UseRuntime)
            {
                item.RunningTime = FetchedItem.RunningTime;
                UpdatedOptions.UseRuntime = true;
            }
            if (options.UseRating && FetchedItem.Rating.IsValidRating() && !UpdatedOptions.UseRating)
            {
                item.Rating = FetchedItem.Rating;
                UpdatedOptions.UseRating = true;
            }
            if (options.UseMPAARating && !string.IsNullOrEmpty(FetchedItem.MPAARating) && !UpdatedOptions.UseMPAARating)
            {
                item.MPAARating = FetchedItem.MPAARating;
                UpdatedOptions.UseMPAARating = true;
            }
            if (options.UseOverview && !string.IsNullOrEmpty(FetchedItem.Overview) && !UpdatedOptions.UseOverview)
            {
                item.Overview = FetchedItem.Overview;
                UpdatedOptions.UseOverview = true;
            }
            if (options.UseAspectRatio && !string.IsNullOrEmpty(FetchedItem.AspectRatio) && !UpdatedOptions.UseAspectRatio)
            {
                item.AspectRatio = FetchedItem.AspectRatio;
                UpdatedOptions.UseAspectRatio = true;
            }
            if (options.UseCasting)
            {
                if (FetchedItem.Actors.IsNonEmpty())
                {
                    if (item.Actors == null) item.Actors = new List<Actor>();
                    item.Actors.AddDistinct(FetchedItem.Actors);
                }
                if (FetchedItem.Crew.IsNonEmpty())
                {
                    if (item.Crew == null) item.Crew = new List<CrewMember>();
                    item.Crew.AddDistinct(FetchedItem.Crew);
                }
            }
            if (options.UseGenres)
            {
                if (item.Genres == null) item.Genres = new List<string>();
                item.Genres.AddDistinct(FetchedItem.Genres);
            }
            if (options.UseStudios)
            {
                if (item.Studios == null) item.Studios = new List<string>();
                item.Studios.AddDistinct(FetchedItem.Studios);
            }
            if (options.UseCountries)
            {
                if (item.Countries == null) item.Countries = new List<string>();
                item.Countries.AddDistinct(FetchedItem.Countries);
            }
            if (options.UsePoster && FetchedItem.ImagesPaths.IsNonEmpty())
            {
                if (item.ImagesPaths == null) item.ImagesPaths = new List<Poster>();
                if (UpdatedOptions.UsePoster)
                {
                    foreach (Poster p in FetchedItem.ImagesPaths)
                        p.Checked = false;
                }
                else
                {
                    FetchedItem.ImagesPaths[0].Checked = true;
                }
                UpdatedOptions.UsePoster = true;
                item.ImagesPaths.AddDistinct(FetchedItem.ImagesPaths);
            }
            if (options.UseBackdrop && FetchedItem.BackdropImagePaths.IsNonEmpty())
            {
                if (item.BackdropImagePaths == null) item.BackdropImagePaths = new List<Poster>();
                if (UpdatedOptions.UseBackdrop)
                {
                    foreach (Poster p in FetchedItem.BackdropImagePaths)
                        p.Checked = false;
                }
                else
                {
                    for (int i = 0; i < Math.Min(FetchedItem.BackdropImagePaths.Count, Config.Instance.MaxBdSaved); i++)
                        FetchedItem.BackdropImagePaths[i].Checked = true;
                }
                UpdatedOptions.UseBackdrop = true;
                item.BackdropImagePaths.AddDistinct(FetchedItem.BackdropImagePaths);
            }
            if (options.UseBanner && FetchedItem.BannersPaths.IsNonEmpty())
            {
                if (item.BannersPaths == null) item.BannersPaths = new List<Poster>();
                if (UpdatedOptions.UseBanner)
                {
                    foreach (Poster p in FetchedItem.BannersPaths)
                        p.Checked = false;
                }
                else
                {
                    FetchedItem.BannersPaths[0].Checked = true;
                }
                UpdatedOptions.UseBanner = true;
                item.BannersPaths.AddDistinct(FetchedItem.BannersPaths);
            }
            if (options.UseTrailers)
            {
                if (item.TrailerFiles == null) item.TrailerFiles = new List<string>();
                item.TrailerFiles.AddDistinct(FetchedItem.TrailerFiles);
            }

            if (FetchedItem.ProvidersId != null)
            {
                if (item.ProvidersId == null) item.ProvidersId = new List<DataProviderId>();
                item.ProvidersId.AddRange(FetchedItem.ProvidersId);
            }
            if (FetchedItem.Watched != null) item.Watched = FetchedItem.Watched;
            if (FetchedItem.DateAdded != null && FetchedItem.DateAdded != DateTime.MinValue) item.DateAdded = FetchedItem.DateAdded;
        }