Add KIO::DropJobFlag to allow manually showing the menu
ClosedPublic

Authored by trmdi on Jan 7 2020, 7:42 AM.

Details

Summary

This patch allows the application to manually popup the menu by using the KIO::ShowMenuManually flag with the DropJob::showMenu() method.

BUG: 415917

Test Plan

Can't reproduce the bug with this patch.

Diff Detail

Repository
R241 KIO
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 21021
Build 21039: arc lint + arc unit
There are a very large number of changes, so older changes are hidden. Show Older Changes
trmdi planned changes to this revision.Jan 7 2020, 9:11 AM
trmdi updated this revision to Diff 72975.Jan 7 2020, 1:32 PM
  • Use signal instead of timer
trmdi retitled this revision from Delay 100ms before showing the menu to Add a new parameter for delaying showing menu.Jan 7 2020, 1:38 PM
trmdi edited the summary of this revision. (Show Details)
trmdi edited the summary of this revision. (Show Details)Jan 7 2020, 3:13 PM
trmdi edited the summary of this revision. (Show Details)Jan 7 2020, 3:36 PM
anthonyfieroni added inline comments.
src/widgets/dropjob.h
149

Do not change signature of exported function, just add another one.

trmdi updated this revision to Diff 73030.Jan 8 2020, 7:26 AM
  • Add a new function instead of changing the old exported one
trmdi marked an inline comment as done.Jan 8 2020, 7:27 AM
broulik added a subscriber: broulik.Jan 8 2020, 3:19 PM

I don't fully understand why popupMenuAboutToShow isn't sufficient.
An alternative approach I could think would be allowing the signal handler to delay the menu as necessary rather than having to create the drop job differently?

src/widgets/dropjob.h
151

bool arguments are generally frowned upon. Perhaps introduce a flag instead.

trmdi updated this revision to Diff 73076.Jan 8 2020, 5:00 PM
  • Move delayPopup to JobFlag
trmdi marked an inline comment as done.Jan 8 2020, 5:00 PM
trmdi edited the summary of this revision. (Show Details)Jan 8 2020, 5:17 PM
trmdi planned changes to this revision.Jan 9 2020, 2:52 AM
trmdi updated this revision to Diff 73112.Jan 9 2020, 4:03 AM
  • Remove the new signal and show a "Fetching data" menu while delaying
trmdi updated this revision to Diff 73113.Jan 9 2020, 4:38 AM
  • Improve code
trmdi updated this revision to Diff 73114.EditedJan 9 2020, 4:45 AM
  • Improve code
trmdi planned changes to this revision.Jan 9 2020, 5:44 PM
trmdi updated this revision to Diff 73175.Jan 10 2020, 3:33 AM
  • Simplify the approach
trmdi edited the summary of this revision. (Show Details)Jan 10 2020, 3:35 AM
trmdi retitled this revision from Add a new parameter for delaying showing menu to Popup menu again to reposition it.Jan 10 2020, 3:37 AM
trmdi added a comment.EditedJan 10 2020, 5:34 PM

@mart @dfaure

I have some questions.
1, Should DropJob::setApplicationActions() be called only one time?
2, I see this when I drop multiple file types at once to the desktop (e.g. 2 jpg and 1 zip), the DropJob::setApplicationActions() is called 3 times as follow:

Mimetype Job returns. "image/jpeg"
Received a suitable dropEvent at QPoint(1199,237)
Creating menu for: "image/jpeg" QPoint(1199,237)

Mimetype Job returns. "application/zip"
Received a suitable dropEvent at QPoint(1199,237)
Creating menu for: "application/zip" QPoint(1199,237)

Mimetype Job returns. "image/jpeg"
Received a suitable dropEvent at QPoint(1199,237)
Creating menu for: "image/jpeg" QPoint(1199,237)

But finally only the last one's appActions are added to the menu (the others are overwritten). This is a bit weird.
I want to understand your intention to make this patch as good as possible.

dfaure requested changes to this revision.Jan 11 2020, 9:20 AM

Sorry I have no idea about the calling side in plasma. It sounds buggy indeed, if those are all calls on the same DropJob instance.

src/widgets/dropjob.cpp
411

The m_ prefix is for member variables. Don't use it for a local stack variable.

414

Doesn't this flicker?

This revision now requires changes to proceed.Jan 11 2020, 9:20 AM

Sorry I have no idea about the calling side in plasma. It sounds buggy indeed, if those are all calls on the same DropJob instance.

Yes, you could check it here: https://phabricator.kde.org/source/plasma-framework/browse/master/src/scriptengines/qml/plasmoid/containmentinterface.cpp
So do you mean this should be fixed to call DropJob::setApplicationActions() only one time?

And do you @mart agree with that?

src/widgets/dropjob.cpp
415

QCursor::pos() should be avoided as it's not reliable on wayland.

The whole "popup() again" here looks like a workaround to me. Can't this be fixed on the plasma side?

