示例#1
0
        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;
                    TraktLogger.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);
        }
示例#2
0
 private void EditList(TraktList list)
 {
     GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
     {
         return(TraktAPI.TraktAPI.ListUpdate(list));
     },
                                                               delegate(bool success, object result)
     {
         if (success)
         {
             TraktResponse response = result as TraktResponse;
             TraktLogger.LogTraktResponse <TraktResponse>(response);
             if (response.Status == "success")
             {
                 // reload with new list
                 TraktLists.ClearCache(TraktSettings.Username);
                 LoadLists();
             }
             else
             {
                 GUIUtils.ShowNotifyDialog(Translation.Lists, response.Error);
             }
         }
     }, Translation.EditingList, true);
 }
示例#3
0
        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);
                TraktLogger.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.IMDBID;
                            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
                    TraktLogger.LogTraktResponse <TraktSyncResponse>(TraktAPI.TraktAPI.ListAddItems(copyParams.Destination));
                    if (response.Status == "success")
                    {
                        TraktLists.ClearCache(TraktSettings.Username);
                    }
                }
            })
            {
                Name         = "CopyList",
                IsBackground = true
            };

            copyThread.Start(copyList);
        }