private void UpdateSearchResults() { try { SearchResults.Clear(); } catch (Exception ex) { } IconMapping iconMapping = Configuration.Instance().Settings["MyTorrents.GlobalIconMapping"] as IconMapping; Regex re = null; if (_filter != "") { re = new Regex(_filter, RegexOptions.IgnoreCase); } foreach (TorrentMatch match in _matches) { if (re != null) { if (!re.IsMatch(match.Title)) { continue; } } GUIListItem item = new GUIListItem(); //item.PinImage = iconMapping.GetIcon(match.Title); item.PinImage = match.Icon; item.Label = String.Format("{0}- {1} - {2} ({3}:{4})", match.Category, match.SubCategory, match.Title, match.Seed, match.Leech); item.Label2 = match.Date.ToShortDateString(); item.Label3 = UnitConvert.SizeToString(match.Size); item.OnItemSelected += OnSearchResultSelected; item.AlbumInfoTag = match; SearchResults.Add(item); } GUIDialogProgress dlg = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS); dlg.Close(); _progressDlg = null; GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", SearchResults.Count)); }
private void UpdateTorrentList(bool timed) { if (torrentList == null) { return; } List <GUIListItem> CurItems = new List <GUIListItem>(torrentList.ListItems); foreach (Torrent torrent in TorrentEngine.Instance().TorrentSession.TorrentsAll) { if (torrent.Progress < 100.0) { GUIListItem item = FindItemByHash(torrentList, torrent); if (item == null) { item = new GUIListItem(string.Format("{0}", Ellipsis(torrent.Name, 75))); item.AlbumInfoTag = torrent; torrentList.Add(item); } else { CurItems.Remove(item); } item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress); //item.Label3 = ((T.fETA == "-1s") || (T.fETA == "0s")) ? "" : T.fETA.ToLower(); } } foreach (var i in CurItems) { torrentList.ListItems.Remove(i); } if (torrentList.ListItems.Count == 0) { GUIPropertyManager.SetProperty("#MyTorrents.Count", "0"); GUIListItem item = new GUIListItem(); item.Label = "No torrents."; torrentList.Add(item); } else { GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", torrentList.ListItems.Count)); } }
public void ShowTorrents() { if (torrentList == null) { return; } List <GUIListItem> tl = new List <GUIListItem>(); var TA = TorrentEngine.Instance().GetTorrents(TorrentView, SortOrder, LabelFilter); foreach (Torrent torrent in TA) { GUIListItem item = new GUIListItem(string.Format("{0}", Ellipsis(torrent.Name, 75))); //GUIImage image = new GUIImage(5678); //item.Icon = image; //item.IconImage = System.IO.Path.Combine(GUIGraphicsContext.Skin, @"\Media\icon_empty_focus1.png"); item.AlbumInfoTag = torrent; tl.Add(item); if (item.Label2 != string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress)) { item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress); } } torrentList.ListItems = tl; if (torrentList.ListItems.Count == 0) { GUIPropertyManager.SetProperty("#MyTorrents.Count", "0"); GUIListItem item = new GUIListItem(); item.Label = "No items."; torrentList.Add(item); } else { GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", torrentList.ListItems.Count)); } }
public List <GUIListItem> GetTorrentDetails(Torrent utorrent) { List <GUIListItem> fileList = new List <GUIListItem>(); SelectedHash = utorrent.Hash; if (utorrent == null) { //torrent got removed! } List <File> files = TorrentEngine.Instance().TorrentSession.GetFiles(utorrent.Hash); foreach (var file in files) { GUIListItem item = new GUIListItem(); item.Label = file.Filename; item.IconImage = System.IO.Path.Combine(GUIGraphicsContext.Skin, @"\Media\icon_empty_focus1.png"); item.AlbumInfoTag = file; fileList.Add(item); item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(file.Filesize), (double)file.Downloaded / file.Filesize * 100.0); } GUIPropertyManager.SetProperty("#MyTorrents.Details.Name", utorrent.Name); GUIPropertyManager.SetProperty("#MyTorrents.Details.Progress", string.Format("{0:F2}", utorrent.Progress)); GUIPropertyManager.SetProperty("#MyTorrents.Details.Ratio", string.Format("{0:F2}", (float)utorrent.Ratio * 0.001)); GUIPropertyManager.SetProperty("#MyTorrents.Details.ETA", UnitConvert.TimeRemainingToString(utorrent.ETA)); GUIPropertyManager.SetProperty("#MyTorrents.Details.UploadSpeed", UnitConvert.TransferSpeedToString(utorrent.UploadSpeed)); GUIPropertyManager.SetProperty("#MyTorrents.Details.DownloadSpeed", UnitConvert.TransferSpeedToString(utorrent.DownloadSpeed)); GUIPropertyManager.SetProperty("#MyTorrents.Details.Peers", string.Format("{0} ({1})", utorrent.PeersConnected, utorrent.PeersInSwarm)); GUIPropertyManager.SetProperty("#MyTorrents.Details.Seeds", string.Format("{0} ({1})", utorrent.SeedsConnected, utorrent.SeedsInSwarm)); GUIPropertyManager.SetProperty("#MyTorrents.Details.Size", UnitConvert.SizeToString(utorrent.Size)); return(fileList); }
public void SearchItemClicked(TorrentMatch match) { GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); dlg.SetHeading("Download this torrent?"); dlg.SetLine(1, match.Title); dlg.SetLine(2, UnitConvert.SizeToString(match.Size)); //dlg.SetLine(3, item.Label3); dlg.DoModal(GUIWindowManager.ActiveWindow); if (!dlg.IsConfirmed) { return; } label = DialogAskLabel.Ask(); if (label == null) { return; } Log.Instance().Print("label is " + label.Name); List <DownloadDir> predefined = TorrentEngine.Instance().TorrentSession.ListDirs(); if (predefined == null) { //MyTorrents.Instance().DisplayError("Unable to connect", "Connection error. Please open your Torrent client before retrying."); //return; } GUIDialogMenu chooser = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (chooser == null) { return; } chooser.Reset(); chooser.SetHeading("Download options"); chooser.Add("No change"); //foreach (DownloadDir dir in predefined) //{ // GUIListItem element = new GUIListItem(); // element.Label = dir.path; // element.Label2 = String.Format("{0} MB Free", Convert.ToString(dir.available)); // chooser.Add(element); //} chooser.Add("Browse Folders"); chooser.DoModal(GUIWindowManager.ActiveWindow); if (chooser.SelectedId == -1) { return; } int selecteddirId = chooser.SelectedId; string selectedText = chooser.SelectedLabelText; Log.Instance().Print("download option is " + selectedText); bool ok = false; // KAT hack string dowOption = ""; if (_searchEngine.GetType() == typeof(TorrentSearch_Combiner)) { Log.Instance().Print("Selected engine is Combiner"); TorrentSearch_Combiner _eng = (TorrentSearch_Combiner)_searchEngine; if (_searchEngine.Parameters.ContainsKey("Options")) { dowOption = _eng.Engines.Where(e => e.Name == match.tracker).First().Parameters["Options"].ToString().Replace("%id%", match.Id); } } else { if (_searchEngine.Parameters.ContainsKey("Options")) { dowOption = _searchEngine.Parameters["Options"].ToString().Replace("%id%", match.Id); } } switch (selectedText) { case "Browse Folders": //FolderBrowser ViewFolders = new FolderBrowser(TorrentEngine.Instance().TorrentSession, label, match, dowOption); Log.Instance().Print("Loading file browser"); MyTorrents.ListType = "FolderBrowser"; MyTorrents.Instance().ShowFolderBrowser(); break; case "No change": if (label != null) { Log.Instance().Print("Starting torrent file downloading"); ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, dowOption, ""); } break; default: if (label != null) { Log.Instance().Print("Starting torrent file downloading"); ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, dowOption, String.Format("&download_dir={0}", selecteddirId - 2)); } break; } /* * if (!ok) * { * GUIDialogNotify notify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); * notify.Reset(); * notify.SetHeading("Failed!"); * notify.SetText("Unable to start download."); * notify.DoModal(GUIWindowManager.ActiveWindow); * * Log.Instance().Print("Downloading failed"); * } * */ }