slitaz-tools view tazdrop/tazdrop @ rev 560

tazdrop: tiny edits
author Paul Issott <paul@slitaz.org>
date Mon Apr 18 18:40:20 2011 +0100 (2011-04-18)
parents 1280698c3bf0
children e9c74b6c3c6f
line source
1 #!/bin/sh
2 #
3 # SliTaz Drag N' Drop tool! Just put whatever you want on the tiny box
4 # or the expanded panel and it will deal with it. Or at least it will
5 # try, since we are in the first stages of the tool.
6 #
7 # Copyright (C) 2011 SliTaz GNU/linux - BSD License
8 # - Christophe Lincoln <pankso@slitaz.org>
9 #
11 # Follow XDG standards
12 CONFIG=$HOME/.config/slitaz/tazdrop.conf
13 NOTES=$HOME/.cache/tazdrop.notes
15 [ ! -f "$CONFIG" ] && cp /etc/slitaz/tazdrop.conf $CONFIG
16 . $CONFIG
18 # Internationalization
19 . /usr/bin/gettext.sh
20 TEXTDOMAIN='tazdrop'
21 export TEXTDOMAIN
23 #
24 # Here are the functions
25 #
27 usage() {
28 cat << EOT
30 $(gettext "Usage:") $(basename $0) [--option|file|url]
32 $(gettext "Options:")
33 --usage $(gettext "Display this small help")
34 --dnd $(gettext "Display the desktop Drag N' Drop window")
35 --notes $(gettext "Display your dropped text notes")
37 EOT
38 }
40 # Write notes content type to a file
41 write_drop() {
42 sed "s/`echo -en '\r'` /\n/g" >> $NOTES << EOT
43 ====
44 $drop
45 EOT
46 }
48 # Get and install a package from an URL
49 get_install_pkg() {
50 tmp=$DOWNLOADS/$$
51 mkdir -p $tmp
52 $TERMINAL -hold -e "cd $tmp && wget $drop && \
53 su -c \"tazpkg install *.tazpkg && mv *.tazpkg .. && \
54 cd .. && rm -rf $tmp\"" &
55 }
57 # Main GUI function
58 drop_main() {
59 yad --text "$DROP_TEXT" \
60 --geometry="${DROP_SIZE}$DROP_GEOM" \
61 --name="tazdrop" \
62 --dnd --sticky --on-top \
63 --undecorated --no-buttons \
64 --command="$0"
65 }
67 # Image GUI function
68 drop_image() {
69 yad --image=$DROP_IMAGE \
70 --geometry="$DROP_GEOM" \
71 --name="tazdrop" \
72 --dnd --sticky --on-top \
73 --undecorated --no-buttons \
74 --command="$0"
75 }
77 # Notes GUI function
78 drop_notes() {
79 text=$(gettext "Edit or clean-up your dropped text notes")
80 yad --text-info --filename=$NOTES \
81 --title="Dropped Notes" --editable \
82 --image=text-editor --image-on-top \
83 --window-icon=/usr/share/pixmaps/slitaz-menu.png \
84 --text="$text" --margins=5 \
85 --width=500 --height=400 \
86 --button="gtk-remove:2" \
87 --button="gtk-save:0" \
88 --button="gtk-close:1"
89 }
91 #
92 # We may have args on cmdline, execute cmd & and exit.
93 #
94 case "$1" in
95 --usage|--help)
96 usage && exit 0 ;;
97 --dnd)
98 drop_main && exit 0 ;;
99 --dnd-image)
100 drop_image && exit 0 ;;
101 --notes)
102 drop_notes > /tmp/notes.$$
103 # Deal with --button
104 case $? in
105 1) continue ;;
106 0) mv -f /tmp/notes.$$ $NOTES ;;
107 2) echo "" > $NOTES ;;
108 esac
109 # Clean cache and exit
110 rm -f /tmp/notes.$$ && exit 0 ;;
111 *)
112 [ -z "$1" ] && usage && exit 0
113 drop="$1" && continue ;;
114 esac
116 #
117 # Drag and drop handler, uritype first filetype after.
118 #
119 # Use 'xdg-open' & 'xdg-mime query filetype /path/to/file',
120 # both need xprop (on slitaz we have obxprop from openbox)?
121 #
122 case "$drop" in
123 file:///*)
124 # Handle local files
125 case "$drop" in
126 *.png|*.jpg|*.jpeg|*.gif|*.xpm|*.ico)
127 $IMAGE "$drop" & ;;
128 *.txt|*.conf|*.css|*.php|*.cgi|*.list|*README*|*TODO| \
129 *.diff|*.log|*.js|*.xml|*receipt)
130 $EDITOR "$drop" & ;;
131 *.pdf)
132 $PDF "$drop" & ;;
133 *.html)
134 $BROWSER "$drop" & ;;
135 *.ogg|*.mp3)
136 file=${drop#file://}
137 $SOUND "$file" & ;;
138 *.tazpkg)
139 file=${drop#file://}
140 dir=$(dirname $file)
141 pkg=$(basename $file)
142 $TERMINAL -e "su -c \"cd $dir && tazpkg install ${pkg%/}\"" & ;;
143 *.desktop)
144 # Exec *.desktop files so they can be used in a non
145 # Freedesktop environment (Ex: Ob/tint2/emlfm2)
146 file=${drop#file://}
147 exec=$(fgrep Exec= "$file" | sed s'/Exec=//')
148 $exec & ;;
149 *)
150 # Can a directory dropped be tarbalized!
151 # Lets leave the tarball in the same directory.
152 file=${drop#file://}
153 if [ -d "$file" ]; then
154 cd $(dirname $file)
155 file=$(basename $file)
156 tar -c -j -f ${file}.tar.bz2 $file &
157 fi
158 # Or maybe an executable binary or script
159 if [ -x "$file" ]; then
160 $file &
161 fi
162 ;;
163 esac
164 ;;
165 http://*|https://*|ftp://*)
166 # Handle URL by filetype extension
167 case "$drop" in
168 *.png|*.jpg|*.jpeg|*.ico|*.gif|*.xpm|*.gz|*.bz2|*.lzma|*.xz| \
169 *.zip|*.pdf|*.iso)
170 $TERMINAL -e "cd $DOWNLOADS && wget $drop" & ;;
171 *.tazpkg)
172 get_install_pkg ;;
173 *.html|*.php|*.cgi|*.py|*.pl|*/|*[a-zA-Z0-9])
174 $BROWSER "$drop" & ;;
175 esac
176 ;;
177 *[a-z0-9]@[a-z0-9]*.[a-z]*)
178 # Handle email
179 exec $EMAIL "$drop" & ;;
180 --*)
181 usage && exit 0 ;;
182 *)
183 write_drop ;;
184 esac
186 exit 0