Reply To: bug in script desktop-menu? antiX 19.x 32bit/64bit

Forum › Forums › antiX-development › Development › bug in script desktop-menu? antiX 19.x 32bit/64bit › Reply To: bug in script desktop-menu? antiX 19.x 32bit/64bit

#82237
Robin
Member

    First sketch for the intended GUI bash script (doesn’t actually change anything at system, presently only infrastructure to handle and store some of the needed user specific settings, but prepared already to communicate with desktop-menu script. Translation resource not present at transifex yet.

    #!/bin/bash
    
    # GPL v3
    # Copyright 2022 the antiX comunity"  (Entry needed to comply with EU legislation)
    
    # antiX-menu-config
    # GUI tool to configure menu display options and menu update behaviour in antiX (and MX)
    
    # This program is free software: you can redistribute it and/or
    # modify it under the terms of the GNU General Public License as
    # published by the Free Software Foundation, either version 3 of
    # the License, or (at your option) any later version.
    
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    
    # You should have received a copy of the GNU General Public
    # License along with this program.  If not, see http://www.gnu.org/licenses/
    
    # written by Robin-antiX for the antiX community 4/2022
    
    # translations to foreign languages:
    # http://www.transifex.com/antix-linux-community-contributions/antix-contribs/antix-menu-config
    # to improve a poorly translated string for this script please sign in for free at transifex and join the translation team.
    
    # gettext translation config
    TEXTDOMAINDIR=/usr/share/locale
    TEXTDOMAIN=antix-menu-config
    
    # general settings
    config_folder="$HOME/.config/antiX-menu-config"
    config_file="$config_folder"/settings
    base_folder="/usr/share/antiX-menus"
    private_folder="$base_folder"/"$(whoami)"
    private_menus="$private_folder"/menu-applications
    key_upd="upd="
    key_disp="disp="
    menu_upd_select=(false false)
    menu_disp_select=(false false false false false false)
    opt_disp[0]="--Name"
    opt_disp[1]="--GenericName"
    opt_disp[2]="--Name --GenericName"
    opt_disp[3]="--Name --Comment"
    opt_disp[4]="--GenericName --Comment"
    opt_disp[5]="--Name --GenericName --Comment"
    opt_upd[0]="--write-out-global"
    opt_upd[1]="--write-out"
    
    function change_update_mode {
    	# under construction
    	echo "do something useful in here"
    }
    
    function apply_setting_disp {
    	# under construction
    	desktop-menu "${opt_upd[$setting_upd]}" "${opt_disp[$setting_disp]}"
    }
    
    function gui-dialog {
    menu_upd_select[$stored_upd]="true"
    menu_disp_select[$stored_disp]="true"
    userchoice="$(yad --plug=$$ --tabnum=1 --list --fixed --no-headers --no-borders \
    	--text="<b>"$"Menu Update Options""</b>\n"$"Applies to automatic updates only" \
    	--radiolist --no-selection --print-column=3 \
    	--column="" --column="Update Options":RB --column="":HD \
    	${menu_upd_select[0]} $"update menu globally (all users)" "0" \
    	${menu_upd_select[1]} $"update menu only for me ($(whoami))" "1" & \
    yad --plug=$$ --tabnum=2 --list --fixed --no-headers --no-borders \
    	--text="<b>"$"Menu Display Options""</b>\n"$"Applies to you only. Show:" \
    	--radiolist --no-selection --print-column=3 \
    	--column="" --column="Display Options":RB --column="":HD \
    	${menu_disp_select[0]} $"Name only" "0"\
    	${menu_disp_select[1]} $"Generic Name only" "1" \
    	${menu_disp_select[2]} $"Name and Generic Name" "2" \
    	${menu_disp_select[3]} $"Name and Comment" "3" \
    	${menu_disp_select[4]} $"Generic Name and Comment" "4" \
    	${menu_disp_select[5]} $"Name, Generic Name and Comment" "5" & \
    yad --title="Menu Options" --center --fixed --undecorated \
    	--width=600 --borders=20 --no-borders --window-icon=gtk-preferences \
    	--paned --key=$$ --orient=hor --splitter=280 \
    	--button=$"Don't apply changes":5 --button=$"Apply changes":6)"
    
    #echo "$userchoice"
    }
    
    function read_stored_settings {
    	if [ -e "$config_file" ]; then
    		stored_upd=$(sed -n "s/^"$key_upd"\([[:digit:]]\)/\1/p" "$config_file")
    		stored_disp=$(sed -n "s/^"$key_disp"\([[:digit:]]\)/\1/p" "$config_file")
    	else
    		if [ $(ls -l /home | grep ^d | wc -l) -le 3 ]; then
    			stored_upd=0
    		else
    			stored_upd=1
    		fi
    		stored_disp=0
    		[ ! -d "$config_folder" ] && mkdir -p "$config_folder"
    		echo "$key_upd=$stored_upd" > "$config_file"
    		echo "$key_disp=$stored_disp" >> "$config_file"
    	fi		
    }
    
    function write_settings_file {
    sed -i "s/^$key_upd..*$/$key_upd$setting_upd/" "$config_file"
    sed -i "s/^$key_disp..*$/$key_disp$setting_disp/" "$config_file"	
    }
    
    function analyse_results {
    if [ "$userchoice" != "" ]; then
    	setting_upd="$(echo $userchoice | tr -d ' \n\r' | cut -d'|' -f1)"
    	setting_disp="$(echo $userchoice | tr -d ' \n\r' | cut -d'|' -f2)"
    else
    	echo "user abort"
    	exit 0
    fi
    }
    
    read_stored_settings
    gui-dialog
    analyse_results
    write_settings_file
    #change_update_mode
    #apply_setting_disp
    
    echo "${opt_upd[$setting_upd]}"
    echo "${opt_disp[$setting_disp]}"
    
    exit 0

    I didn’t include Marcelos proposal for additional entries for languages following different word orders by now. This would make things to much more confusing when testing, and some additional entries like that can get added later easily, once the whole thing works stable. (Moreover we still need to find out whether IceWM and the other WMs would accept different orders within entries-texts before we could add them here.)

    While running, the script will create the ~/.config/antiX-menus-config subdirectory within your home folder to store your personal menu settings, and read it from there on next time it is started.
    (Remark: The paths stored in the variables $base_folder, $private_folder and $private_menus are unused by now.)

    @Dave : To proceed from here with this GUI script I’d need to know whether or how the default symbolic link in the users homes will be changed by antiX solving the original problem and its followup. I’ve described most detailed a possible solution some postings above.

    Windows is like a submarine. Open a window and serious problems will start.