summaryrefslogtreecommitdiff
blob: 62333a28d90379916c246a7a7f28a80af62b1686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# -*-eselect-*-  vim: ft=eselect
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

inherit config

DESCRIPTION="Manage the system default wxWidgets profile"
MAINTAINER="wxwidgets@gentoo.org"
SVN_DATE='$Date$'
VERSION=$(svn_date_to_version "${SVN_DATE}")

WXCONFFILE="${EROOT}"/var/lib/wxwidgets/current
WXCONFDIR="${EROOT}"/usr/lib/wx/config

find_targets() {
	local conf
	for conf in ${WXCONFDIR}/*; do
		[[ -f ${conf} && -x ${conf} ]] && basename ${conf}
	done
}

set_config() {
	local target="${1}" targets

	# selected by number
	if is_number "${target}"; then
		targets=( $(find_targets) )
		[[ ${1} -ge 1 && ${1} -le ${#targets[@]} ]] \
			|| die -q "Number out of range: ${1}"
		target=${targets[$(( ${target} - 1 ))]}
	fi

	if [[ ${target} == "none" ]]; then
		# none is a special case
		:
	else
		[[ ! -f ${WXCONFDIR}/${target} ]] && \
			die -q "\"${1}\" doesn't appear to be a valid profile name"
	fi

	echo
	echo "Setting wxWidgets profile to ${target}"
	echo
	store_config ${WXCONFFILE} WXCONFIG ${target}

	if [[ ! ${target} == "none" ]]; then
		# expose the slot number of the selected target for various uses
		local wxslot=${target##*-}
	fi

	# symlink bakefile presets to current slot (Bug #209150)
	local f
	pushd "${EROOT}"/usr/share/bakefile/presets/ &> /dev/null
	for f in .bkl _presets.py _unix.bkl _win32.bkl _xrc.bkl; do
		if [[ -e wx${f} || -L wx${f} ]]; then
			rm -f wx${f} || die -q "Error removing wx${f}"
		fi
		if [[ ! ${target} == "none" ]]; then
			if [[ -e wx${wxslot/./}${f} ]]; then
				ln -sf wx${wxslot/./}${f} wx${f} \
					|| die -q "Error symlinking wx${wxslot/./}${f}"
			fi
		fi
	done
	popd &> /dev/null
}

### show action ###

describe_show() {
	echo "Show the currently selected profile"
}

do_show() {
	[[ ${#@} -gt 0 ]] && die -q "Too many parameters"

	write_list_start "Current wxWidgets profile:"
	if [[ -e ${WXCONFFILE} ]]; then
		write_kv_list_entry "$(load_config ${WXCONFFILE} WXCONFIG)" ""
	else
		write_kv_list_entry "(none)" ""
	fi
}

### list action ###

describe_list() {
	echo "List available profiles"
}

do_list() {
	local i targets currconf
	# targets is an array containing names of available configs
	targets=( $(find_targets) )
	[[ -e ${WXCONFFILE} ]] && currconf=$(load_config ${WXCONFFILE} WXCONFIG)

	for (( i = 0; i < ${#targets[@]}; i++ )); do
		# highlight current version
		[[ ${targets[i]} = ${currconf} ]] \
			&& targets[i]=$(highlight_marker "${targets[i]}")
	done
	write_list_start "Available wxWidgets profiles:"
	write_numbered_list -m "(none found)" "${targets[@]}"
}

### set action ###

describe_set() {
	echo "Set the system wxWidgets profile"
}

describe_set_options() {
	echo "<target> : Profile name or number (from 'list' action)"
}

describe_set_parameters() {
	echo "<target>"
}

do_set() {
	[[ ! ${#@} -eq 1 ]] \
		&& die -q "You must specify a profile name or number"

	[[ -w "${EROOT}"/var/lib ]] \
		|| die -q "You need write permission to /var/lib to perform this action."

	set_config "${1}"
}

describe_update() {
	echo "Check current profile and update it if invalid (internal use only)"
}

do_update() {
	[[ ! -e ${WXCONFFILE} ]] && do_set none

	currconf=$(load_config ${WXCONFFILE} WXCONFIG)

	# if current config is "none" leave it alone
	[[ ${currconf} == none ]] && return 0

	# if current config is valid leave it alone
	[[ -e ${WXCONFDIR}/${currconf} ]] && return 0

	# split the current config into components
	OIFS=${IFS}
	IFS=-
	set -- ${currconf}
	IFS=${OIFS}

	declare -a wxtoolkit wxchar wxdebug wxver

	# put them into the first element of the arrays
	wxtoolkit=(${1})
	wxchar=(${2})
	if [[ $# -eq 3 ]]; then
		# >=2.9 doesn't have a debug component, so fake it
		wxdebug=(release)
		wxver=(${3})
	else
		wxdebug=(${3})
		wxver=(${4})
	fi

	# now put all possible components into the next elements
	local component toolkit char debug ver i opt

	for component in toolkit char debug ver; do
		i=1
		case ${component} in
			toolkit)
				for opt in base gtk2; do
					if [[ ${opt} == ${wxtoolkit[0]} ]]; then
						continue
					else
						wxtoolkit[${i}]=${opt}
						(( i++ ))
					fi
				done
				;;

			char)
				for opt in ansi unicode; do
					if [[ ${opt} == ${wxchar[0]} ]]; then
						continue
					else
						wxchar[${i}]=${opt}
						(( i++ ))
					fi
				done
				;;

			debug)
				for opt in release debug; do
					if [[ ${opt} == ${wxdebug[0]} ]]; then
						continue
					else
						wxdebug[${i}]=${opt}
						(( i++ ))
					fi
				done
				;;

			ver)
				for opt in 2.9 2.8 2.6; do
					if [[ ${opt} == ${wxver[0]} ]]; then
						continue
					else
						wxver[${i}]=${opt}
						(( i++ ))
					fi
				done
				;;
		esac
	done

	# Now we iterate through all the installed configs and find the closest match
	# ( debug -> char -> toolkit -> ver )
	# meaning w/ a current config of gtk2-unicode-debug-2.6, it will pick
	# gtk2-unicode-release-2.6 before
	# gtk2-ansi-debug-2.6 before
	# base-unicode-debug-2.6 before
	# gtk2-unicode-debug-2.8

	local d c t v checkconf foundconf

	for (( v = 0 ; v < ${#wxver[@]} ; v++ )); do
		for (( t = 0 ; t < ${#wxtoolkit[@]} ; t++ )); do
			for (( c = 0 ; c < ${#wxchar[@]} ; c++ )); do
				for (( d = 0 ; d < ${#wxdebug[@]} ; d++ )); do
					if [[ ${wxver[$v]} != 2.[6,8] ]]; then
						# >=2.9 doesn't have a debug component
						checkconf="${wxtoolkit[$t]}-${wxchar[$c]}-${wxver[$v]}"
					else
						checkconf="${wxtoolkit[$t]}-${wxchar[$c]}-${wxdebug[$d]}-${wxver[$v]}"
					fi
					[[ -e ${WXCONFDIR}/${checkconf} ]] || continue
					foundconf=${checkconf}
					break 4
				done
			done
		done
	done

	# nothing installed
	[[ -z ${foundconf} ]] && foundconf="none"

	echo
	write_warning_msg "Your currently selected wxWidgets profile:    ( ${currconf} )"
	write_warning_msg "is no longer available."
	write_warning_msg
	write_warning_msg "The closest matching profile:                 ( ${foundconf} )"
	write_warning_msg "will be activated in its place."

	do_set ${foundconf}
}