Skip to content

Commit

Permalink
Merge pull request #1066 from transmission-remote-gui/dev
Browse files Browse the repository at this point in the history
New Feature: #1043 Implement the Display of Relative Dates/Times (to Now)
  • Loading branch information
PeterDaveHello authored Jan 19, 2018
2 parents afb6da4 + 4f3394a commit ff475f6
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 17 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ Params2={same for item 2}

[MainForm]
BigToolBarHeight=48 {Height of the Big Icon Toolbar if missing default is 64}

[MainForm]
FromNow=1 {1=Shows the dates relatives to now , 0=Absolute Dates MM/DD/YY HH:MM:SS}
```

## License
Expand Down
2 changes: 2 additions & 0 deletions lang/transgui.template
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Status bar=Status bar
%dd=%dd
%dh=%dh
%dm=%dm
%dmo=%dmo
%dy=%dy
All torrents=All torrents
Application options=Application options
Ask for password=Ask for password
Expand Down
16 changes: 12 additions & 4 deletions main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,19 @@ inherited MainForm: TMainForm
Visible = False
end
item
Alignment = taCenter
Title.Caption = 'Added on'
Width = 0
Visible = False
end
item
Alignment = taCenter
Title.Caption = 'Completed on'
Width = 0
Visible = False
end
item
Alignment = taCenter
Title.Caption = 'Last active'
Width = 0
Visible = False
Expand Down Expand Up @@ -315,6 +318,7 @@ inherited MainForm: TMainForm
TabOrder = 0
OnClick = gTorrentsClick
OnDblClick = gTorrentsDblClick
OnMouseMove = gTorrentsMouseMove
OnMouseUp = gTorrentsMouseUp
OnResize = gTorrentsResize
OnSetEditText = gTorrentsSetEditText
Expand Down Expand Up @@ -406,6 +410,8 @@ inherited MainForm: TMainForm
ChildSizing.ControlsPerLine = 4
ClientHeight = 120
ClientWidth = 852
ParentShowHint = False
ShowHint = True
TabOrder = 0
object txTorrentNameLabel: TLabel
Left = 4
Expand Down Expand Up @@ -574,6 +580,8 @@ inherited MainForm: TMainForm
ChildSizing.ControlsPerLine = 6
ClientHeight = 111
ClientWidth = 852
ParentShowHint = False
ShowHint = True
TabOrder = 1
object txStatusLabel: TLabel
Left = 4
Expand Down Expand Up @@ -1041,14 +1049,14 @@ inherited MainForm: TMainForm
end
object tabFiles: TTabSheet
Caption = 'Files'
ClientHeight = 558
ClientWidth = 1544
ClientHeight = 298
ClientWidth = 873
ImageIndex = 7
object lvFiles: TVarGrid
Left = 0
Height = 279
Height = 298
Top = 0
Width = 772
Width = 873
Align = alClient
Columns = <
item
Expand Down
85 changes: 72 additions & 13 deletions main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ interface
sMins = '%dm';
sHours = '%dh';
sDays = '%dd';
sMonths = '%dmo';
sYears = '%dy';
sDownloadingSeeding = '%s%s%d downloading, %d seeding%s%s, %s';
sDownSpeed = 'D: %s/s';
sUpSpeed = 'U: %s/s';
Expand Down Expand Up @@ -552,6 +554,8 @@ TMainForm = class(TBaseForm)
procedure acStatusBarSizesExecute(Sender: TObject);
procedure acStopAllTorrentsExecute(Sender: TObject);
procedure acStopTorrentExecute(Sender: TObject);
procedure gTorrentsMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure gTorrentsMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure lvFilesMouseUp(Sender: TObject; Button: TMouseButton;
Expand Down Expand Up @@ -647,6 +651,9 @@ TMainForm = class(TBaseForm)
FLinksFromClipboard: boolean;
FLastClipboardLink: string;
FLinuxOpenDoc: integer;
FFromNow: boolean;
FRow: integer;
FCol: integer;
{$ifdef windows}
FFileManagerDefault: string;
FFileManagerDefaultParam: string;
Expand Down Expand Up @@ -695,7 +702,7 @@ TMainForm = class(TBaseForm)
function GetSeedsText(Seeds, SeedsTotal: integer): string;
function GetPeersText(Peers, PeersTotal, Leechers: integer): string;
function RatioToString(Ratio: double): string;
function TorrentDateTimeToString(d: Int64): string;
function TorrentDateTimeToString(d: Int64; FromNow:Boolean = false): string;
procedure DoRefresh(All: boolean = False);
function GetFilesCommonPath(files: TJSONArray): string;
procedure InternalRemoveTorrent(const Msg, MsgMulti: string; RemoveLocalData: boolean);
Expand Down Expand Up @@ -1391,7 +1398,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
i, j: integer;
R: TRect;
SL: TStringList;
miUserFiles, miUserTorrents, MI, MI2: TMenuItem;
MI, MI2: TMenuItem;
Ico: TIcon;
LargeIco, SmallIco : hIcon;
MenuCaption: String;
Expand Down Expand Up @@ -1552,7 +1559,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
if Ini.ReadBool('MainForm', 'BigToolbar', acBigToolBar.Checked) <> acBigToolBar.Checked then
acBigToolbar.Execute;


FFromNow := Ini.ReadBool('MainForm','FromNow',false);
LoadColumns(gTorrents, 'TorrentsList');
TorrentColumnsChanged;
LoadColumns(lvFiles, 'FilesList');
Expand Down Expand Up @@ -2003,8 +2010,6 @@ procedure TMainForm.acOpenContainingFolderExecute(Sender: TObject);

procedure TMainForm.acOpenFileExecute(Sender: TObject);
var UserDef: boolean;
i: integer;
s: string;
begin
if gTorrents.Items.Count = 0 then
exit;
Expand Down Expand Up @@ -3039,12 +3044,39 @@ function TMainForm.RatioToString(Ratio: double): string;
Result:=Format('%.3f', [Ratio]);
end;

function TMainForm.TorrentDateTimeToString(d: Int64): string;
function HumanReadableTime(ANow,AThen: TDateTime): string;
var
Years, Months, Days, Hours, Minutes, Seconds, Discard: Word;
begin
Try
PeriodBetween(ANow,AThen,Years,Months,Days);
DecodeDateTime(Anow-AThen,discard,Discard,Discard,Hours,Minutes,Seconds,Discard);
if Years > 0 then begin
Result := Format(sYears,[Years]) + ' ' + Format(sMonths,[Months]);
end else if Months > 0 then begin
Result := Format(sMonths,[Months]) + ' ' + Format(sDays,[Days]);
end else if Days > 0 then begin
Result := Format(sDays,[Days]) + ' ' + Format(sHours,[Hours]);
end else if Hours > 0 then begin
Result := Format(sHours,[Hours]) + ' ' + Format(sMins,[Minutes]);
end else if Minutes > 0 then begin
Result := Format(sMins,[Minutes]) + ' ' + Format(sSecs,[Seconds]);
end else begin
Result := Format(sSecs,[Seconds])
end;
Except
Result := 'An Eternity';
End;
end;

function TMainForm.TorrentDateTimeToString(d: Int64; FromNow: Boolean): string;
begin
if d = 0 then
Result:=''
else
Result:=DateTimeToStr(UnixToDateTime(d) + GetTimeZoneDelta);
if FromNow then
Result := HumanReadableTime(Now,UnixToDateTime(d) + GetTimeZoneDelta) else
Result:=DateTimeToStr(UnixToDateTime(d) + GetTimeZoneDelta);
end;

procedure TMainForm.DoRefresh(All: boolean);
Expand Down Expand Up @@ -3617,6 +3649,28 @@ procedure TMainForm.acStopTorrentExecute(Sender: TObject);
TorrentAction(GetSelectedTorrents, 'torrent-stop');
end;

procedure TMainForm.gTorrentsMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var r, c, ADatacol: integer;
begin
gTorrents.MouseToCell(x, y, c, r);
if c>= 0 then ADataCol := gTorrents.ColToDataCol(c);
if r = 0 then gTorrents.Hint:='';
if (ADataCol <> FCol) or (r <> FRow) then
begin
FCol := ADataCol;
FRow := r;
case ADataCol of
idxAddedOn, idxCompletedOn, idxLastActive:
begin
Application.CancelHint;
gTorrents.Hint := TorrentDateTimeToString(gTorrents.Items[ADataCol, FRow-1],not(FFromNow));
end
else gTorrents.Hint:='';
end;
end;
end;

procedure TMainForm.gTorrentsMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Expand Down Expand Up @@ -4142,7 +4196,7 @@ procedure TMainForm.gTorrentsCellAttributes(Sender: TVarGrid; ACol, ARow, ADataC
idxRatio:
Text:=RatioToString(Sender.Items[idxRatio, ARow]);
idxAddedOn, idxCompletedOn, idxLastActive:
Text:=TorrentDateTimeToString(Sender.Items[ADataCol, ARow]);
Text:=TorrentDateTimeToString(Sender.Items[ADataCol, ARow],FFromNow);
idxPriority:
Text:=PriorityToStr(Sender.Items[ADataCol, ARow], ImageIndex);
idxQueuePos:
Expand Down Expand Up @@ -6271,8 +6325,9 @@ procedure TMainForm.FillGeneralInfo(t: TJSONObject);
if f = 1 then
s:=sUpdating
else
s:=DateTimeToStr(UnixToDateTime(Trunc(f)) + GetTimeZoneDelta);
s:=TorrentDateTimeToString(Trunc(f),FFromNow);
txTrackerUpdate.Caption:=s;
txTrackerUpdate.Hint:=TorrentDateTimeToString(Trunc(f),not(FFromNow));
txTracker.Caption:=UTF8Encode(widestring(gTorrents.Items[idxTracker, idx]));
if RpcObj.RPCVersion >= 7 then
if t.Arrays['trackerStats'].Count > 0 then
Expand All @@ -6295,7 +6350,8 @@ procedure TMainForm.FillGeneralInfo(t: TJSONObject);
s:=StringReplace(s, '/', ' ' + sOf + ' ', []);
txPeers.Caption:=StringReplace(s, ')', ' '+ sInSwarm+ ')', []);
txMaxPeers.Caption:=t.Strings['maxConnectedPeers'];
txLastActive.Caption:=TorrentDateTimeToString(Trunc(t.Floats['activityDate']));
txLastActive.Caption:=TorrentDateTimeToString(Trunc(t.Floats['activityDate']),FFromNow);
txLastActive.Hint:=TorrentDateTimeToString(Trunc(t.Floats['activityDate']),Not(FFromNow));
panTransfer.ChildSizing.Layout:=cclLeftToRightThenTopToBottom;

if RpcObj.RPCVersion >= 7 then
Expand All @@ -6311,7 +6367,8 @@ procedure TMainForm.FillGeneralInfo(t: TJSONObject);
s:=Trim(UTF8Encode(t.Strings['creator']));
if s <> '' then
s:=' by ' + s;
txCreated.Caption:=TorrentDateTimeToString(Trunc(t.Floats['dateCreated'])) + s;
txCreated.Caption:=TorrentDateTimeToString(Trunc(t.Floats['dateCreated']),FFromNow) + s;
txCreated.Hint :=TorrentDateTimeToString(Trunc(t.Floats['dateCreated']),Not(FFromNow)) + s;
if gTorrents.Items[idxSize, idx] >= 0 then begin
txTotalSize.Caption:=Format(sDone, [GetHumanSize(t.Floats['totalSize']), GetHumanSize(t.Floats['sizeWhenDone'] - t.Floats['leftUntilDone'])]);
if t.Floats['totalSize'] = t.Floats['haveValid'] then
Expand Down Expand Up @@ -6344,8 +6401,10 @@ procedure TMainForm.FillGeneralInfo(t: TJSONObject);
txComment.ParentFont:=True;
end;
end;
txAddedOn.Caption:=TorrentDateTimeToString(Trunc(t.Floats['addedDate']));
txCompletedOn.Caption:=TorrentDateTimeToString(Trunc(t.Floats['doneDate']));
txAddedOn.Caption:=TorrentDateTimeToString(Trunc(t.Floats['addedDate']),FFromNow);
txAddedOn.Hint:=TorrentDateTimeToString(Trunc(t.Floats['addedDate']),Not(FFromNow));
txCompletedOn.Caption:=TorrentDateTimeToString(Trunc(t.Floats['doneDate']),FFromNow);
txCompletedOn.Hint:=TorrentDateTimeToString(Trunc(t.Floats['doneDate']),Not(FFromNow));
panGeneralInfo.ChildSizing.Layout:=cclLeftToRightThenTopToBottom;
DetailsUpdated;
end;
Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ Params2={same for item 2}
[MainForm]
BigToolBarHeight=48 {Height of the Big Icon Toolbar if missing default is 64}

[MainForm]
FromNow=1 {1=Shows the dates relatives to now , 0=Absolute Dates MM/DD/YY HH:MM:SS}
*********************************************************************************
Big Icons

Expand Down

0 comments on commit ff475f6

Please sign in to comment.