Browse Source

Use lightweight printf instead of iostream

Using iostream usually adds a lot of other operators (<<, endl), whereas
*printf takes only 1 function call.

Also use qUtf8Printable whenever possible.
adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
37ea01bd44
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 15
      src/app/application.cpp
  2. 4
      src/app/cmdoptions.cpp
  3. 26
      src/app/main.cpp
  4. 5
      src/app/upgrade.h
  5. 4
      src/base/bittorrent/session.cpp
  6. 1
      src/gui/search/searchwidget.cpp

15
src/app/application.cpp

@ -74,7 +74,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "shutdownconfirmdlg.h" #include "shutdownconfirmdlg.h"
#else // DISABLE_GUI #else // DISABLE_GUI
#include <iostream> #include <cstdio>
#endif // DISABLE_GUI #endif // DISABLE_GUI
#ifndef DISABLE_WEBUI #ifndef DISABLE_WEBUI
@ -491,13 +491,16 @@ int Application::exec(const QStringList &params)
#ifndef DISABLE_WEBUI #ifndef DISABLE_WEBUI
Preferences* const pref = Preferences::instance(); Preferences* const pref = Preferences::instance();
// Display some information to the user // Display some information to the user
std::cout << std::endl << "******** " << qPrintable(tr("Information")) << " ********" << std::endl; const QString mesg = QString("\n******** %1 ********\n").arg(tr("Information"))
std::cout << qPrintable(tr("To control qBittorrent, access the Web UI at http://localhost:%1").arg(QString::number(pref->getWebUiPort()))) << std::endl; + tr("To control qBittorrent, access the Web UI at %1")
std::cout << qPrintable(tr("The Web UI administrator user name is: %1").arg(pref->getWebUiUsername())) << std::endl; .arg(QString("http://localhost:") + QString::number(pref->getWebUiPort())) + '\n'
+ tr("The Web UI administrator user name is: %1").arg(pref->getWebUiUsername()) + '\n';
printf("%s", qUtf8Printable(mesg));
qDebug() << "Password:" << pref->getWebUiPassword(); qDebug() << "Password:" << pref->getWebUiPassword();
if (pref->getWebUiPassword() == "f6fdffe48c908deb0f4c3bd36c032e72") { if (pref->getWebUiPassword() == "f6fdffe48c908deb0f4c3bd36c032e72") {
std::cout << qPrintable(tr("The Web UI administrator password is still the default one: %1").arg("adminadmin")) << std::endl; const QString warning = tr("The Web UI administrator password is still the default one: %1").arg("adminadmin") + '\n'
std::cout << qPrintable(tr("This is a security risk, please consider changing your password from program preferences.")) << std::endl; + tr("This is a security risk, please consider changing your password from program preferences.") + '\n';
printf("%s", qUtf8Printable(warning));
} }
#endif // DISABLE_WEBUI #endif // DISABLE_WEBUI
#else #else

4
src/app/cmdoptions.cpp

@ -32,7 +32,7 @@
#include "cmdoptions.h" #include "cmdoptions.h"
#include <iostream> #include <cstdio>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
@ -578,7 +578,7 @@ QString makeUsage(const QString &prgName)
void displayUsage(const QString &prgName) void displayUsage(const QString &prgName)
{ {
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
std::cout << qPrintable(makeUsage(prgName)) << std::endl; printf("%s\n", qUtf8Printable(makeUsage(prgName)));
#else #else
QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prgName), QMessageBox::Ok); QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prgName), QMessageBox::Ok);
msgBox.show(); // Need to be shown or to moveToCenter does not work msgBox.show(); // Need to be shown or to moveToCenter does not work

26
src/app/main.cpp

