20 March 2010

Gentoo Logo in KDE menu

Categories:  Linux  KDE  Gentoo

How to quickly change a standard KDE menu logo for Gentoo (or any other distribution) logo.

Many distributions like for example Kubuntu offers their own menu logos, but my Gentoo is using by default, standrad oxygen icon. After few months of using KDE 4 on my computer I got terribly tired of this bit ugly standard icon. I searched the Internet and found realy nicly looking Gentoo Linux SVG Icon which would be perfect for menu icon.

SVG Gentoo Linux Logo

Replacing the old icons would require me to copy the new one over the old ones way to many times. What was even worst if I will be using default oxygen icon theme which comes with KDE, I may loose my changes with every new KDE compilation, and then I need to copy it again. I may also decide to use localy installed icon theme, but still I would like to have easy way to put my beloved Gentoo logo as menu icon.

I solved this problem the Linux way. I spend few minutes to wrote a simple script, which will do the job for me.

View the script source
  1. ICON=gentoo-start-icon.svg
  2. RESOLUTION=(16x16 22x22 32x32 48x48 64x64 128x128 256x256)
  3. URL="http://gentoo-art.org/CONTENT/content-files/117383-gentoo-start-icon.svg"
  4. WGET=/usr/bin/wget
  5. MV=/bin/mv
  6. CP=/bin/cp
  7. RM=/bin/rm
  8.  
  9. if [ "${1}" = "global" ]; then
  10. PATH="/usr/share/icons/"
  11. elif [ "${1}" = "local" ]; then
  12. PATH=`echo ~/.kde4/share/icons/`
  13. else
  14. echo
  15. echo "Usage ./kde-icon.sh local | global [theme_name] [restore]"
  16. echo
  17. echo "Examples:"
  18. echo "If you want to change the icons just run:"
  19. echo "./kde-icon.sh local OxygenRefit2-black-version"
  20. echo
  21. echo "If you want to restore old icons run:"
  22. echo "./kde-icon.sh local OxygenRefit2-black-version restore"
  23. echo
  24. exit 1
  25. fi
  26.  
  27. if [ "${#}" -eq 1 ]; then
  28. echo "You didn't provide a theme_name I'm assuming we are changing the oxygen default icon theme"
  29. echo
  30. THEME="oxygen"
  31. else
  32. THEME=${2}
  33. fi
  34.  
  35. echo "Checking if full theme path: ${PATH}${THEME} exists"
  36. echo
  37. if [ -d ${PATH}${THEME} ]; then
  38. echo "Path seems ok"
  39. echo
  40. else
  41. echo "Can not find the provided path check script parameters"
  42. echo
  43. exit 1
  44. fi
  45.  
  46. echo "Checking if you have write access to theme path"
  47. echo
  48. if [ -w ${PATH}${THEME} ]; then
  49. echo "Your rights seems ok"
  50. echo
  51. else
  52. echo "You do not have write access to the theme path you will not be able to change the icons"
  53. echo "Maybe you should run the script as root"
  54. echo
  55. exit 1
  56. fi
  57.  
  58. if [ "${3}" == "restore" ] ; then
  59. echo "You requested restoration of previously stored icons"
  60. echo
  61. echo "Checking if stored copies of old icons are available and performing restore if possible"
  62. for i in "${RESOLUTION[@]}";
  63. do
  64. echo processing ${PATH}${THEME}/$i/places/start-here-kde.png
  65. if [ -w ${PATH}${THEME}/$i/places/start-here-kde.png.bak ]; then
  66. if [ -w ${PATH}${THEME}/$i/places/start-here-kde.svg ]; then
  67. echo "Removing svg icon: ${PATH}${THEME}/$i/places/start-here-kde.svg"
  68. ${RM} ${PATH}${THEME}/$i/places/start-here-kde.svg
  69. echo
  70. fi
  71. echo "Restoring old icons"
  72. ${MV} -f ${PATH}${THEME}/$i/places/start-here-kde.png.bak ${PATH}/${THEME}/$i/places/start-here-kde.png
  73. echo
  74. else
  75. echo "Can't find ${PATH}${THEME}/$i/places/start-here-kde.png.bak or you do not have write access to file"
  76. echo
  77. fi
  78. done
  79. echo "Finished"
  80. echo "To see the changes you need to change the icon set using KDE system settings"
  81. echo
  82. else
  83. echo "Downloading the logo icon"
  84. echo
  85. ${WGET} --output-document=${ICON} ${URL} || die "downloading of the icon failed"
  86.  
  87. echo "Making backup of existing icons"
  88. echo
  89. for i in "${RESOLUTION[@]}";
  90. do
  91. echo processing ${PATH}${THEME}/$i/places/start-here-kde.png
  92. if [ -w ${PATH}${THEME}/$i/places/start-here-kde.png ]; then
  93. if (${MV} -f ${PATH}${THEME}/$i/places/start-here-kde.png ${PATH}/${THEME}/$i/places/start-here-kde.png.bak) then
  94. echo "Storing ${PATH}${THEME}/$i/places/start-here-kde.png as ${PATH}/${THEME}/$i/places/start-here-kde.png.bak succsesfull"
  95. echo
  96. else
  97. echo "There was error while storing icon ${PATH}${THEME}/$i/places/start-here-kde.png"
  98. fi
  99. else
  100. echo "Icon ${PATH}${THEME}/$i/places/start-here-kde.png dosn't exist or you don't have the write access to it!"
  101. echo "I have nothing to do here"
  102. echo
  103. fi
  104. done
  105.  
  106. echo
  107. echo "Placing new Icon"
  108. echo
  109. for i in "${RESOLUTION[@]}";
  110. do
  111. echo processing ${PATH}${THEME}/$i/places/start-here-kde.svg
  112. if (${CP} ${ICON} ${PATH}${THEME}/$i/places/start-here-kde.svg) then
  113. echo "Placing icon ${PATH}${THEME}/$i/places/start-here-kde.svg succsesfull"
  114. echo
  115. else
  116. echo "There was error while placing icon ${PATH}${THEME}/$i/places/start-here-kde.svg"
  117. echo
  118. fi
  119. done
  120. echo "I'm Removing the downloaded icon"
  121. ${RM} -f ${ICON}
  122. echo
  123. echo "That's all!"
  124. echo "To see the changes you need to change the icon set using KDE system settings"
  125. echo
  126. fi

