private void PublishListSkinProperties(TraktUserList list)
 {
     SetProperty("#Trakt.List.Name", list.Name);
     SetProperty("#Trakt.List.Description", list.Description);
     SetProperty("#Trakt.List.Privacy", list.Privacy);
     SetProperty("#Trakt.List.Slug", list.Slug);
     SetProperty("#Trakt.List.Url", list.Url);
 }
        private void CopyList(TraktUserList sourceList, TraktList newList)
        {
            CopyList copyList = new CopyList { Username = CurrentUser, Source = sourceList, Destination = newList };

            Thread copyThread = new Thread(delegate(object obj)
            {
                CopyList copyParams = obj as CopyList;

                // first create new list
                TraktLogger.Info("Creating new '{0}' list '{1}'", copyParams.Destination.Privacy, copyParams.Destination.Name);
                TraktAddListResponse response = TraktAPI.TraktAPI.ListAdd(copyParams.Destination);
                TraktAPI.TraktAPI.LogTraktResponse<TraktResponse>(response);
                if (response.Status == "success")
                {
                    // update with offical slug
                    copyParams.Destination.Slug = response.Slug;

                    // get items from other list
                    TraktUserList userList = TraktAPI.TraktAPI.GetUserList(copyParams.Username, copyParams.Source.Slug);
                    // copy items to new list
                    List<TraktListItem> items = new List<TraktListItem>();
                    foreach (var item in userList.Items)
                    {
                        TraktListItem listItem = new TraktListItem();
                        listItem.Type = item.Type;

                        switch (item.Type)
                        {
                            case "movie":
                                listItem.Title = item.Movie.Title;
                                listItem.Year = Convert.ToInt32(item.Movie.Year);
                                listItem.ImdbId = item.Movie.Imdb;
                                break;
                            case "show":
                                listItem.Title = item.Show.Title;
                                listItem.Year = item.Show.Year;
                                listItem.TvdbId = item.Show.Tvdb;
                                break;
                            case "season":
                                listItem.Title = item.Show.Title;
                                listItem.Year = item.Show.Year;
                                listItem.TvdbId = item.Show.Tvdb;
                                listItem.Season = Convert.ToInt32(item.SeasonNumber);
                                break;
                            case "episode":
                                listItem.Title = item.Show.Title;
                                listItem.Year = item.Show.Year;
                                listItem.TvdbId = item.Show.Tvdb;
                                listItem.Season = Convert.ToInt32(item.SeasonNumber);
                                listItem.Episode = Convert.ToInt32(item.EpisodeNumber);
                                break;
                        }
                        items.Add(listItem);
                    }
                    copyParams.Destination.Items = items;

                    // add items to the list
                    TraktAPI.TraktAPI.LogTraktResponse<TraktSyncResponse>(TraktAPI.TraktAPI.ListAddItems(copyParams.Destination));
                    if (response.Status == "success") TraktLists.ClearCache(TraktSettings.Username);
                }
            })
            {
                Name = "Copy List",
                IsBackground = true
            };
            copyThread.Start(copyList);
        }
        private void DeleteList(TraktUserList list)
        {
            if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.ConfirmDeleteList, false))
            {
                return;
            }

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                TraktLogger.Info("Deleting list '{0}'", list.Name);
                TraktList deleteList = new TraktList{ UserName = TraktSettings.Username, Password = TraktSettings.Password, Slug = list.Slug };
                return TraktAPI.TraktAPI.ListDelete(deleteList);
            },
            delegate(bool success, object result)
            {
                if (success)
                {
                    TraktResponse response = result as TraktResponse;
                    TraktAPI.TraktAPI.LogTraktResponse<TraktResponse>(response);
                    if (response.Status == "success")
                    {
                        // reload with new list
                        TraktLists.ClearCache(TraktSettings.Username);
                        LoadLists();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, response.Error);
                    }
                }
            }, Translation.DeletingList, true);
        }
        private void SendListItemsToFacade(TraktUserList list)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (list.Items == null || list.Items.Count() == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoListItemsFound);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            int itemId = 0;
            List<object> images = new List<object>();

            // Add each list item
            foreach (var listItem in list.Items)
            {
                GUITraktCustomListItem item = new GUITraktCustomListItem(listItem.ToString());

                item.Label2 = listItem.Year;
                item.TVTag = listItem;
                item.Item = listItem.Images;
                item.IsPlayed = listItem.Watched;
                item.ItemId = Int32.MaxValue - itemId;
                item.IconImage = "defaultVideo.png";
                item.IconImageBig = "defaultVideoBig.png";
                item.ThumbnailImage = "defaultVideoBig.png";
                item.OnItemSelected += OnItemSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;

                // add image for download
                images.Add(listItem.Images);
            }

            // Set Facade Layout
            Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
            GUIControl.FocusControl(GetID, Facade.GetID);

            Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", list.Items.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", list.Items.Count().ToString(), list.Items.Count() > 1 ? Translation.Items : Translation.Item));

            // Download images Async and set to facade
            GetImages(images);
        }