2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* @(#)$XConsortium: select.c /main/6 1996/11/21 12:17:43 cde-hp $ */
27 static int fill_ims_ent(/* list, top, last */);
28 static int setup_local_selection(/* sel, list, conf_all */);
29 static int setup_remote_selection(/* sel */);
30 static int setup_user_selection(/* sel, list, idx */);
38 ImsList *list = (ImsList *) 0;
39 FileSel *fsel = (FileSel *) 0;
40 UserSelection *sel = &userSel;
42 OpState = State_Select;
44 /* clear_UserSelection(sel); */
48 if ((ret = get_ims_list(&list, NULL, False)) != NoError) {
49 OpState = State_Select_Err;
60 if (Opt.SelectMode == SEL_MODE_GIVEN) {
61 sel->name = NEWSTR(Opt.ImsName);
65 if (read_user_selection(&sel->fsel, NULL) == NoError) {
68 if (DebugLvl > 1) pr_FileSel(sel->fsel);
72 if (list->default_idx >= 0)
73 def_ims = list->elist[list->default_idx]->name;
75 if ((OpFlag & FLAG_NOSAVE) || Opt.SelectMode == SEL_MODE_NOAUTO) {
77 } else if (Opt.SelectMode == SEL_MODE_AUTO) {
79 #ifdef SelectMode_ONCE
80 } else if (Opt.SelectMode == SEL_MODE_ONCE) {
83 #endif /* SelectMode_ONCE */
85 #ifdef AutoSelectionForSoleIMS
86 } else if (list->num_ent == 1) {
87 DPR(("ximsSelect(): only one entry in locale_conf\n"));
88 sel->name = NEWSTR(list->elist[0]->name);
90 #endif /* AutoSelectionForSoleIMS */
93 if (fsel->select_mode != SEL_MODE_NOAUTO
94 && ((fsel->select_mode == SEL_MODE_AUTO ||
95 list->def_selmode == SEL_MODE_AUTO)
96 && (def_ims || fsel->name))
97 #ifdef SelectMode_ONCE
98 || ((fsel->select_mode == SEL_MODE_ONCE
99 || list->def_selmode == SEL_MODE_ONCE)
101 #endif /* SelectMode_ONCE */
104 } else if (list->def_selmode == SEL_MODE_AUTO && def_ims) {
105 DPR(("ximsSelect(): def_selmode==AUTO in locale_conf\n"));
110 if (sel->iconic == -1) {
111 sel->iconic = fsel ? fsel->iconic : 0;
112 } else if (sel->iconic != fsel->iconic) { /* this should never happen ! */
113 sel->flag |= F_SELECT_CHANGED;
116 if (fsel && fsel->select_mode == SEL_MODE_NONE) {
117 if (list->def_selmode != SEL_MODE_NONE) {
118 fsel->select_mode = list->def_selmode;
119 sel->flag |= F_SELECT_CHANGED;
123 if (!sel->name && fsel && fsel->name)
124 sel->name = NEWSTR(fsel->name);
126 sel->name = NEWSTR(def_ims);
129 sel->hostname = NEWSTR(Opt.HostName);
130 else if (fsel && fsel->hostname)
131 sel->hostname = NEWSTR(fsel->hostname);
134 sel->host_type = check_hostname(sel->hostname);
136 sel->host_type = HOST_LOCAL;
138 if (use_win == True) {
139 ret = setup_local_selection(sel, list, True);
140 ret = start_selection_window();
143 switch (sel->host_type) {
145 ret = setup_remote_selection(sel);
146 if (ret != NoError) {
147 put_xims_errmsg(ret, 0, 0, 0);
152 ret = setup_local_selection(sel, list, False);
156 ret = ErrUnknownHost;
157 /* put_xims_errmsg(ret, sel->hostname, 0, 0); */
163 OpState = ret == NoError ? State_Select_Done : State_Select_Err;
169 static int fill_ims_ent(list, top, last)
178 /* if (top < 0 || last < 0) return 0; */
180 for (i = top; i <= last; i++) { /* read IMS conf */
182 ent = list->elist[i];
184 if (!ims) ims = ALLOC(1, ImsConf);
185 ret = read_imsconf(ims, ent->name, ent->fname);
186 if (ret == NoError) {
198 return last - top + 1;
202 static int setup_local_selection(sel, list, conf_all)
210 idx = get_ims_idx(list, sel->name);
212 if (conf_all) last = list->num_ent - 1;
213 else if (idx >= 0) top = last = idx;
214 fill_ims_ent(list, top, last);
216 ret = setup_user_selection(sel, list, idx);
221 static int setup_remote_selection(sel)
228 ret = get_remote_conf(&new_list, sel->hostname, NULL, sel->name);
230 if (ret == NoError) {
231 idx = get_ims_idx(new_list, sel->name);
232 ret = setup_user_selection(sel, new_list, idx);
238 static int setup_user_selection(sel, list, idx)
245 sel->ent = list->elist[idx];
246 sel->status = sel->ent->status;
248 /* this ims isn't registered in locale_conf */
249 sel->status = ErrNotRegistered;
252 sel->status = ErrNoSelection;
259 int update_user_selection(sel, list, idx, host, host_type)
268 if (idx < 0 || idx >= list->num_ent) return False;
269 ent = list->elist[idx];
271 if (ent->status != NoError) return False;
273 if (strcmp(sel->name, ent->name)) {
274 RENEWSTR(sel->name, ent->name);
276 if ((host) && (!(sel->hostname) || strcmp(sel->hostname, host))) {
277 RENEWSTR(sel->hostname, host);
279 sel->host_type = host_type;
281 if (sel->list && sel->list != localList && sel->list != list) {
282 clear_ImsList(sel->list);
287 sel->status = ent->status;
289 sel->flag |= F_SELECT_CHANGED;
295 int get_ims_idx(list, name)
302 for (idx = 0; idx < list->num_ent; idx++)
303 if (strcmp(name, list->elist[idx]->name) == 0)
309 int set_ims_status(ent)
313 ImsConf *ims = ent->ims;
315 if (ent->name && strcmp(ent->name, NAME_NONE) == 0) {
319 } else if (ims->cmd_path && !(ims->flags & F_BUILTIN)
320 && !is_executable(ims->cmd_path)) {
321 DPR(("set_ims_status(%s): executable '%s' not exist\n",
322 ent->name, ims->cmd_path));
323 ret = ErrNoExecutable;
331 int get_ims_list(listp, locale, fill_ent)
339 list = ALLOC(1, ImsList);
341 if ((ret = read_localeconf(list, locale)) != NoError) {
342 ret = ErrNoLocaleConf;
343 } else if (list->num_ent == 0) {
344 DPR(("get_ims_list(%s): no IMS in locale conf\n", locale));
346 } else if (fill_ent) {
347 fill_ims_ent(list, 0, list->num_ent - 1);
350 if (ret == NoError) {
355 list = (ImsList *) 0;