mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-23 01:36:15 +03:00
Fixed possible crash on exit
Cleaned up main() function
This commit is contained in:
parent
864bb8285e
commit
1e21ac3d79
3 changed files with 66 additions and 105 deletions
|
@ -279,10 +279,7 @@ GUI::~GUI() {
|
|||
delete BTSession;
|
||||
// Deleting remaining top level widgets
|
||||
qDebug("Deleting remaining top level widgets");
|
||||
foreach (QWidget *win, QApplication::topLevelWidgets()) {
|
||||
if(win && win != this)
|
||||
delete win;
|
||||
}
|
||||
|
||||
// May freeze for a few seconds after the next line
|
||||
// because the Bittorrent session proxy will
|
||||
// actually be deleted now and destruction
|
||||
|
|
|
@ -1113,7 +1113,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
|||
//Getting fast resume data if existing
|
||||
std::vector<char> buf;
|
||||
if(resumed) {
|
||||
const QString fastresume_path = torrentBackup.path()+QDir::separator()+hash+QString(".fastresume");
|
||||
const QString fastresume_path = torrentBackup.absoluteFilePath(hash+QString(".fastresume"));
|
||||
qDebug("Trying to load fastresume data: %s", qPrintable(fastresume_path));
|
||||
if (load_file(fastresume_path.toLocal8Bit().constData(), buf) == 0) {
|
||||
fastResume = true;
|
||||
|
|
86
src/main.cpp
86
src/main.cpp
|
@ -63,16 +63,6 @@
|
|||
#include "misc.h"
|
||||
#include "preferences.h"
|
||||
|
||||
#ifdef DISABLE_GUI
|
||||
QtSingleCoreApplication *app;
|
||||
#else
|
||||
#ifndef Q_WS_MAC
|
||||
QtSingleApplication *app;
|
||||
#else
|
||||
QMacApplication *app;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class UsageDisplay: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -158,12 +148,11 @@ void sigabrtHandler(int) {
|
|||
#endif
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
void useStyle(QApplication *app, QString style){
|
||||
Q_UNUSED(app);
|
||||
void useStyle(QString style){
|
||||
if(!style.isEmpty()) {
|
||||
QApplication::setStyle(QStyleFactory::create(style));
|
||||
}
|
||||
Preferences::setStyle(app->style()->objectName());
|
||||
Preferences::setStyle(QApplication::style()->objectName());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -172,25 +161,17 @@ int main(int argc, char *argv[]){
|
|||
// Create Application
|
||||
QString uid = misc::getUserIDString();
|
||||
#ifdef DISABLE_GUI
|
||||
app = new QtSingleCoreApplication("qBittorrent-"+uid, argc, argv);
|
||||
QtSingleCoreApplication app("qBittorrent-"+uid, argc, argv);
|
||||
#else
|
||||
#ifndef Q_WS_MAC
|
||||
app = new QtSingleApplication("qBittorrent-"+uid, argc, argv);
|
||||
QtSingleApplication app("qBittorrent-"+uid, argc, argv);
|
||||
#else
|
||||
app = new QMacApplication("qBittorrent-"+uid, argc, argv);
|
||||
QMacApplication app("qBittorrent-"+uid, argc, argv);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// XXX: Workaround to avoid the following Qt bug:
|
||||
// http://bugreports.qt.nokia.com/browse/QTBUG-7105
|
||||
#ifndef DISABLE_GUI
|
||||
// Force the creation of an input context to avoid
|
||||
// a crash in QApplication destructor
|
||||
app->inputContext();
|
||||
#endif
|
||||
|
||||
// Check if qBittorrent is already running for this user
|
||||
if(app->isRunning()) {
|
||||
if(app.isRunning()) {
|
||||
qDebug("qBittorrent is already running for this user.");
|
||||
//Pass program parameters if any
|
||||
QString message;
|
||||
|
@ -204,7 +185,7 @@ int main(int argc, char *argv[]){
|
|||
if(!message.isEmpty()) {
|
||||
qDebug("Passing program parameters to running instance...");
|
||||
qDebug("Message: %s", qPrintable(message));
|
||||
app->sendMessage(message);
|
||||
app.sendMessage(message);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -227,27 +208,25 @@ int main(int argc, char *argv[]){
|
|||
}else{
|
||||
qDebug("%s locale unrecognized, using default (en_GB).", qPrintable(locale));
|
||||
}
|
||||
app->installTranslator(&translator);
|
||||
app.installTranslator(&translator);
|
||||
#ifndef DISABLE_GUI
|
||||
if(locale.startsWith("ar")) {
|
||||
qDebug("Right to Left mode");
|
||||
app->setLayoutDirection(Qt::RightToLeft);
|
||||
app.setLayoutDirection(Qt::RightToLeft);
|
||||
} else {
|
||||
app->setLayoutDirection(Qt::LeftToRight);
|
||||
app.setLayoutDirection(Qt::LeftToRight);
|
||||
}
|
||||
#endif
|
||||
app->setApplicationName(QString::fromUtf8("qBittorrent"));
|
||||
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';
|
||||
delete app;
|
||||
return 0;
|
||||
}
|
||||
if(QString::fromLocal8Bit(argv[1]) == QString::fromUtf8("--help")){
|
||||
UsageDisplay::displayUsage(argv[0]);
|
||||
delete app;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -284,8 +263,8 @@ int main(int argc, char *argv[]){
|
|||
}
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
useStyle(app, settings.value("Preferences/General/Style", "").toString());
|
||||
app->setStyleSheet("QStatusBar::item { border-width: 0; }");
|
||||
useStyle(settings.value("Preferences/General/Style", "").toString());
|
||||
app.setStyleSheet("QStatusBar::item { border-width: 0; }");
|
||||
QSplashScreen *splash = 0;
|
||||
if(!no_splash) {
|
||||
splash = new QSplashScreen(QPixmap(QString::fromUtf8(":/Icons/skin/splash.png")));
|
||||
|
@ -297,11 +276,10 @@ int main(int argc, char *argv[]){
|
|||
#ifndef DISABLE_GUI
|
||||
delete splash;
|
||||
#endif
|
||||
delete app;
|
||||
return 0;
|
||||
}
|
||||
#ifndef DISABLE_GUI
|
||||
app->setQuitOnLastWindowClosed(false);
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
#endif
|
||||
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
|
||||
signal(SIGABRT, sigabrtHandler);
|
||||
|
@ -310,41 +288,27 @@ int main(int argc, char *argv[]){
|
|||
signal(SIGSEGV, sigsegvHandler);
|
||||
#endif
|
||||
// Read torrents given on command line
|
||||
QStringList torrentCmdLine = app->arguments();
|
||||
QStringList torrentCmdLine = app.arguments();
|
||||
// Remove first argument (program name)
|
||||
torrentCmdLine.removeFirst();
|
||||
#ifndef DISABLE_GUI
|
||||
GUI *window = new GUI(0, torrentCmdLine);
|
||||
GUI window(0, torrentCmdLine);
|
||||
if(!no_splash) {
|
||||
splash->finish(window);
|
||||
splash->finish(&window);
|
||||
delete splash;
|
||||
}
|
||||
QObject::connect(app, SIGNAL(messageReceived(const QString&)),
|
||||
window, SLOT(processParams(const QString&)));
|
||||
app->setActivationWindow(window);
|
||||
QObject::connect(&app, SIGNAL(messageReceived(const QString&)),
|
||||
&window, SLOT(processParams(const QString&)));
|
||||
app.setActivationWindow(&window);
|
||||
#else
|
||||
// Load Headless class
|
||||
HeadlessLoader *loader = new HeadlessLoader(torrentCmdLine);
|
||||
QObject::connect(app, SIGNAL(messageReceived(const QString&)),
|
||||
loader, SLOT(processParams(const QString&)));
|
||||
#endif
|
||||
int ret = app->exec();
|
||||
|
||||
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
|
||||
// Application has exited, stop catching SIGINT and SIGTERM
|
||||
signal(SIGINT, 0);
|
||||
signal(SIGTERM, 0);
|
||||
HeadlessLoader loader(torrentCmdLine);
|
||||
QObject::connect(&app, SIGNAL(messageReceived(const QString&)),
|
||||
&loader, SLOT(processParams(const QString&)));
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
delete window;
|
||||
qDebug("GUI was deleted!");
|
||||
#else
|
||||
delete loader;
|
||||
#endif
|
||||
qDebug("Deleting app...");
|
||||
delete app;
|
||||
qDebug("App was deleted! All good.");
|
||||
int ret = app.exec();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue