OSDN Git Service

・お気に入りが URL 主体の保存になったので、
authoryoffy <yoffy>
Sat, 22 Nov 2003 15:10:18 +0000 (15:10 +0000)
committeryoffy <yoffy>
Sat, 22 Nov 2003 15:10:18 +0000 (15:10 +0000)
 TFavoriteBoardItem および TFavoriteThreadItem のコンストラクタは
 URL の引数無しでは呼び出せなくなった。

Favorite.pas
FavoriteAdd.pas

index 2b4e015..e028ee4 100644 (file)
@@ -14,18 +14,24 @@ type
        TFavoriteBoardItem = class
        private
                FItem                           : TBoard;
+               FURL                            : string;
                FTitle                  : string;
        public
+               constructor Create( inURL : string; inTitle : string = ''; inItem : TBoard = nil );
                property Item                           : TBoard        read FItem write FItem;
+               property URL                            : string        read FURL write FURL;   // Item \82ª\8eæ\93¾\82Å\82«\82È\82­\82Ä\82à URL \82Í\8fí\82É\95Û\8e\9d\82³\82ê\82é
                property Title                  : string        read FTitle write FTitle;
        end;
 
        TFavoriteThreadItem = class
        private
                FItem                           : TThreadItem;
+               FURL                            : string;
                FTitle                  : string;
        public
+               constructor Create( inURL : string; inTitle : string = ''; inItem : TThreadItem = nil );
                property Item                           : TThreadItem   read FItem write FItem;
+               property URL                            : string                        read FURL write FURL;   // Item \82ª\8eæ\93¾\82Å\82«\82È\82­\82Ä\82à URL \82Í\8fí\82É\95Û\8e\9d\82³\82ê\82é
                property Title                  : string                        read FTitle write FTitle;
        end;
 
@@ -47,8 +53,8 @@ type
 //             procedure SAXCharacters(Sender: TObject; const PCh: SAXString);
        public
                { Public \90é\8c¾ }
-        function GetFavoriteFilePath() : String;
-        function SaveFavoriteFile(FileName: String) : Boolean;
+                               function GetFavoriteFilePath() : String;
+                               function SaveFavoriteFile(FileName: String) : Boolean;
                procedure SetFavTreeView(TreeView: TTreeView);
                procedure ReadFavorite;
                procedure WriteFavorite;
@@ -70,6 +76,36 @@ const
 
 {$R *.dfm}
 
+constructor TFavoriteBoardItem.Create(
+       inURL           : string;
+       inTitle : string = '';
+       inItem  : TBoard = nil
+);
+begin
+
+       inherited Create;
+
+       URL             := inURL;
+       Title   := inTitle;
+       Item    := inItem;
+
+end;
+
+constructor TFavoriteThreadItem.Create(
+       inURL           : string;
+       inTitle : string = '';
+       inItem  : TThreadItem = nil
+);
+begin
+
+       inherited Create;
+
+       URL             := inURL;
+       Title   := inTitle;
+       Item    := inItem;
+
+end;
+
 procedure TFavoriteDM.DataModuleCreate(Sender: TObject);
 begin
        //FTreeView := TreeView;
@@ -164,15 +200,16 @@ end;
 procedure TFavoriteDM.ReadNode(Node: IXMLNode);
 var
        i: Integer;
-  j, jBound : Integer;
+       j, jBound : Integer;
 
        ParentNode: TTreeNode;
        CurrentNode: TTreeNode;
        FavFolder: TFavoriteFolder;
        FavBoard: TFavoriteBoardItem;
        FavThread: TFavoriteThreadItem;
-  board : TBoard;
-  url          : string;
+       board                           : TBoard;
+       threadItem      : TThreadItem;
+       url                                     : string;
 begin
        if Node.NodeName = 'folder' then begin
                ParentNode := FStack.Peek;
@@ -181,7 +218,7 @@ begin
                        CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavFolder);
                        CurrentNode.ImageIndex := 14;
                        CurrentNode.SelectedIndex := 14;
-      CurrentNode.Expanded := Node.Attributes[ 'expanded' ] = 'true';
+                       CurrentNode.Expanded := Node.Attributes[ 'expanded' ] = 'true';
                        FStack.Push(CurrentNode);
                end;
                for i := 0 to Node.ChildNodes.Count - 1 do begin
