Use KLineEdit for folder name if folder has write access, else use QLabel
ClosedPublic

Authored by shubham on Aug 4 2018, 6:40 PM.

Details

Summary

T9297: 5th point
Use QLabel for "write" protected folder

Test Plan
  1. Open dolphin
  2. Create two folders, one with write access and other with write access denied

Before:
All folders used KLineEdit for folder name

After:
Folder with write access uses KLineEdit
Folder with write access denied uses QLabel instead

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.
shubham created this revision.Aug 4 2018, 6:40 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptAug 4 2018, 6:40 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
shubham requested review of this revision.Aug 4 2018, 6:40 PM
shubham edited the summary of this revision. (Show Details)
shubham updated this revision to Diff 39082.Aug 4 2018, 7:38 PM
shubham retitled this revision from Make KLineEdit read only if write access is denied to Use KLineEdit if folder has write access, else use QLabel.
shubham edited the summary of this revision. (Show Details)
shubham edited the test plan for this revision. (Show Details)
shubham edited the test plan for this revision. (Show Details)Aug 4 2018, 7:42 PM
shubham retitled this revision from Use KLineEdit if folder has write access, else use QLabel to Use KLineEdit for folder name if folder has write access, else use QLabel.
dfaure requested changes to this revision.Aug 4 2018, 9:11 PM
dfaure added inline comments.
src/widgets/kpropertiesdialog.cpp
994

What about this code path? You broke it by removing the call to grid->addWidget(d->nameArea, curRow++, 2); in that case.

998

This method accesses d->m_lined which isn't created yet (you moved that below), so it's null always, and this call would now be dead code.

