From f592083f15da58cf95d451dae2851ebe4a2107d5 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Thu, 30 Jul 2015 06:18:02 +0000 Subject: [PATCH] Create dialogs on demand, don't keep them ready all the time --- qt/AboutDialog.cc | 17 +++++++----- qt/AboutDialog.h | 8 ++++-- qt/Application.cc | 10 ++----- qt/CMakeLists.txt | 1 + qt/DetailsDialog.cc | 2 -- qt/LicenseDialog.cc | 34 +---------------------- qt/LicenseDialog.h | 5 ++++ qt/LicenseDialog.ui | 66 +++++++++++++++++++++++++++++++++++++++++++++ qt/MainWindow.cc | 57 +++++++++++++++++++-------------------- qt/MainWindow.h | 21 ++++++++++----- qt/StatsDialog.ui | 2 +- qt/Utils.h | 17 ++++++++++++ 12 files changed, 151 insertions(+), 89 deletions(-) create mode 100644 qt/LicenseDialog.ui diff --git a/qt/AboutDialog.cc b/qt/AboutDialog.cc index a6265777b..3815ba8d4 100644 --- a/qt/AboutDialog.cc +++ b/qt/AboutDialog.cc @@ -17,10 +17,11 @@ #include "AboutDialog.h" #include "LicenseDialog.h" +#include "Utils.h" AboutDialog::AboutDialog (QWidget * parent): QDialog (parent, Qt::Dialog), - myLicenseDialog (new LicenseDialog (this)) + myLicenseDialog () { ui.setupUi (this); @@ -29,13 +30,11 @@ AboutDialog::AboutDialog (QWidget * parent): QPushButton * b; - b = new QPushButton (tr ("C&redits"), this); - ui.dialogButtons->addButton (b, QDialogButtonBox::ActionRole); + b = ui.dialogButtons->addButton (tr ("C&redits"), QDialogButtonBox::ActionRole); connect (b, SIGNAL (clicked ()), this, SLOT (showCredits ())); - b = new QPushButton (tr ("&License"), this); - ui.dialogButtons->addButton (b, QDialogButtonBox::ActionRole); - connect (b, SIGNAL (clicked ()), myLicenseDialog, SLOT (show ())); + b = ui.dialogButtons->addButton (tr ("&License"), QDialogButtonBox::ActionRole); + connect (b, SIGNAL (clicked ()), this, SLOT (showLicense ())); ui.dialogButtons->button (QDialogButtonBox::Close)->setDefault (true); } @@ -49,3 +48,9 @@ AboutDialog::showCredits () QString::fromUtf8 ("Jordan Lee (Backend; Daemon; GTK+; Qt)\n" "Michell Livingston (OS X)\n")); } + +void +AboutDialog::showLicense () +{ + Utils::openDialog (myLicenseDialog, this); +} diff --git a/qt/AboutDialog.h b/qt/AboutDialog.h index 248220034..9ecb7b938 100644 --- a/qt/AboutDialog.h +++ b/qt/AboutDialog.h @@ -11,9 +11,12 @@ #define QTR_ABOUT_DIALOG_H #include +#include #include "ui_AboutDialog.h" +class LicenseDialog; + class AboutDialog: public QDialog { Q_OBJECT @@ -22,13 +25,14 @@ class AboutDialog: public QDialog AboutDialog (QWidget * parent = nullptr); virtual ~AboutDialog () {} - public slots: + private slots: void showCredits (); + void showLicense (); private: Ui::AboutDialog ui; - QDialog * myLicenseDialog; + QPointer myLicenseDialog; }; #endif // QTR_ABOUT_DIALOG_H diff --git a/qt/Application.cc b/qt/Application.cc index d554b7a10..f9395b20f 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -34,7 +34,6 @@ #include "OptionsDialog.h" #include "Prefs.h" #include "Session.h" -#include "SessionDialog.h" #include "TorrentModel.h" #include "WatchDir.h" @@ -292,14 +291,9 @@ Application::Application (int& argc, char ** argv): maybeUpdateBlocklist (); if (!firstTime) - { - mySession->restart (); - } + mySession->restart (); else - { - QDialog * d = new SessionDialog (*mySession, *myPrefs, myWindow); - d->show (); - } + myWindow->openSession (); if (!myPrefs->getBool (Prefs::USER_HAS_GIVEN_INFORMED_CONSENT)) { diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 2dd528828..8c3dc615b 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -119,6 +119,7 @@ set(${PROJECT_NAME}_HEADERS tr_qt_wrap_ui(${PROJECT_NAME}_UI_SOURCES AboutDialog.ui DetailsDialog.ui + LicenseDialog.ui MainWindow.ui MakeDialog.ui MakeProgressDialog.ui diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index bf35e0d60..fb54fc4fa 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -195,8 +195,6 @@ DetailsDialog::DetailsDialog (Session & session, adjustSize (); ui.commentBrowser->setMaximumHeight (QWIDGETSIZE_MAX); - setAttribute (Qt::WA_DeleteOnClose, true); - QList initKeys; initKeys << Prefs::SHOW_TRACKER_SCRAPES << Prefs::SHOW_BACKUP_TRACKERS; diff --git a/qt/LicenseDialog.cc b/qt/LicenseDialog.cc index 19305d464..63fc50fc1 100644 --- a/qt/LicenseDialog.cc +++ b/qt/LicenseDialog.cc @@ -7,42 +7,10 @@ * $Id$ */ -#include -#include -#include - #include "LicenseDialog.h" LicenseDialog::LicenseDialog (QWidget * parent): QDialog (parent, Qt::Dialog) { - setWindowTitle (tr ("License")); - resize (400, 300); - QVBoxLayout * v = new QVBoxLayout (this); - - QPlainTextEdit * t = new QPlainTextEdit (this); - t->setReadOnly (true); - t->setPlainText (QLatin1String ( - "Copyright 2005-2014. All code is copyrighted by the respective authors.\n" - "\n" - "Transmission can be redistributed and/or modified under the terms of the " - "GNU GPL versions 2 or 3 or by any future license endorsed by Mnemosyne LLC.\n" - "\n" - "In addition, linking to and/or using OpenSSL is allowed.\n" - "\n" - "This program is distributed in the hope that it will be useful, " - "but WITHOUT ANY WARRANTY; without even the implied warranty of " - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" - "\n" - "Some of Transmission's source files have more permissive licenses. " - "Those files may, of course, be used on their own under their own terms.\n")); - v->addWidget (t); - - QDialogButtonBox * box = new QDialogButtonBox; - box->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed); - box->setOrientation (Qt::Horizontal); - box->setStandardButtons (QDialogButtonBox::Close); - v->addWidget (box); - - connect (box, SIGNAL (rejected ()), this, SLOT (hide ())); + ui.setupUi (this); } diff --git a/qt/LicenseDialog.h b/qt/LicenseDialog.h index 53888e135..023eb99dc 100644 --- a/qt/LicenseDialog.h +++ b/qt/LicenseDialog.h @@ -12,6 +12,8 @@ #include +#include "ui_LicenseDialog.h" + class LicenseDialog: public QDialog { Q_OBJECT @@ -19,6 +21,9 @@ class LicenseDialog: public QDialog public: LicenseDialog (QWidget * parent = nullptr); virtual ~LicenseDialog () {} + + private: + Ui::LicenseDialog ui; }; #endif // QTR_LICENSE_DIALOG_H diff --git a/qt/LicenseDialog.ui b/qt/LicenseDialog.ui new file mode 100644 index 000000000..295bd3810 --- /dev/null +++ b/qt/LicenseDialog.ui @@ -0,0 +1,66 @@ + + + LicenseDialog + + + + 0 + 0 + 400 + 300 + + + + License + + + + + + true + + + Copyright 2005-2014. All code is copyrighted by the respective authors. + +Transmission can be redistributed and/or modified under the terms of the GNU GPL versions 2 or 3 or by any future license endorsed by Mnemosyne LLC. + +In addition, linking to and/or using OpenSSL is allowed. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +Some of Transmission's source files have more permissive licenses. Those files may, of course, be used on their own under their own terms. + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + dialogButtons + rejected() + LicenseDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/qt/MainWindow.cc b/qt/MainWindow.cc index 2a2dea655..eff80c068 100644 --- a/qt/MainWindow.cc +++ b/qt/MainWindow.cc @@ -42,6 +42,7 @@ #include "TorrentDelegateMin.h" #include "TorrentFilter.h" #include "TorrentModel.h" +#include "Utils.h" #define PREFS_KEY "prefs-key"; @@ -83,11 +84,11 @@ MainWindow::MainWindow (Session& session, Prefs& prefs, TorrentModel& model, boo myPrefs (prefs), myModel (model), myLastFullUpdateTime (0), - mySessionDialog (new SessionDialog (session, prefs, this)), + mySessionDialog (), myPrefsDialog (), - myAboutDialog (new AboutDialog (this)), - myStatsDialog (new StatsDialog (session, this)), - myDetailsDialog (0), + myAboutDialog (), + myStatsDialog (), + myDetailsDialog (), myFilterModel (prefs), myTorrentDelegate (new TorrentDelegate (this)), myTorrentDelegateMin (new TorrentDelegateMin (this)), @@ -169,15 +170,15 @@ MainWindow::MainWindow (Session& session, Prefs& prefs, TorrentModel& model, boo connect (ui.action_AddURL, SIGNAL (triggered ()), this, SLOT (openURL ())); connect (ui.action_New, SIGNAL (triggered ()), this, SLOT (newTorrent ())); connect (ui.action_Preferences, SIGNAL (triggered ()), this, SLOT (openPreferences ())); - connect (ui.action_Statistics, SIGNAL (triggered ()), myStatsDialog, SLOT (show ())); + connect (ui.action_Statistics, SIGNAL (triggered ()), this, SLOT (openStats ())); connect (ui.action_Donate, SIGNAL (triggered ()), this, SLOT (openDonate ())); - connect (ui.action_About, SIGNAL (triggered ()), myAboutDialog, SLOT (show ())); + connect (ui.action_About, SIGNAL (triggered ()), this, SLOT (openAbout ())); connect (ui.action_Contents, SIGNAL (triggered ()), this, SLOT (openHelp ())); connect (ui.action_OpenFolder, SIGNAL (triggered ()), this, SLOT (openFolder ())); connect (ui.action_CopyMagnetToClipboard, SIGNAL (triggered ()), this, SLOT (copyMagnetLinkToClipboard ())); connect (ui.action_SetLocation, SIGNAL (triggered ()), this, SLOT (setLocation ())); connect (ui.action_Properties, SIGNAL (triggered ()), this, SLOT (openProperties ())); - connect (ui.action_SessionDialog, SIGNAL (triggered ()), mySessionDialog, SLOT (show ())); + connect (ui.action_SessionDialog, SIGNAL (triggered ()), this, SLOT (openSession ())); connect (ui.listView, SIGNAL (activated (QModelIndex)), ui.action_Properties, SLOT (trigger ())); @@ -514,38 +515,22 @@ MainWindow::hideEvent (QHideEvent * event) ****/ void -MainWindow::openPreferences () +MainWindow::openSession () { - if (myPrefsDialog.isNull ()) - { - myPrefsDialog = new PrefsDialog (mySession, myPrefs, this); - myPrefsDialog->setAttribute (Qt::WA_DeleteOnClose); - myPrefsDialog->show (); - } - else - { - myPrefsDialog->raise (); - myPrefsDialog->activateWindow (); - } + Utils::openDialog (mySessionDialog, mySession, myPrefs, this); } void -MainWindow::onDetailsDestroyed () +MainWindow::openPreferences () { - myDetailsDialog = 0; + Utils::openDialog (myPrefsDialog, mySession, myPrefs, this); } void MainWindow::openProperties () { - if (myDetailsDialog == 0) - { - myDetailsDialog = new DetailsDialog (mySession, myPrefs, myModel, this); - connect (myDetailsDialog, SIGNAL (destroyed (QObject*)), this, SLOT (onDetailsDestroyed ())); - } - + Utils::openDialog (myDetailsDialog, mySession, myPrefs, myModel, this); myDetailsDialog->setIds (getSelectedTorrents ()); - myDetailsDialog->show (); } void @@ -617,12 +602,24 @@ MainWindow::copyMagnetLinkToClipboard () mySession.copyMagnetLinkToClipboard (id); } +void +MainWindow::openStats () +{ + Utils::openDialog (myStatsDialog, mySession, this); +} + void MainWindow::openDonate () { QDesktopServices::openUrl (QUrl (QLatin1String ("http://www.transmissionbt.com/donate.php"))); } +void +MainWindow::openAbout () +{ + Utils::openDialog (myAboutDialog, this); +} + void MainWindow::openHelp () { @@ -792,7 +789,7 @@ MainWindow::refreshActionSensitivity () ui.action_QueueMoveDown->setEnabled (haveSelection); ui.action_QueueMoveBottom->setEnabled (haveSelection); - if (myDetailsDialog) + if (!myDetailsDialog.isNull ()) myDetailsDialog->setIds (getSelectedTorrents ()); } @@ -1382,7 +1379,7 @@ void MainWindow::wrongAuthentication () { mySession.stop (); - mySessionDialog->show (); + openSession (); } /*** diff --git a/qt/MainWindow.h b/qt/MainWindow.h index dfc3bef9a..ed8c919df 100644 --- a/qt/MainWindow.h +++ b/qt/MainWindow.h @@ -28,10 +28,14 @@ class QAction; class QIcon; class QMenu; +class AboutDialog; class AddData; -class Prefs; class DetailsDialog; +class Prefs; +class PrefsDialog; class Session; +class SessionDialog; +class StatsDialog; class TorrentDelegate; class TorrentDelegateMin; class TorrentModel; @@ -73,6 +77,8 @@ class MainWindow: public QMainWindow void refreshActionSensitivitySoon (); void wrongAuthentication (); + void openSession (); + protected: // QWidget virtual void contextMenuEvent (QContextMenuEvent *); @@ -98,7 +104,6 @@ class MainWindow: public QMainWindow private slots: void openPreferences (); - void onDetailsDestroyed (); void showTotalRatio (); void showTotalTransfer (); void showSessionRatio (); @@ -114,7 +119,9 @@ class MainWindow: public QMainWindow void refreshPref (int key); void addTorrents (const QStringList& filenames); void removeTorrents (const bool deleteFiles); + void openStats (); void openDonate (); + void openAbout (); void openHelp (); void openFolder (); void copyMagnetLinkToClipboard (); @@ -151,11 +158,11 @@ class MainWindow: public QMainWindow Ui_MainWindow ui; time_t myLastFullUpdateTime; - QDialog * mySessionDialog; - QPointer myPrefsDialog; - QDialog * myAboutDialog; - QDialog * myStatsDialog; - DetailsDialog * myDetailsDialog; + QPointer mySessionDialog; + QPointer myPrefsDialog; + QPointer myAboutDialog; + QPointer myStatsDialog; + QPointer myDetailsDialog; QSystemTrayIcon myTrayIcon; TorrentFilter myFilterModel; TorrentDelegate * myTorrentDelegate; diff --git a/qt/StatsDialog.ui b/qt/StatsDialog.ui index ccdb324cc..66147944c 100644 --- a/qt/StatsDialog.ui +++ b/qt/StatsDialog.ui @@ -121,7 +121,7 @@ 18 - + ... diff --git a/qt/Utils.h b/qt/Utils.h index 09f60b8cc..eaac3d25d 100644 --- a/qt/Utils.h +++ b/qt/Utils.h @@ -41,6 +41,23 @@ class Utils static QColor getFadedColor (const QColor& color); + template + static void + openDialog (QPointer& dialog, ArgsT&&... args) + { + if (dialog.isNull ()) + { + dialog = new DialogT (std::forward (args)...); + dialog->setAttribute (Qt::WA_DeleteOnClose); + dialog->show (); + } + else + { + dialog->raise (); + dialog->activateWindow (); + } + } + /// /// URLs ///