-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLMS.Form.Main.pas
213 lines (172 loc) · 5 KB
/
LMS.Form.Main.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
unit LMS.Form.Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.Menus, System.Actions, Vcl.ActnList,
Vcl.ToolWin, Vcl.ActnMan, Vcl.ActnCtrls, Vcl.ActnMenus,
Vcl.PlatformDefaultStyleActnCtrls, REST.Types, REST.Client,
Data.Bind.Components, Data.Bind.ObjectScope, Vcl.StdCtrls, Vcl.StdActns,
LMS.TreeView.Network, Vcl.AppEvnts, System.ImageList, Vcl.ImgList;
const
WM_AFTER_CREATE = WM_USER + 300;
type
TMainForm = class(TForm)
ActionMainMenuBar1: TActionMainMenuBar;
MainActionManager: TActionManager;
actAbout: TAction;
Memo1: TMemo;
WindowCascade1: TWindowCascade;
WindowMinimizeAll1: TWindowMinimizeAll;
Action2: TAction;
Panel1: TPanel;
Splitter1: TSplitter;
CoursesActionManager: TActionManager;
ActionMainMenuBar2: TActionMainMenuBar;
edFilter: TEdit;
Action3: TAction;
actExit: TAction;
ImageList1: TImageList;
Button1: TButton;
actCollapseAll: TAction;
actExpandAll: TAction;
procedure edFilterChange(Sender: TObject);
procedure actAboutExecute(Sender: TObject);
procedure Action2Execute(Sender: TObject);
procedure Action2Update(Sender: TObject);
procedure Action3Update(Sender: TObject);
procedure Action3Execute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure actExitExecute(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure actCollapseAllExecute(Sender: TObject);
procedure actExpandAllExecute(Sender: TObject);
private
aLMSNetworkTreeView: TLMSNetworkTreeView;
procedure WmAfterCreate(var Msg: TMessage); message WM_AFTER_CREATE;
public
constructor Create(Owner: Tcomponent); override;
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses
inifiles,
System.JSON,
urlmon,
LMS._interface.LMS,
LMS._class.LMS,
LMS._class.Network,
LMS.Helper.Log,
LMS.Helper.Utils,
LMS.Form.About;
procedure TMainForm.actAboutExecute(Sender: TObject);
begin
with TAboutForm.Create(self) do
begin
ShowModal;
free;
end;
end;
procedure TMainForm.Action2Execute(Sender: TObject);
begin
for var i := Screen.FormCount - 1 downto 1 do
Screen.Forms[i].Close;
end;
procedure TMainForm.Action2Update(Sender: TObject);
begin
Action2.Enabled := (Screen.FormCount > 1);
end;
procedure TMainForm.Action3Execute(Sender: TObject);
begin
edFilter.Text := '';
edFilter.OnChange(edFilter);
aLMSNetworkTreeView.FocusSelectedNode;
end;
procedure TMainForm.Action3Update(Sender: TObject);
begin
Action3.Enabled := edFilter.Text <> '';
end;
procedure TMainForm.actCollapseAllExecute(Sender: TObject);
begin
self.aLMSNetworkTreeView.FullCollapse();
end;
procedure TMainForm.actExitExecute(Sender: TObject);
begin
actExit.Checked := true;
Close;
end;
procedure TMainForm.actExpandAllExecute(Sender: TObject);
begin
aLMSNetworkTreeView.FullExpandLMS;
end;
constructor TMainForm.Create(Owner: Tcomponent);
begin
inherited;
top := 0;
left := 0;
ClientWidth := Screen.Width;
ClientHeight := Screen.Height;
aLMSNetworkTreeView := TLMSNetworkTreeView.Create(self);
aLMSNetworkTreeView.parent := Panel1;
aLMSNetworkTreeView.Align := alClient;
end;
procedure TMainForm.Button1Click(Sender: TObject);
begin
hhide := not hhide;
if hhide then
Button1.caption := '*)'
else
Button1.caption := ':)';
end;
procedure TMainForm.edFilterChange(Sender: TObject);
begin
aLMSNetworkTreeView.FilterByText(TEdit(Sender).Text);
actExpandAllExecute(self);
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := true;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
PostMessage(self.Handle, WM_AFTER_CREATE, 0, 0);
end;
procedure TMainForm.WmAfterCreate(var Msg: TMessage);
var
aIniFile: TIniFile;
aSections: TStrings;
aSection: string;
aIniFilePath: string;
begin
aIniFilePath := ExtractFilePath(ParamStr(0)) + 'config.ini';
// log('Trying to load ' + aIniFilePath);
if not FileExists(aIniFilePath) then
begin
Log('Please, create the config.ini file to continue. You can use the config.ini_dist as template');
end
else
begin
aIniFile := TIniFile.Create(aIniFilePath);
// log('Config file loaded');
aSections := TStringList.Create;
aIniFile.ReadSections(aSections);
for aSection in aSections do
begin
var
aLMS: ILMS := TLMS.Create(self);
aLMS.id := aSection;
aLMS.Host := aIniFile.ReadString(aSection, 'url', '');
aLMS.user := aIniFile.ReadString(aSection, 'user', '');
aLMS.password := aIniFile.ReadString(aSection, 'password', '');
aLMS.service := aIniFile.ReadString(aSection, 'service', '');
aLMS.autoconnect := aIniFile.ReadBool(aSection, 'autoconnect', false);
GetGlobalNetwork.add(aLMS);
end;
aLMSNetworkTreeView.LMSNetwork := GetGlobalNetwork;
end;
end;
end.