forked from transmission-remote-gui/transgui
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconnoptionstransmissionframe.pas
199 lines (174 loc) · 7.03 KB
/
connoptionstransmissionframe.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
{*************************************************************************************
This file is part of Transmission Remote GUI.
Copyright (c) 2008-2019 by Yury Sidorov and Transmission Remote GUI working group.
Copyright (c) 2023-2024 by Daniel Kamil Kozar
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.
In addition, as a special exception, the copyright holders give permission to
link the code of portions of this program with the
OpenSSL library under certain conditions as described in each individual
source file, and distribute linked combinations including the two.
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 ConnOptionsTransmissionFrame;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, StdCtrls, Spin, Utils, Main,
synacode, Dialogs, Menus, rpc;
type
{ TConnOptionsTransmissionFrame }
TConnOptionsTransmissionFrame = class(TFrame)
cbAskPassword: TCheckBox;
cbAuth: TCheckBox;
cbAutoReconnect: TCheckBox;
cbSSL: TCheckBox;
edCertFile: TEdit;
edCertPass: TEdit;
edHost: TEdit;
edPassword: TEdit;
edPort: TSpinEdit;
edRpcPath: TEdit;
edUserName: TEdit;
txCertFile: TLabel;
txCertPass: TLabel;
txConnHelp: TLabel;
txHost: TLabel;
txPassword: TLabel;
txPort: TLabel;
txRpcPath: TLabel;
txUserName: TLabel;
procedure cbAskPasswordClick(Sender: TObject);
procedure cbAuthClick(Sender: TObject);
procedure cbSSLClick(Sender: TObject);
public
constructor Create(TheOwner: TComponent); reintroduce;
procedure LoadConnSettings(const Section: string; Ini: TIniFileUtf8);
procedure SaveConnSettings(const Section: string; Ini: TIniFileUtf8);
function IsConnSettingsChanged(const Section: string; Ini: TIniFileUtf8) : Boolean;
end;
implementation
{ TConnOptionsTransmissionFrame }
constructor TConnOptionsTransmissionFrame.Create(TheOwner: TComponent);
begin
inherited Create(Owner);
txConnHelp.Caption:=Format(txConnHelp.Caption, [Main.AppName]);
end;
procedure TConnOptionsTransmissionFrame.cbSSLClick(Sender: TObject);
begin
{$ifndef windows}
Utils.EnableControls(cbSSL.Checked, [txCertFile, edCertFile, txCertPass, edCertPass]);
{$else}
Utils.EnableControls(False, [txCertFile, edCertFile, txCertPass, edCertPass]);
{$endif windows}
end;
procedure TConnOptionsTransmissionFrame.cbAuthClick(Sender: TObject);
begin
Utils.EnableControls(cbAuth.Checked, [txUserName, edUserName, txPassword, cbAskPassword]);
cbAskPasswordClick(nil);
end;
procedure TConnOptionsTransmissionFrame.cbAskPasswordClick(Sender: TObject);
begin
Utils.EnableControls(not cbAskPassword.Checked and cbAskPassword.Enabled, [txPassword, edPassword]);
end;
procedure TConnOptionsTransmissionFrame.LoadConnSettings(const Section: string; Ini: TIniFileUtf8);
var
s: string;
begin
edHost.Text:=Ini.ReadString(Section, 'Host', '');
edPort.Value:=Ini.ReadInteger(Section, 'Port', 9091);
cbSSL.Checked:=Ini.ReadBool(Section, 'UseSSL', False);
edCertFile.Text:=Ini.ReadString(Section, 'CertFile', '');
if cbSSL.Checked then
if Ini.ReadString(Section, 'CertPass', '') <> '' then
edCertPass.Text:='******'
else
edCertPass.Text:='';
cbAutoReconnect.Checked:=Ini.ReadBool(Section, 'Autoreconnect', False);
edUserName.Text:=Ini.ReadString(Section, 'UserName', '');
s:=Ini.ReadString(Section, 'Password', '');
cbAuth.Checked:=(edUserName.Text <> '') or (s <> '');
if cbAuth.Checked then begin
cbAskPassword.Checked:=s = '-';
if not cbAskPassword.Checked then
if s <> '' then
edPassword.Text:='******'
else
edPassword.Text:='';
end;
cbAuthClick(nil);
cbSSLClick(nil);
edRpcPath.Text:=Ini.ReadString(Section, 'RpcPath', rpc.DefaultRpcPath);
end;
procedure TConnOptionsTransmissionFrame.SaveConnSettings(const Section: string; Ini: TIniFileUtf8);
var
s, ss: string;
begin
Ini.WriteString(Section, 'Host', Trim(edHost.Text));
Ini.WriteBool(Section, 'UseSSL', cbSSL.Checked);
if not cbSSL.Checked then begin
edCertFile.Text:='';
edCertPass.Text:='';
end;
Ini.WriteString(Section, 'CertFile', edCertFile.Text);
if edCertPass.Text <> '******' then begin
if edCertPass.Text = '' then
s:=''
else
s:=EncodeBase64(edCertPass.Text);
Ini.WriteString(Section, 'CertPass', s);
end;
Ini.WriteBool(Section, 'Autoreconnect', cbAutoReconnect.Checked);
Ini.WriteInteger(Section, 'Port', edPort.Value);
if not cbAuth.Checked then begin
edUserName.Text:='';
edPassword.Text:='';
cbAskPassword.Checked:=False;
end;
Ini.WriteString(Section, 'UserName', edUserName.Text);
if cbAskPassword.Checked then
Ini.WriteString(Section, 'Password', '-')
else
if edPassword.Text <> '******' then begin
ss := edPassword.Text;
if (Pos('{', ss) > 0) or (Pos('}', ss) > 0) then begin
Dialogs.MessageDlg('The password can''t contain the characters: { }', mtError, [mbOK], 0);
end;
if edPassword.Text = '' then
s:=''
else
s:=EncodeBase64(edPassword.Text);
Ini.WriteString(Section, 'Password', s);
end;
if (edRpcPath.Text = rpc.DefaultRpcPath) or (edRpcPath.Text = '') then
Ini.DeleteKey(Section, 'RpcPath')
else
Ini.WriteString(Section, 'RpcPath', edRpcPath.Text);
end;
function TConnOptionsTransmissionFrame.IsConnSettingsChanged(const Section: string; Ini: TIniFileUtf8) : Boolean;
begin
with Ini do begin
Result := (edPort.Value <> ReadInteger(Section, 'Port', 9091)) or
(edHost.Text <> ReadString(Section, 'Host', '')) or
(cbSSL.Checked <> ReadBool(Section, 'UseSSL', False)) or
(edCertFile.Text <> ReadString(Section, 'CertFile', '')) or
((ReadString(Section, 'CertPass', '') = '') and (edCertPass.Text <> '')) or
((ReadString(Section, 'CertPass', '') <> '') and (edCertPass.Text <> '******')) or
(cbAutoReconnect.Checked <> ReadBool(Section, 'Autoreconnect', False)) or
(edUserName.Text <> ReadString(Section, 'UserName', '')) or
((ReadString(Section, 'Password', '') = '') and (edPassword.Text <> '')) or
((ReadString(Section, 'Password', '') <> '') and (edPassword.Text <> '******')) or
(edRpcPath.Text <> ReadString(Section, 'RpcPath', rpc.DefaultRpcPath));
end;
end;
initialization
{$I connoptionstransmissionframe.lrs}
end.