Remove custom icon selection for trash
ClosedPublic

Authored by shubham on Jul 25 2018, 10:10 AM.

Details

Summary

BUG: 391200

Test Plan
  1. Right click trash on places panel
  2. Edit

Result: No custom icon menu

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.
There are a very large number of changes, so older changes are hidden. Show Older Changes
ngraham requested changes to this revision.Jul 25 2018, 6:49 PM
ngraham added a reviewer: Dolphin.
ngraham added inline comments.
src/filewidgets/kfileplaceeditdialog.cpp
123

Let's also avoid adding the button to the layout in this case, just like you're doing in D14378.

This revision now requires changes to proceed.Jul 25 2018, 6:49 PM
shubham updated this revision to Diff 38452.Jul 25 2018, 6:57 PM
ngraham requested changes to this revision.Jul 25 2018, 7:24 PM
ngraham added a reviewer: Frameworks.

It's important to test your changes before submitting. :) This now causes Gwenview to segfault when you try to edit its Trash entry. The reason is because now that m_iconButton isn't added to the layout, the line beginning with layout->labelForField() crashes when it tries to run, since `m_iconButton isn't in a layout. That needs to be moved into the conditional as well.

This revision now requires changes to proceed.Jul 25 2018, 7:24 PM
shubham updated this revision to Diff 38468.Jul 26 2018, 5:25 AM
pino added a subscriber: pino.Jul 26 2018, 5:28 AM

TBH creating a widget without adding it to a layout does not make much sense to me -- in the past I saw those situations as "floating" widgets usually anchored at the top-left corner of the parent widget.
The best way here is to just not create m_iconButton at all, like I suggested in D14378: Remove custom icon selection for trash too.

This comment was removed by shubham.
pino added a comment.Jul 26 2018, 5:52 AM

pino: I don't why m_iconButton isn't needed(because it is being used by other entries also ), am I right?

I don't understandwhat you mean, can you please rephrase it?

The point is: if the icon must not be edited, then even creating the KiconButton for it is not useful, because it's an unused widget. Even more, Creating it and making it hidden still uses the resources needed to create it, and load the icon for it. So... just do not create it, taking care of handling in the dialog the case when m_iconButton is null.

This comment was removed by shubham.
shubham updated this revision to Diff 38524.Jul 26 2018, 5:52 PM

Creating m_iconButton only for entries other than TRASH

pino requested changes to this revision.Jul 26 2018, 6:05 PM

It is a good start, but not enough:

  • m_iconButton must be set to null in the constructor (ideally at the beginning, in the initializer list), otherwise it will be uninitialized memory
  • KFilePlaceEditDialog::icon() will crash now, so its usage of m_iconButton must be guarded; either you return the icon passed to the constructor (which thus you need to save), or adjust callers to ask whether the icon could be changed, and only in that case get the icon
src/filewidgets/kfileplaceeditdialog.cpp
123

No need to SCREAM in comments :)

This revision now requires changes to proceed.Jul 26 2018, 6:05 PM
shubham updated this revision to Diff 38633.EditedJul 28 2018, 4:10 AM

Check before getting the icon, whether it's editable or not
No need to get icon for trash

pino requested changes to this revision.Jul 28 2018, 4:24 AM
pino added inline comments.
src/filewidgets/kfileplaceeditdialog.cpp
66

This duplicates the logic that is used in the constructor below. A better option might be to create an helper class method to get whether the icon can be edited, basically checking for m_iconButton.

123

This variable assignment can be moved inside the if as well, since this "what's this" text is used only for the icon button & its label.

132

Extra empty line.

138

Extra empty line.

This revision now requires changes to proceed.Jul 28 2018, 4:24 AM
shubham added a comment.EditedJul 28 2018, 5:27 AM

pino, I understood your idea of having a helper class function, but the condition for editing the icon will remain the same ( based on its scheme), what can be the other condition?(maybe based on protocol?)

pino added a comment.Jul 28 2018, 5:32 AM

pino, I understood your idea of having a helper class function, but the condition for editing the icon will remain the same ( based on its scheme), what can be the other condition?

For example if in the future you exclude another scheme from icon editing. Generally speaking, there is a logic here (url.scheme() != QLatin1String("trash")), and usually duplicating it even across the very same source file is not a good idea.

indirectly you mean to transfer all the logic to helper function

pino added a comment.Jul 28 2018, 5:45 AM

indirectly you mean to transfer all the logic to helper function

No, I suggested something like:

bool KFilePlaceEditDialog::canEditIcon() const
{
  return m_iconButton;
}

using it in KFilePlaceEditDialog::getInformation().

pino: suppose this function is created(canEditIcon()),then this function must also be called when we are creating the m_iconButton at line 123 so as to generalize it's creation ( as you had said to take into account other entries also if they are also to be excluded).

pino added a comment.Jul 28 2018, 6:21 AM

pino: suppose this function is created(canEditIcon()),then this function must also be called when we are creating the m_iconButton at line 123 so as to generalize it's creation ( as you had said to take into account other entries also if they are also to be excluded).

The function I suggested shows to the external users of KFilePlaceEditDialog (which is only the static KFilePlaceEditDialog::getInformation()) whether the icon could be edited or not.

This comment was removed by shubham.
shubham updated this revision to Diff 38637.EditedJul 28 2018, 6:26 AM

Add check for icon's editability using dedicated function

shubham removed a reviewer: dfaure.Jul 28 2018, 7:13 AM
ngraham requested changes to this revision.Jul 30 2018, 10:45 PM

This works and doesn't crash Gwenview for me anymore, yay! Please fix the below issues. And @pino, does the code look sensible now?

src/filewidgets/kfileplaceeditdialog.h
124

Remove the extra four spaces on this line please

127

This is a public function so please add @since 5.49

This revision now requires changes to proceed.Jul 30 2018, 10:45 PM
ngraham added inline comments.Jul 30 2018, 10:48 PM
src/filewidgets/kfileplaceeditdialog.h
126

Change the text to "@returns whether the item's icon is editable"

cfeck added a subscriber: cfeck.Jul 31 2018, 2:11 AM
cfeck added inline comments.
src/filewidgets/kfileplaceeditdialog.h
128

Why is this a public API function? If it needs to be public, it should have better documentation. There is no 'setIconEditable()' function, so a hint why some icons are not editable would be nice.

Also, I would have named it 'isIconEditable()'.

shubham updated this revision to Diff 38824.Jul 31 2018, 5:03 AM

made above requested changes

Almost there! Please implement cfeck's suggestion for additional documentation for this function in the header file, in particular describing why come icons might not be editable.

shubham added a comment.EditedJul 31 2018, 1:55 PM

Almost there! Please implement cfeck's suggestion for additional documentation for this function in the header file, in particular describing why come icons might not be editable.

I could't find the best way to describe it , any suggestions

Space is cheap. :) Verbosity is no problem as long as it communicates important information. How about this:

* @returns whether the item's icon is editable, as some icons are not (e.g. the Trash has the capability to display two icons, representing full and empty states, and it's far simpler to make these icons non-editable than is it to provide an interface to edit them both)
cfeck added a comment.EditedJul 31 2018, 2:11 PM

I still would like to understand why it needs to be public API, instead of just an @internal method. If I understand it correctly, the API isn't needed by any application, but only by the dialog itself. Also, if we decide to implement choosing both icons, or have a new icon format that supports multiple states, we don't need this API.

shubham added a comment.EditedJul 31 2018, 2:17 PM

@cfeck agree with you(it's just a helper)
@ngraham what you reckon?

Yep, I agree.

shubham updated this revision to Diff 38852.Jul 31 2018, 3:36 PM

Remove helper function isIconEditable() (wasn't required), the check can directly be carried out in if clause for dialog->m_iconButton

pino added a comment.Jul 31 2018, 5:58 PM

I still would like to understand why it needs to be public API, instead of just an @internal method.

This is not a public API, since KFilePlaceEditDialog is a private class which is not even exported.

src/filewidgets/kfileplaceeditdialog.cpp
65

This is even worse than the method. Please switch back to the method, since it is the better solution,

pino requested changes to this revision.Jul 31 2018, 5:58 PM
This revision now requires changes to proceed.Jul 31 2018, 5:58 PM
shubham updated this revision to Diff 38868.EditedJul 31 2018, 6:21 PM

revert back, is this fine now?

cfeck added a comment.Jul 31 2018, 6:33 PM

If it's not public, it doesn't need a @since tag.

Why isn't the header called *_p.h ...?

pino added a comment.Jul 31 2018, 6:46 PM

If it's not public, it doesn't need a @since tag.

No idea, it was not me to suggest that.

Why isn't the header called *_p.h ...?

No idea either.

anthonyfieroni added inline comments.
src/filewidgets/kfileplaceeditdialog.cpp
220

This will produce error on strict level it should be

m_iconButton != nullptr

@anthonyfieroni righty said , strictly it should return T/F

shubham updated this revision to Diff 38913.Aug 1 2018, 7:00 PM

remove @since tag,
return m_iconButton != nullptr

dfaure added a subscriber: dfaure.Aug 2 2018, 7:43 AM
dfaure added inline comments.
src/filewidgets/kfileplaceeditdialog.cpp
220

Which strict level is that? AFAIK it's perfectly valid to "cast" a pointer into a boolean, we do this *everywhere*...

src/filewidgets/kfileplaceeditdialog.h
120

it's => its

This comment was removed by shubham.
shubham updated this revision to Diff 38927.Aug 2 2018, 8:03 AM

Fix typos
return m_iconButton

dfaure accepted this revision.Aug 2 2018, 8:14 AM

@dfaure I don't have commit access

cfeck accepted this revision.Aug 2 2018, 11:53 AM

Well, I had to look up your 'previous contributions' page to find your full name and mail address, and I would say given your rate of submits it makes sense to apply for a developer account so that you can commit yourself. This means less work for us.

Going to commit this one in a minute :)

This revision was not accepted when it landed; it landed in state Needs Review.Aug 2 2018, 12:08 PM
This revision was automatically updated to reflect the committed changes.
cfeck added a comment.Aug 2 2018, 1:38 PM

I just noticed that this header says "const QString &icon() const;" i.e. we return a reference to a string. Assuming this API is really not public, it probably needs to be changed to a non-reference, correct?

Well, I had to look up your 'previous contributions' page to find your full name and mail address, and I would say given your rate of submits it makes sense to apply for a developer account so that you can commit yourself. This means less work for us.

Going to commit this one in a minute :)

@cfeck Thank you for committing it on my behalf. BTW can I give your name as supporter for KDE developer account application?

shubham added a comment.EditedAug 2 2018, 2:20 PM

I just noticed that this header says "const QString &icon() const;" i.e. we return a reference to a string. Assuming this API is really not public, it probably needs to be changed to a non-reference, correct?

Yeah even @ngraham had said that it is actually a private header but not named so.
will probably rename it to a private header in another patch.

cfeck added a comment.Aug 2 2018, 2:22 PM

can I give your name as supporter for KDE developer account application?

Sure (even if I hate the mail I will receive from sysadmins ;)

can I give your name as supporter for KDE developer account application?

Sure (even if I hate the mail I will receive from sysadmins ;)

hahaha : )

I have now renamed the header to _p.h to avoid further confusion.