Browse Source

Fix previous commit.

adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
18ee87f586
  1. 21
      src/app/application.cpp
  2. 4
      src/base/preferences.cpp
  3. 146
      src/gui/confirmshutdowndlg.ui
  4. 1
      src/gui/gui.pri
  5. 58
      src/gui/shutdownconfirm.cpp
  6. 14
      src/gui/shutdownconfirm.h

21
src/app/application.cpp

@ -287,12 +287,12 @@ void Application::allTorrentsFinished() @@ -287,12 +287,12 @@ void Application::allTorrentsFinished()
Preferences *const pref = Preferences::instance();
bool will_shutdown = (pref->shutdownWhenDownloadsComplete()
|| pref->shutdownqBTWhenDownloadsComplete()
|| pref->suspendWhenDownloadsComplete()
|| pref->hibernateWhenDownloadsComplete());
bool will_exit_only = pref->shutdownqBTWhenDownloadsComplete();
// Auto-Shutdown
if (will_exit_only || will_shutdown) {
if (will_shutdown) {
bool suspend = pref->suspendWhenDownloadsComplete();
bool hibernate = pref->hibernateWhenDownloadsComplete();
bool shutdown = pref->shutdownWhenDownloadsComplete();
@ -306,20 +306,13 @@ void Application::allTorrentsFinished() @@ -306,20 +306,13 @@ void Application::allTorrentsFinished()
else if (shutdown)
action = ShutdownAction::Shutdown;
if (will_exit_only) {
if (!pref->dontConfirmAutoExit()) {
bool exitConfirmed = false;
bool neverAskForExitConfirmationAgain = false;
ShutdownConfirmDlg::askForConfirmation(action, &exitConfirmed, &neverAskForExitConfirmationAgain);
if (neverAskForExitConfirmationAgain && exitConfirmed/*discard the request to never show again if dialog not accepted*/)
pref->setDontConfirmAutoExit(true);
if (!exitConfirmed) return;
}
if ((action == ShutdownAction::None) && (!pref->dontConfirmAutoExit())) {
if (!ShutdownConfirmDlg::askForConfirmation(action))
return;
}
else { //exit and shutdown
bool shutdownConfirmed = false;
ShutdownConfirmDlg::askForConfirmation(action, &shutdownConfirmed);
if (!shutdownConfirmed) return;
if (!ShutdownConfirmDlg::askForConfirmation(action))
return;
}
// Actually shut down

4
src/base/preferences.cpp

@ -1166,12 +1166,12 @@ void Preferences::setShutdownqBTWhenDownloadsComplete(bool shutdown) @@ -1166,12 +1166,12 @@ void Preferences::setShutdownqBTWhenDownloadsComplete(bool shutdown)
bool Preferences::dontConfirmAutoExit() const
{
return value("Preferences/Downloads/DontConfirmAutoExit", false).toBool();
return value("ShutdownConfirmDlg/DontConfirmAutoExit", false).toBool();
}
void Preferences::setDontConfirmAutoExit(bool dontConfirmAutoExit)
{
setValue("Preferences/Downloads/DontConfirmAutoExit", dontConfirmAutoExit);
setValue("ShutdownConfirmDlg/DontConfirmAutoExit", dontConfirmAutoExit);
}
uint Preferences::diskCacheSize() const

146
src/gui/confirmshutdowndlg.ui

@ -0,0 +1,146 @@ @@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>confirmShutdownDlg</class>
<widget class="QDialog" name="confirmShutdownDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>463</width>
<height>128</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>20</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="topMargin">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="warningLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">warning icon goes here</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="topMargin">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="shutdownText">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">shutdown message goes here</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="neverShowAgainCheckbox">
<property name="text">
<string>Don't show again</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox"/>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>confirmShutdownDlg</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>confirmShutdownDlg</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

1
src/gui/gui.pri

@ -103,6 +103,7 @@ FORMS += \ @@ -103,6 +103,7 @@ FORMS += \
$$PWD/bandwidth_limit.ui \
$$PWD/updownratiodlg.ui \
$$PWD/confirmdeletiondlg.ui \
$$PWD/confirmshutdowndlg.ui \
$$PWD/torrentimportdlg.ui \
$$PWD/executionlog.ui \
$$PWD/addnewtorrentdialog.ui \

58
src/gui/shutdownconfirm.cpp

@ -30,9 +30,6 @@ @@ -30,9 +30,6 @@
* Contact : hammered999@gmail.com
*/
#include "base/types.h"
#include "shutdownconfirm.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QStyle>
@ -42,43 +39,35 @@ @@ -42,43 +39,35 @@
#include <QCheckBox>
#include <QPushButton>
#include "base/preferences.h"
#include "base/types.h"
#include "shutdownconfirm.h"
#include "ui_confirmshutdowndlg.h"
ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
: m_neverShowAgain(false)
: ui(new Ui::confirmShutdownDlg)
, m_timeout(15)
, m_action(action)
{
QVBoxLayout *myLayout = new QVBoxLayout();
//Warning Icon and Text
QHBoxLayout *messageRow = new QHBoxLayout();
QLabel *warningLabel = new QLabel();
ui->setupUi(this);
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);
ui->warningLabel->setPixmap(warningIcon.pixmap(warningIcon.actualSize(QSize(32, 32))));
updateText();
QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Horizontal);
// Never show again checkbox, Title, and button
if (m_action == ShutdownAction::None) {
//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)));
setWindowTitle(tr("Exit confirmation"));
buttons->addButton(new QPushButton(tr("Exit Now")), QDialogButtonBox::AcceptRole);
ui->buttonBox->addButton(new QPushButton(tr("Exit Now"), this), QDialogButtonBox::AcceptRole);
}
else {
setWindowTitle(tr("Shutdown confirmation"));
buttons->addButton(new QPushButton(tr("Shutdown Now")), QDialogButtonBox::AcceptRole);
ui->buttonBox->addButton(new QPushButton(tr("Shutdown Now"), this), QDialogButtonBox::AcceptRole);
ui->neverShowAgainCheckbox->setVisible(false);
}
// Cancel Button
QPushButton *cancelButton = buttons->addButton(QDialogButtonBox::Cancel);
QPushButton *cancelButton = ui->buttonBox->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()));
// Always on top
setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
// Set 'Cancel' as default button.
@ -86,28 +75,20 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action) @@ -86,28 +75,20 @@ ShutdownConfirmDlg::ShutdownConfirmDlg(const ShutdownAction &action)
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
// Move to center
move(Utils::Misc::screenCenter(this));
setLayout(myLayout);
cancelButton->setFocus();
}
bool ShutdownConfirmDlg::neverShowAgain() const
{
return m_neverShowAgain;
}
void ShutdownConfirmDlg::showEvent(QShowEvent *event)
{
QDialog::showEvent(event);
m_timer.start();
}
void ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action, bool *shutdownConfirmed, bool *neverShowAgain)
bool ShutdownConfirmDlg::askForConfirmation(const ShutdownAction &action)
{
ShutdownConfirmDlg dlg(action);
dlg.exec();
*shutdownConfirmed = dlg.shutdown();
if (neverShowAgain)
*neverShowAgain = dlg.neverShowAgain();
return dlg.shutdown();
}
void ShutdownConfirmDlg::updateSeconds()
@ -120,9 +101,10 @@ void ShutdownConfirmDlg::updateSeconds() @@ -120,9 +101,10 @@ void ShutdownConfirmDlg::updateSeconds()
}
}
void ShutdownConfirmDlg::handleNeverShowAgainCheckboxToggled(bool checked)
void ShutdownConfirmDlg::accept()
{
m_neverShowAgain = checked;
Preferences::instance()->setDontConfirmAutoExit(ui->neverShowAgainCheckbox->isChecked());
QDialog::accept();
}
bool ShutdownConfirmDlg::shutdown() const
@ -149,5 +131,5 @@ void ShutdownConfirmDlg::updateText() @@ -149,5 +131,5 @@ void ShutdownConfirmDlg::updateText()
break;
}
m_text->setText(text);
ui->shutdownText->setText(text);
}

14
src/gui/shutdownconfirm.h

@ -36,6 +36,12 @@ @@ -36,6 +36,12 @@
#include "base/utils/misc.h"
class QLabel;
class QCheckBox;
namespace Ui
{
class confirmShutdownDlg;
}
class ShutdownConfirmDlg : public QDialog
{
@ -43,25 +49,23 @@ class ShutdownConfirmDlg : public QDialog @@ -43,25 +49,23 @@ class ShutdownConfirmDlg : public QDialog
public:
ShutdownConfirmDlg(const ShutdownAction &action);
bool neverShowAgain() const;
bool shutdown() const;
static void askForConfirmation(const ShutdownAction &action, bool *shutdownConfirmed, bool *neverShowAgain = 0);
static bool askForConfirmation(const ShutdownAction &action);
protected:
void showEvent(QShowEvent *event);
private slots:
void updateSeconds();
void handleNeverShowAgainCheckboxToggled(bool checked);
void accept() override;
private:
// Methods
void updateText();
// Vars
QLabel *m_text;
bool m_neverShowAgain;
Ui::confirmShutdownDlg *ui;
QTimer m_timer;
int m_timeout;
ShutdownAction m_action;

Loading…
Cancel
Save