Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
4.6 KiB
143 lines
4.6 KiB
10 years ago
|
/*
|
||
10 years ago
|
* Bittorrent Client using Qt and libtorrent.
|
||
8 years ago
|
* Copyright (C) 2014 sledgehammer999 <hammered999@gmail.com>
|
||
|
* Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
|
||
10 years ago
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
7 years ago
|
#include "shutdownconfirmdialog.h"
|
||
9 years ago
|
|
||
9 years ago
|
#include <QDialogButtonBox>
|
||
8 years ago
|
#include <QIcon>
|
||
10 years ago
|
#include <QPushButton>
|
||
8 years ago
|
#include <QStyle>
|
||
10 years ago
|
|
||
9 years ago
|
#include "base/preferences.h"
|
||
9 years ago
|
#include "base/utils/misc.h"
|
||
7 years ago
|
#include "ui_shutdownconfirmdialog.h"
|
||
7 years ago
|
#include "utils.h"
|
||
9 years ago
|
|
||
7 years ago
|
ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDialogAction &action)
|
||
9 years ago
|
: QDialog(parent)
|
||
7 years ago
|
, m_ui(new Ui::ShutdownConfirmDialog)
|
||
10 years ago
|
, m_timeout(15)
|
||
|
, m_action(action)
|
||
|
{
|
||
8 years ago
|
m_ui->setupUi(this);
|
||
9 years ago
|
|
||
9 years ago
|
initText();
|
||
9 years ago
|
QIcon warningIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning));
|
||
8 years ago
|
m_ui->warningLabel->setPixmap(warningIcon.pixmap(32));
|
||
9 years ago
|
|
||
9 years ago
|
if (m_action == ShutdownDialogAction::Exit)
|
||
8 years ago
|
m_ui->neverShowAgainCheckbox->setVisible(true);
|
||
9 years ago
|
else
|
||
8 years ago
|
m_ui->neverShowAgainCheckbox->setVisible(false);
|
||
9 years ago
|
|
||
10 years ago
|
// Cancel Button
|
||
8 years ago
|
QPushButton *cancelButton = m_ui->buttonBox->button(QDialogButtonBox::Cancel);
|
||
9 years ago
|
cancelButton->setFocus();
|
||
9 years ago
|
cancelButton->setDefault(true);
|
||
9 years ago
|
|
||
10 years ago
|
// Always on top
|
||
9 years ago
|
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
||
9 years ago
|
move(Utils::Misc::screenCenter(this));
|
||
|
|
||
10 years ago
|
m_timer.setInterval(1000); // 1sec
|
||
7 years ago
|
connect(&m_timer, &QTimer::timeout, this, &ShutdownConfirmDialog::updateSeconds);
|
||
7 years ago
|
|
||
|
Utils::Gui::resize(this);
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
ShutdownConfirmDialog::~ShutdownConfirmDialog()
|
||
9 years ago
|
{
|
||
8 years ago
|
delete m_ui;
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
void ShutdownConfirmDialog::showEvent(QShowEvent *event)
|
||
10 years ago
|
{
|
||
9 years ago
|
QDialog::showEvent(event);
|
||
10 years ago
|
m_timer.start();
|
||
10 years ago
|
}
|
||
|
|
||
7 years ago
|
bool ShutdownConfirmDialog::askForConfirmation(QWidget *parent, const ShutdownDialogAction &action)
|
||
10 years ago
|
{
|
||
7 years ago
|
ShutdownConfirmDialog dlg(parent, action);
|
||
9 years ago
|
return (dlg.exec() == QDialog::Accepted);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
7 years ago
|
void ShutdownConfirmDialog::updateSeconds()
|
||
10 years ago
|
{
|
||
|
--m_timeout;
|
||
10 years ago
|
updateText();
|
||
10 years ago
|
if (m_timeout == 0) {
|
||
|
m_timer.stop();
|
||
10 years ago
|
accept();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
7 years ago
|
void ShutdownConfirmDialog::accept()
|
||
9 years ago
|
{
|
||
8 years ago
|
Preferences::instance()->setDontConfirmAutoExit(m_ui->neverShowAgainCheckbox->isChecked());
|
||
9 years ago
|
QDialog::accept();
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
void ShutdownConfirmDialog::initText()
|
||
10 years ago
|
{
|
||
8 years ago
|
QPushButton *okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok);
|
||
10 years ago
|
|
||
10 years ago
|
switch (m_action) {
|
||
9 years ago
|
case ShutdownDialogAction::Exit:
|
||
9 years ago
|
m_msg = tr("qBittorrent will now exit.");
|
||
9 years ago
|
okButton->setText(tr("E&xit Now"));
|
||
|
setWindowTitle(tr("Exit confirmation"));
|
||
10 years ago
|
break;
|
||
9 years ago
|
case ShutdownDialogAction::Shutdown:
|
||
9 years ago
|
m_msg = tr("The computer is going to shutdown.");
|
||
9 years ago
|
okButton->setText(tr("&Shutdown Now"));
|
||
|
setWindowTitle(tr("Shutdown confirmation"));
|
||
10 years ago
|
break;
|
||
9 years ago
|
case ShutdownDialogAction::Suspend:
|
||
9 years ago
|
m_msg = tr("The computer is going to enter suspend mode.");
|
||
9 years ago
|
okButton->setText(tr("&Suspend Now"));
|
||
|
setWindowTitle(tr("Suspend confirmation"));
|
||
10 years ago
|
break;
|
||
9 years ago
|
case ShutdownDialogAction::Hibernate:
|
||
9 years ago
|
m_msg = tr("The computer is going to enter hibernation mode.");
|
||
9 years ago
|
okButton->setText(tr("&Hibernate Now"));
|
||
|
setWindowTitle(tr("Hibernate confirmation"));
|
||
10 years ago
|
break;
|
||
|
}
|
||
10 years ago
|
|
||
7 years ago
|
m_msg += '\n';
|
||
9 years ago
|
updateText();
|
||
|
}
|
||
|
|
||
7 years ago
|
void ShutdownConfirmDialog::updateText()
|
||
9 years ago
|
{
|
||
7 years ago
|
QString t = tr("You can cancel the action within %1 seconds.").arg(QString::number(m_timeout)) + '\n';
|
||
8 years ago
|
m_ui->shutdownText->setText(m_msg + t);
|
||
10 years ago
|
}
|