2006-09-30 20:02:39 +04:00
/*
2014-12-14 22:18:05 +03:00
* Bittorrent Client using Qt and libtorrent .
* Copyright ( C ) 2014 Vladimir Golovnev < glassez @ yandex . ru >
2018-05-31 12:19:07 +03:00
* Copyright ( C ) 2006 Christophe Dumez < chris @ qbittorrent . org >
2006-09-30 20:02:39 +04:00
*
2007-07-14 18:31:59 +04:00
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
2006-09-30 20:02:39 +04:00
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2007-07-14 18:31:59 +04:00
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
2009-04-05 21:00:55 +04:00
* In addition , as a special exception , the copyright holders give permission to
* link this program with the OpenSSL project ' s " OpenSSL " library ( or with
* modified versions of it that use the same license as the " OpenSSL " library ) ,
* and distribute the linked executables . You must obey the GNU General Public
* License in all respects for all of the code used other than " OpenSSL " . If you
* modify file ( s ) , you may extend this exception to your version of the file ( s ) ,
* but you are not obligated to do so . If you do not wish to do so , delete this
* exception statement from your version .
2006-09-30 20:02:39 +04:00
*/
2018-12-27 23:04:48 +03:00
# include <QtGlobal>
2019-02-14 18:47:00 +03:00
# include <csignal>
2018-03-14 19:13:47 +03:00
# include <cstdlib>
2019-02-16 07:29:57 +03:00
# include <memory>
2018-03-14 19:13:47 +03:00
2019-06-26 08:44:58 +03:00
# if defined(Q_OS_UNIX)
# include <sys/resource.h>
# endif
2018-12-27 23:04:48 +03:00
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
# include <unistd.h>
2018-10-15 11:59:17 +03:00
# elif defined Q_OS_WIN && defined DISABLE_GUI
# include <io.h>
2018-12-27 23:04:48 +03:00
# endif
2014-07-05 16:44:13 +04:00
# include <QDebug>
2017-04-26 08:58:43 +03:00
# include <QThread>
2009-12-15 13:56:41 +03:00
2009-12-15 14:08:22 +03:00
# ifndef DISABLE_GUI
2015-06-13 09:20:16 +03:00
// GUI-only includes
2014-12-14 22:18:05 +03:00
# include <QFont>
# include <QMessageBox>
# include <QPainter>
# include <QPen>
# include <QPushButton>
# include <QSplashScreen>
2019-01-17 04:20:27 +03:00
# include <QTimer>
2017-03-20 09:11:49 +03:00
2014-12-14 22:18:05 +03:00
# ifdef QBT_STATIC_QT
2012-12-28 15:40:22 +04:00
# include <QtPlugin>
2014-05-01 23:53:29 +04:00
Q_IMPORT_PLUGIN ( QICOPlugin )
2014-12-14 22:18:05 +03:00
# endif // QBT_STATIC_QT
2015-06-13 09:20:16 +03:00
# else
// NoGUI-only includes
2015-01-22 15:56:16 +03:00
# include <cstdio>
2014-12-14 22:18:05 +03:00
# endif // DISABLE_GUI
2009-12-15 13:56:41 +03:00
2018-04-09 23:30:20 +03:00
# ifdef STACKTRACE
# ifdef Q_OS_UNIX
2009-09-30 22:57:06 +04:00
# include "stacktrace.h"
2018-04-09 23:30:20 +03:00
# else
2013-01-19 20:16:57 +04:00
# include "stacktrace_win.h"
2018-10-15 11:59:17 +03:00
# ifndef DISABLE_GUI
2018-06-14 12:54:23 +03:00
# include "stacktracedialog.h"
2018-10-15 11:59:17 +03:00
# endif // DISABLE_GUI
2018-04-09 23:30:20 +03:00
# endif // Q_OS_UNIX
# endif //STACKTRACE
2013-01-19 20:16:57 +04:00
2018-05-31 12:19:07 +03:00
# include "base/preferences.h"
2016-05-03 22:45:06 +03:00
# include "base/profile.h"
2015-09-25 11:10:05 +03:00
# include "base/utils/misc.h"
2018-05-31 12:19:07 +03:00
# include "application.h"
2017-05-07 14:40:33 +03:00
# include "cmdoptions.h"
2015-06-18 10:08:07 +03:00
# include "upgrade.h"
2019-03-02 08:22:13 +03:00
# ifndef DISABLE_GUI
# include "gui/utils.h"
# endif
2014-12-15 21:43:01 +03:00
// Signal handlers
2015-12-13 13:14:12 +03:00
void sigNormalHandler ( int signum ) ;
2018-04-09 23:30:20 +03:00
# ifdef STACKTRACE
2015-12-13 13:14:12 +03:00
void sigAbnormalHandler ( int signum ) ;
2018-04-09 23:30:20 +03:00
# endif
2015-12-13 13:14:12 +03:00
// sys_signame[] is only defined in BSD
2018-12-20 10:28:49 +03:00
const char * const sysSigName [ ] = {
2017-10-25 13:49:30 +03:00
# if defined(Q_OS_WIN)
" " , " " , " SIGINT " , " " , " SIGILL " , " " , " SIGABRT_COMPAT " , " " , " SIGFPE " , " " ,
" " , " SIGSEGV " , " " , " " , " " , " SIGTERM " , " " , " " , " " , " " ,
" " , " SIGBREAK " , " SIGABRT " , " " , " " , " " , " " , " " , " " , " " ,
" " , " "
# else
2015-12-13 13:14:12 +03:00
" " , " SIGHUP " , " SIGINT " , " SIGQUIT " , " SIGILL " , " SIGTRAP " , " SIGABRT " , " SIGBUS " , " SIGFPE " , " SIGKILL " ,
" SIGUSR1 " , " SIGSEGV " , " SIGUSR2 " , " SIGPIPE " , " SIGALRM " , " SIGTERM " , " SIGSTKFLT " , " SIGCHLD " , " SIGCONT " , " SIGSTOP " ,
" SIGTSTP " , " SIGTTIN " , " SIGTTOU " , " SIGURG " , " SIGXCPU " , " SIGXFSZ " , " SIGVTALRM " , " SIGPROF " , " SIGWINCH " , " SIGIO " ,
" SIGPWR " , " SIGUNUSED "
2017-10-25 13:49:30 +03:00
# endif
2015-12-13 13:14:12 +03:00
} ;
2014-12-15 21:43:01 +03:00
2018-10-15 11:59:17 +03:00
# if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU
2018-05-31 12:19:07 +03:00
void reportToUser ( const char * str ) ;
2017-05-03 02:31:02 +03:00
# endif
2014-12-15 21:43:01 +03:00
void displayVersion ( ) ;
bool userAgreesWithLegalNotice ( ) ;
2014-12-27 22:58:37 +03:00
void displayBadArgMessage ( const QString & message ) ;
2014-12-15 21:43:01 +03:00
2017-03-20 09:11:49 +03:00
# if !defined(DISABLE_GUI)
void showSplashScreen ( ) ;
# endif // DISABLE_GUI
2019-06-26 08:44:58 +03:00
# if defined(Q_OS_UNIX)
void adjustFileDescriptorLimit ( ) ;
# endif
2014-12-15 21:43:01 +03:00
// Main
int main ( int argc , char * argv [ ] )
{
2019-06-26 08:44:58 +03:00
# if defined(Q_OS_UNIX)
adjustFileDescriptorLimit ( ) ;
# endif
2014-12-15 21:43:01 +03:00
// We must save it here because QApplication constructor may change it
bool isOneArg = ( argc = = 2 ) ;
2016-05-03 22:45:06 +03:00
try {
// Create Application
2019-02-09 18:40:14 +03:00
const QString appId = QLatin1String ( " qBittorrent- " ) + Utils : : Misc : : getUserIDString ( ) ;
2019-02-16 07:29:57 +03:00
std : : unique_ptr < Application > app ( new Application ( appId , argc , argv ) ) ;
2017-03-20 09:11:49 +03:00
2017-05-08 19:01:38 +03:00
const QBtCommandLineParameters params = app - > commandLineArgs ( ) ;
2016-11-06 04:00:09 +03:00
2016-05-03 22:45:06 +03:00
if ( ! params . unknownParameter . isEmpty ( ) ) {
throw CommandLineParameterError ( QObject : : tr ( " %1 is an unknown command line parameter. " ,
" --random-parameter is an unknown command line parameter. " )
. arg ( params . unknownParameter ) ) ;
2014-12-21 10:40:38 +03:00
}
2018-10-15 11:59:17 +03:00
# if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
2016-05-03 22:45:06 +03:00
if ( params . showVersion ) {
if ( isOneArg ) {
displayVersion ( ) ;
return EXIT_SUCCESS ;
}
throw CommandLineParameterError ( QObject : : tr ( " %1 must be the single command line parameter. " )
. arg ( QLatin1String ( " -v (or --version) " ) ) ) ;
2014-12-21 10:40:38 +03:00
}
2014-12-21 17:26:31 +03:00
# endif
2016-05-03 22:45:06 +03:00
if ( params . showHelp ) {
if ( isOneArg ) {
displayUsage ( argv [ 0 ] ) ;
return EXIT_SUCCESS ;
}
throw CommandLineParameterError ( QObject : : tr ( " %1 must be the single command line parameter. " )
2014-12-21 10:40:38 +03:00
. arg ( QLatin1String ( " -h (or --help) " ) ) ) ;
}
2014-12-15 21:43:01 +03:00
2016-05-03 22:45:06 +03:00
// Set environment variable
if ( ! qputenv ( " QBITTORRENT " , QBT_VERSION ) )
2018-03-14 19:13:47 +03:00
fprintf ( stderr , " Couldn't set environment variable... \n " ) ;
2014-12-15 21:43:01 +03:00
2015-11-17 23:39:59 +03:00
# ifndef DISABLE_GUI
2016-05-03 22:45:06 +03:00
if ( ! userAgreesWithLegalNotice ( ) )
return EXIT_SUCCESS ;
2018-10-15 11:59:17 +03:00
# elif defined(Q_OS_WIN)
if ( _isatty ( _fileno ( stdin ) )
& & _isatty ( _fileno ( stdout ) )
& & ! userAgreesWithLegalNotice ( ) )
return EXIT_SUCCESS ;
2015-11-17 23:39:59 +03:00
# else
2016-05-03 22:45:06 +03:00
if ( ! params . shouldDaemonize
& & isatty ( fileno ( stdin ) )
& & isatty ( fileno ( stdout ) )
& & ! userAgreesWithLegalNotice ( ) )
return EXIT_SUCCESS ;
2015-11-17 23:39:59 +03:00
# endif
2014-12-15 21:43:01 +03:00
2016-05-03 22:45:06 +03:00
// Check if qBittorrent is already running for this user
if ( app - > isRunning ( ) ) {
2018-10-15 11:59:17 +03:00
# if defined(DISABLE_GUI) && !defined(Q_OS_WIN)
2016-05-03 22:45:06 +03:00
if ( params . shouldDaemonize ) {
throw CommandLineParameterError ( QObject : : tr ( " You cannot use %1: qBittorrent is already running for this user. " )
. arg ( QLatin1String ( " -d (or --daemon) " ) ) ) ;
}
else
2014-12-21 10:40:38 +03:00
# endif
2016-05-03 22:45:06 +03:00
qDebug ( " qBittorrent is already running for this user. " ) ;
2015-01-20 18:00:37 +03:00
2017-04-26 08:58:43 +03:00
QThread : : msleep ( 300 ) ;
2016-07-15 05:15:10 +03:00
app - > sendParams ( params . paramList ( ) ) ;
2014-12-15 21:43:01 +03:00
2016-05-03 22:45:06 +03:00
return EXIT_SUCCESS ;
}
2014-12-15 21:43:01 +03:00
2017-01-19 15:10:09 +03:00
# if defined(Q_OS_WIN)
2016-05-03 22:45:06 +03:00
// This affects only Windows apparently and Qt5.
// When QNetworkAccessManager is instantiated it regularly starts polling
// the network interfaces to see what's available and their status.
// This polling creates jitter and high ping with wifi interfaces.
// So here we disable it for lack of better measure.
// It will also spew this message in the console: QObject::startTimer: Timers cannot have negative intervals
// For more info see:
// 1. https://github.com/qbittorrent/qBittorrent/issues/4209
// 2. https://bugreports.qt.io/browse/QTBUG-40332
// 3. https://bugreports.qt.io/browse/QTBUG-46015
qputenv ( " QT_BEARER_POLL_TIMEOUT " , QByteArray : : number ( - 1 ) ) ;
2018-10-15 11:59:17 +03:00
# if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) && !defined(DISABLE_GUI)
2017-12-08 06:05:52 +03:00
// this is the default in Qt6
app - > setAttribute ( Qt : : AA_DisableWindowContextHelpButton ) ;
# endif
2018-11-06 18:49:17 +03:00
# endif // Q_OS_WIN
2016-03-27 22:53:40 +03:00
2019-09-05 15:11:33 +03:00
# if defined(Q_OS_MACOS)
2017-06-12 22:47:28 +03:00
// Since Apple made difficult for users to set PATH, we set here for convenience.
// Users are supposed to install Homebrew Python for search function.
// For more info see issue #5571.
QByteArray path = " /usr/local/bin: " ;
path + = qgetenv ( " PATH " ) ;
qputenv ( " PATH " , path . constData ( ) ) ;
2017-10-25 13:49:30 +03:00
2017-06-12 22:47:28 +03:00
// On OS X the standard is to not show icons in the menus
app - > setAttribute ( Qt : : AA_DontShowIconsInMenus ) ;
2016-11-07 07:29:55 +03:00
# endif
2015-11-17 23:39:59 +03:00
# ifndef DISABLE_GUI
2016-05-03 22:45:06 +03:00
if ( ! upgrade ( ) ) return EXIT_FAILURE ;
2018-10-15 11:59:17 +03:00
# elif defined(Q_OS_WIN)
if ( ! upgrade ( _isatty ( _fileno ( stdin ) )
& & _isatty ( _fileno ( stdout ) ) ) ) return EXIT_FAILURE ;
2015-11-17 23:39:59 +03:00
# else
2016-05-03 22:45:06 +03:00
if ( ! upgrade ( ! params . shouldDaemonize
& & isatty ( fileno ( stdin ) )
& & isatty ( fileno ( stdout ) ) ) ) return EXIT_FAILURE ;
2015-11-17 23:39:59 +03:00
# endif
2018-10-15 11:59:17 +03:00
# if defined(DISABLE_GUI) && !defined(Q_OS_WIN)
2016-05-03 22:45:06 +03:00
if ( params . shouldDaemonize ) {
app . reset ( ) ; // Destroy current application
2018-06-06 16:48:17 +03:00
if ( daemon ( 1 , 0 ) = = 0 ) {
2016-05-03 22:45:06 +03:00
app . reset ( new Application ( appId , argc , argv ) ) ;
if ( app - > isRunning ( ) ) {
// Another instance had time to start.
return EXIT_FAILURE ;
}
}
else {
qCritical ( " Something went wrong while daemonizing, exiting... " ) ;
2014-12-21 14:26:12 +03:00
return EXIT_FAILURE ;
}
}
2018-10-15 11:59:17 +03:00
# elif !defined(DISABLE_GUI)
2016-05-03 22:45:06 +03:00
if ( ! ( params . noSplash | | Preferences : : instance ( ) - > isSplashScreenDisabled ( ) ) )
showSplashScreen ( ) ;
2014-12-15 21:43:01 +03:00
# endif
2016-05-03 22:45:06 +03:00
signal ( SIGINT , sigNormalHandler ) ;
signal ( SIGTERM , sigNormalHandler ) ;
2018-04-09 23:30:20 +03:00
# ifdef STACKTRACE
2016-05-03 22:45:06 +03:00
signal ( SIGABRT , sigAbnormalHandler ) ;
signal ( SIGSEGV , sigAbnormalHandler ) ;
2014-12-21 17:26:31 +03:00
# endif
2014-12-21 10:40:38 +03:00
2016-07-15 05:15:10 +03:00
return app - > exec ( params . paramList ( ) ) ;
2016-05-03 22:45:06 +03:00
}
2019-05-16 10:02:17 +03:00
catch ( const CommandLineParameterError & er ) {
2016-05-03 22:45:06 +03:00
displayBadArgMessage ( er . messageForUser ( ) ) ;
return EXIT_FAILURE ;
2014-12-21 10:40:38 +03:00
}
}
2018-10-15 11:59:17 +03:00
# if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU
2018-05-31 12:19:07 +03:00
void reportToUser ( const char * str )
2017-05-03 02:31:02 +03:00
{
const size_t strLen = strlen ( str ) ;
2018-10-15 11:59:17 +03:00
# ifndef Q_OS_WIN
2017-05-03 02:31:02 +03:00
if ( write ( STDERR_FILENO , str , strLen ) < static_cast < ssize_t > ( strLen ) ) {
2019-02-09 18:40:14 +03:00
const auto dummy = write ( STDOUT_FILENO , str , strLen ) ;
2018-10-15 11:59:17 +03:00
# else
if ( _write ( STDERR_FILENO , str , strLen ) < static_cast < ssize_t > ( strLen ) ) {
const auto dummy = _write ( STDOUT_FILENO , str , strLen ) ;
# endif
2017-05-03 02:31:02 +03:00
Q_UNUSED ( dummy ) ;
}
}
# endif
2015-12-13 13:14:12 +03:00
void sigNormalHandler ( int signum )
2014-12-13 20:22:35 +03:00
{
2018-10-15 11:59:17 +03:00
# if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU
2017-10-25 13:49:30 +03:00
const char msg1 [ ] = " Catching signal: " ;
const char msg2 [ ] = " \n Exiting cleanly \n " ;
reportToUser ( msg1 ) ;
reportToUser ( sysSigName [ signum ] ) ;
reportToUser ( msg2 ) ;
2015-12-13 13:14:12 +03:00
# endif // !defined Q_OS_WIN && !defined Q_OS_HAIKU
signal ( signum , SIG_DFL ) ;
qApp - > exit ( ) ; // unsafe, but exit anyway
2009-09-30 22:57:06 +04:00
}
2014-12-13 20:22:35 +03:00
2018-04-09 23:30:20 +03:00
# ifdef STACKTRACE
2015-12-13 13:14:12 +03:00
void sigAbnormalHandler ( int signum )
2014-12-13 20:22:35 +03:00
{
2015-12-13 13:14:12 +03:00
const char * sigName = sysSigName [ signum ] ;
2018-10-15 11:59:17 +03:00
# if !(defined Q_OS_WIN && !defined DISABLE_GUI) && !defined Q_OS_HAIKU
2017-10-25 13:49:30 +03:00
const char msg [ ] = " \n \n ************************************************************* \n "
" Please file a bug report at http://bug.qbittorrent.org and provide the following information: \n \n "
" qBittorrent version: " QBT_VERSION " \n \n "
" Caught signal: " ;
reportToUser ( msg ) ;
2017-05-03 02:31:02 +03:00
reportToUser ( sigName ) ;
2017-10-25 13:49:30 +03:00
reportToUser ( " \n " ) ;
2015-12-13 13:14:12 +03:00
print_stacktrace ( ) ; // unsafe
2018-04-09 23:30:20 +03:00
# endif
2018-10-15 11:59:17 +03:00
# if defined Q_OS_WIN && !defined DISABLE_GUI
2018-06-14 12:54:23 +03:00
StacktraceDialog dlg ; // unsafe
2017-10-25 13:49:30 +03:00
dlg . setStacktraceString ( QLatin1String ( sigName ) , straceWin : : getBacktrace ( ) ) ;
2014-12-13 20:22:35 +03:00
dlg . exec ( ) ;
2018-04-09 23:30:20 +03:00
# endif
2015-12-13 13:14:12 +03:00
signal ( signum , SIG_DFL ) ;
raise ( signum ) ;
2009-11-15 13:42:03 +03:00
}
2018-04-09 23:30:20 +03:00
# endif // STACKTRACE
2006-09-30 20:02:39 +04:00
2017-03-20 09:11:49 +03:00
# if !defined(DISABLE_GUI)
2014-12-14 22:18:05 +03:00
void showSplashScreen ( )
2014-12-13 20:22:35 +03:00
{
2018-06-06 16:48:17 +03:00
QPixmap splashImg ( " :/icons/skin/splash.png " ) ;
QPainter painter ( & splashImg ) ;
2019-02-09 18:40:14 +03:00
const QString version = QBT_VERSION ;
2014-12-14 22:18:05 +03:00
painter . setPen ( QPen ( Qt : : white ) ) ;
painter . setFont ( QFont ( " Arial " , 22 , QFont : : Black ) ) ;
2019-07-01 09:34:02 +03:00
# if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
painter . drawText ( 224 - painter . fontMetrics ( ) . horizontalAdvance ( version ) , 270 , version ) ;
# else
2014-12-14 22:18:05 +03:00
painter . drawText ( 224 - painter . fontMetrics ( ) . width ( version ) , 270 , version ) ;
2019-07-01 09:34:02 +03:00
# endif
2018-06-06 16:48:17 +03:00
QSplashScreen * splash = new QSplashScreen ( splashImg ) ;
2014-12-14 22:18:05 +03:00
splash - > show ( ) ;
2018-05-10 20:42:19 +03:00
QTimer : : singleShot ( 1500 , splash , & QObject : : deleteLater ) ;
2014-12-14 22:18:05 +03:00
qApp - > processEvents ( ) ;
}
2017-03-20 09:11:49 +03:00
# endif // DISABLE_GUI
2014-12-13 20:22:35 +03:00
2014-12-14 22:18:05 +03:00
void displayVersion ( )
{
2018-03-14 19:13:47 +03:00
printf ( " %s %s \n " , qUtf8Printable ( qApp - > applicationName ( ) ) , QBT_VERSION ) ;
2014-12-14 22:18:05 +03:00
}
2018-05-31 12:19:07 +03:00
void displayBadArgMessage ( const QString & message )
2014-12-21 17:26:31 +03:00
{
2019-02-09 18:40:14 +03:00
const QString help = QObject : : tr ( " Run application with -h option to read about command line parameters. " ) ;
2018-10-15 11:59:17 +03:00
# if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
2014-12-21 17:26:31 +03:00
QMessageBox msgBox ( QMessageBox : : Critical , QObject : : tr ( " Bad command line " ) ,
message + QLatin1Char ( ' \n ' ) + help , QMessageBox : : Ok ) ;
msgBox . show ( ) ; // Need to be shown or to moveToCenter does not work
2019-03-02 08:22:13 +03:00
msgBox . move ( Utils : : Gui : : screenCenter ( & msgBox ) ) ;
2014-12-21 17:26:31 +03:00
msgBox . exec ( ) ;
# else
2018-03-14 19:13:47 +03:00
const QString errMsg = QObject : : tr ( " Bad command line: " ) + ' \n '
+ message + ' \n '
+ help + ' \n ' ;
fprintf ( stderr , " %s " , qUtf8Printable ( errMsg ) ) ;
2010-10-02 00:03:27 +04:00
# endif
2014-12-14 22:18:05 +03:00
}
2010-07-20 21:13:28 +04:00
2014-12-14 22:18:05 +03:00
bool userAgreesWithLegalNotice ( )
{
2018-05-31 12:19:07 +03:00
Preferences * const pref = Preferences : : instance ( ) ;
2014-12-14 22:18:05 +03:00
if ( pref - > getAcceptedLegal ( ) ) // Already accepted once
return true ;
2010-01-03 01:20:37 +03:00
2014-12-14 22:18:05 +03:00
# ifdef DISABLE_GUI
2018-03-14 19:13:47 +03:00
const QString eula = QString ( " \n *** %1 *** \n " ) . arg ( QObject : : tr ( " Legal Notice " ) )
+ 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 "
+ 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 ) ) ;
2019-02-09 18:40:14 +03:00
const char ret = getchar ( ) ; // Read pressed key
2018-06-06 16:48:17 +03:00
if ( ( ret = = ' y ' ) | | ( ret = = ' Y ' ) ) {
2014-12-14 22:18:05 +03:00
// Save the answer
pref - > setAcceptedLegal ( true ) ;
return true ;
2014-12-13 20:22:35 +03:00
}
2014-12-14 22:18:05 +03:00
# else
QMessageBox msgBox ;
msgBox . setText ( 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 No further notices will be issued. " ) ) ;
msgBox . setWindowTitle ( QObject : : tr ( " Legal notice " ) ) ;
msgBox . addButton ( QObject : : tr ( " Cancel " ) , QMessageBox : : RejectRole ) ;
2019-02-09 18:40:14 +03:00
const QAbstractButton * agreeButton = msgBox . addButton ( QObject : : tr ( " I Agree " ) , QMessageBox : : AcceptRole ) ;
2014-12-14 22:18:05 +03:00
msgBox . show ( ) ; // Need to be shown or to moveToCenter does not work
2019-03-02 08:22:13 +03:00
msgBox . move ( Utils : : Gui : : screenCenter ( & msgBox ) ) ;
2014-12-14 22:18:05 +03:00
msgBox . exec ( ) ;
2018-06-06 16:48:17 +03:00
if ( msgBox . clickedButton ( ) = = agreeButton ) {
2014-12-14 22:18:05 +03:00
// Save the answer
pref - > setAcceptedLegal ( true ) ;
return true ;
2014-12-13 20:22:35 +03:00
}
2018-05-31 12:19:07 +03:00
# endif // DISABLE_GUI
2014-12-13 20:22:35 +03:00
2014-12-14 22:18:05 +03:00
return false ;
}
2019-06-26 08:44:58 +03:00
# if defined(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