-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.pas
313 lines (279 loc) · 8.87 KB
/
options.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
{*************************************************************************************
This file is part of Transmission Remote GUI.
Copyright (c) 2008-2014 by Yury Sidorov.
Transmission Remote GUI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Transmission Remote GUI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Transmission Remote GUI; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*************************************************************************************}
unit Options;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls, Spin, Buttons, ButtonPanel, BaseForm,
ConnOptions;
type
{ TOptionsForm }
TOptionsForm = class(TBaseForm)
Buttons: TButtonPanel;
cbDeleteTorrentFile: TCheckBox;
cbLanguage: TComboBox;
cbLinksFromClipboard: TCheckBox;
cbShowAddTorrentWindow: TCheckBox;
cbTrayClose: TCheckBox;
cbTrayIconAlways: TCheckBox;
cbTrayMinimize: TCheckBox;
cbCheckNewVersion: TCheckBox;
cbCalcAvg: TCheckBox;
cbRegExt: TCheckBox;
cbRegMagnet: TCheckBox;
cbTrayNotify: TCheckBox;
edIntfScale: TSpinEdit;
edCheckVersionDays: TSpinEdit;
edRefreshInterval: TSpinEdit;
edRefreshIntervalMin: TSpinEdit;
gbTray: TGroupBox;
gbNewTorrent: TGroupBox;
gbData: TGroupBox;
gbSysInt: TGroupBox;
txDays: TLabel;
tabGeneral: TTabSheet;
txPerc: TLabel;
Page: TPageControl;
tabAdvanced: TTabSheet;
txLanguage: TLabel;
txIntfScale: TLabel;
txRefreshInterval: TLabel;
txRefreshIntervalMin: TLabel;
txSeconds: TLabel;
txSeconds2: TLabel;
procedure cbCheckNewVersionClick(Sender: TObject);
procedure cbLanguageEnter(Sender: TObject);
procedure cbLanguageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure cbLanguageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure OKButtonClick(Sender: TObject);
private
FLangList: TStringList;
{$ifdef mswindows}
FRegExt: boolean;
FRegMagnet: boolean;
{$endif mswindows}
procedure FillLanguageItems;
public
ConnForm: TConnOptionsForm;
end;
implementation
uses
{$ifdef mswindows}
registry,
{$endif mswindows}
main, utils, ResTranslator;
{ TOptionsForm }
procedure TOptionsForm.FormCreate(Sender: TObject);
var
i: integer;
pg: TTabSheet;
{$ifdef mswindows}
reg: TRegistry;
s: string;
{$endif mswindows}
begin
cbRegExt.Caption:=Format(cbRegExt.Caption, [AppName]);
cbRegMagnet.Caption:=Format(cbRegMagnet.Caption, [AppName]);
ConnForm:=TConnOptionsForm.Create(Self);
while ConnForm.Page.ControlCount > 0 do begin
pg:=ConnForm.Page.Pages[0];
pg.Parent:=Page;
pg.TabVisible:=True;
end;
ConnForm.Page.Free;
ConnForm.Page:=Page;
Page.ActivePageIndex:=0;
Buttons.OKButton.ModalResult:=mrNone;
Buttons.OKButton.OnClick:=@OKButtonClick;
cbLanguage.Items.Add(FTranslationLanguage);
cbLanguage.ItemIndex:=0;
i:=80*100 div (ScaleInt(100)*100 div IntfScale);
i:=i - i mod 5;
if i < 10 then
i:=10;
edIntfScale.MinValue:=i;
{$ifdef LCLgtk2}
cbLanguage.OnDropDown:=@cbLanguageEnter;
cbLanguage.OnMouseMove:=@cbLanguageMouseMove;
{$endif LCLgtk2}
{$ifdef mswindows}
gbSysInt.Visible:=True;
reg:=TRegistry.Create;
try
if reg.OpenKeyReadOnly('Software\Classes\.torrent') then begin
if reg.ReadString('') = AppName then begin
reg.CloseKey;
if reg.OpenKeyReadOnly(Format('Software\Classes\%s\shell\open\command', [AppName])) then begin
s:=reg.ReadString('');
FRegExt:=CompareFilePath(s, Format('"%s" "%%1"', [ParamStr(0)])) = 0;
end;
end;
end;
reg.CloseKey;
if reg.OpenKeyReadOnly('Software\Classes\Magnet\shell\open\command') then begin
s:=reg.ReadString('');
FRegMagnet:=CompareFilePath(s, Format('"%s" "%%1"', [ParamStr(0)])) = 0;
end;
finally
reg.Free;
end;
cbRegExt.Checked:=FRegExt;
cbRegMagnet.Checked:=FRegMagnet;
{$endif mswindows}
end;
procedure TOptionsForm.cbLanguageEnter(Sender: TObject);
begin
if not Assigned(FLangList) then
FillLanguageItems;
end;
procedure TOptionsForm.cbCheckNewVersionClick(Sender: TObject);
begin
edCheckVersionDays.Enabled:=cbCheckNewVersion.Checked;
end;
procedure TOptionsForm.cbLanguageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
cbLanguageEnter(cbLanguage);
end;
procedure TOptionsForm.cbLanguageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
cbLanguageEnter(cbLanguage);
end;
procedure TOptionsForm.FillLanguageItems;
var
i: integer;
begin
AppBusy;
cbLanguage.Items.BeginUpdate;
try
cbLanguage.Items.Clear;
cbLanguage.Items.Add('English');
FLangList := GetAvailableTranslations;
FLangList.Sort;
with FLangList do
for i := 0 to Count - 1 do
cbLanguage.Items.Add(Names[i]);
with cbLanguage do
ItemIndex:= Items.IndexOf(FTranslationLanguage);
finally
cbLanguage.Items.EndUpdate;
end;
AppNormal;
end;
procedure TOptionsForm.FormDestroy(Sender: TObject);
begin
FLangList.Free;
end;
procedure TOptionsForm.FormShow(Sender: TObject);
begin
ConnForm.FormShow(nil);
if ConnForm.edHost.Text = '' then begin
tabGeneral.Hide;
ActiveControl:=ConnForm.edHost;
end;
end;
procedure TOptionsForm.OKButtonClick(Sender: TObject);
var
s: string;
restart: boolean;
{$ifdef mswindows}
reg: TRegistry;
{$endif mswindows}
begin
ConnForm.ModalResult:=mrNone;
ConnForm.btOKClick(nil);
if ConnForm.ModalResult = mrNone then
exit;
restart:=False;
if cbLanguage.Text <> FTranslationLanguage then begin
if cbLanguage.Text = 'English' then
s:='-'
else
s:=FLangList.Values[cbLanguage.Text];
Ini.WriteString('Interface', 'TranslationFile', s);
restart:=True;
end;
{$ifdef mswindows}
reg:=TRegistry.Create;
try
if cbRegExt.Checked <> FRegExt then
if cbRegExt.Checked then begin
if reg.OpenKey('Software\Classes\.torrent', True) then begin
reg.WriteString('', AppName);
reg.CloseKey;
if reg.OpenKey(Format('Software\Classes\%s\DefaultIcon', [AppName]), True) then begin
reg.WriteString('', Format('"%s",0', [ParamStr(0)]));
reg.CloseKey;
if reg.OpenKey(Format('Software\Classes\%s\shell\open\command', [AppName]), True) then begin
reg.WriteString('', Format('"%s" "%%1"', [ParamStr(0)]));
reg.CloseKey;
end;
end;
end;
end
else begin
if reg.OpenKey('Software\Classes\.torrent', False) then begin
reg.DeleteValue('');
reg.CloseKey;
end;
s:=Format('Software\Classes\%s', [AppName]);
reg.DeleteKey(s + '\DefaultIcon');
reg.DeleteKey(s + '\shell\open\command');
reg.DeleteKey(s + '\shell\open');
reg.DeleteKey(s + '\shell');
reg.DeleteKey(s);
end;
if cbRegMagnet.Checked <> FRegMagnet then
if cbRegMagnet.Checked then begin
if reg.OpenKey('Software\Classes\Magnet', True) then begin
if not reg.ValueExists('') then
reg.WriteString('', 'Magnet URI');
reg.WriteString('Content Type', 'application/x-magnet');
reg.WriteString('URL Protocol', '');
reg.CloseKey;
if reg.OpenKey('Software\Classes\Magnet\DefaultIcon', True) then begin
reg.WriteString('', Format('"%s",0', [ParamStr(0)]));
reg.CloseKey;
if reg.OpenKey('Software\Classes\Magnet\shell', True) then begin
reg.WriteString('', 'open');
reg.CloseKey;
if reg.OpenKey('Software\Classes\Magnet\shell\open\command', True) then begin
reg.WriteString('', Format('"%s" "%%1"', [ParamStr(0)]));
reg.CloseKey;
end;
end;
end;
end;
end
else begin
reg.DeleteKey('Software\Classes\Magnet\DefaultIcon');
reg.DeleteKey('Software\Classes\Magnet\shell\open\command');
end;
finally
reg.Free;
end;
{$endif mswindows}
if edIntfScale.Value <> IntfScale then
restart:=True;
if restart then
MessageDlg(sRestartRequired, mtInformation, [mbOk], 0);
ModalResult:=mrOk;
end;
initialization
{$I options.lrs}
end.