Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emblem For (Encrypted) Volume Icons #42

Closed
wants to merge 1 commit into from
Closed

Conversation

tsujan
Copy link
Member

@tsujan tsujan commented Sep 29, 2016

GLib may give emblems to volume icons but drawing emblems was not possible because there is no size hint in PlacesModelItem (see #41 (comment)). This PR simply gets the required icon size from PlacesView (through PlacesModel) and draws the GIcon emblem.

In my opinion, the hard task of hacking XdgIcon is an overkill for such a simple job -- we don't need emblems in other places (for now).

@palinek
Copy link
Contributor

palinek commented Sep 29, 2016

I may miss something...
but why not create/use something similar like here: https://github.com/lxde/libfm-qt/blob/master/src/folderitemdelegate.cpp#L102. The FmFileInfo contains information about icon (the GIcon)... so just adding the newRole and implementing the *::data(newRole) and using it in the *ItemDelegate to paint the emblem.

@tsujan
Copy link
Member Author

tsujan commented Sep 29, 2016

@palinek
This isn't about files (GFile) but about GVolume.

@tsujan
Copy link
Member Author

tsujan commented Sep 29, 2016

@palinek
... And even for GFile, that wouldn't help because FmFileInfo doesn't contain any emblem info: even if you get GFile from FmFileInfo, there will be no emblem info.

@palinek
Copy link
Contributor

palinek commented Sep 29, 2016

OK... I see, I'm missing a lot 😄

@tsujan
Copy link
Member Author

tsujan commented Sep 29, 2016

@palinek
It's OK. Yesterday, I learned a lot in the 3 hours I tried to implement file emblems (to no avail).

GLib may give emblems to volume icons but drawing emblems was not possible because there is no size hint in PlacesModelItem (see #41 (comment)). This PR simply gets the required icon size from PlacesView (through PlacesModel) and draws the GIcon emblem.

In my opinion, the hard task of hacking XdgIcon is an overkill for such a simple job -- we don't need emblems in other places (for now).
@tsujan
Copy link
Member Author

tsujan commented Sep 30, 2016

@palinek
This isn't related to the PR but I was wrong about GFile above: although FmFileInfo doesn't contain any emblem info, GFileInfo can be derived from it indirectly to provide emblem info. I think the same info could be added to FmFileInfo in libfm.

@PCMan
Copy link
Member

PCMan commented Sep 30, 2016

@tsujan Thank you for all of the hard work. Reading others' code, understanding it correctly, and trying to enhance its features is never an easy task. Good job so far!
To make your work even better, I'd suggest thinking more about design-pattern at the same time.
The folder view/model stuff is what we called MVC pattern.
Different icon sizes are actually different ways to "view" the same data "model".
So ideally it should not be controlled by the model itself. This PR breaks the design pattern.
The best place to do the emblem hack is definitely inside QIcon, which is not possible at the moment.
As an alternative, I'd suggest:

  1. Add Fm::Icon::pixmap(size, state) to render the pixmap, so this code can be reused everywhere when an emblemed icon is needed. Even better, try to cache these pixmaps to some extent since generating it is very expensive. (This is what QIcon does internally) Using g_object_set_qdata() to attach the QPixmap objects to the GIcon object is the most easy and effective way.
  2. Make Fm::FolderItemDelegate support PlacesModel (better) or develop another item delegate for the places model (also works). Inside this delegate, you have Fm::FileInfo and then you can get FmIcon of it. Then, call Fm::Icon::pixmap() to render the icon.

Then it's done. No need to spread the emblem code everywhere. In the future if the GIcon/Fm::Icon stuff is changed, nothing outside these classes will be affected as they are well-encapsulated.

@PCMan PCMan mentioned this pull request Sep 30, 2016
@tsujan
Copy link
Member Author

tsujan commented Sep 30, 2016

@PCMan
It's about 3-4 months that I don't understand your arguments anymore. Maybe something has got wrong with me or .... So, no further comment.

@PCMan
Copy link
Member

PCMan commented Sep 30, 2016

@tsujan To sum up. Your code works, which is good and I appreciate your effort. However, adding view information in data model is against the Qt MVC design pattern. Your code is good, but the problem is where to add it.There are many places that you can hack to make it work, but it's better to add it at the right place so we only need to do it once and no further refactoring is needed in the future.
Don't get me wrong. I like your contribution and appreciate that. Just wan to see if there are ways to make the API design better.
If you feel offended, that's probably my problem but I'm not intended to do so. We can also merge your PR first and later do the refactor. This requires frequent changes to library API, though.

@PCMan
Copy link
Member

PCMan commented Sep 30, 2016

@tsujan Two views with different icon sizes can share the same data model and that's why you should not set icon size on the data model. Though we don't do this in the program at the moment, it's not good API design and might break in the future.
I'm here to help, not to reject all PRs deliberately.
I respect your contribution and hope you can understand that.

@tsujan
Copy link
Member Author

tsujan commented Sep 30, 2016

@PCMan
I'm no able to feel offended -- that's part of my personality as a pragmatist. The matter is that, with the attitude you have adopted recently, my contribution would be senseless. Your arguments have become strange and, as I said, incomprehensible to me. Let's not continue this discussion -- it'll go nowhere.

@PCMan
Copy link
Member

PCMan commented Sep 30, 2016

@tsujan OK, I'll merge your PR first and do the required refactor later before the next release. It's not about attitude. It's about design patterns. Your contribution is always welcomed, but I cannot agree with you on this one. Mixing view stuff with the data model is against the purpose of model/view separation and should generally be avoided.

@tsujan
Copy link
Member Author

tsujan commented Sep 30, 2016

@PCMan
Don't merge it if you really think that your argument is correct pracically! What's important to me is not my PR but the final result, provided that there is a result/change.

@PCMan
Copy link
Member

PCMan commented Sep 30, 2016

@tsujan Merged and did some refactor.

  1. Emblem information is now cached in Fm::IconTheme and not built from GIcon everytime.
  2. Now icon sizes are only controlled by PlacesView, not PlacesModel. Multiple PlacesViews can have different icon sizes and still share the same model. (but we don't use it now) This API change is still backward compatible and still split model/view/controller cleanly.
  3. Reuse FolderItemDelegate to paint the items of PlacesModel to avoid code duplication. All views that need to paint an emblemed icon should reuse this. So we only need to do it once.

Thanks for the contribution. Now the places icon and file icons both support emblems.

@PCMan PCMan closed this Sep 30, 2016
@tsujan
Copy link
Member Author

tsujan commented Sep 30, 2016

Works as intended.

@agaida agaida added this to Rejected/Declined in Pull Requests Apr 1, 2018
@agaida agaida added this to Archive in Pull Requests Aug 11, 2018
@agaida agaida added this to old in PRs Nov 5, 2018
@agaida agaida added this to Archive in PRs Nov 5, 2018
@agaida agaida deleted the emblemed_volume branch December 2, 2018 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PRs
  
Archive
Pull Requests
  
Old Archive (fucked up)
Development

Successfully merging this pull request may close these issues.

None yet

3 participants