From aee93b171377700e34eb4c0add59d430344e1886 Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Sat, 18 Feb 2006 07:35:40 +0000 Subject: [PATCH] tuxpaint-import shell script now examines Tux Paint's configuration file (first in /usr/local/etc/tuxpaint, then /etc/tuxpaint, then $HOME) for the window size settings and saved-file directory options (rather than assuming a 640x480 screen and images saved in $HOME/.tuxpaint/saved/). Discovered (or assumed) window size and directory settings are shown when tuxpaint-import is first run (even with no arguments). --- docs/CHANGES.txt | 9 +++ src/tuxpaint-import.sh | 133 +++++++++++++++++++++++++++++++---------- 2 files changed, 112 insertions(+), 30 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 713eaa125..5d7810a50 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -19,6 +19,15 @@ $Id$ back into 16-bit unicode characters to satisfy SDL_ttf. Tested on Windows and Linux.) John Popplewell + + * tuxpaint-import shell script now examines Tux Paint's configuration + file (first in /usr/local/etc/tuxpaint, then /etc/tuxpaint, then $HOME) + for the window size settings and saved-file directory options + (rather than assuming a 640x480 screen and images saved in + $HOME/.tuxpaint/saved/). + + Discovered (or assumed) window size and directory settings are shown + when tuxpaint-import is first run (even with no arguments). * Magic tool improvements: ------------------------ diff --git a/src/tuxpaint-import.sh b/src/tuxpaint-import.sh index 52e42c5e3..e7a575bcc 100755 --- a/src/tuxpaint-import.sh +++ b/src/tuxpaint-import.sh @@ -28,32 +28,51 @@ # September 21, 2002 - February 17, 2006 -SAVEDIR=$HOME/.tuxpaint/saved +SAVEDIR=$HOME/.tuxpaint TMPDIR=$SAVEDIR -if [ $# -eq 0 ]; then - # No arguments provided (sorry, you can't pipe into this script's stdin!) - echo "Usage: tuxpaint-import filename(s)" - echo " tuxpaint-import --help" - exit +if [ $# -ne 0 ]; then + if [ $1 = "--help" ]; then + # --help, show usage: + echo + echo "tuxpaint-import" + echo + echo "Imports an arbitrary image (GIF, JPEG, PNG, etc. format)" + echo "into Tux Paint (see: tuxpaint(1)) so that it appears in the" + echo "'Open' dialog." + echo + echo "Usage: tuxpaint-import filename(s)" + echo " tuxpaint-import --help" + echo + exit + fi fi -if [ $1 = "--help" ]; then - # --help, show usage: - echo - echo "tuxpaint-import" - echo - echo "Imports an arbitrary image (GIF, JPEG, PNG, etc. format)" - echo "into Tux Paint (see: tuxpaint(1)) so that it appears in the" - echo "'Open' dialog." - echo - echo "Usage: tuxpaint-import filename(s)" - echo " tuxpaint-import --help" - echo - exit + +# Determine preferred savedir + +# First, check /usr/local/etc/ +x=`grep -m 1 "^savedir=" /usr/local/etc/tuxpaint/tuxpaint.conf` +if test $? = 0 ; then + SAVEDIR=`echo $x | cut -d = -f 2-99` fi +# First, check /etc/ +x=`grep -m 1 "^savedir=" /etc/tuxpaint/tuxpaint.conf` +if test $? = 0 ; then + SAVEDIR=`echo $x | cut -d = -f 2-99` +fi + +# First, check $HOME +x=`grep -m 1 "^savedir=" $HOME/.tuxpaintrc` +if test $? = 0 ; then + SAVEDIR=`echo $x | cut -d = -f 2-99` +fi + + +echo "Using save directory: $SAVEDIR/saved" + # Make sure savedir exists! if [ ! -d $SAVEDIR ]; then @@ -61,10 +80,63 @@ if [ ! -d $SAVEDIR ]; then mkdir -p $SAVEDIR fi +# Make sure savedir/saved exists! +if [ ! -d $SAVEDIR/saved ]; then + echo "Creating $SAVEDIR/saved" + mkdir -p $SAVEDIR/saved +fi + # Make sure savedir thumbs directory exists! -if [ ! -d $SAVEDIR/.thumbs ]; then - echo "Creating $SAVEDIR/.thumbs" - mkdir -p $SAVEDIR/.thumbs +if [ ! -d $SAVEDIR/saved/.thumbs ]; then + echo "Creating $SAVEDIR/saved/.thumbs" + mkdir -p $SAVEDIR/saved/.thumbs +fi + + +# Determine appropriate size for images, based on Tux Paint's current +# configuration + +# First, assume 800x600 Tux Paint +window_width=800 +window_height=600 + +# First, check /usr/local/etc/ +x=`grep -m 1 "^windowsize=" /usr/local/etc/tuxpaint/tuxpaint.conf` +if test $? = 0 ; then + window_width=`echo $x | cut -d = -f 2 | cut -d x -f 1` + window_height=`echo $x | cut -d = -f 2 | cut -d x -f 2` +fi + +# First, check /etc/ +x=`grep -m 1 "^windowsize=" /etc/tuxpaint/tuxpaint.conf` +if test $? = 0 ; then + window_width=`echo $x | cut -d = -f 2 | cut -d x -f 1` + window_height=`echo $x | cut -d = -f 2 | cut -d x -f 2` +fi + +# First, check $HOME +x=`grep -m 1 "^windowsize=" $HOME/.tuxpaintrc` +if test $? = 0 ; then + window_width=`echo $x | cut -d = -f 2 | cut -d x -f 1` + window_height=`echo $x | cut -d = -f 2 | cut -d x -f 2` +fi + + +# (Image width is window width minus 192, +# image height is window height minus 104) + +width=`expr $window_width - 192` +height=`expr $window_height - 104` + + +echo "Using $width x $height images (for $window_width x $window_height Tux Paint" + +if [ $# -eq 0 ]; then + # No arguments provided (sorry, you can't pipe into this script's stdin!) + echo + echo "Usage: tuxpaint-import filename(s)" + echo " tuxpaint-import --help" + exit fi @@ -74,26 +146,27 @@ do if [ -e $i ]; then # Determine a filename for it: NEWFILENAME=`date "+%Y%m%d%H%M%S"` - echo "$i -> $SAVEDIR/$NEWFILENAME.png" + echo "$i -> $SAVEDIR/saved/$NEWFILENAME.png" # Convert and scale down, save as a temp file: - anytopnm $i | pnmscale -xysize 448 376 > $TMPDIR/$NEWFILENAME.ppm + anytopnm $i | pnmscale -xysize $width $height > $TMPDIR/saved/$NEWFILENAME.ppm # Place inside the correctly-sized canvas: # FIXME: Center, instead of placing at upper right - ppmmake "#FFFFFF" 448 376 \ - | pnmpaste -replace $TMPDIR/$NEWFILENAME.ppm 0 0 \ - | pnmtopng > $SAVEDIR/$NEWFILENAME.png + ppmmake "#FFFFFF" $width $height \ + | pnmpaste -replace $TMPDIR/saved/$NEWFILENAME.ppm 0 0 \ + | pnmtopng > $SAVEDIR/saved/$NEWFILENAME.png # Remove temp file: - rm $TMPDIR/$NEWFILENAME.ppm + rm $TMPDIR/saved/$NEWFILENAME.ppm # Create thumbnail for 'Open' dialog: - pngtopnm $SAVEDIR/$NEWFILENAME.png | pnmscale -xysize 92 56 \ - | pnmtopng > $SAVEDIR/.thumbs/$NEWFILENAME-t.png + pngtopnm $SAVEDIR/saved/$NEWFILENAME.png | pnmscale -xysize 92 56 \ + | pnmtopng > $SAVEDIR/saved/.thumbs/$NEWFILENAME-t.png else # File wasn't there! echo "$i - File not found" fi done +