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 /* $TOG: DtFindSet.C /main/5 1998/07/24 16:12:36 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
31 #include "DtFindSet.h"
32 #include "DtPrtProps.h"
35 #include "Container.h"
38 #include "ComboBoxObj.h"
39 #include "HelpSystem.h"
42 #include "dtprintinfomsg.h"
46 #include <unistd.h> // This is for the getuid function
47 #include <stdlib.h> // This is for the getenv function
49 const char *GET_DIRS =
51 "for i in $(echo $XMICONSEARCHPATH | sed -e 's/:/ /g' -e s/%L/$lang/g) ; "
56 // Subclass IconObj in order to disable SetOpen method
57 class FindSetIcon : public IconObj
61 FindSetIcon(AnyUI *parent, char *name, char *icon) :
62 IconObj(parent, name, icon) { }
63 boolean SetOpen(boolean) { return true; }
66 DtFindSet::DtFindSet(DtMainW *parent, char *name, CallerCallback _callback)
67 : Dialog(parent, name, MODAL)
74 Invoke *_thread = new Invoke(GET_DIRS, &output);
75 char *s, *s1 = output;
78 while (s && (s = strchr(s1, '\n')))
83 if (_thread->status || n_dirs == 0)
86 struct passwd * pwInfo;
87 char *home = getenv("HOME");
88 if (home == NULL || strlen(home) == 0)
90 pwInfo = getpwuid(getuid());
91 home = pwInfo->pw_dir;
93 output = new char[strlen(home) + 80];
95 sprintf(output, "%s/.dt/icons\n"
96 "/usr/dt/appconfig/icons/C\n"
97 "/etc/dt/appconfig/icons/C\n", (home[1] ? home : "" ));
99 dirs = new char *[n_dirs];
100 filenames = new FileNames [n_dirs];
103 for (i = 0; i < n_dirs; i++)
108 dirs[i] = strdup(s1);
109 filenames[i] = new FileNamesStruct;
110 filenames[i]->icons = NULL;
111 filenames[i]->read_it = true;
112 filenames[i]->n_icons = 0;
117 comboBox = new ComboBoxObj(this, ComboBoxCB, MESSAGE(IconFoldersL), dirs,
120 icon_label = new LabelObj(this, MESSAGE(IconTitleL));
121 icons = new Container(this, "icons", SCROLLED_WORK_AREA);
123 empty = new LabelObj(icons, MESSAGE(EmptyL));
124 empty->Visible(false);
126 comboBox->AttachTop(5);
127 comboBox->AttachLeft();
128 comboBox->AttachRight();
130 icon_label->AttachTop(comboBox, 10);
131 icon_label->AttachLeft();
132 icon_label->AttachRight();
133 icons->AttachTop(icon_label);
134 icons->AttachRight();
136 icons->AttachBottom();
138 ok = new Button(this, MESSAGE(OKL), PUSH_BUTTON, OkCB, this);
139 cancel = new Button(this, MESSAGE(CancelL), PUSH_BUTTON, CancelCB, this);
140 help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
143 CancelButton(cancel);
146 DtFindSet::~DtFindSet()
149 for (i = 0; i < n_dirs; i++)
158 void DtFindSet::InitComboBox(BaseUI *obj, void * /*data*/)
160 DtFindSet *findSet = (DtFindSet *)obj;
162 ComboBoxCB(findSet->comboBox, findSet->dirs[0], 1);
165 boolean DtFindSet::SetVisiblity(boolean flag)
167 if (last_position == -1)
168 AddTimeOut(&DtFindSet::InitComboBox, NULL, 1000);
169 Dialog::SetVisiblity(flag);
173 void DtFindSet::Reset()
177 void DtFindSet::Apply()
181 icons->Selection(&n_items, &items);
182 if (n_items && callback)
184 FindSetIcon *icon = (FindSetIcon *)items[0];
186 if (iconfile = strrchr(icon->IconFile(), '/'))
189 iconfile = icon->IconFile();
190 (*callback)(caller, iconfile);
195 void DtFindSet::CloseCB()
201 void DtFindSet::OkCB(void *data)
203 DtFindSet *obj = (DtFindSet *) data;
209 void DtFindSet::ApplyCB(void *data)
211 DtFindSet *obj = (DtFindSet *) data;
215 void DtFindSet::CancelCB(void *data)
217 DtFindSet *obj = (DtFindSet *) data;
223 void DtFindSet::ResetCB(void *data)
225 DtFindSet *obj = (DtFindSet *) data;
230 void DtFindSet::HelpCB(void *data)
232 DtFindSet *obj = (DtFindSet *) data;
233 obj->HandleHelpRequest();
236 boolean DtFindSet::HandleHelpRequest()
239 strcpy(old_msg, mainw->status_line->Name());
240 mainw->status_line->Name(MESSAGE(GettingHelpL));
241 mainw->WorkingCursor(true);
245 char *title = new char[120];
247 sprintf(title, "%s - %s", mainw->Name(), MESSAGE(HelpL));
249 helpSystem = new HelpSystem(this, title, "Printmgr", "FindSetDE",
251 helpSystem->Visible(true);
256 helpSystem->Visible(true);
257 helpSystem->Refresh();
258 helpSystem->HelpVolume("Printmgr", "FindSetDE");
260 mainw->status_line->Name(old_msg);
261 mainw->WorkingCursor(false);
265 void DtFindSet::ComboBoxCB(ComboBoxObj *obj, char *dir, int position)
267 DtFindSet *findSet = (DtFindSet *)obj->Parent();
268 if (findSet->last_position == position)
273 char *buf = new char[400]; // This allows for a directory len of 240 bytes
275 findSet->PointerShape(HOUR_GLASS_CURSOR);
276 findSet->icons->BeginUpdate();
277 findSet->icons->SelectAll(false);
278 if (findSet->last_position > 0)
280 filenames = findSet->filenames[findSet->last_position - 1];
281 FindSetIcon **icon = filenames->icons;
282 for (i = 0; i < filenames->n_icons; i++, icon++)
283 (*icon)->Visible(false);
285 filenames = findSet->filenames[position - 1];
286 if (filenames->read_it)
288 sprintf(buf, "cd %s 2> /dev/null ; "
289 "/bin/ls -1 | grep '\\.l\\.pm$' | "
290 "sed 's/\\.l\\.pm//g' | "
291 "while read file ; do "
292 "if [ -f $file.m.pm -a -f $file.t.pm ] ; "
293 "then echo $file ; fi ; "
297 Invoke *_thread = new Invoke(buf, &output);
298 char *s, *s1 = output;
300 filenames->n_icons = 0;
301 while (s && (s = strchr(s1, '\n')))
303 filenames->n_icons++;
306 if (filenames->n_icons)
309 filenames->icons = new FindSetIcon*[filenames->n_icons];
310 for (i = 0; i < filenames->n_icons; i++)
317 sprintf(buf, MESSAGE(LoadingIconsL), i, filenames->n_icons);
318 findSet->icons->UpdateMessage(buf);
320 sprintf(buf, "%s/%s", dir, s1);
321 filenames->icons[i] = new FindSetIcon(findSet->icons, s1, buf);
326 filenames->read_it = false;
330 FindSetIcon **icon = filenames->icons;
331 for (i = 0; i < filenames->n_icons; i++, icon++)
332 (*icon)->Visible(true);
334 findSet->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
335 findSet->icons->EndUpdate();
336 sprintf(buf, MESSAGE(IconTitleL), filenames->n_icons);
337 findSet->icon_label->Name(buf);
338 if (filenames->n_icons)
339 findSet->empty->Visible(false);
341 findSet->empty->Visible(true);
342 findSet->last_position = position;