diff --git a/Changelog b/Changelog index 9e053af05..7f169f24f 100644 --- a/Changelog +++ b/Changelog @@ -18,6 +18,7 @@ - BUGFIX: Fixed spacing problem in toolbar when toggling its visibility - BUGFIX: Fixed some compilation and Qt4 warnings - BUGFIX: Do not use an addition dialog for torrents from folder scanning + - BUGFIX: Catch SIGTERM to exit cleanly (e.g. computer shutdown) * Sun Nov 9 2008 - Christophe Dumez - v1.2.1 - BUGFIX: Fixed possible crash when deleting a torrent permanently diff --git a/src/GUI.cpp b/src/GUI.cpp index 78ddd83dd..166b60c49 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -244,6 +244,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis // Destructor GUI::~GUI() { qDebug("GUI destruction"); + hide(); delete dlSpeedLbl; delete upSpeedLbl; delete ratioLbl; diff --git a/src/main.cpp b/src/main.cpp index 3dbc792b2..b5c8e8b43 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,12 +43,23 @@ #ifdef Q_WS_MAC #include #endif +#ifndef Q_WS_WIN + #include +#endif #include #include "GUI.h" #include "misc.h" #include "ico.h" +QApplication *app; + +#ifndef Q_WS_WIN + void sigtermHandler(int) { + qDebug("Catching SIGTERM, exiting cleanly"); + app->exit(); + } +#endif void useStyle(QApplication *app, int style){ switch(style) { @@ -144,9 +155,9 @@ int main(int argc, char *argv[]){ #ifndef QT_4_4 } #endif - QApplication app(argc, argv); - useStyle(&app, settings.value("Preferences/General/Style", 0).toInt()); - app.setStyleSheet("QStatusBar::item { border-width: 0; }"); + app = new QApplication(argc, argv); + useStyle(app, settings.value("Preferences/General/Style", 0).toInt()); + app->setStyleSheet("QStatusBar::item { border-width: 0; }"); QSplashScreen *splash = new QSplashScreen(QPixmap(QString::fromUtf8(":/Icons/splash.png"))); splash->show(); // Open options file to read locale @@ -161,17 +172,20 @@ int main(int argc, char *argv[]){ }else{ qDebug("%s locale unrecognized, using default (en_GB).", (const char*)locale.toUtf8()); } - app.installTranslator(&translator); - app.setApplicationName(QString::fromUtf8("qBittorrent")); - app.setQuitOnLastWindowClosed(false); + app->installTranslator(&translator); + app->setApplicationName(QString::fromUtf8("qBittorrent")); + app->setQuitOnLastWindowClosed(false); // Read torrents given on command line - QStringList torrentCmdLine = app.arguments(); + QStringList torrentCmdLine = app->arguments(); // Remove first argument (program name) torrentCmdLine.removeFirst(); GUI window(0, torrentCmdLine); splash->finish(&window); delete splash; - return app.exec(); +#ifndef Q_WS_WIN + signal(SIGTERM, sigtermHandler); +#endif + return app->exec(); }