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:
parent
129bfac549
commit
1e86ea8c0a
19
src/GUI.cpp
19
src/GUI.cpp
@ -71,6 +71,7 @@
|
||||
void qt_mac_set_dock_menu(QMenu *menu);
|
||||
#endif
|
||||
#include "lineedit.h"
|
||||
#include "sessionapplication.h"
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
@ -88,6 +89,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for
|
||||
ui_locked = Preferences::isUILocked();
|
||||
setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION)));
|
||||
displaySpeedInTitle = Preferences::speedInTitleBar();
|
||||
// Clean exit on log out
|
||||
connect(static_cast<SessionApplication*>(qApp), SIGNAL(sessionIsShuttingDown()), this, SLOT(deleteBTSession()));
|
||||
// Setting icons
|
||||
this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png")));
|
||||
actionOpen->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/open.png")));
|
||||
@ -248,6 +251,16 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for
|
||||
#endif
|
||||
}
|
||||
|
||||
void GUI::deleteBTSession() {
|
||||
guiUpdater->stop();
|
||||
status_bar->stopTimer();
|
||||
if(BTSession) {
|
||||
delete BTSession;
|
||||
BTSession = 0;
|
||||
}
|
||||
QTimer::singleShot(0, this, SLOT(close()));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
GUI::~GUI() {
|
||||
qDebug("GUI destruction");
|
||||
@ -258,7 +271,9 @@ GUI::~GUI() {
|
||||
#endif
|
||||
// Async deletion of Bittorrent session as early as possible
|
||||
// in order to speed up exit
|
||||
session_proxy sp = BTSession->asyncDeletion();
|
||||
session_proxy sp;
|
||||
if(BTSession)
|
||||
sp = BTSession->asyncDeletion();
|
||||
// Some saving
|
||||
properties->saveSettings();
|
||||
disconnect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int)));
|
||||
@ -663,7 +678,7 @@ void GUI::closeEvent(QCloseEvent *e) {
|
||||
e->accept();
|
||||
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(!isVisible())
|
||||
show();
|
||||
|
@ -80,6 +80,7 @@ public slots:
|
||||
void downloadFromURLList(const QStringList& urls);
|
||||
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 deleteBTSession();
|
||||
|
||||
protected slots:
|
||||
// GUI related slots
|
||||
|
@ -165,6 +165,7 @@ Bittorrent::~Bittorrent() {
|
||||
#endif
|
||||
saveSessionState();
|
||||
saveFastResumeData();
|
||||
qDebug("Deleting the session");
|
||||
// Delete session
|
||||
session_proxy sp = s->abort();
|
||||
delete s;
|
||||
@ -1541,6 +1542,7 @@ void Bittorrent::saveTempFastResumeData() {
|
||||
// Only save fast resume data for unfinished and unpaused torrents (Optimization)
|
||||
// Called periodically and on exit
|
||||
void Bittorrent::saveFastResumeData() {
|
||||
qDebug("Saving fast resume data...");
|
||||
// Stop listening for alerts
|
||||
resumeDataTimer.stop();
|
||||
timerAlerts->stop();
|
||||
|
18
src/main.cpp
18
src/main.cpp
@ -38,11 +38,7 @@
|
||||
#include <QStyle>
|
||||
#include <QSplashScreen>
|
||||
#include <QPushButton>
|
||||
#ifdef Q_WS_MAC
|
||||
#include "qmacapplication.h"
|
||||
#else
|
||||
#include "qtsingleapplication.h"
|
||||
#endif
|
||||
#include "sessionapplication.h"
|
||||
#include "GUI.h"
|
||||
#include "ico.h"
|
||||
#else
|
||||
@ -160,15 +156,11 @@ void useStyle(QString style){
|
||||
int main(int argc, char *argv[]){
|
||||
// Create Application
|
||||
QString uid = misc::getUserIDString();
|
||||
#ifdef DISABLE_GUI
|
||||
#ifdef DISABLE_GUI
|
||||
QtSingleCoreApplication app("qBittorrent-"+uid, argc, argv);
|
||||
#else
|
||||
#ifndef Q_WS_MAC
|
||||
QtSingleApplication app("qBittorrent-"+uid, argc, argv);
|
||||
#else
|
||||
QMacApplication app("qBittorrent-"+uid, argc, argv);
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
SessionApplication app("qBittorrent-"+uid, argc, argv);
|
||||
#endif
|
||||
|
||||
// Check if qBittorrent is already running for this user
|
||||
if(app.isRunning()) {
|
||||
|
39
src/sessionapplication.h
Normal file
39
src/sessionapplication.h
Normal 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
|
@ -342,7 +342,8 @@ contains(DEFINES, DISABLE_GUI) {
|
||||
advancedsettings.h \
|
||||
cookiesdlg.h \
|
||||
rsssettings.h \
|
||||
hidabletabwidget.h
|
||||
hidabletabwidget.h \
|
||||
sessionapplication.h
|
||||
|
||||
macx {
|
||||
HEADERS += qmacapplication.h
|
||||
|
@ -170,6 +170,10 @@ public slots:
|
||||
bar->insertWidget(1, new QLabel(tr("qBittorrent needs to be restarted")));
|
||||
}
|
||||
|
||||
void stopTimer() {
|
||||
refreshTimer->stop();
|
||||
}
|
||||
|
||||
void refreshStatusBar() {
|
||||
// Update connection status
|
||||
session_status sessionStatus = BTSession->getSessionStatus();
|
||||
|
Loading…
Reference in New Issue
Block a user