2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2006-2012 Christophe Dumez <chris@qbittorrent.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
29 #include "torrentcontentmodelitem.h"
33 #include "base/unicodestrings.h"
34 #include "base/utils/misc.h"
35 #include "base/utils/string.h"
36 #include "torrentcontentmodelfolder.h"
38 TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder
*parent
)
39 : m_parentItem(parent
)
43 TorrentContentModelItem::~TorrentContentModelItem() = default;
45 bool TorrentContentModelItem::isRootItem() const
50 QString
TorrentContentModelItem::name() const
52 Q_ASSERT(!isRootItem());
56 void TorrentContentModelItem::setName(const QString
&name
)
58 Q_ASSERT(!isRootItem());
62 qulonglong
TorrentContentModelItem::size() const
64 Q_ASSERT(!isRootItem());
69 qreal
TorrentContentModelItem::progress() const
71 Q_ASSERT(!isRootItem());
73 return (m_size
> 0) ? m_progress
: 1;
76 qulonglong
TorrentContentModelItem::remaining() const
78 Q_ASSERT(!isRootItem());
79 return (m_priority
== BitTorrent::DownloadPriority::Ignored
) ? 0 : m_remaining
;
82 qreal
TorrentContentModelItem::availability() const
84 Q_ASSERT(!isRootItem());
86 return (m_size
> 0) ? m_availability
: 0;
89 BitTorrent::DownloadPriority
TorrentContentModelItem::priority() const
91 Q_ASSERT(!isRootItem());
95 int TorrentContentModelItem::columnCount() const
100 QString
TorrentContentModelItem::displayData(const int column
) const
103 return m_itemData
.value(column
);
112 case BitTorrent::DownloadPriority::Mixed
:
113 return tr("Mixed", "Mixed (priorities");
114 case BitTorrent::DownloadPriority::Ignored
:
115 return tr("Not downloaded");
116 case BitTorrent::DownloadPriority::High
:
117 return tr("High", "High (priority)");
118 case BitTorrent::DownloadPriority::Maximum
:
119 return tr("Maximum", "Maximum (priority)");
121 return tr("Normal", "Normal (priority)");
124 return (m_progress
>= 1)
126 : (Utils::String::fromDouble((m_progress
* 100), 1) + u
'%');
128 return Utils::Misc::friendlyUnit(m_size
);
130 return Utils::Misc::friendlyUnit(remaining());
131 case COL_AVAILABILITY
:
133 const qreal avail
= availability();
137 const QString value
= (avail
>= 1)
139 : Utils::String::fromDouble((avail
* 100), 1);
140 return (value
+ u
'%');
148 QVariant
TorrentContentModelItem::underlyingData(const int column
) const
151 return m_itemData
.value(column
);
158 return static_cast<int>(m_priority
);
160 return progress() * 100;
165 case COL_AVAILABILITY
:
166 return availability();
173 int TorrentContentModelItem::row() const
176 return m_parentItem
->children().indexOf(const_cast<TorrentContentModelItem
*>(this));
180 TorrentContentModelFolder
*TorrentContentModelItem::parent() const