summaryrefslogtreecommitdiffstats
path: root/plugins/infowidget/iwfiletreediritem.cpp
blob: c143e7e0d6037b5dc5d784b8cc93f85b5e0ef754 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/***************************************************************************
 *   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.             *
 ***************************************************************************/
#include <kglobal.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kmessagebox.h>
#include <util/functions.h>
#include <interfaces/torrentfileinterface.h>
#include <interfaces/torrentinterface.h>
#include "iwfiletreediritem.h"
#include "iwfiletreeitem.h"
#include "functions.h"

using namespace kt;

namespace kt
{
	
	IWFileTreeDirItem::IWFileTreeDirItem(KListView* klv,const TQString & name)
		: kt::FileTreeDirItem(klv,name)
	{
	}
	
	IWFileTreeDirItem::IWFileTreeDirItem(IWFileTreeDirItem* parent,const TQString & name)
		: kt::FileTreeDirItem(parent,name)
	{
	}
	
	IWFileTreeDirItem::~IWFileTreeDirItem()
	{
	}
		
	
	void IWFileTreeDirItem::updatePercentageInformation()
	{
		// first set all the child items
		bt::PtrMap<TQString,FileTreeItem>::iterator i = tqchildren.begin();
		while (i != tqchildren.end())
		{
			IWFileTreeItem* item = (IWFileTreeItem*)i->second;
			item->updatePercentageInformation();
			i++;
		}
	
		// then recursivly move on to subdirs
		bt::PtrMap<TQString,FileTreeDirItem>::iterator j = subdirs.begin();
		while (j != subdirs.end())
		{
			((IWFileTreeDirItem*)j->second)->updatePercentageInformation();
			j++;
		}
	}
	
	void IWFileTreeDirItem::updatePreviewInformation(kt::TorrentInterface* tc)
	{
		// first set all the child items
		bt::PtrMap<TQString,FileTreeItem>::iterator i = tqchildren.begin();
		while (i != tqchildren.end())
		{
			IWFileTreeItem* item = (IWFileTreeItem*)i->second;
			item->updatePreviewInformation(tc);
			i++;
		}
	
		// then recursivly move on to subdirs
		bt::PtrMap<TQString,FileTreeDirItem>::iterator j = subdirs.begin();
		while (j != subdirs.end())
		{
			((IWFileTreeDirItem*)j->second)->updatePreviewInformation(tc);
			j++;
		}
	}
	
	Priority IWFileTreeDirItem::updatePriorityInformation(kt::TorrentInterface* tc)
	{
                // first set all the child items
		bt::PtrMap<TQString,FileTreeItem>::iterator i = tqchildren.begin();
		bool setpriority = false;
		bool oneexcluded = false;
		Priority priority = PREVIEW_PRIORITY;
		if(i != tqchildren.end())
		{
			IWFileTreeItem* item = (IWFileTreeItem*)i->second;
			item->updatePriorityInformation(tc);
			i++;
			priority = item->getTorrentFile().getPriority();
			if(priority == EXCLUDED)
				oneexcluded = true;
			setpriority = true;
		}
		while (i != tqchildren.end())
		{
			IWFileTreeItem* item = (IWFileTreeItem*)i->second;
			item->updatePriorityInformation(tc);
			i++;
			if(item->getTorrentFile().getPriority() != priority)
				setpriority = false;
			if(item->getTorrentFile().getPriority() == EXCLUDED)
				oneexcluded = true;
		}

                // then recursivly move on to subdirs
		bt::PtrMap<TQString,FileTreeDirItem>::iterator j = subdirs.begin();
		if(j != subdirs.end() && tqchildren.begin() == tqchildren.end())
		{
			Priority priority =
					((IWFileTreeDirItem*)j->second)->updatePriorityInformation(tc);
			if(priority != PREVIEW_PRIORITY)
				setpriority = true;
			if(priority == EXCLUDED)
				oneexcluded = true;
			j++;
		}

		while (j != subdirs.end())
		{
			if(((IWFileTreeDirItem*)j->second)->updatePriorityInformation(tc)
						  != priority)
				setpriority = false;
			if(((IWFileTreeDirItem*)j->second)->updatePriorityInformation(tc)
						  == EXCLUDED)
				oneexcluded = true;
			j++;
		}

		if(setpriority)
		{
			switch(priority)
			{
				case FIRST_PRIORITY:
					setText(2, i18n("Yes, First"));
					childStateChange();
					break;
				case LAST_PRIORITY:
					setText(2, i18n("Yes, Last"));
					childStateChange();
					break;
				case EXCLUDED:
					setText(2, i18n("No"));
					childStateChange();
					break;
				default:
					setText(2, i18n("Yes"));
					childStateChange();
					break;
			}
			return priority;
		}
		if(oneexcluded)
		{
			setText(2, i18n("No"));
			childStateChange();
		}
		else
		{
			setText(2, i18n("Yes"));
			childStateChange();
		}
		return PREVIEW_PRIORITY;
	}

	FileTreeItem* IWFileTreeDirItem::newFileTreeItem(const TQString & name,TorrentFileInterface & file)
	{
		return new IWFileTreeItem(this,name,file);
	}
	
	FileTreeDirItem* IWFileTreeDirItem::newFileTreeDirItem(const TQString & subdir)
	{
		return new IWFileTreeDirItem(this,subdir);
	}
	
	void IWFileTreeDirItem::updateDNDInformation()
	{
			// first set all the child items
		bt::PtrMap<TQString,FileTreeItem>::iterator i = tqchildren.begin();
		while (i != tqchildren.end())
		{
			IWFileTreeItem* item = (IWFileTreeItem*)i->second;
			item->updateDNDInformation();
			i++;
		}
	
		// then recursivly move on to subdirs
		bt::PtrMap<TQString,FileTreeDirItem>::iterator j = subdirs.begin();
		while (j != subdirs.end())
		{
			((IWFileTreeDirItem*)j->second)->updateDNDInformation();
			j++;
		}
	}

	bt::ConfirmationResult IWFileTreeDirItem::confirmationDialog()
	{
		return bt::KEEP_DATA;
/*		TQString msg = i18n("Do you want to keep the existing data for seeding ?");
		int ret = KMessageBox::warningYesNoCancel(0,msg,TQString(),
				KGuiItem(i18n("Keep the data")),
				KGuiItem(i18n("Delete the data")));
		if (ret == KMessageBox::Yes)
			return bt::KEEP_DATA;
		else if (ret == KMessageBox::No)
			return bt::THROW_AWAY_DATA;
		else
			return bt::CANCELED;
		*/
	}
}