Kategoriern-Filter eingebaut

This commit is contained in:
io 2004-11-13 11:10:59 +00:00
parent 801486effc
commit 90255cea97

View file

@ -3,7 +3,8 @@
set -u set -u
KATEG_FILES="`dirname $0`/kategorien-norm.lst `dirname $0`/kategorien-debian.lst" 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" WRITE_DESKTOP_DIR="`dirname $0`/desktop-files"
#DATA_FILE="`dirname $0`/database.dat" #DATA_FILE="`dirname $0`/database.dat"
DATA_FILE="/tmp/database.dat" DATA_FILE="/tmp/database.dat"
@ -24,7 +25,7 @@ hole_app_liste()
# Parameter: app-name # Parameter: app-name
lade_app_kategs() 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" if [ -e "$DATA_FILE" ] && grep -q "^$1=" "$DATA_FILE"
then grep "^$1=" "$DATA_FILE" | cut -d "=" -f 2 then grep "^$1=" "$DATA_FILE" | cut -d "=" -f 2
else [ -e "$DDATEI" ] && grep "^Categories=" "$DDATEI" | cut -d "=" -f 2 | tr "\n" " " | tr ";" " " 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() 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 EINTRAEGE=`echo "$POST_DATA" | grep "^text_kategs_" | cut -d = -f 1 | sed 's/^text_kategs_//'`
local NEUE_KATEGS local NEUE_KATEGS
local APP_NAME local APP_NAME
@ -167,7 +188,7 @@ html_apps_config()
html_formular() html_formular()
{ {
echo -n '<FORM NAME="Kategorien-Zuordnung" METHOD="POST"' echo -n '<FORM NAME="Kategorien-Zuordnung" METHOD="POST"'
echo " ACTION=\"`basename $0`?action=speichern&app_start_nr=$1\">" echo " ACTION=\"`basename $0`?action=speichern&app_start_nr=$APP_START_NR\">"
echo "<TABLE BORDER=\"0\">" echo "<TABLE BORDER=\"0\">"
echo " <TR>" echo " <TR>"
echo " <TH>Programm</TH>" echo " <TH>Programm</TH>"
@ -177,12 +198,10 @@ html_formular()
echo " <TH>weitere Kategorie</TH>" echo " <TH>weitere Kategorie</TH>"
echo " </TR>" echo " </TR>"
local START=$1 local uebrig=$EINTRAEGE_PRO_SEITE
local i=$START echo -e "$ALLE_APPS" | sed 1,$((APP_START_NR-1))d | while [ $uebrig -gt 0 ] && read num name
local ENDE=$((START+EINTRAEGE_PRO_SEITE-1)) do html_apps_config $num
while [ $i -le $ENDE ] uebrig=$((uebrig-1))
do html_apps_config $i
i=$((i+1))
done done
echo "</TABLE>" echo "</TABLE>"
@ -191,10 +210,18 @@ html_formular()
} }
############# cgi-Zeug ############# ############# 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() hole_parameter()
{ {
set | grep -q "^QUERY_STRING" || return local ERG=$2
echo "$QUERY_STRING" | tr "&" "\n" | grep "^$1" | cut -d "=" -f 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! ############ ############# los geht es! ############
@ -204,16 +231,19 @@ html_header
ALLE_KATEGS=`hole_kateg_liste` ALLE_KATEGS=`hole_kateg_liste`
ALLE_APPS=`hole_app_liste` ALLE_APPS=`hole_app_liste`
ACTION=`hole_parameter action` KATEG_FILTER=`hole_parameter kateg_filter ""`
[ -z "$ACTION" ] && ACTION=formular [ -n "$KATEG_FILTER" ] && ALLE_APPS=`filter_apps_nach_kateg "$KATEG_FILTER"`
ACTION=`hole_parameter action formular`
case "$ACTION" in case "$ACTION" in
speichern|formular) speichern|formular)
[ "$ACTION" = "speichern" ] && speichere_formdaten [ "$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 html_footer
;; ;;
*) *)