mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-11 15:56:17 -07:00
Implement search filters in the proxy model. Partially closes #972
This commit is contained in:
parent
93d8cadaaf
commit
1336cb7a61
16 changed files with 704 additions and 133 deletions
|
@ -86,7 +86,9 @@ static struct { const char *source; const char *comment; } units[] = {
|
|||
QT_TRANSLATE_NOOP3("misc", "KiB", "kibibytes (1024 bytes)"),
|
||||
QT_TRANSLATE_NOOP3("misc", "MiB", "mebibytes (1024 kibibytes)"),
|
||||
QT_TRANSLATE_NOOP3("misc", "GiB", "gibibytes (1024 mibibytes)"),
|
||||
QT_TRANSLATE_NOOP3("misc", "TiB", "tebibytes (1024 gibibytes)")
|
||||
QT_TRANSLATE_NOOP3("misc", "TiB", "tebibytes (1024 gibibytes)"),
|
||||
QT_TRANSLATE_NOOP3("misc", "PiB", "pebibytes (1024 tebibytes)"),
|
||||
QT_TRANSLATE_NOOP3("misc", "EiB", "exbibytes (1024 pebibytes)")
|
||||
};
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
|
@ -318,30 +320,58 @@ QString Utils::Misc::pythonVersionComplete() {
|
|||
return version;
|
||||
}
|
||||
|
||||
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
|
||||
QString Utils::Misc::unitString(Utils::Misc::SizeUnit unit)
|
||||
{
|
||||
return QCoreApplication::translate("misc",
|
||||
units[static_cast<int>(unit)].source, units[static_cast<int>(unit)].comment);
|
||||
}
|
||||
|
||||
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB, ...)
|
||||
// use Binary prefix standards from IEC 60027-2
|
||||
// see http://en.wikipedia.org/wiki/Kilobyte
|
||||
// value must be given in bytes
|
||||
// to send numbers instead of strings with suffixes
|
||||
QString Utils::Misc::friendlyUnit(qreal val, bool is_speed)
|
||||
bool Utils::Misc::friendlyUnit(qint64 sizeInBytes, qreal &val, Utils::Misc::SizeUnit &unit)
|
||||
{
|
||||
if (val < 0)
|
||||
return QCoreApplication::translate("misc", "Unknown", "Unknown (size)");
|
||||
if (sizeInBytes < 0) return false;
|
||||
|
||||
int i = 0;
|
||||
while(val >= 1024. && i < 4) {
|
||||
val /= 1024.;
|
||||
qreal rawVal = static_cast<qreal>(sizeInBytes);
|
||||
|
||||
while ((rawVal >= 1024.) && (i <= static_cast<int>(SizeUnit::ExbiByte))) {
|
||||
rawVal /= 1024.;
|
||||
++i;
|
||||
}
|
||||
val = rawVal;
|
||||
unit = static_cast<SizeUnit>(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Utils::Misc::friendlyUnit(qint64 bytesValue, bool isSpeed)
|
||||
{
|
||||
SizeUnit unit;
|
||||
qreal friendlyVal;
|
||||
if (!friendlyUnit(bytesValue, friendlyVal, unit)) {
|
||||
return QCoreApplication::translate("misc", "Unknown", "Unknown (size)");
|
||||
}
|
||||
QString ret;
|
||||
if (i == 0)
|
||||
ret = QString::number((long)val) + " " + QCoreApplication::translate("misc", units[0].source, units[0].comment);
|
||||
if (unit == SizeUnit::Byte)
|
||||
ret = QString::number(bytesValue) + " " + unitString(unit);
|
||||
else
|
||||
ret = Utils::String::fromDouble(val, 1) + " " + QCoreApplication::translate("misc", units[i].source, units[i].comment);
|
||||
if (is_speed)
|
||||
ret = Utils::String::fromDouble(friendlyVal, 1) + " " + unitString(unit);
|
||||
if (isSpeed)
|
||||
ret += QCoreApplication::translate("misc", "/s", "per second");
|
||||
return ret;
|
||||
}
|
||||
|
||||
qlonglong Utils::Misc::sizeInBytes(qreal size, Utils::Misc::SizeUnit unit)
|
||||
{
|
||||
for (int i = 0; i < static_cast<int>(unit); ++i) {
|
||||
size *= 1024;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
bool Utils::Misc::isPreviewable(const QString& extension)
|
||||
{
|
||||
static QSet<QString> multimedia_extensions;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue