/var/lib/sorcery/modules/libmedia
1 #!/bin/bash
2 #---------------------------------------------------------------------
3 ##
4 ##=head1 SYNOPSIS
5 ##
6 ## Functions for dealing with screen and sound settings
7 ##
8 ##=head1 DESCRIPTION
9 ##
10 ## Provides color schemes
11 ##
12 ##=head1 COPYRIGHT
13 ##
14 ## Copyright (C) 2004 The Source Mage Team <http://www.sourcemage.org>
15 ##
16 ##=head1 FUNCTIONS
17 #---------------------------------------------------------------------
18
19 #---------------------------------------------------------------------
20 ## sets the colors based upon COLOR_SCHEME and defaults to a BRIGHT
21 ## color scheme
22 #---------------------------------------------------------------------
23 function media_init() {
24
25 # color ASCII codes
26 #
27 DEFAULT_COLOR="\e[0m"
28 BOLD="\e[1m"
29 BLACK="\e[30m"
30 RED="\e[31m"
31 GREEN="\e[32m"
32 YELLOW="\e[33m"
33 BLUE="\e[34m"
34 VIOLET="\e[35m"
35 CYAN="\e[36m"
36 WHITE="\e[37m"
37
38 # color schemes
39 #
40 case X$(echo $COLOR_SCHEME | tr "[A-Z]" "[a-z]") in
41 Xdark)
42 SPELL_COLOR="${BLACK}${BOLD}"
43 VERSION_COLOR="${BLACK}${BOLD}"
44 QUERY_COLOR="${BLUE}${BOLD}"
45 DISPEL_COLOR="${BLUE}${BOLD}"
46 CHECK_COLOR="${DEFAULT_COLOR}${CYAN}"
47 RESURRECT_COLOR="${GREEN}${BOLD}"
48 FILE_COLOR="${GREEN}${BOLD}"
49 SYMLINK_COLOR="${CYAN}${BOLD}"
50 PROBLEM_COLOR="${RED}${BOLD}"
51 MESSAGE_COLOR="${DEFAULT_COLOR}${CYAN}"
52 ;;
53
54 Xblueish)
55 SPELL_COLOR="${BLACK}${BOLD}"
56 VERSION_COLOR="${BLACK}${BOLD}"
57 QUERY_COLOR="${BLUE}${BOLD}"
58 DISPEL_COLOR="${BLUE}${BOLD}"
59 CHECK_COLOR="${DEFAULT_COLOR}${CYAN}"
60 RESURRECT_COLOR="${VIOLET}"
61 FILE_COLOR="${VIOLET}${BOLD}"
62 SYMLINK_COLOR="${CYAN}${BOLD}"
63 PROBLEM_COLOR="${RED}${BOLD}"
64 MESSAGE_COLOR="${DEFAULT_COLOR}${CYAN}"
65 ;;
66
67 X*)
68 SPELL_COLOR="${WHITE}${BOLD}\e[40m"
69 VERSION_COLOR="${WHITE}${BOLD}\e[40m"
70 QUERY_COLOR="${YELLOW}${BOLD}"
71 DISPEL_COLOR="${YELLOW}${BOLD}"
72 CHECK_COLOR="${DEFAULT_COLOR}${CYAN}"
73 RESURRECT_COLOR="${GREEN}${BOLD}"
74 FILE_COLOR="${GREEN}${BOLD}"
75 SYMLINK_COLOR="${CYAN}${BOLD}"
76 PROBLEM_COLOR="${RED}${BOLD}"
77 MESSAGE_COLOR="${DEFAULT_COLOR}${CYAN}"
78 ;;
79 esac
80 }
81
82
83 #---------------------------------------------------------------------
84 ##
85 ## Setup sound menu from existing installed sorcery sound spells.
86 ## Currently no check done for installed sound schemes, just message
87 ## to user.
88 ##
89 ## Passes name of chosen scheme to the set_sound_scheme funtion.
90 ##
91 #---------------------------------------------------------------------
92 function sound_schemes_menu() {
93
94 local SOUND_HELP="Here you can choose your prefered sound scheme"
95 FER_SOUND="Ferris sound scheme"
96 MIS_SOUND="Misc sound scheme"
97 SIM_SOUND="Simpsons sound scheme"
98 STA_SOUND="Startrek sound scheme"
99 OFF_SOUND="Sound off"
100
101 if SOUND_CHECKS=`eval $DIALOG ' --title "Sound Schemes" \
102 --cancel-label "Exit" \
103 --ok-label "Select" \
104 --item-help \
105 --menu \
106 "$SOUND_HELP" \
107 0 0 0 \
108 "OFF" "$OFF_SOUND" "$SOUND_HELP" \
109 "FER" "$FER_SOUND" "$SOUND_HELP" \
110 "MIS" "$MIS_SOUND" "$SOUND_HELP" \
111 "SIM" "$SIM_SOUND" "$SOUND_HELP" \
112 "STA" "$STA_SOUND" "$SOUND_HELP"'`
113 then
114
115 for CHECK in $SOUND_CHECKS; do
116 case $CHECK in
117 OFF) remove_config $LOCAL_CONFIG "SOUND"
118 modify_config $LOCAL_MEDIA_CONFIG "SOUND" "off" &&
119 SOUND=off
120 eval $DIALOG '--msgbox "Sorcery sounds have been turned off." 0 0'
121 ;;
122 FER) set_sound_theme ferris ;;
123 MIS) set_sound_theme misc ;;
124 SIM) set_sound_theme simpsons ;;
125 STA) set_sound_theme startrek ;;
126 esac
127 done
128
129 fi
130
131 }
132
133
134 #---------------------------------------------------------------------
135 ## @param sound scheme name
136 ##
137 ## Here the passed scheme is set as default sound scheme.
138 ## If the sound spell is not installed it will be cast for the user.
139 ##
140 #---------------------------------------------------------------------
141 function set_sound_theme() {
142
143 remove_config $LOCAL_CONFIG "SOUND"
144 remove_config $LOCAL_CONFIG "SOUND_THEME"
145
146 modify_config $LOCAL_MEDIA_CONFIG "SOUND" "on" &&
147 modify_config $LOCAL_MEDIA_CONFIG "SOUND_THEME" "$1" &&
148 SOUND=on &&
149 SOUND_THEME=$1
150
151
152 if ! spell_ok sorcery-sound-$SOUND_THEME
153 then
154 eval $DIALOG '--msgbox "Sorcery has determined that the $SOUND_THEME \
155 theme must be installed to work. It will now \
156 be cast for you!" 0 0'
157 cast sorcery-sound-$SOUND_THEME
158 else
159 eval $DIALOG '--msgbox "The $SOUND_THEME theme is installed and ready \
160 for you to enjoy your new sounds!" 0 0'
161 fi
162
163 }
164
165
166 color_schemes_menu() {
167
168 if
169
170 local L_HELP="Light color scheme for use on dark backgrounds"
171 local D_HELP="Dark color scheme for use on bright backgrounds"
172 local B_HELP="blueish color scheme"
173
174 COMMAND=`eval $DIALOG ' --title "Current scheme: $COLOR_SCHEME" \
175 --item-help \
176 --ok-label "Select" \
177 --cancel-label "Exit" \
178 --menu \
179 "" \
180 0 0 0 \
181 "L" "Light" "$L_HELP" \
182 "D" "Dark" "$D_HELP" \
183 "B" "Blueish" "$B_HELP" '`
184
185 then
186 case $COMMAND in
187
188 B) COLOR_SCHEME=blueish ;;
189 D) COLOR_SCHEME=dark ;;
190 L) COLOR_SCHEME=light ;;
191
192 esac
193 remove_config $LOCAL_CONFIG COLOR_SCHEME
194
195 modify_config $LOCAL_MEDIA_CONFIG COLOR_SCHEME $COLOR_SCHEME &&
196 media_init
197 fi
198 }
199
200 #---------------------------------------------------------------------
201 ## @param on/off
202 ##
203 ## First argument is "off" or "on" to turn console colors off or on
204 ##
205 #---------------------------------------------------------------------
206 function color() {
207
208 case $1 in
209 off) unset SPELL_COLOR
210 unset VERSION_COLOR
211 unset QUERY_COLOR
212 unset DISPEL_COLOR
213 unset CHECK_COLOR
214 unset RESURRECT_COLOR
215 unset FILE_COLOR
216 unset SYMLINK_COLOR
217 unset PROBLEM_COLOR
218 unset MESSAGE_COLOR
219 unset DEFAULT_COLOR
220 COLOR=off
221 ;;
222 on) COLOR=on
223 ;;
224 esac
225
226 }
227
228
229 #---------------------------------------------------------------------
230 ## @License
231 ##
232 ## This software is free software; you can redistribute it and/or modify
233 ## it under the terms of the GNU General Public License as published by
234 ## the Free Software Foundation; either version 2 of the License, or
235 ## (at your option) any later version.
236 ##
237 ## This software is distributed in the hope that it will be useful,
238 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
239 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
240 ## GNU General Public License for more details.
241 ##
242 ## You should have received a copy of the GNU General Public License
243 ## along with this software; if not, write to the Free Software
244 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
245 ##
246 #---------------------------------------------------------------------