1 /***************************************************************************
2        csharetreefolder.h  -  Object for storing a tree of folders
3                              -------------------
4     begin                : Fri Jul 25 2008
5     copyright            : (C) 2008 by Edward Sheldrake
6     email                : ejs1920@yahoo.co.uk
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
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.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef CSHARETREEFOLDER_H
19 #define CSHARETREEFOLDER_H
20 
21 /**
22  * @author Edward Sheldrake
23  *
24  * In order to respond to partial list requests via "$ADCGET list ..."
25  * we need to store the files and folders that make up the share
26  * in a useful format, index.lst was probably designed for
27  * creating the text share list and is not helpful for creating
28  * partial listings.
29  *
30  * To save some memory empty lists will not be stored or
31  * returned, instead NULL will be returned and lists will
32  * be created as necessary.
33  *
34  * This class should be able to generate the entire XML
35  * list, but it does it recursively, so the existing
36  * method in CShareList is probably faster.
37  */
38 
39 #include <dclib/dcos.h>
40 #include <dclib/core/cstring.h>
41 
42 #include <list>
43 
44 class CSearchIndex;
45 
46 class CShareTreeFolder {
47 
48 public:
49 	/** Constructor */
50 	CShareTreeFolder( const CString & name, const CShareTreeFolder * parent );
51 	/** Destructor - virtual in case something extends this class */
52 	virtual ~CShareTreeFolder();
53 
54 	/** Gets the name */
55 	const CString & GetName() const;
56 
57 	/** Gets the parent folder object */
58 	const CShareTreeFolder * GetParent() const;
59 
60 	/**
61 	 * Gets the list of child folders.
62 	 *
63 	 * Returns 0 not an empty list if no children.
64 	 */
65 	std::list<CShareTreeFolder*> * GetChildren() const;
66 
67 	/** Adds a new subfolder */
68 	CShareTreeFolder * AddFolder( const CString & name );
69 
70 	/**
71 	 * Gets the list of files.
72 	 *
73 	 * Returns 0 not an empty list if no files.
74 	 */
75 	std::list<unsigned long int> * GetFiles() const;
76 
77 	/** Adds a file */
78 	void AddFile( const unsigned long int fbi );
79 
80 	/**
81 	 * Gets the XML to given depth.
82 	 * depth = -1 for unlimited
83 	 */
84 	CString GetXML( int depth, CSearchIndex * si ) const;
85 
86 /** */
87 private:
88 	/** The folder name */
89 	const CString m_sName;
90 	/** The parent folder */
91 	const CShareTreeFolder * m_pParent;
92 	/** List of folders */
93 	std::list<CShareTreeFolder*> * m_pFolderList;
94 	/** List of files */
95 	std::list<unsigned long int> * m_pFileList;
96 };
97 
98 #endif // CSHARETREEFOLDER_H
99