@@ -193,74 +230,70 @@ begin
                ParentNode := FStack.Peek;
                if TObject(ParentNode.Data) is TFavoriteFolder then begin
                        if Node.Attributes['favtype'] = 'board' then begin
-                               FavBoard                                                := TFavoriteBoardItem.Create;
-        FavBoard.Item                          := BBSsFindBoardFromURL( Node.Attributes[ 'url' ] );
-        // \8b\8c\8e®\82Ì\82¨\8bC\82É\93ü\82è\82Æ\82Ì\8cÝ\8a·\90«\82Ì\82½\82ß
-        if FavBoard.Item = nil then begin
-               if Node.Attributes[ 'url' ] = '' then begin
-            FavBoard.Item := BBSsFindBoardFromBBSID( Node.Attributes[ 'bbs' ] );
-            if FavBoard.Item = nil then begin
-              FavBoard.Free;
-              Exit;
-            end;
-          end else begin
-               // \81¦\8dì\82Á\82Ä\82à\81A\92Ç\89Á\82·\82é\83J\83e\83S\83\8a\82ª\96³\82¢\82Ì\82Å\8c\83\82µ\82­\95Û\97¯
-               //FavBoard.Item := TBoard.Create( nil, Node.Attributes[ 'url' ] );
-          end;
-        end;
-                               FavBoard.Title  := Node.Attributes['title'];
+                               board := BBSsFindBoardFromURL( Node.Attributes[ 'url' ] );
+                               // \8b\8c\8e®\82Ì\82¨\8bC\82É\93ü\82è\82Æ\82Ì\8cÝ\8a·\90«\82Ì\82½\82ß
+                               if board = nil then begin
+                                       if Node.Attributes[ 'url' ] = '' then begin
+                                               board := BBSsFindBoardFromBBSID( Node.Attributes[ 'bbs' ] );
+                                               if board = nil then
+                                                       Exit;
+                                       end else begin
+                                               // \81¦\8dì\82Á\82Ä\82à\81A\92Ç\89Á\82·\82é\83J\83e\83S\83\8a\82ª\96³\82¢\82Ì\82Å\8c\83\82µ\82­\95Û\97¯
+                                               board := TBoard.Create( nil, Node.Attributes[ 'url' ] );
+                                       end;
+                               end;
+                               FavBoard := TFavoriteBoardItem.Create( board.URL, Node.Attributes['title'], board );
                                CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavBoard);
                                CurrentNode.ImageIndex := 15;
                                CurrentNode.SelectedIndex := 15;
                        end else if Node.Attributes['favtype'] = 'thread' then begin
