Attracted by virtual constructs

April 26, 2012

Herding your program’s icons, how?

Filed under: Calligra,KDE — by frinring @ 12:06 pm

The last weeks I have been doing my small share of bit-flipping to contribute to the polishing of that big, big rough diamond which there is called Calligra, doing some pixel pushing here and there (e.g. on the line-end-style selectors and the rulers) and fixing a few bugs.

Now I wanted to give all icons used in Calligra a check, to see both if there is an icon for the given icon-id as well as if there are icon files installed which are no longer used. After all Calligra is a quite large codebase, coming over a long and winding road (some files have up to 13 and more authors, the first one usually in 1998 :) ), so a few icon usages got broken during the trip.

Problem
But how to get all icon-ids in your codebase?

I have used a simple approach to get at least most of them, doing a grep for lines with “KIcon(“. That gave me more than 1000 lines for Calligra, and almost all also directly used an icon-id, so there was chance to do a check and create a report for these.

Now this is quite unsatisfying to not be able to easily get a list of all the icon resources used in your codebase. How do you deal with this in your project?

Proposal
Ideally icon-ids would be kind-of tagged when used, so like gettext is able to extract all strings which need a translation, some geticon would be able to extract all icon-ids. The result could then be used to check the icon-ids against the icons available from the icon themes and the icons installed from the project itself, ideally automatically (as doing that manually is… pretty boring, time-consuming and error-prone).

I could imagine that there could be some macros

kicon("some-icon")

and

kiconid("some-icon")

which would resolve to

KIcon(QLatin1String("some-icon"))

and

"some-icon"

and would enable to automatically extract these icon-ids.

What do you think? Comments, other/better proposals welcome!

About these ads

6 Comments »

  1. Another thing that is worth checking is whether the icons are the size (dimensions) they are supposed to be. I see a lot of rpmlint warnings that a KDE icon is in a folder for icons of a particular size but isn’t that size. This may be intentional, but it would be good to include in the report just to be sure.

    -Todd

    Comment by TheBlackCat — April 26, 2012 @ 5:01 pm |Reply

    • Not sure how that could be intentional, IMHO that would indeed be a bug, good that you mention it.
      But IMHO this is something that should be checked independently of the problem here, as the check for correct icon sizes could than be used for all icon themes, not just the Oxygen set.

      To have the rpmlint warnings fixed, please file a bug at bugs.kde.org for the product “Oxygen” and the component “icons” and post there the rpmlint warnings that you see, thanks.
      Follow e.g. this link: https://bugs.kde.org/enter_bug.cgi?product=Oxygen&format=guided

      Comment by frinring — April 27, 2012 @ 4:15 pm |Reply

  2. The heuristics you used means you also some unused code has been checked (e.g. in Kexi – but we’ll have it removed rather soon).

    IMHO a good idea for real would be to temporarily re-define KIcon function into some global function that gives a compiler warning when used; then it’s possible to grep for that specific warnings. This way we’re sure only used code is checked.

    Comment by jstaniek — April 26, 2012 @ 9:38 pm |Reply

    • I thought about redefining KIcon(…) before as well, but after more thinking Idropped the idea, because it means you have to make sure that all code which does a KIcon(…) call is actually run. Ensuring that (especially with all the #ifdefs) looked like way more work in the end, so I chose to use the grep method, at least for the first approach to this problem. It definitely needs to be made done automatically, e.g. as krazy task.

      Well, and checking unused code at least increases the chance that once it gets used more icons are correct :)

      Comment by frinring — April 27, 2012 @ 3:56 pm |Reply

  3. One more possibility for this macro could be that KDevelop could recognise it and show tooltip with the icon, no?

    Comment by jenny — April 26, 2012 @ 10:01 pm |Reply

    • Yes, that is another nice use-case idea.
      KDevelop and other IDEs could also help if recognising the macros with checking the validness of icon-ids or offer code-completion when the user starts typing, again with preview of the icons for the possible completions.

      Comment by frinring — April 27, 2012 @ 3:46 pm |Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Toni Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: