source: tags/1.1.0/Forms/UFormImportSource.pas

Last change on this file was 46, checked in by chronos, 8 years ago
  • Added: Now user name and password can be specified for import sources which require user authentication. Password is not stored in project file for safety reasons. Only Basic authentication is supported.
File size: 4.6 KB
Line 
1unit UFormImportSource;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ActnList, Menus, ExtCtrls, MaskEdit, UAcronym;
10
11type
12
13 { TFormImportSource }
14
15 TFormImportSource = class(TForm)
16 ACategoryAdd: TAction;
17 ACategoryRemove: TAction;
18 ActionList1: TActionList;
19 Bevel1: TBevel;
20 Button1: TButton;
21 Button2: TButton;
22 ButtonShowFormat: TButton;
23 ButtonOk: TButton;
24 ButtonCancel: TButton;
25 CheckBoxEnabled: TCheckBox;
26 ComboBox1: TComboBox;
27 EditUserName: TEdit;
28 EditName: TEdit;
29 EditURL: TEdit;
30 EditPassword: TEdit;
31 Label1: TLabel;
32 Label2: TLabel;
33 Label3: TLabel;
34 Label4: TLabel;
35 Label5: TLabel;
36 Label6: TLabel;
37 ListBox1: TListBox;
38 MenuItem1: TMenuItem;
39 MenuItem2: TMenuItem;
40 PopupMenuCategory: TPopupMenu;
41 procedure ACategoryAddExecute(Sender: TObject);
42 procedure ACategoryRemoveExecute(Sender: TObject);
43 procedure ButtonShowFormatClick(Sender: TObject);
44 procedure FormShow(Sender: TObject);
45 private
46 { private declarations }
47 public
48 procedure UpdateInterface;
49 procedure Load(ImportSource: TImportSource);
50 procedure Save(ImportSource: TImportSource);
51 end;
52
53var
54 FormImportSource: TFormImportSource;
55
56implementation
57
58{$R *.lfm}
59
60uses
61 UFormMain, UFormImportFormat, UFormCategorySelect;
62
63{ TFormImportSource }
64
65procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
66var
67 NewImportFormat: TImportFormat;
68begin
69 if ComboBox1.ItemIndex <> -1 then begin
70 NewImportFormat := TImportFormat.Create;
71 NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
72 FormImportFormat.Load(NewImportFormat);
73 if FormImportFormat.ShowModal = mrOk then begin
74 FormImportFormat.Save(NewImportFormat);
75 TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
76 FormMain.AcronymDb.Modified := True;
77 ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
78 end;
79 if Assigned(NewImportFormat) then NewImportFormat.Free;
80 end;
81end;
82
83procedure TFormImportSource.FormShow(Sender: TObject);
84begin
85 UpdateInterface;
86end;
87
88procedure TFormImportSource.UpdateInterface;
89begin
90 ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
91end;
92
93procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
94var
95 I: Integer;
96begin
97 FormCategorySelect.Load(ListBox1.Items);
98 if FormCategorySelect.ShowModal = mrOk then begin
99 for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
100 if FormCategorySelect.ListBox1.Selected[I] then begin
101 ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
102 end;
103 end;
104end;
105
106procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
107var
108 I: Integer;
109begin
110 if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
111 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
112 for I := ListBox1.Items.Count - 1 downto 0 do
113 if ListBox1.Selected[I] then
114 ListBox1.Items.Delete(I);
115 UpdateInterface;
116 end;
117end;
118
119procedure TFormImportSource.Load(ImportSource: TImportSource);
120var
121 I: Integer;
122begin
123 EditName.Text := ImportSource.Name;
124 EditURL.Text := ImportSource.URL;
125 while ComboBox1.Items.Count > FormMain.AcronymDb.ImportFormats.Count do
126 ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
127 while ComboBox1.Items.Count < FormMain.AcronymDb.ImportFormats.Count do
128 ComboBox1.Items.Add('');
129 for I := 0 to FormMain.AcronymDb.ImportFormats.Count - 1 do begin
130 ComboBox1.Items[I] := TImportFormat(FormMain.AcronymDb.ImportFormats[I]).Name;
131 ComboBox1.Items.Objects[I] := FormMain.AcronymDb.ImportFormats[I];
132 end;
133 ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
134 if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
135 ComboBox1.ItemIndex := 0;
136 CheckBoxEnabled.Checked := ImportSource.Enabled;
137 ImportSource.Categories.AssignToStrings(ListBox1.Items);
138 EditUserName.Text := ImportSource.UserName;
139 EditPassword.Text := ImportSource.Password;
140end;
141
142procedure TFormImportSource.Save(ImportSource: TImportSource);
143begin
144 ImportSource.Name := EditName.Text;
145 ImportSource.URL := EditURL.Text;
146 ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
147 ImportSource.Enabled := CheckBoxEnabled.Checked;
148 ImportSource.Categories.AssignFromStrings(ListBox1.Items);
149 ImportSource.UserName := EditUserName.Text;
150 ImportSource.Password := EditPassword.Text;
151end;
152
153end.
154
Note: See TracBrowser for help on using the repository browser.