Remove the max half-open connections option from GUI
[qBittorrent.git] / src / gui / shutdownconfirmdialog.cpp
blob82de9afaa75889e57e0fd8217262668a6ce0eee5
1 /*
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>
33 #include <QIcon>
34 #include <QPushButton>
35 #include <QStyle>
37 #include "base/preferences.h"
38 #include "ui_shutdownconfirmdialog.h"
39 #include "utils.h"
41 ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDialogAction &action)
42 : QDialog(parent)
43 , m_ui(new Ui::ShutdownConfirmDialog)
44 , m_timeout(15)
45 , m_action(action)
47 m_ui->setupUi(this);
49 initText();
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);
55 else
56 m_ui->neverShowAgainCheckbox->setVisible(false);
58 // Cancel Button
59 QPushButton *cancelButton = m_ui->buttonBox->button(QDialogButtonBox::Cancel);
60 cancelButton->setFocus();
61 cancelButton->setDefault(true);
63 // Always on top
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()
75 delete m_ui;
78 void ShutdownConfirmDialog::showEvent(QShowEvent *event)
80 QDialog::showEvent(event);
81 m_timer.start();
84 bool ShutdownConfirmDialog::askForConfirmation(QWidget *parent, const ShutdownDialogAction &action)
86 ShutdownConfirmDialog dlg(parent, action);
87 return (dlg.exec() == QDialog::Accepted);
90 void ShutdownConfirmDialog::updateSeconds()
92 --m_timeout;
93 updateText();
94 if (m_timeout == 0) {
95 m_timer.stop();
96 accept();
100 void ShutdownConfirmDialog::accept()
102 Preferences::instance()->setDontConfirmAutoExit(m_ui->neverShowAgainCheckbox->isChecked());
103 QDialog::accept();
106 void ShutdownConfirmDialog::initText()
108 QPushButton *okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok);
110 switch (m_action) {
111 case ShutdownDialogAction::Exit:
112 m_msg = tr("qBittorrent will now exit.");
113 okButton->setText(tr("E&xit Now"));
114 setWindowTitle(tr("Exit confirmation"));
115 break;
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"));
120 break;
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"));
125 break;
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"));
130 break;
133 m_msg += '\n';
134 updateText();
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);