57
44
# Files in the Templates directory are deliberately ignored
58
46
test -f ${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs && source ${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs
59
48
if [ "`dirname "$ifile"`" == "${XDG_TEMPLATES_DIR:-$HOME/Templates}" ]; then
60
49
echo "Ignoring files in XDG templates directory"
64
mime=`file "$ifile" --mime-type --brief` # mime-type of $ifile
66
# This function sets the $icon variable according to mime-type
53
# This function prints the filename of the appropriate icon according to mime-type
68
function set_icon_variable {
69
58
case "`file "$1" --mime-type --brief`" in
70
59
application/vnd.oasis.opendocument.text | \
71
60
application/vnd.sun.xml.writer | \
72
61
application/vnd.sun.xml.writer.global | \
73
62
application/msword | \
74
63
application/vnd.openxmlformats-officedocument.wordprocessingml.document)
75
icon=openofficeorg3-oasis-text.png
77
66
application/vnd.oasis.opendocument.presentation | \
78
67
application/vnd.sun.xml.impress | \
79
68
application/vnd.ms-powerpoint | \
80
69
application/vnd.openxmlformats-officedocument.presentationml.presentation)
81
icon=openofficeorg3-oasis-presentation.png
70
icon=oasis-presentation.png
83
72
application/vnd.oasis.opendocument.graphics | \
84
73
application/vnd.sun.xml.draw)
85
icon=openofficeorg3-oasis-drawing.png
74
icon=oasis-drawing.png
87
76
application/vnd.oasis.opendocument.spreadsheet | \
88
77
application/vnd.sun.xml.calc | \
89
78
application/vnd.ms-excel | \
90
79
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
91
icon=openofficeorg3-oasis-spreadsheet.png
80
icon=oasis-spreadsheet.png
93
82
application/vnd.oasis.opendocument.presentation-template | \
94
83
application/vnd.sun.xml.impress.template)
95
icon=openofficeorg3-oasis-presentation-template.png
84
icon=oasis-presentation-template.png
97
86
application/vnd.oasis.opendocument.spreadsheet-template | \
98
87
application/vnd.sun.xml.calc.template)
99
icon=openofficeorg3-oasis-spreadsheet-template.png
88
icon=oasis-spreadsheet-template.png
101
90
application/vnd.oasis.opendocument.text-template | \
102
91
application/vnd.sun.xml.writer.template)
103
icon=openofficeorg3-oasis-text-template.png
92
icon=oasis-text-template.png
105
94
application/vnd.oasis.opendocument.text-master)
106
icon=openofficeorg3-oasis-master-document.png
95
icon=oasis-master-document.png
108
97
application/vnd.oasis.opendocument.graphics-template | \
109
98
application/vnd.sun.xml.draw.template)
110
icon=openofficeorg3-oasis-drawing-template.png
99
icon=oasis-drawing-template.png
112
101
application/vnd.oasis.opendocument.chart)
113
icon=openofficeorg3-oasis-drawing.png
102
icon=oasis-drawing.png
115
104
application/vnd.oasis.opendocument.image)
116
icon=openofficeorg3-oasis-drawing.png
105
icon=oasis-drawing.png
118
107
application/vnd.oasis.opendocument.formula | \
119
108
application/vnd.sun.xml.math)
120
icon=openofficeorg3-oasis-formula.png
109
icon=oasis-formula.png
124
113
case "${ext,,}" in
126
icon=openofficeorg3-oasis-drawing.png
129
icon=openofficeorg3-oasis-text.png
132
icon=openofficeorg3-oasis-spreadsheet.png
115
icon=oasis-drawing.png
117
docx | doc | odt | sxw)
120
xls | xlsx | ods | sxc)
121
icon=oasis-spreadsheet.png
134
123
ppt | pptx | sxi | odp)
135
icon=openofficeorg3-oasis-presentation.png
124
icon=oasis-presentation.png
138
icon=openofficeorg3-oasis-drawing-template.png
127
icon=oasis-drawing-template.png
141
icon=openofficeorg3-oasis-presentation-template.png
130
icon=oasis-presentation-template.png
144
icon=openofficeorg3-oasis-text-template.png
133
icon=oasis-text-template.png
147
icon=openofficeorg3-oasis-master-document.png
136
icon=oasis-master-document.png
150
icon=openofficeorg3-oasis-spreadsheet-template.png
139
icon=oasis-spreadsheet-template.png
153
icon=openofficeorg3-oasis-formula.png
142
icon=oasis-formula.png
156
145
echo "Unsupported file type (file: $1 extension: $ext mime-type:`file "$1" --mime-type --brief`)" 1>&2
160
icon=/usr/share/icons/hicolor/32x32/mimetypes/$icon
150
prefix=/usr/share/icons/hicolor/32x32/mimetypes
151
for match in "$prefix/openofficeorg3-$icon" "$prefix/libreoffice"*"-$icon" ; do
152
if [ -e "$match" ] ; then
153
printf '%s\n' "$match"
163
# This function tries to use gsf-office-thumbnailer, overlaying an
164
# OpenOffice.org icon on the thumbnail, and returns an appropriate
160
# This function tries to use gsf-office-thumbnailer, and returns an appropriate
166
162
# arguments: file thumbnail-file
167
163
function try_gsf_thumbnailer {
171
167
# gsf-office-thumbnailer is buggy when it comes to Excel files
174
if gsf-office-thumbnailer -i "$1" -o "$2" -s "${size:-128}"; then
175
set_icon_variable "$1"
176
if [ -x /usr/bin/composite ] && [ -e "$icon" ]; then
177
convert "$2" -background white -flatten -scale ${size:-128}x${size:-128} "png:-" | composite -gravity SouthEast "$icon" - "$2"
184
try_gsf_thumbnailer "$ifile" "$ofile" && exit 0
186
# If script continues past this point then gsf-office-thumbnailer
187
# has been unsuccessful.
189
# If file is in Microsoft Office format, convert the
190
# file to OpenOffice.org format and use that new temporary file
191
iextension=$(expr "$ifile" : '.*\(....\)')
192
iextension=${iextension,,}
193
if [ "$mime" == application/vnd.ms-powerpoint -o "$mime" == application/vnd.openxmlformats-officedocument.presentationml.presentation \
194
-o "$mime" == application/vnd.ms-excel -o "$mime" == application/vnd.openxmlformats-officedocument.spreadsheetml.sheet \
195
-o "$mime" == application/msword -o "$mime" == application/vnd.ms-office \
196
-o "$mime" == application/vnd.openxmlformats-officedocument.wordprocessingml.document \
197
-o "$iextension" == xlsx \
198
-o "$iextension" == docx ]
200
if [ "$MAX_SIZE" -gt 0 -a "`stat -c%s "$ifile"`" -gt $MAX_SIZE ]; then
201
echo "Skipping conversion of Microsoft Office file bigger than $MAX_SIZE"
205
if [ "$mime" == application/vnd.ms-powerpoint \
206
-o "$mime" == application/vnd.openxmlformats-officedocument.presentationml.presentation ]; then
208
elif [ "$mime" == application/vnd.ms-excel \
209
-o "$mime" == application/vnd.openxmlformats-officedocument.spreadsheetml.sheet \
210
-o "$iextension" == xlsx ]; then
212
elif [ "$mime" == application/msword \
213
-o "$mime" == application/vnd.openxmlformats-officedocument.wordprocessingml.document \
214
-o "$iextension" == docx -o "$iextension" == doc ]; then
217
echo "Unrecongised Microsoft Office file type" 1>&2
220
tmpfile=`mktemp --tmpdir="$cache"`.$extension
221
echo "Converting Microsoft Office file to OpenOffice.org format"
222
unoconv -f "$extension" --stdout "$ifile" 1> "$tmpfile"
223
try_gsf_thumbnailer "$tmpfile" "$ofile" || {
224
echo "gsf-office-thumbnailer failed" 1>&2
230
# Not a Microsoft Office file, and gsf-office-thumbnailer previously
232
echo "ooo-thumbnailer: gsf-office-thumbnailer could not thumbnail this OpenOffice.org file" 1>&2
170
gsf-office-thumbnailer -i "$1" -o "$2" -s "${size:-128}"
174
# This functions decorates a thumbnail with a mime-type icon
175
# arguments: document-filename thumbnail-filename
176
function decorate_with_icon {
178
icon=$(get_icon "$1")
179
if [ ! -e "$icon" ] ; then
180
echo "$icon does not exist" 1>&2
183
if [ -x /usr/bin/composite ] && [ -e "$icon" ]; then
184
convert "$1" -background white -flatten -scale ${size:-128}x${size:-128} "png:-" | composite -gravity SouthEast "$icon" - "$2"
189
# Prepare temporary intermediate file
191
tmpfile=$(mktemp --tmpdir="${XDG_CACHE_HOME:-$HOME/.cache}" --suffix="${ifile##*/}" )
198
try_gsf_thumbnailer "$ifile" "$tmpfile"
199
decorate_with_icon "$tmpfile" "$ofile"