I know that this script could be much shorter but I like to know what is going on, thats why I added so many echo commands.
The script will:

  • download logo from internet (you can change the URL variable to pull different logo)
  • check the user access rights to icons path
  • beckup previous menu icons that were part of an icon set
  • place the new icon in place of old ones
  • restore old icons (if the user will add a resotore parameter)

The script is accepting 3 parameters:

  1. local | global - required to perform changes for globaly or localy installed icons
  2. theme_name - optional the name of the theme this should be the name of the main catalog of icon theme, if no name is specified the script will use default oxygen folder name
  3. replace - optional used a long side with theme_name parameter to restore previously backed up icons

Of course make sure you make this script executable before using it:

chmod +x kde-icon.sh

Example of usage:

  • To change menu icon for default icon set (requires super user access rights)
    ./kde-icon.sh global
  • To change menu icon for localy installed icon set named OxygenRefit2-black-version
    ./kde-icon.sh local OxygenRefit2-black-version
  • To restore menu icons from previously stored backups
    ./kde-icon.sh local OxygenRefit2-black-version restore

The script will report errors if any operation will not be successful.

Exept of running the script you have to also lunch KDE system settings and reset the icon theme in there, without it you will not see the changes. You can consult following screen shot.

KDE Reloading Icons

And to prove it's working here is my menu before:

KDE Menu Icon Before

And here is after:

KDE Menu Icon After

Script is also availble on my svn server, you can access it by following this link.




Comments

If you have found something wrong with the information provided above or maybe you just want to speak your mind about it, feel free to leave a comment.
All comments will show up on page after being approved. Sorry for such policy but I want to make sure that my site will be free of abusive or vulgar content. I don't mind being criticized just do it using right words.

Leave a comment

  • Posted on:
  • Author:
  •  
  • Comment:
  • 24.12.2012
  • Andrzej
  •  
  • "@Alex":
    @Alex To tell you the truth - I no longer use KDE on any actively used computers so currently I do not have any place to test the script. As you can see this is quite an old post. From what I recall any update to oxygen Icon theme would make the default icons back, but running the script again should fix it.
  • 23.12.2012
  • Alex
  •  
  • "Alex":
    Hi, I was using this script for a while and its work very well, but for some reason after some updates on Gentoo ~amd64 the KDE icon back to figure on menu. I believe if the icons are not .png it back to the original. I need to make some tests. Thank you!