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()
Preferences *const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
bool will_shutdown = (pref->shutdownWhenDownloadsComplete() bool will_shutdown = (pref->shutdownWhenDownloadsComplete()
|| pref->shutdownqBTWhenDownloadsComplete()
|| pref->suspendWhenDownloadsComplete() || pref->suspendWhenDownloadsComplete()
|| pref->hibernateWhenDownloadsComplete()); || pref->hibernateWhenDownloadsComplete());
bool will_exit_only = pref->shutdownqBTWhenDownloadsComplete();
// Auto-Shutdown // Auto-Shutdown
if (will_exit_only || will_shutdown) { if (will_shutdown) {
bool suspend = pref->suspendWhenDownloadsComplete(); bool suspend = pref->suspendWhenDownloadsComplete();
bool hibernate = pref->hibernateWhenDownloadsComplete(); bool hibernate = pref->hibernateWhenDownloadsComplete();
bool shutdown = pref->shutdownWhenDownloadsComplete(); bool shutdown = pref->shutdownWhenDownloadsComplete();
@ -306,20 +306,13 @@ void Application::allTorrentsFinished()
else if (shutdown) else if (shutdown)
action = ShutdownAction::Shutdown; action = ShutdownAction::Shutdown;
if (will_exit_only) { if ((action == ShutdownAction::None) && (!pref->dontConfirmAutoExit())) {
if (!pref->dontConfirmAutoExit()) { if (!ShutdownConfirmDlg::askForConfirmation(action))
bool exitConfirmed = false; return;
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;
}
} }
else { //exit and shutdown else { //exit and shutdown
bool shutdownConfirmed = false; if (!ShutdownConfirmDlg::askForConfirmation(action))
ShutdownConfirmDlg::askForConfirmation(action, &shutdownConfirmed); return;
if (!shutdownConfirmed) return;
} }
// Actually shut down // Actually shut down

4
src/base/preferences.cpp

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

146
src/gui/confirmshutdowndlg.ui

@ -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 += \
$$PWD/bandwidth_limit.ui \ $$PWD/bandwidth_limit.ui \
$$PWD/updownratiodlg.ui \ $$PWD/updownratiodlg.ui \
$$PWD/confirmdeletiondlg.ui \ $$PWD/confirmdeletiondlg.ui \
$$PWD/confirmshutdowndlg.ui \
$$PWD/torrentimportdlg.ui \ $$PWD/torrentimportdlg.ui \
$$PWD/executionlog.ui \ $$PWD/executionlog.ui \
$$PWD/addnewtorrentdialog.ui \ $$PWD/addnewtorrentdialog.ui \

58
src/gui/shutdownconfirm.cpp

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

14
src/gui/shutdownconfirm.h

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

Loading…
Cancel
Save