summaryrefslogtreecommitdiffstats
path: root/libktorrent/interfaces/filetreediritem.h
blob: 37de320cce6d466ff0fb4b23e5770ffb021d366f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/***************************************************************************
 *   Copyright (C) 2005 by Joris Guisson                                   *
 *   [email protected]                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#ifndef KTFILETREEDIRITEM_H
#define KTFILETREEDIRITEM_H

#include <klistview.h>
#include <util/constants.h>
#include <util/ptrmap.h>

namespace kt
{
	using namespace bt;
	
	class FileTreeItem;
	class TorrentFileInterface;
	class TorrentInterface;
	
	class FileTreeRootListener 
	{
	public: 
		/// An item in the file tree has changed his state
		virtual void treeItemChanged() = 0;
	};

	/**
	 * @author Joris Guisson
	 *
	 * Directory item the file tree showing the files in a multifile torrent
	 */
	class FileTreeDirItem : public TQCheckListItem
	{
	protected:
		TQString name;
		Uint64 size;
		bt::PtrMap<TQString,FileTreeItem> tqchildren;
		bt::PtrMap<TQString,FileTreeDirItem> subdirs;
		FileTreeDirItem* parent;
		bool manual_change;
		FileTreeRootListener* root_listener;
	public:
		FileTreeDirItem(KListView* klv,const TQString & name,FileTreeRootListener* rl = 0);
		FileTreeDirItem(FileTreeDirItem* parent,const TQString & name);
		virtual ~FileTreeDirItem();
		
		/// Get the path of the directory (if this is the root directory / will be returned)
		TQString getPath() const;

		/**
		 * Recursively insert a TorrentFileInterface.
		 * @param path Path of file
		 * @param file File itself
		 */
		void insert(const TQString & path,kt::TorrentFileInterface & file);

		/**
		 * Recursivly walk the tree to find the TorrentFile which
		 * is shown by a TQListViewItem (which should be an FileTreeItem).
		 * If item can't be found or item is an FileTreeDirItem, a reference to
		 * TorrentFile::null will be returned. In which case the isNull() function
		 * of TorrentFile will return true
		 * @param item Pointer to the TQListViewItem
		 * @return A reference to the TorrentFile
		 */
		kt::TorrentFileInterface & findTorrentFile(TQListViewItem* item);

		/**
		 * Set all items checked or not.
		 * @param on true everything checked, false everything not checked
		 * @param keep_data In case of unchecking keep the data or not
		 */
		void setAllChecked(bool on,bool keep_data = false);

		/**
		 * Invert all items, checked items become unchecked and unchecked become checked.
		 */
		void invertChecked();

		/**
		 * Called by the child to notify the parent it's state has changed.
		 */
		void childStateChange();

		FileTreeDirItem* getParent() {return parent;}
		
		/// Recusively get the total number of bytes to download
		Uint64 bytesToDownload() const;

	protected:
		/**
		 * Can be overrided by subclasses, so they can use their own
		 * custom FileTreeItem's. Will be called in insert.
		 * @param name Name of the file
		 * @param file The TorrentFileInterface
		 * @return A newly created FileTreeItem
		 */
		virtual FileTreeItem* newFileTreeItem(const TQString & name,
											  TorrentFileInterface & file);


		/**
		 * Can be overrided by subclasses, so they can use their own
		 * custom FileTreeDirItem's. Will be called in insert.
		 * @param subdir The name of the subdir
		 * @return A newly created FileTreeDirItem
		 */
		virtual FileTreeDirItem* newFileTreeDirItem(const TQString & subdir);
		
		
		/**
		 * Subclasses should override this if they want to show a confirmation dialog. 
		 * @return What to do (i.e. keep the data, get rid of it or do nothing
		 */
		virtual bt::ConfirmationResult confirmationDialog();
		
	private:
		virtual void stateChange(bool on);
		virtual int compare(TQListViewItem* i, int col, bool ascending) const;
		bool allChildrenOn();
	};

}

#endif