icon_switcher 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/sh
  2. #(c) Copyright Nov 2007 Barry Kauler www.puppylinux.com
  3. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  4. #written dec 2007 for Puppy Linux.
  5. #v3.98 BK: fix unionfs saving problem when newer file in pup_save.
  6. #v4.00 HairyWill: restart rox and jwm immediately.
  7. #w477 record name of theme in /etc/desktop_icon_theme
  8. #100411 fbpanel menu did not update.
  9. #110721 new standardised icons to show when mounted.
  10. #110912 modify jwm to use menu icon 'start-button.png' if present.
  11. #120201 rodin.s: internationalized
  12. export TEXTDOMAIN=icon_switcher
  13. export TEXTDOMAINDIR=/usr/share/locale
  14. export OUTPUT_CHARSET=UTF-8
  15. eval_gettext (){
  16. local myMESSAGE=$(gettext "$1")
  17. eval echo \"$myMESSAGE\"
  18. }
  19. export LANGORG=$LANG
  20. func_switch (){
  21. NEWTHEME="$1"
  22. [ "$NEWTHEME" = "" ] && exit
  23. [ ! -d /usr/local/lib/X11/themes/${NEWTHEME} ] && exit
  24. #show splash if running in gui mode
  25. if [ "$UPDATE" = "true" ]; then
  26. /usr/lib/gtkdialog/box_splash -close never -fontsize large -icon_width 60 -icon /usr/share/pixmaps/puppy/puppy_config.svg -text "Changing theme" &
  27. XPID=$!
  28. fi
  29. #---
  30. for ONESVG in `find /usr/local/lib/X11/themes/${NEWTHEME}/ -maxdepth 1 -name \*.svg | tr '\n' ' '`; do
  31. ONEBASENAME="`basename $ONESVG .svg`"
  32. rm -f /usr/local/lib/X11/pixmaps/${ONEBASENAME}48.png
  33. rsvg-convert -w 48 -h 48 -o /usr/local/lib/X11/pixmaps/${ONEBASENAME}48.png $ONESVG
  34. rm -f /usr/local/lib/X11/pixmaps/${ONEBASENAME}24.png
  35. done
  36. for ONEPNG in `find /usr/local/lib/X11/themes/${NEWTHEME}/ -maxdepth 1 -type f -name \*.png | tr '\n' ' '`; do
  37. ONEBASENAME="`basename $ONEPNG .png`"
  38. cp -f $ONEPNG /usr/local/lib/X11/pixmaps/
  39. touch -m /usr/local/lib/X11/pixmaps/${ONEBASENAME}.png #v3.98
  40. done
  41. #new standardised icons to show when mounted...
  42. if [ "`which pngoverlay`" -a -e /usr/local/lib/X11/pixmaps/closebox_outline48.png ];then #overlay app created by vovchik (see source /usr/sbin/pngoverlay.bac)
  43. rm -f /usr/local/lib/X11/pixmaps/*_mntd*.png
  44. cd /usr/local/lib/X11/pixmaps
  45. cp -f /usr/sbin/pngoverlay /usr/local/lib/X11/pixmaps/ #dumb, but needs to be in same folder.
  46. for ONEDRV in card drive floppy optical usbdrv; do
  47. ./pngoverlay ${ONEDRV}48.png closebox_outline48.png ${ONEDRV}_mntd48.png #background foreground output.
  48. ./pngoverlay ${ONEDRV}48.png locked_outline48.png ${ONEDRV}_mntd_boot48.png
  49. done
  50. rm -f /usr/local/lib/X11/pixmaps/pngoverlay
  51. fi
  52. #modify jwm to use menu icon 'start-button.png' if present...
  53. #note, similar code also in 3builddistro in Woof.
  54. if [ -f /root/.jwmrc-tray ] && [ -f /usr/local/lib/X11/${NEWTHEME}/start-button.png ]; then #chosen theme has menu icon.
  55. if [ -f /usr/local/lib/X11/pixmaps/start-button.png ];then #precaution.
  56. if [ ! "`grep -F 'start-button.png' /root/.jwmrc-tray`" ]; then
  57. #the default is to use 'mini-dog.xpm' with text "Menu"...
  58. sed -i 's%label="Menu" icon="puppy.svg"%icon="start-button.png"%' $HOME/.jwmrc-tray
  59. fi
  60. else
  61. #chosen theme does not have start-button.png, so go back to the mini-dog.xpm...
  62. sed -i 's%icon="start-button.png"%label="Menu" icon="puppy.svg"%' $HOME/.jwmrc-tray
  63. fi
  64. fi
  65. #record current theme...
  66. echo -n "$NEWTHEME" > /etc/desktop_icon_theme
  67. if [ "$UPDATE" = "true" ]; then
  68. #restart rox and jwm immediately...
  69. rox -p=/root/Choices/ROX-Filer/PuppyPin
  70. jwm -restart
  71. #kill splash
  72. kill $XPID
  73. fi
  74. }
  75. export -f func_switch
  76. #parameters
  77. while [ $# != 0 ]; do
  78. I=1
  79. while [ $I -le `echo $# | wc -c` ]; do
  80. case $1 in
  81. -a) NEWTHEME="$2"; shift;;
  82. -u) UPDATE=true;;
  83. -h|--help)
  84. echo 'Usage: icon_switcher [OPTION]
  85. Options
  86. -a THEME Activate theme
  87. -h Show this help message
  88. -u Update desktop'; exit;;
  89. esac
  90. shift
  91. I=$[$I+1]
  92. done
  93. done
  94. if [ "$NEWTHEME" ]; then
  95. func_switch "$NEWTHEME"
  96. else
  97. GUI=true
  98. UPDATE=true
  99. ICONSETSGUI=""
  100. for ONEDIR in `find /usr/local/lib/X11/themes/ -mindepth 1 -maxdepth 1 -type d | tr '\n' ' '`; do
  101. ONENAME="`basename $ONEDIR`"
  102. [ -f $ONEDIR/folder.svg ] && rsvg-convert -w 48 -h 48 -o /tmp/pis-${ONENAME}-folder.png $ONEDIR/folder.svg
  103. [ -f $ONEDIR/folder48.png ] && cp -f $ONEDIR/folder48.png /tmp/pis-${ONENAME}-folder.png
  104. [ -f $ONEDIR/www.svg ] && rsvg-convert -w 48 -h 48 -o /tmp/pis-${ONENAME}-www.png $ONEDIR/www.svg
  105. [ -f $ONEDIR/www48.png ] && cp -f $ONEDIR/www48.png /tmp/pis-${ONENAME}-www.png
  106. [ -f $ONEDIR/word.svg ] && rsvg-convert -w 48 -h 48 -o /tmp/pis-${ONENAME}-word.png $ONEDIR/word.svg
  107. [ -f $ONEDIR/word48.png ] && cp -f $ONEDIR/word48.png /tmp/pis-${ONENAME}-word.png
  108. [ -f $ONEDIR/spread.svg ] && rsvg-convert -w 48 -h 48 -o /tmp/pis-${ONENAME}-spread.png $ONEDIR/spread.svg
  109. [ -f $ONEDIR/spread48.png ] && cp -f $ONEDIR/spread48.png /tmp/pis-${ONENAME}-spread.png
  110. ICONSETSGUI=$ICONSETSGUI'
  111. <hbox space-expand="true" space-fill="true">
  112. <hbox border-width="8" spacing="20" space-expand="false" space-fill="false">
  113. <pixmap space-expand="false" space-fill="false"><input file>/tmp/pis-'${ONENAME}'-folder.png</input></pixmap>
  114. <pixmap space-expand="false" space-fill="false"><input file>/tmp/pis-'${ONENAME}'-www.png</input></pixmap>
  115. <pixmap space-expand="false" space-fill="false"><input file>/tmp/pis-'${ONENAME}'-word.png</input></pixmap>
  116. <pixmap space-expand="false" space-fill="false"><input file>/tmp/pis-'${ONENAME}'-spread.png</input></pixmap>
  117. </hbox>
  118. <text width-request="20" space-expand="false" space-fill="false"><label>""</label></text>
  119. <vbox space-expand="true" space-fill="true">
  120. <text height-request="1" space-expand="true" space-fill="true"><label>""</label></text>
  121. <button space-expand="false" space-fill="false">
  122. <label>'${ONENAME}'</label>
  123. <action>export UPDATE=true; func_switch "'${ONENAME}'"</action>
  124. </button>
  125. <text height-request="10" space-expand="false" space-fill="false"><label>""</label></text>
  126. </vbox>
  127. </hbox>'
  128. done
  129. export ICONSWITCHGUI='
  130. <window title="'$(gettext 'Puppy Icon Switcher')'" icon-name="gtk-convert" height-request="500" width-request="520">
  131. <vbox>
  132. '"`/usr/lib/gtkdialog/xml_info fixed "desktop_icons.svg" 60 "$(gettext 'The Puppy icon switcher sets icons for both the <b>desktop</b> and the <b>menu</b>')"`"'
  133. <vbox space-expand="true" space-fill="true">
  134. <vbox scrollable="true">
  135. <eventbox name="bg" above-child="false" visible-window="true" space-expand="true" space-fill="true">
  136. <vbox border-width="20" space-expand="false" space-fill="false">
  137. '${ICONSETSGUI}'
  138. </vbox>
  139. </eventbox>
  140. </vbox>
  141. </vbox>
  142. <hbox space-expand="false" space-fill="false">
  143. <button>
  144. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  145. <label>'$(gettext 'Cancel')'</label>
  146. </button>
  147. '"`/usr/lib/gtkdialog/xml_scalegrip`"'
  148. </hbox>
  149. </vbox>
  150. </window>'
  151. #set background pic
  152. BG_FILE="`cat $HOME/.config/wallpaper/bg_img`"
  153. [ ! "$BG_FILE" ] && BG_FILE="`grep -F '<backdrop' $HOME/.config/rox.sourceforge.net/ROX-Filer/pb_default | cut -d'>' -f2 | cut -d'<' -f1`"
  154. [ ! "$BG_FILE" ] && BG_FILE="`cat $HOME/Choices/ROX-Filer/PuppyPin | grep '<backdrop ' | cut -f 2 -d '>' | cut -f 1 -d '<'`"
  155. BG_PATH="`dirname "$BG_FILE"`"
  156. BG_NAME="`basename "$BG_FILE"`"
  157. echo '
  158. pixmap_path "'$BG_PATH'"
  159. style "bg" { bg_pixmap[NORMAL] = "'$BG_NAME'" }
  160. widget "*bg*" style "bg"' > /tmp/gtkrc_bg
  161. export GTK2_RC_FILES=/tmp/gtkrc_bg:/root/.gtkrc-2.0
  162. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  163. gtkdialog -p ICONSWITCHGUI
  164. fi