-       url                                                                             := Node.Attributes[ 'url' ];
-                               FavThread                                                       := TFavoriteThreadItem.Create;
-        FavThread.Item                         := BBSsFindThreadFromURL( url );
-        // \8b\8c\8e®\82Ì\82¨\8bC\82É\93ü\82è\82Æ\82Ì\8cÝ\8a·\90«\82Ì\82½\82ß
-        if FavThread.Item = nil then begin
-               if Node.Attributes[ 'url' ] = '' then begin
-            board := BBSsFindBoardFromBBSID( Node.Attributes[ 'bbs' ] );
-            if board = nil then begin
-              FavThread.Free;
-              Exit;
-            end;
-            if not board.IsThreadDatRead then
-              GikoSys.ReadSubjectFile( board );
-            FavThread.Item := board.Find( Node.Attributes[ 'thread' ] );
-            if FavThread.Item = nil then begin
-              FavThread.Item := TThreadItem.Create(
-                board.BoardPlugIn,
-                GikoSys.Get2chBoard2ThreadURL( board, ChangeFileExt( Node.Attributes[ 'thread' ], '' ) ) );
-              board.Add( FavThread.Item )
-            end;
-          end else begin
-               board := BBSsFindBoardFromURL( GikoSys.Get2chThreadURL2BoardURL( url ) );
-            if board <> nil then begin
-              //===== \83v\83\89\83O\83C\83\93
-              try
-                jBound := Length( BoardPlugIns ) - 1;
-                for j := 0 to jBound do begin
-                  if Assigned( Pointer( BoardPlugIns[ j ].Module ) ) then begin
-                    if BoardPlugIns[ j ].AcceptURL( url ) = atThread then begin
-                      FavThread.Item := TThreadItem.Create( BoardPlugIns[ j ], url );
-
-                      Break;
-                    end;
-                  end;
-                end;
-              except
-                // exception \82ª\94­\90\82µ\82½\8fê\8d\87\82Í\93à\95\94\8f\88\97\9d\82É\94C\82¹\82½\82¢\82Ì\82Å\82±\82±\82Å\82Í\89½\82à\82µ\82È\82¢
-              end;
-
-              //===== \93à\95\94
-              if FavThread.Item = nil then
-               FavThread.Item := TThreadItem.Create( nil, url );
-
-              board.Add( FavThread.Item );
-            end;
-          end;
-        end;
-                               FavThread.Title := Node.Attributes['title'];
+                               url                                     := Node.Attributes[ 'url' ];
+                               threadItem      := BBSsFindThreadFromURL( url );
+                               // \8b\8c\8e®\82Ì\82¨\8bC\82É\93ü\82è\82Æ\82Ì\8cÝ\8a·\90«\82Ì\82½\82ß
+                               if threadItem = nil then begin
+                                       if Node.Attributes[ 'url' ] = '' then begin
+                                               board := BBSsFindBoardFromBBSID( Node.Attributes[ 'bbs' ] );
+                                               if board = nil then
+                                                       Exit;
+                                               if not board.IsThreadDatRead then
+                                                       GikoSys.ReadSubjectFile( board );
+                                               threadItem := board.Find( Node.Attributes[ 'thread' ] );
+                                               if threadItem = nil then begin
+                                                       threadItem := TThreadItem.Create(
+                                                               board.BoardPlugIn,
+                                                               GikoSys.Get2chBoard2ThreadURL( board, ChangeFileExt( Node.Attributes[ 'thread' ], '' ) ) );
+                                                       board.Add( threadItem );
+                                               end;
+                                       end else begin
+                                               board := BBSsFindBoardFromURL( GikoSys.Get2chThreadURL2BoardURL( url ) );
+
+                                               //===== \83v\83\89\83O\83C\83\93
+                                               try
+                                                       jBound := Length( BoardPlugIns ) - 1;
+                                                       for j := 0 to jBound do begin
+                                                               if Assigned( Pointer( BoardPlugIns[ j ].Module ) ) then begin
+                                                                       if BoardPlugIns[ j ].AcceptURL( url ) = atThread then begin
+                                                                               threadItem := TThreadItem.Create( BoardPlugIns[ j ], url );
+
+                                                                               Break;
+                                                                       end;
+                                                               end;
+                                                       end;
+                                               except
+                                                       // exception \82ª\94­\90\82µ\82½\8fê\8d\87\82Í\93à\95\94\8f\88\97\9d\82É\94C\82¹\82½\82¢\82Ì\82Å\82±\82±\82Å\82Í\89½\82à\82µ\82È\82¢
+                                               end;
+
+                                               //===== \93à\95\94
+                                               if board = nil then
+                                                       // \81¦\8dì\82Á\82Ä\82à\81A\92Ç\89Á\82·\82é\83J\83e\83S\83\8a\82ª\96³\82¢\82Ì\82Å\8c\83\82µ\82­\95Û\97¯
+                                                       board := TBoard.Create( nil, Node.Attributes[ 'url' ] );
+
+                                               if threadItem = nil then
+                                                       threadItem := TThreadItem.Create( nil, url );
+                                               board.Add( threadItem );
+                                       end;
+                               end;
+                               FavThread := TFavoriteThreadItem.Create( threadItem.URL, Node.Attributes['title'], threadItem );
                                CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavThread);
                                CurrentNode.ImageIndex := 16;
                                CurrentNode.SelectedIndex := 16;
@@ -281,7 +314,7 @@ var
        XMLNode: IXMLNode;
 //     FavoNode: IXMLNode;
 begin
-       XMLDoc :=  NewXMLDocument;
+       XMLDoc :=       NewXMLDocument;
        XMLDoc.Encoding := 'Shift_JIS';
        XMLDoc.StandAlone := 'yes';
        XMLNode := XMLDoc.AddChild('favorite');
