예제 #1
0
        private void ShowUTorrentList(List <Torrent> torrents)
        {
            // make sure the user has valid utorrent details
            // do not show if the user is on a different window
            // don't refresh if the user is actually looking at the files for a torrent
            if (GUIWindowManager.ActiveWindow != Constants.WindowIDs.DOWNLOADS)
            {
                //BaseConfig.MyAnimeLog.Write("Not showing torrents");
                return;
            }

            try
            {
                GUIListItem item      = null;
                GUIListItem foundItem = null;

                // if the user is not actually looking at this window we will not refresh the list
                // however we may still want to send a notification

                if (dummyPageTorrents.IsVisible)
                {
                    // check for any torrents that have been removed
                    // if they have it is easier just to clear the list
                    bool missingTorrents = false;
                    for (int itemIndex = 0; itemIndex < GUIControl.GetItemCount(this.GetID, this.m_Facade.GetID); itemIndex++)
                    {
                        bool foundTorrent = false;
                        item = GUIControl.GetListItem(this.GetID, this.m_Facade.GetID, itemIndex);
                        Torrent torItem = item.TVTag as Torrent;

                        if (torItem != null)
                        {
                            foreach (Torrent tor in torrents)
                            {
                                if (tor.Hash == torItem.Hash)
                                {
                                    foundTorrent = true;
                                    break;
                                }
                            }
                        }

                        if (!foundTorrent)
                        {
                            missingTorrents = true;
                            break;
                        }
                    }

                    if (missingTorrents)
                    {
                        m_Facade.Clear();
                    }


                    long totalSpeed     = 0;
                    int  activeTorrents = 0;
                    foreach (Torrent tor in torrents)
                    {
                        foundItem = null;
                        if (tor.IsDownloading)
                        {
                            activeTorrents++;
                            totalSpeed += tor.DownloadSpeed;
                        }

                        for (int itemIndex = 0; itemIndex < GUIControl.GetItemCount(this.GetID, this.m_Facade.GetID); itemIndex++)
                        {
                            item = GUIControl.GetListItem(this.GetID, this.m_Facade.GetID, itemIndex);
                            Torrent torItem = item.TVTag as Torrent;

                            if (curTorrent != null)
                            {
                                if (curTorrent.Hash == torItem.Hash)
                                {
                                    curTorrent = torItem;
                                }
                            }

                            if (tor.Hash == torItem.Hash)
                            {
                                foundItem = item;
                            }
                        }

                        SetTorrentListItem(ref foundItem, tor);
                    }

                    // refresh the current torrent details if focused
                    if (curTorrent != null)
                    {
                        DisplayTorrentDetails(curTorrent);
                    }



                    setGUIProperty("Torrent.Summary", string.Format("{0} Active Torrents at {1}/sec", activeTorrents, Utils.FormatByteSize((long)totalSpeed)));
                }
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
예제 #2
0
        public override bool OnMessage(GUIMessage message)
        {
            switch (message.Message)
            {
            case GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT:
            {
                SetControlLabel(GetID, (int)Controls.CONTROL_HEADING, string.Empty);
                base.OnMessage(message);
                DeInitControls();
                Dispose();
                return(true);
            }

            case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT:
            {
                m_bButtonPressed = false;
                base.OnMessage(message);
                _selectedLabel = -1;
                ClearControl(GetID, (int)Controls.CONTROL_LIST);

                for (int i = 0; i < m_vecList.Count; i++)
                {
                    GUIListItem pItem = (GUIListItem)m_vecList[i];
                    AddListItemControl(GetID, (int)Controls.CONTROL_LIST, pItem);
                }

                string wszText = String.Format("{0} {1}", m_vecList.Count, GUILocalizeStrings.Get(127));

                SetControlLabel(GetID, (int)Controls.CONTROL_NUMBEROFFILES, wszText);

                if (m_bButtonEnabled)
                {
                    EnableControl(GetID, (int)Controls.CONTROL_BUTTON);
                }
                else
                {
                    DisableControl(GetID, (int)Controls.CONTROL_BUTTON);
                }
            }
                return(true);

            case GUIMessage.MessageType.GUI_MSG_CLICKED:
            {
                int iControl = message.SenderControlId;
                if ((int)Controls.CONTROL_LIST == iControl)
                {
                    int iAction = message.Param1;
                    if ((int)Action.ActionType.ACTION_SELECT_ITEM == iAction)
                    {
                        _selectedLabel = GetSelectedItemNo();
                        m_strSelected  = GetSelectedItem().Label;
                        PageDestroy();
                    }
                }
                if ((int)Controls.CONTROL_BUTTON == iControl)
                {
                    _selectedLabel   = -1;
                    m_bButtonPressed = true;
                    PageDestroy();
                }
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_ITEM_SELECTED:
            {
                if (m_bNewBehaviour)
                {
                    if (GetSelectedItem() != null)
                    {
                        GUIPropertyManager.SetProperty("#selecteditem", GetSelectedItem().Label);
                    }
                }
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS_CHANGED:
            {
                if (m_bNewBehaviour)
                {
                    int iControl = message.SenderControlId;
                    if ((int)Controls.CONTROL_LIST == iControl)
                    {
                        if (GetSelectedItem() != null)
                        {
                            m_strItemSelectedLabelTextNoFocus = GetSelectedItem().Label;
                            m_iItemSelectedIndexNoFocus       = GetSelectedItemNo();
                        }
                    }
                }
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_SETFOCUS:
            {
                if (m_bNewBehaviour)
                {
                    int iControl = message.TargetControlId;

                    if ((int)Controls.CONTROL_LIST == iControl)
                    {
                        if (GetSelectedItem() != null)
                        {
                            //GetSelectedItem().Selected = false;
                            int itemCount = GUIControl.GetItemCount(GetID, (int)Controls.CONTROL_LIST);

                            for (int i = 0; i < itemCount; i++)
                            {
                                GUIControl.GetListItem(GetID, (int)Controls.CONTROL_LIST, i).Selected = false;
                            }
                        }
                    }
                    if ((int)Controls.CONTROL_BUTTON == iControl)
                    {
                        if (GetSelectedItem() != null)
                        {
                            GetSelectedItem().Selected = true;
                        }
                    }
                }
            }
            break;
            }

            return(base.OnMessage(message));
        }
예제 #3
0
        protected override void OnShowContextMenu()
        {
            GUIListItem currentitem = this.m_Facade.SelectedListItem;

            if (currentitem == null)
            {
                if (dummyPageSearch.Visible)
                {
                    ShowContextMenuSearch(null);
                }
                if (dummyPageBrowse.Visible)
                {
                    ShowContextMenuBrowse(null);
                }

                return;
            }

            if (currentitem.TVTag == null)
            {
                return;
            }

            if (currentitem.TVTag.GetType() == typeof(Torrent))
            {
                Torrent tor = currentitem.TVTag as Torrent;
                if (tor == null)
                {
                    return;
                }

                ShowContextMenuTorrents(tor);
            }

            if (currentitem.TVTag.GetType() == typeof(TorrentFile))
            {
                TorrentFile tor = currentitem.TVTag as TorrentFile;
                if (tor == null)
                {
                    return;
                }

                int idx = -1;
                for (int itemIndex = 0; itemIndex < GUIControl.GetItemCount(this.GetID, this.m_Facade.GetID); itemIndex++)
                {
                    GUIListItem item    = GUIControl.GetListItem(this.GetID, this.m_Facade.GetID, itemIndex);
                    TorrentFile torTemp = item.TVTag as TorrentFile;

                    if (torTemp != null)
                    {
                        if (torTemp.FileName == tor.FileName)
                        {
                            idx = itemIndex;
                            break;
                        }
                    }
                }

                if (idx >= 0)
                {
                    idx = idx - 1;
                    ShowContextMenuTorrentFiles(tor, idx);
                }
            }

            if (currentitem.TVTag.GetType() == typeof(TorrentLink) && dummyPageSearch.Visible)
            {
                TorrentLink torLink = currentitem.TVTag as TorrentLink;
                if (torLink == null)
                {
                    return;
                }

                ShowContextMenuSearch(torLink);
            }

            if (currentitem.TVTag.GetType() == typeof(TorrentLink) && dummyPageBrowse.Visible)
            {
                TorrentLink torLink = currentitem.TVTag as TorrentLink;
                if (torLink == null)
                {
                    return;
                }

                ShowContextMenuBrowse(torLink);
            }
        }