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 >
2007-07-14 18:31:59 +04:00
* Copyright ( C ) 2006 Christophe Dumez
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 .
*
2007-07-14 18:31:59 +04:00
* Contact : chris @ qbittorrent . org
2006-09-30 20:02:39 +04:00
*/
2014-07-05 16:44:13 +04:00
# include <QDebug>
2014-12-21 14:26:12 +03:00
# include <QScopedPointer>
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>
# 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>
2015-06-13 09:20:16 +03:00
# ifdef Q_OS_UNIX
# include "unistd.h"
# endif
2014-12-14 22:18:05 +03:00
# endif // DISABLE_GUI
2009-12-15 13:56:41 +03:00
2014-12-14 22:18:05 +03:00
# ifdef Q_OS_UNIX
2009-09-30 22:57:06 +04:00
# include <signal.h>
# include <execinfo.h>
# include "stacktrace.h"
2014-12-14 22:18:05 +03:00
# endif // Q_OS_UNIX
2010-03-30 15:35:20 +04:00
2013-03-03 03:17:04 +04:00
# ifdef STACKTRACE_WIN
2013-01-19 20:16:57 +04:00
# include <signal.h>
# include "stacktrace_win.h"
# include "stacktrace_win_dlg.h"
2014-12-14 22:18:05 +03:00
# endif //STACKTRACE_WIN
2013-01-19 20:16:57 +04:00
2015-01-22 15:56:16 +03:00
# include <cstdlib>
2015-01-28 12:03:22 +03:00
# include <iostream>
# include "application.h"
2015-09-25 11:10:05 +03:00
# include "base/utils/misc.h"
# include "base/preferences.h"
2008-11-05 01:39:43 +03:00
2015-06-18 10:08:07 +03:00
# include "upgrade.h"
2014-12-15 21:43:01 +03:00
// Signal handlers
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
2015-12-13 13:14:12 +03:00
void sigNormalHandler ( int signum ) ;
void sigAbnormalHandler ( int signum ) ;
// sys_signame[] is only defined in BSD
const char * sysSigName [ ] = {
" " , " 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 "
} ;
2014-12-15 21:43:01 +03:00
# endif
2014-12-27 22:58:37 +03:00
struct QBtCommandLineParameters
2014-12-21 10:40:38 +03:00
{
bool showHelp ;
2014-12-21 17:26:31 +03:00
# ifndef Q_OS_WIN
bool showVersion ;
# endif
2014-12-15 21:43:01 +03:00
# ifndef DISABLE_GUI
2014-12-21 10:40:38 +03:00
bool noSplash ;
2014-12-15 21:43:01 +03:00
# else
2014-12-21 10:40:38 +03:00
bool shouldDaemonize ;
# endif
int webUiPort ;
QStringList torrents ;
2015-01-08 20:34:35 +03:00
QString unknownParameter ;
2014-12-21 17:26:31 +03:00
2014-12-27 22:58:37 +03:00
QBtCommandLineParameters ( )
2014-12-21 17:26:31 +03:00
: showHelp ( false )
# ifndef Q_OS_WIN
, showVersion ( false )
# endif
# ifndef DISABLE_GUI
, noSplash ( Preferences : : instance ( ) - > isSplashScreenDisabled ( ) )
# else
, shouldDaemonize ( false )
# endif
, webUiPort ( Preferences : : instance ( ) - > getWebUiPort ( ) )
{
}
2014-12-21 10:40:38 +03:00
} ;
# ifndef DISABLE_GUI
void showSplashScreen ( ) ;
2014-12-15 21:43:01 +03:00
# endif
void displayVersion ( ) ;
2014-12-27 22:58:37 +03:00
void displayUsage ( const QString & prg_name ) ;
2014-12-15 21:43:01 +03:00
bool userAgreesWithLegalNotice ( ) ;
2014-12-27 22:58:37 +03:00
void displayBadArgMessage ( const QString & message ) ;
QBtCommandLineParameters parseCommandLine ( ) ;
2014-12-15 21:43:01 +03:00
// Main
int main ( int argc , char * argv [ ] )
{
// We must save it here because QApplication constructor may change it
bool isOneArg = ( argc = = 2 ) ;
2016-10-07 16:42:47 +03:00
# ifdef Q_OS_MAC
// On macOS 10.12 Sierra, Apple changed the behaviour of CFPreferencesSetValue() https://bugreports.qt.io/browse/QTBUG-56344
// Due to this, we have to move from native plist to IniFormat
2016-12-12 00:20:31 +03:00
macMigratePlists ( ) ;
2016-10-07 16:42:47 +03:00
# endif
2016-11-06 04:00:09 +03:00
# ifndef DISABLE_GUI
migrateRSS ( ) ;
# endif
2014-12-15 21:43:01 +03:00
// Create Application
2015-05-06 14:53:27 +03:00
QString appId = QLatin1String ( " qBittorrent- " ) + Utils : : Misc : : getUserIDString ( ) ;
2015-01-21 20:30:24 +03:00
QScopedPointer < Application > app ( new Application ( appId , argc , argv ) ) ;
2014-12-15 21:43:01 +03:00
2014-12-27 22:58:37 +03:00
const QBtCommandLineParameters params = parseCommandLine ( ) ;
2014-12-15 21:43:01 +03:00
2015-01-08 20:34:35 +03:00
if ( ! params . unknownParameter . isEmpty ( ) ) {
displayBadArgMessage ( QObject : : tr ( " %1 is an unknown command line parameter. " , " --random-parameter is an unknown command line parameter. " )
. arg ( params . unknownParameter ) ) ;
2014-12-27 21:07:31 +03:00
return EXIT_FAILURE ;
}
2014-12-21 17:26:31 +03:00
# ifndef Q_OS_WIN
2014-12-21 10:40:38 +03:00
if ( params . showVersion ) {
if ( isOneArg ) {
displayVersion ( ) ;
return EXIT_SUCCESS ;
}
else {
displayBadArgMessage ( QObject : : tr ( " %1 must be the single command line parameter. " )
. arg ( QLatin1String ( " -v (or --version) " ) ) ) ;
return EXIT_FAILURE ;
}
}
2014-12-21 17:26:31 +03:00
# endif
2014-12-15 21:43:01 +03:00
2014-12-21 10:40:38 +03:00
if ( params . showHelp ) {
if ( isOneArg ) {
displayUsage ( argv [ 0 ] ) ;
return EXIT_SUCCESS ;
}
else {
displayBadArgMessage ( QObject : : tr ( " %1 must be the single command line parameter. " )
. arg ( QLatin1String ( " -h (or --help) " ) ) ) ;
return EXIT_FAILURE ;
}
}
2014-12-15 21:43:01 +03:00
2014-12-21 10:40:38 +03:00
if ( ( params . webUiPort > 0 ) & & ( params . webUiPort < = 65535 ) ) {
Preferences : : instance ( ) - > setWebUiPort ( params . webUiPort ) ;
}
else {
displayBadArgMessage ( QObject : : tr ( " %1 must specify the correct port (1 to 65535). " )
. arg ( QLatin1String ( " --webui-port " ) ) ) ;
return EXIT_FAILURE ;
}
2014-12-15 21:43:01 +03:00
// Set environment variable
2017-03-03 11:42:13 +03:00
if ( ! qputenv ( " QBITTORRENT " , QBT_VERSION ) )
2014-12-15 21:43:01 +03:00
std : : cerr < < " Couldn't set environment variable... \n " ;
2015-11-17 23:39:59 +03:00
# ifndef DISABLE_GUI
2014-12-15 21:43:01 +03:00
if ( ! userAgreesWithLegalNotice ( ) )
return EXIT_SUCCESS ;
2015-11-17 23:39:59 +03:00
# else
if ( ! params . shouldDaemonize
& & isatty ( fileno ( stdin ) )
& & isatty ( fileno ( stdout ) )
& & ! userAgreesWithLegalNotice ( ) )
return EXIT_SUCCESS ;
# endif
2014-12-15 21:43:01 +03:00
// Check if qBittorrent is already running for this user
2014-12-21 14:26:12 +03:00
if ( app - > isRunning ( ) ) {
2014-12-21 10:40:38 +03:00
# ifdef DISABLE_GUI
if ( params . shouldDaemonize ) {
displayBadArgMessage ( QObject : : tr ( " You cannot use %1: qBittorrent is already running for this user. " )
. arg ( QLatin1String ( " -d (or --daemon) " ) ) ) ;
return EXIT_FAILURE ;
}
2015-01-21 20:30:24 +03:00
else
2014-12-21 10:40:38 +03:00
# endif
2015-01-21 20:30:24 +03:00
qDebug ( " qBittorrent is already running for this user. " ) ;
2015-01-20 18:00:37 +03:00
2015-05-06 14:53:27 +03:00
Utils : : Misc : : msleep ( 300 ) ;
2015-01-22 15:56:16 +03:00
app - > sendParams ( params . torrents ) ;
2014-12-15 21:43:01 +03:00
return EXIT_SUCCESS ;
}
2017-01-19 15:10:09 +03:00
# if defined(Q_OS_WIN)
2016-03-27 22:53:40 +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 ) ) ;
# endif
2016-11-07 07:29:55 +03:00
# if defined(Q_OS_MAC)
{
// 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 ( ) ) ;
}
# endif
2015-11-17 23:39:59 +03:00
# ifndef DISABLE_GUI
2015-06-18 10:08:07 +03:00
if ( ! upgrade ( ) ) return EXIT_FAILURE ;
2015-11-17 23:39:59 +03:00
# else
if ( ! upgrade ( ! params . shouldDaemonize
& & isatty ( fileno ( stdin ) )
& & isatty ( fileno ( stdout ) ) ) ) return EXIT_FAILURE ;
# endif
2015-06-18 10:08:07 +03:00
2014-12-15 21:43:01 +03:00
# ifdef DISABLE_GUI
2014-12-21 10:40:38 +03:00
if ( params . shouldDaemonize ) {
2014-12-21 14:26:12 +03:00
app . reset ( ) ; // Destroy current application
if ( ( daemon ( 1 , 0 ) = = 0 ) ) {
2015-01-21 20:30:24 +03:00
app . reset ( new Application ( appId , argc , argv ) ) ;
2014-12-21 14:26:12 +03:00
if ( app - > isRunning ( ) ) {
// Another instance had time to start.
return EXIT_FAILURE ;
}
}
else {
qCritical ( " Something went wrong while daemonizing, exiting... " ) ;
return EXIT_FAILURE ;
}
2014-12-15 21:43:01 +03:00
}
# else
2014-12-21 17:26:31 +03:00
if ( ! params . noSplash )
2014-12-15 21:43:01 +03:00
showSplashScreen ( ) ;
# endif
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
2015-12-13 13:14:12 +03:00
signal ( SIGINT , sigNormalHandler ) ;
signal ( SIGTERM , sigNormalHandler ) ;
signal ( SIGABRT , sigAbnormalHandler ) ;
signal ( SIGSEGV , sigAbnormalHandler ) ;
2014-12-15 21:43:01 +03:00
# endif
2015-01-22 15:56:16 +03:00
return app - > exec ( params . torrents ) ;
2014-12-15 21:43:01 +03:00
}
2014-12-27 22:58:37 +03:00
QBtCommandLineParameters parseCommandLine ( )
2014-12-21 10:40:38 +03:00
{
2014-12-27 22:58:37 +03:00
QBtCommandLineParameters result ;
2014-12-21 10:40:38 +03:00
QStringList appArguments = qApp - > arguments ( ) ;
for ( int i = 1 ; i < appArguments . size ( ) ; + + i ) {
const QString & arg = appArguments [ i ] ;
2014-12-27 21:07:31 +03:00
if ( ( arg . startsWith ( " -- " ) & & ! arg . endsWith ( " .torrent " ) ) | |
( arg . startsWith ( " - " ) & & arg . size ( ) = = 2 ) ) {
//Parse known parameters
if ( ( arg = = QLatin1String ( " -h " ) ) | | ( arg = = QLatin1String ( " --help " ) ) ) {
result . showHelp = true ;
}
2014-12-21 17:26:31 +03:00
# ifndef Q_OS_WIN
2014-12-27 21:07:31 +03:00
else if ( ( arg = = QLatin1String ( " -v " ) ) | | ( arg = = QLatin1String ( " --version " ) ) ) {
result . showVersion = true ;
}
2014-12-21 17:26:31 +03:00
# endif
2014-12-27 21:07:31 +03:00
else if ( arg . startsWith ( QLatin1String ( " --webui-port= " ) ) ) {
QStringList parts = arg . split ( QLatin1Char ( ' = ' ) ) ;
if ( parts . size ( ) = = 2 )
result . webUiPort = parts . last ( ) . toInt ( ) ;
}
2014-12-21 10:40:38 +03:00
# ifndef DISABLE_GUI
2014-12-27 21:07:31 +03:00
else if ( arg = = QLatin1String ( " --no-splash " ) ) {
result . noSplash = true ;
}
2014-12-21 10:40:38 +03:00
# else
2014-12-27 21:07:31 +03:00
else if ( ( arg = = QLatin1String ( " -d " ) ) | | ( arg = = QLatin1String ( " --daemon " ) ) ) {
result . shouldDaemonize = true ;
}
2014-12-21 10:40:38 +03:00
# endif
2014-12-27 21:07:31 +03:00
else {
2015-01-08 20:34:35 +03:00
//Unknown argument
result . unknownParameter = arg ;
2014-12-27 21:07:31 +03:00
break ;
}
}
2014-12-21 10:40:38 +03:00
else {
QFileInfo torrentPath ;
torrentPath . setFile ( arg ) ;
if ( torrentPath . exists ( ) )
result . torrents + = torrentPath . absoluteFilePath ( ) ;
else
result . torrents + = arg ;
}
}
return result ;
}
2013-09-21 11:59:58 +04:00
# if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
2015-12-13 13:14:12 +03:00
void sigNormalHandler ( int signum )
2014-12-13 20:22:35 +03:00
{
2014-09-11 06:44:25 +04:00
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
2015-12-13 13:14:12 +03:00
const char str1 [ ] = " Catching signal: " ;
const char * sigName = sysSigName [ signum ] ;
const char str2 [ ] = " \n Exiting cleanly \n " ;
write ( STDERR_FILENO , str1 , strlen ( str1 ) ) ;
write ( STDERR_FILENO , sigName , strlen ( sigName ) ) ;
write ( STDERR_FILENO , str2 , strlen ( str2 ) ) ;
# 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
2015-12-13 13:14:12 +03:00
void sigAbnormalHandler ( int signum )
2014-12-13 20:22:35 +03:00
{
2014-09-11 06:44:25 +04:00
# if !defined Q_OS_WIN && !defined Q_OS_HAIKU
2015-12-13 13:14:12 +03:00
const char str1 [ ] = " \n \n ************************************************************* \n Catching signal: " ;
const char * sigName = sysSigName [ signum ] ;
const char str2 [ ] = " \n Please file a bug report at http://bug.qbittorrent.org and provide the following information: \n \n "
2017-03-03 11:42:13 +03:00
" qBittorrent version: " QBT_VERSION " \n " ;
2015-12-13 13:14:12 +03:00
write ( STDERR_FILENO , str1 , strlen ( str1 ) ) ;
write ( STDERR_FILENO , sigName , strlen ( sigName ) ) ;
write ( STDERR_FILENO , str2 , strlen ( str2 ) ) ;
print_stacktrace ( ) ; // unsafe
# endif // !defined Q_OS_WIN && !defined Q_OS_HAIKU
2013-01-25 22:52:12 +04:00
# ifdef STACKTRACE_WIN
2015-12-13 13:14:12 +03:00
StraceDlg dlg ; // unsafe
2014-12-13 20:22:35 +03:00
dlg . setStacktraceString ( straceWin : : getBacktrace ( ) ) ;
dlg . exec ( ) ;
2015-12-13 13:14:12 +03:00
# endif // STACKTRACE_WIN
signal ( signum , SIG_DFL ) ;
raise ( signum ) ;
2009-11-15 13:42:03 +03:00
}
2015-12-13 13:14:12 +03:00
# endif // defined(Q_OS_UNIX) || defined(STACKTRACE_WIN)
2006-09-30 20:02:39 +04:00
2014-12-14 22:18:05 +03:00
# ifndef DISABLE_GUI
void showSplashScreen ( )
2014-12-13 20:22:35 +03:00
{
2015-01-18 15:13:06 +03:00
QPixmap splash_img ( " :/icons/skin/splash.png " ) ;
2014-12-14 22:18:05 +03:00
QPainter painter ( & splash_img ) ;
2017-03-03 11:42:13 +03:00
QString version = QBT_VERSION ;
2014-12-14 22:18:05 +03:00
painter . setPen ( QPen ( Qt : : white ) ) ;
painter . setFont ( QFont ( " Arial " , 22 , QFont : : Black ) ) ;
painter . drawText ( 224 - painter . fontMetrics ( ) . width ( version ) , 270 , version ) ;
2016-01-25 16:59:20 +03:00
QSplashScreen * splash = new QSplashScreen ( splash_img ) ;
2014-12-14 22:18:05 +03:00
splash - > show ( ) ;
2016-02-03 19:39:10 +03:00
QTimer : : singleShot ( 1500 , splash , SLOT ( deleteLater ( ) ) ) ;
2014-12-14 22:18:05 +03:00
qApp - > processEvents ( ) ;
}
2013-11-11 12:38:20 +04:00
# endif
2014-12-13 20:22:35 +03:00
2014-12-14 22:18:05 +03:00
void displayVersion ( )
{
2017-03-03 11:42:13 +03:00
std : : cout < < qPrintable ( qApp - > applicationName ( ) ) < < " " < < QBT_VERSION < < std : : endl ;
2014-12-14 22:18:05 +03:00
}
2014-12-27 22:58:37 +03:00
QString makeUsage ( const QString & prg_name )
2014-12-14 22:18:05 +03:00
{
2014-12-21 17:26:31 +03:00
QString text ;
text + = QObject : : tr ( " Usage: " ) + QLatin1Char ( ' \n ' ) ;
# ifndef Q_OS_WIN
text + = QLatin1Char ( ' \t ' ) + prg_name + QLatin1String ( " (-v | --version) " ) + QLatin1Char ( ' \n ' ) ;
# endif
text + = QLatin1Char ( ' \t ' ) + prg_name + QLatin1String ( " (-h | --help) " ) + QLatin1Char ( ' \n ' ) ;
text + = QLatin1Char ( ' \t ' ) + prg_name
+ QLatin1String ( " [--webui-port=<port>] " )
2014-12-14 22:18:05 +03:00
# ifndef DISABLE_GUI
2014-12-21 17:26:31 +03:00
+ QLatin1String ( " [--no-splash] " )
2010-10-02 00:03:27 +04:00
# else
2014-12-21 17:26:31 +03:00
+ QLatin1String ( " [-d | --daemon] " )
# endif
+ QLatin1String ( " [(<filename> | <url>)...] " ) + QLatin1Char ( ' \n ' ) ;
text + = QObject : : tr ( " Options: " ) + QLatin1Char ( ' \n ' ) ;
# ifndef Q_OS_WIN
text + = QLatin1String ( " \t -v | --version \t \t " ) + QObject : : tr ( " Displays program version " ) + QLatin1Char ( ' \n ' ) ;
# endif
text + = QLatin1String ( " \t -h | --help \t \t " ) + QObject : : tr ( " Displays this help message " ) + QLatin1Char ( ' \n ' ) ;
text + = QLatin1String ( " \t --webui-port=<port> \t " )
2015-03-30 14:15:48 +03:00
+ QObject : : tr ( " Changes the Web UI port (current: %1) " ) . arg ( QString : : number ( Preferences : : instance ( ) - > getWebUiPort ( ) ) )
2014-12-21 17:26:31 +03:00
+ QLatin1Char ( ' \n ' ) ;
# ifndef DISABLE_GUI
text + = QLatin1String ( " \t --no-splash \t \t " ) + QObject : : tr ( " Disable splash screen " ) + QLatin1Char ( ' \n ' ) ;
# else
text + = QLatin1String ( " \t -d | --daemon \t \t " ) + QObject : : tr ( " Run in daemon-mode (background) " ) + QLatin1Char ( ' \n ' ) ;
# endif
text + = QLatin1String ( " \t files or urls \t \t " ) + QObject : : tr ( " Downloads the torrents passed by the user " ) ;
return text ;
}
2014-12-27 22:58:37 +03:00
void displayUsage ( const QString & prg_name )
2014-12-21 17:26:31 +03:00
{
# ifndef Q_OS_WIN
std : : cout < < qPrintable ( makeUsage ( prg_name ) ) < < std : : endl ;
# else
QMessageBox msgBox ( QMessageBox : : Information , QObject : : tr ( " Help " ) , makeUsage ( prg_name ) , QMessageBox : : Ok ) ;
msgBox . show ( ) ; // Need to be shown or to moveToCenter does not work
2015-05-06 14:53:27 +03:00
msgBox . move ( Utils : : Misc : : screenCenter ( & msgBox ) ) ;
2014-12-21 17:26:31 +03:00
msgBox . exec ( ) ;
# endif
}
2014-12-27 22:58:37 +03:00
void displayBadArgMessage ( const QString & message )
2014-12-21 17:26:31 +03:00
{
QString help = QObject : : tr ( " Run application with -h option to read about command line parameters. " ) ;
# ifdef Q_OS_WIN
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
2015-05-06 14:53:27 +03:00
msgBox . move ( Utils : : Misc : : screenCenter ( & msgBox ) ) ;
2014-12-21 17:26:31 +03:00
msgBox . exec ( ) ;
# else
std : : cerr < < qPrintable ( QObject : : tr ( " Bad command line: " ) ) ;
std : : cerr < < qPrintable ( message ) < < std : : endl ;
std : : cerr < < qPrintable ( help ) < < std : : endl ;
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 ( )
{
Preferences * const pref = Preferences : : instance ( ) ;
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
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 ;
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 ) ;
QAbstractButton * agree_button = msgBox . addButton ( QObject : : tr ( " I Agree " ) , QMessageBox : : AcceptRole ) ;
msgBox . show ( ) ; // Need to be shown or to moveToCenter does not work
2015-05-06 14:53:27 +03:00
msgBox . move ( Utils : : Misc : : screenCenter ( & msgBox ) ) ;
2014-12-14 22:18:05 +03:00
msgBox . exec ( ) ;
if ( msgBox . clickedButton ( ) = = agree_button ) {
// Save the answer
pref - > setAcceptedLegal ( true ) ;
return true ;
2014-12-13 20:22:35 +03:00
}
2009-12-15 13:56:41 +03:00
# endif
2014-12-13 20:22:35 +03:00
2014-12-14 22:18:05 +03:00
return false ;
}