@@ -351,9 +384,9 @@ var
 begin
        for i := 0 to Node.Count - 1 do begin
                if TObject(Node.Item[i].Data) is TFavoriteFolder then begin
-       if Node.Item[ i ].Expanded then
+                       if Node.Item[ i ].Expanded then
                                s := Format('<folder title="%s" expanded="true">', [HttpEncode(Node.Item[i].Text)])
-      else
+                       else
                                s := Format('<folder title="%s" expanded="false">', [HttpEncode(Node.Item[i].Text)]);
                        SaveList.Add(s);
                        AddSaveString(Node.Item[i], SaveList);
@@ -361,12 +394,12 @@ begin
                end else if TObject(Node.Item[i].Data) is TFavoriteBoardItem then begin
                        FavBoard := TFavoriteBoardItem(Node.Item[i].Data);
                        s := Format('<favitem type="2ch" favtype="board" url="%s" title="%s"/>',
-                                                                       [HttpEncode( FavBoard.Item.URL ), HttpEncode(FavBoard.Title)]);
+                                                                       [HttpEncode( FavBoard.URL ), HttpEncode(FavBoard.Title)]);
                        SaveList.Add(s);
                end else if TObject(Node.Item[i].Data) is TFavoriteThreadItem then begin
                        FavThread := TFavoriteThreadItem(Node.Item[i].Data);
                        s := Format('<favitem type="2ch" favtype="thread" url="%s" title="%s"/>',
-                                                                       [HttpEncode( FavThread.Item.URL ), HttpEncode(FavThread.Title)]);
+                                                                       [HttpEncode( FavThread.URL ), HttpEncode(FavThread.Title)]);
                        SaveList.Add(s);
                end;
        end;
@@ -443,23 +476,23 @@ end;
 function TFavoriteDM.SaveFavoriteFile(FileName: String) : Boolean;
 var
        FavoriteFilePath: string;
-    tempStringList: TStringList;
+               tempStringList: TStringList;
 begin
 
        FavoriteFilePath := GikoSys.GetConfigDir + FAVORITE_FILE_NAME;
 
        if FileExists( FavoriteFilePath ) then begin
-        tempStringList := TStringList.Create;
+               tempStringList := TStringList.Create;
                try
-               tempStringList.LoadFromFile( FavoriteFilePath );
-            tempStringList.SaveToFile( FileName );
+                       tempStringList.LoadFromFile( FavoriteFilePath );
+                       tempStringList.SaveToFile( FileName );
                finally
-               tempStringList.Free;
+                       tempStringList.Free;
                end;
-        Result := true;
+               Result := true;
        end else begin
-       Result := false;
-    end;
+               Result := false;
+       end;
 end;
 
 function TFavoriteDM.GetFavoriteFilePath() : String;
index cac4dce..a4fc7cc 100644 (file)
@@ -114,16 +114,12 @@ begin
        FavNode := GetGikoFavoriteNode(FolderTreeView.Selected.Data);
        if FavNode <> nil then begin
                if FBoard <> nil then begin
-                       FavoBoardItem := TFavoriteBoardItem.Create;
-                       FavoBoardItem.Item := FBoard;
-                       FavoBoardItem.Title := FBoard.Title;
+                       FavoBoardItem := TFavoriteBoardItem.Create( FBoard.URL, FBoard.Title, FBoard );
                        Node := FavoriteDM.TreeView.Items.AddChildObject(FavNode, CaptionEdit.Text, FavoBoardItem);
                        Node.ImageIndex := 15;
                        Node.SelectedIndex := 15;
                end else if FThreadItem <> nil then begin
-                       FavoThreadItem := TFavoriteThreadItem.Create;
-                       FavoThreadItem.Item := FThreadItem;
-                       FavoThreadItem.Title := FThreadItem.Title;
+                       FavoThreadItem := TFavoriteThreadItem.Create( FThreadItem.URL, FThreadItem.Title, FThreadItem );
                        Node := FavoriteDM.TreeView.Items.AddChildObject(FavNode, CaptionEdit.Text, FavoThreadItem);
                        Node.ImageIndex := 16;
                        Node.SelectedIndex := 16;