Contents of /mcore-src/trunk/mcore-tools/src/modules/idesk/idesk-generate-icon.in
Parent Directory | Revision Log
Revision 2372 -
(show annotations)
(download)
Wed Aug 26 11:09:27 2015 UTC (8 years, 8 months ago) by niro
File size: 4865 byte(s)
Wed Aug 26 11:09:27 2015 UTC (8 years, 8 months ago) by niro
File size: 4865 byte(s)
-restart idesk after altering the icons
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 | restart_idesk() |
17 | { |
18 | # restart idesk |
19 | killall idesk; x11runas "nohup idesk > /dev/null &" |
20 | } |
21 | |
22 | # very basic getops |
23 | for i in $* |
24 | do |
25 | case $1 in |
26 | --add|--del|--print) method="${1//--}" ;; |
27 | --resource|-r) shift; icon_resource="$1" ;; |
28 | --name|-n) shift; argv_name="$1" ;; |
29 | --command|-c) shift; argv_command="$1" ;; |
30 | --icon|-i) shift; argv_icon="$1" ;; |
31 | --filename|-f) shift; argv_filename="$1" ;; |
32 | --xres|-x) shift; argv_xres="$1" ;; |
33 | --yres|-y) shift; argv_yres="$1" ;; |
34 | --icon-width|-w) shift; argv_iwidth="$1" ;; |
35 | --icon-height|-h) shift; argv_iheight="$1" ;; |
36 | --default-icon) shift; argv_deficon="$1" ;; |
37 | esac |
38 | shift |
39 | done |
40 | |
41 | # some sanity checks: |
42 | [[ -z ${method} ]] && die "No method given" |
43 | |
44 | case "${method}" in |
45 | add) |
46 | if [[ -n ${icon_resource} ]] |
47 | then |
48 | [[ -f ${icon_resource} ]] || die "Icon resource '${icon_resource}' does not exist" |
49 | else |
50 | name="${argv_name}" |
51 | command="${argv_command}" |
52 | filename="${argv_filename}" |
53 | xres="${argv_xres}" |
54 | yres="${argv_yres}" |
55 | icon="${argv_icon}" |
56 | deficon="${argv_deficon}" |
57 | iwidth="${argv_iwidth}" |
58 | iheight="${argv_iheight}" |
59 | |
60 | # abort if name or command not given |
61 | [[ -z ${name} ]] && die "No name given" |
62 | [[ -z ${command} ]] && die "No command given" |
63 | |
64 | [[ -z ${filename} ]] && filename="${name}" |
65 | |
66 | # use some defaults for icon, dest, {x,y}res |
67 | [[ -z ${xres} ]] && xres=50 |
68 | [[ -z ${yres} ]] && yres=50 |
69 | if [[ -z ${icon} ]] |
70 | then |
71 | # if no default icon is given use default.png |
72 | [[ -z ${deficon} ]] && deficon="default.png" |
73 | icon="${deficon}" |
74 | fi |
75 | |
76 | ${MCORE_LIBDIR}/idesk-generate-icon-info \ |
77 | --add \ |
78 | --name "${name}" \ |
79 | --command "${command}" \ |
80 | --icon "${icon}" \ |
81 | --filename "${filename}" \ |
82 | --xres "${xres}" \ |
83 | --yres "${yres}" \ |
84 | --icon-width "${iwidth}" \ |
85 | --icon-height "${iheight}" \ |
86 | --default-icon "${deficon}" \ |
87 | || die "adding icon-info" |
88 | |
89 | icon_resource="${ICON_INFO_PATH}/${filename}.${ICON_INFO_SUFFIX}" |
90 | fi |
91 | |
92 | source "${icon_resource}" |
93 | |
94 | # icon resource overrides |
95 | [[ -n ${argv_name} ]] && name="${argv_name}" |
96 | [[ -n ${argv_command} ]] && command="${argv_command}" |
97 | [[ -n ${argv_filename} ]] && filename="${argv_filename}" |
98 | [[ -n ${argv_xres} ]] && xres="${argv_xres}" |
99 | [[ -n ${argv_yres} ]] && yres="${argv_yres}" |
100 | [[ -n ${argv_icon} ]] && icon="${argv_icon}" |
101 | [[ -n ${argv_deficon} ]] && deficon="${argv_deficon}" |
102 | [[ -n ${argv_iwidth} ]] && iwidth="${argv_iwidth}" |
103 | [[ -n ${argv_iheight} ]] && iheight="${argv_iheight}" |
104 | |
105 | [[ -z ${filename} ]] && die "Error \$filename is empty in icon resource '${icon_resource}'" |
106 | |
107 | # get the right icon path, local overrides global |
108 | [[ -f ${GLOBAL_PIXMAPS_PATH}/${icon} ]] && icon_path="${GLOBAL_PIXMAPS_PATH}" |
109 | [[ -f ${LOCAL_PIXMAPS_PATH}/${icon} ]] && icon_path="${LOCAL_PIXMAPS_PATH}" |
110 | # no icon found, use default icon |
111 | if [[ -z ${icon_path} ]] |
112 | then |
113 | icon_path="${GLOBAL_PIXMAPS_PATH}" |
114 | icon="default.png" |
115 | fi |
116 | |
117 | CONFIG="${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX}" |
118 | clearconfig |
119 | |
120 | addconfig 'table Icon' |
121 | addconfig " Caption: ${name}" |
122 | addconfig " Command: ${command}" |
123 | addconfig " Icon: ${icon_path}/${icon}" |
124 | addconfig " X: ${xres}" |
125 | addconfig " Y: ${yres}" |
126 | |
127 | # add these only if not zero |
128 | if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]] |
129 | then |
130 | addconfig " Width: ${iwidth}" |
131 | addconfig " Height: ${iheight}" |
132 | fi |
133 | |
134 | addconfig 'end' |
135 | |
136 | restart_idesk |
137 | ;; |
138 | |
139 | del) |
140 | if [[ -n ${icon_resource} ]] |
141 | then |
142 | [[ -f ${icon_resource} ]] || die "Icon resource '${icon_resource}' does not exist" |
143 | source "${icon_resource}" |
144 | fi |
145 | |
146 | # icon resource overrides |
147 | [[ -n ${argv_name} ]] && name="${argv_name}" |
148 | [[ -n ${argv_command} ]] && command="${argv_command}" |
149 | [[ -n ${argv_filename} ]] && filename="${argv_filename}" |
150 | [[ -n ${argv_xres} ]] && xres="${argv_xres}" |
151 | [[ -n ${argv_yres} ]] && yres="${argv_yres}" |
152 | [[ -n ${argv_icon} ]] && icon="${argv_icon}" |
153 | [[ -n ${argv_deficon} ]] && deficon="${argv_deficon}" |
154 | [[ -n ${argv_iwidth} ]] && iwidth="${argv_iwidth}" |
155 | [[ -n ${argv_iheight} ]] && iheight="${argv_iheight}" |
156 | |
157 | [[ -z ${filename} ]] && filename="${name}" |
158 | |
159 | ${MCORE_LIBDIR}/idesk-generate-icon-info --del --name "${name}" --filename "${filename}" || die "deleting icon info" |
160 | if [[ -f ${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX} ]] |
161 | then |
162 | rm ${MCORE_UNPRIV_HOME}/.idesktop/${filename}.${ICON_SUFFIX} |
163 | fi |
164 | |
165 | restart_idesk |
166 | ;; |
167 | |
168 | print) |
169 | ${MCORE_LIBDIR}/idesk-generate-icon-info --print |
170 | ;; |
171 | esac |