slitaz-tools view tazdrop/tazdrop @ rev 933

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