-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue #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.
- Loading branch information
1 parent
5c9f940
commit 5d2ec98
Showing
7 changed files
with
486 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.