OSDN Git Service

This commit was manufactured by cvs2svn to create branch 'Bb55'.
[gikonavigoeson/gikonavi.git] / NewBoard.pas
index 9b1cff0..a242402 100644 (file)
@@ -6,7 +6,7 @@ uses
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
        Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
        IdTCPConnection, IdTCPClient, IdHTTP, IDException, StdCtrls, IniFiles,
-       GikoSystem, BoardGroup, MojuUtils;
+       GikoSystem, BoardGroup;
 
 type
        TNewBoardItem = record
@@ -22,27 +22,29 @@ type
                Indy: TIdHTTP;
                IdAntiFreeze: TIdAntiFreeze;
                StopButton: TButton;
-               Label2: TLabel;
        BoardURLComboBox: TComboBox;
        Label13: TLabel;
        EditIgnoreListsButton: TButton;
+       Label2: TLabel;
                procedure UpdateButtonClick(Sender: TObject);
                procedure StopButtonClick(Sender: TObject);
                procedure CloseButtonClick(Sender: TObject);
                procedure FormCreate(Sender: TObject);
        procedure EditIgnoreListsButtonClick(Sender: TObject);
-    procedure FormClose(Sender: TObject; var Action: TCloseAction);
+       procedure FormClose(Sender: TObject; var Action: TCloseAction);
        private
                { Private \90é\8c¾ }
                IgnoreLists : TStringList;
                FAbort: Boolean;
-               function BoardDownload: TNewBoardItem;
-               procedure UpdateURL(s: string);
+               function BoardDownload(const URL: String): TNewBoardItem;
+               function BoardLoardFromFile(const FilePath: String): String;
+               function UpdateURL(s: string): boolean;
                procedure SetIgnoreCategory(b: boolean);
                procedure EditIgnoreList(Sender: TObject);
                procedure UpdateIgnoreList(Sender: TObject);
        public
                { Public \90é\8c¾ }
+        class procedure InitHTTPClient(client : TIdHTTP);
        end;
 
 var
@@ -51,33 +53,53 @@ var
 
 implementation
 
-uses Giko, IdHeaderList;
+uses Giko, IdHeaderList, MojuUtils, GikoDataModule;
 
 {$R *.dfm}
 
 procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject);
 var
        Item: TNewBoardItem;
+       URL : String;
+       protocol, host, path, document, port, bookmark: String;
+    TabURLs: TStringList;
 begin
        try
-        GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1;
+               MessageMemo.Clear;
+               GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1;
                FAbort := False;
                UpdateButton.Enabled := False;
                StopButton.Enabled := True;
                CloseButton.Enabled := False;
-               Item := BoardDownload;
+               EditIgnoreListsButton.Enabled := False;
+               URL := BoardURLComboBox.Text;
+               GikoSys.ParseURI(URL, protocol, host, path, document, port, bookmark);
+               if (protocol = '') then begin
+                       Item.FContent := BoardLoardFromFile(URL);
+               end else if (AnsiPos('http', protocol) > 0) then begin
+                       Item := BoardDownload(URL);
+               end;
                StopButton.Enabled := False;
                if FAbort then
                        Exit;
                if Item.FContent <> '' then begin
-                       UpdateURL(Item.FContent);
-                       GikoForm.ReloadBBS;
+            TabURLs := TStringList.Create;
+            try
+                GikoDM.GetTabURLs(TabURLs);
+                       if (UpdateURL(Item.FContent)) then begin
+                               GikoForm.ReloadBBS;
+                           end;
+                GikoDM.OpenURLs(TabURLs);
+            finally
+                       TabURLs.Free;
+            end;
                end else
                        MessageMemo.Lines.Add('\83_\83E\83\93\83\8d\81[\83h\82ª\8e¸\94s\82µ\82Ü\82µ\82½[' + IntToStr(Item.FResponseCode) + ']');
        finally
                UpdateButton.Enabled := True;
                StopButton.Enabled := False;
                CloseButton.Enabled := True;
+               EditIgnoreListsButton.Enabled := True;
        end;
 end;
 
@@ -92,40 +114,14 @@ begin
        Close;
 end;
 
-function TNewBoardDialog.BoardDownload: TNewBoardItem;
+function TNewBoardDialog.BoardDownload(const URL: String): TNewBoardItem;
 var
-       URL: string;
        Stream: TMemoryStream;
        s: string;
        i: Integer;
 begin
