-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainform.pas
315 lines (286 loc) · 7.26 KB
/
mainform.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
313
314
unit mainform;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, cyPanel, Forms, Controls, Graphics,
Dialogs, ComCtrls, ExtCtrls, Menus, nkTitleBar, nkResizer,
VirtualTrees, rxctrls, BCLabel, gogopluginss, rccmd, filesform;
type
{ TfrmMain }
TfrmMain = class(TForm)
BCLabel1: TBCLabel;
CyPanel1: TCyPanel;
ImageList1: TImageList;
ImageList2: TImageList;
ListRemotes: TListView;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
nkResizer2: TnkResizer;
nkTitleBar2: TnkTitleBar;
Tabs: TPageControl;
Panel1: TPanel;
PopAddRemote: TPopupMenu;
RxSpeedButton1: TRxSpeedButton;
RxSpeedButton2: TRxSpeedButton;
RxSpeedButton3: TRxSpeedButton;
Splitter1: TSplitter;
StatusBar: TCyPanel;
StatusBar1: TCyPanel;
TabSheet1: TTabSheet;
ToolAddNode: TToolButton;
ToolAddRemote: TToolButton;
ToolAddUSer: TToolButton;
ToolAddUsers: TToolButton;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolDeleteNode: TToolButton;
ToolDeleteRemote: TToolButton;
ToolDeleteUser: TToolButton;
ToolEditNode: TToolButton;
ToolEditRemote: TToolButton;
ToolEditUser: TToolButton;
ToolHelp: TToolButton;
ToolNodeLicense: TToolButton;
ToolStartNode: TToolButton;
ToolStopNode: TToolButton;
ToolSyncAll: TToolButton;
ToolSyncData: TToolButton;
procedure FormShow(Sender: TObject);
procedure RxSpeedButton1Click(Sender: TObject);
procedure RxSpeedButton2Click(Sender: TObject);
procedure RxSpeedButton3Click(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure ToolHelpClick(Sender: TObject);
private
WinMax : boolean;
OldLeft,OldTop,OldWidth,OldHeight:integer;
public
procedure InitDB;
procedure InitPlugins;
procedure InitPopAddRemote;
procedure PopAddRemoteClick(Sender: TObject);
procedure ReloadListRemotes;
procedure ClearTab;
procedure AddFilesTab(AAlias:string; ACaption:string);
function IndexOfFilesTab(AAlias:string):integer;
end;
var
frmMain: TfrmMain;
implementation
uses
datamodule;
{$R *.frm}
{ TfrmMain }
procedure TfrmMain.ClearTab;
begin
if Assigned(Tabs.ActivePage) then
begin
Tabs.ActivePage.Free;
end;
end;
procedure TfrmMain.AddFilesTab(AAlias: string; ACaption:string);
Var
TabSheet: TFilesPanel;
mIndex:integer;
begin
mIndex:=IndexOfFilesTab(AAlias);
if mIndex = -1 then
begin
//ClearTab; TODO:改成查询是否存在相同Alias
TabSheet := TFilesPanel.Create(Tabs);
TabSheet.Parent := Tabs;
TabSheet.RAlias:='webdav_1';
TabSheet.RootPath:='';
TabSheet.Caption:=ACaption;
Tabsheet.ShowForm;
Tabs.ActivePageIndex := TabSheet.PageIndex;
end
else
begin
Tabs.ActivePageIndex:=mIndex;
end;
end;
function TfrmMain.IndexOfFilesTab(AAlias: string): integer;
var
i:integer;
begin
Result:=-1;
for i:=0 to Tabs.PageCount-1 do
begin
if Tabs.Pages[i] is TFilesPanel then
begin
if Trim((Tabs.Pages[i] as TFilesPanel).RAlias)=Trim(AAlias) then
begin
Result:=i;
Break;
end;
end;
end;
end;
procedure TfrmMain.RxSpeedButton1Click(Sender: TObject);
begin
Hide;
Dm.Plugins.Clear;
//Dm.Plugins.Free;
Close;
// Application.Terminate;
end;
procedure TfrmMain.FormShow(Sender: TObject);
begin
InitDB;
InitPlugins;
InitPopAddRemote;
RxSpeedButton2Click(nil);
ReloadListRemotes;
end;
procedure TfrmMain.RxSpeedButton2Click(Sender: TObject);
begin
if WinMax = False then
begin
OldLeft := Self.Left;
OldTop := Self.Top;
OldWidth := Self.Width;
OldHeight := Self.Height;
Self.Top:=Self.Monitor.WorkareaRect.Top;
Self.Left:=Self.Monitor.WorkareaRect.Left;
Self.Width:=Self.Monitor.WorkareaRect.Width;
Self.Height:=Self.Monitor.WorkareaRect.Height;
WinMax := True;
end
else
begin
Self.Top:=OldTop;
Self.Left:=OldLeft;
Self.Width:=OldWidth;
Self.Height:=OldHeight;
WinMax := False;
end;
end;
procedure TfrmMain.RxSpeedButton3Click(Sender: TObject);
begin
Application.Minimize;
end;
procedure TfrmMain.ToolButton6Click(Sender: TObject);
begin
Self.AddFilesTab('webdav_1','demo1');
end;
procedure TfrmMain.ToolHelpClick(Sender: TObject);
var
mPlugin:TGoGoPluginItem;
m:string;
begin
//测试plugin
mPlugin:=TGoGoPluginItem.Create(Self,ExtractFilepath(Application.ExeName)+'\plugin\webdav.dll');
// -----------------------------
// m:=mPlugin.PlugInfo();
// ShowMessage('Plugin.PlugInfo 说: '+#10#13+#10#13+m);
// mPlugin.Free;
// mPlugin:=nil;
// -----------------------------
// m:=mPlugin.Edit(Self.Handle,Dm.conn);
//showmessage(m);
//窗口自释放,无需mPlugin.Free;
// -----------------------------
m:=mPlugIn.CreateRemote(1,Dm.conn);
ShowMessage(m);
end;
procedure TfrmMain.InitDB;
begin
dm.conn.LibraryLocation:=ExtractFilepath(Application.ExeName)+'\data\sqlite3.dll';
dm.conn.Database:=ExtractFilepath(Application.ExeName)+'\data\config.db';
dm.conn.Connect;
end;
procedure TfrmMain.InitPlugins;
var
mFiles:TStrings;
i:integer;
mItem:TGoGoPluginItem;
mInfo:string;
m:string;
begin
dm.Plugins:=TGoGoPlugins.Create(Self);
//查找plugin目录下的插件Dll
mFiles := FindAllFiles(ExtractFilepath(Application.ExeName)+'plugin', '*.dll', False);
for i:=0 to mFiles.Count-1 do
begin
mItem:=TGoGoPluginItem.Create(Self,Trim(mFiles.Strings[i]));
m:=mItem.PlugType();
mInfo := m;
mItem.LibType:=mInfo;
Dm.Plugins.Add(mItem);
end;
mFiles.Free;
//测试
//if Dm.Plugins.Count>0 then
//begin
// ShowMessage(Dm.Plugins.Item(0).LibType);
//end;
end;
procedure TfrmMain.InitPopAddRemote;
var
i:integer;
mItem:TMenuItem;
begin
PopAddRemote.Items.Clear;
for i:=0 to Dm.Plugins.Count-1 do
begin
mItem:=TMenuItem.Create(PopAddRemote);
mItem.Caption:='添加 '+UpperCase(Dm.Plugins.Item(i).LibType)+' 存储';
mItem.Tag:=i;
mItem.OnClick:=@PopAddRemoteClick;
PopAddRemote.Items.Add(mItem);
end;
end;
procedure TfrmMain.PopAddRemoteClick(Sender: TObject);
var
mIndex:integer;
mResult:string;
begin
mIndex:=(Sender as TMenuItem).Tag;
mResult:=dm.Plugins.Item(mIndex).Edit(Self.Handle,Dm.conn);
if mResult='OK' then
begin
//窗口返回mrOK,刷新目录列表
ReloadListRemotes;
end;
end;
procedure TfrmMain.ReloadListRemotes;
begin
ListRemotes.Items.BeginUpdate;
ListRemotes.Items.Clear;
with dm.InnerQry do
begin
Close;
Sql.Clear;
Sql.Add('select * from remotes2 order by rname asc');
Open;
First;
while not Eof do
begin
with ListRemotes.Items.Add do
begin
Caption:='';//FieldByName('rtype').AsString;
SubItems.Add(FieldByName('rname').AsString);
if Trim(FieldByName('rletter').AsString)='' then
SubItems.Add('-')
else
SubItems.Add(FieldByName('rletter').AsString);
SubItems.Add(FieldByName('rcomment').AsString);
SubItems.Add(inttostr(FieldByName('id').AsInteger));
ImageIndex:=0;
end;
Next;
end;
end;
listRemotes.Items.EndUpdate;
end;
end.