OSDN Git Service

・板一覧更新の処理メッセージを追加
[gikonavigoeson/gikonavi.git] / AbonInfoSet.pas
1 unit AbonInfoSet;
2
3 interface
4
5 uses
6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7   Dialogs, AbonInfo, StdCtrls, ExtCtrls;
8
9 type
10   TAbonInfoEdit = class(TForm)
11     AbonTypeRadio: TRadioGroup;
12     CompTypeRadio: TRadioGroup;
13     GroupBox1: TGroupBox;
14     AllRadio: TRadioButton;
15     ThreadRadio: TRadioButton;
16     BoardRadio: TRadioButton;
17     ThrNameEdit: TEdit;
18     ThrIDEdit: TEdit;
19     BrdNameEdit: TEdit;
20     BrdIDEdit: TEdit;
21     OkButton: TButton;
22     CancelButton: TButton;
23     ThrSelButton: TButton;
24     BrdSelButton: TButton;
25     procedure FormShow(Sender: TObject);
26     procedure TargetRadioClick(Sender: TObject);
27     procedure OkButtonClick(Sender: TObject);
28     procedure FormCreate(Sender: TObject);
29     procedure FormDestroy(Sender: TObject);
30     procedure ThrSelButtonClick(Sender: TObject);
31     procedure BrdSelButtonClick(Sender: TObject);
32   private
33     { Private \90é\8c¾ }
34     FInf: TLineInfo;
35     function GetThreadTitle(SrcID: String): String;
36     function GetBoardTitle(BrdID: String): String;
37   public
38     { Public \90é\8c¾ }
39
40     procedure SetInfo(const src: TLineInfo);
41     procedure GetInfo(var dst: TLineInfo);
42   end;
43
44 var
45   AbonInfoEdit: TAbonInfoEdit;
46
47 implementation
48
49 uses BoardGroup, BbsThrSel, GikoSystem;
50
51 {$R *.dfm}
52
53
54 procedure TAbonInfoEdit.FormCreate(Sender: TObject);
55 var
56     CenterForm: TCustomForm;
57 begin
58     CenterForm := TCustomForm(Owner);
59     if Assigned(CenterForm) then begin
60         Left := ((CenterForm.Width - Width) div 2) + CenterForm.Left;
61         Top := ((CenterForm.Height - Height) div 2) + CenterForm.Top;
62     end else begin
63         Left := (Screen.Width - Width) div 2;
64         Top := (Screen.Height - Height) div 2;
65     end;
66
67     FInf := TLineInfo.Create;
68 end;
69
70 procedure TAbonInfoEdit.FormDestroy(Sender: TObject);
71 begin
72     FInf.Free;
73 end;
74
75 procedure TAbonInfoEdit.SetInfo(const src: TLineInfo);
76 begin
77     FInf.Copy(src);
78 end;
79
80 procedure TAbonInfoEdit.GetInfo(var dst: TLineInfo);
81 begin
82     dst.Copy(FInf);
83 end;
84
85 procedure TAbonInfoEdit.FormShow(Sender: TObject);
86 begin
87     case FInf.AbonType of
88         atStandard:    AbonTypeRadio.ItemIndex := 0;
89         stTransparent: AbonTypeRadio.ItemIndex := 1;
90     end;
91
92     case FInf.CompType of
93         ctStandard: CompTypeRadio.ItemIndex := 0;
94         ctRegexp:   CompTypeRadio.ItemIndex := 1;
95     end;
96
97     case FInf.TargetType of
98         ttAll:    begin
99             AllRadio.Checked    := True;
100         end;
101         ttThread: begin
102             ThreadRadio.Checked := True;
103             ThrNameEdit.Text := GetThreadTitle(FInf.TargetThread);
104             ThrIDEdit.Text := FInf.TargetThread;
105         end;
106         ttBoard:  begin
107             BoardRadio.Checked  := True;
108             BrdNameEdit.Text := GetBoardTitle(FInf.TargetBoard);
109             BrdIDEdit.Text := FInf.TargetBoard;
110         end;
111     end;
112
113     TargetRadioClick(AllRadio);
114 end;
115
116 function TAbonInfoEdit.GetThreadTitle(SrcID: String): String;
117 var
118     ThrID: String;
119     BrdID: String;
120     Sep: Integer;
121     i: Integer;
122     j: Integer;
123     Brd: TBoard;
124 begin
125     Result := '';
126
127     if (SrcID = '') then
128         Exit;
129
130     Sep := Pos('/', SrcID);
131     if (Sep <= 0) then
132         Exit;
133
134     BrdID := Copy(SrcID, 1, Sep - 1);
135     ThrID := Copy(SrcID, Sep + 1, Length(SrcID) - Sep);
136
137     Brd := nil;
138     if (BBSs[0].IsBoardFileRead = False) then
139         GikoSys.ReadBoardFile(BBSs[0]);
140     for i := 0 to BBSs[0].Count - 1 do begin
141         for j := 0 to BBSs[0].Items[i].Count - 1 do begin
142             if (BrdID = BBSs[0].Items[i].Items[j].BBSID) then begin
143                 Brd := BBSs[0].Items[i].Items[j];
144                 Result := Brd.Title + '\81^';
145                 Break;
146             end;
147         end;
148     end;
149
150     if (Brd <> nil) then begin
151         if (Brd.IsThreadDatRead = False) then
152             GikoSys.ReadSubjectFile(Brd);
153         for i := 0 to Brd.Count - 1 do begin
154             if (ThrID = ChangeFileExt(Brd.Items[i].FileName, '')) then begin
155                 Result := Result + Brd.Items[i].Title;
156                 Break;
157             end;
158         end;
159     end;
160 end;
161
162
163 function TAbonInfoEdit.GetBoardTitle(BrdID: String): String;
164 var
165     i: Integer;
166     j: Integer;
167 begin
168     Result := '';
169
170     if (BrdID = '') then
171         Exit;
172
173     if (BBSs[0].IsBoardFileRead = False) then
174         GikoSys.ReadBoardFile(BBSs[0]);
175     for i := 0 to BBSs[0].Count - 1 do begin
176         for j := 0 to BBSs[0].Items[i].Count - 1 do begin
177             if (BrdID = BBSs[0].Items[i].Items[j].BBSID) then begin
178                 Result := BBSs[0].Items[i].Items[j].Title;
179                 Break;
180             end;
181         end;
182     end;
183 end;
184
185 procedure TAbonInfoEdit.TargetRadioClick(Sender: TObject);
186 begin
187     if (ThreadRadio.Checked = True) then begin
188         ThrNameEdit.Enabled := True;
189         ThrIDEdit.Enabled := True;
190         ThrSelButton.Enabled := True;
191         BrdNameEdit.Enabled := False;
192         BrdIDEdit.Enabled := False;
193         BrdSelButton.Enabled := False;
194     end else if (BoardRadio.Checked = True) then begin
195         ThrNameEdit.Enabled := False;
196         ThrIDEdit.Enabled := False;
197         ThrSelButton.Enabled := False;
198         BrdNameEdit.Enabled := True;
199         BrdIDEdit.Enabled := True;
200         BrdSelButton.Enabled := True;
201     end else begin
202         ThrNameEdit.Enabled := False;
203         ThrIDEdit.Enabled := False;
204         ThrSelButton.Enabled := False;
205         BrdNameEdit.Enabled := False;
206         BrdIDEdit.Enabled := False;
207         BrdSelButton.Enabled := False;
208     end;
209 end;
210
211 procedure TAbonInfoEdit.OkButtonClick(Sender: TObject);
212 begin
213     if (ThreadRadio.Checked = True) then begin
214         if (ThrIDEdit.Text = '') then begin
215             Application.MessageBox('\91Î\8fÛ\82Ì\83X\83\8c\83b\83h\82ð\8ew\92è\82µ\82½\82­\82¾\82³\82¢\81B', PChar(Caption), MB_OK or MB_ICONERROR);
216             Exit;
217         end;
218     end else if (BoardRadio.Checked = True) then begin
219         if (BrdIDEdit.Text = '') then begin
220             Application.MessageBox('\91Î\8fÛ\82Ì\94Â\82ð\8ew\92è\82µ\82½\82­\82¾\82³\82¢\81B', PChar(Caption), MB_OK or MB_ICONERROR);
221             Exit;
222         end;
223     end;
224
225     if (AbonTypeRadio.ItemIndex = 1) then
226         FInf.AbonType := stTransparent
227     else
228         FInf.AbonType := atStandard;
229
230     if (CompTypeRadio.ItemIndex = 1) then
231         FInf.CompType := ctRegexp
232     else
233         FInf.CompType := ctStandard;
234
235     if (ThreadRadio.Checked = True) then
236         FInf.TargetType := ttThread
237     else if (BoardRadio.Checked = True) then
238         FInf.TargetType := ttBoard
239     else
240         FInf.TargetType := ttAll;
241
242     FInf.TargetThread := ThrIDEdit.Text;
243     FInf.TargetBoard  := BrdIDEdit.Text;
244
245     ModalResult := mrOk;
246 end;
247
248 procedure TAbonInfoEdit.ThrSelButtonClick(Sender: TObject);
249 var
250     Dlg: TBbsThreadSel;
251     Sep: Integer;
252 begin
253     Dlg := TBbsThreadSel.Create(Self);
254     Dlg.ThreadMode := True;
255     Sep := Pos('/', ThrIDEdit.Text);
256     if (Sep > 0) then begin
257         Dlg.BoardID  := Copy(ThrIDEdit.Text, 1, Sep - 1);
258         Dlg.ThreadID := Copy(ThrIDEdit.Text, Sep + 1, Length(ThrIDEdit.Text) - Sep);
259     end;
260     if (Dlg.ShowModal = mrOk) then begin
261         ThrNameEdit.Text := Dlg.BoardTitle + '\81^' + Dlg.ThreadTitle;
262         ThrIDEdit.Text := Dlg.BoardID + '/' + Dlg.ThreadID;
263     end;
264     Dlg.Free;
265 end;
266
267 procedure TAbonInfoEdit.BrdSelButtonClick(Sender: TObject);
268 var
269     Dlg: TBbsThreadSel;
270 begin
271     Dlg := TBbsThreadSel.Create(Self);
272     Dlg.ThreadMode := False;
273     Dlg.BoardID := BrdIDEdit.Text;
274     if (Dlg.ShowModal = mrOk) then begin
275         BrdNameEdit.Text := Dlg.BoardTitle;
276         BrdIDEdit.Text := Dlg.BoardID;
277     end;
278     Dlg.Free;
279 end;
280
281 end.