| 1 | unit FormExport;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
|
|---|
| 7 | ExtCtrls, Table, LazFileUtils, FormEx;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 |
|
|---|
| 11 | { TFormExport }
|
|---|
| 12 |
|
|---|
| 13 | TFormExport = class(TFormEx)
|
|---|
| 14 | ButtonBrowse: TButton;
|
|---|
| 15 | ButtonCancel: TButton;
|
|---|
| 16 | ButtonExport: TButton;
|
|---|
| 17 | CheckBoxHumanReadableHeader: TCheckBox;
|
|---|
| 18 | ComboBoxOutputFormat: TComboBox;
|
|---|
| 19 | EditOutputFile: TEdit;
|
|---|
| 20 | Label1: TLabel;
|
|---|
| 21 | Label2: TLabel;
|
|---|
| 22 | ListView1: TListView;
|
|---|
| 23 | SaveDialog1: TSaveDialog;
|
|---|
| 24 | ScrollBox1: TScrollBox;
|
|---|
| 25 | TimerRedraw: TTimer;
|
|---|
| 26 | procedure ButtonBrowseClick(Sender: TObject);
|
|---|
| 27 | procedure ButtonExportClick(Sender: TObject);
|
|---|
| 28 | procedure CheckBoxHumanReadableHeaderChange(Sender: TObject);
|
|---|
| 29 | procedure ComboBoxOutputFormatChange(Sender: TObject);
|
|---|
| 30 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 31 | procedure FormCreate(Sender: TObject);
|
|---|
| 32 | procedure FormDestroy(Sender: TObject);
|
|---|
| 33 | procedure FormShow(Sender: TObject);
|
|---|
| 34 | procedure TimerRedrawTimer(Sender: TObject);
|
|---|
| 35 | private
|
|---|
| 36 | Table: TTable;
|
|---|
| 37 | RedrawPending: Boolean;
|
|---|
| 38 | procedure UpdateFileNameExt;
|
|---|
| 39 | procedure LoadConfig;
|
|---|
| 40 | procedure SaveConfig;
|
|---|
| 41 | end;
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | implementation
|
|---|
| 45 |
|
|---|
| 46 | {$R *.lfm}
|
|---|
| 47 |
|
|---|
| 48 | uses
|
|---|
| 49 | Core, Common, RegistryEx, VCardFile, VCard;
|
|---|
| 50 |
|
|---|
| 51 | { TFormExport }
|
|---|
| 52 |
|
|---|
| 53 | procedure TFormExport.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 54 | begin
|
|---|
| 55 | SaveConfig;
|
|---|
| 56 | end;
|
|---|
| 57 |
|
|---|
| 58 | procedure TFormExport.ButtonExportClick(Sender: TObject);
|
|---|
| 59 | var
|
|---|
| 60 | TableFormat: TTableFormat;
|
|---|
| 61 | begin
|
|---|
| 62 | TableFormat := TTableFormat(ComboBoxOutputFormat.Items.Objects[ComboBoxOutputFormat.ItemIndex]);
|
|---|
| 63 | TVCardFile(Core.Core.DataFile).VCard.ExportToFile(EditOutputFile.Text, TableFormat,
|
|---|
| 64 | CheckBoxHumanReadableHeader.Checked);
|
|---|
| 65 | end;
|
|---|
| 66 |
|
|---|
| 67 | procedure TFormExport.CheckBoxHumanReadableHeaderChange(Sender: TObject);
|
|---|
| 68 | begin
|
|---|
| 69 | RedrawPending := True;
|
|---|
| 70 | end;
|
|---|
| 71 |
|
|---|
| 72 | procedure TFormExport.ComboBoxOutputFormatChange(Sender: TObject);
|
|---|
| 73 | begin
|
|---|
| 74 | UpdateFileNameExt;
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | procedure TFormExport.ButtonBrowseClick(Sender: TObject);
|
|---|
| 78 | begin
|
|---|
| 79 | SaveDialog1.DefaultExt := '';
|
|---|
| 80 | SaveDialog1.InitialDir := ExtractFileDir(EditOutputFile.Text);
|
|---|
| 81 | SaveDialog1.FileName := ExtractFileName(EditOutputFile.Text);
|
|---|
| 82 | if SaveDialog1.Execute then begin
|
|---|
| 83 | EditOutputFile.Text := SaveDialog1.FileName;
|
|---|
| 84 | end;
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | procedure TFormExport.FormCreate(Sender: TObject);
|
|---|
| 88 | var
|
|---|
| 89 | TableFormat: TTableFormat;
|
|---|
| 90 | begin
|
|---|
| 91 | ComboBoxOutputFormat.Items.BeginUpdate;
|
|---|
| 92 | try
|
|---|
| 93 | for TableFormat := Low(TTableFormat) to High(TTableFormat) do
|
|---|
| 94 | if TableFormat <> tfListView then
|
|---|
| 95 | ComboBoxOutputFormat.Items.AddObject(TableFormatText[TableFormat], TObject(TableFormat));
|
|---|
| 96 | if (ComboBoxOutputFormat.ItemIndex = -1) and (ComboBoxOutputFormat.Items.Count > 0) then
|
|---|
| 97 | ComboBoxOutputFormat.ItemIndex := 0;
|
|---|
| 98 | finally
|
|---|
| 99 | ComboBoxOutputFormat.Items.EndUpdate;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 | Table := TTable.Create;
|
|---|
| 103 | LoadConfig;
|
|---|
| 104 | UpdateFileNameExt;
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | procedure TFormExport.FormDestroy(Sender: TObject);
|
|---|
| 108 | begin
|
|---|
| 109 | FreeAndNil(Table);
|
|---|
| 110 | end;
|
|---|
| 111 |
|
|---|
| 112 | procedure TFormExport.FormShow(Sender: TObject);
|
|---|
| 113 | begin
|
|---|
| 114 | RedrawPending := True;
|
|---|
| 115 | end;
|
|---|
| 116 |
|
|---|
| 117 | procedure TFormExport.TimerRedrawTimer(Sender: TObject);
|
|---|
| 118 | begin
|
|---|
| 119 | if RedrawPending then begin
|
|---|
| 120 | TVCardFile(Core.Core.DataFile).VCard.ExportToTable(Table,
|
|---|
| 121 | CheckBoxHumanReadableHeader.Checked);
|
|---|
| 122 | Table.GetOutputListView(ListView1);
|
|---|
| 123 | RedrawPending := False;
|
|---|
| 124 | end;
|
|---|
| 125 | end;
|
|---|
| 126 |
|
|---|
| 127 | procedure TFormExport.UpdateFileNameExt;
|
|---|
| 128 | var
|
|---|
| 129 | FileName: string;
|
|---|
| 130 | begin
|
|---|
| 131 | FileName := EditOutputFile.Text;
|
|---|
| 132 | EditOutputFile.Text := Copy(FileName, 1, Length(FileName) - Length(ExtractFileExt(FileName))) +
|
|---|
| 133 | TableFormatExt[TTableFormat(ComboBoxOutputFormat.Items.Objects[ComboBoxOutputFormat.ItemIndex])];
|
|---|
| 134 | end;
|
|---|
| 135 |
|
|---|
| 136 | procedure TFormExport.LoadConfig;
|
|---|
| 137 | var
|
|---|
| 138 | TableFormat: TTableFormat;
|
|---|
| 139 | begin
|
|---|
| 140 | with TRegistryEx.Create do
|
|---|
| 141 | try
|
|---|
| 142 | CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
|
|---|
| 143 | EditOutputFile.Text := ReadStringWithDefault('ExportFileName', 'Export.txt');
|
|---|
| 144 | TableFormat := TTableFormat(ReadIntegerWithDefault('ExportTableFormat', Integer(tfCsv)));
|
|---|
| 145 | CheckBoxHumanReadableHeader.Checked := ReadBoolWithDefault('ExportHumanReadableColumns', CheckBoxHumanReadableHeader.Checked);
|
|---|
| 146 | ComboBoxOutputFormat.ItemIndex := ComboBoxOutputFormat.Items.IndexOfObject(TObject(TableFormat));
|
|---|
| 147 | finally
|
|---|
| 148 | Free;
|
|---|
| 149 | end;
|
|---|
| 150 | end;
|
|---|
| 151 |
|
|---|
| 152 | procedure TFormExport.SaveConfig;
|
|---|
| 153 | begin
|
|---|
| 154 | with TRegistryEx.Create do
|
|---|
| 155 | try
|
|---|
| 156 | CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
|
|---|
| 157 | WriteString('ExportFileName', EditOutputFile.Text);
|
|---|
| 158 | WriteInteger('ExportTableFormat', Integer(ComboBoxOutputFormat.Items.Objects[ComboBoxOutputFormat.ItemIndex]));
|
|---|
| 159 | WriteBool('ExportHumanReadableColumns', CheckBoxHumanReadableHeader.Checked);
|
|---|
| 160 | finally
|
|---|
| 161 | Free;
|
|---|
| 162 | end;
|
|---|
| 163 | end;
|
|---|
| 164 |
|
|---|
| 165 | end.
|
|---|
| 166 |
|
|---|