Skip to content

Commit 66e5e4d

Browse files
[Issue GerryFerdinandus#21] Verify status of public trackers.
Add new TStringGrid view with column for keep, status and trackerURL This new TStringGrid is replacing the 'simple' TCheckListBox list. [ci skip]
1 parent 5c9f940 commit 66e5e4d

File tree

7 files changed

+486
-59
lines changed

7 files changed

+486
-59
lines changed
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
unit controler_trackerlist_online;
2+
3+
{
4+
Show the present status of the trackerURL via TStringGrid
5+
}
6+
{$mode objfpc}{$H+}
7+
8+
interface
9+
10+
uses
11+
Classes, SysUtils, Grids, trackerlist_online, newtrackon;
12+
13+
type
14+
15+
{ TControlerTrackerListOnline }
16+
17+
TControlerTrackerListOnline = class
18+
private
19+
FStringGridTorrentURL: TStringGrid;
20+
FNewTrackon: TNewTrackon;
21+
FTrackerListOnline: TTrackerListOnline;
22+
FTrackerList: TStringList;
23+
24+
//The collumn must be in this design order.
25+
FSelect, //< 0
26+
FTorrentURL, //< 1
27+
FTorrentURL_Status //< 2
28+
: TGridColumn;
29+
30+
function GetChecked(index: integer): boolean;
31+
procedure SetChecked(index: integer; AValue: boolean);
32+
procedure ShowTrackerStatus(Visible: boolean);
33+
procedure AppendRow(Checked: boolean; Status: TTrackerListOnlineStatus;
34+
const TrackerURL: UTF8String);
35+
public
36+
37+
property Checked[index: integer]: boolean read GetChecked write SetChecked;
38+
function TrackerURL(index: integer): string;
39+
function TrackerStatus(index: integer): TTrackerListOnlineStatus;
40+
function Count: integer;
41+
function StableTrackers: TStringList;
42+
43+
//must be called if the tracker list is updated
44+
procedure UpdateView;
45+
46+
function DownloadTrackers: boolean;
47+
48+
constructor Create(StringGridTorrentURL: TStringGrid; TrackerList: TStringList);
49+
destructor Destroy; override;
50+
end;
51+
52+
53+
implementation
54+
55+
uses Graphics;
56+
57+
{ TControlerTrackerListOnline }
58+
59+
60+
function TControlerTrackerListOnline.DownloadTrackers: boolean;
61+
begin
62+
Result := FNewTrackon.DownloadTrackers;
63+
UpdateView;
64+
ShowTrackerStatus(Result);
65+
end;
66+
67+
constructor TControlerTrackerListOnline.Create(StringGridTorrentURL: TStringGrid;
68+
TrackerList: TStringList);
69+
begin
70+
71+
FTrackerList := TrackerList;
72+
73+
FStringGridTorrentURL := StringGridTorrentURL;
74+
FStringGridTorrentURL.RowCount := 1;
75+
FStringGridTorrentURL.FixedRows := 1;
76+
FStringGridTorrentURL.AlternateColor := clCream;
77+
78+
FSelect := FStringGridTorrentURL.Columns.Add;
79+
FSelect.Title.Caption := 'Keep';
80+
FSelect.ButtonStyle := cbsCheckboxColumn;
81+
FSelect.ReadOnly := False;
82+
83+
84+
FTorrentURL_Status := FStringGridTorrentURL.Columns.Add;
85+
FTorrentURL_Status.Title.Caption := 'Online status';
86+
ShowTrackerStatus(False);
87+
FTorrentURL_Status.ReadOnly := True;
88+
89+
FTorrentURL := FStringGridTorrentURL.Columns.Add;
90+
FTorrentURL.Title.Caption := 'Tracker URL';
91+
FTorrentURL.ReadOnly := True;
92+
93+
//make sure all text are fit inside the columns
94+
FStringGridTorrentURL.AutoSizeColumns;
95+
96+
FNewTrackon := TNewTrackon.Create;
97+
FTrackerListOnline := TTrackerListOnline.Create;
98+
99+
//copy tracker list from TNewTrackon to TTrackerListOnline
100+
FTrackerListOnline.TrackerList_Live := FNewTrackon.TrackerList_Live;
101+
FTrackerListOnline.TrackerList_Dead := FNewTrackon.TrackerList_Dead;
102+
FTrackerListOnline.TrackerList_Stable := FNewTrackon.TrackerList_Stable;
103+
end;
104+
105+
destructor TControlerTrackerListOnline.Destroy;
106+
begin
107+
FTrackerListOnline.Free;
108+
FNewTrackon.Free;
109+
inherited Destroy;
110+
end;
111+
112+
procedure TControlerTrackerListOnline.ShowTrackerStatus(Visible: boolean);
113+
begin
114+
FTorrentURL_Status.Visible := Visible;
115+
end;
116+
117+
function TControlerTrackerListOnline.GetChecked(index: integer): boolean;
118+
begin
119+
//read the select checkbox. If '1' then it is True
120+
Result := FStringGridTorrentURL.Cells[0, index +
121+
FStringGridTorrentURL.FixedRows] = '1';
122+
end;
123+
124+
procedure TControlerTrackerListOnline.SetChecked(index: integer; AValue: boolean);
125+
begin
126+
FStringGridTorrentURL.Cells[0, index + FStringGridTorrentURL.FixedRows] :=
127+
BoolToStr(AValue, '1', '0');
128+
end;
129+
130+
131+
procedure TControlerTrackerListOnline.AppendRow(Checked: boolean;
132+
Status: TTrackerListOnlineStatus; const TrackerURL: UTF8String);
133+
var
134+
CheckedStr, StatusStr: string;
135+
begin
136+
CheckedStr := BoolToStr(Checked, '1', '0');
137+
StatusStr := FTrackerListOnline.TrackerListOnlineStatusToString(Status);
138+
139+
//append to the end of the view list
140+
FStringGridTorrentURL.InsertRowWithValues(FStringGridTorrentURL.RowCount,
141+
[CheckedStr, StatusStr, TrackerURL]);
142+
end;
143+
144+
function TControlerTrackerListOnline.TrackerURL(index: integer): string;
145+
begin
146+
Result := FStringGridTorrentURL.Cells[2, index + FStringGridTorrentURL.FixedRows];
147+
end;
148+
149+
function TControlerTrackerListOnline.TrackerStatus(index: integer):
150+
TTrackerListOnlineStatus;
151+
begin
152+
Result := FTrackerListOnline.TrackerStatus(TrackerURL(index));
153+
end;
154+
155+
function TControlerTrackerListOnline.Count: integer;
156+
begin
157+
Result := FStringGridTorrentURL.RowCount - FStringGridTorrentURL.FixedRows;
158+
end;
159+
160+
function TControlerTrackerListOnline.StableTrackers: TStringList;
161+
begin
162+
Result := FNewTrackon.TrackerList_Stable;
163+
end;
164+
165+
procedure TControlerTrackerListOnline.UpdateView;
166+
var
167+
tracker: string;
168+
DeafultChecked: boolean;
169+
begin
170+
//Clear all the previeus data in the view
171+
FStringGridTorrentURL.RowCount := FStringGridTorrentURL.FixedRows;
172+
173+
//the default status is is put all the checkox to true. => keep all trackers
174+
DeafultChecked := True;
175+
176+
FStringGridTorrentURL.BeginUpdate;
177+
178+
//Show the TrackerList list in string grid view
179+
for tracker in FTrackerList do
180+
begin
181+
AppendRow(DeafultChecked, FTrackerListOnline.TrackerStatus(tracker), tracker);
182+
end;
183+
184+
//make sure all text are fit inside the columns
185+
FStringGridTorrentURL.AutoSizeColumns;
186+
187+
FStringGridTorrentURL.EndUpdate;
188+
end;
189+
190+
end.

source/code/main.lfm

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object FormTrackerModify: TFormTrackerModify
2-
Left = 510
2+
Left = 1348
33
Height = 607
4-
Top = 224
4+
Top = 462
55
Width = 1179
66
AllowDropFiles = True
77
Caption = 'Bittorrent Tracker Editor'
@@ -72,15 +72,20 @@ object FormTrackerModify: TFormTrackerModify
7272
Constraints.MinHeight = 100
7373
ParentBidiMode = False
7474
TabOrder = 1
75-
object CheckListBoxTrackersList: TCheckListBox
75+
object StringGridTrackerOnline: TStringGrid
7676
Left = 0
7777
Height = 335
7878
Top = 0
7979
Width = 1165
8080
Align = alClient
81-
Constraints.MinHeight = 50
82-
ItemHeight = 0
81+
AlternateColor = clWhite
82+
ColCount = 0
83+
FixedCols = 0
84+
FixedRows = 0
85+
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goSmoothScroll]
86+
RowCount = 0
8387
TabOrder = 0
88+
TitleFont.Height = -11
8489
end
8590
end
8691
object Splitter1: TSplitter
@@ -288,6 +293,26 @@ object FormTrackerModify: TFormTrackerModify
288293
Caption = '&Delete all the present trackers'
289294
OnClick = MenuTrackersKeepOrDeleteAllTrackersClick
290295
end
296+
object MenuTrackersSeperator1: TMenuItem
297+
Caption = '-'
298+
end
299+
object MenuTrackersDeleteUnstableTrackers: TMenuItem
300+
Caption = 'Delete UNSTABLE trackers'
301+
OnClick = MenuTrackersDeleteTrackersWithStatusClick
302+
end
303+
object MenuTrackersDeleteDeadTrackers: TMenuItem
304+
Tag = 1
305+
Caption = 'Delete DEAD trackers'
306+
OnClick = MenuTrackersDeleteTrackersWithStatusClick
307+
end
308+
object MenuTrackersDeleteUnknownTrackers: TMenuItem
309+
Tag = 2
310+
Caption = 'Delete UNKNOWN trackers'
311+
OnClick = MenuTrackersDeleteTrackersWithStatusClick
312+
end
313+
object MenuTrackersSeperator2: TMenuItem
314+
Caption = '-'
315+
end
291316
object MenuTrackersAllTorrentArePublic: TMenuItem
292317
Tag = 1
293318
Caption = 'All torrent are &public'
@@ -340,6 +365,17 @@ object FormTrackerModify: TFormTrackerModify
340365
OnClick = MenuUpdateRandomizeClick
341366
end
342367
end
368+
object MenuOnlineCheck: TMenuItem
369+
Caption = 'Online Check'
370+
object MenuItemOnlineCheckDownloadNewTrackon: TMenuItem
371+
Caption = 'Check Status Trackers (From newTrackon)'
372+
OnClick = MenuItemOnlineCheckDownloadNewTrackonClick
373+
end
374+
object MenuItemOnlineCheckAppendStableTrackers: TMenuItem
375+
Caption = 'Append Stable Trackers (From newTrackon)'
376+
OnClick = MenuItemOnlineCheckAppendStableTrackersClick
377+
end
378+
end
343379
object MenuHelp: TMenuItem
344380
Caption = '&Help'
345381
object MenuHelpVisitWebsite: TMenuItem

0 commit comments

Comments
 (0)