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-2008 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.
82 uint32_t serverIP
= 0,
83 uint16_t serverPort
= 0,
84 const wxString
& directory
= wxEmptyString
,
85 bool kademlia
= false);
88 /** Frees all children owned by this file. */
89 virtual ~CSearchFile();
93 * Merges the two results into one.
95 * Merges the other result into this one, updating
96 * various informations.
98 * @param other The file to be merged into this.
100 void MergeResults(const CSearchFile
& other
);
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 whose filesize and
129 * filehash matches the parent's. AddChild takes
130 * ownership of the file.
132 void AddChild(CSearchFile
* file
);
134 struct ClientStruct
{
136 : m_ip(0), m_port(0), m_serverIP(0), m_serverPort(0)
139 ClientStruct(uint32_t ip
, uint16_t port
, uint32_t serverIP
, uint16_t serverPort
)
140 : m_ip(ip
), m_port(port
), m_serverIP(serverIP
), m_serverPort(serverPort
)
146 uint32_t m_serverPort
;
149 void AddClient(const ClientStruct
& client
);
150 const std::list
<ClientStruct
>& GetClients() const { return m_clients
; }
152 uint32_t GetClientID() const throw() { return m_clientID
; }
153 void SetClientID(uint32_t clientID
) throw() { m_clientID
= clientID
; }
154 uint16_t GetClientPort() const throw() { return m_clientPort
; }
155 void SetClientPort(uint16_t port
) throw() { m_clientPort
= port
; }
156 uint32_t GetClientServerIP() const throw() { return m_clientServerIP
; }
157 void SetClientServerIP(uint32_t serverIP
) throw() { m_clientServerIP
= serverIP
; }
158 uint16_t GetClientServerPort() const throw() { return m_clientServerPort
; }
159 void SetClientServerPort(uint16_t port
) throw() { m_clientServerPort
= port
; }
160 int GetClientsCount() const { return ((GetClientID() && GetClientPort()) ? 1 : 0) + m_clients
.size(); }
162 void SetKadPublishInfo(uint32_t val
) throw() { m_kadPublishInfo
= val
; }
163 uint32_t GetKadPublishInfo() const throw() { return m_kadPublishInfo
; }
166 //! CSearchFile is not assignable.
167 CSearchFile
& operator=(const CSearchFile
& other
);
170 * Updates a parent file so that it shows various common traits.
172 * Currently, the most common filename is selected, and an average
173 * of fileratings is set, based on files that have a rating only.
177 //! The parent of this result.
178 CSearchFile
* m_parent
;
179 //! Any children this result may have.
180 CSearchResultList m_children
;
181 //! If true, children will be shown on the GUI.
183 //! The unique ID of this search owning this result.
184 wxUIntPtr m_searchID
;
185 //! The total number of sources for this file.
186 uint32 m_sourceCount
;
187 //! The number of sources that have the complete file.
188 uint32 m_completeSourceCount
;
189 //! Specifies if the result is from a kademlia search.
193 //! TODO: Currently not used.
194 wxString m_directory
;
197 std::list
<ClientStruct
> m_clients
;
199 uint16_t m_clientPort
;
200 uint32_t m_clientServerIP
;
201 uint16_t m_clientServerPort
;
203 //! Kademlia publish information.
204 uint32_t m_kadPublishInfo
;
206 friend class CPartFile
;
207 friend class CSearchListRem
;
211 ////////////////////////////////////////////////////////////
215 inline uint32
CSearchFile::GetSourceCount() const
217 return m_sourceCount
;
221 inline uint32
CSearchFile::GetCompleteSourceCount() const
223 return m_completeSourceCount
;
227 inline wxUIntPtr
CSearchFile::GetSearchID() const
233 inline bool CSearchFile::IsKademlia() const
239 inline CSearchFile
* CSearchFile::GetParent() const
245 inline bool CSearchFile::ShowChildren() const
247 return m_showChildren
;
251 inline void CSearchFile::SetShowChildren(bool show
)
253 m_showChildren
= show
;
257 inline const CSearchResultList
& CSearchFile::GetChildren() const
263 inline bool CSearchFile::HasChildren() const
265 return !m_children
.empty();
269 #endif // SEARCHLIST_H
270 // File_checked_for_headers