Fix and improve behavior of the Cancel/Close actions
This commit is contained in:
parent
99e722276e
commit
5221075768
|
@ -256,20 +256,13 @@ void GmicProcessor::cancel()
|
|||
abortCurrentFilterThread();
|
||||
}
|
||||
|
||||
void GmicProcessor::detachAllThreads()
|
||||
void GmicProcessor::detachAllUnfinishedAbortedThreads()
|
||||
{
|
||||
if (_filterThread) {
|
||||
_filterThread->disconnect(this);
|
||||
_filterThread->setParent(nullptr);
|
||||
_filterThread = nullptr;
|
||||
}
|
||||
for (FilterThread * thread : _unfinishedAbortedThreads) {
|
||||
thread->disconnect(this);
|
||||
thread->setParent(nullptr);
|
||||
}
|
||||
_unfinishedAbortedThreads.clear();
|
||||
_waitingCursorTimer.stop();
|
||||
OverrideCursor::setWaiting(false);
|
||||
}
|
||||
|
||||
void GmicProcessor::terminateAllThreads()
|
||||
|
|
|
@ -111,7 +111,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void cancel();
|
||||
void detachAllThreads();
|
||||
void detachAllUnfinishedAbortedThreads();
|
||||
void terminateAllThreads();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -104,9 +104,9 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent), ui(new Ui::MainW
|
|||
tsp.append(QString("/usr/share/icons/gnome"));
|
||||
QIcon::setThemeSearchPaths(tsp);
|
||||
|
||||
_filterUpdateWidgets = {ui->previewWidget, ui->zoomLevelSelector, ui->filtersView, ui->filterParams, ui->tbUpdateFilters, ui->pbFullscreen, ui->pbSettings,
|
||||
ui->pbOk, ui->pbApply, ui->tbResetParameters, ui->tbCopyCommand, ui->searchField, ui->cbPreview, ui->tbAddFave,
|
||||
ui->tbRemoveFave, ui->tbRenameFave, ui->tbExpandCollapse, ui->tbSelectionMode};
|
||||
_filterUpdateWidgets = {ui->previewWidget, ui->zoomLevelSelector, ui->filtersView, ui->filterParams, ui->tbUpdateFilters, ui->pbFullscreen, ui->pbSettings,
|
||||
ui->pbOk, ui->pbApply, ui->pbClose, ui->tbResetParameters, ui->tbCopyCommand, ui->searchField, ui->cbPreview,
|
||||
ui->tbAddFave, ui->tbRemoveFave, ui->tbRenameFave, ui->tbExpandCollapse, ui->tbSelectionMode};
|
||||
|
||||
ui->tbAddFave->setToolTip(tr("Add fave"));
|
||||
|
||||
|
@ -236,6 +236,8 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent), ui(new Ui::MainW
|
|||
|
||||
_forceQuitText = tr("Force &quit");
|
||||
|
||||
ui->pbCancel->setEnabled(false);
|
||||
|
||||
makeConnections();
|
||||
}
|
||||
|
||||
|
@ -259,7 +261,8 @@ void MainWindow::setIcons()
|
|||
ui->pbOk->setIcon(LOAD_ICON("insert-image"));
|
||||
ui->tbResetParameters->setIcon(LOAD_ICON("view-refresh"));
|
||||
ui->tbCopyCommand->setIcon(LOAD_ICON("edit-copy"));
|
||||
ui->pbCancel->setIcon(LOAD_ICON("process-stop"));
|
||||
ui->pbClose->setIcon(LOAD_ICON("close"));
|
||||
ui->pbCancel->setIcon(LOAD_ICON("cancel"));
|
||||
ui->tbAddFave->setIcon(LOAD_ICON("bookmark-add"));
|
||||
ui->tbRemoveFave->setIcon(LOAD_ICON("bookmark-remove"));
|
||||
ui->tbSelectionMode->setIcon(LOAD_ICON("selection_mode"));
|
||||
|
@ -572,7 +575,7 @@ void MainWindow::onEscapeKeyPressed()
|
|||
ui->searchField->clear();
|
||||
if (_processor.isProcessing()) {
|
||||
if (_processor.isProcessingFullImage()) {
|
||||
ui->progressInfoWidget->onCancelClicked();
|
||||
ui->progressInfoWidget->cancel();
|
||||
} else {
|
||||
_processor.cancel();
|
||||
ui->previewWidget->displayOriginalImage();
|
||||
|
@ -644,6 +647,7 @@ void MainWindow::makeConnections()
|
|||
connect(_filtersPresenter, &FiltersPresenter::filterSelectionChanged, this, &MainWindow::onFilterSelectionChanged);
|
||||
connect(ui->pbOk, &QPushButton::clicked, this, &MainWindow::onOkClicked);
|
||||
connect(ui->pbCancel, &QPushButton::clicked, this, &MainWindow::onCancelClicked);
|
||||
connect(ui->pbClose, &QPushButton::clicked, this, &MainWindow::close);
|
||||
connect(ui->pbApply, &QPushButton::clicked, this, &MainWindow::onApplyClicked);
|
||||
connect(ui->tbResetParameters, &QToolButton::clicked, this, &MainWindow::onReset);
|
||||
connect(ui->tbCopyCommand, &QToolButton::clicked, this, &MainWindow::onCopyGMICCommand);
|
||||
|
@ -664,7 +668,8 @@ void MainWindow::makeConnections()
|
|||
connect(ui->cbPreview, &QCheckBox::toggled, this, &MainWindow::onPreviewCheckBoxToggled);
|
||||
connect(ui->searchField, &SearchFieldWidget::textChanged, this, &MainWindow::search);
|
||||
connect(ui->tbExpandCollapse, &QToolButton::clicked, this, &MainWindow::expandOrCollapseFolders);
|
||||
connect(ui->progressInfoWidget, &ProgressInfoWidget::cancel, this, &MainWindow::onProgressionWidgetCancelClicked);
|
||||
connect(ui->pbCancel, &QPushButton::clicked, this, &MainWindow::onCancelClicked);
|
||||
connect(ui->progressInfoWidget, &ProgressInfoWidget::canceled, this, &MainWindow::onProgressionWidgetCancelClicked);
|
||||
connect(ui->tbSelectionMode, &QToolButton::toggled, this, &MainWindow::onFiltersSelectionModeToggled);
|
||||
connect(&_processor, &GmicProcessor::previewImageAvailable, this, &MainWindow::onPreviewImageAvailable);
|
||||
connect(&_processor, &GmicProcessor::previewCommandFailed, this, &MainWindow::onPreviewError);
|
||||
|
@ -792,8 +797,9 @@ void MainWindow::processImage()
|
|||
return;
|
||||
}
|
||||
|
||||
ui->progressInfoWidget->startFilterThreadAnimationAndShow(true);
|
||||
ui->progressInfoWidget->startFilterThreadAnimationAndShow();
|
||||
enableWidgetList(false);
|
||||
ui->pbCancel->setEnabled(true);
|
||||
|
||||
GmicProcessor::FilterContext context;
|
||||
context.requestType = GmicProcessor::FilterContext::RequestType::FullImage;
|
||||
|
@ -818,6 +824,7 @@ void MainWindow::onFullImageProcessingError(const QString & message)
|
|||
ui->progressInfoWidget->stopAnimationAndHide();
|
||||
QMessageBox::warning(this, tr("Error"), message, QMessageBox::Close);
|
||||
enableWidgetList(true);
|
||||
ui->pbCancel->setEnabled(false);
|
||||
if ((_pendingActionAfterCurrentProcessing == ProcessingAction::Ok) || (_pendingActionAfterCurrentProcessing == ProcessingAction::Close)) {
|
||||
close();
|
||||
}
|
||||
|
@ -869,6 +876,7 @@ void MainWindow::onFullImageProcessingDone()
|
|||
{
|
||||
ui->progressInfoWidget->stopAnimationAndHide();
|
||||
enableWidgetList(true);
|
||||
ui->pbCancel->setEnabled(false);
|
||||
ui->previewWidget->update();
|
||||
ui->filterParams->setValues(_processor.gmicStatus(), false);
|
||||
ui->filterParams->setVisibilityStates(_processor.parametersVisibilityStates());
|
||||
|
@ -931,21 +939,6 @@ void MainWindow::onOkClicked()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::onProgressionWidgetCancelClicked()
|
||||
{
|
||||
if (ui->progressInfoWidget->mode() == ProgressInfoWidget::Mode::GmicProcessing) {
|
||||
if (_processor.isProcessing()) {
|
||||
_pendingActionAfterCurrentProcessing = ProcessingAction::NoAction;
|
||||
_processor.cancel();
|
||||
ui->progressInfoWidget->stopAnimationAndHide();
|
||||
enableWidgetList(true);
|
||||
}
|
||||
}
|
||||
if (ui->progressInfoWidget->mode() == ProgressInfoWidget::Mode::FiltersUpdate) {
|
||||
Updater::getInstance()->cancelAllPendingDownloads();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onReset()
|
||||
{
|
||||
if (!_filtersPresenter->currentFilter().hash.isEmpty() && _filtersPresenter->currentFilter().isAFave) {
|
||||
|
@ -1419,6 +1412,13 @@ void MainWindow::enableWidgetList(bool on)
|
|||
ui->inOutSelector->setEnabled(on);
|
||||
}
|
||||
|
||||
void MainWindow::onProgressionWidgetCancelClicked()
|
||||
{
|
||||
if (ui->progressInfoWidget->mode() == ProgressInfoWidget::Mode::FiltersUpdate) {
|
||||
Updater::getInstance()->cancelAllPendingDownloads();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::abortProcessingOnCloseRequest()
|
||||
{
|
||||
_pendingActionAfterCurrentProcessing = ProcessingAction::Close;
|
||||
|
@ -1426,34 +1426,41 @@ void MainWindow::abortProcessingOnCloseRequest()
|
|||
ui->progressInfoWidget->showBusyIndicator();
|
||||
ui->previewWidget->setOverlayMessage(tr("Waiting for cancelled jobs..."));
|
||||
enableWidgetList(false);
|
||||
ui->pbCancel->setEnabled(true);
|
||||
ui->pbCancel->setText(_forceQuitText);
|
||||
_processor.detachAllThreads(); // Keep only one thread in list after next line
|
||||
ui->pbCancel->setEnabled(false);
|
||||
ui->pbClose->setEnabled(false);
|
||||
|
||||
QTimer::singleShot(2000, [this]() {
|
||||
_pendingActionAfterCurrentProcessing = ProcessingAction::ForceQuit;
|
||||
ui->pbClose->setText(_forceQuitText);
|
||||
ui->pbClose->setEnabled(true);
|
||||
});
|
||||
|
||||
_processor.detachAllUnfinishedAbortedThreads(); // Keep only one thread in list after next line
|
||||
_processor.cancel();
|
||||
}
|
||||
|
||||
void MainWindow::onCancelClicked()
|
||||
{
|
||||
close();
|
||||
ui->progressInfoWidget->cancel();
|
||||
if (_processor.isProcessing()) {
|
||||
_pendingActionAfterCurrentProcessing = ProcessingAction::NoAction;
|
||||
_processor.cancel();
|
||||
ui->progressInfoWidget->stopAnimationAndHide();
|
||||
enableWidgetList(true);
|
||||
ui->pbCancel->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent * e)
|
||||
{
|
||||
if (_pendingActionAfterCurrentProcessing == ProcessingAction::ForceQuit) {
|
||||
_processor.disconnect(this);
|
||||
_processor.detachAllThreads();
|
||||
_processor.cancel();
|
||||
_processor.detachAllUnfinishedAbortedThreads();
|
||||
e->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_processor.hasUnfinishedAbortedThreads() && (ui->pbCancel->text() == _forceQuitText)) {
|
||||
ui->pbCancel->setEnabled(false);
|
||||
_pendingActionAfterCurrentProcessing = ProcessingAction::ForceQuit;
|
||||
QTimer::singleShot(2000, this, &MainWindow::close);
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_processor.isProcessing() && (_pendingActionAfterCurrentProcessing != ProcessingAction::Close)) {
|
||||
if (confirmAbortProcessingOnCloseRequest()) {
|
||||
abortProcessingOnCloseRequest();
|
||||
|
|
|
@ -77,6 +77,7 @@ public:
|
|||
public slots:
|
||||
void onUpdateDownloadsFinished(int status);
|
||||
void onApplyClicked();
|
||||
void onProgressionWidgetCancelClicked();
|
||||
void onPreviewUpdateRequested(bool synchronous);
|
||||
void onPreviewUpdateRequested();
|
||||
void onPreviewKeypointsEvent(unsigned int flags, unsigned long time);
|
||||
|
@ -85,7 +86,6 @@ public slots:
|
|||
void search(const QString &);
|
||||
void onOkClicked();
|
||||
void onCancelClicked();
|
||||
void onProgressionWidgetCancelClicked();
|
||||
void onReset();
|
||||
void onCopyGMICCommand();
|
||||
void onPreviewZoomReset();
|
||||
|
|
|
@ -48,10 +48,10 @@ ProgressInfoWidget::ProgressInfoWidget(QWidget * parent) : QWidget(parent), ui(n
|
|||
_growing = true;
|
||||
setWindowTitle(tr("G'MIC-Qt Plug-in progression"));
|
||||
ui->progressBar->setRange(0, 100);
|
||||
ui->tbCancel->setIcon(LOAD_ICON("process-stop"));
|
||||
ui->tbCancel->setIcon(LOAD_ICON("cancel"));
|
||||
ui->tbCancel->setToolTip(tr("Abort"));
|
||||
connect(&_timer, &QTimer::timeout, this, &ProgressInfoWidget::onTimeOut);
|
||||
connect(ui->tbCancel, &QToolButton::clicked, this, &ProgressInfoWidget::onCancelClicked);
|
||||
connect(ui->tbCancel, &QToolButton::clicked, this, &ProgressInfoWidget::cancel);
|
||||
if (!parent) {
|
||||
QRect position = frameGeometry();
|
||||
QList<QScreen *> screens = QGuiApplication::screens();
|
||||
|
@ -97,10 +97,10 @@ void ProgressInfoWidget::onTimeOut()
|
|||
}
|
||||
}
|
||||
|
||||
void ProgressInfoWidget::onCancelClicked()
|
||||
void ProgressInfoWidget::cancel()
|
||||
{
|
||||
_canceled = true;
|
||||
emit cancel();
|
||||
emit canceled();
|
||||
}
|
||||
|
||||
void ProgressInfoWidget::stopAnimationAndHide()
|
||||
|
@ -110,14 +110,14 @@ void ProgressInfoWidget::stopAnimationAndHide()
|
|||
hide();
|
||||
}
|
||||
|
||||
void ProgressInfoWidget::startFilterThreadAnimationAndShow(bool showCancelButton)
|
||||
void ProgressInfoWidget::startFilterThreadAnimationAndShow()
|
||||
{
|
||||
layout()->removeWidget(ui->tbCancel);
|
||||
layout()->removeWidget(ui->progressBar);
|
||||
layout()->removeWidget(ui->label);
|
||||
layout()->addWidget(ui->progressBar);
|
||||
layout()->addWidget(ui->tbCancel);
|
||||
layout()->addWidget(ui->label);
|
||||
ui->tbCancel->hide();
|
||||
|
||||
_canceled = false;
|
||||
_mode = Mode::GmicProcessing;
|
||||
|
@ -127,7 +127,6 @@ void ProgressInfoWidget::startFilterThreadAnimationAndShow(bool showCancelButton
|
|||
onTimeOut();
|
||||
_timer.setInterval(250);
|
||||
_timer.start();
|
||||
ui->tbCancel->setVisible(showCancelButton);
|
||||
show();
|
||||
}
|
||||
|
||||
|
|
|
@ -55,14 +55,14 @@ public:
|
|||
void setGmicProcessor(const GmicProcessor * processor);
|
||||
|
||||
public slots:
|
||||
void cancel();
|
||||
void onTimeOut();
|
||||
void onCancelClicked();
|
||||
void stopAnimationAndHide();
|
||||
void startFilterThreadAnimationAndShow(bool showCancelButton);
|
||||
void startFilterThreadAnimationAndShow();
|
||||
void startFiltersUpdateAnimationAndShow();
|
||||
void showBusyIndicator();
|
||||
signals:
|
||||
void cancel();
|
||||
void canceled();
|
||||
|
||||
private:
|
||||
void updateThreadInformation();
|
||||
|
|
Loading…
Reference in New Issue