From 90255cea979a8db7b2670f34ac63661e5acdde36 Mon Sep 17 00:00:00 2001 From: io <> Date: Sat, 13 Nov 2004 11:10:59 +0000 Subject: [PATCH] Kategoriern-Filter eingebaut --- gnome-menu/viertversuch/manage-kategs.sh | 64 +++++++++++++++++------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/gnome-menu/viertversuch/manage-kategs.sh b/gnome-menu/viertversuch/manage-kategs.sh index ddab4da..d2efecb 100755 --- a/gnome-menu/viertversuch/manage-kategs.sh +++ b/gnome-menu/viertversuch/manage-kategs.sh @@ -3,7 +3,8 @@ set -u KATEG_FILES="`dirname $0`/kategorien-norm.lst `dirname $0`/kategorien-debian.lst" -READ_DESKTOP_DIR="/var/lib/menu-xdg/applications/menu-xdg" +#READ_DESKTOP_DIR="/var/lib/menu-xdg/applications/menu-xdg" +READ_DESKTOP_DIR="/usr/share/applications" WRITE_DESKTOP_DIR="`dirname $0`/desktop-files" #DATA_FILE="`dirname $0`/database.dat" DATA_FILE="/tmp/database.dat" @@ -24,7 +25,7 @@ hole_app_liste() # Parameter: app-name lade_app_kategs() { - DDATEI="$READ_DESKTOP_DIR/$1.desktop" + DDATEI=`find $READ_DESKTOP_DIR -type f -name $1.desktop` if [ -e "$DATA_FILE" ] && grep -q "^$1=" "$DATA_FILE" then grep "^$1=" "$DATA_FILE" | cut -d "=" -f 2 else [ -e "$DDATEI" ] && grep "^Categories=" "$DDATEI" | cut -d "=" -f 2 | tr "\n" " " | tr ";" " " @@ -69,9 +70,29 @@ hole_verwandte_kategs_der_app() } +hole_anzahl_apps() +{ + echo "$ALLE_APPS" | wc -l +} + + +# entfernt alle Apps, die nicht in der angegebenen Kategorie sind +# Parameter: - die Kategorie +# - die Anwendungen +filter_apps_nach_kateg() +{ + local KATEG="$1" + shift + echo -e "$ALLE_APPS" | while read num name + do lade_app_kategs "$name" | grep -q "$KATEG" && echo -e "$num\t$name" + done +} + + + speichere_formdaten() { - local POST_DATA=`cat - | tr "&" "\n" | tee /tmp/out` + local POST_DATA=`cat - | tr "&" "\n"` local EINTRAEGE=`echo "$POST_DATA" | grep "^text_kategs_" | cut -d = -f 1 | sed 's/^text_kategs_//'` local NEUE_KATEGS local APP_NAME @@ -167,7 +188,7 @@ html_apps_config() html_formular() { echo -n '
" + echo " ACTION=\"`basename $0`?action=speichern&app_start_nr=$APP_START_NR\">" echo "" echo " " echo " " @@ -177,12 +198,10 @@ html_formular() echo " " echo " " - local START=$1 - local i=$START - local ENDE=$((START+EINTRAEGE_PRO_SEITE-1)) - while [ $i -le $ENDE ] - do html_apps_config $i - i=$((i+1)) + local uebrig=$EINTRAEGE_PRO_SEITE + echo -e "$ALLE_APPS" | sed 1,$((APP_START_NR-1))d | while [ $uebrig -gt 0 ] && read num name + do html_apps_config $num + uebrig=$((uebrig-1)) done echo "
Programmweitere Kategorie
" @@ -191,10 +210,18 @@ html_formular() } ############# cgi-Zeug ############# + +# liest einen cgi-Parameter ein und liefert notfalls einen angegebenen Default-Wert zurueck +# Parameter: der Name des Parameters und der default-Wert hole_parameter() { - set | grep -q "^QUERY_STRING" || return - echo "$QUERY_STRING" | tr "&" "\n" | grep "^$1" | cut -d "=" -f 2 + local ERG=$2 + if set | grep -q "^QUERY_STRING" + then ERG=`echo "$QUERY_STRING" | tr "&" "\n" | grep "^$1" | cut -d "=" -f 2` + else ERG="$2" + fi + [ -z "$ERG" ] && ERG="$2" + echo -e "$ERG" } ############# los geht es! ############ @@ -204,16 +231,19 @@ html_header ALLE_KATEGS=`hole_kateg_liste` ALLE_APPS=`hole_app_liste` -ACTION=`hole_parameter action` -[ -z "$ACTION" ] && ACTION=formular +KATEG_FILTER=`hole_parameter kateg_filter ""` +[ -n "$KATEG_FILTER" ] && ALLE_APPS=`filter_apps_nach_kateg "$KATEG_FILTER"` + + +ACTION=`hole_parameter action formular` case "$ACTION" in speichern|formular) [ "$ACTION" = "speichern" ] && speichere_formdaten - APP_START_NR=`hole_parameter app_start_nr` - [ -z "$APP_START_NR" ] && APP_START_NR=1 - html_formular $APP_START_NR + APP_START_NR=`hole_parameter app_start_nr 1` + + html_formular html_footer ;; *)