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 | procedure AAddExecute(Sender: TObject);
|
---|
29 | procedure AModifyExecute(Sender: TObject);
|
---|
30 | procedure AProcessExecute(Sender: TObject);
|
---|
31 | procedure ARemoveExecute(Sender: TObject);
|
---|
32 | procedure FormShow(Sender: TObject);
|
---|
33 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
34 | procedure ListView1DblClick(Sender: TObject);
|
---|
35 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
36 | Selected: Boolean);
|
---|
37 | private
|
---|
38 | procedure ProcessImportJob(Job: TJob);
|
---|
39 | { private declarations }
|
---|
40 | public
|
---|
41 | ImportSources: TImportSources;
|
---|
42 | procedure UpdateList;
|
---|
43 | procedure UpdateInterface;
|
---|
44 | end;
|
---|
45 |
|
---|
46 | var
|
---|
47 | FormImportSources: TFormImportSources;
|
---|
48 |
|
---|
49 | implementation
|
---|
50 |
|
---|
51 | {$R *.lfm}
|
---|
52 |
|
---|
53 | uses
|
---|
54 | UFormMain, UFormImportSource;
|
---|
55 |
|
---|
56 | resourcestring
|
---|
57 | SRemoveImportSource = 'Remove import sources';
|
---|
58 | SRemoveImportSourceQuery = 'Do you really want to remove selected import sources?';
|
---|
59 | SImportSourceAlreadyExists = 'Import source %s already exists!';
|
---|
60 |
|
---|
61 |
|
---|
62 | { TFormImportSources }
|
---|
63 |
|
---|
64 | procedure TFormImportSources.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
65 | begin
|
---|
66 | if Item.Index < ImportSources.Count then
|
---|
67 | with TImportSource(ImportSources[Item.Index]) do begin
|
---|
68 | Item.Caption := Name;
|
---|
69 | Item.Data := ImportSources[Item.Index];
|
---|
70 | Item.SubItems.Add(URL);
|
---|
71 | Item.SubItems.Add(IntToStr(ItemCount));
|
---|
72 | Item.SubItems.Add(Categories.GetString);
|
---|
73 | Item.Checked := Enabled;
|
---|
74 | end;
|
---|
75 | end;
|
---|
76 |
|
---|
77 | procedure TFormImportSources.ListView1DblClick(Sender: TObject);
|
---|
78 | begin
|
---|
79 | AModify.Execute;
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TFormImportSources.ListView1SelectItem(Sender: TObject;
|
---|
83 | Item: TListItem; Selected: Boolean);
|
---|
84 | begin
|
---|
85 | UpdateInterface;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TFormImportSources.UpdateList;
|
---|
89 | begin
|
---|
90 | ListView1.Items.Count := ImportSources.Count;
|
---|
91 | ListView1.Refresh;
|
---|
92 | UpdateInterface;
|
---|
93 | end;
|
---|
94 |
|
---|
95 | procedure TFormImportSources.UpdateInterface;
|
---|
96 | begin
|
---|
97 | ARemove.Enabled := Assigned(ListView1.Selected);
|
---|
98 | AModify.Enabled := Assigned(ListView1.Selected);
|
---|
99 | end;
|
---|
100 |
|
---|
101 | procedure TFormImportSources.FormShow(Sender: TObject);
|
---|
102 | begin
|
---|
103 | UpdateList;
|
---|
104 | end;
|
---|
105 |
|
---|
106 | procedure TFormImportSources.AAddExecute(Sender: TObject);
|
---|
107 | var
|
---|
108 | NewImportSource: TImportSource;
|
---|
109 | begin
|
---|
110 | NewImportSource := TImportSource.Create;
|
---|
111 | NewImportSource.Sources := ImportSources;
|
---|
112 | FormImportSource.Load(NewImportSource);
|
---|
113 | if FormImportSource.ShowModal = mrOk then begin
|
---|
114 | FormImportSource.Save(NewImportSource);
|
---|
115 | if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
|
---|
116 | ImportSources.Add(NewImportSource);
|
---|
117 | NewImportSource := nil;
|
---|
118 | FormMain.AcronymDb.Modified := True;
|
---|
119 | UpdateList;
|
---|
120 | end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
|
---|
121 | end;
|
---|
122 | if Assigned(NewImportSource) then NewImportSource.Free;
|
---|
123 | end;
|
---|
124 |
|
---|
125 | procedure TFormImportSources.AModifyExecute(Sender: TObject);
|
---|
126 | var
|
---|
127 | NewImportSource: TImportSource;
|
---|
128 | begin
|
---|
129 | if Assigned(ListView1.Selected) then begin
|
---|
130 | NewImportSource := TImportSource.Create;
|
---|
131 | NewImportSource.Assign(ListView1.Selected.Data);
|
---|
132 | FormImportSource.Load(NewImportSource);
|
---|
133 | if FormImportSource.ShowModal = mrOk then begin
|
---|
134 | FormImportSource.Save(NewImportSource);
|
---|
135 | if (NewImportSource.Name <> TImportSource(ListView1.Selected.Data).Name) then begin
|
---|
136 | if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
|
---|
137 | TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
|
---|
138 | FormMain.AcronymDb.Modified := True;
|
---|
139 | UpdateList;
|
---|
140 | end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
|
---|
141 | end else begin
|
---|
142 | TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
|
---|
143 | FormMain.AcronymDb.Modified := True;
|
---|
144 | UpdateList;
|
---|
145 | end;
|
---|
146 | end;
|
---|
147 | if Assigned(NewImportSource) then NewImportSource.Free;
|
---|
148 | end;
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TFormImportSources.AProcessExecute(Sender: TObject);
|
---|
152 | begin
|
---|
153 | if Assigned(ListView1.Selected) then begin
|
---|
154 | JobProgressView1.AddJob('Process selected import source', ProcessImportJob);
|
---|
155 | JobProgressView1.Start;
|
---|
156 | ShowMessage(Format(SAddedCount, [TImportSource(ListView1.Selected.Data).ItemCount]));
|
---|
157 | end;
|
---|
158 | end;
|
---|
159 |
|
---|
160 | procedure TFormImportSources.ProcessImportJob(Job: TJob);
|
---|
161 | begin
|
---|
162 | TImportSource(ListView1.Selected.Data).Process;
|
---|
163 | end;
|
---|
164 |
|
---|
165 | procedure TFormImportSources.ARemoveExecute(Sender: TObject);
|
---|
166 | var
|
---|
167 | I: Integer;
|
---|
168 | begin
|
---|
169 | if Assigned(ListView1.Selected) then begin
|
---|
170 | if MessageDlg(SRemoveImportSource, SRemoveImportSourceQuery,
|
---|
171 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
172 | for I := ListView1.Items.Count - 1 downto 0 do
|
---|
173 | if ListView1.Items[I].Selected then
|
---|
174 | ImportSources.Remove(ListView1.Items[I].Data);
|
---|
175 | UpdateList;
|
---|
176 | end;
|
---|
177 | end;
|
---|
178 | end;
|
---|
179 |
|
---|
180 | end.
|
---|
181 |
|
---|