Create dialogs on demand, don't keep them ready all the time

This commit is contained in:
Mike Gelfand 2015-07-30 06:18:02 +00:00
parent 18ea8c429a
commit f592083f15
12 changed files with 151 additions and 89 deletions

View File

@ -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);
}

View File

@ -11,9 +11,12 @@
#define QTR_ABOUT_DIALOG_H
#include <QDialog>
#include <QPointer>
#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<LicenseDialog> myLicenseDialog;
};
#endif // QTR_ABOUT_DIALOG_H

View File

@ -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))
{

View File

@ -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

View File

@ -195,8 +195,6 @@ DetailsDialog::DetailsDialog (Session & session,
adjustSize ();
ui.commentBrowser->setMaximumHeight (QWIDGETSIZE_MAX);
setAttribute (Qt::WA_DeleteOnClose, true);
QList<int> initKeys;
initKeys << Prefs::SHOW_TRACKER_SCRAPES
<< Prefs::SHOW_BACKUP_TRACKERS;

View File

@ -7,42 +7,10 @@
* $Id$
*/
#include <QDialogButtonBox>
#include <QPlainTextEdit>
#include <QVBoxLayout>
#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);
}

View File

@ -12,6 +12,8 @@
#include <QDialog>
#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

66
qt/LicenseDialog.ui Normal file
View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LicenseDialog</class>
<widget class="QDialog" name="LicenseDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>License</string>
</property>
<layout class="QVBoxLayout" name="dialogLayout">
<item>
<widget class="QPlainTextEdit" name="licenseEdit">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string notr="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.</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="dialogButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>dialogButtons</sender>
<signal>rejected()</signal>
<receiver>LicenseDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -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 ();
}
/***

View File

@ -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<QDialog> myPrefsDialog;
QDialog * myAboutDialog;
QDialog * myStatsDialog;
DetailsDialog * myDetailsDialog;
QPointer<SessionDialog> mySessionDialog;
QPointer<PrefsDialog> myPrefsDialog;
QPointer<AboutDialog> myAboutDialog;
QPointer<StatsDialog> myStatsDialog;
QPointer<DetailsDialog> myDetailsDialog;
QSystemTrayIcon myTrayIcon;
TorrentFilter myFilterModel;
TorrentDelegate * myTorrentDelegate;

View File

@ -121,7 +121,7 @@
<property name="leftMargin">
<number>18</number>
</property>
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="startCountLabel">
<property name="text">
<string notr="true">...</string>

View File

@ -41,6 +41,23 @@ class Utils
static QColor getFadedColor (const QColor& color);
template<typename DialogT, typename... ArgsT>
static void
openDialog (QPointer<DialogT>& dialog, ArgsT&&... args)
{
if (dialog.isNull ())
{
dialog = new DialogT (std::forward<ArgsT> (args)...);
dialog->setAttribute (Qt::WA_DeleteOnClose);
dialog->show ();
}
else
{
dialog->raise ();
dialog->activateWindow ();
}
}
///
/// URLs
///