trmdi added inline comments.Jan 11 2020, 12:45 PM
src/widgets/dropjob.cpp
415

I'm having a plan to make it popup only one time.

QCursor::pos() should be avoided as it's not reliable on wayland.

this is how it does currently, I just copy the original code. This could need to be resolved in another patch.

trmdi added inline comments.Jan 11 2020, 12:51 PM
src/widgets/dropjob.cpp
415

Can't this be fixed on the plasma side?

I think it can't, because KIO::DropJob popup the menu, only afterward Plasma adds new items into it.

trmdi updated this revision to Diff 73273.Jan 11 2020, 2:00 PM
  • use the flag approach and add DropJob::menuPopup()
trmdi retitled this revision from Popup menu again to reposition it to Add KIO::DelayPopup flag and DropJob::menuPopup().Jan 11 2020, 2:04 PM
trmdi edited the summary of this revision. (Show Details)
trmdi marked 5 inline comments as done.
dfaure requested changes to this revision.Jan 11 2020, 9:11 PM

I agree with the approach. Just naming needs to be improved.

I'd call the method "showMenu" or "showPopup".
DelayPopup hints at a builtin timer, better call it something like DontShowPopup (even though some people don't like negative flags). ManualShowPopup? ExplicitShowPopup?
And it shouldn't be in the job_base.h enum, which can be used by all jobs.
Better add something to DropJob specifically.

The new method also needs docu including @since.

Thanks!

src/widgets/dropjob.cpp
418

This '{' goes on its own line.

This revision now requires changes to proceed.Jan 11 2020, 9:11 PM
trmdi updated this revision to Diff 73337.Jan 12 2020, 2:56 PM
  • Move the flag to DropJob header, rename
trmdi retitled this revision from Add KIO::DelayPopup flag and DropJob::menuPopup() to Add KIO::DropJobFlag flag and DropJob::menuPopup().Jan 12 2020, 2:57 PM
trmdi retitled this revision from Add KIO::DropJobFlag flag and DropJob::menuPopup() to Add KIO::DropJobFlag to allow manually showing the menu.
trmdi edited the summary of this revision. (Show Details)Jan 12 2020, 3:03 PM
dfaure requested changes to this revision.Jan 12 2020, 7:43 PM

Almost there.

Please add @since 5.67 to the new enum and the new methods.

src/widgets/dropjob.cpp
418

Not fixed.

src/widgets/dropjob.h
147 ↗(On Diff #73337)

Please document this method (copy/pasting is OK)

And add @since 5.67

This revision now requires changes to proceed.Jan 12 2020, 7:43 PM
trmdi updated this revision to Diff 73363.Jan 13 2020, 4:40 AM
  • Improve comment/doc
trmdi marked 3 inline comments as done.Jan 13 2020, 4:42 AM
dfaure accepted this revision.Jan 13 2020, 8:39 AM

You can land after making these last minute adjustments, no need for another round of review :)

src/widgets/dropjob.h
82 ↗(On Diff #73337)

Nitpick: normally it's a single star on the last line. Dunno if it matters for doxygen.

160 ↗(On Diff #73337)

(same)

161 ↗(On Diff #73337)

BIC = Binary Incompatible Change. What's BCI?

In any case better add "TODO KF6" to the comment, I'm sure we'll be grepping for that when the time comes (rather than BCI/BIC).

This revision is now accepted and ready to land.Jan 13 2020, 8:39 AM
trmdi updated this revision to Diff 73399.Jan 13 2020, 12:34 PM
  • Comment
This revision was automatically updated to reflect the committed changes.
kossebau added a subscriber: kossebau.EditedMay 9 2024, 12:12 PM

Hi. I just came across dropping random data (in my case an image) into file views not working, i.e. not creating any new files due to no more data in the QMimeData instance referred to in the DropJob.

Looking into the details, it seems this is due to the flaw of KIO::DropJob being async, but the QDropEvent (which got a respective comment) and even more the QMimeData it exposes (which has no comment, but just a helpless QPointer wrapper) is not defined to outlive the QWidget drop event handler call. And both at least X11 and Wayland protocol seems to negotiate things by the drop serving instance only offering a list of MIME types, next to the copy or move action, and only on the reply of the drop consumer actually deliver the data of the selected MIME type. All this happens during what is wrapped by Qt in the QDropEvent.

My naive reaction to this would be to use some QEventLoop inside KIO::drop() for the user interaction to query "Copy or Move" and "Which format?", then extract the very data from the QMimeData, before returning to the Qt drop event handler call from which KIO::drop() would be called.

But the method added here, DropJob::showMenu() and their usage would not be fixed by this. Anyone around still involved with this who could work on this from their use case POV? Or at least give some thoughts on this?

And now reported the challenge of drop objects lifetime vs user input on decisions by https://bugreports.qt.io/browse/QTBUG-125229