--- alx-src/trunk/alxconfig-ng/functions/config_sessions.sh 2005/08/31 23:55:24 316 +++ alx-src/trunk/alxconfig-ng/functions/config_sessions.sh 2005/09/01 18:27:44 317 @@ -1,4 +1,4 @@ -# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.12 2005-08-28 22:50:09 niro Exp $ +# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.13 2005-09-01 18:27:44 niro Exp $ # configures ica-sessions on the host via mysql db settings get_sessions_settings() @@ -26,7 +26,12 @@ count=0 fi + # get settings from database + ALX_PROGRAMS=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'") + export ALX_SESSIONS + export ALX_PROGRAMS } get_autostart_settings() @@ -121,52 +126,94 @@ done } +# generates a sh file to start programs +generate_program_sh() +{ + local dest + local name + local exec + local workdir + + # very basic getops + for i in $* + do + case $1 in + --name|-n) shift; name="$1" ;; + --exec|-x) shift; exec="$1" ;; + --dest|-d) shift; dest="$1" ;; + --workdir|-w) shift; workdir="$1" ;; + esac + shift + done + + # abort if name, dest or exec not given + [ -z "${name}" ] && return 1 + [ -z "${exec}" ] && return 1 + [ -z "${dest}" ] && return 1 + + echo "#!/bin/sh" > ${dest} + [ -n "${workdir}" ] && echo "cd ${workdir}" >> ${dest} + echo "exec ${exec}" >> ${dest} + + chmod 0755 ${dest} +} + get_other_menuitems() { - local x i count name exec icon workdir + local x i progsh_path name exec icon workdir # all arrays: # -> session1 session2 ... sessionN - # get settings from database - count=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'") + # get settings from database -> now stored in ALX_PROGRAMS - # get all instances and put them into an array - if [ -n "${count}" ] - then - for x in ${count} - do - # to be sure - unset name - unset exec - unset workdir - unset icon - - name=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") - - exec=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") - - workdir=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") - - icon=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") - - # debug only - #echo "DEBUG: ${x}: name:'${name}' exec:'${exec}' workdir:'${workdir}' ic$ - - # now echo config line for fluxbox-menu - # make it "configureable" :P - [ -n "${workdir}" ] && workdir="cd ${workdir};" - [ -n "${icon}" ] && icon="[${icon}]" - echo "[exec] (${name}) {${workdir}${exec}} ${icon}" - done - fi -} + # abort if empty + [ -z "${ALX_PROGRAMS}" ] && return 0 + + progsh_path=${ALX_UNPRIV_HOME}/.alxprogs + [ -d ${progsh_path} ] && rm -rf ${progsh_path} + install -d ${progsh_path} + # gen menu items + for x in ${ALX_PROGRAMS} + do + # to be sure + unset name + unset exec + unset workdir + unset icon + + name=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") + + exec=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") + + workdir=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") + + icon=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") + + # debug only + #echo "DEBUG: ${x}: name:'${name}' exec:'${exec}' workdir:'${workdir}' ic$ + + # now echo config line for fluxbox-menu + # make it "configureable" :P + #[ -n "${workdir}" ] && workdir="cd ${workdir};" + [ -n "${workdir}" ] && workdir="--workdir ${workdir}" + [ -n "${icon}" ] && icon="<${icon}>" + + # gen prog startup wrapper + generate_program_sh \ + --name "${name}" \ + --exec "${exec}" \ + --dest "${progsh_path}/${name}" \ + "${workdir}" + + echo "[exec] (${name}) {${progsh_path}/${name}} ${icon}" + done +} # helper functions for generate all desktop icons generate_icon() @@ -179,6 +226,7 @@ local xres local iwidth local iheight + local deficon # very basic getops for i in $* @@ -192,6 +240,7 @@ --yres|-y) shift; yres="$1" ;; --icon-width|-w) shift; iwidth="$1" ;; --icon-height|-h) shift; iheight="$1" ;; + --default-icon) shift; deficon="$1" ;; esac shift done @@ -208,7 +257,9 @@ [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" if [ -z "${icon}" ] || [ ! -f "${icon}" ] then - icon="${ALX_SESSIONS_ICONS}/default.png" + # if no default icon is given use default.png + [ -z "${deficon}" ] && deficon="default.png" + icon="${ALX_SESSIONS_ICONS}/${deficon}" fi echo "table Icon" > ${dest} @@ -238,6 +289,7 @@ local x local y local item + local progsh_path # get the resolution res=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ @@ -293,7 +345,7 @@ generate_icon \ --name "${item}" \ - --command "wfica ${ALX_ICA_SESSIONS}/${item}.ica" \ + --command "${progsh_path}/${item}" \ --icon "${ALX_SESSIONS_ICONS}/${item}.png" \ --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \ --xres "${x}" \ @@ -303,6 +355,45 @@ done + # generate program icons + icon_list="${ALX_PROGRAMS}" + + progsh_path=${ALX_UNPRIV_HOME}/.alxprogs + + for item in ${icon_list} + do + # abort if empty + [ -z "${item}" ] && continue + + # new line if x > xres + if [ ${x} -ge ${xres} ];then + x=20 + y=$((${y} + 80)) + fi + + # new row if y > yres + if [ ${y} -ge ${yres} ];then + x=$((${x} + 120)) + y=20 + + # re-check x + [ ${x} -ge ${xres} ] && x=20 + fi + + generate_icon \ + --name "${item}" \ + --command "${progsh_path}/${item}" \ + --icon "${ALX_SESSIONS_ICONS}/${item}.png" \ + --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \ + --xres "${x}" \ + --yres "${y}" \ + --default-icon "default_item.png" + + y=$((${y} + 80)) + done + + + # last but not least gen a icon with some sys informations local sysinfo local hostname @@ -424,4 +515,5 @@ # unset vars unset ALX_SESSIONS + unset ALX_PROGRAMS }