Combine all the column filter related widgets
[qBittorrent.git] / src / gui / shutdownconfirmdialog.cpp
blobdd1f9ecb966f97b426fdf399244891067126816e
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 <chrono>
34 #include <QDialogButtonBox>
35 #include <QIcon>
36 #include <QPushButton>
37 #include <QStyle>
39 #include "base/preferences.h"
40 #include "ui_shutdownconfirmdialog.h"
41 #include "utils.h"
43 using namespace std::chrono_literals;
45 ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDialogAction &action)
46 : QDialog(parent)
47 , m_ui(new Ui::ShutdownConfirmDialog)
48 , m_action(action)
50 m_ui->setupUi(this);
52 initText();
53 QIcon warningIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning));
54 m_ui->warningLabel->setPixmap(warningIcon.pixmap(32));
56 if (m_action == ShutdownDialogAction::Exit)
57 m_ui->neverShowAgainCheckbox->setVisible(true);
58 else
59 m_ui->neverShowAgainCheckbox->setVisible(false);
61 // Cancel Button
62 QPushButton *cancelButton = m_ui->buttonBox->button(QDialogButtonBox::Cancel);
63 cancelButton->setFocus();
64 cancelButton->setDefault(true);
66 // Always on top
67 setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
68 move(Utils::Gui::screenCenter(this));
70 m_timer.setInterval(1s);
71 connect(&m_timer, &QTimer::timeout, this, &ShutdownConfirmDialog::updateSeconds);
74 ShutdownConfirmDialog::~ShutdownConfirmDialog()
76 delete m_ui;
79 void ShutdownConfirmDialog::showEvent(QShowEvent *event)
81 QDialog::showEvent(event);
82 m_timer.start();
85 bool ShutdownConfirmDialog::askForConfirmation(QWidget *parent, const ShutdownDialogAction &action)
87 ShutdownConfirmDialog dlg(parent, action);
88 return (dlg.exec() == QDialog::Accepted);
91 void ShutdownConfirmDialog::updateSeconds()
93 --m_timeout;
94 updateText();
95 if (m_timeout == 0)
97 m_timer.stop();
98 accept();
102 void ShutdownConfirmDialog::accept()
104 Preferences::instance()->setDontConfirmAutoExit(m_ui->neverShowAgainCheckbox->isChecked());
105 QDialog::accept();
108 void ShutdownConfirmDialog::initText()
110 QPushButton *okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok);
112 switch (m_action)
114 case ShutdownDialogAction::Exit:
115 m_msg = tr("qBittorrent will now exit.");
116 okButton->setText(tr("E&xit Now"));
117 setWindowTitle(tr("Exit confirmation"));
118 break;
119 case ShutdownDialogAction::Shutdown:
120 m_msg = tr("The computer is going to shutdown.");
121 okButton->setText(tr("&Shutdown Now"));
122 setWindowTitle(tr("Shutdown confirmation"));
123 break;
124 case ShutdownDialogAction::Suspend:
125 m_msg = tr("The computer is going to enter suspend mode.");
126 okButton->setText(tr("&Suspend Now"));
127 setWindowTitle(tr("Suspend confirmation"));
128 break;
129 case ShutdownDialogAction::Hibernate:
130 m_msg = tr("The computer is going to enter hibernation mode.");
131 okButton->setText(tr("&Hibernate Now"));
132 setWindowTitle(tr("Hibernate confirmation"));
133 break;
136 m_msg += u'\n';
137 updateText();
140 void ShutdownConfirmDialog::updateText()
142 QString t = tr("You can cancel the action within %1 seconds.").arg(QString::number(m_timeout)) + u'\n';
143 m_ui->shutdownText->setText(m_msg + t);