#!/bin/sh
#called from 3builddistro
#141204 now have file 'default-theme' (see 3builddistro).

BI_ITEMS=""; DEFITEM=""
if [ "$DEFAULT_THEME_WALLPAPER" ];then #141204
 DEFITEM="$(echo -n "$DEFAULT_THEME_WALLPAPER" | cut -f 2 -d ':')"
 [ -f rootfs-complete/usr/share/backgrounds/${DEFITEM} ] && BI_ITEMS="<item>${DEFITEM}</item>"
fi
for ONEITEM in `ls -1 rootfs-complete/usr/share/backgrounds | tr '\n' ' '`
do
 [ "$ONEITEM" == "$DEFITEM" ] && continue #141204
 BI_ITEMS="${BI_ITEMS}<item>${ONEITEM}</item>"
done

GT_ITEMS=""; DEFITEM=""
if [ "$DEFAULT_THEME_GTK2" ];then #141204
 DEFITEM="$(echo -n "$DEFAULT_THEME_GTK2" | cut -f 2 -d ':')"
 [ -d rootfs-complete/usr/share/themes/${DEFITEM}/gtk-2.0 ] && GT_ITEMS="<item>${DEFITEM}</item>"
fi
for ONEITEM in `ls -1 rootfs-complete/usr/share/themes/*/gtk-2.0 | grep '^rootfs-complete/usr/share/themes' | cut -f 5 -d '/'`
do
 [ "$ONEITEM" == "$DEFITEM" ] && continue #141204
 GT_ITEMS="${GT_ITEMS}<item>${ONEITEM}</item>"
done

DI_ITEMS=""; DEFITEM=""
if [ "$DEFAULT_THEME_DESK_ICONS" ];then #141204
 DEFITEM="$(echo -n "$DEFAULT_THEME_DESK_ICONS" | cut -f 2 -d ':')"
 [ "$DEFITEM" ] && [ -d rootfs-complete/usr/local/lib/X11/themes/${DEFITEM} ] && DI_ITEMS="<item>${DEFITEM}</item>"
fi
for ONEITEM in `find rootfs-complete/usr/local/lib/X11/themes -maxdepth 1 -mindepth 1 -type d | rev | cut -f 1 -d '/' | rev`
do
 [ "$ONEITEM" == "$DEFITEM" ] && continue #141204
 DI_ITEMS="${DI_ITEMS}<item>${ONEITEM}</item>"
done

JT_ITEMS=""; DEFITEM=""
if [ "$DEFAULT_THEME_JWM" ];then #141204
 DEFITEM="$(echo -n "$DEFAULT_THEME_JWM" | cut -f 2 -d ':')"
 [ -f rootfs-complete/root/.jwm/themes/${DEFITEM}-jwmrc ] && JT_ITEMS="<item>${DEFITEM}</item>"
fi
for ONEITEM in `ls -1 rootfs-complete/root/.jwm/themes/*-jwmrc | rev | cut -f 1 -d '/' | cut -f 2-99 -d '-' | rev`
do
 [ "$ONEITEM" == "$DEFITEM" ] && continue #141204
 JT_ITEMS="${JT_ITEMS}<item>${ONEITEM}</item>"
done

OB_ITEMS=""; DEFITEM=""
if [ "$DEFAULT_THEME_OPENBOX" ];then #141204
 DEFITEM="$(echo -n "$DEFAULT_THEME_OPENBOX" | cut -f 2 -d ':')"
 [ "$DEFITEM" ] && [ -d rootfs-complete/usr/share/themes/${DEFITEM}/openbox-3 ] && OB_ITEMS="<item>${DEFITEM}</item>"
fi
for ONEITEM in `ls -1 rootfs-complete/usr/share/themes | tr '\n' ' '`
do
 [ "$ONEITEM" == "$DEFITEM" ] && continue #141204
 [ ! -e rootfs-complete/usr/share/themes/${ONEITEM}/openbox-3 ] && continue
 OB_ITEMS="${OB_ITEMS}<item>${ONEITEM}</item>"
done

export MAIN_DIALOG="
<vbox>
  <text><label>Choose the default themes...</label></text>
  <hbox>
    <text><label>Background image (ref: usr/share/backgrounds):</label></text>
    <combobox>
      <variable>BACKGROUNDIMAGE</variable>
	  ${BI_ITEMS}
    </combobox>
  </hbox>
  <hbox>
    <text><label>GTK theme (ref: usr/share/themes/*/gtk-2.0):</label></text>
    <combobox>
      <variable>GTKTHEME</variable>
	  ${GT_ITEMS}
    </combobox>
  </hbox>
  <hbox>
    <text><label>Desk icons (ref: usr/local/lib/X11/themes):</label></text>
    <combobox>
      <variable>DESKICONS</variable>
	  ${DI_ITEMS}
    </combobox>
  </hbox>
  <hbox>
    <text><label>JWM theme (ref: root/.jwm/themes):</label></text>
    <combobox>
      <variable>JWMTHEME</variable>
	  ${JT_ITEMS}
    </combobox>
  </hbox>
  <hbox>
    <text><label>Openbox theme (ref: usr/share/themes/*/openbox-3):</label></text>
    <combobox>
      <variable>OBTHEME</variable>
	  ${OB_ITEMS}
    </combobox>
  </hbox>
  <hbox>
   <button ok></button>
  </hbox>
 </vbox>
"

gtkdialog3 --center --program=MAIN_DIALOG


