mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Refactor
Add helper function to initialize shutdown message. Group similar functions together. Merge shutdown() function into its only caller. Add override keyword
This commit is contained in:
parent
acd65e3185
commit
7779efbc30
2 changed files with 21 additions and 21 deletions
|
@ -49,11 +49,10 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
initText();
|
||||||
QIcon warningIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning));
|
QIcon warningIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning));
|
||||||
ui->warningLabel->setPixmap(warningIcon.pixmap(32));
|
ui->warningLabel->setPixmap(warningIcon.pixmap(32));
|
||||||
|
|
||||||
updateText();
|
|
||||||
|
|
||||||
if (m_action == ShutdownAction::None)
|
if (m_action == ShutdownAction::None)
|
||||||
ui->neverShowAgainCheckbox->setVisible(true);
|
ui->neverShowAgainCheckbox->setVisible(true);
|
||||||
else
|
else
|
||||||
|
@ -63,12 +62,13 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
|
||||||
QPushButton *cancelButton = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
QPushButton *cancelButton = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
||||||
cancelButton->setFocus();
|
cancelButton->setFocus();
|
||||||
cancelButton->setDefault(true);
|
cancelButton->setDefault(true);
|
||||||
|
|
||||||
// Always on top
|
// Always on top
|
||||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
||||||
|
move(Utils::Misc::screenCenter(this));
|
||||||
|
|
||||||
m_timer.setInterval(1000); // 1sec
|
m_timer.setInterval(1000); // 1sec
|
||||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
||||||
// Move to center
|
|
||||||
move(Utils::Misc::screenCenter(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ShutdownConfirmDlg::~ShutdownConfirmDlg()
|
ShutdownConfirmDlg::~ShutdownConfirmDlg()
|
||||||
|
@ -85,8 +85,7 @@ void ShutdownConfirmDlg::showEvent(QShowEvent *event)
|
||||||
bool ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action)
|
bool ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action)
|
||||||
{
|
{
|
||||||
ShutdownConfirmDlg dlg(action);
|
ShutdownConfirmDlg dlg(action);
|
||||||
dlg.exec();
|
return (dlg.exec() == QDialog::Accepted);
|
||||||
return dlg.shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownConfirmDlg::updateSeconds()
|
void ShutdownConfirmDlg::updateSeconds()
|
||||||
|
@ -105,43 +104,43 @@ void ShutdownConfirmDlg::accept()
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShutdownConfirmDlg::shutdown() const
|
void ShutdownConfirmDlg::initText()
|
||||||
{
|
{
|
||||||
return (result() == QDialog::Accepted);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShutdownConfirmDlg::updateText()
|
|
||||||
{
|
|
||||||
QString text;
|
|
||||||
QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||||
|
|
||||||
switch (m_action) {
|
switch (m_action) {
|
||||||
case ShutdownAction::None:
|
case ShutdownAction::None:
|
||||||
text = tr("qBittorrent will now exit.");
|
m_msg = tr("qBittorrent will now exit.");
|
||||||
|
|
||||||
okButton->setText(tr("E&xit Now"));
|
okButton->setText(tr("E&xit Now"));
|
||||||
setWindowTitle(tr("Exit confirmation"));
|
setWindowTitle(tr("Exit confirmation"));
|
||||||
break;
|
break;
|
||||||
case ShutdownAction::Shutdown:
|
case ShutdownAction::Shutdown:
|
||||||
text = tr("The computer is going to shutdown.");
|
m_msg = tr("The computer is going to shutdown.");
|
||||||
|
|
||||||
okButton->setText(tr("&Shutdown Now"));
|
okButton->setText(tr("&Shutdown Now"));
|
||||||
setWindowTitle(tr("Shutdown confirmation"));
|
setWindowTitle(tr("Shutdown confirmation"));
|
||||||
break;
|
break;
|
||||||
case ShutdownAction::Suspend:
|
case ShutdownAction::Suspend:
|
||||||
text = tr("The computer is going to enter suspend mode.");
|
m_msg = tr("The computer is going to enter suspend mode.");
|
||||||
|
|
||||||
okButton->setText(tr("&Suspend Now"));
|
okButton->setText(tr("&Suspend Now"));
|
||||||
setWindowTitle(tr("Suspend confirmation"));
|
setWindowTitle(tr("Suspend confirmation"));
|
||||||
break;
|
break;
|
||||||
case ShutdownAction::Hibernate:
|
case ShutdownAction::Hibernate:
|
||||||
text = tr("The computer is going to enter hibernation mode.");
|
m_msg = tr("The computer is going to enter hibernation mode.");
|
||||||
|
|
||||||
okButton->setText(tr("&Hibernate Now"));
|
okButton->setText(tr("&Hibernate Now"));
|
||||||
setWindowTitle(tr("Hibernate confirmation"));
|
setWindowTitle(tr("Hibernate confirmation"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
text += "\n" + tr("You can cancel the action within %1 seconds.").arg(QString::number(m_timeout)) + "\n";
|
m_msg += "\n";
|
||||||
ui->shutdownText->setText(text);
|
updateText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShutdownConfirmDlg::updateText()
|
||||||
|
{
|
||||||
|
QString t = tr("You can cancel the action within %1 seconds.").arg(QString::number(m_timeout)) + "\n";
|
||||||
|
ui->shutdownText->setText(m_msg + t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,12 +47,11 @@ class ShutdownConfirmDlg: public QDialog
|
||||||
public:
|
public:
|
||||||
ShutdownConfirmDlg(const ShutdownAction &action);
|
ShutdownConfirmDlg(const ShutdownAction &action);
|
||||||
~ShutdownConfirmDlg();
|
~ShutdownConfirmDlg();
|
||||||
bool shutdown() const;
|
|
||||||
|
|
||||||
static bool askForConfirmation(const ShutdownAction &action);
|
static bool askForConfirmation(const ShutdownAction &action);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateSeconds();
|
void updateSeconds();
|
||||||
|
@ -60,6 +59,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Methods
|
// Methods
|
||||||
|
void initText();
|
||||||
void updateText();
|
void updateText();
|
||||||
|
|
||||||
// Vars
|
// Vars
|
||||||
|
@ -67,6 +67,7 @@ private:
|
||||||
QTimer m_timer;
|
QTimer m_timer;
|
||||||
int m_timeout;
|
int m_timeout;
|
||||||
ShutdownAction m_action;
|
ShutdownAction m_action;
|
||||||
|
QString m_msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHUTDOWNCONFIRM_H
|
#endif // SHUTDOWNCONFIRM_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue