Trash for Ice

Stuff that has yet to be sorted into a category.
Message
Author
GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#21 Post by GuestToo »

putting these lines in AppRun:

APPDIR=`dirname "$0"`
cd "$APPDIR"
APPDIR="`pwd`"

should set $APPDIR to the dir AppRun is in
although you can have problems if the dir has spaces in the name

so a copy command like this should work:

cp -f "$APPDIR/trashcan_empty.png" "$APPDIR/.DirIcon"

or since you have already cd'ed to $APPDIR, maybe:

cp -f trashcan_empty.png .DirIcon

(the reason to cd to $APPDIR then `pwd`, is to make the path in $APPDIR absolute, rather than relative ... if you don't care if the path is absolute or relative, then
APPDIR=`dirname "$0"`
would probably work)

(export APPDIR if you need $APPDIR in sub-processes)

i don't know if there's a practical way to get the icon to refresh ... restarting the pinboard should work, kinda drastic though

maybe the -x option works (type rox -h for help)
something like:
rox -x .DirIcon
or:
rox -x "$APPDIR/.DirIcon"

User avatar
dvw86
Posts: 636
Joined: Thu 05 May 2005, 00:55
Location: Washington State

#22 Post by dvw86 »

I have updated the application to automatically create /root/.Trash if it does not already exist. The trash icon will now change based on if it is full or empty. It also does not matter where the application resides. In order to automatically update the icon I automatically restart the Pinboard. On my system this just causes a slight flicker of the desktop icons. I have not seen any ill side effects. Please let me know if there are any issues with doing this. It may take longer on slower systems. I could not get rox -x "$APPDIR/.DirIcon" to work.
Here is the code.

Code: Select all

#!/bin/sh
# July 2, 2005 - Dan Van Wormer - Puppy Linux

# Create the >Trash directory if it does not already exist.
[ -d /root/.Trash ] || mkdir /root/.Trash

# Determine the path to this application.
APPDIR=`dirname "$0"`
cd "$APPDIR"
APPDIR="`pwd`" 

# Check to see if they clicked on the application or sent a file or directory to be deleted.
test -sd "$@"
if [ "$?" = "0" ]
then
exec rox /root/.Trash
else mv "$@" /root/.Trash/
cp -f "$APPDIR/trashcan_full.png" "$APPDIR/.DirIcon" 
rox -o -p /root/Choices/ROX-Filer/PuppyPin
fi

# If they chose the "Empty the Trash" option.
if [ "$1" = "-empty" ]
then
rm -r /root/.Trash/*
cp -f "$APPDIR/trashcan_empty.png" "$APPDIR/.DirIcon" 
rox -o -p /root/Choices/ROX-Filer/PuppyPin
fi
EDIT File removed. Download final copy here
Last edited by dvw86 on Tue 19 Jul 2005, 00:10, edited 1 time in total.

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#23 Post by GuestToo »

i haven't tried your latest version, but if you restart the pinboard from a dir other than $HOME, it might change what rox thinks is $HOME

you might want to check that when you click the rox icon, it opens a window showning $HOME (/root) and that clicking the home button goes to /root

in other words, if might be better to
cd ${HOME}
before restarting the pinboard

also, if someone is using a non-standard pinboard
(i once had 3 or 4 desktops, with icons to flip from one to another ... rox -op 1 ... rox -op 2 ... rox -op 3), your program would switch from the non-standard pinboard to the standard Puppy pinboard

which is probably not important, but it is another thing to think about when you write a program

User avatar
dvw86
Posts: 636
Joined: Thu 05 May 2005, 00:55
Location: Washington State

#24 Post by dvw86 »

GuestToo wrote:i haven't tried your latest version, but if you restart the pinboard from a dir other than $HOME, it might change what rox thinks is $HOME

you might want to check that when you click the rox icon, it opens a window showning $HOME (/root) and that clicking the home button goes to /root

in other words, if might be better to
cd ${HOME}
before restarting the pinboard
I have tested it on two systems so far and rox still goes to /root as $HOME so it shouldn't be an issue but I will add cd ${HOME} just to be on the safe side.

Puppy running on my iBook in Virtual PC is equivalent to a 200MHz PII or slower. Restarting the Pinboard on that system is definitely more than just a flicker. I may have two versions of Trash. One for faster hardware (my 800MHz VIA for example) that restarts the Pinboard, and another for slower hardware (200MHz and less) that requires you to mouse over the icon for it to be updated. The last thing to work on is the numerical increments of duplicate names in the trash. Once that is done (if I can get it to work :oops: ) I will put it into a DotPup and post it on the Wiki.

User avatar
dvw86
Posts: 636
Joined: Thu 05 May 2005, 00:55
Location: Washington State

#25 Post by dvw86 »

Well I think this is it. I had to change the logic a little because it was changing the icon twice when emptying the trash. While this didn't hurt anything it made things just that much slower on older hardware. It will now add a unique number to the end of anything being sent to the Trash. This is to prevent files from being over written. When right clicking the trash icon you now have two choices. The first choice (Empty the Trash) will display every thing in the Trash and ask for confirmation before deleting them. The second option (Quickly Empty the Trash) does not display a list of items and does not ask for confirmation. Lastly it also plays a little sound when things are sent to the Trash and when the Trash is emptied. If this meets with approval I will make it a Dotpup and also a Simple-Trash Dotpup that does not restart the pinboard and does not have the sound file. Here is the code.

Code: Select all

#!/bin/sh
# July 4, 2005 - Dan Van Wormer - Puppy Linux

# Create the >Trash directory if it does not already exist.
[ -d /root/.Trash ] || mkdir /root/.Trash

# Determine the path to this application.
APPDIR=`dirname "$0"`
cd "$APPDIR"
APPDIR="`pwd`" 

# If they chose the "Empty the Trash" option.
if [ "$1" = "-empty" ]
	then

	# See what is in the trash.
	stuff=`ls /root/.Trash`

	# Wright the confirmation message.
	MSG=`which gxmessage` || MSG=xmessage
	$MSG -buttons "Delete:21,Cancel" -center -geometry 300x300 -title 	"Confirm Delete" "$stuff"

	# If they chose to cancel.
	[ $? -eq 21 ] || exit

	# If they chose to delete.
	rm -r /root/.Trash/*
	cp -f "$APPDIR/trashcan_empty.png" "$APPDIR/.DirIcon"
	cd ${HOME} 
	rox -o -p /root/Choices/ROX-Filer/PuppyPin
	play.tcl $APPDIR/systemmsg.wav

		# If they chose to "Quickly Empty the Trash".
		elif [ "$1" = "-empty-quick" ]
		then
		rm -r /root/.Trash/*
		cp -f "$APPDIR/trashcan_empty.png" "$APPDIR/.DirIcon"
		cd ${HOME} 
		rox -o -p /root/Choices/ROX-Filer/PuppyPin
		play.tcl $APPDIR/systemmsg.wav
		
			else
			# Check to see if they clicked on the application or sent a file or directory to be deleted.
			test -sd "$@"
				if [ "$?" = "0" ]
				then

				# If they just clicked on the icon.
				exec rox /root/.Trash
					else 

					# If they sent something to the trash can.
					mv "$@" "$@-$$"
					mv "$@-$$" "/root/.Trash/"
					cp -f "$APPDIR/trashcan_full.png" "$APPDIR/.DirIcon" 
					cd ${HOME}
					rox -o -p /root/Choices/ROX-Filer/PuppyPin
					play.tcl $APPDIR/systemmsg.wav
				fi

		fi

fi

EDIT File removed. Download final copy here
Last edited by dvw86 on Tue 19 Jul 2005, 00:11, edited 1 time in total.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#26 Post by Flash »

Just let me know when it's ready for the index.

User avatar
papaschtroumpf
Posts: 250
Joined: Fri 17 Jun 2005, 04:23

#27 Post by papaschtroumpf »

does it work for non-root users?
Mandriva LE 2005 user and puppy newbie

User avatar
dvw86
Posts: 636
Joined: Thu 05 May 2005, 00:55
Location: Washington State

#28 Post by dvw86 »

papaschtroumpf wrote:does it work for non-root users?
To tell the truth I don't know since you always run as root in Puppy. As long as the application can read and write to /root it should work.

User avatar
dvw86
Posts: 636
Joined: Thu 05 May 2005, 00:55
Location: Washington State

#29 Post by dvw86 »

The "Complete Trash" application has been posted in the Dotpup thread.
http://www.murga.org/~puppy/viewtopic.php?p=5309#5309

User avatar
papaschtroumpf
Posts: 250
Joined: Fri 17 Jun 2005, 04:23

#30 Post by papaschtroumpf »

dvw86 wrote:
papaschtroumpf wrote:does it work for non-root users?
To tell the truth I don't know since you always run as root in Puppy. As long as the application can read and write to /root it should work.
Then the answer is no.
Or if the app has access to /root then it's a security risk (probably mean a user could see and erase root's trash files, no good).
Mandriva LE 2005 user and puppy newbie

User avatar
dvw86
Posts: 636
Joined: Thu 05 May 2005, 00:55
Location: Washington State

#31 Post by dvw86 »

papaschtroumpf wrote: Then the answer is no.
Or if the app has access to /root then it's a security risk (probably mean a user could see and erase root's trash files, no good).
Since you always run as root in Puppy I don't really see it as an issue, but you could easily change where the hidden trash file resides. For instance /usr/X11R6 or you could have a trash file for every user in their home account..

User avatar
dvw86
Posts: 636
Joined: Thu 05 May 2005, 00:55
Location: Washington State

#32 Post by dvw86 »

Well "Trash" seams to be fairly well received. (down loaded 19 times so far) I am working on the next upgrade. I gave it the ability to move multiple items to the trash simultaneously. Now I would like it to test and see if anything is using the sound card and skip playing the trash sound file if the sound card is already in use. Does any one know how to see if another application is using the sound card? Otherwise I will just have to test for all popular sound apps individually, which I would rather not do. Thanks

User avatar
dvw86
Posts: 636
Joined: Thu 05 May 2005, 00:55
Location: Washington State

How to detect if an app is already using the audio

#33 Post by dvw86 »

I figured it out. Here is the code that I will be using to test if the sound file will cause problems.

Code: Select all

# See if /dev/dsp is in use. If it is then do not play the sound file.
		fuser /dev/dsp
		if [ $? -eq 0 ];then #=0 if found.
			exit
			else
 			play.tcl $APPDIR/systemmsg.wav
		fi
		exit

Post Reply