2014-08-23 20:06:20 +04:00
|
|
|
/*
|
2015-03-31 14:59:26 +03:00
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
2014-08-23 20:06:20 +04:00
|
|
|
* Copyright (C) 2011 Christophe Dumez
|
|
|
|
* Copyright (C) 2014 sledgehammer999
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
|
|
|
* Contact : hammered999@gmail.com
|
|
|
|
*/
|
|
|
|
|
2015-09-25 11:10:05 +03:00
|
|
|
#include "base/types.h"
|
2014-08-23 20:06:20 +04:00
|
|
|
#include "shutdownconfirm.h"
|
|
|
|
|
2015-12-09 11:01:48 +03:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QCheckBox>
|
2014-08-23 22:08:27 +04:00
|
|
|
#include <QPushButton>
|
2014-08-23 20:06:20 +04:00
|
|
|
|
2015-05-06 14:53:27 +03:00
|
|
|
ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
|
2015-12-09 11:01:48 +03:00
|
|
|
: m_neverShowAgain(false)
|
2015-03-31 14:59:26 +03:00
|
|
|
, m_timeout(15)
|
|
|
|
, m_action(action)
|
|
|
|
{
|
2015-12-09 11:01:48 +03:00
|
|
|
QVBoxLayout *myLayout = new QVBoxLayout();
|
|
|
|
//Warning Icon and Text
|
|
|
|
QHBoxLayout *messageRow = new QHBoxLayout();
|
|
|
|
QLabel *warningLabel = new QLabel();
|
|
|
|
QIcon warningIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, this));
|
|
|
|
warningLabel->setPixmap(warningIcon.pixmap(warningIcon.actualSize(QSize(32, 32))));
|
|
|
|
messageRow->addWidget(warningLabel);
|
|
|
|
m_text = new QLabel();
|
|
|
|
messageRow->addWidget(m_text);
|
|
|
|
myLayout->addLayout(messageRow);
|
|
|
|
updateText();
|
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Horizontal);
|
|
|
|
// Never show again checkbox, Title, and button
|
2015-05-06 14:53:27 +03:00
|
|
|
if (m_action == ShutdownAction::None) {
|
2015-12-09 11:01:48 +03:00
|
|
|
//Never show again checkbox (shown only when exitting without shutdown)
|
|
|
|
QCheckBox *neverShowAgainCheckbox = new QCheckBox(tr("Never show again"));
|
|
|
|
myLayout->addWidget(neverShowAgainCheckbox, 0, Qt::AlignHCenter);
|
|
|
|
//Title and button
|
|
|
|
connect(neverShowAgainCheckbox, SIGNAL(clicked(bool)), this, SLOT(handleNeverShowAgainCheckboxToggled(bool)));
|
2015-02-25 12:48:40 +03:00
|
|
|
setWindowTitle(tr("Exit confirmation"));
|
2015-12-09 11:01:48 +03:00
|
|
|
buttons->addButton(new QPushButton(tr("Exit Now")), QDialogButtonBox::AcceptRole);
|
2015-02-25 12:48:40 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
setWindowTitle(tr("Shutdown confirmation"));
|
2015-12-09 11:01:48 +03:00
|
|
|
buttons->addButton(new QPushButton(tr("Shutdown Now")), QDialogButtonBox::AcceptRole);
|
2015-02-25 12:48:40 +03:00
|
|
|
}
|
|
|
|
// Cancel Button
|
2015-12-09 11:01:48 +03:00
|
|
|
QPushButton *cancelButton = buttons->addButton(QDialogButtonBox::Cancel);
|
|
|
|
cancelButton->setDefault(true);
|
|
|
|
myLayout->addWidget(buttons, 0, Qt::AlignHCenter);
|
|
|
|
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
2015-02-25 12:48:40 +03:00
|
|
|
// Always on top
|
|
|
|
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
|
|
|
|
// Set 'Cancel' as default button.
|
2015-03-31 14:59:26 +03:00
|
|
|
m_timer.setInterval(1000); // 1sec
|
2015-11-25 19:30:43 +03:00
|
|
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
2015-02-25 12:48:40 +03:00
|
|
|
// Move to center
|
2015-05-06 14:53:27 +03:00
|
|
|
move(Utils::Misc::screenCenter(this));
|
2015-12-09 11:01:48 +03:00
|
|
|
setLayout(myLayout);
|
|
|
|
cancelButton->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShutdownConfirmDlg::neverShowAgain() const
|
|
|
|
{
|
|
|
|
return m_neverShowAgain;
|
2014-08-23 20:06:20 +04:00
|
|
|
}
|
|
|
|
|
2015-03-31 14:59:26 +03:00
|
|
|
void ShutdownConfirmDlg::showEvent(QShowEvent *event)
|
|
|
|
{
|
2015-12-09 11:01:48 +03:00
|
|
|
QDialog::showEvent(event);
|
2015-03-31 14:59:26 +03:00
|
|
|
m_timer.start();
|
2014-08-23 22:08:27 +04:00
|
|
|
}
|
|
|
|
|
2015-12-09 11:01:48 +03:00
|
|
|
void ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action, bool *shutdownConfirmed, bool *neverShowAgain)
|
2015-03-31 14:59:26 +03:00
|
|
|
{
|
2015-02-25 12:48:40 +03:00
|
|
|
ShutdownConfirmDlg dlg(action);
|
|
|
|
dlg.exec();
|
2015-12-09 11:01:48 +03:00
|
|
|
*shutdownConfirmed = dlg.shutdown();
|
|
|
|
if (neverShowAgain)
|
|
|
|
*neverShowAgain = dlg.neverShowAgain();
|
2014-08-23 20:06:20 +04:00
|
|
|
}
|
2014-08-23 22:08:27 +04:00
|
|
|
|
2015-03-31 14:59:26 +03:00
|
|
|
void ShutdownConfirmDlg::updateSeconds()
|
|
|
|
{
|
|
|
|
--m_timeout;
|
2015-02-25 12:48:40 +03:00
|
|
|
updateText();
|
2015-03-31 14:59:26 +03:00
|
|
|
if (m_timeout == 0) {
|
|
|
|
m_timer.stop();
|
2015-02-25 12:48:40 +03:00
|
|
|
accept();
|
|
|
|
}
|
2014-08-23 22:08:27 +04:00
|
|
|
}
|
|
|
|
|
2015-12-09 11:01:48 +03:00
|
|
|
void ShutdownConfirmDlg::handleNeverShowAgainCheckboxToggled(bool checked)
|
|
|
|
{
|
|
|
|
m_neverShowAgain = checked;
|
|
|
|
}
|
|
|
|
|
2015-03-31 14:59:26 +03:00
|
|
|
bool ShutdownConfirmDlg::shutdown() const
|
|
|
|
{
|
2015-12-09 11:01:48 +03:00
|
|
|
return (result() == QDialog::Accepted);
|
2014-08-23 22:08:27 +04:00
|
|
|
}
|
|
|
|
|
2015-03-31 14:59:26 +03:00
|
|
|
void ShutdownConfirmDlg::updateText()
|
|
|
|
{
|
2015-02-25 12:48:40 +03:00
|
|
|
QString text;
|
2014-08-23 22:08:27 +04:00
|
|
|
|
2015-03-31 14:59:26 +03:00
|
|
|
switch (m_action) {
|
2015-05-06 14:53:27 +03:00
|
|
|
case ShutdownAction::None:
|
2015-03-31 14:59:26 +03:00
|
|
|
text = tr("qBittorrent will now exit unless you cancel within the next %1 seconds.").arg(QString::number(m_timeout));
|
2015-02-25 12:48:40 +03:00
|
|
|
break;
|
2015-05-06 14:53:27 +03:00
|
|
|
case ShutdownAction::Shutdown:
|
2015-03-31 14:59:26 +03:00
|
|
|
text = tr("The computer will now be switched off unless you cancel within the next %1 seconds.").arg(QString::number(m_timeout));
|
2015-02-25 12:48:40 +03:00
|
|
|
break;
|
2015-05-06 14:53:27 +03:00
|
|
|
case ShutdownAction::Suspend:
|
2015-03-31 14:59:26 +03:00
|
|
|
text = tr("The computer will now go to sleep mode unless you cancel within the next %1 seconds.").arg(QString::number(m_timeout));
|
2015-02-25 12:48:40 +03:00
|
|
|
break;
|
2015-05-06 14:53:27 +03:00
|
|
|
case ShutdownAction::Hibernate:
|
2015-03-31 14:59:26 +03:00
|
|
|
text = tr("The computer will now go to hibernation mode unless you cancel within the next %1 seconds.").arg(QString::number(m_timeout));
|
2015-02-25 12:48:40 +03:00
|
|
|
break;
|
|
|
|
}
|
2014-08-23 22:08:27 +04:00
|
|
|
|
2015-12-09 11:01:48 +03:00
|
|
|
m_text->setText(text);
|
2015-03-31 14:59:26 +03:00
|
|
|
}
|