slitaz-tools view tazdrop/tazdrop @ rev 586

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