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

4
src/app/application.h

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

36
src/gui/hidabletabwidget.h

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

112
src/gui/mainwindow.cpp

@ -169,6 +169,7 @@ MainWindow::MainWindow(QWidget *parent)
QAction *clearUiLockPasswdAct = lockMenu->addAction(tr("Clear the password")); QAction *clearUiLockPasswdAct = lockMenu->addAction(tr("Clear the password"));
connect(clearUiLockPasswdAct, SIGNAL(triggered()), this, SLOT(clearUILockPassword())); connect(clearUiLockPasswdAct, SIGNAL(triggered()), this, SLOT(clearUILockPassword()));
actionLock_qBittorrent->setMenu(lockMenu); actionLock_qBittorrent->setMenu(lockMenu);
// Creating Bittorrent session // Creating Bittorrent session
connect(QBtSession::instance(), SIGNAL(fullDiskError(QTorrentHandle, QString)), this, SLOT(fullDiskError(QTorrentHandle, QString))); connect(QBtSession::instance(), SIGNAL(fullDiskError(QTorrentHandle, QString)), this, SLOT(fullDiskError(QTorrentHandle, QString)));
connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle)), this, SLOT(finishedTorrent(QTorrentHandle))); connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle)), this, SLOT(finishedTorrent(QTorrentHandle)));
@ -180,19 +181,22 @@ MainWindow::MainWindow(QWidget *parent)
connect(QBtSession::instance(), SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle))); connect(QBtSession::instance(), SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle)));
qDebug("create tabWidget"); qDebug("create tabWidget");
tabs = new HidableTabWidget(); tabs = new HidableTabWidget(this);
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int))); connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int)));
vSplitter = new QSplitter(Qt::Horizontal);
vSplitter = new QSplitter(Qt::Horizontal, this);
//vSplitter->setChildrenCollapsible(false); //vSplitter->setChildrenCollapsible(false);
hSplitter = new QSplitter(Qt::Vertical);
hSplitter = new QSplitter(Qt::Vertical, this);
hSplitter->setChildrenCollapsible(false); hSplitter->setChildrenCollapsible(false);
hSplitter->setContentsMargins(0, 4, 0, 0); hSplitter->setContentsMargins(0, 4, 0, 0);
// Name filter // Name filter
search_filter = new LineEdit(); search_filter = new LineEdit(this);
searchFilterAct = toolBar->insertWidget(actionLock_qBittorrent, search_filter); searchFilterAct = toolBar->insertWidget(actionLock_qBittorrent, search_filter);
search_filter->setPlaceholderText(tr("Filter torrent list...")); search_filter->setPlaceholderText(tr("Filter torrent list..."));
search_filter->setFixedWidth(200); search_filter->setFixedWidth(200);
QWidget *spacer = new QWidget(this); QWidget *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
toolBar->insertWidget(searchFilterAct, spacer); toolBar->insertWidget(searchFilterAct, spacer);
@ -275,7 +279,7 @@ MainWindow::MainWindow(QWidget *parent)
QTimer::singleShot(0, this, SLOT(on_actionSearch_engine_triggered())); QTimer::singleShot(0, this, SLOT(on_actionSearch_engine_triggered()));
// Auto shutdown actions // Auto shutdown actions
QActionGroup * autoShutdownGroup = new QActionGroup(this); QActionGroup *autoShutdownGroup = new QActionGroup(this);
autoShutdownGroup->setExclusive(true); autoShutdownGroup->setExclusive(true);
autoShutdownGroup->addAction(actionAutoShutdown_Disabled); autoShutdownGroup->addAction(actionAutoShutdown_Disabled);
autoShutdownGroup->addAction(actionAutoExit_qBittorrent); autoShutdownGroup->addAction(actionAutoExit_qBittorrent);
@ -310,13 +314,10 @@ MainWindow::MainWindow(QWidget *parent)
properties->readSettings(); properties->readSettings();
// Start watching the executable for updates // 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))); connect(executable_watcher, SIGNAL(fileChanged(QString)), this, SLOT(notifyOfUpdate(QString)));
executable_watcher->addPath(qApp->applicationFilePath()); executable_watcher->addPath(qApp->applicationFilePath());
// Resume unfinished torrents
QBtSession::instance()->startUpTorrents();
// Populate the transfer list // Populate the transfer list
transferList->getSourceModel()->populate(); transferList->getSourceModel()->populate();
transferList->setFocus(); transferList->setFocus();
@ -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() void MainWindow::addToolbarContextMenu()
{ {
const Preferences* const pref = Preferences::instance(); const Preferences* const pref = Preferences::instance();
@ -448,68 +459,6 @@ void MainWindow::toolbarFollowSystem()
Preferences::instance()->setToolbarTextPosition(Qt::ToolButtonFollowStyle); 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() void MainWindow::defineUILockPassword()
{ {
QString old_pass_md5 = Preferences::instance()->getUILockPasswordMD5(); QString old_pass_md5 = Preferences::instance()->getUILockPasswordMD5();
@ -563,8 +512,9 @@ void MainWindow::displayRSSTab(bool enable)
tabs->setTabIcon(index_tab, IconProvider::instance()->getIcon("application-rss+xml")); tabs->setTabIcon(index_tab, IconProvider::instance()->getIcon("application-rss+xml"));
} }
} }
else if (rssWidget) else if (rssWidget) {
delete rssWidget; delete rssWidget;
}
} }
@ -578,8 +528,9 @@ void MainWindow::displaySearchTab(bool enable)
tabs->insertTab(1, searchEngine, IconProvider::instance()->getIcon("edit-find"), tr("Search")); tabs->insertTab(1, searchEngine, IconProvider::instance()->getIcon("edit-find"), tr("Search"));
} }
} }
else if (searchEngine) else if (searchEngine) {
delete searchEngine; delete searchEngine;
}
} }
@ -684,14 +635,16 @@ void MainWindow::createKeyboardShortcuts()
actionOpen->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+O"))); actionOpen->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+O")));
actionDownload_from_URL->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Shift+O"))); actionDownload_from_URL->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Shift+O")));
actionExit->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Q"))); 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())); 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())); 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())); 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())); connect(switchRSSShortcut, SIGNAL(activated()), this, SLOT(displayRSSTab()));
actionDocumentation->setShortcut(QKeySequence("F1")); actionDocumentation->setShortcut(QKeySequence("F1"));
actionOptions->setShortcut(QKeySequence(QString::fromUtf8("Alt+O"))); actionOptions->setShortcut(QKeySequence(QString::fromUtf8("Alt+O")));
actionStart->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+S"))); actionStart->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+S")));
@ -1147,7 +1100,7 @@ void MainWindow::loadPreferences(bool configure_session)
const Preferences* const pref = Preferences::instance(); const Preferences* const pref = Preferences::instance();
const bool newSystrayIntegration = pref->systrayIntegration(); const bool newSystrayIntegration = pref->systrayIntegration();
actionLock_qBittorrent->setVisible(newSystrayIntegration); actionLock_qBittorrent->setVisible(newSystrayIntegration);
if (newSystrayIntegration != (systrayIcon!=0)) { if (newSystrayIntegration != (systrayIcon != 0)) {
if (newSystrayIntegration) { if (newSystrayIntegration) {
// create the trayicon // create the trayicon
if (!QSystemTrayIcon::isSystemTrayAvailable()) { if (!QSystemTrayIcon::isSystemTrayAvailable()) {
@ -1572,8 +1525,9 @@ void MainWindow::on_actionExecution_Logs_triggered(bool checked)
int index_tab = tabs->addTab(m_executionLog, tr("Execution Log")); int index_tab = tabs->addTab(m_executionLog, tr("Execution Log"));
tabs->setTabIcon(index_tab, IconProvider::instance()->getIcon("view-calendar-journal")); tabs->setTabIcon(index_tab, IconProvider::instance()->getIcon("view-calendar-journal"));
} }
else if (m_executionLog) else if (m_executionLog) {
delete m_executionLog; delete m_executionLog;
}
Preferences::instance()->setExecutionLogEnabled(checked); Preferences::instance()->setExecutionLogEnabled(checked);
} }

16
src/gui/mainwindow.h

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

Loading…
Cancel
Save