slitaz-tools view tazdrop/tazdrop @ rev 939

tazbox: fix subox icon when ~/.local/share/applications is absent; fix working with freegeoip; write full list of icons used; all other files: 2015 and insert blank lines.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Apr 17 07:35:02 2015 +0300 (2015-04-17)
parents c79e656b37a5
children
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-2015 SliTaz GNU/linux - BSD License
8 # - Christophe Lincoln <pankso@slitaz.org>
9 #
11 . /lib/libtaz.sh
12 export TEXTDOMAIN='tazdrop' # i18n
15 # Follow XDG standards
17 CONFIG=$HOME/.config/slitaz/tazdrop.conf
18 NOTES=$HOME/.cache/tazdrop.notes
20 [ ! -f "$CONFIG" ] && cp /etc/slitaz/tazdrop.conf $CONFIG
21 . $CONFIG
23 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
26 #
27 # Functions
28 #
30 usage() {
31 newline; _ 'SliTaz Drag N Drop tool'
33 newline; boldify "$(_ 'Usage:')"
34 echo " $(basename $0) [--$(_n 'option')|$(_n 'file')|$(_n 'URL')]"
36 newline; boldify "$(_ 'Options:')"
37 optlist "\
38 --usage|-h|--help $(_ 'Display this small help')
39 --dnd $(_ 'Display the desktop Drag N Drop window')
40 --image $(_ 'Display the desktop Drag N Drop image')
41 --notes $(_ 'Display your dropped text notes')"
42 newline
43 }
46 # Write notes content type to a file
48 write_drop() {
49 sed "s/$(echo -en '\r') /\n/g" >> $NOTES << EOT
50 ====[ $(date '+%x %X') ]====
51 $drop
52 EOT
53 }
56 # Get and install a package from an URL
58 get_install_pkg() {
59 tmp=$DOWNLOADS/$$
60 mkdir -p $tmp
61 cd $tmp
62 wget $drop
63 su -c "tazpkg install *.tazpkg && mv *.tazpkg .. && cd .. && rm -rf $tmp"
64 }
67 # Main GUI function
69 drop_main() {
70 yad --geometry="$DROP_SIZE$DROP_GEOM" \
71 --sticky --on-top --skip-taskbar --undecorated --no-buttons \
72 --text "$DROP_TEXT" \
73 --name="tazdrop" \
74 --dnd \
75 --command="$0"
76 }
79 # Image GUI function
81 drop_image() {
82 yad --geometry="$DROP_IMAGE_GEOM" \
83 --sticky --on-top --skip-taskbar --undecorated --no-buttons \
84 --image=$DROP_IMAGE \
85 --name="tazdrop" \
86 --dnd \
87 --command="$0"
88 }
91 # Notes GUI function
93 drop_notes() {
94 icon='text-editor'
95 yad --title="$(_ 'Dropped Notes')" --window-icon=$icon \
96 --width=500 --height=400 --margins=5 \
97 --image=$icon --image-on-top \
98 --text-info --editable --filename=$NOTES \
99 --text="$(_ 'Edit or clean-up your dropped text notes')" \
100 --button="gtk-remove:2" \
101 --button="gtk-save:0" \
102 --button="gtk-close:1"
103 }
106 #
107 # We may have args on cmdline, execute cmd & and exit.
108 #
110 case "$1" in
111 --usage|-h|--help)
112 usage && exit 0 ;;
113 --dnd)
114 drop_main && exit 0 ;;
115 --image)
116 drop_image && exit 0 ;;
117 --notes)
118 drop_notes > /tmp/notes.$$
119 # Deal with --button
120 case $? in
121 1) continue ;;
122 0) mv -f /tmp/notes.$$ $NOTES ;;
123 2) echo "" > $NOTES ;;
124 esac
125 # Clean cache and exit
126 rm -f /tmp/notes.$$ && exit 0 ;;
127 get_install_pkg)
128 get_install_pkg ;;
129 *)
130 [ -z "$1" ] && usage && exit 0
131 drop="$1" && continue ;;
132 esac
135 #
136 # Drag and drop handler, uritype first filetype after.
137 #
138 # Use 'xdg-open' & 'xdg-mime query filetype /path/to/file',
139 # both need xprop (on slitaz we have obxprop from openbox)?
140 #
142 case "$drop" in
143 file:///*)
144 # Handle local files
145 case "$drop" in
146 *.png|*.jpg|*.jpeg|*.gif|*.xpm|*.ico)
147 $IMAGE "$drop" & ;;
148 *.txt|*.conf|*.css|*.php|*.cgi|*.list|*README*|*TODO| \
149 *.diff|*.log|*.js|*.xml|*receipt)
150 editor "$drop" & ;;
151 *.pdf)
152 $PDF "$drop" & ;;
153 *.html)
154 browser "$drop" & ;;
155 *.ogg|*.mp3)
156 file=${drop#file://}
157 $SOUND "$file" & ;;
158 *.tazpkg)
159 file=${drop#file://}
160 dir=$(dirname $file)
161 pkg=$(basename $file)
162 tazbox su tazpkg actions $file ;;
163 *.desktop)
164 # Exec *.desktop files so they can be used in a non
165 # Freedesktop environment (Ex: Ob/tint2/emlfm2)
166 file=${drop#file://}
167 # FIXME: should process all other stuff from .desktop file!
168 exec=$(fgrep Exec= "$file" | sed s'/Exec=//')
169 $exec & ;;
170 *)
171 # Can a directory dropped be tarbalized!
172 # Lets leave the tarball in the same directory.
173 file=${drop#file://}
174 if [ -d "$file" ]; then
175 cd $(dirname $file)
176 file=$(basename $file)
177 tar -c -j -f ${file}.tar.bz2 $file &
178 fi
179 # Or maybe an executable binary or script
180 if [ -x "$file" ]; then
181 $file &
182 fi
183 ;;
184 esac
185 ;;
186 http://*|https://*|ftp://*)
187 # Handle URL by filetype extension
188 case "$drop" in
189 *.png|*.jpg|*.jpeg|*.ico|*.gif|*.xpm|*.gz|*.bz2|*.lzma|*.xz| \
190 *.zip|*.pdf|*.iso)
191 terminal -e "cd $DOWNLOADS && wget $drop" & ;;
192 *.tazpkg)
193 terminal -hold -e $0 get_install_pkg ;;
194 *.html|*.php|*.cgi|*.py|*.pl|*/|*[a-zA-Z0-9])
195 browser "$drop" & ;;
196 esac
197 ;;
198 *[a-z0-9]@[a-z0-9]*.[a-z]*)
199 # Handle email
200 exec $EMAIL "$drop" & ;;
201 --*)
202 usage && exit 0 ;;
203 *)
204 write_drop ;;
205 esac
207 exit 0