Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2369 - (hide 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 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     --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 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     xres="${argv_xres}"
48     yres="${argv_yres}"
49     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 2369 # 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 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     --xres "${xres}" \
77     --yres "${yres}" \
78     --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     [[ -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 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 2358
114 niro 2369 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 niro 2358
121 niro 2369 # 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 niro 2358
128 niro 2369 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