mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-14 08:48:17 +00:00
Remove usage of QTextStream
Other classes already provide rich methods so avoid another layer of QTextStream which slow things down (slightly). PR #17180.
This commit is contained in:
parent
ca07540675
commit
eddeda7bab
@ -35,7 +35,6 @@
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QTextStream>
|
||||
|
||||
#if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
|
||||
#include <QMessageBox>
|
||||
@ -525,59 +524,57 @@ QString wrapText(const QString &text, int initialIndentation = USAGE_TEXT_COLUMN
|
||||
|
||||
QString makeUsage(const QString &prgName)
|
||||
{
|
||||
QString text;
|
||||
QTextStream stream(&text, QIODevice::WriteOnly);
|
||||
QString indentation = QString(USAGE_INDENTATION, u' ');
|
||||
const QString indentation {USAGE_INDENTATION, u' '};
|
||||
|
||||
stream << QObject::tr("Usage:") << '\n'
|
||||
<< indentation << prgName << u" [options] [(<filename> | <url>)...]"_qs << '\n'
|
||||
const QString text = QObject::tr("Usage:") + u'\n'
|
||||
+ indentation + prgName + u" [options] [(<filename> | <url>)...]" + u'\n'
|
||||
|
||||
<< QObject::tr("Options:") << '\n'
|
||||
+ QObject::tr("Options:") + u'\n'
|
||||
#if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
|
||||
<< SHOW_VERSION_OPTION.usage() << wrapText(QObject::tr("Display program version and exit")) << '\n'
|
||||
+ SHOW_VERSION_OPTION.usage() + wrapText(QObject::tr("Display program version and exit")) + u'\n'
|
||||
#endif
|
||||
<< SHOW_HELP_OPTION.usage() << wrapText(QObject::tr("Display this help message and exit")) << '\n'
|
||||
<< WEBUI_PORT_OPTION.usage(QObject::tr("port"))
|
||||
<< wrapText(QObject::tr("Change the Web UI port"))
|
||||
<< '\n'
|
||||
+ SHOW_HELP_OPTION.usage() + wrapText(QObject::tr("Display this help message and exit")) + u'\n'
|
||||
+ WEBUI_PORT_OPTION.usage(QObject::tr("port"))
|
||||
+ wrapText(QObject::tr("Change the Web UI port"))
|
||||
+ u'\n'
|
||||
#ifndef DISABLE_GUI
|
||||
<< NO_SPLASH_OPTION.usage() << wrapText(QObject::tr("Disable splash screen")) << '\n'
|
||||
+ NO_SPLASH_OPTION.usage() + wrapText(QObject::tr("Disable splash screen")) + u'\n'
|
||||
#elif !defined(Q_OS_WIN)
|
||||
<< DAEMON_OPTION.usage() << wrapText(QObject::tr("Run in daemon-mode (background)")) << '\n'
|
||||
+ DAEMON_OPTION.usage() + wrapText(QObject::tr("Run in daemon-mode (background)")) + u'\n'
|
||||
#endif
|
||||
//: Use appropriate short form or abbreviation of "directory"
|
||||
<< PROFILE_OPTION.usage(QObject::tr("dir"))
|
||||
<< wrapText(QObject::tr("Store configuration files in <dir>")) << '\n'
|
||||
<< CONFIGURATION_OPTION.usage(QObject::tr("name"))
|
||||
<< wrapText(QObject::tr("Store configuration files in directories qBittorrent_<name>")) << '\n'
|
||||
<< RELATIVE_FASTRESUME.usage()
|
||||
<< wrapText(QObject::tr("Hack into libtorrent fastresume files and make file paths relative "
|
||||
"to the profile directory")) << '\n'
|
||||
<< Option::padUsageText(QObject::tr("files or URLs"))
|
||||
<< wrapText(QObject::tr("Download the torrents passed by the user")) << '\n'
|
||||
<< '\n'
|
||||
+ PROFILE_OPTION.usage(QObject::tr("dir"))
|
||||
+ wrapText(QObject::tr("Store configuration files in <dir>")) + u'\n'
|
||||
+ CONFIGURATION_OPTION.usage(QObject::tr("name"))
|
||||
+ wrapText(QObject::tr("Store configuration files in directories qBittorrent_<name>")) + u'\n'
|
||||
+ RELATIVE_FASTRESUME.usage()
|
||||
+ wrapText(QObject::tr("Hack into libtorrent fastresume files and make file paths relative "
|
||||
"to the profile directory")) + u'\n'
|
||||
+ Option::padUsageText(QObject::tr("files or URLs"))
|
||||
+ wrapText(QObject::tr("Download the torrents passed by the user")) + u'\n'
|
||||
+ u'\n'
|
||||
|
||||
<< wrapText(QObject::tr("Options when adding new torrents:"), 0) << '\n'
|
||||
<< SAVE_PATH_OPTION.usage(QObject::tr("path")) << wrapText(QObject::tr("Torrent save path")) << '\n'
|
||||
<< PAUSED_OPTION.usage() << wrapText(QObject::tr("Add torrents as started or paused")) << '\n'
|
||||
<< SKIP_HASH_CHECK_OPTION.usage() << wrapText(QObject::tr("Skip hash check")) << '\n'
|
||||
<< CATEGORY_OPTION.usage(QObject::tr("name"))
|
||||
<< wrapText(QObject::tr("Assign torrents to category. If the category doesn't exist, it will be "
|
||||
"created.")) << '\n'
|
||||
<< SEQUENTIAL_OPTION.usage() << wrapText(QObject::tr("Download files in sequential order")) << '\n'
|
||||
<< FIRST_AND_LAST_OPTION.usage()
|
||||
<< wrapText(QObject::tr("Download first and last pieces first")) << '\n'
|
||||
<< SKIP_DIALOG_OPTION.usage()
|
||||
<< wrapText(QObject::tr("Specify whether the \"Add New Torrent\" dialog opens when adding a "
|
||||
"torrent.")) << '\n'
|
||||
<< '\n'
|
||||
+ wrapText(QObject::tr("Options when adding new torrents:"), 0) + u'\n'
|
||||
+ SAVE_PATH_OPTION.usage(QObject::tr("path")) + wrapText(QObject::tr("Torrent save path")) + u'\n'
|
||||
+ PAUSED_OPTION.usage() + wrapText(QObject::tr("Add torrents as started or paused")) + u'\n'
|
||||
+ SKIP_HASH_CHECK_OPTION.usage() + wrapText(QObject::tr("Skip hash check")) + u'\n'
|
||||
+ CATEGORY_OPTION.usage(QObject::tr("name"))
|
||||
+ wrapText(QObject::tr("Assign torrents to category. If the category doesn't exist, it will be "
|
||||
"created.")) + u'\n'
|
||||
+ SEQUENTIAL_OPTION.usage() + wrapText(QObject::tr("Download files in sequential order")) + u'\n'
|
||||
+ FIRST_AND_LAST_OPTION.usage()
|
||||
+ wrapText(QObject::tr("Download first and last pieces first")) + u'\n'
|
||||
+ SKIP_DIALOG_OPTION.usage()
|
||||
+ wrapText(QObject::tr("Specify whether the \"Add New Torrent\" dialog opens when adding a "
|
||||
"torrent.")) + u'\n'
|
||||
+ u'\n'
|
||||
|
||||
<< wrapText(QObject::tr("Option values may be supplied via environment variables. For option named "
|
||||
+ wrapText(QObject::tr("Option values may be supplied via environment variables. For option named "
|
||||
"'parameter-name', environment variable name is 'QBT_PARAMETER_NAME' (in upper "
|
||||
"case, '-' replaced with '_'). To pass flag values, set the variable to '1' or "
|
||||
"'TRUE'. For example, to disable the splash screen: "), 0) << "\n"
|
||||
<< u"QBT_NO_SPLASH=1 "_qs << prgName << '\n'
|
||||
<< wrapText(QObject::tr("Command line parameters take precedence over environment variables"), 0) << '\n';
|
||||
"'TRUE'. For example, to disable the splash screen: "), 0) + u'\n'
|
||||
+ u"QBT_NO_SPLASH=1 " + prgName + u'\n'
|
||||
+ wrapText(QObject::tr("Command line parameters take precedence over environment variables"), 0) + u'\n';
|
||||
|
||||
return text;
|
||||
}
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QSet>
|
||||
#include <QTextStream>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QVariant>
|
||||
@ -522,9 +521,11 @@ void TorrentFilesWatcher::Worker::processFolder(const Path &path, const Path &wa
|
||||
QFile file {filePath.data()};
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QTextStream str {&file};
|
||||
while (!str.atEnd())
|
||||
emit magnetFound(BitTorrent::MagnetUri(str.readLine()), addTorrentParams);
|
||||
while (!file.atEnd())
|
||||
{
|
||||
const auto line = QString::fromLatin1(file.readLine()).trimmed();
|
||||
emit magnetFound(BitTorrent::MagnetUri(line), addTorrentParams);
|
||||
}
|
||||
|
||||
file.close();
|
||||
Utils::Fs::removeFile(filePath);
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include <QHelpEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QTextStream>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "base/bittorrent/torrent.h"
|
||||
@ -88,25 +87,29 @@ namespace
|
||||
class DetailedTooltipRenderer
|
||||
{
|
||||
public:
|
||||
DetailedTooltipRenderer(QTextStream &stream, const QString &header)
|
||||
: m_stream(stream)
|
||||
DetailedTooltipRenderer(QString &string, const QString &header)
|
||||
: m_string(string)
|
||||
{
|
||||
m_stream << header
|
||||
<< R"(<table style="width:100%; padding: 3px; vertical-align: middle;">)";
|
||||
m_string += header
|
||||
+ uR"(<table style="width:100%; padding: 3px; vertical-align: middle;">)";
|
||||
}
|
||||
|
||||
~DetailedTooltipRenderer()
|
||||
{
|
||||
m_stream << "</table>";
|
||||
m_string += u"</table>";
|
||||
}
|
||||
|
||||
void operator()(const QString &size, const Path &path)
|
||||
{
|
||||
m_stream << R"(<tr><td style="white-space:nowrap">)" << size << "</td><td>" << path.toString() << "</td></tr>";
|
||||
m_string += uR"(<tr><td style="white-space:nowrap">)"
|
||||
+ size
|
||||
+ u"</td><td>"
|
||||
+ path.toString()
|
||||
+ u"</td></tr>";
|
||||
}
|
||||
|
||||
private:
|
||||
QTextStream &m_stream;
|
||||
QString &m_string;
|
||||
};
|
||||
}
|
||||
|
||||
@ -252,17 +255,16 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
|
||||
return;
|
||||
|
||||
QString toolTipText;
|
||||
QTextStream stream(&toolTipText, QIODevice::WriteOnly);
|
||||
|
||||
const bool showDetailedInformation = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
|
||||
if (showDetailedInformation && m_torrent->hasMetadata())
|
||||
{
|
||||
const BitTorrent::TorrentInfo torrentInfo = m_torrent->info();
|
||||
const int imagePos = e->pos().x() - borderWidth;
|
||||
if ((imagePos >=0) && (imagePos < m_image.width()))
|
||||
if ((imagePos >= 0) && (imagePos < m_image.width()))
|
||||
{
|
||||
stream << "<html><body>";
|
||||
PieceIndexToImagePos transform {torrentInfo, m_image};
|
||||
int pieceIndex = transform.pieceIndex(imagePos);
|
||||
const PieceIndexToImagePos transform {torrentInfo, m_image};
|
||||
const int pieceIndex = transform.pieceIndex(imagePos);
|
||||
const QVector<int> files {torrentInfo.fileIndicesForPiece(pieceIndex)};
|
||||
|
||||
QString tooltipTitle;
|
||||
@ -278,27 +280,28 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
|
||||
tooltipTitle = tr("File in these pieces");
|
||||
}
|
||||
|
||||
DetailedTooltipRenderer renderer(stream, tooltipTitle);
|
||||
toolTipText.reserve(files.size() * 128);
|
||||
toolTipText += u"<html><body>";
|
||||
|
||||
for (int f : files)
|
||||
DetailedTooltipRenderer renderer {toolTipText, tooltipTitle};
|
||||
|
||||
for (const int f : files)
|
||||
{
|
||||
const Path filePath = torrentInfo.filePath(f);
|
||||
renderer(Utils::Misc::friendlyUnit(torrentInfo.fileSize(f)), filePath);
|
||||
}
|
||||
stream << "</body></html>";
|
||||
toolTipText += u"</body></html>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << simpleToolTipText();
|
||||
toolTipText += simpleToolTipText();
|
||||
if (showDetailedInformation) // metadata are not available at this point
|
||||
stream << '\n' << tr("Wait until metadata become available to see detailed information");
|
||||
toolTipText += u'\n' + tr("Wait until metadata become available to see detailed information");
|
||||
else
|
||||
stream << '\n' << tr("Hold Shift key for detailed information");
|
||||
toolTipText += u'\n' + tr("Hold Shift key for detailed information");
|
||||
}
|
||||
|
||||
stream.flush();
|
||||
|
||||
QToolTip::showText(e->globalPos(), toolTipText, this);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,6 @@
|
||||
#include <QObject>
|
||||
#include <QRegularExpression>
|
||||
#include <QShortcut>
|
||||
#include <QTextStream>
|
||||
#include <QVector>
|
||||
|
||||
#include "base/global.h"
|
||||
@ -93,22 +92,20 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
|
||||
m_ui->setupUi(this);
|
||||
m_ui->tabWidget->tabBar()->installEventFilter(this);
|
||||
|
||||
QString searchPatternHint;
|
||||
QTextStream stream(&searchPatternHint, QIODevice::WriteOnly);
|
||||
stream << "<html><head/><body><p>"
|
||||
<< tr("A phrase to search for.") << "<br>"
|
||||
<< tr("Spaces in a search term may be protected by double quotes.")
|
||||
<< "</p><p>"
|
||||
<< tr("Example:", "Search phrase example")
|
||||
<< "<br>"
|
||||
<< tr("<b>foo bar</b>: search for <b>foo</b> and <b>bar</b>",
|
||||
const QString searchPatternHint = u"<html><head/><body><p>"
|
||||
+ tr("A phrase to search for.") + u"<br>"
|
||||
+ tr("Spaces in a search term may be protected by double quotes.")
|
||||
+ u"</p><p>"
|
||||
+ tr("Example:", "Search phrase example")
|
||||
+ u"<br>"
|
||||
+ tr("<b>foo bar</b>: search for <b>foo</b> and <b>bar</b>",
|
||||
"Search phrase example, illustrates quotes usage, a pair of "
|
||||
"space delimited words, individal words are highlighted")
|
||||
<< "<br>"
|
||||
<< tr("<b>"foo bar"</b>: search for <b>foo bar</b>",
|
||||
+ u"<br>"
|
||||
+ tr("<b>"foo bar"</b>: search for <b>foo bar</b>",
|
||||
"Search phrase example, illustrates quotes usage, double quoted"
|
||||
"pair of space delimited words, the whole pair is highlighted")
|
||||
<< "</p></body></html>";
|
||||
+ u"</p></body></html>";
|
||||
m_ui->lineEditSearchPattern->setToolTip(searchPatternHint);
|
||||
|
||||
#ifndef Q_OS_MACOS
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QScreen>
|
||||
#include <QSize>
|
||||
#include <QStyle>
|
||||
#include <QThread>
|
||||
#include <QUrl>
|
||||
|
@ -28,13 +28,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QSize>
|
||||
|
||||
#include "base/pathfwd.h"
|
||||
|
||||
class QIcon;
|
||||
class QPixmap;
|
||||
class QPoint;
|
||||
class QSize;
|
||||
class QWidget;
|
||||
|
||||
namespace Utils::Gui
|
||||
|
Loading…
Reference in New Issue
Block a user