RFC: Herding your program’s icons, how?

Andre Heinecke aheinecke at intevation.de
Fri Apr 27 17:24:47 BST 2012


On Thursday 26 April 2012 15:36:41 Friedrich W. H. Kossebau wrote:
> Hi,
> (cc: to kde-bindings for heads-up, follow-ups please only on
> kde-core-devel)
> Problem__
> How to get all icon-ids in your codebase?

I've faced this issue before while packaging kleopatra for windows and kdepim 
for windows ce, in both cases my solution was to abuse krazy for this job.

Krazy has a nice check for iconnames. (I think they were for kde3tokde4 name 
changes). (krazy2/plugins/general/iconnames)
Just put all valid icons names in there instead of the old kde3 ones and there 
you go. You get a complete list (with --verbose ) of all codelines where 
icons are used. Then i've used another script to match that list against the 
list of all icons to find out which icon was actually used and I was done. 

I don't have the icon lists laying around but with find / awk / sort it should 
be no problem to generate.

I'm sending you the script to compare all icons with the list from krazy off 
the list.

As you have a clearly defined and small dictonary of valid icon names
you could also do a different approach:
something like:
for icon in $all_valid_icons do;
	find <myproject> -name \*.cpp \*.qml | xargs grep $icon

But Krazy does this better and more intelligent :)
> Just blogged* about this, but then more something for this ml.
> * http://frinring.wordpress.com/2012/04/26/herding-your-programs-icons-how/
> When seeing for the icon-ids used in Calligra, 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, and having to do manually
> extraction is not nice. 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"))  // kicon("...") is even more
> readable
> and
>     "some-icon"
> and would enable to automatically extract these icon-ids (with metadata
> like file, line, etc). It should be backward-compatible, as it is just some
> mark-up which resolves to what there was before. And while there is nothing
> to enforce that all icon-ids are marked up, the same problem exists with
> i18n, so something we are okay with.
> With that markup IDEs might be even able to check the validness of icon-ids
> or offer code-completion, perhaps even with preview of the actual icon :)
> </dream>

I think your suggestion is ok. 
My counterpoints:
 1. Another macro 
 2. Something you need to enforce and ppl tend to forget (like localization)
 3. Very, very few use cases for this only a subset of packagers cares about 
> Questions__
> What about icons used in UI files, will they still pass KIconLoader or
> whatever makes the icon being picked from the usual places?
> Are there other usages of icon-ids which might not be catchable this way?
> Would something similar work for non-C++ languages?
> What could be better keywords for the macros?
> What do you think in general? Comments, other/better proposals welcome!

To summarize my approach: Don't look at it like i18n where you have to find 
the words to put in a dictonary. You already know all the words and have the 
dictonary so just check if those words are used in your code.


Andre Heinecke |  ++49-541-335083-262 |  http://www.intevation.de/
Intevation GmbH, Neuer Graben 17, 49074 Osnabrück | AG Osnabrück, HR B 18998
Geschäftsführer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner

More information about the kde-core-devel mailing list