|
|
|
@ -132,18 +132,22 @@ bool userAgreesWithLegalNotice()
@@ -132,18 +132,22 @@ bool userAgreesWithLegalNotice()
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN) |
|
|
|
|
void sigintHandler(int) { |
|
|
|
|
void sigintHandler(int) |
|
|
|
|
{ |
|
|
|
|
signal(SIGINT, 0); |
|
|
|
|
qDebug("Catching SIGINT, exiting cleanly"); |
|
|
|
|
qApp->exit(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void sigtermHandler(int) { |
|
|
|
|
void sigtermHandler(int) |
|
|
|
|
{ |
|
|
|
|
signal(SIGTERM, 0); |
|
|
|
|
qDebug("Catching SIGTERM, exiting cleanly"); |
|
|
|
|
qApp->exit(); |
|
|
|
|
} |
|
|
|
|
void sigsegvHandler(int) { |
|
|
|
|
|
|
|
|
|
void sigsegvHandler(int) |
|
|
|
|
{ |
|
|
|
|
signal(SIGABRT, 0); |
|
|
|
|
signal(SIGSEGV, 0); |
|
|
|
|
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU |
|
|
|
@ -160,7 +164,9 @@ void sigsegvHandler(int) {
@@ -160,7 +164,9 @@ void sigsegvHandler(int) {
|
|
|
|
|
#endif |
|
|
|
|
raise(SIGSEGV); |
|
|
|
|
} |
|
|
|
|
void sigabrtHandler(int) { |
|
|
|
|
|
|
|
|
|
void sigabrtHandler(int) |
|
|
|
|
{ |
|
|
|
|
signal(SIGABRT, 0); |
|
|
|
|
signal(SIGSEGV, 0); |
|
|
|
|
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU |
|
|
|
@ -180,25 +186,26 @@ void sigabrtHandler(int) {
@@ -180,25 +186,26 @@ void sigabrtHandler(int) {
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Main
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
|
int main(int argc, char *argv[]) |
|
|
|
|
{ |
|
|
|
|
#if defined(Q_OS_MACX) && !defined(DISABLE_GUI) |
|
|
|
|
if ( QSysInfo::MacintoshVersion > QSysInfo::MV_10_8 ) |
|
|
|
|
{ |
|
|
|
|
if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) { |
|
|
|
|
// fix Mac OS X 10.9 (mavericks) font issue
|
|
|
|
|
// https://bugreports.qt-project.org/browse/QTBUG-32789
|
|
|
|
|
QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Create Application
|
|
|
|
|
QString uid = misc::getUserIDString(); |
|
|
|
|
#ifdef DISABLE_GUI |
|
|
|
|
bool shouldDaemonize = false; |
|
|
|
|
for(int i=1; i<argc; i++) { |
|
|
|
|
if(strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--daemon") == 0) { |
|
|
|
|
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]; |
|
|
|
|
for (int j = i; j < argc; j++) { |
|
|
|
|
argv[j] = argv[j + 1]; |
|
|
|
|
} |
|
|
|
|
i--; |
|
|
|
|
} |
|
|
|
@ -225,22 +232,27 @@ int main(int argc, char *argv[]) {
@@ -225,22 +232,27 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
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
|
|
|
|
|
} |
|
|
|
|
else { // Raise main window
|
|
|
|
|
app.sendMessage("qbt://show"); |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
return EXIT_SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
srand(time(0)); |
|
|
|
@ -248,7 +260,7 @@ int main(int argc, char *argv[]) {
@@ -248,7 +260,7 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
#ifndef DISABLE_GUI |
|
|
|
|
bool no_splash = false; |
|
|
|
|
#else |
|
|
|
|
if(shouldDaemonize && daemon(1, 0) != 0) { |
|
|
|
|
if (shouldDaemonize && daemon(1, 0) != 0) { |
|
|
|
|
qCritical("Something went wrong while daemonizing, exiting..."); |
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|
} |
|
|
|
@ -262,6 +274,7 @@ int main(int argc, char *argv[]) {
@@ -262,6 +274,7 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
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)) || |
|
|
|
@ -269,42 +282,50 @@ int main(int argc, char *argv[]) {
@@ -269,42 +282,50 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
#endif |
|
|
|
|
QString::fromUtf8("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { |
|
|
|
|
qDebug("Qt %s locale recognized, using translation.", qPrintable(locale)); |
|
|
|
|
}else{ |
|
|
|
|
} |
|
|
|
|
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{ |
|
|
|
|
} |
|
|
|
|
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 { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
app.setLayoutDirection(Qt::LeftToRight); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
app.setApplicationName(QString::fromUtf8("qBittorrent")); |
|
|
|
|
|
|
|
|
|
// Check for executable parameters
|
|
|
|
|
if (argc > 1) { |
|
|
|
|
if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--version")) { |
|
|
|
|
std::cout << "qBittorrent " << VERSION << '\n'; |
|
|
|
|
return 0; |
|
|
|
|
return EXIT_SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--help")) { |
|
|
|
|
displayUsage(argv[0]); |
|
|
|
|
return 0; |
|
|
|
|
return EXIT_SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i=1; i<argc; ++i) { |
|
|
|
|
for (int i = 1; i < argc; ++i) { |
|
|
|
|
#ifndef DISABLE_GUI |
|
|
|
|
if (QString::fromLocal8Bit(argv[i]) == QString::fromUtf8("--no-splash")) { |
|
|
|
|
no_splash = true; |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
#endif |
|
|
|
|
if (QString::fromLocal8Bit(argv[i]).startsWith("--webui-port=")) { |
|
|
|
|
QStringList parts = QString::fromLocal8Bit(argv[i]).split("="); |
|
|
|
@ -326,6 +347,7 @@ int main(int argc, char *argv[]) {
@@ -326,6 +347,7 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
if (pref->isSlashScreenDisabled()) { |
|
|
|
|
no_splash = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QSplashScreen *splash = 0; |
|
|
|
|
if (!no_splash) { |
|
|
|
|
QPixmap splash_img(":/Icons/skin/splash.png"); |
|
|
|
@ -340,6 +362,7 @@ int main(int argc, char *argv[]) {
@@ -340,6 +362,7 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
app.processEvents(); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Set environment variable
|
|
|
|
|
if (!qputenv("QBITTORRENT", QByteArray(VERSION))) { |
|
|
|
|
std::cerr << "Couldn't set environment variable...\n"; |
|
|
|
@ -350,17 +373,20 @@ int main(int argc, char *argv[]) {
@@ -350,17 +373,20 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (!userAgreesWithLegalNotice()) { |
|
|
|
|
return 0; |
|
|
|
|
return EXIT_SUCCESS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_GUI |
|
|
|
|
app.setQuitOnLastWindowClosed(false); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN) |
|
|
|
|
signal(SIGABRT, sigabrtHandler); |
|
|
|
|
signal(SIGTERM, sigtermHandler); |
|
|
|
|
signal(SIGINT, sigintHandler); |
|
|
|
|
signal(SIGSEGV, sigsegvHandler); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Read torrents given on command line
|
|
|
|
|
QStringList torrents; |
|
|
|
|
QStringList appArguments = app.arguments(); |
|
|
|
@ -390,5 +416,3 @@ int main(int argc, char *argv[]) {
@@ -390,5 +416,3 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
qDebug("Application has exited"); |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|