Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/src/modules/idesk/idesk-generate-icon.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2369 - (show annotations) (download)
Wed Aug 26 11:03:13 2015 UTC (8 years, 8 months ago) by niro
File size: 4196 byte(s)
-added add,del,print support
1 #!/bin/bash
2
3 MCORE_LIBDIR="@@MCORE_LIBDIR@@"
4 source @@SYSCONFDIR@@/mcore/mcore.conf
5 source ${MCORE_LIBDIR}/include/common.global.class
6
7 GLOBAL_PIXMAPS_PATH="@@GLOBAL_PIXMAPS_PATH@@"
8 LOCAL_PIXMAPS_PATH="${MCORE_CONFIG_PATH}/icons/default"
9
10 ICON_INFO_PATH="${MCORE_CONFIG_PATH}/icons/info"
11 ICON_INFO_SUFFIX="@@ICON_INFO_SUFFIX@@"
12 ICON_SUFFIX="@@ICON_SUFFIX@@"
13
14 die() { echo "ERROR: $@"; exit 1; }
15
16 # very basic getops
17 for i in $*
18 do
19 case $1 in
20 --add|--del|--print) method="${1//--}" ;;
21 --resource|-r) shift; icon_resource="$1" ;;
22 --name|-n) shift; argv_name="$1" ;;
23 --command|-c) shift; argv_command="$1" ;;
24 --icon|-i) shift; argv_icon="$1" ;;
25 --filename|-f) shift; argv_filename="$1" ;;
26 --xres|-x) shift; argv_xres="$1" ;;
27 --yres|-y) shift; argv_yres="$1" ;;
28 --icon-width|-w) shift; argv_iwidth="$1" ;;
29 --icon-height|-h) shift; argv_iheight="$1" ;;
30 --default-icon) shift; argv_deficon="$1" ;;
31 esac
32 shift
33 done
34
35 # some sanity checks:
36 [[ -z ${method} ]] && die "No method given"
37
38 case "${method}" in
39 add)
40 if [[ -n ${icon_resource} ]]
41 then
42 [[ -f ${icon_resource} ]] || die "Icon resource '${icon_resource}' does not exist"
43 else
44 name="${argv_name}"
45 command="${argv_command}"
46 filename="${argv_filename}"
47 xres="${argv_xres}"
48 yres="${argv_yres}"
49 icon="${argv_icon}"
50 deficon="${argv_deficon}"
51 iwidth="${argv_iwidth}"
52 iheight="${argv_iheight}"
53
54 # abort if name or command not given
55 [[ -z ${name} ]] && die "No name given"
56 [[ -z ${command} ]] && die "No command given"
57
58 [[ -z ${filename} ]] && filename="${name}"
59
60 # use some defaults for icon, dest, {x,y}res
61 [[ -z ${xres} ]] && xres=50
62 [[ -z ${yres} ]] && yres=50
63 if [[ -z ${icon} ]]
64 then
65 # if no default icon is given use default.png
66 [[ -z ${deficon} ]] && deficon="default.png"
67 icon="${deficon}"
68 fi
69
70 ${MCORE_LIBDIR}/idesk-generate-icon-info \
71 --add \
72 --name "${name}" \
73 --command "${command}" \
74 --icon "${icon}" \
75 --filename "${filename}" \
76 --xres "${xres}" \
77 --yres "${yres}" \
78 --icon-width "${iwidth}" \
79 --icon-height "${iheight}" \
80 --default-icon "${deficon}" \
81 || die "adding icon-info"
82
83 icon_resource="${ICON_INFO_PATH}/${filename}.${ICON_INFO_SUFFIX}"
84 fi
85
86 source "${icon_resource}"
87
88 # icon resource overrides
89 [[ -n ${argv_name} ]] && name="${argv_name}"
90 [[ -n ${argv_command} ]] && command="${argv_command}"
91 [[ -n ${argv_filename} ]] && filename="${argv_filename}"
92 [[ -n ${argv_xres} ]] && xres="${argv_xres}"
93 [[ -n ${argv_yres} ]] && yres="${argv_yres}"
94 [[ -n ${argv_icon} ]] && icon="${argv_icon}"
95 [[ -n ${argv_deficon} ]] && deficon="${argv_deficon}"
96 [[ -n ${argv_iwidth} ]] && iwidth="${argv_iwidth}"
97 [[ -n ${argv_iheight} ]] && iheight="${argv_iheight}"
98
99 [[ -z ${filename} ]] && die "Error \$filename is empty in icon resource '${icon_resource}'"
100
101 # get the right icon path, local overrides global
102 [[ -f ${GLOBAL_PIXMAPS_PATH}/${icon} ]] && icon_path="${GLOBAL_PIXMAPS_PATH}"
103 [[ -f ${LOCAL_PIXMAPS_PATH}/${icon} ]] && icon_path="${LOCAL_PIXMAPS_PATH}"
104 # no icon found, use default icon
105 if [[ -z ${icon_path} ]]
106 then
107 icon_path="${GLOBAL_PIXMAPS_PATH}"
108 icon="default.png"
109 fi
110
111 CONFIG="${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX}"
112 clearconfig
113
114 addconfig 'table Icon'
115 addconfig " Caption: ${name}"
116 addconfig " Command: ${command}"
117 addconfig " Icon: ${icon_path}/${icon}"
118 addconfig " X: ${xres}"
119 addconfig " Y: ${yres}"
120
121 # add these only if not zero
122 if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]]
123 then
124 addconfig " Width: ${iwidth}"
125 addconfig " Height: ${iheight}"
126 fi
127
128 addconfig 'end'
129 ;;
130
131 del)
132 if [[ -n ${icon_resource} ]]
133 then
134 [[ -f ${icon_resource} ]] || die "Icon resource '${icon_resource}' does not exist"
135 source "${icon_resource}"
136 fi
137 ${MCORE_LIBDIR}/idesk-generate-icon-info --del --name "${name}" --filename "${filename}" || die "deleting icon info"
138 if [[ -f ${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX} ]]
139 then
140 rm ${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX}
141 fi
142 ;;
143
144 print)
145 ${MCORE_LIBDIR}/idesk-generate-icon-info --print
146 ;;
147 esac