@ -29,6 +29,8 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#include <cstdlib>
#include <QDebug> #include <QDebug>
#include <QScopedPointer> #include <QScopedPointer>
#include <QThread> #include <QThread>
@ -67,15 +69,11 @@ Q_IMPORT_PLUGIN(QICOPlugin)
#include "stacktrace_win_dlg.h" #include "stacktrace_win_dlg.h"
#endif //STACKTRACE_WIN #endif //STACKTRACE_WIN
#include <cstdlib>
#include <iostream>
#include "application.h" #include "application.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "cmdoptions.h" #include "cmdoptions.h"
#include "upgrade.h" #include "upgrade.h"
// Signal handlers // Signal handlers
@ -169,7 +167,7 @@ int main(int argc, char *argv[])
// Set environment variable // Set environment variable
if (!qputenv("QBITTORRENT", QBT_VERSION)) if (!qputenv("QBITTORRENT", QBT_VERSION))
std::cerr << "Couldn't set environment variable...\n"; fprintf(stderr, "Couldn't set environment variable...\n");
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (!userAgreesWithLegalNotice()) if (!userAgreesWithLegalNotice())
@ -346,7 +344,7 @@ void setupDpi()
void displayVersion() void displayVersion()
{ {
std::cout << qPrintable(qApp->applicationName()) << " " << QBT_VERSION << std::endl; printf("%s %s\n", qUtf8Printable(qApp->applicationName()), QBT_VERSION);
} }
void displayBadArgMessage(const QString& message) void displayBadArgMessage(const QString& message)
@ -359,9 +357,10 @@ void displayBadArgMessage(const QString& message)
msgBox.move(Utils::Misc::screenCenter(&msgBox)); msgBox.move(Utils::Misc::screenCenter(&msgBox));
msgBox.exec(); msgBox.exec();
#else #else
std::cerr << qPrintable(QObject::tr("Bad command line: ")); const QString errMsg = QObject::tr("Bad command line: ") + '\n'
std::cerr << qPrintable(message) << std::endl; + message + '\n'
std::cerr << qPrintable(help) << std::endl; + help + '\n';
fprintf(stderr, "%s", qUtf8Printable(errMsg));
#endif #endif
} }
@ -372,9 +371,12 @@ bool userAgreesWithLegalNotice()
return true; return true;
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
std::cout << std::endl << "*** " << qPrintable(QObject::tr("Legal Notice")) << " ***" << std::endl; const QString eula = QString("\n*** %1 ***\n").arg(QObject::tr("Legal Notice"))
std::cout << qPrintable(QObject::tr("qBittorrent is a file sharing program. When you run a torrent, its data will be made available to others by means of upload. Any content you share is your sole responsibility.\n\nNo further notices will be issued.")) << std::endl << std::endl; + QObject::tr("qBittorrent is a file sharing program. When you run a torrent, its data will be made available to others by means of upload. Any content you share is your sole responsibility.") + "\n\n"
std::cout << qPrintable(QObject::tr("Press %1 key to accept and continue...").arg("'y'")) << std::endl; + QObject::tr("No further notices will be issued.") + "\n\n"
+ QObject::tr("Press %1 key to accept and continue...").arg("'y'") + '\n';
printf("%s", qUtf8Printable(eula));
char ret = getchar(); // Read pressed key char ret = getchar(); // Read pressed key
if (ret == 'y' || ret == 'Y') { if (ret == 'y' || ret == 'Y') {
// Save the answer // Save the answer

5
src/app/upgrade.h

@ -61,10 +61,11 @@
bool userAcceptsUpgrade() bool userAcceptsUpgrade()
{ {
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
std::cout << std::endl << "*** " << qPrintable(QObject::tr("Upgrade")) << " ***" << std::endl; printf("\n*** %s ***\n", qUtf8Printable(QObject::tr("Upgrade")));
char ret = '\0'; char ret = '\0';
do { do {
std::cout << qPrintable(QObject::tr("You updated from an older version that saved things differently. You must migrate to the new saving system. You will not be able to use an older version than v3.3.0 again. Continue? [y/n]")) << std::endl; printf("%s\n"
, qUtf8Printable(QObject::tr("You updated from an older version that saved things differently. You must migrate to the new saving system. You will not be able to use an older version than v3.3.0 again. Continue? [y/n]")));
ret = getchar(); // Read pressed key ret = getchar(); // Read pressed key
} }
while ((ret != 'y') && (ret != 'Y') && (ret != 'n') && (ret != 'N')); while ((ret != 'y') && (ret != 'Y') && (ret != 'n') && (ret != 'N'));

4
src/base/bittorrent/session.cpp

@ -2355,9 +2355,7 @@ void Session::saveResumeData()
std::vector<libt::alert *> alerts; std::vector<libt::alert *> alerts;
getPendingAlerts(alerts, 30 * 1000); getPendingAlerts(alerts, 30 * 1000);
if (alerts.empty()) { if (alerts.empty()) {
std::cerr << " aborting with " << m_numResumeData fprintf(stderr, " aborting with %d outstanding torrents to save resume data for\n", m_numResumeData);
<< " outstanding torrents to save resume data for"
<< std::endl;
break; break;
} }

1
src/gui/search/searchwidget.cpp

@ -29,7 +29,6 @@
#include "searchwidget.h" #include "searchwidget.h"
#include <iostream>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <cstdlib> #include <cstdlib>
#endif #endif

Loading…
Cancel
Save