Skip to content

Commit

Permalink
New Feature: #1070 Local Folder Watch
Browse files Browse the repository at this point in the history
Adding the new feature of scan a LOCAL folder for .torrent files and automatically add to the Transmission Daemon
  • Loading branch information
antekgla committed Feb 13, 2018
1 parent bb79014 commit d7bff3e
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ If the program finds the transgui.ini file in the same folder as the binary file
## Advanced parameters

There are some parameters in the `transgui.ini file`, that can not be modified via the GUI.
More info on: [#924](https://github.com/transmission-remote-gui/transgui/issues/924) (File Manager & Shortcuts) and [#1020](https://github.com/transmission-remote-gui/transgui/issues/1020) (User Defined Menu *Windows Only*)
More info on: [#924](https://github.com/transmission-remote-gui/transgui/issues/924) (File Manager & Shortcuts) , [#1020](https://github.com/transmission-remote-gui/transgui/issues/1020) (User Defined Menu *Windows Only*) and [#1070](https://github.com/transmission-remote-gui/transgui/issues/1070) (.torrent Auto Opening)

```ini
[Interface]
Expand All @@ -153,6 +153,11 @@ FileManagerDefaultParam={Alternate parameters, could be left blank}
GlobalHotkey={Virtual Key Code} full list here http://docwiki.embarcadero.com/RADStudio/Seattle/en/Virtual_Key_Codes (Plus VK_A...VK_Z and VK_0..VK_9)
GlobalHotkeyMod={Modifier Key} [MOD_SHIFT , MOD_CONTROL , MOD_ALT , MOD_WIN alone or combined with + sign]

[Interface]
WatchLocalFolder= {LOCAL Folder to watch for torrent files}
WatchDestinationFolder= {REMOTE destination where the data would be saved if missing or empty last destination folder is used}
WatchInterval=1 {Time period in MINUTES between folder scans for torrents, may be fractional values 0,50 = 30 seconds}

[Shortcuts]
;Modify all the shortcuts of the GUI here

Expand Down
13 changes: 12 additions & 1 deletion main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,6 @@ inherited MainForm: TMainForm
AutoSize = True
BorderSpacing.Bottom = 2
ButtonHeight = 23
ButtonWidth = 23
Caption = 'MainToolBar'
Images = ImageList16
Indent = 4
Expand All @@ -1185,6 +1184,7 @@ inherited MainForm: TMainForm
Left = 225
Height = 23
Top = 2
Width = 5
Caption = 'ToolButton2'
Style = tbsDivider
end
Expand Down Expand Up @@ -1213,13 +1213,15 @@ inherited MainForm: TMainForm
Left = 174
Height = 23
Top = 2
Width = 5
Caption = 'ToolButton6'
Style = tbsDivider
end
object ToolButton7: TToolButton
Left = 378
Height = 23
Top = 2
Width = 5
Caption = 'ToolButton7'
Style = tbsDivider
end
Expand Down Expand Up @@ -1256,13 +1258,15 @@ inherited MainForm: TMainForm
Left = 350
Height = 23
Top = 2
Width = 5
Caption = 'sepAltSpeed'
Style = tbsDivider
end
object sepQueue: TToolButton
Left = 299
Height = 23
Top = 2
Width = 5
Caption = 'sepQueue'
Style = tbsDivider
end
Expand Down Expand Up @@ -10618,4 +10622,11 @@ inherited MainForm: TMainForm
0000000000000000000000000000
}
end
object LocalWatchTimer: TTimer[31]
Enabled = False
Interval = 60000
OnTimer = LocalWatchTimerTimer
left = 40
top = 136
end
end
45 changes: 43 additions & 2 deletions main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ TMainForm = class(TBaseForm)
MenuItem502: TMenuItem;
SearchToolbar: TToolBar;
tbSearchCancel: TToolButton;
LocalWatchTimer: TTimer;
txMagLabel: TLabel;
txMagnetLink: TEdit;
MenuItem101: TMenuItem;
Expand Down Expand Up @@ -558,6 +559,7 @@ TMainForm = class(TBaseForm)
Y: Integer);
procedure gTorrentsMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure LocalWatchTimerTimer(Sender: TObject);
procedure lvFilesMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MenuShowExecute(Sender: TObject);
Expand Down Expand Up @@ -652,6 +654,9 @@ TMainForm = class(TBaseForm)
FLastClipboardLink: string;
FLinuxOpenDoc: integer;
FFromNow: boolean;
FWatchLocalFolder: string;
FWatchDestinationFolder: string;
FWatchDownloading: boolean;
FRow: integer;
FCol: integer;
{$ifdef windows}
Expand Down Expand Up @@ -729,6 +734,7 @@ TMainForm = class(TBaseForm)
procedure CheckAddTorrents;
procedure CheckClipboardLink;
procedure CenterDetailsWait;
procedure ReadLocalFolderWatch;
function GetPageInfoType(pg: TTabSheet): TAdvInfoType;
procedure DetailsUpdated;
function RenameTorrent(TorrentId: integer; const OldPath, NewName: string): boolean;
Expand Down Expand Up @@ -930,7 +936,19 @@ function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LR

{$endif windows}


procedure TMainForm.ReadLocalFolderWatch;
var
sr: TSearchRec;
begin
if FPendingTorrents.Count = 0 then
begin
if FindFirstUTF8(FWatchLocalFolder+'*.torrent',faAnyFile,sr)=0 then
repeat
FPendingTorrents.Add(FWatchLocalFolder+sr.Name);
until FindNextUTF8(sr)<>0;
FindCloseUTF8(sr);
end;
end;

function GetHumanSize(sz: double; RoundTo: integer; const EmptyStr: string): string;
var
Expand Down Expand Up @@ -1560,6 +1578,15 @@ procedure TMainForm.FormCreate(Sender: TObject);
acBigToolbar.Execute;

FFromNow := Ini.ReadBool('MainForm','FromNow',false);
FWatchLocalFolder := Ini.ReadString('Interface','WatchLocalFolder','');
if FWatchLocalFolder <> '' then
if DirPathExists(FWatchLocalFolder) and DirectoryIsWritable(FWatchLocalFolder) then
begin
FWatchLocalFolder := AppendPathDelim(FWatchLocalFolder);
FWatchDestinationFolder := Ini.ReadString('Interface','WatchDestinationFolder','');
LocalWatchTimer.Interval:=trunc(Ini.ReadFloat('Interface','WatchInterval',1)*60000);
LocalWatchTimer.Enabled := true;
end;
LoadColumns(gTorrents, 'TorrentsList');
TorrentColumnsChanged;
LoadColumns(lvFiles, 'FilesList');
Expand Down Expand Up @@ -2489,6 +2516,7 @@ function TMainForm.DoAddTorrent(const FileName: Utf8String): boolean;

IniSec:='AddTorrent.' + FCurConn;
FillDownloadDirs(cbDestFolder, 'LastDownloadDir');
if (FWatchDownloading) and (FWatchDestinationFolder <> '') then cbDestFolder.Text:=FWatchDestinationFolder;

req:=TJSONObject.Create;
try
Expand Down Expand Up @@ -2597,6 +2625,7 @@ function TMainForm.DoAddTorrent(const FileName: Utf8String): boolean;
AppNormal;

ok:=not Ini.ReadBool('Interface', 'ShowAddTorrentWindow', True);
if FWatchDownloading then ok:= true;
if ok then
btSelectAllClick(nil)
else begin
Expand Down Expand Up @@ -2692,7 +2721,7 @@ function TMainForm.DoAddTorrent(const FileName: Utf8String): boolean;
SelectTorrent(id, 2000);

id:=0;
if Ini.ReadBool('Interface', 'DeleteTorrentFile', False) and not IsProtocolSupported(FileName) then
if (Ini.ReadBool('Interface', 'DeleteTorrentFile', False) and not IsProtocolSupported(FileName)) or (FWatchDownloading) then
DeleteFileUTF8(FileName);

Ini.WriteInteger(IniSec, 'PeerLimit', edPeerLimit.Value);
Expand Down Expand Up @@ -3677,6 +3706,17 @@ procedure TMainForm.gTorrentsMouseUp(Sender: TObject; Button: TMouseButton;
if Button = mbRight then pmTorrents.PopUp;
end;

procedure TMainForm.LocalWatchTimerTimer(Sender: TObject);
begin
ReadLocalFolderWatch;
if FPendingTorrents.Count > 0 then
begin
FWatchDownloading := true;
TickTimerTimer(nil);
end;
end;


procedure TMainForm.lvFilesMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Expand Down Expand Up @@ -7527,6 +7567,7 @@ procedure TMainForm.CheckAddTorrents;
finally
if WasHidden then
HideTaskbarButton;
FWatchDownloading := false;
end;
end;
finally
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ ADVANCED PARAMETERS

There are some parameters in the transgui.ini file, that can not be modified via the GUI.
More info on: https://github.com/transmission-remote-gui/transgui/issues/924 (File Manager & Shortcuts)
and https://github.com/transmission-remote-gui/transgui/issues/1020 (User Defined Menu -Windows Only-)
, https://github.com/transmission-remote-gui/transgui/issues/1020 (User Defined Menu -Windows Only-)
and https://github.com/transmission-remote-gui/transgui/issues/1070 (.torrent Auto Opening)

[Interface]
; Maximum number of elements in the folder history list
Expand All @@ -102,6 +103,12 @@ FileManagerDefaultParam={Alternate parameters, could be left blank}
GlobalHotkey={Virtual Key Code} full list here http://docwiki.embarcadero.com/RADStudio/Seattle/en/Virtual_Key_Codes (Plus VK_A...VK_Z and VK_0..VK_9)
GlobalHotkeyMod={Modifier Key} [MOD_SHIFT , MOD_CONTROL , MOD_ALT , MOD_WIN alone or combined with + sign]

[Interface]
WatchLocalFolder= {LOCAL Folder to watch for torrent files}
WatchDestinationFolder= {REMOTE destination where the data would be saved if missing or empty last destination folder is used}
WatchInterval=1 {Time period in MINUTES between folder scans for torrents, may be fractional values 0,50 = 30 seconds}


[Shortcuts]
;Modify all the shortcuts of the GUI here

Expand Down
2 changes: 1 addition & 1 deletion transgui.lpi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="10"/>
<Version Value="9"/>
<PathDelim Value="\"/>
<General>
<Flags>
Expand Down

0 comments on commit d7bff3e

Please sign in to comment.