@@ -49,11 +49,10 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
4949{
5050 ui->setupUi (this );
5151
52+ initText ();
5253 QIcon warningIcon (style ()->standardIcon (QStyle::SP_MessageBoxWarning));
5354 ui->warningLabel ->setPixmap (warningIcon.pixmap (32 ));
5455
55- updateText ();
56-
5756 if (m_action == ShutdownAction::None)
5857 ui->neverShowAgainCheckbox ->setVisible (true );
5958 else
@@ -63,12 +62,13 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
6362 QPushButton *cancelButton = ui->buttonBox ->button (QDialogButtonBox::Cancel);
6463 cancelButton->setFocus ();
6564 cancelButton->setDefault (true );
65+
6666 // Always on top
6767 setWindowFlags (windowFlags () | Qt::WindowStaysOnTopHint);
68+ move (Utils::Misc::screenCenter (this ));
69+
6870 m_timer.setInterval (1000 ); // 1sec
6971 connect (&m_timer, SIGNAL (timeout ()), this , SLOT (updateSeconds ()));
70- // Move to center
71- move (Utils::Misc::screenCenter (this ));
7272}
7373
7474ShutdownConfirmDlg::~ShutdownConfirmDlg ()
@@ -85,8 +85,7 @@ void ShutdownConfirmDlg::showEvent(QShowEvent *event)
8585bool ShutdownConfirmDlg::askForConfirmation (const ShutdownAction &action)
8686{
8787 ShutdownConfirmDlg dlg (action);
88- dlg.exec ();
89- return dlg.shutdown ();
88+ return (dlg.exec () == QDialog::Accepted);
9089}
9190
9291void ShutdownConfirmDlg::updateSeconds ()
@@ -105,43 +104,43 @@ void ShutdownConfirmDlg::accept()
105104 QDialog::accept ();
106105}
107106
108- bool ShutdownConfirmDlg::shutdown () const
107+ void ShutdownConfirmDlg::initText ()
109108{
110- return (result () == QDialog::Accepted);
111- }
112-
113- void ShutdownConfirmDlg::updateText ()
114- {
115- QString text;
116109 QPushButton *okButton = ui->buttonBox ->button (QDialogButtonBox::Ok);
117110
118111 switch (m_action) {
119112 case ShutdownAction::None:
120- text = tr (" qBittorrent will now exit." );
113+ m_msg = tr (" qBittorrent will now exit." );
121114
122115 okButton->setText (tr (" E&xit Now" ));
123116 setWindowTitle (tr (" Exit confirmation" ));
124117 break ;
125118 case ShutdownAction::Shutdown:
126- text = tr (" The computer is going to shutdown." );
119+ m_msg = tr (" The computer is going to shutdown." );
127120
128121 okButton->setText (tr (" &Shutdown Now" ));
129122 setWindowTitle (tr (" Shutdown confirmation" ));
130123 break ;
131124 case ShutdownAction::Suspend:
132- text = tr (" The computer is going to enter suspend mode." );
125+ m_msg = tr (" The computer is going to enter suspend mode." );
133126
134127 okButton->setText (tr (" &Suspend Now" ));
135128 setWindowTitle (tr (" Suspend confirmation" ));
136129 break ;
137130 case ShutdownAction::Hibernate:
138- text = tr (" The computer is going to enter hibernation mode." );
131+ m_msg = tr (" The computer is going to enter hibernation mode." );
139132
140133 okButton->setText (tr (" &Hibernate Now" ));
141134 setWindowTitle (tr (" Hibernate confirmation" ));
142135 break ;
143136 }
144137
145- text += " \n " + tr (" You can cancel the action within %1 seconds." ).arg (QString::number (m_timeout)) + " \n " ;
146- ui->shutdownText ->setText (text);
138+ m_msg += " \n " ;
139+ updateText ();
140+ }
141+
142+ void ShutdownConfirmDlg::updateText ()
143+ {
144+ QString t = tr (" You can cancel the action within %1 seconds." ).arg (QString::number (m_timeout)) + " \n " ;
145+ ui->shutdownText ->setText (m_msg + t);
147146}
0 commit comments