Do not change auto save action visibility and title when auto save task failed to be spawned.

"Auto save output as" still became "Stop Autosave" when cancelling in file dialog.

Make SessionTask::execute return value that indicates the task has been spawned
successfully or not. So SessionController::autoSaveHistory could decide whether
to change the visibility of _startAutoSaveAction and _stopAutoSaveAction.

BUG: 507069
This commit is contained in:
Jack Xu
2025-07-16 02:33:31 +00:00
parent c74dc5156f
commit 95c324615e
8 changed files with 28 additions and 19 deletions

View File

@@ -36,7 +36,7 @@ SaveHistoryAutoTask::SaveHistoryAutoTask(QObject *parent)
SaveHistoryAutoTask::~SaveHistoryAutoTask() = default;
void SaveHistoryAutoTask::execute()
bool SaveHistoryAutoTask::execute()
{
QFileDialog *dialog = new QFileDialog(QApplication::activeWindow());
dialog->setAcceptMode(QFileDialog::AcceptSave);
@@ -65,7 +65,7 @@ void SaveHistoryAutoTask::execute()
int result = dialog->exec();
if (result != QDialog::Accepted) {
return;
return false;
}
QUrl url = (dialog->selectedUrls()).at(0);
@@ -73,7 +73,7 @@ void SaveHistoryAutoTask::execute()
if (!url.isValid()) {
// UI: Can we make this friendlier?
KMessageBox::error(nullptr, i18n("%1 is an invalid URL, the output could not be saved.", url.url()));
return;
return false;
}
// Save selected URL for next time
@@ -86,7 +86,7 @@ void SaveHistoryAutoTask::execute()
if (!_destinationFile.open(QFile::ReadWrite)) {
KMessageBox::error(nullptr, i18n("Failed to create autosave file at %1.", url.url()));
return;
return false;
}
_watcher.addPath(path);
@@ -107,6 +107,7 @@ void SaveHistoryAutoTask::execute()
readLines();
dialog->deleteLater();
return true;
}
void SaveHistoryAutoTask::fileModified()

View File

@@ -36,7 +36,7 @@ public:
*
* The data transfer is performed asynchronously and will continue after execute() returns.
*/
void execute() override;
bool execute() override;
public Q_SLOTS:
// Stops the autosave process.

View File

@@ -37,7 +37,7 @@ SaveHistoryTask::SaveHistoryTask(QObject *parent)
SaveHistoryTask::~SaveHistoryTask() = default;
void SaveHistoryTask::execute()
bool SaveHistoryTask::execute()
{
// TODO - think about the UI when saving multiple history sessions, if there are more than two or
// three then providing a URL for each one will be tedious
@@ -134,6 +134,7 @@ void SaveHistoryTask::execute()
}
dialog->deleteLater();
return true;
}
void SaveHistoryTask::jobDataRequested(KIO::Job *job, QByteArray &data)

View File

@@ -36,7 +36,7 @@ public:
*
* The data transfer is performed asynchronously and will continue after execute() returns.
*/
void execute() override;
bool execute() override;
private Q_SLOTS:
void jobDataRequested(KIO::Job *job, QByteArray &data);

View File

@@ -20,7 +20,7 @@ void SearchHistoryTask::addScreenWindow(Session *session, ScreenWindow *searchWi
_windows.insert(session, searchWindow);
}
void SearchHistoryTask::execute()
bool SearchHistoryTask::execute()
{
auto iter = QMapIterator<QPointer<Session>, ScreenWindowPtr>(_windows);
@@ -32,6 +32,7 @@ void SearchHistoryTask::execute()
if (autoDelete()) {
deleteLater();
}
return true;
}
void SearchHistoryTask::executeOnScreenWindow(const QPointer<Session> &session, const ScreenWindowPtr &window)

View File

@@ -76,7 +76,7 @@ public:
*
* To continue the search looking for further matches, call execute() again.
*/
void execute() override;
bool execute() override;
private:
using ScreenWindowPtr = QPointer<ScreenWindow>;

View File

@@ -1816,17 +1816,22 @@ void SessionController::autoSaveHistory()
_autoSaveTask = new SaveHistoryAutoTask(this);
_autoSaveTask->setAutoDelete(true);
_autoSaveTask->addSession(session());
_autoSaveTask->execute();
auto success = _autoSaveTask->execute();
// Only show the button to start autosave when autosave is not ongoing.
// Only show the button to stop autosave when auytosave is ongoing.
connect(_autoSaveTask, &SaveHistoryAutoTask::completed, this, [&]() {
_startAutoSaveAction->setVisible(true);
_stopAutoSaveAction->setVisible(false);
});
if (success) {
// Only show the button to start autosave when autosave is not ongoing.
// Only show the button to stop autosave when autosave is ongoing.
connect(_autoSaveTask, &SaveHistoryAutoTask::completed, this, [&]() {
_startAutoSaveAction->setVisible(true);
_stopAutoSaveAction->setVisible(false);
});
_startAutoSaveAction->setVisible(false);
_stopAutoSaveAction->setVisible(true);
_startAutoSaveAction->setVisible(false);
_stopAutoSaveAction->setVisible(true);
} else {
// Reset to avoid snapshot changing title.
_autoSaveTask->stop();
}
}
void SessionController::stopAutoSaveHistory()

View File

@@ -46,10 +46,11 @@ public:
/**
* Executes the task on each of the sessions in the group.
* Returns true if the task has been spawned successfully.
* The completed() signal is emitted when the task is finished, depending on the specific sub-class
* execute() may be synchronous or asynchronous
*/
virtual void execute() = 0;
virtual bool execute() = 0;
Q_SIGNALS:
/**