Ignore:
Timestamp:
Mar 9, 2012, 1:09:52 PM (12 years ago)
Author:
chronos
Message:
  • Fixed: Selection of available protocols in profile manager.
  • Modified: Initialization of persistent data structures rewrited to more native structures.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormLoginProfile.pas

    r42 r43  
    1010
    1111type
    12   TConnectProtocol = (cpXMLRPC, cpDirect);
     12  TConnectProtocol = (cpXMLRPC, cpDirect, cpMySQL);
    1313
    1414  { TConnectProfile }
     
    5151    Label5: TLabel;
    5252    LabelServer: TLabel;
    53     ListBox1: TListBox;
     53    ListBoxProfiles: TListBox;
    5454    Panel1: TPanel;
    5555    SpinEditPort: TSpinEdit;
     
    6565    procedure FormDestroy(Sender: TObject);
    6666    procedure FormShow(Sender: TObject);
    67     procedure ListBox1SelectionChange(Sender: TObject; User: boolean);
     67    procedure ListBoxProfilesSelectionChange(Sender: TObject; User: boolean);
    6868    procedure SpinEditPortChange(Sender: TObject);
    6969  private
     
    7676  SProfile = 'Profile';
    7777  SProtocolXMLRPC = 'XML-RPC';
     78  SProtocolMySQL = 'MySQL';
     79  SProtocolDirect = 'Direct';
    7880
    7981var
    8082  LoginProfileForm: TLoginProfileForm;
     83  ProtocolTypeText: array[TConnectProtocol] of string;
     84
     85procedure UpdateTranslation;
    8186
    8287implementation
     
    123128procedure TLoginProfileForm.ComboBoxProtocolChange(Sender: TObject);
    124129begin
    125   if ListBox1.ItemIndex <> - 1 then
    126     TConnectProfile(ProfileList[ListBox1.ItemIndex]).Protocol := TConnectProtocol(ComboBoxProtocol.ItemIndex);
     130  if ListBoxProfiles.ItemIndex <> - 1 then
     131    TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).Protocol :=
     132      TConnectProtocol(ComboBoxProtocol.Items.Objects[ComboBoxProtocol.ItemIndex]);
    127133end;
    128134
    129135procedure TLoginProfileForm.EditNameChange(Sender: TObject);
    130136begin
    131   if ListBox1.ItemIndex <> - 1 then begin
    132     TConnectProfile(ProfileList[ListBox1.ItemIndex]).Name := EditName.Text;
    133     ListBox1.Items[ListBox1.ItemIndex] := EditName.Text;
     137  if ListBoxProfiles.ItemIndex <> - 1 then begin
     138    TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).Name := EditName.Text;
     139    ListBoxProfiles.Items[ListBoxProfiles.ItemIndex] := EditName.Text;
    134140  end;
    135141end;
     
    137143procedure TLoginProfileForm.EditDatabaseChange(Sender: TObject);
    138144begin
    139   if ListBox1.ItemIndex <> - 1 then
    140     TConnectProfile(ProfileList[ListBox1.ItemIndex]).Database := EditDatabase.Text;
     145  if ListBoxProfiles.ItemIndex <> - 1 then
     146    TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).Database := EditDatabase.Text;
    141147end;
    142148
    143149procedure TLoginProfileForm.EditServerChange(Sender: TObject);
    144150begin
    145   if ListBox1.ItemIndex <> - 1 then
    146     TConnectProfile(ProfileList[ListBox1.ItemIndex]).HostName := EditServer.Text;
     151  if ListBoxProfiles.ItemIndex <> - 1 then
     152    TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).HostName := EditServer.Text;
    147153end;
    148154
     
    156162begin
    157163  ProfileList.AddNew(TConnectProfile.Create);
    158   ListBox1.Items.AddObject(TConnectProfile(ProfileList.Last).Name,
     164  ListBoxProfiles.Items.AddObject(TConnectProfile(ProfileList.Last).Name,
    159165    TConnectProfile(ProfileList.Last));
    160166end;
     
    162168procedure TLoginProfileForm.ButtonDeleteClick(Sender: TObject);
    163169begin
    164   if ListBox1.ItemIndex <> - 1 then begin
    165     ProfileList.Delete(ListBox1.ItemIndex);
    166     ListBox1.Items.Delete(ListBox1.ItemIndex);
     170  if ListBoxProfiles.ItemIndex <> - 1 then begin
     171    ProfileList.Delete(ListBoxProfiles.ItemIndex);
     172    ListBoxProfiles.Items.Delete(ListBoxProfiles.ItemIndex);
    167173  end;
    168174end;
     
    178184begin
    179185  ComboBoxProtocol.Clear;
    180   ComboBoxProtocol.Items.Add(SProtocolXMLRPC);
     186  for I := 0 to Integer(High(ProtocolTypeText)) do
     187    ComboBoxProtocol.Items.AddObject(ProtocolTypeText[TConnectProtocol(I)],
     188      Pointer(I));
    181189
    182190  MainForm.PersistentForm.Load(Self);
    183191  ProfileList.Assign(Core.Profiles);
    184   ProfileList.FillStrings(ListBox1.Items);
    185   if Core.LastProfile < ListBox1.Count then
    186     ListBox1.ItemIndex := Core.LastProfile;
    187   if (ListBox1.Items.Count > 0) and
    188     (ListBox1.ItemIndex = -1) then ListBox1.ItemIndex := 0;
    189 end;
    190 
    191 procedure TLoginProfileForm.ListBox1SelectionChange(Sender: TObject;
     192  ProfileList.FillStrings(ListBoxProfiles.Items);
     193  if Core.LastProfile < ListBoxProfiles.Count then
     194    ListBoxProfiles.ItemIndex := Core.LastProfile;
     195  if (ListBoxProfiles.Items.Count > 0) and
     196    (ListBoxProfiles.ItemIndex = -1) then ListBoxProfiles.ItemIndex := 0;
     197end;
     198
     199procedure TLoginProfileForm.ListBoxProfilesSelectionChange(Sender: TObject;
    192200  User: boolean);
    193201begin
    194   if ListBox1.ItemIndex <> -1 then
    195   with TConnectProfile(ProfileList[ListBox1.ItemIndex]) do begin
     202  if ListBoxProfiles.ItemIndex <> -1 then
     203  with TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]) do begin
    196204    EditServer.Text := HostName;
    197205    EditDatabase.Text := Database;
    198     ComboBoxProtocol.ItemIndex := Integer(Protocol);
     206    ComboBoxProtocol.ItemIndex := ComboBoxProtocol.Items.IndexOfObject(Pointer(Protocol));
    199207    SpinEditPort.Value := Port;
    200208    EditName.Text := Name;
     
    204212procedure TLoginProfileForm.SpinEditPortChange(Sender: TObject);
    205213begin
    206   if ListBox1.ItemIndex <> - 1 then
    207     TConnectProfile(ProfileList[ListBox1.ItemIndex]).Port := SpinEditPort.Value;
     214  if ListBoxProfiles.ItemIndex <> - 1 then
     215    TConnectProfile(ProfileList[ListBoxProfiles.ItemIndex]).Port := SpinEditPort.Value;
    208216end;
    209217
     
    281289end;
    282290
     291procedure UpdateTranslation;
     292begin
     293  ProtocolTypeText[cpXMLRPC] := SProtocolXMLRPC;
     294  ProtocolTypeText[cpMySQL] := SProtocolMySQL;
     295  ProtocolTypeText[cpDirect] := SProtocolDirect;
     296end;
     297
    283298end.
    284299
Note: See TracChangeset for help on using the changeset viewer.