Enable AutoErrorHandling for rename job
ClosedPublic

Authored by muhlenpfordt on Jun 27 2018, 10:38 AM.

Details

Summary

If a rename job started from View Mode fails, no warning message is
shown. This is caused by the default disabled AutoErrorHandling in
KJobUiDelegate.
This patch enables the flag after creating the job.

BUG: 395890
FIXED-IN: 18.04.3

Test Plan
  1. Open Gwenview in View Mode
  2. Try to rename image to already existing filename
  3. An error message should be displayed

Diff Detail

Repository
R260 Gwenview
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
muhlenpfordt requested review of this revision.Jun 27 2018, 10:38 AM
muhlenpfordt created this revision.

An extended error message (e.g. with Overwrite option) for Browse Mode needs a bit of rework, since the renaming is done by the model (not Gwenview) here.

Remove showErrorMessage() call

muhlenpfordt added inline comments.Jun 27 2018, 11:01 AM
app/fileoperations.cpp
249

Calling showErrorMessage() outside a result slot is not recommended and not needed anymore.

rkflx accepted this revision.Jun 27 2018, 10:39 PM
rkflx added a subscriber: rkflx.

Thanks, LGTM.

I also added some comments to https://bugs.kde.org/show_bug.cgi?id=395890#c4. Keep in mind I did not know yet about your Diff when I wrote them, but apparently you came up with the same fix ;) I'd say let's land your patch to stable, and we can see about further improvements in master.

The only thing I'm not sure about is showErrorMessage(): Why did it work in KDE 4, but does not work anymore? Your new code is fine, but maybe we also have a problem in KF5, which obviously we should try to fix (or we might run into it again and again… – e.g. did you check GVPart::showJobError?).

This revision is now accepted and ready to land.Jun 27 2018, 10:39 PM

The only thing I'm not sure about is showErrorMessage(): Why did it work in KDE 4, but does not work anymore? Your new code is fine, but maybe we also have a problem in KF5, which obviously we should try to fix (or we might run into it again and again… – e.g. did you check GVPart::showJobError?).

I think it just works like stated in the api docu now and the previous use was incorrect (but worked nevertheless). Calling showErrorMessage() from inside a result slot is ok and the error message shows up, e.g. using this code instead of enabling AutoErrorHandling works too:

KIO::SimpleJob* job = KIO::rename(oldUrl, newUrl, KIO::HideProgressInfo);
QObject::connect(job, &KJob::result, [=](KJob* job) {
    job->uiDelegate()->showErrorMessage();
});

(GVPart::saveAs() / GVPart::showJobError should work fine but no idea how to test this.)

rkflx added a comment.Jun 28 2018, 9:55 AM
KIO::SimpleJob* job = KIO::rename(oldUrl, newUrl, KIO::HideProgressInfo);
QObject::connect(job, &KJob::result, [=](KJob* job) {
    job->uiDelegate()->showErrorMessage();
});

Okay, at least it's still working in that case. Thanks for the sample code ;)

The following change in R288 KJobWidgets makes it work for me, so this seems to be related to event handling:

@@ -102,7 +104,7 @@ void KDialogJobUiDelegate::Private::queuedMessageBox(QWidget *widget, KMessageBo
 
     if (!running) {
         running = true;
-        QMetaObject::invokeMethod(this, "next", Qt::QueuedConnection);
+        next();
     }
 }

Looks like some of the porting work to KF5 caused this: efbf655b7ab5. Anyway, probably better to keep this as is.


(GVPart::saveAs() / GVPart::showJobError should work fine but no idea how to test this.)

You are right, I could now confirm it works fine: Using Gwenview's KPart, Save As in Konqueror to a read-only directory and compare w/ and w/o the call to showErrorMessage (the rename case is already caught by the file dialog).

The following change in R288 KJobWidgets makes it work for me, so this seems to be related to event handling:

@@ -102,7 +104,7 @@ void KDialogJobUiDelegate::Private::queuedMessageBox(QWidget *widget, KMessageBo
 
     if (!running) {
         running = true;
-        QMetaObject::invokeMethod(this, "next", Qt::QueuedConnection);
+        next();
     }
 }

Looks like some of the porting work to KF5 caused this: efbf655b7ab5. Anyway, probably better to keep this as is.

BTW, this also works:

job->uiDelegate()->showErrorMessage();
qApp->processEvents();

(Might be useful in cases where setAutoErrorHandlingEnabled(true) is inappropriate.)

This revision was automatically updated to reflect the committed changes.