-       MessageMemo.Clear;
-       Indy.Request.Clear;
-       Indy.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
-       Indy.ProxyParams.BasicAuthentication := False;
-       if GikoSys.Setting.ReadProxy then begin
-               if GikoSys.Setting.ProxyProtocol then
-                       Indy.ProtocolVersion := pv1_1
-               else
-                       Indy.ProtocolVersion := pv1_0;
-               Indy.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
-               Indy.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
-               Indy.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
-               Indy.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
-               if GikoSys.Setting.ReadProxyUserID <> '' then
-                       Indy.ProxyParams.BasicAuthentication := True;
-       end else begin
-               if GikoSys.Setting.Protocol then
-                       Indy.ProtocolVersion := pv1_1
-               else
-                       Indy.ProtocolVersion := pv1_0;
-               Indy.ProxyParams.ProxyServer := '';
-               Indy.ProxyParams.ProxyPort := 80;
-               Indy.ProxyParams.ProxyUsername := '';
-               Indy.ProxyParams.ProxyPassword := '';
-       end;
-       //URL := GikoSys.Setting.BoardURL2ch;
-    URL := BoardURLComboBox.Text;
+    InitHTTPClient( Indy );
+
        Indy.Request.UserAgent := GikoSys.GetUserAgent;
        Indy.Request.Referer := '';
        Indy.Request.AcceptEncoding := 'gzip';
@@ -139,9 +135,14 @@ begin
                try
                        MessageMemo.Lines.Add('\88È\89º\82Ì\8fê\8f\8a\82©\82ç\8eæ\93¾\82µ\82Ü\82·');
                        //MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch);
-            MessageMemo.Lines.Add(URL);
+                       MessageMemo.Lines.Add(URL);
                        MessageMemo.Lines.Add('\83_\83E\83\93\83\8d\81[\83h\82ð\8aJ\8en\82µ\82Ü\82·');
-                       Indy.Get(URL, Stream);
+                       IdAntiFreeze.Active := True;
+                       try
+                               Indy.Get(URL, Stream);
+                       finally
+                               IdAntiFreeze.Active := False;
+                       end;
                        Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding);
                        MessageMemo.Lines.Add('\83_\83E\83\93\83\8d\81[\83h\82ª\8a®\97¹\82µ\82Ü\82µ\82½');
                except
@@ -175,10 +176,9 @@ begin
        end;
 end;
 
-procedure TNewBoardDialog.UpdateURL(s: string);
+function TNewBoardDialog.UpdateURL(s: string): boolean;
 var
        i: Integer;
-//     j: Integer;
        idx: Integer;
        idx1: Integer;
        idx2: Integer;
@@ -314,6 +314,7 @@ begin
        oldURLs.Free;
        newURLs.Free;
        end;
+       Result := Change;
 end;
 
 procedure TNewBoardDialog.FormCreate(Sender: TObject);
@@ -373,7 +374,7 @@ procedure TNewBoardDialog.UpdateIgnoreList(Sender: TObject);
 var
        i: Integer;
 begin
-       Label2.Caption := '\81¦\8c»\8dÝ\81A\8aJ\82¢\82Ä\82¢\82é\83^\83u\82â\83q\83X\83g\83\8a\82È\82Ç\82Í\94Â\8dX\90V\8e\9e\82É\83N\83\8a\83A\82³\82ê\82Ü\82·';
+       Label2.Caption := '';
     UpdateButton.Enabled := true;
        EditIgnoreListsButton.Caption := '\8f\9c\8aO\83J\83e\83S\83\8a\81[\95Ò\8fW';
        IgnoreLists.Clear;
@@ -392,5 +393,50 @@ procedure TNewBoardDialog.FormClose(Sender: TObject;
 begin
        IgnoreLists.Free;
 end;
+//! \83\8d\81[\83J\83\8b\83t\83@\83C\83\8b\82ð\83\8d\81[\83h\82·\82é
+function TNewBoardDialog.BoardLoardFromFile(const FilePath: String): String;
+var
+       html : TStringList;
+begin
+       Result := '';
+       // \83t\83@\83C\83\8b\82ª\91\8dÝ\82µ\82Ä\82¢\82é\82©\83`\83F\83b\83N
+       if (FileExists(FilePath)) then begin
+               html := TStringList.Create();
+               try
+                       html.LoadFromFile(FilePath);
+                       Result := html.Text;
+               finally
+                       html.Free;
+               end;
+       end;
+end;
 
+class procedure TNewBoardDialog.InitHTTPClient(client : TIdHTTP);
+begin
+       client.Request.Clear;
+    client.Request.CustomHeaders.Clear;
+       client.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
+       client.ProxyParams.BasicAuthentication := False;
+       if GikoSys.Setting.ReadProxy then begin
+               if GikoSys.Setting.ProxyProtocol then
+                       client.ProtocolVersion := pv1_1
+               else
+                       client.ProtocolVersion := pv1_0;
+               client.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
+               client.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
+               client.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
+               client.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
+               if GikoSys.Setting.ReadProxyUserID <> '' then
+                       client.ProxyParams.BasicAuthentication := True;
+       end else begin
+               if GikoSys.Setting.Protocol then
+                       client.ProtocolVersion := pv1_1
+               else
+                       client.ProtocolVersion := pv1_0;
+               client.ProxyParams.ProxyServer := '';
+               client.ProxyParams.ProxyPort := 80;
+               client.ProxyParams.ProxyUsername := '';
+               client.ProxyParams.ProxyPassword := '';
+       end;
+end;
 end.