User:Pino/Handling icons

From KDE TechBase
Warning
This is not an official page.


noframe
noframe
 
Under Construction
This page is under construction. This page is actively being developed and updated with new information, and may be incomplete. You can help by editing this page


Installing

Compact naming

One of the most common ways to name icons in sources is a "compact" form which includes various details. The format is the following:

<theme><size>-<context>-<name>.<extension>

Where:

  • theme: the two-letter name of the icon theme; supported themes are:
    • hi: hicolor
    • ox: Oxygen
    • cr: Crystal SVG
    • lo: locolor
  • size: the size of the icon in pixels (e.g. 24 for a 24x24 icon), with the special value sc for scalable icons in SVG(Z) format
  • context: the context for the icon, as specified in either the XDG icon theme specification or the XDG icon naming specification; e.g. app for application icons, mime for MIME type icons, and so on
  • name: the real name of the icon
  • extension: the extension of the icon, e.g. png, svg, etc

Installing with CMake (KDE 4)

To install icons with the CMake buildsystem using the KDE4 macros, you just need to use one macro:

kde4_install_icons(<installation directory>)

<installation directory> is usually

  • ${ICON_INSTALL_DIR}: installs the icons in the share/icons subdirectory of the installation prefix.
  • ${DATA_INSTALL_DIR}/applicationname/icons: locally for an application only (see also the section below)
Warning
This CMake macros takes all the icons with a "compact" naming in the current directory, and installs them in the <installation directory> specified. Hence, to install some icons in one location and some in another, the only solution is to put the icons in different directories with ad-hoc kde4_install_icons() calls.


Choosing the right icon theme and installation directory

There are few things to keep into account when choosing which icon theme use for icons, and which directory install them into.

One thing to remember is that the hicolor icon theme (called fallback theme) is the only common denimonator among all the possible icon themes.

Application icon

When install the application icon of an application (i.e. the icon representing the application, usually named after the application itself), you want to make it used by anyone, regardless of which icon theme they are using. Because of this:

  • use the hi (hicolor) icon theme
  • use ${ICON_INSTALL_DIR} as installation directory, as it allows the icon to be seen by all the other applications installed in the same prefix

Simple application, other icons

This is the case for KDE applications with nothing like plugins for plugin systems not of the own application itself (like kparts, kioslaves, konqueror service menus, etc). In this case:

  • use the hi (hicolor) icon theme
  • use ${DATA_INSTALL_DIR}/applicationname/icons as installation directory

Installing the icons in a icons subdirectory of the application data directory allows the application to make use of them without "polluting" the global icon theme with application-specific icons, but still making icon themes able to override the hicolor icons of the application with own icons.