summaryrefslogtreecommitdiffstats
path: root/plugins/infowidget/iwfiletreeitem.cpp
blob: effe20ae73b9003ec283b704cd396025c35f03b9 (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
/***************************************************************************
 *   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 <tdelocale.h>
#include <tdeglobal.h>
#include <tdemessagebox.h>
#include <interfaces/functions.h>
#include <interfaces/torrentinterface.h>
#include <interfaces/torrentfileinterface.h>
#include <util/bitset.h>
#include "iwfiletreeitem.h"
#include "iwfiletreediritem.h"
#include "functions.h"

using namespace kt;

namespace kt
{
				
	IWFileTreeItem::IWFileTreeItem(IWFileTreeDirItem* item,const TQString & name,kt::TorrentFileInterface & file)
		: FileTreeItem(item,name,file)
	{
		perc_complete = 0.0;
		connect(&file,TQT_SIGNAL(downloadPercentageChanged( float )),this,TQT_SLOT(onPercentageUpdated( float )));
		connect(&file,TQT_SIGNAL(previewAvailable( bool )),this,TQT_SLOT(onPreviewAvailable( bool )));
	}
	
	IWFileTreeItem::~IWFileTreeItem()
	{
	}
	
	int IWFileTreeItem::compare(TQListViewItem* i, int col, bool ascending) const
	{
		if (col == 4)
		{
			IWFileTreeItem* other = dynamic_cast<IWFileTreeItem*>(i);
			if (!other)
				return 0;
			else
				return CompareVal(perc_complete,other->perc_complete);
		}
		else
		{
			return FileTreeItem::compare(i, col, ascending);
		}
	}

	
	void IWFileTreeItem::updatePreviewInformation(kt::TorrentInterface* tc)
	{
		if (file.isMultimedia())
		{
			if (tc->readyForPreview(file.getFirstChunk(), file.getFirstChunk()+1) )
			{
				setText(3, i18n("Available"));
			}
			else
			{
				setText(3, i18n("Pending"));
			}
		}
		else
			setText(3, i18n("No"));
	}

	void IWFileTreeItem::updatePercentageInformation()
	{
		onPercentageUpdated(file.getDownloadPercentage());
	}
	
	void IWFileTreeItem::onPercentageUpdated(float p)
	{
		double percent = p;
		if (percent < 0.0)
			percent = 0.0;
		else if (percent > 100.0)
			percent = 100.0;
		TDELocale* loc = TDEGlobal::locale();
		setText(4,i18n("%1 %").arg(loc->formatNumber(percent,2)));
		perc_complete = percent;
	}
	
	void IWFileTreeItem::onPreviewAvailable(bool av)
	{
		if (av)
		{
			setText(3, i18n("Available"));
		}
		else if (file.isMultimedia())
		{
			setText(3, i18n("Pending"));
		}
		else
		{
			setText(3, i18n("No"));
		}
	}

	void IWFileTreeItem::updatePriorityInformation(kt::TorrentInterface* tc)
	{
		switch(file.getPriority())
		{
			case FIRST_PRIORITY:
				setText(2, i18n("Yes, First"));
				break;
			case LAST_PRIORITY:
				setText(2, i18n("Yes, Last"));
				break;
			case ONLY_SEED_PRIORITY:
			case EXCLUDED:
				setText(2, i18n("No"));		
				break;
			case PREVIEW_PRIORITY:
				break;
			default:
				setText(2, i18n("Yes"));
				break;
		}
	}
	
	void IWFileTreeItem::updateDNDInformation()
	{
		if (file.doNotDownload() && isOn())
		{
			setChecked(false);
			setText(2, i18n("No"));
		}
	}
	
	bt::ConfirmationResult IWFileTreeItem::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;
		*/
	}
	
}

#include "iwfiletreeitem.moc"