1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Clean program exit on system shutdown/logout

This commit is contained in:
Christophe Dumez 2010-10-01 20:03:27 +00:00
parent 129bfac549
commit 1e86ea8c0a
7 changed files with 70 additions and 16 deletions

View File

@ -71,6 +71,7 @@
void qt_mac_set_dock_menu(QMenu *menu); void qt_mac_set_dock_menu(QMenu *menu);
#endif #endif
#include "lineedit.h" #include "lineedit.h"
#include "sessionapplication.h"
using namespace libtorrent; using namespace libtorrent;
@ -88,6 +89,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for
ui_locked = Preferences::isUILocked(); ui_locked = Preferences::isUILocked();
setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION))); setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION)));
displaySpeedInTitle = Preferences::speedInTitleBar(); displaySpeedInTitle = Preferences::speedInTitleBar();
// Clean exit on log out
connect(static_cast<SessionApplication*>(qApp), SIGNAL(sessionIsShuttingDown()), this, SLOT(deleteBTSession()));
// Setting icons // Setting icons
this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png"))); this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png")));
actionOpen->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/open.png"))); actionOpen->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/open.png")));
@ -248,6 +251,16 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for
#endif #endif
} }
void GUI::deleteBTSession() {
guiUpdater->stop();
status_bar->stopTimer();
if(BTSession) {
delete BTSession;
BTSession = 0;
}
QTimer::singleShot(0, this, SLOT(close()));
}
// Destructor // Destructor
GUI::~GUI() { GUI::~GUI() {
qDebug("GUI destruction"); qDebug("GUI destruction");
@ -258,7 +271,9 @@ GUI::~GUI() {
#endif #endif
// Async deletion of Bittorrent session as early as possible // Async deletion of Bittorrent session as early as possible
// in order to speed up exit // in order to speed up exit
session_proxy sp = BTSession->asyncDeletion(); session_proxy sp;
if(BTSession)
sp = BTSession->asyncDeletion();
// Some saving // Some saving
properties->saveSettings(); properties->saveSettings();
disconnect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int))); disconnect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int)));
@ -663,7 +678,7 @@ void GUI::closeEvent(QCloseEvent *e) {
e->accept(); e->accept();
return; return;
} }
if(settings.value(QString::fromUtf8("Preferences/General/ExitConfirm"), true).toBool() && BTSession->hasActiveTorrents()) { if(settings.value(QString::fromUtf8("Preferences/General/ExitConfirm"), true).toBool() && BTSession && BTSession->hasActiveTorrents()) {
if(e->spontaneous() || force_exit) { if(e->spontaneous() || force_exit) {
if(!isVisible()) if(!isVisible())
show(); show();

View File

@ -80,6 +80,7 @@ public slots:
void downloadFromURLList(const QStringList& urls); void downloadFromURLList(const QStringList& urls);
void updateAltSpeedsBtn(bool alternative); void updateAltSpeedsBtn(bool alternative);
void updateNbTorrents(unsigned int nb_downloading, unsigned int nb_seeding, unsigned int nb_active, unsigned int nb_inactive, unsigned int nb_paused); void updateNbTorrents(unsigned int nb_downloading, unsigned int nb_seeding, unsigned int nb_active, unsigned int nb_inactive, unsigned int nb_paused);
void deleteBTSession();
protected slots: protected slots:
// GUI related slots // GUI related slots

View File

@ -165,6 +165,7 @@ Bittorrent::~Bittorrent() {
#endif #endif
saveSessionState(); saveSessionState();
saveFastResumeData(); saveFastResumeData();
qDebug("Deleting the session");
// Delete session // Delete session
session_proxy sp = s->abort(); session_proxy sp = s->abort();
delete s; delete s;
@ -1541,6 +1542,7 @@ void Bittorrent::saveTempFastResumeData() {
// Only save fast resume data for unfinished and unpaused torrents (Optimization) // Only save fast resume data for unfinished and unpaused torrents (Optimization)
// Called periodically and on exit // Called periodically and on exit
void Bittorrent::saveFastResumeData() { void Bittorrent::saveFastResumeData() {
qDebug("Saving fast resume data...");
// Stop listening for alerts // Stop listening for alerts
resumeDataTimer.stop(); resumeDataTimer.stop();
timerAlerts->stop(); timerAlerts->stop();

View File

@ -38,11 +38,7 @@
#include <QStyle> #include <QStyle>
#include <QSplashScreen> #include <QSplashScreen>
#include <QPushButton> #include <QPushButton>
#ifdef Q_WS_MAC #include "sessionapplication.h"
#include "qmacapplication.h"
#else
#include "qtsingleapplication.h"
#endif
#include "GUI.h" #include "GUI.h"
#include "ico.h" #include "ico.h"
#else #else
@ -160,15 +156,11 @@ void useStyle(QString style){
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
// Create Application // Create Application
QString uid = misc::getUserIDString(); QString uid = misc::getUserIDString();
#ifdef DISABLE_GUI #ifdef DISABLE_GUI
QtSingleCoreApplication app("qBittorrent-"+uid, argc, argv); QtSingleCoreApplication app("qBittorrent-"+uid, argc, argv);
#else #else
#ifndef Q_WS_MAC SessionApplication app("qBittorrent-"+uid, argc, argv);
QtSingleApplication app("qBittorrent-"+uid, argc, argv); #endif
#else
QMacApplication app("qBittorrent-"+uid, argc, argv);
#endif
#endif
// Check if qBittorrent is already running for this user // Check if qBittorrent is already running for this user
if(app.isRunning()) { if(app.isRunning()) {

39
src/sessionapplication.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef SESSIONAPPLICATION_H
#define SESSIONAPPLICATION_H
#ifdef Q_WS_MAC
#include "qmacapplication.h"
#else
#include "qtsingleapplication.h"
#endif
#include <QSessionManager>
class SessionApplication :
#ifdef Q_WS_MAC
public QMacApplication
#else
public QtSingleApplication
#endif
{
Q_OBJECT
public:
SessionApplication(const QString &id, int &argc, char **argv) :
#ifdef Q_WS_MAC
QMacApplication(id, argc, argv)
#else
QtSingleApplication(id, argc, argv)
#endif
{}
void commitData(QSessionManager & manager) {
Q_UNUSED(manager);
emit sessionIsShuttingDown();
}
signals:
void sessionIsShuttingDown();
};
#endif // SESSIONAPPLICATION_H

View File

@ -342,7 +342,8 @@ contains(DEFINES, DISABLE_GUI) {
advancedsettings.h \ advancedsettings.h \
cookiesdlg.h \ cookiesdlg.h \
rsssettings.h \ rsssettings.h \
hidabletabwidget.h hidabletabwidget.h \
sessionapplication.h
macx { macx {
HEADERS += qmacapplication.h HEADERS += qmacapplication.h

View File

@ -170,6 +170,10 @@ public slots:
bar->insertWidget(1, new QLabel(tr("qBittorrent needs to be restarted"))); bar->insertWidget(1, new QLabel(tr("qBittorrent needs to be restarted")));
} }
void stopTimer() {
refreshTimer->stop();
}
void refreshStatusBar() { void refreshStatusBar() {
// Update connection status // Update connection status
session_status sessionStatus = BTSession->getSessionStatus(); session_status sessionStatus = BTSession->getSessionStatus();