Changeset 28 for trunk


Ignore:
Timestamp:
Jul 12, 2016, 4:28:22 PM (8 years ago)
Author:
chronos
Message:
  • Added: Import format items can be repetitive.
  • Added: Show total count of imported items.
  • Added: Button for direct open of import format definition from import source window.
Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/AcronymDecoder.lpi

    r27 r28  
    181181        <IsPartOfProject Value="True"/>
    182182        <ComponentName Value="FormImportPattern"/>
     183        <HasResources Value="True"/>
    183184        <ResourceBaseClass Value="Form"/>
    184185      </Unit14>
  • trunk/Forms/UFormAbout.lfm

    r23 r28  
    11object FormAbout: TFormAbout
    2   Left = 866
     2  Left = 561
    33  Height = 397
    4   Top = 623
     4  Top = 276
    55  Width = 473
    66  Caption = 'About'
     
    1212  object LabelAppName: TLabel
    1313    Left = 20
    14     Height = 55
     14    Height = 54
    1515    Top = 20
    1616    Width = 433
     
    2424  object LabelDescription: TLabel
    2525    Left = 20
    26     Height = 48
    27     Top = 95
     26    Height = 40
     27    Top = 94
    2828    Width = 433
    2929    Align = alTop
     
    4545  object LabelContent: TLabel
    4646    Left = 20
    47     Height = 24
    48     Top = 163
     47    Height = 20
     48    Top = 154
    4949    Width = 433
    5050    Align = alTop
     
    7373    EmailContact = 'robie@centrum.cz'
    7474    AppName = 'Acronym Decoder'
    75     ReleaseDate = 42494
     75    ReleaseDate = 42563
    7676    RegistryKey = '\Software\'
    7777    RegistryRoot = rrKeyCurrentUser
  • trunk/Forms/UFormImportFormat.lfm

    r27 r28  
    11object FormImportFormat: TFormImportFormat
    2   Left = 514
     2  Left = 461
    33  Height = 433
    4   Top = 316
     4  Top = 321
    55  Width = 664
    66  Caption = 'Import format'
    77  ClientHeight = 433
    88  ClientWidth = 664
     9  OnCreate = FormCreate
    910  OnShow = FormShow
    1011  LCLVersion = '1.6.0.4'
     
    99100        Caption = 'Variable'
    100101        Width = 100
     102      end   
     103      item
     104        Caption = 'Repetition'
     105        Width = 100
    101106      end>
    102107    OwnerData = True
  • trunk/Forms/UFormImportFormat.lrt

    r27 r28  
    99TFORMIMPORTFORMAT.LISTVIEWITEMRULES.COLUMNS[2].CAPTION=Action
    1010TFORMIMPORTFORMAT.LISTVIEWITEMRULES.COLUMNS[3].CAPTION=Variable
     11TFORMIMPORTFORMAT.LISTVIEWITEMRULES.COLUMNS[4].CAPTION=Repetition
    1112TFORMIMPORTFORMAT.LABEL2.CAPTION=Item rules:
    1213TFORMIMPORTFORMAT.AADD.CAPTION=Add
  • trunk/Forms/UFormImportFormat.pas

    r27 r28  
    4141    procedure AMoveUpExecute(Sender: TObject);
    4242    procedure ARemoveExecute(Sender: TObject);
     43    procedure FormCreate(Sender: TObject);
    4344    procedure FormShow(Sender: TObject);
    4445    procedure ListViewItemRulesData(Sender: TObject; Item: TListItem);
     
    5455var
    5556  FormImportFormat: TFormImportFormat;
     57  YesNoString: array[Boolean] of string;
    5658
    5759
     
    6668  SRemoveImportPattern = 'Remove import pattern';
    6769  SRemoveImportPatternQuery = 'Do you really want to remove selected import patterns?';
     70  SYes = 'Yes';
     71  SNo = 'No';
    6872
    6973
     
    135139end;
    136140
     141procedure TFormImportFormat.FormCreate(Sender: TObject);
     142begin
     143  YesNoString[False] := SNo;
     144  YesNoString[True] := SYes;
     145end;
     146
    137147procedure TFormImportFormat.FormShow(Sender: TObject);
    138148begin
     
    149159    Item.SubItems.Add(ImportPatternFlagString[Flag]);
    150160    Item.SubItems.Add(ImportVariableString[Variable]);
     161    Item.SubItems.Add(YesNoString[Repetition]);
    151162    Item.Data := ImportFormat.ItemPatterns[Item.Index];
    152163  end;
  • trunk/Forms/UFormImportPattern.lfm

    r27 r28  
    4747    Top = 384
    4848    Width = 75
     49    Anchors = [akRight, akBottom]
    4950    Caption = 'Cancel'
    5051    ModalResult = 2
     
    5657    Top = 384
    5758    Width = 75
     59    Anchors = [akRight, akBottom]
    5860    Caption = 'Ok'
    5961    ModalResult = 1
     
    99101    TabOrder = 5
    100102  end
     103  object CheckBoxRepetition: TCheckBox
     104    Left = 24
     105    Height = 24
     106    Top = 160
     107    Width = 93
     108    Caption = 'Repetition'
     109    TabOrder = 6
     110  end
    101111end
  • trunk/Forms/UFormImportPattern.lrt

    r27 r28  
    66TFORMIMPORTPATTERN.LABEL10.CAPTION=Action:
    77TFORMIMPORTPATTERN.LABEL11.CAPTION=Variable:
     8TFORMIMPORTPATTERN.CHECKBOXREPETITION.CAPTION=Repetition
  • trunk/Forms/UFormImportPattern.pas

    r27 r28  
    1616    ButtonCancel: TButton;
    1717    ButtonOk: TButton;
     18    CheckBoxRepetition: TCheckBox;
    1819    ComboBoxAction: TComboBox;
    1920    ComboBoxVariable: TComboBox;
     
    7879  Pattern.Variable := TImportVariable(ComboBoxVariable.ItemIndex);
    7980  Pattern.Flag := TImportPatternFlag(ComboBoxAction.ItemIndex);
     81  Pattern.Repetition := CheckBoxRepetition.Checked;
    8082end;
    8183
     
    8688  ComboBoxVariable.ItemIndex := Integer(Pattern.Variable);
    8789  ComboBoxAction.ItemIndex := Integer(Pattern.Flag);
     90  CheckBoxRepetition.Checked := Pattern.Repetition;
    8891end;
    8992
  • trunk/Forms/UFormImportSource.lfm

    r22 r28  
    1010  object EditName: TEdit
    1111    Left = 160
    12     Height = 34
     12    Height = 28
    1313    Top = 10
    1414    Width = 432
     
    1818  object Label1: TLabel
    1919    Left = 10
    20     Height = 24
     20    Height = 20
    2121    Top = 9
    22     Width = 56
     22    Width = 43
    2323    Caption = 'Name:'
    2424    ParentColor = False
     
    2626  object Label2: TLabel
    2727    Left = 8
    28     Height = 24
     28    Height = 20
    2929    Top = 48
    30     Width = 101
     30    Width = 78
    3131    Caption = 'Source URL:'
    3232    ParentColor = False
     
    3434  object EditURL: TEdit
    3535    Left = 160
    36     Height = 34
     36    Height = 28
    3737    Top = 49
    3838    Width = 432
     
    6262  object Label3: TLabel
    6363    Left = 11
    64     Height = 24
     64    Height = 20
    6565    Top = 96
    66     Width = 108
     66    Width = 84
    6767    Caption = 'Data format:'
    6868    ParentColor = False
     
    7070  object ComboBox1: TComboBox
    7171    Left = 160
    72     Height = 36
     72    Height = 28
    7373    Top = 91
    74     Width = 432
     74    Width = 304
    7575    Anchors = [akTop, akLeft, akRight]
    76     ItemHeight = 0
     76    ItemHeight = 20
    7777    Style = csDropDownList
    7878    TabOrder = 4
    7979  end
     80  object ButtonShowFormat: TButton
     81    Left = 472
     82    Height = 25
     83    Top = 91
     84    Width = 120
     85    Anchors = [akTop, akRight]
     86    Caption = 'Configure'
     87    OnClick = ButtonShowFormatClick
     88    TabOrder = 5
     89  end
    8090end
  • trunk/Forms/UFormImportSource.lrt

    r22 r28  
    55TFORMIMPORTSOURCE.BUTTONCANCEL.CAPTION=Cancel
    66TFORMIMPORTSOURCE.LABEL3.CAPTION=Data format:
     7TFORMIMPORTSOURCE.BUTTONSHOWFORMAT.CAPTION=Configure
  • trunk/Forms/UFormImportSource.pas

    r22 r28  
    1414
    1515  TFormImportSource = class(TForm)
     16    ButtonShowFormat: TButton;
    1617    ButtonOk: TButton;
    1718    ButtonCancel: TButton;
     
    2223    Label2: TLabel;
    2324    Label3: TLabel;
     25    procedure ButtonShowFormatClick(Sender: TObject);
    2426  private
    2527    { private declarations }
     
    3739
    3840uses
    39   UFormMain;
     41  UFormMain, UFormImportFormat;
    4042
    4143{ TFormImportSource }
     44
     45procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
     46var
     47  NewImportFormat: TImportFormat;
     48begin
     49  if ComboBox1.ItemIndex <> -1 then begin
     50    NewImportFormat := TImportFormat.Create;
     51    NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
     52    FormImportFormat.Load(NewImportFormat);
     53    if FormImportFormat.ShowModal = mrOk then begin
     54      FormImportFormat.Save(NewImportFormat);
     55      TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
     56      FormMain.AcronymDb.Modified := True;
     57      ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
     58    end;
     59    if Assigned(NewImportFormat) then NewImportFormat.Free;
     60  end;
     61end;
    4262
    4363procedure TFormImportSource.Load(ImportSource: TImportSource);
  • trunk/Forms/UFormImportSources.pas

    r22 r28  
    146146procedure TFormImportSources.AProcessExecute(Sender: TObject);
    147147begin
    148   if Assigned(ListView1.Selected) then
     148  if Assigned(ListView1.Selected) then begin
    149149    TImportSource(ListView1.Selected.Data).Process;
     150    ShowMessage(Format(SAddedCount, [TImportSource(ListView1.Selected.Data).ItemCount]));
     151  end;
    150152end;
    151153
  • trunk/Forms/UFormMain.pas

    r27 r28  
    119119  FormMain: TFormMain;
    120120
     121resourcestring
     122  SAddedCount = 'Imported %d acronyms';
     123
     124
    121125implementation
    122126
     
    252256var
    253257  I: Integer;
    254 begin
    255   for I := 0 to AcronymDb.ImportSources.Count - 1 do
     258  TotalItemCount: Integer;
     259begin
     260  TotalItemCount := 0;
     261  for I := 0 to AcronymDb.ImportSources.Count - 1 do begin
    256262    TImportSource(AcronymDb.ImportSources[I]).Process;
     263    TotalItemCount := TotalItemCount + TImportSource(AcronymDb.ImportSources[I]).ItemCount;
     264  end;
     265  ShowMessage(Format(SAddedCount, [TotalItemCount]));
    257266  UpdateAcronymsList;
    258267  UpdateInterface;
  • trunk/Languages/AcronymDecoder.cs.po

    r27 r28  
    261261msgstr ""
    262262
     263#: tformimportformat.listviewitemrules.columns[4].caption
     264msgctxt "tformimportformat.listviewitemrules.columns[4].caption"
     265msgid "Repetition"
     266msgstr ""
     267
    263268#: tformimportformats.aadd.caption
    264269msgctxt "tformimportformats.aadd.caption"
     
    302307msgstr ""
    303308
     309#: tformimportpattern.checkboxrepetition.caption
     310msgctxt "tformimportpattern.checkboxrepetition.caption"
     311msgid "Repetition"
     312msgstr ""
     313
    304314#: tformimportpattern.label10.caption
    305315msgid "Action:"
     
    328338msgstr "Ok"
    329339
     340#: tformimportsource.buttonshowformat.caption
     341msgid "Configure"
     342msgstr ""
     343
    330344#: tformimportsource.caption
    331345msgctxt "tformimportsource.caption"
     
    587601msgstr "Importováno %d nových zkratek."
    588602
     603#: uformimportformat.sno
     604msgid "No"
     605msgstr ""
     606
    589607#: uformimportformat.sremoveimportpattern
    590608msgid "Remove import pattern"
     
    593611#: uformimportformat.sremoveimportpatternquery
    594612msgid "Do you really want to remove selected import patterns?"
     613msgstr ""
     614
     615#: uformimportformat.syes
     616msgid "Yes"
    595617msgstr ""
    596618
     
    622644msgstr "Opravdu chcete odebrat vybrané zdroje importu?"
    623645
     646#: uformmain.saddedcount
     647msgid "Imported %d acronyms"
     648msgstr ""
     649
    624650#: uformmain.sappexit
    625651msgid "Application exit"
  • trunk/Languages/AcronymDecoder.po

    r27 r28  
    246246msgstr ""
    247247
     248#: tformimportformat.listviewitemrules.columns[4].caption
     249msgctxt "TFORMIMPORTFORMAT.LISTVIEWITEMRULES.COLUMNS[4].CAPTION"
     250msgid "Repetition"
     251msgstr ""
     252
    248253#: tformimportformats.aadd.caption
    249254msgctxt "TFORMIMPORTFORMATS.AADD.CAPTION"
     
    285290msgstr ""
    286291
     292#: tformimportpattern.checkboxrepetition.caption
     293msgctxt "tformimportpattern.checkboxrepetition.caption"
     294msgid "Repetition"
     295msgstr ""
     296
    287297#: tformimportpattern.label10.caption
    288298msgid "Action:"
     
    311321msgstr ""
    312322
     323#: tformimportsource.buttonshowformat.caption
     324msgid "Configure"
     325msgstr ""
     326
    313327#: tformimportsource.caption
    314328msgctxt "tformimportsource.caption"
     
    570584msgstr ""
    571585
     586#: uformimportformat.sno
     587msgid "No"
     588msgstr ""
     589
    572590#: uformimportformat.sremoveimportpattern
    573591msgid "Remove import pattern"
     
    576594#: uformimportformat.sremoveimportpatternquery
    577595msgid "Do you really want to remove selected import patterns?"
     596msgstr ""
     597
     598#: uformimportformat.syes
     599msgid "Yes"
    578600msgstr ""
    579601
     
    605627msgstr ""
    606628
     629#: uformmain.saddedcount
     630msgid "Imported %d acronyms"
     631msgstr ""
     632
    607633#: uformmain.sappexit
    608634msgid "Application exit"
  • trunk/UAcronym.pas

    r27 r28  
    77uses
    88  Classes, SysUtils, Contnrs, XMLConf, XMLRead, XMLWrite, DOM, UXMLUtils,
    9   SpecializedList, fphttpclient;
     9  SpecializedList, fphttpclient, Dialogs;
    1010
    1111type
     
    119119    Variable: TImportVariable;
    120120    Flag: TImportPatternFlag;
     121    Repetition: Boolean;
    121122    procedure Assign(Source: TImportPattern);
    122123    procedure SaveToNode(Node: TDOMNode);
     
    167168    LastTime: TDateTime;
    168169    Sources: TImportSources;
     170    ItemCount: Integer;
    169171    function DownloadHTTP(URL: string; Stream: TStream): Boolean;
    170172    procedure Process;
     
    265267  Variable := Source.Variable;
    266268  Flag := Source.Flag;
     269  Repetition := Source.Repetition;
    267270end;
    268271
     
    273276  WriteInteger(Node, 'Variable', Integer(Variable));
    274277  WriteInteger(Node, 'Flag', Integer(Flag));
     278  WriteBoolean(Node, 'Repetition', Repetition);
    275279end;
    276280
     
    281285  Variable := TImportVariable(ReadInteger(Node, 'Variable', 0));
    282286  Flag := TImportPatternFlag(ReadInteger(Node, 'Flag', 0));
     287  Repetition := ReadBoolean(Node, 'Repetition', False);
    283288end;
    284289
     
    295300var
    296301  HTTPClient: TFPHTTPClient;
     302  FormData: TStringList;
    297303begin
    298304  HTTPClient := TFPHttpClient.Create(nil);
    299305  HTTPClient.OnPassword := DoPassword;
     306  FormData := TStringList.Create;
     307(*
     308FormData.action=clientlogin
     309  &loginreturnurl=http://example.com/&
     310  logintoken=29590a3037d325be70b93fb8258ed29257448cfb%2B%5C&
     311  username=Bob&
     312  password=secret&
     313  rememberMe=1
     314  HTTPClient.FormPost(URL, FormData, Stream);
     315  *)
    300316  HTTPClient.Get(URL, Stream);
     317  FormData.Free;
    301318  HTTPClient.Free;
    302319  Result := True;
     
    502519  NewAcronym: TAcronymEntry;
    503520  P: Integer;
     521  P1, P2: Integer;
    504522  Q: Integer;
    505523  I: Integer;
     
    507525  LastLength: Integer;
    508526begin
     527  ItemCount := 0;
    509528  Stream := TMemoryStream.Create;
    510529  NewAcronym := TAcronymEntry.Create;
     
    547566      repeat
    548567        LastLength := Length(S);
    549         for I := 0 to Format.ItemPatterns.Count - 1 do
    550         with TImportPattern(Format.ItemPatterns[I]) do
    551         if Flag <> ipfSkip then begin
    552           if Length(StartString) > 0 then begin
    553             P := Pos(StartString, S);
    554             if P > 0 then Delete(S, 1, P + Length(StartString) - 1);
     568        I := 0;
     569        while I < Format.ItemPatterns.Count do
     570        with TImportPattern(Format.ItemPatterns[I]) do begin
     571          if Flag <> ipfSkip then begin
     572            if Length(StartString) > 0 then begin
     573              P := Pos(StartString, S);
     574              if P > 0 then Delete(S, 1, P + Length(StartString) - 1);
     575            end;
     576
     577            if ((Length(StartString) > 0) and (P > 0)) or (Length(StartString) = 0) then begin
     578              P := Pos(EndString, S);
     579              T := StripHTML(Copy(S, 1, P - 1));
     580              T := StringReplace(T, '&quot;', '"', [rfReplaceAll]);
     581              T := StringReplace(T, '&trade;', 'TM', [rfReplaceAll]);
     582              T := StringReplace(T, '&amp;', '&', [rfReplaceAll]);
     583              T := StringReplace(T, '&#160;', ' ', [rfReplaceAll]); // No break space
     584              T := Trim(T);
     585              case Variable of
     586                ivAcronym: NewAcronym.Name := T;
     587                ivMeaning: NewAcronym.Meaning := T;
     588              end;
     589              Delete(S, 1, P + Length(EndString) - 1);
     590
     591              if (Flag = ipfNewItem) and (Trim(NewAcronym.Name) <> '') and
     592                (Trim(NewAcronym.Meaning) <> '') then begin
     593                  Sources.AcronymDb.AddAcronym(NewAcronym.Name, NewAcronym.Meaning);
     594                  Inc(ItemCount);
     595                end;
     596
     597              if Repetition then begin
     598                if Length(StartString) > 0 then begin
     599                  P1 := Pos(StartString, S);
     600                  if P1 > 0 then begin
     601                    P2 := Pos(TImportPattern(Format.ItemPatterns[(I + 1) mod Format.ItemPatterns.Count]).StartString, S);
     602                    if (P2 > 0) and (P1 < P2) then Continue;
     603                  end;
     604                end;
     605              end;
     606            end;
    555607          end;
    556 
    557           if ((Length(StartString) > 0) and (P > 0)) or (Length(StartString) = 0) then begin
    558             P := Pos(EndString, S);
    559             T := StripHTML(Copy(S, 1, P - 1));
    560             T := StringReplace(T, '&quot;', '"', [rfReplaceAll]);
    561             T := StringReplace(T, '&trade;', 'TM', [rfReplaceAll]);
    562             T := StringReplace(T, '&amp;', '&', [rfReplaceAll]);
    563             T := Trim(T);
    564             case Variable of
    565               ivAcronym: NewAcronym.Name := T;
    566               ivMeaning: NewAcronym.Meaning := T;
    567             end;
    568             Delete(S, 1, P + Length(EndString) - 1);
    569 
    570             if (Flag = ipfNewItem) and (Trim(NewAcronym.Name) <> '') and
    571               (Trim(NewAcronym.Meaning) <> '') then
    572               Sources.AcronymDb.AddAcronym(NewAcronym.Name, NewAcronym.Meaning);
    573           end;
     608          Inc(I);
    574609        end;
    575610      until Length(S) = LastLength;
Note: See TracChangeset for help on using the changeset viewer.