Upstream tarball 20080512
[amule.git] / src / SearchFile.h
blobb2b4a060f0ef082091c69e88c21ffe238ef16d3e
1 //
2 // This file is part of the aMule Project.
3 //
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 )
6 //
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
9 // respective authors.
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.
20 //
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
26 #ifndef SEARCHFILE_H
27 #define SEARCHFILE_H
29 #include "KnownFile.h" // Needed for CAbstractFile
32 class CMemFile;
33 class CMD4Hash;
34 class CSearchFile;
37 typedef std::vector<CSearchFile*> CSearchResultList;
40 /**
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
61 public:
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);
67 /**
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.
78 CSearchFile(
79 const CMemFile& data,
80 bool optUTF8,
81 wxUIntPtr searchID,
82 uint32 serverIP = 0,
83 uint16 serverPort = 0,
84 const wxString& directory = wxEmptyString,
85 bool kademlia = false);
88 /** Frees all children owned by this file. */
89 virtual ~CSearchFile();
92 /**
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);
135 //@{
136 //! TODO: Currently not used.
137 uint32 GetClientID() const;
138 void SetClientID(uint32 clientID);
139 uint16 GetClientPort() const;
140 void SetClientPort(uint16 port);
141 //@}
143 void SetKadPublishInfo(uint32_t val) throw() { m_kadPublishInfo = val; }
144 uint32_t GetKadPublishInfo() const throw() { return m_kadPublishInfo; }
146 private:
147 //! CSearchFile is not assignable.
148 CSearchFile& operator=(const CSearchFile& other);
151 * Updates a parent file so that it shows various common traits.
153 * Currently, the most common filename is selected, and an average
154 * of fileratings is set, based on files that have a rating only.
156 void UpdateParent();
158 //! The parent of this result.
159 CSearchFile* m_parent;
160 //! Any children this result may have.
161 CSearchResultList m_children;
162 //! If true, children will be shown on the GUI.
163 bool m_showChildren;
164 //! The unique ID of this search owning this result.
165 wxUIntPtr m_searchID;
166 //! The total number of sources for this file.
167 uint32 m_sourceCount;
168 //! The number of sources that have the complete file.
169 uint32 m_completeSourceCount;
170 //! Specifies if the result is from a kademlia search.
171 bool m_kademlia;
173 //@{
174 //! TODO: Currently not used.
175 uint32 m_clientID;
176 uint16 m_clientPort;
177 wxString m_directory;
178 //@}
180 //! Kademlia publish information.
181 uint32_t m_kadPublishInfo;
183 friend class CPartFile;
184 friend class CSearchListRem;
188 ////////////////////////////////////////////////////////////
189 // Implementations
192 inline uint32 CSearchFile::GetSourceCount() const
194 return m_sourceCount;
198 inline uint32 CSearchFile::GetCompleteSourceCount() const
200 return m_completeSourceCount;
204 inline wxUIntPtr CSearchFile::GetSearchID() const
206 return m_searchID;
210 inline bool CSearchFile::IsKademlia() const
212 return m_kademlia;
216 inline CSearchFile* CSearchFile::GetParent() const
218 return m_parent;
222 inline bool CSearchFile::ShowChildren() const
224 return m_showChildren;
228 inline void CSearchFile::SetShowChildren(bool show)
230 m_showChildren = show;
234 inline const CSearchResultList& CSearchFile::GetChildren() const
236 return m_children;
240 inline bool CSearchFile::HasChildren() const
242 return !m_children.empty();
246 inline uint32 CSearchFile::GetClientID() const
248 return m_clientID;
252 inline void CSearchFile::SetClientID(uint32 clientID)
254 m_clientID = clientID;
258 inline uint16 CSearchFile::GetClientPort() const
260 return m_clientPort;
264 inline void CSearchFile::SetClientPort(uint16 port)
266 m_clientPort = port;
269 #endif // SEARCHLIST_H
270 // File_checked_for_headers