forked from transmission-remote-gui/transgui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
connoptionsframes.pas
153 lines (125 loc) · 5.06 KB
/
connoptionsframes.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
{*************************************************************************************
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 ConnOptionsFrames;
{$mode ObjFPC}{$H+}{$J-}
interface
uses
Classes, SysUtils, ComCtrls, Dialogs, Utils, ConnOptionsTransmissionFrame,
ConnOptionsProxyFrame, ConnOptionsPathsFrame, ConnOptionsMiscFrame;
resourcestring
sNoHost = 'No host name specified.';
sNoProxy = 'No proxy server specified.';
type
TConnOptionsFrames = class
transmission: TConnOptionsTransmissionFrame;
proxy: TConnOptionsProxyFrame;
paths: TConnOptionsPathsFrame;
misc: TConnOptionsMiscFrame;
constructor Create(TheOwner: TComponent; tabTr: TTabSheet;
tabPr: TTabSheet; tabPa: TTabSheet; tabMi: TTabSheet; page: TPageControl);
function Validate : Boolean;
procedure LoadConnSettings(const ConnName: string; Ini: TIniFileUtf8);
procedure SaveConnSettings(const ConnName: string; Ini: TIniFileUtf8);
function IsConnSettingsChanged(const ConnName: string; Ini: TIniFileUtf8) : Boolean;
private
tabTransmission: TTabSheet;
tabProxy: TTabSheet;
tabPaths: TTabSheet;
tabMisc: TTabSheet;
pageControl: TPageControl;
class function ConnNameToSectionName(const ConnName: string; Ini: TIniFileUtf8) : String; static;
end;
implementation
constructor TConnOptionsFrames.Create(TheOwner: TComponent; tabTr: TTabSheet;
tabPr: TTabSheet; tabPa: TTabSheet; tabMi: TTabSheet; page: TPageControl);
begin
transmission := TConnOptionsTransmissionFrame.Create(TheOwner);
proxy := TConnOptionsProxyFrame.Create(TheOwner);
paths := TConnOptionsPathsFrame.Create(TheOwner);
misc := TConnOptionsMiscFrame.Create(TheOwner);
tabTransmission := tabTr;
tabProxy := tabPr;
tabPaths := tabPa;
tabMisc := tabMi;
transmission.Parent := tabTransmission;
proxy.Parent := tabProxy;
paths.Parent := tabPaths;
misc.Parent := tabMisc;
end;
function TConnOptionsFrames.Validate : Boolean;
begin
Result:=False;
transmission.edHost.Text:=Trim(transmission.edHost.Text);
if Trim(transmission.edHost.Text) = '' then begin
pageControl.ActivePage:=tabTransmission;
transmission.edHost.SetFocus;
MessageDlg(sNoHost, mtError, [mbOK], 0);
exit;
end;
proxy.edProxy.Text:=Trim(proxy.edProxy.Text);
if tabProxy.TabVisible and proxy.cbUseProxy.Checked and (proxy.edProxy.Text = '') then begin
pageControl.ActivePage:=tabProxy;
proxy.edProxy.SetFocus;
MessageDlg(sNoProxy, mtError, [mbOK], 0);
exit;
end;
Result:=True;
end;
procedure TConnOptionsFrames.LoadConnSettings(const ConnName: string; Ini: TIniFileUtf8);
var
Section: String;
begin
Section := ConnNameToSectionName(ConnName, Ini);
transmission.LoadConnSettings(Section, Ini);
proxy.LoadConnSettings(Section, Ini);
paths.LoadConnSettings(Section, Ini);
misc.LoadConnSettings(Section, Ini);
end;
procedure TConnOptionsFrames.SaveConnSettings(const ConnName: string; Ini: TIniFileUtf8);
var
Section: String;
begin
Section := ConnNameToSectionName(ConnName, Ini);
transmission.SaveConnSettings(Section, Ini);
proxy.SaveConnSettings(Section, Ini);
paths.SaveConnSettings(Section, Ini);
misc.SaveConnSettings(Section, Ini);
end;
function TConnOptionsFrames.IsConnSettingsChanged(const ConnName: string; Ini: TIniFileUtf8) : Boolean;
var
Section: String;
begin
Section := ConnNameToSectionName(ConnName, Ini);
Result:=transmission.IsConnSettingsChanged(Section, Ini) or
proxy.IsConnSettingsChanged(Section, Ini) or
paths.IsConnSettingsChanged(Section,Ini) or
misc.IsConnSettingsChanged(Section, Ini);
end;
class function TConnOptionsFrames.ConnNameToSectionName(const ConnName: string; Ini: TIniFileUtf8) : String;
var
Section: String;
begin
Section := 'Connection.' + ConnName;
if (ConnName <> '') and not Ini.SectionExists(Section) then
Section := 'Connection';
Result := Section;
end;
end.