@ -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,77 +78,144 @@ 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
# ifndef DISABLE_GUI
void showSplashScreen ( ) ;
void parseCommandLine ( bool & showVersion , bool & showUsage , bool & noSplash , QStringList & torrents ) ;
# else
void parseCommandLine ( bool & showVersion , bool & showUsage , bool & shouldDaemonize , QStringList & torrents ) ;
# endif
void displayVersion ( ) ;
void displayUsage ( const char * prg_name ) ;
bool userAgreesWithLegalNotice ( ) ;
public :
// Main
static void displayUsage ( char * prg_name ) {
int main ( int argc , char * argv [ ] )
std : : cout < < qPrintable ( tr ( " Usage: " ) ) < < std : : endl ;
{
std : : cout < < ' \t ' < < prg_name < < " --version: " < < qPrintable ( tr ( " displays program version " ) ) < < std : : endl ;
// We must save it here because QApplication constructor may change it
bool isOneArg = ( argc = = 2 ) ;
bool showVersion ;
bool showUsage ;
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
std : : cout < < ' \t ' < < prg_name < < " --no-splash: " < < qPrintable ( tr ( " disable splash screen " ) ) < < std : : endl ;
bool noSplash ;
# else
# else
std : : cout < < ' \t ' < < prg_name < < " -d | --daemon: " < < qPrintable ( tr ( " run in daemon-mode (background) " ) ) < < std : : endl ;
bool shouldDaemonize ;
# endif
# endif
std : : cout < < ' \t ' < < prg_name < < " --help: " < < qPrintable ( tr ( " displays this help message " ) ) < < std : : endl ;
QStringList torrents ;
std : : cout < < ' \t ' < < prg_name < < " --webui-port=x: " < < qPrintable ( tr ( " changes the webui port (current: %1) " ) . arg ( QString : : number ( Preferences : : instance ( ) - > getWebUiPort ( ) ) ) ) < < std : : endl ;
std : : cout < < ' \t ' < < prg_name < < " " < < qPrintable ( tr ( " [files or urls]: downloads the torrents passed by the user (optional) " ) ) < < std : : endl ;
// Create Application
Application app ( " qBittorrent- " + misc : : getUserIDString ( ) , argc , argv ) ;
# ifndef DISABLE_GUI
parseCommandLine ( showVersion , showUsage , noSplash , torrents ) ;
# else
parseCommandLine ( showVersion , showUsage , shouldDaemonize , torrents ) ;
# endif
if ( showVersion )
displayVersion ( ) ;
if ( showUsage )
displayUsage ( argv [ 0 ] ) ;
// If only one parameter is present and it is "--version"
// 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 " ;
}
}
} ;
class LegalNotice : public QObject {
if ( ! userAgreesWithLegalNotice ( ) )
Q_OBJECT
return EXIT_SUCCESS ;
public :
// Check if qBittorrent is already running for this user
static bool userAgreesWithNotice ( ) {
if ( app . isRunning ( ) ) {
Preferences * const pref = Preferences : : instance ( ) ;
qDebug ( " qBittorrent is already running for this user. " ) ;
if ( pref - > getAcceptedLegal ( ) ) // Already accepted once
# ifdef Q_OS_WIN
return true ;
DWORD pid = ( DWORD ) app . getRunningPid ( ) ;
if ( pid > 0 ) {
BOOL b = AllowSetForegroundWindow ( pid ) ;
qDebug ( " AllowSetForegroundWindow() returns %s " , b ? " TRUE " : " FALSE " ) ;
}
# endif
if ( ! torrents . isEmpty ( ) ) {
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
std : : cout < < std : : endl < < " *** " < < qPrintable ( tr ( " Legal Notice " ) ) < < " *** " < < std : : endl ;
if ( shouldDaemonize & & ( daemon ( 1 , 0 ) ! = 0 ) ) {
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 ;
qCritical ( " Something went wrong while daemonizing, exiting... " ) ;
std : : cout < < qPrintable ( tr ( " Press %1 key to accept and continue... " ) . arg ( " 'y' " ) ) < < std : : endl ;
return EXIT_FAILURE ;
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 ;
if ( ! noSplash )
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. " ) ) ;
showSplashScreen ( ) ;
msgBox . setWindowTitle ( tr ( " Legal notice " ) ) ;
# endif
msgBox . addButton ( tr ( " Cancel " ) , QMessageBox : : RejectRole ) ;
QAbstractButton * agree_button = msgBox . addButton ( tr ( " I Agree " ) , QMessageBox : : AcceptRole ) ;
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
msgBox . show ( ) ; // Need to be shown or to moveToCenter does not work
signal ( SIGABRT , sigabrtHandler ) ;
msgBox . move ( misc : : screenCenter ( & msgBox ) ) ;
signal ( SIGTERM , sigtermHandler ) ;
msgBox . exec ( ) ;
signal ( SIGINT , sigintHandler ) ;
if ( msgBox . clickedButton ( ) = = agree_button ) {
signal ( SIGSEGV , sigsegvHandler ) ;
// Save the answer
# endif
pref - > setAcceptedLegal ( true ) ;
return true ;
# ifndef DISABLE_GUI
}
MainWindow window ( 0 , torrents ) ;
return false ;
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
// Load Headless class
HeadlessLoader loader ( torrents ) ;
QObject : : connect ( & app , SIGNAL ( messageReceived ( const QString & ) ) ,
& loader , SLOT ( processParams ( const QString & ) ) ) ;
# endif
# endif
}
} ;
# include "main.moc"
int ret = app . exec ( ) ;
qDebug ( " Application has exited " ) ;
return ret ;
}
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
void sigintHandler ( int ) {
void sigintHandler ( int )
{
signal ( SIGINT , 0 ) ;
signal ( SIGINT , 0 ) ;
qDebug ( " Catching SIGINT, exiting cleanly " ) ;
qDebug ( " Catching SIGINT, exiting cleanly " ) ;
qApp - > exit ( ) ;
qApp - > exit ( ) ;
}
}
void sigtermHandler ( int ) {
void sigtermHandler ( int )
{
signal ( SIGTERM , 0 ) ;
signal ( SIGTERM , 0 ) ;
qDebug ( " Catching SIGTERM, exiting cleanly " ) ;
qDebug ( " Catching SIGTERM, exiting cleanly " ) ;
qApp - > exit ( ) ;
qApp - > exit ( ) ;
}
}
void sigsegvHandler ( int ) {
void sigsegvHandler ( int )
{
signal ( SIGABRT , 0 ) ;
signal ( SIGABRT , 0 ) ;
signal ( SIGSEGV , 0 ) ;
signal ( SIGSEGV , 0 ) ;
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
@ -170,7 +232,9 @@ void sigsegvHandler(int) {
# endif
# endif
raise ( SIGSEGV ) ;
raise ( SIGSEGV ) ;
}
}
void sigabrtHandler ( int ) {
void sigabrtHandler ( int )
{
signal ( SIGABRT , 0 ) ;
signal ( SIGABRT , 0 ) ;
signal ( SIGSEGV , 0 ) ;
signal ( SIGSEGV , 0 ) ;
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
@ -189,216 +253,129 @@ void sigabrtHandler(int) {
}
}
# endif
# endif
// Main
# ifndef DISABLE_GUI
int main ( int argc , char * argv [ ] ) {
void showSplashScreen ( )
# if defined(Q_OS_MACX) && !defined(DISABLE_GUI)
{
if ( QSysInfo : : MacintoshVersion > QSysInfo : : MV_10_8 )
QPixmap splash_img ( " :/Icons/skin/splash.png " ) ;
{
QPainter painter ( & splash_img ) ;
// fix Mac OS X 10.9 (mavericks) font issue
QString version = VERSION ;
// https://bugreports.qt-project.org/browse/QTBUG-32789
painter . setPen ( QPen ( Qt : : white ) ) ;
QFont : : insertSubstitution ( " .Lucida Grande UI " , " Lucida Grande " ) ;
painter . setFont ( QFont ( " Arial " , 22 , QFont : : Black ) ) ;
}
painter . drawText ( 224 - painter . fontMetrics ( ) . width ( version ) , 270 , version ) ;
# endif
QSplashScreen * splash = new QSplashScreen ( splash_img , Qt : : WindowStaysOnTopHint ) ;
// Create Application
QTimer : : singleShot ( 1500 , splash , SLOT ( deleteLater ( ) ) ) ;
QString uid = misc : : getUserIDString ( ) ;
splash - > show ( ) ;
# ifdef DISABLE_GUI
qApp - > processEvents ( ) ;
bool shouldDaemonize = false ;
}
for ( int i = 1 ; i < argc ; i + + ) {
if ( strcmp ( argv [ i ] , " -d " ) = = 0 | | strcmp ( argv [ i ] , " --daemon " ) = = 0 ) {
shouldDaemonize = true ;
argc - - ;
for ( int j = i ; j < argc ; j + + ) {
argv [ j ] = argv [ j + 1 ] ;
}
i - - ;
}
}
QtSingleCoreApplication app ( " qBittorrent- " + uid , argc , argv ) ;
# else
SessionApplication app ( " qBittorrent- " + uid , argc , argv ) ;
# endif
# endif
// Check if qBittorrent is already running for this user
void displayVersion ( )
if ( app . isRunning ( ) ) {
{
qDebug ( " qBittorrent is already running for this user. " ) ;
std : : cout < < qPrintable ( qApp - > applicationName ( ) ) < < " " < < VERSION < < std : : endl ;
// Read torrents given on command line
}
# ifdef Q_OS_WIN
DWORD pid = ( DWORD ) app . getRunningPid ( ) ;
if ( pid > 0 ) {
BOOL b = AllowSetForegroundWindow ( pid ) ;
qDebug ( " AllowSetForegroundWindow() returns %s " , b ? " TRUE " : " FALSE " ) ;
}
# 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 ) ) ;
void displayUsage ( const char * prg_name )
Preferences * const pref = Preferences : : instance ( ) ;
{
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
bool no_splash = false ;
std : : cout < < ' \t ' < < prg_name < < " --no-splash: " < < qPrintable ( QObject : : tr ( " disable splash screen " ) ) < < std : : endl ;
# else
# else
if ( shouldDaemonize & & daemon ( 1 , 0 ) ! = 0 ) {
std : : cout < < ' \t ' < < prg_name < < " -d | --daemon: " < < qPrintable ( QObject : : tr ( " run in daemon-mode (background) " ) ) < < std : : endl ;
qCritical ( " Something went wrong while daemonizing, exiting... " ) ;
return EXIT_FAILURE ;
}
# 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 ;
}
// Load translation
# ifndef DISABLE_GUI
QString locale = pref - > getLocale ( ) ;
void parseCommandLine ( bool & showVersion , bool & showUsage , bool & noSplash , QStringList & torrents )
QTranslator qtTranslator ;
# else
QTranslator translator ;
void parseCommandLine ( bool & showVersion , bool & showUsage , bool & shouldDaemonize , QStringList & torrents )
if ( locale . isEmpty ( ) ) {
locale = QLocale : : system ( ) . name ( ) ;
pref - > setLocale ( locale ) ;
}
if ( qtTranslator . load (
# if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QString : : fromUtf8 ( " qtbase_ " ) + locale , QLibraryInfo : : location ( QLibraryInfo : : TranslationsPath ) ) | |
qtTranslator . load (
# endif
# endif
QString : : fromUtf8 ( " qt_ " ) + locale , QLibraryInfo : : location ( QLibraryInfo : : TranslationsPath ) ) ) {
{
qDebug ( " Qt %s locale recognized, using translation. " , qPrintable ( locale ) ) ;
// Default values
} else {
showVersion = false ;
qDebug ( " Qt %s locale unrecognized, using default (en). " , qPrintable ( locale ) ) ;
showUsage = false ;
}
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
# ifndef DISABLE_GUI
if ( locale . startsWith ( " ar " ) | | locale . startsWith ( " he " ) ) {
noSplash = Preferences : : instance ( ) - > isSlashScreenDisabled ( ) ;
qDebug ( " Right to Left mode " ) ;
# else
app . setLayoutDirection ( Qt : : RightToLeft ) ;
shouldDaemonize = false ;
} else {
app . setLayoutDirection ( Qt : : LeftToRight ) ;
}
# endif
# endif
app . setApplicationName ( QString : : fromUtf8 ( " qBittorrent " ) ) ;
torrents . clear ( ) ;
// Check for executable parameters
QStringList appArguments = qApp - > arguments ( ) ;
if ( argc > 1 ) {
if ( QString : : fromLocal8Bit ( argv [ 1 ] ) = = QString : : fromUtf8 ( " --version " ) ) {
for ( int i = 1 ; i < appArguments . size ( ) ; + + i ) {
std : : cout < < " qBittorrent " < < VERSION < < ' \n ' ;
QString & arg = appArguments [ i ] ;
return 0 ;
if ( arg = = " --version " ) {
showVersion = true ;
}
}
if ( QString : : fromLocal8Bit ( argv [ 1 ] ) = = QString : : fromUtf8 ( " --help " ) ) {
else if ( arg = = " --usage " ) {
UsageDisplay : : displayUsage ( argv [ 0 ] ) ;
showUsage = true ;
return 0 ;
}
}
else if ( arg . startsWith ( " --webui-port= " ) ) {
for ( int i = 1 ; i < argc ; + + i ) {
QStringList parts = arg . split ( " = " ) ;
# ifndef DISABLE_GUI
if ( QString : : fromLocal8Bit ( argv [ i ] ) = = QString : : fromUtf8 ( " --no-splash " ) ) {
no_splash = true ;
} else {
# endif
if ( QString : : fromLocal8Bit ( argv [ i ] ) . startsWith ( " --webui-port= " ) ) {
QStringList parts = QString : : fromLocal8Bit ( argv [ i ] ) . split ( " = " ) ;
if ( parts . size ( ) = = 2 ) {
if ( parts . size ( ) = = 2 ) {
bool ok = false ;
bool ok = false ;
int new_port = parts . last ( ) . toInt ( & ok ) ;
int new_port = parts . last ( ) . toInt ( & ok ) ;
if ( ok & & new_port > 0 & & new_port < = 65535 ) {
if ( ok & & ( new_port > 0 ) & & ( new_port < = 65535 ) )
Preferences : : instance ( ) - > setWebUiPort ( new_port ) ;
Preferences : : instance ( ) - > setWebUiPort ( new_port ) ;
}
}
}
}
}
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
else if ( arg = = " --no-splash " ) {
noSplash = true ;
}
}
# endif
# else
}
else if ( ( arg = = " -d " ) | | ( arg = = " --daemon " ) ) {
shouldDaemonize = true ;
}
}
# endif
else if ( ! arg . startsWith ( " -- " ) ) {
QFileInfo torrentPath ;
torrentPath . setFile ( arg ) ;
# ifndef DISABLE_GUI
if ( torrentPath . exists ( ) )
if ( pref - > isSlashScreenDisabled ( ) ) {
torrents + = torrentPath . absoluteFilePath ( ) ;
no_splash = true ;
else
}
torrents + = arg ;
QSplashScreen * splash = 0 ;
if ( ! no_splash ) {
QPixmap splash_img ( " :/Icons/skin/splash.png " ) ;
QPainter painter ( & splash_img ) ;
QString version = VERSION ;
painter . setPen ( QPen ( Qt : : white ) ) ;
painter . setFont ( QFont ( " Arial " , 22 , QFont : : Black ) ) ;
painter . drawText ( 224 - painter . fontMetrics ( ) . width ( version ) , 270 , version ) ;
splash = new QSplashScreen ( splash_img , Qt : : WindowStaysOnTopHint ) ;
QTimer : : singleShot ( 1500 , splash , SLOT ( deleteLater ( ) ) ) ;
splash - > show ( ) ;
app . processEvents ( ) ;
}
}
# endif
// Set environment variable
if ( ! qputenv ( " QBITTORRENT " , QByteArray ( VERSION ) ) ) {
std : : cerr < < " Couldn't set environment variable... \n " ;
}
}
}
# ifndef DISABLE_GUI
bool userAgreesWithLegalNotice ( )
app . setStyleSheet ( " QStatusBar::item { border-width: 0; } " ) ;
{
# endif
Preferences * const pref = Preferences : : instance ( ) ;
if ( pref - > getAcceptedLegal ( ) ) // Already accepted once
return true ;
if ( ! LegalNotice : : userAgreesWithNotice ( ) ) {
# ifdef DISABLE_GUI
return 0 ;
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 ;
# ifndef DISABLE_GUI
std : : cout < < qPrintable ( QObject : : tr ( " Press %1 key to accept and continue... " ) . arg ( " 'y' " ) ) < < std : : endl ;
app . setQuitOnLastWindowClosed ( false ) ;
char ret = getchar ( ) ; // Read pressed key
# endif
if ( ret = = ' y ' | | ret = = ' Y ' ) {
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
// Save the answer
signal ( SIGABRT , sigabrtHandler ) ;
pref - > setAcceptedLegal ( true ) ;
signal ( SIGTERM , sigtermHandler ) ;
return true ;
signal ( SIGINT , sigintHandler ) ;
signal ( SIGSEGV , sigsegvHandler ) ;
# endif
// Read torrents given on command line
QStringList torrents ;
QStringList appArguments = app . arguments ( ) ;
for ( int i = 1 ; i < appArguments . size ( ) ; + + i ) {
if ( ! appArguments [ i ] . startsWith ( " -- " ) ) {
qDebug ( ) < < " Command line argument: " < < appArguments [ i ] ;
torrents < < appArguments [ i ] ;
}
}
}
# ifndef DISABLE_GUI
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
// Load Headless class
QMessageBox msgBox ;
HeadlessLoader loader ( torrents ) ;
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. " ) ) ;
QObject : : connect ( & app , SIGNAL ( messageReceived ( const QString & ) ) ,
msgBox . setWindowTitle ( QObject : : tr ( " Legal notice " ) ) ;
& loader , SLOT ( processParams ( const QString & ) ) ) ;
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
# endif
int ret = app . exec ( ) ;
return false ;
qDebug ( " Application has exited " ) ;
return ret ;
}
}