private void CreateList(TraktList list)
        {
            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                return(TraktAPI.TraktAPI.CreateCustomList(list));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    var response = result as TraktListDetail;
                    if (response != null)
                    {
                        // add to MovingPictures categories and filters menu
                        if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                        {
                            // not very thread safe if we tried to add more than one before response!
                            TraktHandlers.MovingPictures.AddCustomListNode(list.Name);
                        }

                        // reload with new list
                        TraktLists.ClearListCache(TraktSettings.Username);
                        LoadLists();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.FailedCreateList);
                    }
                }
            }, Translation.CreatingList, true);
        }
        private void EditList(TraktListDetail list)
        {
            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                return(TraktAPI.TraktAPI.UpdateCustomList(list));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    var response = result as TraktListDetail;
                    if (response == null)
                    {
                        // reload with new list
                        TraktLists.ClearListCache(TraktSettings.Username);
                        LoadLists();

                        var thread = new Thread((o) =>
                        {
                            TraktCache.ClearCustomListCache();

                            // updated MovingPictures categories and filters menu
                            if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                            {
                                TraktHandlers.MovingPictures.UpdateCategoriesMenu(SyncListType.CustomList);
                                TraktHandlers.MovingPictures.UpdateFiltersMenu(SyncListType.CustomList);
                            }
                        })
                        {
                            Name         = "EditList",
                            IsBackground = true
                        };
                        thread.Start();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.FailedUpdateList);
                    }
                }
            }, Translation.EditingList, true);
        }
        private void DeleteList(TraktListDetail list)
        {
            if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.ConfirmDeleteList, false))
            {
                return;
            }

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                TraktLogger.Info("Deleting list from online. Name = '{0}', Id = '{1}'", list.Name, list.Ids.Trakt);
                return(TraktAPI.TraktAPI.DeleteUserList("me", list.Ids.Trakt.ToString()));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    if ((result as bool?) == true)
                    {
                        // remove from MovingPictures categories and filters menu
                        if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                        {
                            // not very thread safe if we tried to delete more than one before response!
                            TraktHandlers.MovingPictures.RemoveCustomListNode(list.Name);
                        }

                        // reload with new list
                        TraktLists.ClearListCache(TraktSettings.Username);
                        LoadLists();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.FailedDeleteList);
                    }
                }
            }, Translation.DeletingList, true);
        }
        private void CopyList(TraktListDetail sourceList, TraktList newList)
        {
            var copyList = new CopyList {
                Username    = CurrentUser,
                Source      = sourceList,
                Destination = newList
            };

            var copyThread = new Thread((obj) =>
            {
                var copyParams = obj as CopyList;

                // first create new list
                TraktLogger.Info("Creating new list online. Privacy = '{0}', Name = '{1}'", copyParams.Destination.Privacy, copyParams.Destination.Name);
                var response = TraktAPI.TraktAPI.CreateCustomList(copyParams.Destination);
                if (response == null || response.Ids == null)
                {
                    TraktLogger.Error("Failed to create user list. List Name = '{0}'", copyParams.Destination.Name);
                    return;
                }

                // get items from other list
                var userListItems = TraktAPI.TraktAPI.GetUserListItems(copyParams.Source.User.Ids.Slug, copyParams.Source.Ids.Trakt.ToString(), "min");
                if (userListItems == null)
                {
                    TraktLogger.Error("Failed to get user list items. List Name = '{0}', ID = '{1}'", copyParams.Destination.Name, copyParams.Source.Ids.Trakt);
                    return;
                }

                // copy items to new list
                var itemsToAdd = new TraktSyncAll();
                foreach (var item in userListItems)
                {
                    var listItem  = new TraktListItem();
                    listItem.Type = item.Type;

                    switch (item.Type)
                    {
                    case "movie":
                        if (itemsToAdd.Movies == null)
                        {
                            itemsToAdd.Movies = new List <TraktMovie>();
                        }

                        itemsToAdd.Movies.Add(new TraktMovie {
                            Ids = item.Movie.Ids
                        });
                        break;

                    case "show":
                        if (itemsToAdd.Shows == null)
                        {
                            itemsToAdd.Shows = new List <TraktShow>();
                        }

                        itemsToAdd.Shows.Add(new TraktShow {
                            Ids = item.Show.Ids
                        });
                        break;

                    case "season":
                        if (itemsToAdd.Seasons == null)
                        {
                            itemsToAdd.Seasons = new List <TraktSeason>();
                        }

                        itemsToAdd.Seasons.Add(new TraktSeason {
                            Ids = item.Season.Ids
                        });
                        break;

                    case "episode":
                        if (itemsToAdd.Episodes == null)
                        {
                            itemsToAdd.Episodes = new List <TraktEpisode>();
                        }

                        itemsToAdd.Episodes.Add(new TraktEpisode {
                            Ids = item.Episode.Ids
                        });
                        break;

                    case "person":
                        if (itemsToAdd.People == null)
                        {
                            itemsToAdd.People = new List <TraktPerson>();
                        }

                        itemsToAdd.People.Add(new TraktPerson {
                            Ids = item.Person.Ids
                        });
                        break;
                    }
                }

                // add items to the list
                var ItemsAddedResponse = TraktAPI.TraktAPI.AddItemsToList("me", response.Ids.Trakt.ToString(), itemsToAdd);

                if (ItemsAddedResponse != null)
                {
                    TraktLists.ClearListCache(TraktSettings.Username);
                    TraktCache.ClearCustomListCache();

                    // updated MovingPictures categories and filters menu
                    if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                    {
                        MovingPictures.UpdateCategoriesMenu(SyncListType.CustomList);
                        MovingPictures.UpdateFiltersMenu(SyncListType.CustomList);
                    }
                }
            })
            {
                Name         = "CopyList",
                IsBackground = true
            };

            copyThread.Start(copyList);
        }