2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "KnownFile.h" // Needed for CAbstractFile
37 typedef std::vector
<CSearchFile
*> CSearchResultList
;
41 * Represents a search-result returned from a server or client.
43 * A file may have either a parent or any number of children.
44 * When a child is added to a result, the parent becomes a generic
45 * representation of all its children, which will include a copy
46 * of the original result. The parent object will contain the sum
47 * of sources (total/complete) and will have the most common
48 * filename. Children are owned by their parents, and can be
49 * displayed on CSearchListCtrl.
51 * Basic file parameters (hash, name, size, rating) can be read
52 * via the CAbstractFile functions. Tags pertaining to meta-data
53 * are stored in the taglist inherited from CAbstractFile.
55 * TODO: Server IP/Port are currently not used.
56 * TODO: Client ID/Port are currently not used.
57 * TODO: Directories are currently not used.
59 class CSearchFile
: public CAbstractFile
62 /** Constructor used to create results on the remote GUI. */
63 CSearchFile(class CEC_SearchFile_Tag
* tag
);
64 /** Copy constructor, also copies children. */
65 CSearchFile(const CSearchFile
& other
);
68 * Normal constructor, reads a result from a packet.
70 * @param data Source of results-packet.
71 * @param optUTF8 Specifies if text-strings are to be read as UTF8.
72 * @param searchID searchID The
73 * @param serverIP The IP of the server that sent this result.
74 * @param serverPort The port of the server that sent this result.
75 * @param directory If from a clients shared files, the directory this file is in.
76 * @param kademlia Specifies if this was from a kad-search.
83 uint16 serverPort
= 0,
84 const wxString
& directory
= wxEmptyString
,
85 bool kademlia
= false);
88 /** Frees all children owned by this file. */
89 virtual ~CSearchFile();
93 * Adds the given sources to the file.
95 * @param count Total source count.
96 * @param count_complete Number of sources that have the complete file.
98 * Note that for Kademlia results, only the largest value is used.
100 void AddSources(uint32 count
, uint32 count_complete
);
102 /** Returns the total number of sources. */
103 uint32
GetSourceCount() const;
104 /** Returns the number of sources that have the entire file. */
105 uint32
GetCompleteSourceCount() const;
106 /** Returns the ID of the search, used to select the right list when displaying. */
107 wxUIntPtr
GetSearchID() const;
108 /** Returns true if the result is from a Kademlia search. */
109 bool IsKademlia() const;
112 /** Returns the parent of this file. */
113 CSearchFile
*GetParent() const;
114 /** Returns the list of children belonging to this file. */
115 const CSearchResultList
&GetChildren() const;
116 /** Returns true if this item has children. */
117 bool HasChildren() const;
118 /** Returns true if children should be displayed. */
119 bool ShowChildren() const;
120 /** Enable/Disable displaying of children (set in CSearchListCtrl). */
121 void SetShowChildren(bool show
);
124 * Adds the given file as a child of this file.
126 * Note that a file can either be a parent _or_
127 * a child, but not both. Also note that it is
128 * only legal to add children whoose filesize and
129 * filehash matches the parent's. AddChild takes
130 * ownership of the file.
132 void AddChild(CSearchFile
* file
);
136 //! TODO: Currently not used.
137 uint32
GetClientID() const;
138 void SetClientID(uint32 clientID
);
139 uint16
GetClientPort() const;
140 void SetClientPort(uint16 port
);
144 //! CSearchFile is not assignable.
145 CSearchFile
& operator=(const CSearchFile
& other
);
148 * Updates a parent file so that it shows various common traits.
150 * Currently, the most common filename is selected, and an average
151 * of fileratings is set, based on files that have a rating only.
155 //! The parent of this result.
156 CSearchFile
* m_parent
;
157 //! Any children this result may have.
158 CSearchResultList m_children
;
159 //! If true, children will be shown on the GUI.
161 //! The unique ID of this search owning this result.
162 wxUIntPtr m_searchID
;
163 //! The total number of sources for this file.
164 uint32 m_sourceCount
;
165 //! The number of sources that have the complete file.
166 uint32 m_completeSourceCount
;
167 //! Specifies if the result is from a kademlia search.
171 //! TODO: Currently not used.
174 wxString m_directory
;
177 friend class CPartFile
;
178 friend class CSearchListRem
;
182 ////////////////////////////////////////////////////////////
186 inline uint32
CSearchFile::GetSourceCount() const
188 return m_sourceCount
;
192 inline uint32
CSearchFile::GetCompleteSourceCount() const
194 return m_completeSourceCount
;
198 inline wxUIntPtr
CSearchFile::GetSearchID() const
204 inline bool CSearchFile::IsKademlia() const
210 inline CSearchFile
* CSearchFile::GetParent() const
216 inline bool CSearchFile::ShowChildren() const
218 return m_showChildren
;
222 inline void CSearchFile::SetShowChildren(bool show
)
224 m_showChildren
= show
;
228 inline const CSearchResultList
& CSearchFile::GetChildren() const
234 inline bool CSearchFile::HasChildren() const
236 return !m_children
.empty();
240 inline uint32
CSearchFile::GetClientID() const
246 inline void CSearchFile::SetClientID(uint32 clientID
)
248 m_clientID
= clientID
;
252 inline uint16
CSearchFile::GetClientPort() const
258 inline void CSearchFile::SetClientPort(uint16 port
)
263 #endif // SEARCHLIST_H
264 // File_checked_for_headers