@ -1,5 +1,6 @@
/*
/*
* Bittorrent Client using Qt4 and libtorrent .
* Bittorrent Client using Qt and libtorrent .
* Copyright ( C ) 2014 Vladimir Golovnev < glassez @ yandex . ru >
* Copyright ( C ) 2006 Christophe Dumez
* Copyright ( C ) 2006 Christophe Dumez
*
*
* This program is free software ; you can redistribute it and / or
* This program is free software ; you can redistribute it and / or
@ -28,52 +29,46 @@
* Contact : chris @ qbittorrent . org
* Contact : chris @ qbittorrent . org
*/
*/
# include <QLocale>
# include <QTranslator>
# include <QFile>
# include <QLibraryInfo>
# include <QDebug>
# include <QDebug>
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
# if defined(QBT_STATIC_QT)
# include <QFont>
# include <QMessageBox>
# include <QPainter>
# include <QPen>
# include <QPushButton>
# include <QSplashScreen>
# include <QStyle>
# include <QStyleFactory>
# ifdef QBT_STATIC_QT
# include <QtPlugin>
# include <QtPlugin>
# if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
# if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
Q_IMPORT_PLUGIN ( QICOPlugin )
Q_IMPORT_PLUGIN ( QICOPlugin )
# else
# else
Q_IMPORT_PLUGIN ( qico )
Q_IMPORT_PLUGIN ( qico )
# endif
# endif
# endif
# endif // QBT_STATIC_QT
# include <QMessageBox>
# include <QStyleFactory>
# include <QStyle>
# include <QSplashScreen>
# include <QPainter>
# include <QPen>
# include <QFont>
# include <QPushButton>
# include <QTimer>
# include "sessionapplication.h"
# include "mainwindow.h"
# include "mainwindow.h"
# include "ico.h"
# include "ico.h"
# else
# else // DISABLE_GUI
# include "qtsinglecoreapplication.h"
# include <iostream>
# include <iostream>
# include <stdio.h>
# include <stdio.h>
# include "headlessloader.h"
# include "headlessloader.h"
# endif
# endif // DISABLE_GUI
# include "preferences.h"
# include "application.h"
# if defined(Q_OS_UNIX)
# ifdef Q_OS_UNIX
# include <signal.h>
# include <signal.h>
# include <execinfo.h>
# include <execinfo.h>
# include "stacktrace.h"
# include "stacktrace.h"
# endif
# endif // Q_OS_UNIX
# ifdef STACKTRACE_WIN
# ifdef STACKTRACE_WIN
# include <signal.h>
# include <signal.h>
# include "stacktrace_win.h"
# include "stacktrace_win.h"
# include "stacktrace_win_dlg.h"
# include "stacktrace_win_dlg.h"
# endif
# endif //STACKTRACE_WIN
# include <stdlib.h>
# include <stdlib.h>
# include "misc.h"
# include "misc.h"
@ -83,322 +78,304 @@ Q_IMPORT_PLUGIN(qico)
# error You seem to have updated QtSingleApplication without porting our custom QtSingleApplication::getRunningPid() function. Please see previous version to understate how it works.
# error You seem to have updated QtSingleApplication without porting our custom QtSingleApplication::getRunningPid() function. Please see previous version to understate how it works.
# endif
# endif
class UsageDisplay : public QObject {
// Signal handlers
Q_OBJECT
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
void sigintHandler ( int ) ;
void sigtermHandler ( int ) ;
void sigsegvHandler ( int ) ;
void sigabrtHandler ( int ) ;
# endif
public :
static void displayUsage ( char * prg_name ) {
std : : cout < < qPrintable ( tr ( " Usage: " ) ) < < std : : endl ;
std : : cout < < ' \t ' < < prg_name < < " --version: " < < qPrintable ( tr ( " displays program version " ) ) < < std : : endl ;
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
std : : cout < < ' \t ' < < prg_name < < " --no-splash: " < < qPrintable ( tr ( " disable splash screen " ) ) < < std : : endl ;
void showSplashScreen ( ) ;
void parseCommandLine ( bool & showVersion , bool & showUsage , bool & noSplash , QStringList & torrents ) ;
# else
# else
std : : cout < < ' \t ' < < prg_name < < " -d | --daemon: " < < qPrintable ( tr ( " run in daemon-mode (background) " ) ) < < std : : endl ;
void parseCommandLine ( bool & showVersion , bool & showUsage , bool & shouldDaemonize , QStringList & torrents ) ;
# endif
# endif
std : : cout < < ' \t ' < < prg_name < < " --help: " < < qPrintable ( tr ( " displays this help message " ) ) < < std : : endl ;
void displayVersion ( ) ;
std : : cout < < ' \t ' < < prg_name < < " --webui-port=x: " < < qPrintable ( tr ( " changes the webui port (current: %1) " ) . arg ( QString : : number ( Preferences : : instance ( ) - > getWebUiPort ( ) ) ) ) < < std : : endl ;
void displayUsage ( const char * prg_name ) ;
std : : cout < < ' \t ' < < prg_name < < " " < < qPrintable ( tr ( " [files or urls]: downloads the torrents passed by the user (optional) " ) ) < < std : : endl ;
bool userAgreesWithLegalNotice ( ) ;
}
} ;
class LegalNotice : public QObject {
// Main
Q_OBJECT
int main ( int argc , char * argv [ ] )
{
public :
// We must save it here because QApplication constructor may change it
static bool userAgreesWithNotice ( ) {
bool isOneArg = ( argc = = 2 ) ;
Preferences * const pref = Preferences : : instance ( ) ;
bool showVersion ;
if ( pref - > getAcceptedLegal ( ) ) // Already accepted once
bool showUsage ;
return true ;
# ifndef DISABLE_GUI
# ifdef DISABLE_GUI
bool noSplash ;
std : : cout < < std : : endl < < " *** " < < qPrintable ( tr ( " Legal Notice " ) ) < < " *** " < < std : : endl ;
std : : cout < < qPrintable ( 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. " ) ) < < std : : endl < < std : : endl ;
std : : cout < < qPrintable ( tr ( " Press %1 key to accept and continue... " ) . arg ( " 'y' " ) ) < < std : : endl ;
char ret = getchar ( ) ; // Read pressed key
if ( ret = = ' y ' | | ret = = ' Y ' ) {
// Save the answer
pref - > setAcceptedLegal ( true ) ;
return true ;
}
return false ;
# else
# else
QMessageBox msgBox ;
bool shouldDaemonize ;
msgBox . setText ( 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 ( tr ( " Legal notice " ) ) ;
msgBox . addButton ( tr ( " Cancel " ) , QMessageBox : : RejectRole ) ;
QAbstractButton * agree_button = msgBox . addButton ( tr ( " I Agree " ) , QMessageBox : : AcceptRole ) ;
msgBox . show ( ) ; // Need to be shown or to moveToCenter does not work
msgBox . move ( misc : : screenCenter ( & msgBox ) ) ;
msgBox . exec ( ) ;
if ( msgBox . clickedButton ( ) = = agree_button ) {
// Save the answer
pref - > setAcceptedLegal ( true ) ;
return true ;
}
return false ;
# endif
# endif
}
QStringList torrents ;
} ;
# include "main.moc"
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
// Create Application
void sigintHandler ( int ) {
Application app ( " qBittorrent- " + misc : : getUserIDString ( ) , argc , argv ) ;
signal ( SIGINT , 0 ) ;
qDebug ( " Catching SIGINT, exiting cleanly " ) ;
qApp - > exit ( ) ;
}
void sigtermHandler ( int ) {
# ifndef DISABLE_GUI
signal ( SIGTERM , 0 ) ;
parseCommandLine ( showVersion , showUsage , noSplash , torrents ) ;
qDebug ( " Catching SIGTERM, exiting cleanly " ) ;
qApp - > exit ( ) ;
}
void sigsegvHandler ( int ) {
signal ( SIGABRT , 0 ) ;
signal ( SIGSEGV , 0 ) ;
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
std : : cerr < < " \n \n ************************************************************* \n " ;
std : : cerr < < " Catching SIGSEGV, please report a bug at http://bug.qbittorrent.org \n and provide the following backtrace: \n " ;
std : : cerr < < " qBittorrent version: " < < VERSION < < std : : endl ;
print_stacktrace ( ) ;
# else
# ifdef STACKTRACE_WIN
StraceDlg dlg ;
dlg . setStacktraceString ( straceWin : : getBacktrace ( ) ) ;
dlg . exec ( ) ;
# endif
# endif
raise ( SIGSEGV ) ;
}
void sigabrtHandler ( int ) {
signal ( SIGABRT , 0 ) ;
signal ( SIGSEGV , 0 ) ;
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
std : : cerr < < " \n \n ************************************************************* \n " ;
std : : cerr < < " Catching SIGABRT, please report a bug at http://bug.qbittorrent.org \n and provide the following backtrace: \n " ;
std : : cerr < < " qBittorrent version: " < < VERSION < < std : : endl ;
print_stacktrace ( ) ;
# else
# else
# ifdef STACKTRACE_WIN
parseCommandLine ( showVersion , showUsage , shouldDaemonize , torrents ) ;
StraceDlg dlg ;
dlg . setStacktraceString ( straceWin : : getBacktrace ( ) ) ;
dlg . exec ( ) ;
# endif
# endif
raise ( SIGABRT ) ;
}
# endif
# endif
// Main
if ( showVersion )
int main ( int argc , char * argv [ ] ) {
displayVersion ( ) ;
# if defined(Q_OS_MACX) && !defined(DISABLE_GUI)
if ( QSysInfo : : MacintoshVersion > QSysInfo : : MV_10_8 )
if ( showUsage )
{
displayUsage ( argv [ 0 ] ) ;
// fix Mac OS X 10.9 (mavericks) font issue
// https://bugreports.qt-project.org/browse/QTBUG-32789
// If only one parameter is present and it is "--version"
QFont : : insertSubstitution ( " .Lucida Grande UI " , " Lucida Grande " ) ;
// or "--help", program exits after printing appropriate message.
}
if ( isOneArg & & ( showVersion | | showUsage ) )
return EXIT_SUCCESS ;
// Set environment variable
if ( ! qputenv ( " QBITTORRENT " , QByteArray ( VERSION ) ) ) {
std : : cerr < < " Couldn't set environment variable... \n " ;
}
if ( ! userAgreesWithLegalNotice ( ) )
return EXIT_SUCCESS ;
// Check if qBittorrent is already running for this user
if ( app . isRunning ( ) ) {
qDebug ( " qBittorrent is already running for this user. " ) ;
# ifdef Q_OS_WIN
DWORD pid = ( DWORD ) app . getRunningPid ( ) ;
if ( pid > 0 ) {
BOOL b = AllowSetForegroundWindow ( pid ) ;
qDebug ( " AllowSetForegroundWindow() returns %s " , b ? " TRUE " : " FALSE " ) ;
}
# endif
# endif
// Create Application
if ( ! torrents . isEmpty ( ) ) {
QString uid = misc : : getUserIDString ( ) ;
QString message = torrents . join ( " | " ) ;
qDebug ( " Passing program parameters to running instance... " ) ;
qDebug ( " Message: %s " , qPrintable ( message ) ) ;
app . sendMessage ( message ) ;
}
else { // Raise main window
app . sendMessage ( " qbt://show " ) ;
}
return EXIT_SUCCESS ;
}
srand ( time ( 0 ) ) ;
# ifdef DISABLE_GUI
# ifdef DISABLE_GUI
bool shouldDaemonize = false ;
if ( shouldDaemonize & & ( daemon ( 1 , 0 ) ! = 0 ) ) {
for ( int i = 1 ; i < argc ; i + + ) {
qCritical ( " Something went wrong while daemonizing, exiting... " ) ;
if ( strcmp ( argv [ i ] , " -d " ) = = 0 | | strcmp ( argv [ i ] , " --daemon " ) = = 0 ) {
return EXIT_FAILURE ;
shouldDaemonize = true ;
argc - - ;
for ( int j = i ; j < argc ; j + + ) {
argv [ j ] = argv [ j + 1 ] ;
}
i - - ;
}
}
}
QtSingleCoreApplication app ( " qBittorrent- " + uid , argc , argv ) ;
# else
# else
SessionApplication app ( " qBittorrent- " + uid , argc , argv ) ;
if ( ! noSplash )
showSplashScreen ( ) ;
# endif
# endif
// Check if qBittorrent is already running for this user
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
if ( app . isRunning ( ) ) {
signal ( SIGABRT , sigabrtHandler ) ;
qDebug ( " qBittorrent is already running for this user. " ) ;
signal ( SIGTERM , sigtermHandler ) ;
// Read torrents given on command line
signal ( SIGINT , sigintHandler ) ;
# ifdef Q_OS_WIN
signal ( SIGSEGV , sigsegvHandler ) ;
DWORD pid = ( DWORD ) app . getRunningPid ( ) ;
if ( pid > 0 ) {
BOOL b = AllowSetForegroundWindow ( pid ) ;
qDebug ( " AllowSetForegroundWindow() returns %s " , b ? " TRUE " : " FALSE " ) ;
}
# endif
# endif
QStringList torrentCmdLine = app . arguments ( ) ;
//Pass program parameters if any
QString message ;
QFileInfo torrentPath ;
for ( int a = 1 ; a < torrentCmdLine . size ( ) ; + + a ) {
if ( torrentCmdLine [ a ] . startsWith ( " -- " ) ) continue ;
torrentPath . setFile ( torrentCmdLine [ a ] ) ;
if ( torrentPath . exists ( ) )
message + = torrentPath . absoluteFilePath ( ) ;
else
message + = torrentCmdLine [ a ] ;
if ( a < argc - 1 )
message + = " | " ;
}
if ( ! message . isEmpty ( ) ) {
qDebug ( " Passing program parameters to running instance... " ) ;
qDebug ( " Message: %s " , qPrintable ( message ) ) ;
app . sendMessage ( message ) ;
} else { // Raise main window
app . sendMessage ( " qbt://show " ) ;
}
return 0 ;
}
srand ( time ( 0 ) ) ;
Preferences * const pref = Preferences : : instance ( ) ;
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
bool no_splash = false ;
MainWindow window ( 0 , torrents ) ;
QObject : : connect ( & app , SIGNAL ( messageReceived ( const QString & ) ) ,
& window , SLOT ( processParams ( const QString & ) ) ) ;
app . setActivationWindow ( & window ) ;
# ifdef Q_OS_MAC
static_cast < QMacApplication * > ( & app ) - > setReadyToProcessEvents ( ) ;
# endif // Q_OS_MAC
# else
# else
if ( shouldDaemonize & & daemon ( 1 , 0 ) ! = 0 ) {
// Load Headless class
qCritical ( " Something went wrong while daemonizing, exiting... " ) ;
HeadlessLoader loader ( torrents ) ;
return EXIT_FAILURE ;
QObject : : connect ( & app , SIGNAL ( messageReceived ( const QString & ) ) ,
}
& loader , SLOT ( processParams ( const QString & ) ) ) ;
# endif
# endif
// Load translation
int ret = app . exec ( ) ;
QString locale = pref - > getLocale ( ) ;
qDebug ( " Application has exited " ) ;
QTranslator qtTranslator ;
return ret ;
QTranslator translator ;
}
if ( locale . isEmpty ( ) ) {
locale = QLocale : : system ( ) . name ( ) ;
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
pref - > setLocale ( locale ) ;
void sigintHandler ( int )
}
{
if ( qtTranslator . load (
signal ( SIGINT , 0 ) ;
# if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
qDebug ( " Catching SIGINT, exiting cleanly " ) ;
QString : : fromUtf8 ( " qtbase_ " ) + locale , QLibraryInfo : : location ( QLibraryInfo : : TranslationsPath ) ) | |
qApp - > exit ( ) ;
qtTranslator . load (
}
void sigtermHandler ( int )
{
signal ( SIGTERM , 0 ) ;
qDebug ( " Catching SIGTERM, exiting cleanly " ) ;
qApp - > exit ( ) ;
}
void sigsegvHandler ( int )
{
signal ( SIGABRT , 0 ) ;
signal ( SIGSEGV , 0 ) ;
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
std : : cerr < < " \n \n ************************************************************* \n " ;
std : : cerr < < " Catching SIGSEGV, please report a bug at http://bug.qbittorrent.org \n and provide the following backtrace: \n " ;
std : : cerr < < " qBittorrent version: " < < VERSION < < std : : endl ;
print_stacktrace ( ) ;
# else
# ifdef STACKTRACE_WIN
StraceDlg dlg ;
dlg . setStacktraceString ( straceWin : : getBacktrace ( ) ) ;
dlg . exec ( ) ;
# endif
# endif
QString : : fromUtf8 ( " qt_ " ) + locale , QLibraryInfo : : location ( QLibraryInfo : : TranslationsPath ) ) ) {
qDebug ( " Qt %s locale recognized, using translation. " , qPrintable ( locale ) ) ;
} else {
qDebug ( " Qt %s locale unrecognized, using default (en). " , qPrintable ( locale ) ) ;
}
app . installTranslator ( & qtTranslator ) ;
if ( translator . load ( QString : : fromUtf8 ( " :/lang/qbittorrent_ " ) + locale ) ) {
qDebug ( " %s locale recognized, using translation. " , qPrintable ( locale ) ) ;
} else {
qDebug ( " %s locale unrecognized, using default (en). " , qPrintable ( locale ) ) ;
}
app . installTranslator ( & translator ) ;
# ifndef DISABLE_GUI
if ( locale . startsWith ( " ar " ) | | locale . startsWith ( " he " ) ) {
qDebug ( " Right to Left mode " ) ;
app . setLayoutDirection ( Qt : : RightToLeft ) ;
} else {
app . setLayoutDirection ( Qt : : LeftToRight ) ;
}
# endif
# endif
app . setApplicationName ( QString : : fromUtf8 ( " qBittorrent " ) ) ;
raise ( SIGSEGV ) ;
}
// Check for executable parameters
if ( argc > 1 ) {
if ( QString : : fromLocal8Bit ( argv [ 1 ] ) = = QString : : fromUtf8 ( " --version " ) ) {
std : : cout < < " qBittorrent " < < VERSION < < ' \n ' ;
return 0 ;
}
if ( QString : : fromLocal8Bit ( argv [ 1 ] ) = = QString : : fromUtf8 ( " --help " ) ) {
UsageDisplay : : displayUsage ( argv [ 0 ] ) ;
return 0 ;
}
for ( int i = 1 ; i < argc ; + + i ) {
void sigabrtHandler ( int )
# ifndef DISABLE_GUI
{
if ( QString : : fromLocal8Bit ( argv [ i ] ) = = QString : : fromUtf8 ( " --no-splash " ) ) {
signal ( SIGABRT , 0 ) ;
no_splash = true ;
signal ( SIGSEGV , 0 ) ;
} else {
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
std : : cerr < < " \n \n ************************************************************* \n " ;
std : : cerr < < " Catching SIGABRT, please report a bug at http://bug.qbittorrent.org \n and provide the following backtrace: \n " ;
std : : cerr < < " qBittorrent version: " < < VERSION < < std : : endl ;
print_stacktrace ( ) ;
# else
# ifdef STACKTRACE_WIN
StraceDlg dlg ;
dlg . setStacktraceString ( straceWin : : getBacktrace ( ) ) ;
dlg . exec ( ) ;
# endif
# endif
if ( QString : : fromLocal8Bit ( argv [ i ] ) . startsWith ( " --webui-port= " ) ) {
QStringList parts = QString : : fromLocal8Bit ( argv [ i ] ) . split ( " = " ) ;
if ( parts . size ( ) = = 2 ) {
bool ok = false ;
int new_port = parts . last ( ) . toInt ( & ok ) ;
if ( ok & & new_port > 0 & & new_port < = 65535 ) {
Preferences : : instance ( ) - > setWebUiPort ( new_port ) ;
}
}
}
# ifndef DISABLE_GUI
}
# endif
# endif
}
raise ( SIGABRT ) ;
}
}
# endif
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
if ( pref - > isSlashScreenDisabled ( ) ) {
void showSplashScreen ( )
no_splash = true ;
{
}
QSplashScreen * splash = 0 ;
if ( ! no_splash ) {
QPixmap splash_img ( " :/Icons/skin/splash.png " ) ;
QPixmap splash_img ( " :/Icons/skin/splash.png " ) ;
QPainter painter ( & splash_img ) ;
QPainter painter ( & splash_img ) ;
QString version = VERSION ;
QString version = VERSION ;
painter . setPen ( QPen ( Qt : : white ) ) ;
painter . setPen ( QPen ( Qt : : white ) ) ;
painter . setFont ( QFont ( " Arial " , 22 , QFont : : Black ) ) ;
painter . setFont ( QFont ( " Arial " , 22 , QFont : : Black ) ) ;
painter . drawText ( 224 - painter . fontMetrics ( ) . width ( version ) , 270 , version ) ;
painter . drawText ( 224 - painter . fontMetrics ( ) . width ( version ) , 270 , version ) ;
splash = new QSplashScreen ( splash_img , Qt : : WindowStaysOnTopHint ) ;
QSplashScreen * splash = new QSplashScreen ( splash_img , Qt : : WindowStaysOnTopHint ) ;
QTimer : : singleShot ( 1500 , splash , SLOT ( deleteLater ( ) ) ) ;
QTimer : : singleShot ( 1500 , splash , SLOT ( deleteLater ( ) ) ) ;
splash - > show ( ) ;
splash - > show ( ) ;
app . processEvents ( ) ;
qApp - > processEvents ( ) ;
}
}
# endif
# endif
// Set environment variable
if ( ! qputenv ( " QBITTORRENT " , QByteArray ( VERSION ) ) ) {
std : : cerr < < " Couldn't set environment variable... \n " ;
}
void displayVersion ( )
{
std : : cout < < qPrintable ( qApp - > applicationName ( ) ) < < " " < < VERSION < < std : : endl ;
}
void displayUsage ( const char * prg_name )
{
std : : cout < < qPrintable ( QObject : : tr ( " Usage: " ) ) < < std : : endl ;
std : : cout < < ' \t ' < < prg_name < < " --version: " < < qPrintable ( QObject : : tr ( " displays program version " ) ) < < std : : endl ;
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
app . setStyleSheet ( " QStatusBar::item { border-width: 0; } " ) ;
std : : cout < < ' \t ' < < prg_name < < " --no-splash: " < < qPrintable ( QObject : : tr ( " disable splash screen " ) ) < < std : : endl ;
# else
std : : cout < < ' \t ' < < prg_name < < " -d | --daemon: " < < qPrintable ( QObject : : tr ( " run in daemon-mode (background) " ) ) < < std : : endl ;
# endif
# endif
std : : cout < < ' \t ' < < prg_name < < " --help: " < < qPrintable ( QObject : : tr ( " displays this help message " ) ) < < std : : endl ;
std : : cout < < ' \t ' < < prg_name < < " --webui-port=x: " < < qPrintable ( QObject : : tr ( " changes the webui port (current: %1) " ) . arg ( QString : : number ( Preferences : : instance ( ) - > getWebUiPort ( ) ) ) ) < < std : : endl ;
std : : cout < < ' \t ' < < prg_name < < " " < < qPrintable ( QObject : : tr ( " [files or urls]: downloads the torrents passed by the user (optional) " ) ) < < std : : endl ;
}
if ( ! LegalNotice : : userAgreesWithNotice ( ) ) {
return 0 ;
}
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
app . setQuitOnLastWindowClosed ( false ) ;
void parseCommandLine ( bool & showVersion , bool & showUsage , bool & noSplash , QStringList & torrents )
# else
void parseCommandLine ( bool & showVersion , bool & showUsage , bool & shouldDaemonize , QStringList & torrents )
# endif
# endif
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
{
signal ( SIGABRT , sigabrtHandler ) ;
// Default values
signal ( SIGTERM , sigtermHandler ) ;
showVersion = false ;
signal ( SIGINT , sigintHandler ) ;
showUsage = false ;
signal ( SIGSEGV , sigsegvHandler ) ;
# ifndef DISABLE_GUI
noSplash = Preferences : : instance ( ) - > isSlashScreenDisabled ( ) ;
# else
shouldDaemonize = false ;
# endif
# endif
// Read torrents given on command line
torrents . clear ( ) ;
QStringList torrents ;
QStringList appArguments = app . arguments ( ) ;
QStringList appArguments = qApp - > arguments ( ) ;
for ( int i = 1 ; i < appArguments . size ( ) ; + + i ) {
if ( ! appArguments [ i ] . startsWith ( " -- " ) ) {
for ( int i = 1 ; i < appArguments . size ( ) ; + + i ) {
qDebug ( ) < < " Command line argument: " < < appArguments [ i ] ;
QString & arg = appArguments [ i ] ;
torrents < < appArguments [ i ] ;
}
}
if ( arg = = " --version " ) {
showVersion = true ;
}
else if ( arg = = " --usage " ) {
showUsage = true ;
}
else if ( arg . startsWith ( " --webui-port= " ) ) {
QStringList parts = arg . split ( " = " ) ;
if ( parts . size ( ) = = 2 ) {
bool ok = false ;
int new_port = parts . last ( ) . toInt ( & ok ) ;
if ( ok & & ( new_port > 0 ) & & ( new_port < = 65535 ) )
Preferences : : instance ( ) - > setWebUiPort ( new_port ) ;
}
}
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
MainWindow window ( 0 , torrents ) ;
else if ( arg = = " --no-splash " ) {
QObject : : connect ( & app , SIGNAL ( messageReceived ( const QString & ) ) ,
noSplash = true ;
& window , SLOT ( processParams ( const QString & ) ) ) ;
}
app . setActivationWindow ( & window ) ;
# ifdef Q_OS_MAC
static_cast < QMacApplication * > ( & app ) - > setReadyToProcessEvents ( ) ;
# endif // Q_OS_MAC
# else
# else
// Load Headless class
else if ( ( arg = = " -d " ) | | ( arg = = " --daemon " ) ) {
HeadlessLoader loader ( torrents ) ;
shouldDaemonize = true ;
QObject : : connect ( & app , SIGNAL ( messageReceived ( const QString & ) ) ,
}
& loader , SLOT ( processParams ( const QString & ) ) ) ;
# endif
# endif
else if ( ! arg . startsWith ( " -- " ) ) {
QFileInfo torrentPath ;
torrentPath . setFile ( arg ) ;
int ret = app . exec ( ) ;
if ( torrentPath . exists ( ) )
qDebug ( " Application has exited " ) ;
torrents + = torrentPath . absoluteFilePath ( ) ;
return ret ;
else
torrents + = arg ;
}
}
}
}
bool userAgreesWithLegalNotice ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
if ( pref - > getAcceptedLegal ( ) ) // Already accepted once
return true ;
# ifdef DISABLE_GUI
std : : cout < < std : : endl < < " *** " < < qPrintable ( QObject : : tr ( " Legal Notice " ) ) < < " *** " < < std : : endl ;
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 \n No further notices will be issued. " ) ) < < std : : endl < < std : : endl ;
std : : cout < < qPrintable ( QObject : : tr ( " Press %1 key to accept and continue... " ) . arg ( " 'y' " ) ) < < std : : endl ;
char ret = getchar ( ) ; // Read pressed key
if ( ret = = ' y ' | | ret = = ' Y ' ) {
// Save the answer
pref - > setAcceptedLegal ( true ) ;
return true ;
}
# 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 ) ;
QAbstractButton * agree_button = msgBox . addButton ( QObject : : tr ( " I Agree " ) , QMessageBox : : AcceptRole ) ;
msgBox . show ( ) ; // Need to be shown or to moveToCenter does not work
msgBox . move ( misc : : screenCenter ( & msgBox ) ) ;
msgBox . exec ( ) ;
if ( msgBox . clickedButton ( ) = = agree_button ) {
// Save the answer
pref - > setAcceptedLegal ( true ) ;
return true ;
}
# endif
return false ;
}