Browse Source

Use zenity to select users and copy their tox ID to the clipboard

Bob Mottram 7 years ago
parent
commit
8481a701eb
1 changed files with 23 additions and 7 deletions
  1. 23
    7
      src/freedombone-image-customise

+ 23
- 7
src/freedombone-image-customise View File

@@ -887,6 +887,10 @@ function configure_user_interface {
887 887
     # for gtk dialog entry
888 888
     chroot "$rootdir" apt-get -yq install zenity
889 889
 
890
+    StrMeshUsers=$"Mesh Users"
891
+    StrUsername=$'Username'
892
+    StrToxID=$'Tox ID'
893
+
890 894
     # Produce a text file on the desktop listing users on the mesh
891 895
     cat <<EOF > $rootdir/usr/bin/list-tox-users
892 896
 #!/bin/bash
@@ -901,13 +905,25 @@ if [ \$no_of_users -gt 0 ]; then
901 905
     echo "\$users_list" > /tmp/Users.txt
902 906
     chown $MY_USERNAME:$MY_USERNAME /tmp/Users.txt
903 907
 
904
-    echo 'showing_users=\$(ps aux | grep $MESH_TEXT_EDITOR | grep "Users.txt")' > /home/$MY_USERNAME/showusers
905
-    echo 'if [ \${#showing_users} -eq 0 ]; then' >> /home/$MY_USERNAME/showusers
906
-    echo '    $MESH_TEXT_EDITOR /tmp/Users.txt' >> /home/$MY_USERNAME/showusers
907
-    echo 'fi' >> /home/$MY_USERNAME/showusers
908
-    echo 'exit 0' >> /home/$MY_USERNAME/showusers
909
-    chmod +x /home/$MY_USERNAME/showusers
910
-    chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/showusers
908
+    if [ ! -f /home/$MY_USERNAME/showusers ]; then
909
+        echo '#!/bin/bash' > /home/$MY_USERNAME/showusers
910
+        echo 'data=$(' >> /home/$MY_USERNAME/showusers
911
+        echo 'cat /tmp/Users.txt | \' >> /home/$MY_USERNAME/showusers
912
+        echo "    awk -F ' ' '{" >> /home/$MY_USERNAME/showusers
913
+        echo '        for(i=1;i<=NF;i++){' >> /home/$MY_USERNAME/showusers
914
+        echo '            print $i;' >> /home/$MY_USERNAME/showusers
915
+        echo '        }' >> /home/$MY_USERNAME/showusers
916
+        echo "}' | \\" >> /home/$MY_USERNAME/showusers
917
+        echo '    zenity --list \' >> /home/$MY_USERNAME/showusers
918
+        echo "     --title='$StrMeshUsers' \\" >> /home/$MY_USERNAME/showusers
919
+        echo "     --column='$StrUsername' --column='$StrToxID' \\" >> /home/$MY_USERNAME/showusers
920
+        echo '     --print-column=2 --hide-column=2 --width=250 --height=400)' >> /home/$MY_USERNAME/showusers
921
+        echo 'if [ ! $data ]; then' >> /home/$MY_USERNAME/showusers
922
+        echo '    exit 0' >> /home/$MY_USERNAME/showusers
923
+        echo 'fi' >> /home/$MY_USERNAME/showusers
924
+        echo 'echo "$data" | xclip -selection clipboard' >> /home/$MY_USERNAME/showusers
925
+        chmod +x /home/$MY_USERNAME/showusers
926
+    fi
911 927
 
912 928
     echo '[Desktop Entry]' > /home/$MY_USERNAME/Desktop/Users.desktop
913 929
     if [ \$no_of_users -lt 2 ]; then