Browse Source

MainWindow cleanups.

All MainWindow child widgets use constructors with 'parent' parameter
that allows parent widget to delete them at its destruction.
Some other MainWindow cleanup code replaced to destructor.
Application manages MainWindow instance and remove it when aboutToQuit()
signal emitted.
adaptive-webui-19844
Vladimir Golovnev (Glassez) 10 years ago
parent
commit
458b216b74
  1. 33
      src/app/application.cpp
  2. 4
      src/app/application.h
  3. 36
      src/gui/hidabletabwidget.h
  4. 112
      src/gui/mainwindow.cpp
  5. 16
      src/gui/mainwindow.h

33
src/app/application.cpp

@ -52,17 +52,15 @@ @@ -52,17 +52,15 @@
#endif
#include "application.h"
#include "logger.h"
#include "preferences.h"
#include "qbtsession.h"
#include "logger.h"
#include "torrentpersistentdata.h"
static const char PARAMS_SEPARATOR[] = "|";
Application::Application(const QString &id, int &argc, char **argv)
: BaseApplication(id, argc, argv)
#ifndef DISABLE_GUI
, m_window(0)
#endif
, m_running(false)
{
#if defined(Q_OS_MACX) && !defined(DISABLE_GUI)
@ -80,14 +78,7 @@ Application::Application(const QString &id, int &argc, char **argv) @@ -80,14 +78,7 @@ Application::Application(const QString &id, int &argc, char **argv)
#endif
connect(this, SIGNAL(messageReceived(const QString &)), SLOT(processMessage(const QString &)));
}
Application::~Application()
{
qDebug() << Q_FUNC_INFO;
QBtSession::drop();
Preferences::drop();
Logger::drop();
connect(this, SIGNAL(aboutToQuit()), SLOT(cleanup()));
}
void Application::processMessage(const QString &message)
@ -101,6 +92,17 @@ void Application::processMessage(const QString &message) @@ -101,6 +92,17 @@ void Application::processMessage(const QString &message)
m_paramsQueue.append(params);
}
void Application::cleanup()
{
#ifndef DISABLE_GUI
delete m_window;
#endif
QBtSession::drop();
TorrentPersistentData::drop();
Preferences::drop();
Logger::drop();
}
bool Application::sendParams(const QStringList &params)
{
return sendMessage(params.join(QLatin1String(PARAMS_SEPARATOR)));
@ -181,12 +183,7 @@ int Application::exec(const QStringList &params) @@ -181,12 +183,7 @@ int Application::exec(const QStringList &params)
m_paramsQueue.clear();
}
int res = BaseApplication::exec();
#ifndef DISABLE_GUI
delete m_window;
#endif
qDebug("Application has exited");
return res;
return BaseApplication::exec();
}
#ifndef DISABLE_GUI

4
src/app/application.h

@ -48,7 +48,6 @@ class Application : public BaseApplication @@ -48,7 +48,6 @@ class Application : public BaseApplication
public:
Application(const QString &id, int &argc, char **argv);
~Application();
#if (defined(Q_OS_WIN) && !defined(DISABLE_GUI))
bool isRunning();
@ -66,11 +65,12 @@ protected: @@ -66,11 +65,12 @@ protected:
private slots:
void processMessage(const QString &message);
void cleanup();
private:
bool m_running;
#ifndef DISABLE_GUI
MainWindow *m_window;
QPointer<MainWindow> m_window;
#endif
QTranslator m_qtTranslator;
QTranslator m_translator;

