Implement a kfile dialog where we can add custom widget
ClosedPublic

Authored by mlaurent on Dec 5 2017, 3:00 PM.

Details

Test Plan

I added a test apps + autotest

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mlaurent created this revision.Dec 5 2017, 3:00 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptDec 5 2017, 3:00 PM
Restricted Application added a subscriber: Frameworks. · View Herald Transcript
mlaurent requested review of this revision.Dec 5 2017, 3:00 PM
mlaurent edited the test plan for this revision. (Show Details)Dec 5 2017, 3:01 PM
mlaurent added reviewers: mwolff, dfaure.
mwolff added a comment.Dec 5 2017, 3:24 PM

Most of this is just forwarding code from KFileWidget, so we could just use that directly? I mean if our LO integration is going to be the only user of this class, then maybe we should start by adding this code there and only upstream it if we think more people are going to use it?

It's the problem that if class doesn't exist nobody will think to use it (or he will reimplement it).
After that it's not a problem for me to put this code only in LO :)
As you want :)

Hmm. I can see the usefulness, it's certainly much better than the way people have historically inserted custom widgets into QFileDialog (https://stackoverflow.com/questions/16987916/add-widgets-to-qfiledialog, URGH).

On the other hand, I'm wondering if this is going to be abused as a KFileDialog replacement, losing the "native" look-n-feel for the file dialog on Windows / macOS.
Well, that's certainly a pre-requisite for any custom widget to work, it should just be made extra clear to app developers that what they lose in return is the ability to get native dialogs on Windows and macOS (and Gnome, I suppose).

So, I'm OK with this, provided that this documentation is added:

The downside of using this class is that your application will not be able to get a native file dialog on non-Plasma environments (Windows, macOS, ...). For this reason you should really think twice before deciding to use it, as a custom widget might improve user experience within the Plasma workspace, but might make it worse for users who are used to the native file dialog. In 99% of the cases, you want to use QFileDialog instead.

autotests/kfilecustomdialogtest.cpp
43

This isn't really testing anything useful. Rename the layout and the test breaks. Maybe better verify that dlg itself has a layout, rather than "there is a child layout somwhere called mainlayout".

48

QCOMPARE(dlg.fileWidget(), mFileWidget) ? More useful ;)

tests/kfilecustomdialogtest_gui.cpp
27

remove

tests/kfilecustomdialogtest_gui.h
26 ↗(On Diff #23514)

unused, remove (remove the whole header...)

dfaure requested changes to this revision.Dec 12 2017, 5:08 PM
dfaure added inline comments.
autotests/kfilecustomdialogtest.h
31

not really useful, in unittests (there's initTestcase which is better for initializations anyway)

src/filewidgets/kfilecustomdialog.h
33

API documentation rarely says "we".
Suggested rephrasing:

It uses a KFileWidget and allows the application to provide a custom widget.

... which will be shown where, BTW? Below the directory view and above the buttons? Or on the side? I see the implementation is KFileWidget::setCustomWidget so I could be less lazy and look that up, but the user of KFileCustomDialog wouldn't even know this anyway (unless the docu for setCustomWidget is improved to point there).

44

Please reuse the documentation from KFileWidget, it's better.

69

Is this needed? Does it need to be public? Why not connect to KFileWidget's slotOk directly?

(or using a lambda)
This revision now requires changes to proceed.Dec 12 2017, 5:08 PM
mlaurent marked 7 inline comments as done.Dec 14 2017, 1:50 PM
mlaurent updated this revision to Diff 23908.Dec 14 2017, 1:55 PM
  • Fix doc, remove unused code, etc.
dfaure accepted this revision.Dec 14 2017, 2:09 PM
dfaure added inline comments.
src/filewidgets/CMakeLists.txt
41

nothing to see here

src/filewidgets/kfilecustomdialog.cpp
66

I wonder about the usefulness of these indirection methods, the only caller could do d->mFileWidget->setUrl(url), but well. Your choice :)

(same for the 3 that follow, I don't see much benefit, but OK I don't see much harm either)

src/filewidgets/kfilecustomdialog.h
62

"element" seems weird here. Maybe something like this?

@return the filewidget used inside this dialog

This revision is now accepted and ready to land.Dec 14 2017, 2:09 PM
mlaurent marked 2 inline comments as done.Dec 14 2017, 2:45 PM
mlaurent updated this revision to Diff 23916.Dec 14 2017, 2:47 PM
  • Remove indirection methods as requested by David. Fix doc too
This revision was automatically updated to reflect the committed changes.