Annotation of /mcore-src/trunk/mcore-tools/src/modules/idesk/idesk-generate-icon.in
Parent Directory | Revision Log
Revision 2404 -
(hide annotations)
(download)
Mon Aug 31 08:57:10 2015 UTC (8 years, 8 months ago) by niro
File size: 4848 byte(s)
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 | niro | 2358 | #!/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 | niro | 2360 | die() { echo "ERROR: $@"; exit 1; } |
15 | |||
16 | niro | 2358 | # very basic getops |
17 | for i in $* | ||
18 | do | ||
19 | case $1 in | ||
20 | niro | 2369 | --add|--del|--print) method="${1//--}" ;; |
21 | niro | 2361 | --resource|-r) shift; icon_resource="$1" ;; |
22 | niro | 2358 | --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 | niro | 2404 | --xpos|-x) shift; argv_xpos="$1" ;; |
27 | --ypos|-y) shift; argv_ypos="$1" ;; | ||
28 | niro | 2358 | --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 | niro | 2369 | [[ -z ${method} ]] && die "No method given" |
37 | niro | 2358 | |
38 | niro | 2369 | 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 | niro | 2404 | xpos="${argv_xpos}" |
48 | ypos="${argv_ypos}" | ||
49 | niro | 2369 | icon="${argv_icon}" |
50 | deficon="${argv_deficon}" | ||
51 | iwidth="${argv_iwidth}" | ||
52 | iheight="${argv_iheight}" | ||
53 | niro | 2358 | |
54 | niro | 2369 | # abort if name or command not given |
55 | [[ -z ${name} ]] && die "No name given" | ||
56 | [[ -z ${command} ]] && die "No command given" | ||
57 | niro | 2358 | |
58 | niro | 2369 | [[ -z ${filename} ]] && filename="${name}" |
59 | niro | 2358 | |
60 | niro | 2404 | # use some defaults for icon, dest, {x,y}pos |
61 | [[ -z ${xpos} ]] && xpos=50 | ||
62 | [[ -z ${ypos} ]] && ypos=50 | ||
63 | niro | 2369 | 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 | niro | 2358 | |
70 | niro | 2369 | ${MCORE_LIBDIR}/idesk-generate-icon-info \ |
71 | --add \ | ||
72 | --name "${name}" \ | ||
73 | --command "${command}" \ | ||
74 | --icon "${icon}" \ | ||
75 | --filename "${filename}" \ | ||
76 | niro | 2404 | --xpos "${xpos}" \ |
77 | --ypos "${ypos}" \ | ||
78 | niro | 2369 | --icon-width "${iwidth}" \ |
79 | --icon-height "${iheight}" \ | ||
80 | --default-icon "${deficon}" \ | ||
81 | || die "adding icon-info" | ||
82 | niro | 2358 | |
83 | niro | 2369 | icon_resource="${ICON_INFO_PATH}/${filename}.${ICON_INFO_SUFFIX}" |
84 | fi | ||
85 | niro | 2358 | |
86 | niro | 2369 | source "${icon_resource}" |
87 | niro | 2358 | |
88 | niro | 2369 | # 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 | niro | 2404 | [[ -n ${argv_xpos} ]] && xpos="${argv_xpos}" |
93 | [[ -n ${argv_ypos} ]] && ypos="${argv_ypos}" | ||
94 | niro | 2369 | [[ -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 | niro | 2358 | |
99 | niro | 2369 | [[ -z ${filename} ]] && die "Error \$filename is empty in icon resource '${icon_resource}'" |
100 | niro | 2358 | |
101 | niro | 2369 | # 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 | niro | 2358 | |
111 | niro | 2369 | CONFIG="${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX}" |
112 | clearconfig | ||
113 | niro | 2403 | # fix permissions |
114 | chown "${MCORE_UNPRIV_USER}":"${MCORE_UNPRIV_GROUP}" "${MCORE_UNPRIV_HOME}/.idesktop" | ||
115 | niro | 2358 | |
116 | niro | 2369 | addconfig 'table Icon' |
117 | addconfig " Caption: ${name}" | ||
118 | addconfig " Command: ${command}" | ||
119 | addconfig " Icon: ${icon_path}/${icon}" | ||
120 | niro | 2404 | addconfig " X: ${xpos}" |
121 | addconfig " Y: ${ypos}" | ||
122 | niro | 2358 | |
123 | niro | 2369 | # 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 | niro | 2358 | |
130 | niro | 2369 | 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 | niro | 2370 | |
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 | niro | 2404 | [[ -n ${argv_xpos} ]] && xpos="${argv_xpos}" |
145 | [[ -n ${argv_ypos} ]] && ypos="${argv_ypos}" | ||
146 | niro | 2370 | [[ -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 | niro | 2369 | ${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 |