The proper fix, I think, is to reuse the above code that creates a QLabel instead of a KLineEdit (currently that's for other cases like selecting multiple files, or selecting the root directory, etc.), and go into that condition (the if on line 987) also when the directory doesn't support renaming, or the files can't be moved.

No point in having two different code paths that both create the same QLabel, differently, and with bugs in both, in this version of the patch...

In fact I think your patch should end up removing this call here, no?
If we catch all cases of "renaming forbidden" upfront, this isn't needed anymore.

1000

That test is about writing to the files themselves. To test if the folder forbids renaming, it's the folder that you should be testing for write access, not the file(s).
[at least on Unix; I don't remember the exact semantics on Windows].

Testcase: create a dr-xr-xr-x (0555) folder, and create a -rw-r--r-- (0644) file in it. Renaming is forbidden, if you can write to the file itself, so you should get the label and not the lineedit..

Arguably a possible ("proper") fix would be for KFileItemListProperties::supportsMoving to return false when the directory is readonly, in fact. If that was the case, you would get a readonly lineedit already.
(or do you? the patch description is unclear)

This revision now requires changes to proceed.Aug 4 2018, 9:11 PM
rkflx added a comment.Aug 4 2018, 10:52 PM

@shubham Thanks for helping out with T9297!

reuse the above code that creates a QLabel

@dfaure Thanks for the review! Any advice on how to handle KPropertiesDialog::setFileNameReadOnly, which is used in Plasma's IconApplet and would still show the KLineEdit if I understand your proposal correctly?

Also, KFilePropsPlugin::setFileNameReadOnly checks for m_bFromTemplate. Would this be relevant for your suggestion too?

the patch description is unclear

The main motivation for the patch is to also indicate visually that an item's name cannot be changed. Currently users only notice that by chance due to typing into the line edit not being allowed.

shubham updated this revision to Diff 39112.Aug 5 2018, 7:42 AM

Re-use Qlabel

rkflx added a comment.Aug 5 2018, 12:37 PM

KPropertiesDialog::setFileNameReadOnly
m_bFromTemplate

@shubham Any comments on that (see my questions to @dfaure above)?

src/widgets/kpropertiesdialog.cpp
988

Without your patch, we only tested for !itemList.supportsMoving(). Now you also test for (itemList.isDirectory() & !itemList.supportsWriting(). Could you explain in what cases we need that new test? As far as I can see this blocks renaming the folder you removed the write permission from (while only its children should be prevented from being renamed).

(& instead of && also caught my eye.)

999–1019

Please don't add additional indentation here.

1021

You are moving that line to both the if and the else branch. Why not keep it here?

KPropertiesDialog::setFileNameReadOnly
m_bFromTemplate

@shubham Any comments on that (see my questions to @dfaure above)?

sorry, don't know about it

src/widgets/kpropertiesdialog.cpp
988

this test was intended for blocking directories without write access to rename , but as you say it should be done to it's child

I missed that one & by mistake

dfaure requested changes to this revision.Aug 5 2018, 8:33 PM

Please re-read your diff and, indeed, revert any unnecessary changes like indentation or no-op moving of code.

src/widgets/kpropertiesdialog.cpp
988

You can remove the last condition completely. !itemList.supportsMoving() is enough to detect the case of files in a non-writable directory. See the unittest I just pushed about that, commit 0799ca8f32.

This revision now requires changes to proceed.Aug 5 2018, 8:33 PM
dfaure added a comment.Aug 5 2018, 8:47 PM

KFilePropsPlugin::setFileNameReadOnly checks for m_bFromTemplate for the case where the properties dialog is used by the "Create New / ..." context menu action.
In that case, the source file (the template from /usr) isn't movable, but we still want to let the user type a filename -- for the copied file.

Doing this inside that method won't work anymore, we need to incorporate it into the new if() for using the label. For instance like this:

if (d->bMultiple || isTrash || hasRoot || (!m_bFromTemplate && !itemList.supportsMoving()))

dfaure added a comment.Aug 5 2018, 8:51 PM

Hmm, well, for IconApplet's use case, if you never want a readonly line-edit then a major redesign is needed, switching from the lineedit to the qlabel inside of setFileNameReadOnly itself...
(and using that in the code modified by this patch...). Or adding a ctor flag, to avoid creating+destroying widgets right away...
Given the number of iterations just to get the simple case right, let's do that separately, ok? I could do it myself, faster than doing 10 reviews :-)

shubham updated this revision to Diff 39163.Aug 6 2018, 5:24 AM

Re factor
Remove unnecessary indentations
use only !itemList.supportsMoving()

dfaure requested changes to this revision.Aug 6 2018, 7:13 AM

Better, but you missed the (!m_bFromTemplate && bit. Make sure test "Create New / Text File" in dolphin.

This revision now requires changes to proceed.Aug 6 2018, 7:13 AM
shubham updated this revision to Diff 39164.Aug 6 2018, 7:35 AM

Add check for bFromTemplate
simplify expression (!d->m_bFromTemplate && !itemList.supportsMoving()) to !(d->m_bFromTemplate || itemList.supportsMoving()) for better readability

dfaure requested changes to this revision.Aug 6 2018, 7:47 AM

I disagree that it's more readable, but let's not nitpick :-)

This revision now requires changes to proceed.Aug 6 2018, 7:47 AM
dfaure accepted this revision.Aug 6 2018, 7:47 AM

(oops, misclicked)

This revision is now accepted and ready to land.Aug 6 2018, 7:47 AM
This revision was automatically updated to reflect the committed changes.

Late to the party here, but the read-only label needs to be selectable too. I submitted a patch for that: D14648

rkflx added a comment.Aug 6 2018, 7:46 PM

Hmm, well, for IconApplet's use case

I'd say it would be nice to be consistent everywhere.

I could do it myself, faster than doing 10 reviews :-)

No doubt about that, feel free to work on it ;) If you are busy, we can also add this to T9297 so we don't forget about it.


Make sure test "Create New / Text File" in dolphin.

Interesting, for me only Link to Application will bring up the properties dialog ;)

Hmm, well, for IconApplet's use case

I'd say it would be nice to be consistent everywhere.

I could do it myself, faster than doing 10 reviews :-)

No doubt about that, feel free to work on it ;) If you are busy, we can also add this to T9297 so we don't forget about it.

Done: https://phabricator.kde.org/D14662

Make sure test "Create New / Text File" in dolphin.

Interesting, for me only Link to Application will bring up the properties dialog ;)

Ah yes oops you're right, that's what this is about.