36
src/gui/hidabletabwidget.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
@ -34,31 +34,27 @@ @@ -34,31 +34,27 @@
#include <QTabWidget>
#include <QTabBar>
class HidableTabWidget : public QTabWidget {
class HidableTabWidget : public QTabWidget
{
public:
void showTabBar(bool show) {
tabBar()->setVisible(show);
}
explicit HidableTabWidget(QWidget *parent = 0)
: QTabWidget(parent)
{
}
protected:
void tabInserted(int index) {
QTabWidget::tabInserted(index);
if (count() == 1) {
showTabBar(false);
} else {
showTabBar(true);
void tabInserted(int index)
{
QTabWidget::tabInserted(index);
tabBar()->setVisible(count() != 1);
}
}
void tabRemoved(int index) {
QTabWidget::tabInserted(index);
if (count() == 1) {
showTabBar(false);
} else {
showTabBar(true);
void tabRemoved(int index)
{
//QTabWidget::tabInserted(index);
QTabWidget::tabRemoved(index);
tabBar()->setVisible(count() != 1);
}
}
};
#endif // HIDABLETABWIDGET_H

112
src/gui/mainwindow.cpp

@ -169,6 +169,7 @@ MainWindow::MainWindow(QWidget *parent) @@ -169,6 +169,7 @@ MainWindow::MainWindow(QWidget *parent)
QAction *clearUiLockPasswdAct = lockMenu->addAction(tr("Clear the password"));
connect(clearUiLockPasswdAct, SIGNAL(triggered()), this, SLOT(clearUILockPassword()));
actionLock_qBittorrent->setMenu(lockMenu);
// Creating Bittorrent session
connect(QBtSession::instance(), SIGNAL(fullDiskError(QTorrentHandle, QString)), this, SLOT(fullDiskError(QTorrentHandle, QString)));
connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle)), this, SLOT(finishedTorrent(QTorrentHandle)));
@ -180,19 +181,22 @@ MainWindow::MainWindow(QWidget *parent) @@ -180,19 +181,22 @@ MainWindow::MainWindow(QWidget *parent)
connect(QBtSession::instance(), SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle)));
qDebug("create tabWidget");
tabs = new HidableTabWidget();
tabs = new HidableTabWidget(this);
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int)));
vSplitter = new QSplitter(Qt::Horizontal);
vSplitter = new QSplitter(Qt::Horizontal, this);
//vSplitter->setChildrenCollapsible(false);
hSplitter = new QSplitter(Qt::Vertical);
hSplitter = new QSplitter(Qt::Vertical, this);
hSplitter->setChildrenCollapsible(false);
hSplitter->setContentsMargins(0, 4, 0, 0);
// Name filter
search_filter = new LineEdit();
search_filter = new LineEdit(this);
searchFilterAct = toolBar->insertWidget(actionLock_qBittorrent, search_filter);
search_filter->setPlaceholderText(tr("Filter torrent list..."));
search_filter->setFixedWidth(200);
QWidget *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
toolBar->insertWidget(searchFilterAct, spacer);
@ -275,7 +279,7 @@ MainWindow::MainWindow(QWidget *parent) @@ -275,7 +279,7 @@ MainWindow::MainWindow(QWidget *parent)
QTimer::singleShot(0, this, SLOT(on_actionSearch_engine_triggered()));
// Auto shutdown actions
QActionGroup * autoShutdownGroup = new QActionGroup(this);
QActionGroup *autoShutdownGroup = new QActionGroup(this);
autoShutdownGroup->setExclusive(true);
autoShutdownGroup->addAction(actionAutoShutdown_Disabled);
autoShutdownGroup->addAction(actionAutoExit_qBittorrent);
@ -310,13 +314,10 @@ MainWindow::MainWindow(QWidget *parent) @@ -310,13 +314,10 @@ MainWindow::MainWindow(QWidget *parent)
properties->readSettings();
// Start watching the executable for updates
executable_watcher = new QFileSystemWatcher();
executable_watcher = new QFileSystemWatcher(this);
connect(executable_watcher, SIGNAL(fileChanged(QString)), this, SLOT(notifyOfUpdate(QString)));
executable_watcher->addPath(qApp->applicationFilePath());
// Resume unfinished torrents
QBtSession::instance()->startUpTorrents();
// Populate the transfer list
transferList->getSourceModel()->populate();
transferList->setFocus();
@ -357,6 +358,16 @@ MainWindow::MainWindow(QWidget *parent) @@ -357,6 +358,16 @@ MainWindow::MainWindow(QWidget *parent)
}
}
MainWindow::~MainWindow()
{
// Save window size, columns size
writeSettings();
#ifdef Q_OS_MAC
// Workaround to avoid bug http://bugreports.qt.nokia.com/browse/QTBUG-7305
setUnifiedTitleAndToolBarOnMac(false);
#endif
}
void MainWindow::addToolbarContextMenu()
{
const Preferences* const pref = Preferences::instance();
@ -448,68 +459,6 @@ void MainWindow::toolbarFollowSystem() @@ -448,68 +459,6 @@ void MainWindow::toolbarFollowSystem()
Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonFollowStyle);
}
void MainWindow::shutdownCleanUp()
{
qDebug("GUI destruction");
hide();
guiUpdater->stop();
status_bar->stopTimer();
m_pwr->setActivityState(false);
QBtSession::drop();
// Save window size, columns size
writeSettings();
#ifdef Q_OS_MAC
// Workaround to avoid bug http://bugreports.qt.nokia.com/browse/QTBUG-7305
setUnifiedTitleAndToolBarOnMac(false);
#endif
disconnect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int)));
// Delete other GUI objects
if (executable_watcher)
delete executable_watcher;
delete status_bar;
delete search_filter;
delete transferList;
delete guiUpdater;
if (createTorrentDlg)
delete createTorrentDlg;
if (m_executionLog)
delete m_executionLog;
if (aboutDlg)
delete aboutDlg;
if (statsDlg)
delete statsDlg;
if (options)
delete options;
if (downloadFromURLDialog)
delete downloadFromURLDialog;
if (rssWidget)
delete rssWidget;
if (searchEngine)
delete searchEngine;
delete transferListFilters;
delete properties;
delete hSplitter;
delete vSplitter;
if (systrayCreator)
delete systrayCreator;
if (systrayIcon)
delete systrayIcon;
if (myTrayIconMenu)
delete myTrayIconMenu;
delete tabs;
// Keyboard shortcuts
delete switchSearchShortcut;
delete switchSearchShortcut2;
delete switchTransferShortcut;
delete switchRSSShortcut;
delete toolbarMenu;
IconProvider::drop();
TorrentPersistentData::drop();
Preferences::drop();
Logger::drop();
qDebug("Finished GUI destruction");
}
void MainWindow::defineUILockPassword()
{
QString old_pass_md5 = Preferences::instance()->getUILockPasswordMD5();
@ -563,8 +512,9 @@ void MainWindow::displayRSSTab(bool enable) @@ -563,8 +512,9 @@ void MainWindow::displayRSSTab(bool enable)
tabs->setTabIcon(index_tab, IconProvider::instance()->getIcon("application-rss+xml"));
}
}
else if (rssWidget)
else if (rssWidget) {
delete rssWidget;
}
}
@ -578,8 +528,9 @@ void MainWindow::displaySearchTab(bool enable) @@ -578,8 +528,9 @@ void MainWindow::displaySearchTab(bool enable)
tabs->insertTab(1, searchEngine, IconProvider::instance()->getIcon("edit-find"), tr("Search"));
}
}
else if (searchEngine)
else if (searchEngine) {
delete searchEngine;
}
}
@ -684,14 +635,16 @@ void MainWindow::createKeyboardShortcuts() @@ -684,14 +635,16 @@ void MainWindow::createKeyboardShortcuts()
actionOpen->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+O")));
actionDownload_from_URL->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Shift+O")));
actionExit->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Q")));
switchTransferShortcut = new QShortcut(QKeySequence("Alt+1"), this);
QShortcut *switchTransferShortcut = new QShortcut(QKeySequence("Alt+1"), this);
connect(switchTransferShortcut, SIGNAL(activated()), this, SLOT(displayTransferTab()));
switchSearchShortcut = new QShortcut(QKeySequence("Alt+2"), this);
QShortcut *switchSearchShortcut = new QShortcut(QKeySequence("Alt+2"), this);
connect(switchSearchShortcut, SIGNAL(activated()), this, SLOT(displaySearchTab()));
switchSearchShortcut2 = new QShortcut(QKeySequence("Ctrl+F"), this);
QShortcut *switchSearchShortcut2 = new QShortcut(QKeySequence("Ctrl+F"), this);
connect(switchSearchShortcut2, SIGNAL(activated()), this, SLOT(displaySearchTab()));
switchRSSShortcut = new QShortcut(QKeySequence("Alt+3"), this);
QShortcut *switchRSSShortcut = new QShortcut(QKeySequence("Alt+3"), this);
connect(switchRSSShortcut, SIGNAL(activated()), this, SLOT(displayRSSTab()));
actionDocumentation->setShortcut(QKeySequence("F1"));
actionOptions->setShortcut(QKeySequence(QString::fromUtf8("Alt+O")));
actionStart->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+S")));
@ -1147,7 +1100,7 @@ void MainWindow::loadPreferences(bool configure_session) @@ -1147,7 +1100,7 @@ void MainWindow::loadPreferences(bool configure_session)
const Preferences* const pref = Preferences::instance();
const bool newSystrayIntegration = pref->systrayIntegration();
actionLock_qBittorrent->setVisible(newSystrayIntegration);
if (newSystrayIntegration != (systrayIcon!=0)) {
if (newSystrayIntegration != (systrayIcon != 0)) {
if (newSystrayIntegration) {
// create the trayicon
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
@ -1572,8 +1525,9 @@ void MainWindow::on_actionExecution_Logs_triggered(bool checked) @@ -1572,8 +1525,9 @@ void MainWindow::on_actionExecution_Logs_triggered(bool checked)
int index_tab = tabs->addTab(m_executionLog, tr("Execution Log"));
tabs->setTabIcon(index_tab, IconProvider::instance()->getIcon("view-calendar-journal"));
}
else if (m_executionLog)
else if (m_executionLog) {
delete m_executionLog;
}
Preferences::instance()->setExecutionLogEnabled(checked);
}

16
src/gui/mainwindow.h

@ -48,11 +48,9 @@ class TransferListWidget; @@ -48,11 +48,9 @@ class TransferListWidget;
class TransferListFiltersWidget;
class PropertiesWidget;
class StatusBar;
class consoleDlg;
class about;
class TorrentCreatorDlg;
class downloadFromURL;
class HidableTabWidget;
class LineEdit;
class ExecutionLog;
class PowerManagement;
@ -73,6 +71,7 @@ class MainWindow: public QMainWindow, private Ui::MainWindow @@ -73,6 +71,7 @@ class MainWindow: public QMainWindow, private Ui::MainWindow
public:
// Construct / Destruct
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
// Methods
QWidget* getCurrentTabWidget() const;
TransferListWidget* getTransferList() const { return transferList; }
@ -86,13 +85,10 @@ public slots: @@ -86,13 +85,10 @@ public slots:
void downloadFromURLList(const QStringList& urls);
void updateAltSpeedsBtn(bool alternative);
void updateNbTorrents();
void shutdownCleanUp();
void activate();
protected slots:
// GUI related slots
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void toggleVisibility(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger);
void on_actionAbout_triggered();
void on_actionStatistics_triggered();
@ -144,6 +140,8 @@ protected slots: @@ -144,6 +140,8 @@ protected slots:
#endif
protected:
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void closeEvent(QCloseEvent *);
void showEvent(QShowEvent *);
bool event(QEvent * event);
@ -169,10 +167,9 @@ private: @@ -169,10 +167,9 @@ private:
// GUI related
bool m_posInitialized;
QTimer *guiUpdater;
HidableTabWidget *tabs;
QTabWidget *tabs;
StatusBar *status_bar;
QPointer<options_imp> options;
QPointer<consoleDlg> console;
QPointer<about> aboutDlg;
QPointer<StatsDialog> statsDlg;
QPointer<TorrentCreatorDlg> createTorrentDlg;
@ -189,11 +186,6 @@ private: @@ -189,11 +186,6 @@ private:
bool unlockDlgShowing;
LineEdit *search_filter;
QAction *searchFilterAct;
// Keyboard shortcuts
QShortcut *switchSearchShortcut;
QShortcut *switchSearchShortcut2;
QShortcut *switchTransferShortcut;
QShortcut *switchRSSShortcut;
// Widgets
QAction *prioSeparator;
QAction *prioSeparatorMenu;

Loading…
Cancel
Save