mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 03:28:41 -07:00
parent
0297f0f34b
commit
88ef8a51dd
1 changed files with 71 additions and 80 deletions
151
src/app/main.cpp
151
src/app/main.cpp
|
@ -88,17 +88,83 @@ Q_IMPORT_PLUGIN(QICOPlugin)
|
|||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
void displayVersion();
|
||||
void displayBadArgMessage(const QString &message);
|
||||
void displayErrorMessage(const QString &message);
|
||||
namespace
|
||||
{
|
||||
void displayBadArgMessage(const QString &message)
|
||||
{
|
||||
const QString help = QCoreApplication::translate("Main", "Run application with -h option to read about command line parameters.");
|
||||
#if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
|
||||
QMessageBox msgBox(QMessageBox::Critical, QCoreApplication::translate("Main", "Bad command line"),
|
||||
(message + u'\n' + help), QMessageBox::Ok);
|
||||
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
||||
msgBox.move(Utils::Gui::screenCenter(&msgBox));
|
||||
msgBox.exec();
|
||||
#else
|
||||
const QString errMsg = QCoreApplication::translate("Main", "Bad command line: ") + u'\n'
|
||||
+ message + u'\n'
|
||||
+ help + u'\n';
|
||||
fprintf(stderr, "%s", qUtf8Printable(errMsg));
|
||||
#endif
|
||||
}
|
||||
|
||||
void displayErrorMessage(const QString &message)
|
||||
{
|
||||
#ifndef DISABLE_GUI
|
||||
if (QApplication::instance())
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setText(QCoreApplication::translate("Main", "An unrecoverable error occurred."));
|
||||
msgBox.setInformativeText(message);
|
||||
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
||||
msgBox.move(Utils::Gui::screenCenter(&msgBox));
|
||||
msgBox.exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString errMsg = QCoreApplication::translate("Main", "qBittorrent has encountered an unrecoverable error.") + u'\n' + message + u'\n';
|
||||
fprintf(stderr, "%s", qUtf8Printable(errMsg));
|
||||
}
|
||||
#else
|
||||
const QString errMsg = QCoreApplication::translate("Main", "qBittorrent has encountered an unrecoverable error.") + u'\n' + message + u'\n';
|
||||
fprintf(stderr, "%s", qUtf8Printable(errMsg));
|
||||
#endif
|
||||
}
|
||||
|
||||
void displayVersion()
|
||||
{
|
||||
printf("%s %s\n", qUtf8Printable(qApp->applicationName()), QBT_VERSION);
|
||||
}
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
void showSplashScreen();
|
||||
void showSplashScreen()
|
||||
{
|
||||
QPixmap splashImg(u":/icons/splash.png"_s);
|
||||
QPainter painter(&splashImg);
|
||||
const auto version = QStringLiteral(QBT_VERSION);
|
||||
painter.setPen(QPen(Qt::white));
|
||||
painter.setFont(QFont(u"Arial"_s, 22, QFont::Black));
|
||||
painter.drawText(224 - painter.fontMetrics().horizontalAdvance(version), 270, version);
|
||||
QSplashScreen *splash = new QSplashScreen(splashImg);
|
||||
splash->show();
|
||||
QTimer::singleShot(1500ms, Qt::CoarseTimer, splash, &QObject::deleteLater);
|
||||
qApp->processEvents();
|
||||
}
|
||||
#endif // DISABLE_GUI
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void adjustFileDescriptorLimit();
|
||||
void adjustFileDescriptorLimit()
|
||||
{
|
||||
rlimit limit {};
|
||||
|
||||
if (getrlimit(RLIMIT_NOFILE, &limit) != 0)
|
||||
return;
|
||||
|
||||
limit.rlim_cur = limit.rlim_max;
|
||||
setrlimit(RLIMIT_NOFILE, &limit);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Main
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -272,78 +338,3 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(DISABLE_GUI)
|
||||
void showSplashScreen()
|
||||
{
|
||||
QPixmap splashImg(u":/icons/splash.png"_s);
|
||||
QPainter painter(&splashImg);
|
||||
const auto version = QStringLiteral(QBT_VERSION);
|
||||
painter.setPen(QPen(Qt::white));
|
||||
painter.setFont(QFont(u"Arial"_s, 22, QFont::Black));
|
||||
painter.drawText(224 - painter.fontMetrics().horizontalAdvance(version), 270, version);
|
||||
QSplashScreen *splash = new QSplashScreen(splashImg);
|
||||
splash->show();
|
||||
QTimer::singleShot(1500ms, Qt::CoarseTimer, splash, &QObject::deleteLater);
|
||||
qApp->processEvents();
|
||||
}
|
||||
#endif // DISABLE_GUI
|
||||
|
||||
void displayVersion()
|
||||
{
|
||||
printf("%s %s\n", qUtf8Printable(qApp->applicationName()), QBT_VERSION);
|
||||
}
|
||||
|
||||
void displayBadArgMessage(const QString &message)
|
||||
{
|
||||
const QString help = QCoreApplication::translate("Main", "Run application with -h option to read about command line parameters.");
|
||||
#if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
|
||||
QMessageBox msgBox(QMessageBox::Critical, QCoreApplication::translate("Main", "Bad command line options"),
|
||||
(message + u'\n' + help), QMessageBox::Ok);
|
||||
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
||||
msgBox.move(Utils::Gui::screenCenter(&msgBox));
|
||||
msgBox.exec();
|
||||
#else
|
||||
const QString errMsg = QCoreApplication::translate("Main", "Bad command line options:") + u'\n'
|
||||
+ message + u'\n'
|
||||
+ help + u'\n';
|
||||
fprintf(stderr, "%s", qUtf8Printable(errMsg));
|
||||
#endif
|
||||
}
|
||||
|
||||
void displayErrorMessage(const QString &message)
|
||||
{
|
||||
#ifndef DISABLE_GUI
|
||||
if (QApplication::instance())
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setText(QCoreApplication::translate("Main", "An unrecoverable error occurred."));
|
||||
msgBox.setInformativeText(message);
|
||||
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
||||
msgBox.move(Utils::Gui::screenCenter(&msgBox));
|
||||
msgBox.exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString errMsg = QCoreApplication::translate("Main", "qBittorrent has encountered an unrecoverable error.") + u'\n' + message + u'\n';
|
||||
fprintf(stderr, "%s", qUtf8Printable(errMsg));
|
||||
}
|
||||
#else
|
||||
const QString errMsg = QCoreApplication::translate("Main", "qBittorrent has encountered an unrecoverable error.") + u'\n' + message + u'\n';
|
||||
fprintf(stderr, "%s", qUtf8Printable(errMsg));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void adjustFileDescriptorLimit()
|
||||
{
|
||||
rlimit limit {};
|
||||
|
||||
if (getrlimit(RLIMIT_NOFILE, &limit) != 0)
|
||||
return;
|
||||
|
||||
limit.rlim_cur = limit.rlim_max;
|
||||
setrlimit(RLIMIT_NOFILE, &limit);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue