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 2404 - (show annotations) (download)
Mon Aug 31 08:57:10 2015 UTC (8 years, 8 months ago) by niro
File size: 4848 byte(s)
-renamed icon position variables from {x,y}res to {x,y}pos
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 --xpos|-x) shift; argv_xpos="$1" ;;
27 --ypos|-y) shift; argv_ypos="$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 xpos="${argv_xpos}"
48 ypos="${argv_ypos}"
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}pos
61 [[ -z ${xpos} ]] && xpos=50
62 [[ -z ${ypos} ]] && ypos=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 --xpos "${xpos}" \
77 --ypos "${ypos}" \
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_xpos} ]] && xpos="${argv_xpos}"
93 [[ -n ${argv_ypos} ]] && ypos="${argv_ypos}"
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 # fix permissions
114 chown "${MCORE_UNPRIV_USER}":"${MCORE_UNPRIV_GROUP}" "${MCORE_UNPRIV_HOME}/.idesktop"
115
116 addconfig 'table Icon'
117 addconfig " Caption: ${name}"
118 addconfig " Command: ${command}"
119 addconfig " Icon: ${icon_path}/${icon}"
120 addconfig " X: ${xpos}"
121 addconfig " Y: ${ypos}"
122
123 # add these only if not zero
124 if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]]
125 then
126 addconfig " Width: ${iwidth}"
127 addconfig " Height: ${iheight}"
128 fi
129
130 addconfig 'end'
131 ;;
132
133 del)
134 if [[ -n ${icon_resource} ]]
135 then
136 [[ -f ${icon_resource} ]] || die "Icon resource '${icon_resource}' does not exist"
137 source "${icon_resource}"
138 fi
139
140 # icon resource overrides
141 [[ -n ${argv_name} ]] && name="${argv_name}"
142 [[ -n ${argv_command} ]] && command="${argv_command}"
143 [[ -n ${argv_filename} ]] && filename="${argv_filename}"
144 [[ -n ${argv_xpos} ]] && xpos="${argv_xpos}"
145 [[ -n ${argv_ypos} ]] && ypos="${argv_ypos}"
146 [[ -n ${argv_icon} ]] && icon="${argv_icon}"
147 [[ -n ${argv_deficon} ]] && deficon="${argv_deficon}"
148 [[ -n ${argv_iwidth} ]] && iwidth="${argv_iwidth}"
149 [[ -n ${argv_iheight} ]] && iheight="${argv_iheight}"
150
151 [[ -z ${filename} ]] && filename="${name}"
152
153 ${MCORE_LIBDIR}/idesk-generate-icon-info --del --name "${name}" --filename "${filename}" || die "deleting icon info"
154 if [[ -f ${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX} ]]
155 then
156 rm ${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX}
157 fi
158 ;;
159
160 print)
161 ${MCORE_LIBDIR}/idesk-generate-icon-info --print
162 ;;
163 esac