/// <summary> /// Get all details needed to create a new list or edit existing list /// </summary> /// <param name="list">returns list details</param> /// <returns>true if list details completed</returns> public static bool GetListDetailsFromUser(ref TraktList list) { list.UserName = TraktSettings.Username; list.Password = TraktSettings.Password; bool editing = !string.IsNullOrEmpty(list.Slug); // Show Keyboard for Name of list string name = editing ? list.Name : string.Empty; if (!GUIUtils.GetStringFromKeyboard(ref name)) return false; if ((list.Name = name) == string.Empty) return false; // Skip Description and get Privacy...this requires a custom dialog as // virtual keyboard does not allow very much text for longer descriptions. // We may create a custom dialog for this in future List<GUIListItem> items = new List<GUIListItem>(); GUIListItem item = new GUIListItem(); int selectedItem = 0; // Public item = new GUIListItem { Label = Translation.PrivacyPublic, Label2 = Translation.Public }; if (list.Privacy == "public") { selectedItem = 0; item.Selected = true; } items.Add(item); // Private item = new GUIListItem { Label = Translation.PrivacyPrivate, Label2 = Translation.Private }; if (list.Privacy == "private") { selectedItem = 1; item.Selected = true; } items.Add(item); // Friends item = new GUIListItem { Label = Translation.PrivacyFriends, Label2 = Translation.Friends }; if (list.Privacy == "friends") { selectedItem = 2; item.Selected = true; } items.Add(item); selectedItem = GUIUtils.ShowMenuDialog(Translation.Privacy, items, selectedItem); if (selectedItem == -1) return false; list.Privacy = GetPrivacyLevelFromTranslation(items[selectedItem].Label2); return true; }
private void SendListsToFacade(IEnumerable<TraktUserList> lists) { // clear facade GUIControl.ClearControl(GetID, Facade.GetID); if (lists.Count() == 0 && TraktSettings.Username != CurrentUser) { GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoUserLists, CurrentUser)); CurrentUser = TraktSettings.Username; GUIWindowManager.ShowPreviousWindow(); return; } if (lists.Count() == 0) { if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.NoListsFound, true)) { // nothing to do, exit GUIWindowManager.ShowPreviousWindow(); return; } TraktList list = new TraktList(); if (TraktLists.GetListDetailsFromUser(ref list)) { TraktLogger.Info("Creating new '{0}' list '{1}'", list.Privacy, list.Name); CreateList(list); } return; } int itemId = 0; // Add each list foreach (var list in lists) { GUIListItem item = new GUIListItem(list.Name); item.Label2 = TraktLists.GetPrivacyLevelTranslation(list.Privacy); item.TVTag = list; item.ItemId = Int32.MaxValue - itemId; item.IconImage = "defaultFolder.png"; item.IconImageBig = "defaultFolderBig.png"; item.ThumbnailImage = "defaultFolderBig.png"; item.OnItemSelected += OnItemSelected; Utils.SetDefaultIcons(item); Facade.Add(item); itemId++; } // Set Facade Layout Facade.SetCurrentLayout("List"); GUIControl.FocusControl(GetID, Facade.GetID); if (PreviousSelectedIndex >= lists.Count()) Facade.SelectIndex(PreviousSelectedIndex - 1); else Facade.SelectIndex(PreviousSelectedIndex); // set facade properties GUIUtils.SetProperty("#itemcount", lists.Count().ToString()); GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", lists.Count().ToString(), lists.Count() > 1 ? Translation.Lists : Translation.List)); }
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; 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.EditingList, true); }
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 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); }
protected override void OnShowContextMenu() { if (GUIBackgroundTask.Instance.IsBusy) return; GUIListItem selectedItem = this.Facade.SelectedListItem; if (selectedItem == null) return; TraktUserList selectedList = (TraktUserList)selectedItem.TVTag; IDialogbox dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg == null) return; dlg.Reset(); dlg.SetHeading(GUIUtils.PluginName()); GUIListItem listItem = null; // only allow add/delete/update if viewing your own lists if (CurrentUser == TraktSettings.Username) { listItem = new GUIListItem(Translation.CreateList); dlg.Add(listItem); listItem.ItemId = (int)ContextMenuItem.Create; listItem = new GUIListItem(Translation.EditList); dlg.Add(listItem); listItem.ItemId = (int)ContextMenuItem.Edit; listItem = new GUIListItem(Translation.DeleteList); dlg.Add(listItem); listItem.ItemId = (int)ContextMenuItem.Delete; } else { // copy a friends list listItem = new GUIListItem(Translation.CopyList); dlg.Add(listItem); listItem.ItemId = (int)ContextMenuItem.Copy; } // Show Context Menu dlg.DoModal(GUIWindowManager.ActiveWindow); if (dlg.SelectedId < 0) return; TraktList currentList = new TraktList { Name = selectedList.Name, Description = selectedList.Description, Privacy = selectedList.Privacy, Slug = selectedList.Slug }; switch (dlg.SelectedId) { case ((int)ContextMenuItem.Create): TraktList list = new TraktList(); if (TraktLists.GetListDetailsFromUser(ref list)) { if (Lists.ToList().Exists(l => l.Name == list.Name)) { // list with that name already exists GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.ListNameAlreadyExists); return; } TraktLogger.Info("Creating new '{0}' list '{1}'", list.Privacy, list.Name); CreateList(list); } break; case ((int)ContextMenuItem.Delete): DeleteList(selectedList); break; case ((int)ContextMenuItem.Edit): if (TraktLists.GetListDetailsFromUser(ref currentList)) { TraktLogger.Info("Editing list '{0}'", currentList.Slug); EditList(currentList); } break; case ((int)ContextMenuItem.Copy): if (TraktLists.GetListDetailsFromUser(ref currentList)) { CopyList(selectedList, currentList); } break; default: break; } base.OnShowContextMenu(); }
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); }
internal static void AddRemoveItemInList(List<string> slugs, List<TraktListItem> items, bool remove) { Thread listThread = new Thread(delegate(object obj) { foreach (var slug in slugs) { TraktList list = new TraktList { UserName = TraktSettings.Username, Password = TraktSettings.Password, Slug = slug, Items = items }; TraktSyncResponse response = null; if (!remove) response = TraktAPI.TraktAPI.ListAddItems(list); else response = TraktAPI.TraktAPI.ListDeleteItems(list); TraktAPI.TraktAPI.LogTraktResponse<TraktSyncResponse>(response); if (response.Status == "success") { // clear current items in any lists // list items will be refreshed online if we try to request them TraktLists.ClearItemsInList(TraktSettings.Username, slug); } } }) { Name = remove ? "Remove Item from List" : "Add Item to List", IsBackground = true }; listThread.Start(); }
public static TraktListDetail CreateCustomList(TraktList list, string username = "******") { var response = PostToTrakt(string.Format(TraktURIs.UserListAdd, username), list.ToJSON()); return response.FromJSON<TraktListDetail>(); }
/// <summary> /// Get the slugs for each list selected by a user in the Multi-Select dialog /// </summary> /// <param name="username">username of user</param> /// <param name="lists">List of lists created by user</param> public static List<string> GetUserListSelections(List<TraktUserList> lists) { if (lists.Count == 0) { if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.NoListsFound, true)) { // nothing to do, return return null; } TraktList list = new TraktList(); if (TraktLists.GetListDetailsFromUser(ref list)) { TraktLogger.Info("Creating new '{0}' list '{1}'", list.Privacy, list.Name); TraktAddListResponse response = TraktAPI.TraktAPI.ListAdd(list); TraktAPI.TraktAPI.LogTraktResponse<TraktResponse>(response); if (response.Status == "success") { ClearCache(TraktSettings.Username); return new List<string> { response.Slug }; } } return null; } List<MultiSelectionItem> selectedItems = GUIUtils.ShowMultiSelectionDialog(Translation.SelectLists, GetMultiSelectItems(lists)); if (selectedItems == null) return null; List<string> slugs = new List<string>(); foreach (var item in selectedItems.Where(l => l.Selected == true)) { slugs.Add(item.ItemID); } return slugs; }