Skip to content

Commit

Permalink
[Issue #21] Verify status of public trackers.
Browse files Browse the repository at this point in the history
Add new TStringGrid view with column for
keep, status and trackerURL
This new TStringGrid is replacing the 'simple' TCheckListBox list.
  • Loading branch information
GerryFerdinandus committed Oct 9, 2017
1 parent 5c9f940 commit 5d2ec98
Show file tree
Hide file tree
Showing 7 changed files with 486 additions and 59 deletions.
190 changes: 190 additions & 0 deletions source/code/controler_trackerlist_online.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
unit controler_trackerlist_online;

{
Show the present status of the trackerURL via TStringGrid
}
{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, Grids, trackerlist_online, newtrackon;

type

{ TControlerTrackerListOnline }

TControlerTrackerListOnline = class
private
FStringGridTorrentURL: TStringGrid;
FNewTrackon: TNewTrackon;
FTrackerListOnline: TTrackerListOnline;
FTrackerList: TStringList;

//The collumn must be in this design order.
FSelect, //< 0
FTorrentURL, //< 1
FTorrentURL_Status //< 2
: TGridColumn;

function GetChecked(index: integer): boolean;
procedure SetChecked(index: integer; AValue: boolean);
procedure ShowTrackerStatus(Visible: boolean);
procedure AppendRow(Checked: boolean; Status: TTrackerListOnlineStatus;
const TrackerURL: UTF8String);
public

property Checked[index: integer]: boolean read GetChecked write SetChecked;
function TrackerURL(index: integer): string;
function TrackerStatus(index: integer): TTrackerListOnlineStatus;
function Count: integer;
function StableTrackers: TStringList;

//must be called if the tracker list is updated
procedure UpdateView;

function DownloadTrackers: boolean;

constructor Create(StringGridTorrentURL: TStringGrid; TrackerList: TStringList);
destructor Destroy; override;
end;


implementation

uses Graphics;

{ TControlerTrackerListOnline }


function TControlerTrackerListOnline.DownloadTrackers: boolean;
begin
Result := FNewTrackon.DownloadTrackers;
UpdateView;
ShowTrackerStatus(Result);
end;

constructor TControlerTrackerListOnline.Create(StringGridTorrentURL: TStringGrid;
TrackerList: TStringList);
begin

FTrackerList := TrackerList;

FStringGridTorrentURL := StringGridTorrentURL;
FStringGridTorrentURL.RowCount := 1;
FStringGridTorrentURL.FixedRows := 1;
FStringGridTorrentURL.AlternateColor := clCream;

FSelect := FStringGridTorrentURL.Columns.Add;
FSelect.Title.Caption := 'Keep';
FSelect.ButtonStyle := cbsCheckboxColumn;
FSelect.ReadOnly := False;


FTorrentURL_Status := FStringGridTorrentURL.Columns.Add;
FTorrentURL_Status.Title.Caption := 'Online status';
ShowTrackerStatus(False);
FTorrentURL_Status.ReadOnly := True;

FTorrentURL := FStringGridTorrentURL.Columns.Add;
FTorrentURL.Title.Caption := 'Tracker URL';
FTorrentURL.ReadOnly := True;

//make sure all text are fit inside the columns
FStringGridTorrentURL.AutoSizeColumns;

FNewTrackon := TNewTrackon.Create;
FTrackerListOnline := TTrackerListOnline.Create;

//copy tracker list from TNewTrackon to TTrackerListOnline
FTrackerListOnline.TrackerList_Live := FNewTrackon.TrackerList_Live;
FTrackerListOnline.TrackerList_Dead := FNewTrackon.TrackerList_Dead;
FTrackerListOnline.TrackerList_Stable := FNewTrackon.TrackerList_Stable;
end;

destructor TControlerTrackerListOnline.Destroy;
begin
FTrackerListOnline.Free;
FNewTrackon.Free;
inherited Destroy;
end;

procedure TControlerTrackerListOnline.ShowTrackerStatus(Visible: boolean);
begin
FTorrentURL_Status.Visible := Visible;
end;

function TControlerTrackerListOnline.GetChecked(index: integer): boolean;
begin
//read the select checkbox. If '1' then it is True
Result := FStringGridTorrentURL.Cells[0, index +
FStringGridTorrentURL.FixedRows] = '1';
end;

procedure TControlerTrackerListOnline.SetChecked(index: integer; AValue: boolean);
begin
FStringGridTorrentURL.Cells[0, index + FStringGridTorrentURL.FixedRows] :=
BoolToStr(AValue, '1', '0');
end;


procedure TControlerTrackerListOnline.AppendRow(Checked: boolean;
Status: TTrackerListOnlineStatus; const TrackerURL: UTF8String);
var
CheckedStr, StatusStr: string;
begin
CheckedStr := BoolToStr(Checked, '1', '0');
StatusStr := FTrackerListOnline.TrackerListOnlineStatusToString(Status);

//append to the end of the view list
FStringGridTorrentURL.InsertRowWithValues(FStringGridTorrentURL.RowCount,
[CheckedStr, StatusStr, TrackerURL]);
end;

function TControlerTrackerListOnline.TrackerURL(index: integer): string;
begin
Result := FStringGridTorrentURL.Cells[2, index + FStringGridTorrentURL.FixedRows];
end;

function TControlerTrackerListOnline.TrackerStatus(index: integer):
TTrackerListOnlineStatus;
begin
Result := FTrackerListOnline.TrackerStatus(TrackerURL(index));
end;

function TControlerTrackerListOnline.Count: integer;
begin
Result := FStringGridTorrentURL.RowCount - FStringGridTorrentURL.FixedRows;
end;

function TControlerTrackerListOnline.StableTrackers: TStringList;
begin
Result := FNewTrackon.TrackerList_Stable;
end;

procedure TControlerTrackerListOnline.UpdateView;
var
tracker: string;
DeafultChecked: boolean;
begin
//Clear all the previeus data in the view
FStringGridTorrentURL.RowCount := FStringGridTorrentURL.FixedRows;

//the default status is is put all the checkox to true. => keep all trackers
DeafultChecked := True;

FStringGridTorrentURL.BeginUpdate;

//Show the TrackerList list in string grid view
for tracker in FTrackerList do
begin
AppendRow(DeafultChecked, FTrackerListOnline.TrackerStatus(tracker), tracker);
end;

//make sure all text are fit inside the columns
FStringGridTorrentURL.AutoSizeColumns;

FStringGridTorrentURL.EndUpdate;
end;

end.
46 changes: 41 additions & 5 deletions source/code/main.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object FormTrackerModify: TFormTrackerModify
Left = 510
Left = 1348
Height = 607
Top = 224
Top = 462
Width = 1179
AllowDropFiles = True
Caption = 'Bittorrent Tracker Editor'
Expand Down Expand Up @@ -72,15 +72,20 @@ object FormTrackerModify: TFormTrackerModify
Constraints.MinHeight = 100
ParentBidiMode = False
TabOrder = 1
object CheckListBoxTrackersList: TCheckListBox
object StringGridTrackerOnline: TStringGrid
Left = 0
Height = 335
Top = 0
Width = 1165
Align = alClient
Constraints.MinHeight = 50
ItemHeight = 0
AlternateColor = clWhite
ColCount = 0
FixedCols = 0
FixedRows = 0
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goSmoothScroll]
RowCount = 0
TabOrder = 0
TitleFont.Height = -11
end
end
object Splitter1: TSplitter
Expand Down Expand Up @@ -288,6 +293,26 @@ object FormTrackerModify: TFormTrackerModify
Caption = '&Delete all the present trackers'
OnClick = MenuTrackersKeepOrDeleteAllTrackersClick
end
object MenuTrackersSeperator1: TMenuItem
Caption = '-'
end
object MenuTrackersDeleteUnstableTrackers: TMenuItem
Caption = 'Delete UNSTABLE trackers'
OnClick = MenuTrackersDeleteTrackersWithStatusClick
end
object MenuTrackersDeleteDeadTrackers: TMenuItem
Tag = 1
Caption = 'Delete DEAD trackers'
OnClick = MenuTrackersDeleteTrackersWithStatusClick
end
object MenuTrackersDeleteUnknownTrackers: TMenuItem
Tag = 2
Caption = 'Delete UNKNOWN trackers'
OnClick = MenuTrackersDeleteTrackersWithStatusClick
end
object MenuTrackersSeperator2: TMenuItem
Caption = '-'
end
object MenuTrackersAllTorrentArePublic: TMenuItem
Tag = 1
Caption = 'All torrent are &public'
Expand Down Expand Up @@ -340,6 +365,17 @@ object FormTrackerModify: TFormTrackerModify
OnClick = MenuUpdateRandomizeClick
end
end
object MenuOnlineCheck: TMenuItem
Caption = 'Online Check'
object MenuItemOnlineCheckDownloadNewTrackon: TMenuItem
Caption = 'Check Status Trackers (From newTrackon)'
OnClick = MenuItemOnlineCheckDownloadNewTrackonClick
end
object MenuItemOnlineCheckAppendStableTrackers: TMenuItem
Caption = 'Append Stable Trackers (From newTrackon)'
OnClick = MenuItemOnlineCheckAppendStableTrackersClick
end
end
object MenuHelp: TMenuItem
Caption = '&Help'
object MenuHelpVisitWebsite: TMenuItem
Expand Down
Loading

0 comments on commit 5d2ec98

Please sign in to comment.