Changeset 14553


Ignore:
Timestamp:
Jul 30, 2015, 6:18:02 AM (7 years ago)
Author:
mikedld
Message:

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

Location:
trunk/qt
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/AboutDialog.cc

    r14537 r14553  
    1818#include "AboutDialog.h"
    1919#include "LicenseDialog.h"
     20#include "Utils.h"
    2021
    2122AboutDialog::AboutDialog (QWidget * parent):
    2223  QDialog (parent, Qt::Dialog),
    23   myLicenseDialog (new LicenseDialog (this))
     24  myLicenseDialog ()
    2425{
    2526  ui.setupUi (this);
     
    3031  QPushButton * b;
    3132
    32   b = new QPushButton (tr ("C&redits"), this);
    33   ui.dialogButtons->addButton (b, QDialogButtonBox::ActionRole);
     33  b = ui.dialogButtons->addButton (tr ("C&redits"), QDialogButtonBox::ActionRole);
    3434  connect (b, SIGNAL (clicked ()), this, SLOT (showCredits ()));
    3535
    36   b = new QPushButton (tr ("&License"), this);
    37   ui.dialogButtons->addButton (b, QDialogButtonBox::ActionRole);
    38   connect (b, SIGNAL (clicked ()), myLicenseDialog, SLOT (show ()));
     36  b = ui.dialogButtons->addButton (tr ("&License"), QDialogButtonBox::ActionRole);
     37  connect (b, SIGNAL (clicked ()), this, SLOT (showLicense ()));
    3938
    4039  ui.dialogButtons->button (QDialogButtonBox::Close)->setDefault (true);
     
    5049                        "Michell Livingston (OS X)\n"));
    5150}
     51
     52void
     53AboutDialog::showLicense ()
     54{
     55  Utils::openDialog (myLicenseDialog, this);
     56}
  • trunk/qt/AboutDialog.h

    r14539 r14553  
    1212
    1313#include <QDialog>
     14#include <QPointer>
    1415
    1516#include "ui_AboutDialog.h"
     17
     18class LicenseDialog;
    1619
    1720class AboutDialog: public QDialog
     
    2326    virtual ~AboutDialog () {}
    2427
    25   public slots:
     28  private slots:
    2629    void showCredits ();
     30    void showLicense ();
    2731
    2832  private:
    2933    Ui::AboutDialog ui;
    3034
    31     QDialog * myLicenseDialog;
     35    QPointer<LicenseDialog> myLicenseDialog;
    3236};
    3337
  • trunk/qt/Application.cc

    r14539 r14553  
    3535#include "Prefs.h"
    3636#include "Session.h"
    37 #include "SessionDialog.h"
    3837#include "TorrentModel.h"
    3938#include "WatchDir.h"
     
    293292
    294293  if (!firstTime)
    295     {
    296       mySession->restart ();
    297     }
     294    mySession->restart ();
    298295  else
    299     {
    300       QDialog * d = new SessionDialog (*mySession, *myPrefs, myWindow);
    301       d->show ();
    302     }
     296    myWindow->openSession ();
    303297
    304298  if (!myPrefs->getBool (Prefs::USER_HAS_GIVEN_INFORMED_CONSENT))
  • trunk/qt/CMakeLists.txt

    r14538 r14553  
    120120    AboutDialog.ui
    121121    DetailsDialog.ui
     122    LicenseDialog.ui
    122123    MainWindow.ui
    123124    MakeDialog.ui
  • trunk/qt/DetailsDialog.cc

    r14541 r14553  
    195195  adjustSize ();
    196196  ui.commentBrowser->setMaximumHeight (QWIDGETSIZE_MAX);
    197 
    198   setAttribute (Qt::WA_DeleteOnClose, true);
    199197
    200198  QList<int> initKeys;
  • trunk/qt/LicenseDialog.cc

    r14537 r14553  
    88 */
    99
    10 #include <QDialogButtonBox>
    11 #include <QPlainTextEdit>
    12 #include <QVBoxLayout>
    13 
    1410#include "LicenseDialog.h"
    1511
     
    1713  QDialog (parent, Qt::Dialog)
    1814{
    19   setWindowTitle (tr ("License"));
    20   resize (400, 300);
    21   QVBoxLayout * v = new QVBoxLayout (this);
    22 
    23   QPlainTextEdit * t = new QPlainTextEdit (this);
    24   t->setReadOnly (true);
    25   t->setPlainText (QLatin1String (
    26     "Copyright 2005-2014. All code is copyrighted by the respective authors.\n"
    27     "\n"
    28     "Transmission can be redistributed and/or modified under the terms of the "
    29     "GNU GPL versions 2 or 3 or by any future license endorsed by Mnemosyne LLC.\n"
    30     "\n"
    31     "In addition, linking to and/or using OpenSSL is allowed.\n"
    32     "\n"
    33     "This program is distributed in the hope that it will be useful, "
    34     "but WITHOUT ANY WARRANTY; without even the implied warranty of "
    35     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
    36     "\n"
    37     "Some of Transmission's source files have more permissive licenses. "
    38     "Those files may, of course, be used on their own under their own terms.\n"));
    39   v->addWidget (t);
    40 
    41   QDialogButtonBox * box = new QDialogButtonBox;
    42   box->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
    43   box->setOrientation (Qt::Horizontal);
    44   box->setStandardButtons (QDialogButtonBox::Close);
    45   v->addWidget (box);
    46 
    47   connect (box, SIGNAL (rejected ()), this, SLOT (hide ()));
     15  ui.setupUi (this);
    4816}
  • trunk/qt/LicenseDialog.h

    r14539 r14553  
    1313#include <QDialog>
    1414
     15#include "ui_LicenseDialog.h"
     16
    1517class LicenseDialog: public QDialog
    1618{
     
    2022    LicenseDialog (QWidget * parent = nullptr);
    2123    virtual ~LicenseDialog () {}
     24
     25  private:
     26    Ui::LicenseDialog ui;
    2227};
    2328
  • trunk/qt/MainWindow.cc

    r14547 r14553  
    4343#include "TorrentFilter.h"
    4444#include "TorrentModel.h"
     45#include "Utils.h"
    4546
    4647#define PREFS_KEY "prefs-key";
     
    8485  myModel (model),
    8586  myLastFullUpdateTime (0),
    86   mySessionDialog (new SessionDialog (session, prefs, this)),
     87  mySessionDialog (),
    8788  myPrefsDialog (),
    88   myAboutDialog (new AboutDialog (this)),
    89   myStatsDialog (new StatsDialog (session, this)),
    90   myDetailsDialog (0),
     89  myAboutDialog (),
     90  myStatsDialog (),
     91  myDetailsDialog (),
    9192  myFilterModel (prefs),
    9293  myTorrentDelegate (new TorrentDelegate (this)),
     
    170171  connect (ui.action_New, SIGNAL (triggered ()), this, SLOT (newTorrent ()));
    171172  connect (ui.action_Preferences, SIGNAL (triggered ()), this, SLOT (openPreferences ()));
    172   connect (ui.action_Statistics, SIGNAL (triggered ()), myStatsDialog, SLOT (show ()));
     173  connect (ui.action_Statistics, SIGNAL (triggered ()), this, SLOT (openStats ()));
    173174  connect (ui.action_Donate, SIGNAL (triggered ()), this, SLOT (openDonate ()));
    174   connect (ui.action_About, SIGNAL (triggered ()), myAboutDialog, SLOT (show ()));
     175  connect (ui.action_About, SIGNAL (triggered ()), this, SLOT (openAbout ()));
    175176  connect (ui.action_Contents, SIGNAL (triggered ()), this, SLOT (openHelp ()));
    176177  connect (ui.action_OpenFolder, SIGNAL (triggered ()), this, SLOT (openFolder ()));
     
    178179  connect (ui.action_SetLocation, SIGNAL (triggered ()), this, SLOT (setLocation ()));
    179180  connect (ui.action_Properties, SIGNAL (triggered ()), this, SLOT (openProperties ()));
    180   connect (ui.action_SessionDialog, SIGNAL (triggered ()), mySessionDialog, SLOT (show ()));
     181  connect (ui.action_SessionDialog, SIGNAL (triggered ()), this, SLOT (openSession ()));
    181182
    182183  connect (ui.listView, SIGNAL (activated (QModelIndex)), ui.action_Properties, SLOT (trigger ()));
     
    515516
    516517void
     518MainWindow::openSession ()
     519{
     520  Utils::openDialog (mySessionDialog, mySession, myPrefs, this);
     521}
     522
     523void
    517524MainWindow::openPreferences ()
    518525{
    519   if (myPrefsDialog.isNull ())
    520     {
    521       myPrefsDialog = new PrefsDialog (mySession, myPrefs, this);
    522       myPrefsDialog->setAttribute (Qt::WA_DeleteOnClose);
    523       myPrefsDialog->show ();
    524     }
    525   else
    526     {
    527       myPrefsDialog->raise ();
    528       myPrefsDialog->activateWindow ();
    529     }
    530 }
    531 
    532 void
    533 MainWindow::onDetailsDestroyed ()
    534 {
    535   myDetailsDialog = 0;
     526  Utils::openDialog (myPrefsDialog, mySession, myPrefs, this);
    536527}
    537528
     
    539530MainWindow::openProperties ()
    540531{
    541   if (myDetailsDialog == 0)
    542     {
    543       myDetailsDialog = new DetailsDialog (mySession, myPrefs, myModel, this);
    544       connect (myDetailsDialog, SIGNAL (destroyed (QObject*)), this, SLOT (onDetailsDestroyed ()));
    545     }
    546 
     532  Utils::openDialog (myDetailsDialog, mySession, myPrefs, myModel, this);
    547533  myDetailsDialog->setIds (getSelectedTorrents ());
    548   myDetailsDialog->show ();
    549534}
    550535
     
    619604
    620605void
     606MainWindow::openStats ()
     607{
     608  Utils::openDialog (myStatsDialog, mySession, this);
     609}
     610
     611void
    621612MainWindow::openDonate ()
    622613{
    623614  QDesktopServices::openUrl (QUrl (QLatin1String ("http://www.transmissionbt.com/donate.php")));
     615}
     616
     617void
     618MainWindow::openAbout ()
     619{
     620  Utils::openDialog (myAboutDialog, this);
    624621}
    625622
     
    793790  ui.action_QueueMoveBottom->setEnabled (haveSelection);
    794791
    795   if (myDetailsDialog)
     792  if (!myDetailsDialog.isNull ())
    796793    myDetailsDialog->setIds (getSelectedTorrents ());
    797794}
     
    13831380{
    13841381  mySession.stop ();
    1385   mySessionDialog->show ();
     1382  openSession ();
    13861383}
    13871384
  • trunk/qt/MainWindow.h

    r14539 r14553  
    2929class QMenu;
    3030
     31class AboutDialog;
    3132class AddData;
     33class DetailsDialog;
    3234class Prefs;
    33 class DetailsDialog;
     35class PrefsDialog;
    3436class Session;
     37class SessionDialog;
     38class StatsDialog;
    3539class TorrentDelegate;
    3640class TorrentDelegateMin;
     
    7478    void wrongAuthentication ();
    7579
     80    void openSession ();
     81
    7682  protected:
    7783    // QWidget
     
    99105  private slots:
    100106    void openPreferences ();
    101     void onDetailsDestroyed ();
    102107    void showTotalRatio ();
    103108    void showTotalTransfer ();
     
    115120    void addTorrents (const QStringList& filenames);
    116121    void removeTorrents (const bool deleteFiles);
     122    void openStats ();
    117123    void openDonate ();
     124    void openAbout ();
    118125    void openHelp ();
    119126    void openFolder ();
     
    152159
    153160    time_t myLastFullUpdateTime;
    154     QDialog * mySessionDialog;
    155     QPointer<QDialog> myPrefsDialog;
    156     QDialog * myAboutDialog;
    157     QDialog * myStatsDialog;
    158     DetailsDialog * myDetailsDialog;
     161    QPointer<SessionDialog> mySessionDialog;
     162    QPointer<PrefsDialog> myPrefsDialog;
     163    QPointer<AboutDialog> myAboutDialog;
     164    QPointer<StatsDialog> myStatsDialog;
     165    QPointer<DetailsDialog> myDetailsDialog;
    159166    QSystemTrayIcon myTrayIcon;
    160167    TorrentFilter myFilterModel;
  • trunk/qt/StatsDialog.ui

    r14537 r14553  
    122122      <number>18</number>
    123123     </property>
    124      <item row="0" column="0">
     124     <item row="0" column="0" colspan="2">
    125125      <widget class="QLabel" name="startCountLabel">
    126126       <property name="text">
  • trunk/qt/Utils.h

    r14541 r14553  
    4242    static QColor getFadedColor (const QColor& color);
    4343
     44    template<typename DialogT, typename... ArgsT>
     45    static void
     46    openDialog (QPointer<DialogT>& dialog, ArgsT&&... args)
     47    {
     48      if (dialog.isNull ())
     49        {
     50          dialog = new DialogT (std::forward<ArgsT> (args)...);
     51          dialog->setAttribute (Qt::WA_DeleteOnClose);
     52          dialog->show ();
     53        }
     54      else
     55        {
     56          dialog->raise ();
     57          dialog->activateWindow ();
     58        }
     59    }
     60
    4461    ///
    4562    /// URLs
Note: See TracChangeset for help on using the changeset viewer.