mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-05 11:24:15 +00:00
Fix shutdownconfirm.* coding style (Issue #2192).
This commit is contained in:
parent
d87a9bf7ec
commit
98dfb6302d
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt4 and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
* Copyright (C) 2011 Christophe Dumez
|
* Copyright (C) 2011 Christophe Dumez
|
||||||
* Copyright (C) 2014 sledgehammer999
|
* Copyright (C) 2014 sledgehammer999
|
||||||
*
|
*
|
||||||
@ -34,15 +34,19 @@
|
|||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
ShutdownConfirmDlg::ShutdownConfirmDlg(const shutDownAction &action): exit_now(NULL), timeout(15), action0(action) {
|
ShutdownConfirmDlg::ShutdownConfirmDlg(const shutDownAction &action)
|
||||||
|
: m_exitNow(0)
|
||||||
|
, m_timeout(15)
|
||||||
|
, m_action(action)
|
||||||
|
{
|
||||||
// Title and button
|
// Title and button
|
||||||
if (action0 == NO_SHUTDOWN) {
|
if (m_action == NO_SHUTDOWN) {
|
||||||
setWindowTitle(tr("Exit confirmation"));
|
setWindowTitle(tr("Exit confirmation"));
|
||||||
exit_now = addButton(tr("Exit now"), QMessageBox::AcceptRole);
|
m_exitNow = addButton(tr("Exit now"), QMessageBox::AcceptRole);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setWindowTitle(tr("Shutdown confirmation"));
|
setWindowTitle(tr("Shutdown confirmation"));
|
||||||
exit_now = addButton(tr("Shutdown now"), QMessageBox::AcceptRole);
|
m_exitNow = addButton(tr("Shutdown now"), QMessageBox::AcceptRole);
|
||||||
}
|
}
|
||||||
// Cancel Button
|
// Cancel Button
|
||||||
addButton(QMessageBox::Cancel);
|
addButton(QMessageBox::Cancel);
|
||||||
@ -54,61 +58,75 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const shutDownAction &action): exit_now(N
|
|||||||
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
|
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
|
||||||
// Set 'Cancel' as default button.
|
// Set 'Cancel' as default button.
|
||||||
setDefaultButton(QMessageBox::Cancel);
|
setDefaultButton(QMessageBox::Cancel);
|
||||||
timer.setInterval(1000); // 1sec
|
m_timer.setInterval(1000); // 1sec
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
connect(&m_timer, SIGNAL(m_timeout()), this, SLOT(updateSeconds()));
|
||||||
show();
|
show();
|
||||||
// Move to center
|
// Move to center
|
||||||
move(misc::screenCenter(this));
|
move(misc::screenCenter(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownConfirmDlg::showEvent(QShowEvent *event) {
|
void ShutdownConfirmDlg::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
QMessageBox::showEvent(event);
|
QMessageBox::showEvent(event);
|
||||||
timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShutdownConfirmDlg::askForConfirmation(const shutDownAction &action) {
|
bool ShutdownConfirmDlg::askForConfirmation(const shutDownAction &action)
|
||||||
|
{
|
||||||
ShutdownConfirmDlg dlg(action);
|
ShutdownConfirmDlg dlg(action);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
return dlg.shutdown();
|
return dlg.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownConfirmDlg::updateSeconds() {
|
void ShutdownConfirmDlg::updateSeconds()
|
||||||
--timeout;
|
{
|
||||||
|
--m_timeout;
|
||||||
updateText();
|
updateText();
|
||||||
if (timeout == 0) {
|
if (m_timeout == 0) {
|
||||||
timer.stop();
|
m_timer.stop();
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShutdownConfirmDlg::shutdown() const {
|
bool ShutdownConfirmDlg::shutdown() const
|
||||||
|
{
|
||||||
// This is necessary because result() in the case of QMessageBox
|
// This is necessary because result() in the case of QMessageBox
|
||||||
// returns a type of StandardButton, but since we use a custom button
|
// returns a type of StandardButton, but since we use a custom button
|
||||||
// it will return 0 instead, even though we set the 'accept' role on it.
|
// it will return 0 instead, even though we set the 'accept' role on it.
|
||||||
if (result() != QDialog::Accepted)
|
if (result() != QDialog::Accepted)
|
||||||
return (clickedButton() == exit_now);
|
return (clickedButton() == m_exitNow);
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownConfirmDlg::updateText() {
|
void ShutdownConfirmDlg::updateText()
|
||||||
|
{
|
||||||
QString text;
|
QString text;
|
||||||
|
|
||||||
switch (action0) {
|
switch (m_action) {
|
||||||
case NO_SHUTDOWN:
|
case NO_SHUTDOWN:
|
||||||
text = tr("qBittorrent will now exit unless you cancel within the next %1 seconds.").arg(QString::number(timeout));
|
text = tr("qBittorrent will now exit unless you cancel within the next %1 seconds.").arg(QString::number(m_timeout));
|
||||||
break;
|
break;
|
||||||
case SHUTDOWN_COMPUTER:
|
case SHUTDOWN_COMPUTER:
|
||||||
text = tr("The computer will now be switched off unless you cancel within the next %1 seconds.").arg(QString::number(timeout));
|
text = tr("The computer will now be switched off unless you cancel within the next %1 seconds.").arg(QString::number(m_timeout));
|
||||||
break;
|
break;
|
||||||
case SUSPEND_COMPUTER:
|
case SUSPEND_COMPUTER:
|
||||||
text = tr("The computer will now go to sleep mode unless you cancel within the next %1 seconds.").arg(QString::number(timeout));
|
text = tr("The computer will now go to sleep mode unless you cancel within the next %1 seconds.").arg(QString::number(m_timeout));
|
||||||
break;
|
break;
|
||||||
case HIBERNATE_COMPUTER:
|
case HIBERNATE_COMPUTER:
|
||||||
text = tr("The computer will now go to hibernation mode unless you cancel within the next %1 seconds.").arg(QString::number(timeout));
|
text = tr("The computer will now go to hibernation mode unless you cancel within the next %1 seconds.").arg(QString::number(m_timeout));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
setText(text);
|
setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QAbstractButton *ShutdownConfirmDlg::getExit_now() const
|
||||||
|
{
|
||||||
|
return m_exitNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShutdownConfirmDlg::setExit_now(QAbstractButton *value)
|
||||||
|
{
|
||||||
|
m_exitNow = value;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt4 and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
* Copyright (C) 2011 Christophe Dumez
|
* Copyright (C) 2011 Christophe Dumez
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
@ -35,7 +35,8 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
class ShutdownConfirmDlg : public QMessageBox {
|
class ShutdownConfirmDlg : public QMessageBox
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -44,6 +45,9 @@ public:
|
|||||||
|
|
||||||
static bool askForConfirmation(const shutDownAction &action);
|
static bool askForConfirmation(const shutDownAction &action);
|
||||||
|
|
||||||
|
QAbstractButton *getExit_now() const;
|
||||||
|
void setExit_now(QAbstractButton *value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
|
|
||||||
@ -55,10 +59,10 @@ private:
|
|||||||
void updateText();
|
void updateText();
|
||||||
|
|
||||||
// Vars
|
// Vars
|
||||||
QAbstractButton *exit_now;
|
QAbstractButton *m_exitNow;
|
||||||
QTimer timer;
|
QTimer m_timer;
|
||||||
int timeout;
|
int m_timeout;
|
||||||
shutDownAction action0;
|
shutDownAction m_action;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHUTDOWNCONFIRM_H
|
#endif // SHUTDOWNCONFIRM_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user