Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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,
                ShowNumbers = selectedList.ShowNumbers,
                AllowShouts = selectedList.AllowShouts
            };

            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();
        }
Ejemplo n.º 3
0
        protected override void OnShowContextMenu()
        {
            if (GUIBackgroundTask.Instance.IsBusy)
            {
                return;
            }

            GUIListItem selectedItem = this.Facade.SelectedListItem;

            if (selectedItem == null)
            {
                return;
            }

            TraktListDetail selectedList = null;
            string          username     = CurrentUser;

            if (selectedItem.TVTag is TraktListDetail)
            {
                selectedList = selectedItem.TVTag as TraktListDetail;
            }
            else if (selectedItem.TVTag is TraktListTrending)
            {
                var trending = selectedItem.TVTag as TraktListTrending;
                selectedList = trending.List;
                username     = trending.List.User.Username;
            }
            else if (selectedItem.TVTag is TraktListPopular)
            {
                var popular = selectedItem.TVTag as TraktListPopular;
                selectedList = popular.List;
                username     = popular.List.User.Username;
            }
            else if (selectedItem.TVTag is TraktLike)
            {
                var likedItem = selectedItem.TVTag as TraktLike;
                selectedList = likedItem.List;
                username     = likedItem.List.User.Username;
            }

            var 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 (username == 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
            {
                // like list
                if (!selectedList.IsLiked())
                {
                    listItem = new GUIListItem(Translation.Like);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.Like;
                }
                else
                {
                    // unLike list
                    listItem = new GUIListItem(Translation.UnLike);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.Unlike;
                }

                // copy a friends list
                listItem = new GUIListItem(Translation.CopyList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Copy;
            }

            // allow viewing comments for any type of lists
            // if comments are not allowed there will most like be no comments
            if (selectedList.AllowComments)
            {
                listItem = new GUIListItem(Translation.Comments + "...");
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Comments;
            }

            // Show Context Menu
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedId < 0)
            {
                return;
            }

            var currentList = new TraktListDetail
            {
                Ids            = selectedList.Ids,
                Name           = selectedList.Name,
                Description    = selectedList.Description,
                Privacy        = selectedList.Privacy,
                AllowComments  = selectedList.AllowComments,
                DisplayNumbers = selectedList.DisplayNumbers,
                ItemCount      = selectedList.ItemCount,
                Likes          = selectedList.Likes,
                UpdatedAt      = selectedList.UpdatedAt
            };

            switch (dlg.SelectedId)
            {
            case ((int)ContextMenuItem.Create):
                var list = new TraktListDetail();
                if (TraktLists.GetListDetailsFromUser(ref list))
                {
                    if (Lists.Any(l => l.Name == list.Name))
                    {
                        // list with that name already exists
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.ListNameAlreadyExists);
                        return;
                    }
                    TraktLogger.Info("Creating new list for user online. Privacy = '{0}', Name = '{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. Name = '{0}', Id = '{1}'", currentList.Name);
                    EditList(currentList);
                }
                break;

            case ((int)ContextMenuItem.Copy):
                if (TraktLists.GetListDetailsFromUser(ref currentList))
                {
                    CopyList(selectedList, currentList);
                }
                break;

            case ((int)ContextMenuItem.Like):
                GUICommon.LikeList(selectedList);
                selectedList.Likes++;
                PublishListProperties(selectedList);
                break;

            case ((int)ContextMenuItem.Unlike):
                GUICommon.UnLikeList(selectedList);
                if (selectedList.Likes > 0)
                {
                    // different behaviour basis the current view
                    if (ListType == TraktListType.Liked)
                    {
                        // remove liked list from cache and reload
                        TraktLists.RemovedItemFromLikedListCache(selectedList.Ids.Trakt);
                        LoadLists();
                    }
                    else
                    {
                        // update selected list properties as we have unliked it now.
                        selectedList.Likes--;
                        PublishListProperties(selectedList);
                    }
                }
                break;

            case ((int)ContextMenuItem.Comments):
                ReturningFromListItemsOrComments = true;
                TraktHelper.ShowListShouts(selectedList);
                break;

            default:
                break;
            }

            base.OnShowContextMenu();
        }
Ejemplo n.º 4
0
        private void SendUserListsToFacade(IEnumerable <TraktListDetail> lists)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (lists == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // check if the user has any lists (not the currently logged in user)
            if (ListType == TraktListType.User && lists.Count() == 0 && TraktSettings.Username != CurrentUser)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoUserLists, CurrentUser));
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            // check if the currently logged in user has any lists
            // if none, prompt to create one
            if (ListType == TraktListType.User && lists.Count() == 0)
            {
                if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.NoListsFound, true))
                {
                    // nothing to do, exit
                    GUIWindowManager.ShowPreviousWindow();
                    return;
                }

                var list = new TraktListDetail();
                if (TraktLists.GetListDetailsFromUser(ref list))
                {
                    TraktLogger.Info("Creating new list online. Privacy = '{0}', Name = '{1}'", list.Privacy, list.Name);
                    CreateList(list);
                }
                return;
            }

            int itemId = 0;

            // Add each list
            foreach (var list in lists)
            {
                var item = new GUIListItem(list.Name);

                item.Label2          = string.Format("{0} {1}", list.ItemCount, list.ItemCount != 1 ? Translation.Items : Translation.Item);
                item.TVTag           = list;
                item.ItemId          = Int32.MaxValue - itemId;
                item.PinImage        = TraktLists.GetPrivacyLevelIcon(list.Privacy);
                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.CurrentLayout = GUIFacadeControl.Layout.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));
        }
Ejemplo n.º 5
0
        protected override void OnShowContextMenu()
        {
            if (GUIBackgroundTask.Instance.IsBusy)
            {
                return;
            }

            GUIListItem selectedItem = this.Facade.SelectedListItem;

            if (selectedItem == null)
            {
                return;
            }

            var selectedList = selectedItem.TVTag as TraktListDetail;

            if (selectedItem == null)
            {
                return;
            }

            var 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
            {
                // like list
                if (!selectedList.IsLiked())
                {
                    listItem = new GUIListItem(Translation.Like);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.Like;
                }
                else
                {
                    // unLike list
                    listItem = new GUIListItem(Translation.UnLike);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.Unlike;
                }

                // 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;
            }

            var currentList = new TraktListDetail
            {
                Ids            = selectedList.Ids,
                Name           = selectedList.Name,
                Description    = selectedList.Description,
                Privacy        = selectedList.Privacy,
                AllowComments  = selectedList.AllowComments,
                DisplayNumbers = selectedList.DisplayNumbers,
                ItemCount      = selectedList.ItemCount,
                Likes          = selectedList.Likes,
                UpdatedAt      = selectedList.UpdatedAt
            };

            switch (dlg.SelectedId)
            {
            case ((int)ContextMenuItem.Create):
                var list = new TraktListDetail();
                if (TraktLists.GetListDetailsFromUser(ref list))
                {
                    if (Lists.Any(l => l.Name == list.Name))
                    {
                        // list with that name already exists
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.ListNameAlreadyExists);
                        return;
                    }
                    TraktLogger.Info("Creating new list for user online. Privacy = '{0}', Name = '{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. Name = '{0}', Id = '{1}'", currentList.Name);
                    EditList(currentList);
                }
                break;

            case ((int)ContextMenuItem.Copy):
                if (TraktLists.GetListDetailsFromUser(ref currentList))
                {
                    CopyList(selectedList, currentList);
                }
                break;

            case ((int)ContextMenuItem.Like):
                GUICommon.LikeList(selectedList, CurrentUser);
                selectedList.Likes++;
                PublishListProperties(selectedList);
                break;

            case ((int)ContextMenuItem.Unlike):
                GUICommon.UnLikeList(selectedList, CurrentUser);
                if (selectedList.Likes > 0)
                {
                    selectedList.Likes--;
                    PublishListProperties(selectedList);
                }
                break;

            default:
                break;
            }

            base.OnShowContextMenu();
        }