Example #1
0
        private void ShowContextMenuTorrents(Torrent tor)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
                return;

            dlg.Reset();
            dlg.SetHeading(tor.Name);

            dlg.Add("Stop Torrent");
            dlg.Add("Start Torrent");
            dlg.Add("Pause Torrent");
            dlg.Add("Remove Torrent");
            dlg.Add("Remove Torrent And Data");
            dlg.DoModal(GUIWindowManager.ActiveWindow);

            switch (dlg.SelectedLabel)
            {
                case 0:
                    MainWindow.uTorrent.StopTorrent(tor.Hash);
                    LoadUTorrentListAsync();
                    break;

                case 1:
                    MainWindow.uTorrent.StartTorrent(tor.Hash);
                    LoadUTorrentListAsync();
                    break;

                case 2:
                    MainWindow.uTorrent.PauseTorrent(tor.Hash);
                    LoadUTorrentListAsync();
                    break;

                case 3:
                    MainWindow.uTorrent.RemoveTorrent(tor.Hash);
                    LoadUTorrentListAsync();
                    break;

                case 4:
                    MainWindow.uTorrent.RemoveTorrentAndData(tor.Hash);
                    LoadUTorrentListAsync();
                    break;

            }
        }
Example #2
0
        public bool GetTorrentList(ref List<Torrent> torrents)
        {
            torrents = new List<Torrent>();

            if (!ValidCredentials())
            {
                BaseConfig.MyAnimeLog.Write("Credentials are not valid for uTorrent");
                return false;
            }

            string url = "";
            try
            {
                //http://[IP]:[PORT]/gui/?list=1
                url = string.Format(urlTorrentList, address, port, token);
                string output = GetWebResponse(url);
                if (output.Length == 0) return false;

                //BaseConfig.MyAnimeLog.Write("Torrent List JSON: {0}", output);
                TorrentList torList = JSONHelper.Deserialize<TorrentList>(output);

                foreach (object[] obj in torList.torrents)
                {
                    Torrent tor = new Torrent(obj);
                    torrents.Add(tor);
                }

                return true;
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write("Error in GetTorrentList: {0} - {1}", url, ex.ToString());
                return false;
            }
        }
Example #3
0
 private void SetTorrentListItem(ref GUIListItem item, Torrent tor)
 {
     //BaseConfig.MyAnimeLog.Write(tor.ToString());
     if (item == null)
     {
         item = new GUIListItem();
         item.Label = tor.ListDisplay;
         item.TVTag = tor;
         m_Facade.Add(item);
     }
     else
     {
         item.Label = tor.ListDisplay;
         item.TVTag = tor;
     }
 }
Example #4
0
        private void DisplayTorrentDetails(Torrent tor)
        {
            clearGUIProperty("Torrent.Name");
            clearGUIProperty("Torrent.Size");
            clearGUIProperty("Torrent.Done");
            clearGUIProperty("Torrent.DownloadSpeed");
            clearGUIProperty("Torrent.UploadSpeed");
            clearGUIProperty("Torrent.Downloaded");
            clearGUIProperty("Torrent.Uploaded");
            clearGUIProperty("Torrent.Ratio");
            clearGUIProperty("Torrent.Seeds");
            clearGUIProperty("Torrent.SInSwarm");
            clearGUIProperty("Torrent.Peers");
            clearGUIProperty("Torrent.PInSwarm");

            setGUIProperty("Torrent.Name", tor.Name);
            setGUIProperty("Torrent.Size", tor.SizeFormatted);
            setGUIProperty("Torrent.Done", tor.PercentProgressFormatted);
            setGUIProperty("Torrent.DownloadSpeed", tor.DownloadSpeedFormatted);
            setGUIProperty("Torrent.UploadSpeed", tor.UploadSpeedFormatted);
            setGUIProperty("Torrent.Downloaded", tor.DownloadedFormatted);
            setGUIProperty("Torrent.Uploaded", tor.UploadedFormatted);
            setGUIProperty("Torrent.Ratio", tor.RatioFormatted);
            setGUIProperty("Torrent.Seeds", tor.SeedsConnected.ToString());
            setGUIProperty("Torrent.SInSwarm", tor.SeedsInSwarm.ToString());
            setGUIProperty("Torrent.Peers", tor.PeersConnected.ToString());
            setGUIProperty("Torrent.PInSwarm", tor.PeersInSwarm.ToString());
        }
Example #5
0
        protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            if (MA3WindowManager.HandleWindowChangeButton(control))
                return;

            if (control == this.btnTorrentsUIPage)
            {
                this.btnTorrentsUIPage.IsFocused = false;
                ShowPageTorrents();
                m_Facade.Focus = true;
            }

            if (control == this.btnSearchPage)
            {
                this.btnSearchPage.Focus = false;
                ShowPageSearch(true);
                m_Facade.Focus = true;
            }

            if (control == this.btnBrowseTorrentsPage)
            {
                this.btnBrowseTorrentsPage.Focus = false;
                ShowPageBrowseTorrents();
                m_Facade.Focus = true;
            }

            if (control == this.m_Facade)
            {
                // show the files if we are looking at a torrent
                GUIListItem item = m_Facade.SelectedListItem;

                //BaseConfig.MyAnimeLog.Write("Type: {0}", item.TVTag.GetType());

                // torrents
                // show the files if we are looking at a torrent
                if (item.TVTag.GetType() == typeof(Torrent))
                {
                    Torrent torItem = item.TVTag as Torrent;
                    if (torItem != null)
                    {
                        curTorrent = torItem;
                        List<TorrentFile> torfiles = new List<TorrentFile>();
                        if (MainWindow.uTorrent.GetFileList(torItem.Hash, ref torfiles))
                        {
                            ShowPageTorrentFiles(torfiles);
                        }
                    }
                }

                if (item.TVTag.GetType() == typeof(TorrentFile))
                {
                    if (item.Label == UpFolder)
                    {

                        ShowPageTorrents();
                    }
                }

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

                    ShowContextMenuSearch(torLink);
                }

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

                    ShowContextMenuBrowse(torLink);
                }
            }

            base.OnClicked(controlId, control, actionType);
        }
Example #6
0
        public override bool OnMessage(GUIMessage message)
        {
            switch (message.Message)
            {
                case GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS_CHANGED:
                    {
                        int iControl = message.SenderControlId;
                        if (iControl == (int)m_Facade.GetID)
                        {
                            GUIListItem item = m_Facade.SelectedListItem;

                            if (item == null || item.TVTag == null) return true;

                            //BaseConfig.MyAnimeLog.Write("Type: {0}", item.TVTag.GetType());

                            // torrents
                            if (item.TVTag.GetType() == typeof(Torrent))
                            {
                                Torrent torItem = item.TVTag as Torrent;
                                if (torItem != null)
                                {
                                    curTorrent = torItem;
                                    DisplayTorrentDetails(torItem);
                                }
                            }

                            // torrent file
                            if (item.TVTag.GetType() == typeof(TorrentFile))
                            {
                                TorrentFile torFile = item.TVTag as TorrentFile;
                                if (torFile != null)
                                {
                                    //curTorrent = torItem;
                                    DisplayTorrentFileDetails(torFile);
                                }
                            }

                            // search results
                            if (item.TVTag.GetType() == typeof(TorrentLink))
                            {
                                TorrentLink torLink = item.TVTag as TorrentLink;
                                if (torLink != null)
                                {
                                    //curTorrent = torItem;
                                    DisplayTorrentLinkDetails(torLink);
                                }
                            }
                        }
                    }

                    return true;

                default:
                    return base.OnMessage(message);
            }
        }
Example #7
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());
            }
        }