2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2014 sledgehammer999 <hammered999@gmail.com>
4 * Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
30 #include "shutdownconfirmdialog.h"
32 #include <QDialogButtonBox>
34 #include <QPushButton>
37 #include "base/preferences.h"
38 #include "ui_shutdownconfirmdialog.h"
41 ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget
*parent
, const ShutdownDialogAction
&action
)
43 , m_ui(new Ui::ShutdownConfirmDialog
)
50 QIcon
warningIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning
));
51 m_ui
->warningLabel
->setPixmap(warningIcon
.pixmap(32));
53 if (m_action
== ShutdownDialogAction::Exit
)
54 m_ui
->neverShowAgainCheckbox
->setVisible(true);
56 m_ui
->neverShowAgainCheckbox
->setVisible(false);
59 QPushButton
*cancelButton
= m_ui
->buttonBox
->button(QDialogButtonBox::Cancel
);
60 cancelButton
->setFocus();
61 cancelButton
->setDefault(true);
64 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint
);
65 move(Utils::Gui::screenCenter(this));
67 m_timer
.setInterval(1000); // 1sec
68 connect(&m_timer
, &QTimer::timeout
, this, &ShutdownConfirmDialog::updateSeconds
);
70 Utils::Gui::resize(this);
73 ShutdownConfirmDialog::~ShutdownConfirmDialog()
78 void ShutdownConfirmDialog::showEvent(QShowEvent
*event
)
80 QDialog::showEvent(event
);
84 bool ShutdownConfirmDialog::askForConfirmation(QWidget
*parent
, const ShutdownDialogAction
&action
)
86 ShutdownConfirmDialog
dlg(parent
, action
);
87 return (dlg
.exec() == QDialog::Accepted
);
90 void ShutdownConfirmDialog::updateSeconds()
100 void ShutdownConfirmDialog::accept()
102 Preferences::instance()->setDontConfirmAutoExit(m_ui
->neverShowAgainCheckbox
->isChecked());
106 void ShutdownConfirmDialog::initText()
108 QPushButton
*okButton
= m_ui
->buttonBox
->button(QDialogButtonBox::Ok
);
111 case ShutdownDialogAction::Exit
:
112 m_msg
= tr("qBittorrent will now exit.");
113 okButton
->setText(tr("E&xit Now"));
114 setWindowTitle(tr("Exit confirmation"));
116 case ShutdownDialogAction::Shutdown
:
117 m_msg
= tr("The computer is going to shutdown.");
118 okButton
->setText(tr("&Shutdown Now"));
119 setWindowTitle(tr("Shutdown confirmation"));
121 case ShutdownDialogAction::Suspend
:
122 m_msg
= tr("The computer is going to enter suspend mode.");
123 okButton
->setText(tr("&Suspend Now"));
124 setWindowTitle(tr("Suspend confirmation"));
126 case ShutdownDialogAction::Hibernate
:
127 m_msg
= tr("The computer is going to enter hibernation mode.");
128 okButton
->setText(tr("&Hibernate Now"));
129 setWindowTitle(tr("Hibernate confirmation"));
137 void ShutdownConfirmDialog::updateText()
139 QString t
= tr("You can cancel the action within %1 seconds.").arg(QString::number(m_timeout
)) + '\n';
140 m_ui
->shutdownText
->setText(m_msg
+ t
);