1 | unit UFormImportSources;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
9 | ActnList, Menus, UAcronym, UJobProgressView;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormImportSources }
|
---|
14 |
|
---|
15 | TFormImportSources = class(TForm)
|
---|
16 | AAdd: TAction;
|
---|
17 | AProcess: TAction;
|
---|
18 | ActionList1: TActionList;
|
---|
19 | AModify: TAction;
|
---|
20 | ARemove: TAction;
|
---|
21 | JobProgressView1: TJobProgressView;
|
---|
22 | ListView1: TListView;
|
---|
23 | MenuItem1: TMenuItem;
|
---|
24 | MenuItem2: TMenuItem;
|
---|
25 | MenuItem3: TMenuItem;
|
---|
26 | MenuItem4: TMenuItem;
|
---|
27 | PopupMenuImportSource: TPopupMenu;
|
---|
28 | ToolBar1: TToolBar;
|
---|
29 | ToolButton1: TToolButton;
|
---|
30 | ToolButton2: TToolButton;
|
---|
31 | ToolButton3: TToolButton;
|
---|
32 | ToolButton4: TToolButton;
|
---|
33 | procedure AAddExecute(Sender: TObject);
|
---|
34 | procedure AModifyExecute(Sender: TObject);
|
---|
35 | procedure AProcessExecute(Sender: TObject);
|
---|
36 | procedure ARemoveExecute(Sender: TObject);
|
---|
37 | procedure FormCreate(Sender: TObject);
|
---|
38 | procedure FormShow(Sender: TObject);
|
---|
39 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
40 | procedure ListView1DblClick(Sender: TObject);
|
---|
41 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
42 | Selected: Boolean);
|
---|
43 | private
|
---|
44 | procedure ProcessImportJob(Job: TJob);
|
---|
45 | { private declarations }
|
---|
46 | public
|
---|
47 | ImportSources: TImportSources;
|
---|
48 | procedure UpdateList;
|
---|
49 | procedure UpdateInterface;
|
---|
50 | end;
|
---|
51 |
|
---|
52 | var
|
---|
53 | FormImportSources: TFormImportSources;
|
---|
54 |
|
---|
55 | implementation
|
---|
56 |
|
---|
57 | {$R *.lfm}
|
---|
58 |
|
---|
59 | uses
|
---|
60 | UFormMain, UFormImportSource;
|
---|
61 |
|
---|
62 | resourcestring
|
---|
63 | SRemoveImportSource = 'Remove import sources';
|
---|
64 | SRemoveImportSourceQuery = 'Do you really want to remove selected import sources?';
|
---|
65 | SImportSourceAlreadyExists = 'Import source %s already exists!';
|
---|
66 | SProcessSelectedSource = 'Process selected import source';
|
---|
67 |
|
---|
68 |
|
---|
69 | { TFormImportSources }
|
---|
70 |
|
---|
71 | procedure TFormImportSources.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
72 | begin
|
---|
73 | if Item.Index < ImportSources.Count then
|
---|
74 | with TImportSource(ImportSources[Item.Index]) do begin
|
---|
75 | Item.Caption := Name;
|
---|
76 | Item.Data := ImportSources[Item.Index];
|
---|
77 | Item.SubItems.Add(URL);
|
---|
78 | Item.SubItems.Add(Categories.GetString);
|
---|
79 | Item.SubItems.Add(IntToStr(ItemCount));
|
---|
80 | if LastImportTime <> 0 then
|
---|
81 | Item.SubItems.Add(DateToStr(LastImportTime))
|
---|
82 | else Item.SubItems.Add('');
|
---|
83 | Item.Checked := Enabled;
|
---|
84 | end;
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TFormImportSources.ListView1DblClick(Sender: TObject);
|
---|
88 | begin
|
---|
89 | AModify.Execute;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TFormImportSources.ListView1SelectItem(Sender: TObject;
|
---|
93 | Item: TListItem; Selected: Boolean);
|
---|
94 | begin
|
---|
95 | UpdateInterface;
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormImportSources.UpdateList;
|
---|
99 | begin
|
---|
100 | ListView1.Items.Count := ImportSources.Count;
|
---|
101 | ListView1.Refresh;
|
---|
102 | UpdateInterface;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TFormImportSources.UpdateInterface;
|
---|
106 | begin
|
---|
107 | ARemove.Enabled := Assigned(ListView1.Selected);
|
---|
108 | AModify.Enabled := Assigned(ListView1.Selected);
|
---|
109 | end;
|
---|
110 |
|
---|
111 | procedure TFormImportSources.FormShow(Sender: TObject);
|
---|
112 | begin
|
---|
113 | UpdateList;
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure TFormImportSources.AAddExecute(Sender: TObject);
|
---|
117 | var
|
---|
118 | NewImportSource: TImportSource;
|
---|
119 | begin
|
---|
120 | NewImportSource := TImportSource.Create;
|
---|
121 | NewImportSource.Sources := ImportSources;
|
---|
122 | FormImportSource.Load(NewImportSource);
|
---|
123 | if FormImportSource.ShowModal = mrOk then begin
|
---|
124 | FormImportSource.Save(NewImportSource);
|
---|
125 | if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
|
---|
126 | ImportSources.Add(NewImportSource);
|
---|
127 | NewImportSource := nil;
|
---|
128 | FormMain.AcronymDb.Modified := True;
|
---|
129 | UpdateList;
|
---|
130 | end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
|
---|
131 | end;
|
---|
132 | if Assigned(NewImportSource) then NewImportSource.Free;
|
---|
133 | end;
|
---|
134 |
|
---|
135 | procedure TFormImportSources.AModifyExecute(Sender: TObject);
|
---|
136 | var
|
---|
137 | NewImportSource: TImportSource;
|
---|
138 | begin
|
---|
139 | if Assigned(ListView1.Selected) then begin
|
---|
140 | NewImportSource := TImportSource.Create;
|
---|
141 | NewImportSource.Assign(ListView1.Selected.Data);
|
---|
142 | FormImportSource.Load(NewImportSource);
|
---|
143 | if FormImportSource.ShowModal = mrOk then begin
|
---|
144 | FormImportSource.Save(NewImportSource);
|
---|
145 | if (NewImportSource.Name <> TImportSource(ListView1.Selected.Data).Name) then begin
|
---|
146 | if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
|
---|
147 | TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
|
---|
148 | FormMain.AcronymDb.Modified := True;
|
---|
149 | UpdateList;
|
---|
150 | end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
|
---|
151 | end else begin
|
---|
152 | TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
|
---|
153 | FormMain.AcronymDb.Modified := True;
|
---|
154 | UpdateList;
|
---|
155 | end;
|
---|
156 | end;
|
---|
157 | if Assigned(NewImportSource) then NewImportSource.Free;
|
---|
158 | end;
|
---|
159 | end;
|
---|
160 |
|
---|
161 | procedure TFormImportSources.AProcessExecute(Sender: TObject);
|
---|
162 | begin
|
---|
163 | if Assigned(ListView1.Selected) then begin
|
---|
164 | FormMain.AcronymDb.AddedCount := 0;
|
---|
165 | JobProgressView1.AddJob(SProcessSelectedSource, ProcessImportJob);
|
---|
166 | JobProgressView1.Start;
|
---|
167 | ShowMessage(Format(SAddedCount, [TImportSource(ListView1.Selected.Data).ItemCount, FormMain.AcronymDb.AddedCount]));
|
---|
168 | end;
|
---|
169 | end;
|
---|
170 |
|
---|
171 | procedure TFormImportSources.ProcessImportJob(Job: TJob);
|
---|
172 | begin
|
---|
173 | TImportSource(ListView1.Selected.Data).Process;
|
---|
174 | end;
|
---|
175 |
|
---|
176 | procedure TFormImportSources.ARemoveExecute(Sender: TObject);
|
---|
177 | var
|
---|
178 | I: Integer;
|
---|
179 | begin
|
---|
180 | if Assigned(ListView1.Selected) then begin
|
---|
181 | if MessageDlg(SRemoveImportSource, SRemoveImportSourceQuery,
|
---|
182 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
183 | for I := ListView1.Items.Count - 1 downto 0 do
|
---|
184 | if ListView1.Items[I].Selected then
|
---|
185 | ImportSources.Remove(ListView1.Items[I].Data);
|
---|
186 | UpdateList;
|
---|
187 | end;
|
---|
188 | end;
|
---|
189 | end;
|
---|
190 |
|
---|
191 | procedure TFormImportSources.FormCreate(Sender: TObject);
|
---|
192 | var
|
---|
193 | I: Integer;
|
---|
194 | begin
|
---|
195 | for I := 0 to ToolBar1.ButtonCount - 1 do
|
---|
196 | ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
|
---|
197 | end;
|
---|
198 |
|
---|
199 | end.
|
---|
200 |
|
---|