slitaz-tools view tazdrop/tazdrop @ rev 807

Rewrite "desktopbox tazapps" using Yad (now "tazbox tazapps"), update pot and po; validate and normalize desktop files.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Jul 16 18:31:59 2013 +0300 (2013-07-16)
parents e9c74b6c3c6f
children e232f0e1413a
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 --dnd-image $(gettext "Display the desktop Drag N' Drop image")
38 --notes $(gettext "Display your dropped text notes")
40 EOT
41 }
43 # Write notes content type to a file
44 write_drop() {
45 sed "s/`echo -en '\r'` /\n/g" >> $NOTES << EOT
46 ====
47 $drop
48 EOT
49 }
51 # Get and install a package from an URL
52 get_install_pkg() {
53 tmp=$DOWNLOADS/$$
54 mkdir -p $tmp
55 $TERMINAL -hold -e "cd $tmp && wget $drop && \
56 su -c \"tazpkg install *.tazpkg && mv *.tazpkg .. && \
57 cd .. && rm -rf $tmp\"" &
58 }
60 # Main GUI function
61 drop_main() {
62 yad --text "$DROP_TEXT" \
63 --geometry="${DROP_SIZE}$DROP_GEOM" \
64 --name="tazdrop" --skip-taskbar \
65 --dnd --sticky --on-top \
66 --undecorated --no-buttons \
67 --command="$0"
68 }
70 # Image GUI function
71 drop_image() {
72 yad --image=$DROP_IMAGE \
73 --geometry="$DROP_IMAGE_GEOM" \
74 --name="tazdrop" --skip-taskbar \
75 --dnd --sticky --on-top \
76 --undecorated --no-buttons \
77 --command="$0"
78 }
80 # Notes GUI function
81 drop_notes() {
82 text=$(gettext "Edit or clean-up your dropped text notes")
83 yad --text-info --filename=$NOTES \
84 --title="Dropped Notes" --editable \
85 --image=text-editor --image-on-top \
86 --window-icon=/usr/share/pixmaps/slitaz-menu.png \
87 --text="$text" --margins=5 \
88 --width=500 --height=400 \
89 --button="gtk-remove:2" \
90 --button="gtk-save:0" \
91 --button="gtk-close:1"
92 }
94 #
95 # We may have args on cmdline, execute cmd & and exit.
96 #
97 case "$1" in
98 --usage|--help)
99 usage && exit 0 ;;
100 --dnd)
101 drop_main && exit 0 ;;
102 --dnd-image)
103 drop_image && exit 0 ;;
104 --notes)
105 drop_notes > /tmp/notes.$$
106 # Deal with --button
107 case $? in
108 1) continue ;;
109 0) mv -f /tmp/notes.$$ $NOTES ;;
110 2) echo "" > $NOTES ;;
111 esac
112 # Clean cache and exit
113 rm -f /tmp/notes.$$ && exit 0 ;;
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 $TERMINAL -e "su -c \"cd $dir && tazpkg install ${pkg%/}\"" & ;;
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 exec=$(fgrep Exec= "$file" | sed s'/Exec=//')
151 $exec & ;;
152 *)
153 # Can a directory dropped be tarbalized!
154 # Lets leave the tarball in the same directory.
155 file=${drop#file://}
156 if [ -d "$file" ]; then
157 cd $(dirname $file)
158 file=$(basename $file)
159 tar -c -j -f ${file}.tar.bz2 $file &
160 fi
161 # Or maybe an executable binary or script
162 if [ -x "$file" ]; then
163 $file &
164 fi
165 ;;
166 esac
167 ;;
168 http://*|https://*|ftp://*)
169 # Handle URL by filetype extension
170 case "$drop" in
171 *.png|*.jpg|*.jpeg|*.ico|*.gif|*.xpm|*.gz|*.bz2|*.lzma|*.xz| \
172 *.zip|*.pdf|*.iso)
173 $TERMINAL -e "cd $DOWNLOADS && wget $drop" & ;;
174 *.tazpkg)
175 get_install_pkg ;;
176 *.html|*.php|*.cgi|*.py|*.pl|*/|*[a-zA-Z0-9])
177 $BROWSER "$drop" & ;;
178 esac
179 ;;
180 *[a-z0-9]@[a-z0-9]*.[a-z]*)
181 # Handle email
182 exec $EMAIL "$drop" & ;;
183 --*)
184 usage && exit 0 ;;
185 *)
186 write_drop ;;
187 esac
189 exit 0