Enable silent-rules for compilation
[fsviewer.git] / src / FSPrefs.c
blob9a625de5f51e8135ee7e4977eef85cb5e2cb9506
1 #include <X11/Xatom.h>
2 #include <X11/keysym.h>
3 #include <WINGs/WINGsP.h>
5 #include "FSViewer.h"
6 #include "FSUtils.h"
7 #include "FSPanel.h"
8 #include "FSPrefs.h"
10 #define WIN_WIDTH 572
11 #define WIN_HEIGHT 322
12 #define PADY 5
13 #define PADX 5
14 #define TABVIEW_HEIGHT WIN_HEIGHT-50
15 #define TABVIEW_WIDTH WIN_WIDTH-PADX*2
16 #define VARS_TAB 0
17 #define APPS_TAB 1
18 #define DISCS_TAB 2
19 #define NUM_TABS 3
22 typedef struct _DISK
24 /* FSViewer *app; */
25 /* Nickname for mount point */
26 char *name;
27 /* Mount point */
28 char *point;
29 /* Device name */
30 char *device;
31 /* Mount Cmd */
32 char *mnt;
33 /* UMount cmd */
34 char *umnt;
35 /* Eject Cmd */
36 char *eject;
37 /* Close Cmd */
38 char *close;
40 } _DISK;
42 typedef struct _DISK Disc;
44 static FSPreferencesPanel *FSCreatePreferencesPanel(FSViewer*, char*);
45 static void FSClosePreferencesPanel(WMWidget*, void*);
46 static void FSDestroyPreferencesPanel(FSPreferencesPanel*);
47 static void createVarsTab(FSPreferencesPanel *prefs);
48 static void createDiskTab(FSPreferencesPanel *prefs);
49 static void createTypesTab(FSPreferencesPanel *prefs);
50 static void genericListClick(WMWidget *self, void *data);
51 static void genericButtonActionHandler(WMWidget *self, void *clientData);
52 static void setVarsImage(WMWidget *self, void *data);
53 static void populateVarsTab(FSPreferencesPanel *prefs);
54 static void populateTypesTab(FSPreferencesPanel *prefs);
55 static void populateDisksTab(FSPreferencesPanel *prefs);
56 static void populateDisksFields(FSPreferencesPanel *prefs);
57 static void populateAppsFields(FSPreferencesPanel *prefs);
58 static void populateTypesFields(FSPreferencesPanel *prefs);
59 static void applyBtnCB(WMWidget *self, void *client);
60 static void tfDidChange(struct WMTextFieldDelegate *self,
61 WMNotification *notif);
62 static void setTFDelegate(FSPreferencesPanel *prefs, WMTextField *tf);
63 static void setTVIDelegate(FSPreferencesPanel *prefs, WMTabView *tv);
64 static void tvDidSelectItem(struct WMTabViewDelegate *self,
65 WMTabView *tabView, WMTabViewItem *item);
66 static void saveTab(FSPreferencesPanel *prefs, int tabID);
67 static void saveVarsTab(FSPreferencesPanel *prefs);
68 static void saveAppsTab(FSPreferencesPanel *prefs);
69 static void saveDiscsTab(FSPreferencesPanel *prefs);
70 static void saveAllTabsAndClose(WMWidget *self, void *client);
71 static void genericListDrawProc(WMList *lPtr, int index, Drawable d,
72 char *text, int state, WMRect *rect);
76 static FSPreferencesPanel *preferences = NULL;
78 void FSRunPreferencesPanel(FSViewer *app, char *title)
80 if (preferences)
81 return;
83 if (!(preferences = FSCreatePreferencesPanel(app, title))) { return; }
85 WMMapWidget(preferences->win);
87 while (!(preferences->flags.done))
89 XEvent event;
91 WMNextEvent(preferences->dpy, &event);
92 WMHandleEvent(&event);
94 FSDestroyPreferencesPanel(preferences);
95 preferences = NULL;
98 static FSPreferencesPanel *FSCreatePreferencesPanel(FSViewer *app, char *title)
100 FSPreferencesPanel *prefs;
101 int height, width, offset;
102 WMPixmap *appicon;
103 WMFrame *f;
104 WMLabel *l;
105 WMTabViewItem *tab;
107 /* allocate memory for the prefernces panel */
108 if (!( prefs= (FSPreferencesPanel *)malloc(sizeof(FSPreferencesPanel))))
110 return NULL;
112 memset((void *) prefs, 0, sizeof(FSPreferencesPanel));
114 /* Take in some settings */
115 prefs->app = app;
116 prefs->scr = FSGetFSViewerScreen(app);
117 prefs->dpy = WMScreenDisplay(prefs->scr);
120 height = WIN_HEIGHT;
121 width = WIN_WIDTH;
123 prefs->win = WMCreateWindow(prefs->scr, "prefs");
124 WMResizeWidget(prefs->win, width, height);
125 WMSetWindowTitle(prefs->win, title);
126 WMSetWindowCloseAction(prefs->win, FSClosePreferencesPanel,
127 (void *) prefs);
129 prefs->frame = WMCreateFrame(prefs->win);
130 WMResizeWidget(prefs->frame, width, height);
131 WMMoveWidget(prefs->frame, 0, 0);
132 WMSetFrameRelief(prefs->frame, WRFlat);
134 prefs->tabV = WMCreateTabView(prefs->frame);
135 WMMoveWidget(prefs->tabV, 5, 5);
136 WMResizeWidget(prefs->tabV, TABVIEW_WIDTH, TABVIEW_HEIGHT);
137 setTVIDelegate(prefs, prefs->tabV);
139 /* variables Tab */
140 createVarsTab(prefs);
141 populateVarsTab(prefs);
143 /* App/File Types Tab*/
144 createTypesTab(prefs);
145 populateTypesTab(prefs);
147 /* Disks Tab*/
148 createDiskTab(prefs);
149 populateDisksTab(prefs);
151 /* Ok/Apply/Cancel Buttons */
152 prefs->cancelBtn = WMCreateCommandButton(prefs->frame);
153 WMSetButtonText(prefs->cancelBtn, _("Cancel"));
154 WMResizeWidget(prefs->cancelBtn, 100, 24);
155 WMMoveWidget(prefs->cancelBtn,
156 WIN_WIDTH-330, (WIN_HEIGHT+PADY+TABVIEW_HEIGHT-24)/2);
157 WMSetButtonAction(prefs->cancelBtn, FSClosePreferencesPanel, prefs);
158 WMMapWidget(prefs->cancelBtn);
160 prefs->applyBtn = WMCreateCommandButton(prefs->frame);
161 WMSetButtonText(prefs->applyBtn, _("Apply"));
162 WMResizeWidget(prefs->applyBtn, 100, 24);
163 WMMoveWidget(prefs->applyBtn,
164 WIN_WIDTH-215, (WIN_HEIGHT+PADY+TABVIEW_HEIGHT-24)/2);
165 WMSetButtonAction(prefs->applyBtn, applyBtnCB, prefs);
166 WMSetButtonEnabled(prefs->applyBtn, False);
167 WMMapWidget(prefs->applyBtn);
169 prefs->okBtn = WMCreateCommandButton(prefs->frame);
170 WMSetButtonText(prefs->okBtn, _("OK"));
171 WMResizeWidget(prefs->okBtn, 100, 24);
172 WMMoveWidget(prefs->okBtn,
173 WIN_WIDTH-105, (WIN_HEIGHT+PADY+TABVIEW_HEIGHT-24)/2);
174 WMSetButtonAction(prefs->okBtn, saveAllTabsAndClose, prefs);
175 WMSetButtonEnabled(prefs->okBtn, False);
176 WMMapWidget(prefs->okBtn);
178 prefs->flags.done = 0;
179 prefs->flags.evars = False;
180 prefs->flags.eapps = False;
181 prefs->flags.ediscs = False;
183 WMRealizeWidget(prefs->win);
185 FSAddWindow(prefs->app, WMWidgetXID(prefs->win));
186 WMMapSubwidgets(prefs->frame);
187 WMMapSubwidgets(prefs->win);
189 return prefs;
192 static void
193 createDiskTab(FSPreferencesPanel *prefs)
195 WMFrame *f;
196 WMFrame *f2;
197 WMLabel *l;
198 WMButton *b;
199 WMList *list;
200 WMTextField *tf;
201 WMTabViewItem *tab;
202 int frame_width = 255;
203 int frame_height = 220;
204 int padx = (TABVIEW_WIDTH-PADX*8-frame_width*2);
205 WMTextFieldDelegate *delegate = NULL;
206 f = WMCreateFrame(prefs->frame);
207 WMSetFrameRelief(f, WRFlat);
209 /* Start Disks */
210 f2 = WMCreateFrame(f);
211 WMSetFrameRelief(f2, WRGroove);
212 WMSetFrameTitle(f2, _(" Disks "));
213 WMMoveWidget(f2, PADX*2, 10);
214 WMResizeWidget(f2, TABVIEW_WIDTH-23, frame_height);
215 WMMapWidget(f2);
217 list = WMCreateList(f2);
218 WMMoveWidget(list, 10, 30);
219 WMResizeWidget(list, frame_width-20, 100);
220 WMSetListAction(list, genericListClick, prefs);
221 WMMapWidget(list);
222 prefs->disksList = list;
224 l = WMCreateLabel(f2);
225 WMResizeWidget(l, 45, 18);
226 WMMoveWidget(l, 10, 140);
227 WMSetLabelText(l, _("Name:"));
228 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
229 WMMapWidget(l);
231 tf = WMCreateTextField(f2);
232 WMResizeWidget(tf, 110, 18);
233 WMMoveWidget(tf, 50, 140);
234 WMSetTextFieldText(tf, _("Menu Name"));
235 setTFDelegate(prefs, tf);
236 WMMapWidget(tf);
237 prefs->disksNameTF = tf;
240 l = WMCreateLabel(f2);
241 WMResizeWidget(l, 45, 18);
242 WMMoveWidget(l, 10, 166);
243 WMSetLabelText(l, _("Mnt:"));
244 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
245 WMMapWidget(l);
247 tf = WMCreateTextField(f2);
248 WMResizeWidget(tf, 110, 18);
249 WMMoveWidget(tf, 50, 166);
250 WMSetTextFieldText(tf, _("Mount Point"));
251 /* WMSetTextFieldDelegate(tPtr, delegate); */
252 setTFDelegate(prefs, tf);
253 WMMapWidget(tf);
254 prefs->disksMntTF = tf;
257 l = WMCreateLabel(f2);
258 WMResizeWidget(l, 45, 18);
259 WMMoveWidget(l, 10, 192);
260 WMSetLabelText(l, _("Dev:"));
261 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
262 WMMapWidget(l);
264 tf = WMCreateTextField(f2);
265 WMResizeWidget(tf, 110, 18);
266 WMMoveWidget(tf, 50, 192);
267 WMSetTextFieldText(tf, _("Device"));
268 setTFDelegate(prefs, tf);
269 /* WMSetTextFieldDelegate(tPtr, delegate); */
270 WMMapWidget(tf);
271 prefs->disksDevTF = tf;
274 b = WMCreateCommandButton(f2);
275 WMResizeWidget(b, 68, 18);
276 WMMoveWidget(b, 175, 140);
277 WMSetButtonText(b, _("New"));
278 WMSetButtonAction(b, genericButtonActionHandler, prefs);
279 WMMapWidget(b);
280 prefs->disksNewBtn = b;
283 b = WMCreateCommandButton(f2);
284 WMResizeWidget(b, 68, 18);
285 WMMoveWidget(b, 175, 166);
286 WMSetButtonText(b, _("Update"));
287 WMSetButtonAction(b, genericButtonActionHandler, prefs);
288 WMMapWidget(b);
289 prefs->disksUpdateBtn = b;
292 b = WMCreateCommandButton(f2);
293 WMResizeWidget(b, 68, 18);
294 WMMoveWidget(b, 175, 192);
295 WMSetButtonText(b, _("Remove"));
296 WMSetButtonAction(b, genericButtonActionHandler, prefs);
297 WMMapWidget(b);
298 prefs->disksRemoveBtn = b;
299 /* End Disks */
302 /* Start Commands */
303 /* f2 = WMCreateFrame(f); */
304 /* WMSetFrameRelief(f2, WRGroove); */
305 /* WMSetFrameTitle(f2, " Commands "); */
306 /* WMMoveWidget(f2, frame_width+PADX*2+padx, 10); */
307 /* WMResizeWidget(f2, frame_width, frame_height); */
308 /* WMMapWidget(f2); */
310 l = WMCreateLabel(f2);
311 WMResizeWidget(l, frame_width-20, 18);
312 WMMoveWidget(l, frame_width+PADX*2+padx+10, 30);
313 WMSetLabelText(l, _("Mount:"));
314 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
315 WMMapWidget(l);
317 tf = WMCreateTextField(f2);
318 WMResizeWidget(tf, frame_width-20, 18);
319 WMMoveWidget(tf, frame_width+PADX*2+padx+10, 48);
320 WMSetTextFieldText(tf, _("App"));
321 /* WMSetTextFieldDelegate(tPtr, delegate); */
322 setTFDelegate(prefs, tf);
323 WMMapWidget(tf);
324 prefs->cmdMntTF = tf;
327 l = WMCreateLabel(f2);
328 WMResizeWidget(l, frame_width-20, 18);
329 WMMoveWidget(l, frame_width+PADX*2+padx+10, 76);
330 WMSetLabelText(l, _("Unmount:"));
331 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
332 WMMapWidget(l);
334 tf = WMCreateTextField(f2);
335 WMResizeWidget(tf, frame_width-20, 18);
336 WMMoveWidget(tf, frame_width+PADX*2+padx+10, 94);
337 WMSetTextFieldText(tf, _("App"));
338 /* WMSetTextFieldDelegate(tPtr, delegate); */
339 setTFDelegate(prefs, tf);
340 WMMapWidget(tf);
341 prefs->cmdUMntTF = tf;
344 l = WMCreateLabel(f2);
345 WMResizeWidget(l, frame_width-20, 18);
346 WMMoveWidget(l, frame_width+PADX*2+padx+10, 122);
347 WMSetLabelText(l, _("Eject:"));
348 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
349 WMMapWidget(l);
351 tf = WMCreateTextField(f2);
352 WMResizeWidget(tf, frame_width-20, 18);
353 WMMoveWidget(tf, frame_width+PADX*2+padx+10, 140);
354 WMSetTextFieldText(tf, _("App"));
355 /* WMSetTextFieldDelegate(tPtr, delegate); */
356 setTFDelegate(prefs, tf);
357 WMMapWidget(tf);
358 prefs->cmdEjectTF = tf;
361 l = WMCreateLabel(f2);
362 WMResizeWidget(l, frame_width-20, 18);
363 WMMoveWidget(l, frame_width+PADX*2+padx+10, 168);
364 WMSetLabelText(l, _("Close:"));
365 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
366 WMMapWidget(l);
368 tf = WMCreateTextField(f2);
369 WMResizeWidget(tf, frame_width-20, 18);
370 WMMoveWidget(tf, frame_width+PADX*2+padx+10, 186);
371 WMSetTextFieldText(tf, _("close tray"));
372 /* WMSetTextFieldDelegate(tPtr, delegate); */
373 setTFDelegate(prefs, tf);
374 WMMapWidget(tf);
375 prefs->cmdCloseTF = tf;
376 /* End Commands */
378 tab = WMCreateTabViewItemWithIdentifier(DISCS_TAB);
379 WMSetTabViewItemView(tab, WMWidgetView(f));
380 WMAddItemInTabView(prefs->tabV, tab);
381 WMSetTabViewItemLabel(tab, _("Disks"));
384 static void
385 createTypesTab(FSPreferencesPanel *prefs)
387 WMFrame *f;
388 WMFrame *f2;
389 WMLabel *l;
390 WMButton *b;
391 WMList *list;
392 WMTextField *tf;
393 WMTabViewItem *tab;
394 int frame_width = 255;
395 int frame_height = 220;
396 int padx = (TABVIEW_WIDTH-PADX*4-frame_width*2);
398 f = WMCreateFrame(prefs->frame);
399 WMSetFrameRelief(f, WRFlat);
401 /* Start Apps */
402 f2 = WMCreateFrame(f);
403 WMSetFrameRelief(f2, WRGroove);
404 WMSetFrameTitle(f2, _(" Applications "));
405 WMMoveWidget(f2, PADX*2, 10);
406 WMResizeWidget(f2, frame_width, frame_height);
407 WMMapWidget(f2);
409 list = WMCreateList(f2);
410 WMMoveWidget(list, 10, 30);
411 WMResizeWidget(list, frame_width-100, 100);
412 WMSetListAction(list, genericListClick, prefs);
413 WMSetListUserDrawProc(list, genericListDrawProc);
414 WMMapWidget(list);
415 prefs->appsList = list;
417 b = WMCreateCommandButton(f2);
418 WMMoveWidget(b, 175, 46);
419 WMResizeWidget(b, 68, 68);
420 WMSetButtonEnabled(b, True);
421 WMSetButtonAction(b, genericButtonActionHandler, prefs);
422 WMSetButtonImagePosition(b, WIPImageOnly);
423 WMMapWidget(b);
424 prefs->appsIconBtn = b;
427 l = WMCreateLabel(f2);
428 WMResizeWidget(l, 40, 18);
429 WMMoveWidget(l, 10, 140);
430 WMSetLabelText(l, _("Exec:"));
431 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
432 WMMapWidget(l);
434 tf = WMCreateTextField(f2);
435 WMResizeWidget(tf, 115, 18);
436 WMMoveWidget(tf, 50, 140);
437 WMSetTextFieldText(tf, _("App"));
438 /* WMSetTextFieldDelegate(tPtr, delegate); */
439 setTFDelegate(prefs, tf);
440 WMMapWidget(tf);
441 prefs->appsExecTF = tf;
444 b = WMCreateCommandButton(f2);
445 WMResizeWidget(b, 68, 18);
446 WMMoveWidget(b, 175, 140);
447 WMSetButtonText(b, _("Browse..."));
448 WMSetButtonAction(b, genericButtonActionHandler, prefs);
449 WMMapWidget(b);
450 prefs->appsBrowseBtn = b;
453 b = WMCreateCommandButton(f2);
454 WMResizeWidget(b, 73, 18);
455 WMMoveWidget(b, 10, 166);
456 WMSetButtonText(b, _("Set"));
457 WMSetButtonAction(b, genericButtonActionHandler, prefs);
458 WMMapWidget(b);
459 prefs->appsSetBtn = b;
461 b = WMCreateCommandButton(f2);
462 WMResizeWidget(b, 73, 18);
463 WMMoveWidget(b, 93, 166);
464 WMSetButtonText(b, _("Delete"));
465 WMSetButtonAction(b, genericButtonActionHandler, prefs);
466 WMMapWidget(b);
467 prefs->appsRemoveBtn = b;
468 /* End Apps */
470 /* Start File Types */
471 f2 = WMCreateFrame(f);
472 WMSetFrameRelief(f2, WRGroove);
473 WMSetFrameTitle(f2, _(" File Types "));
474 WMMoveWidget(f2, frame_width+PADX*2+padx, 10);
475 WMResizeWidget(f2, frame_width, frame_height);
476 WMMapWidget(f2);
478 list = WMCreateList(f2);
479 WMMoveWidget(list, 10, 30);
480 WMResizeWidget(list, frame_width-100, 100);
481 WMSetListAction(list, genericListClick, prefs);
482 WMSetListUserDrawProc(list, genericListDrawProc);
483 WMMapWidget(list);
484 prefs->typesList = list;
487 b = WMCreateCommandButton(f2);
488 WMMoveWidget(b, 175, 46);
489 WMResizeWidget(b, 68, 68);
490 WMSetButtonEnabled(b, True);
491 WMSetButtonAction(b, genericButtonActionHandler, prefs);
492 WMSetButtonImagePosition(b, WIPImageOnly);
493 WMMapWidget(b);
494 prefs->typesIconBtn = b;
497 l = WMCreateLabel(f2);
498 WMResizeWidget(l, 40, 18);
499 WMMoveWidget(l, 10, 140);
500 WMSetLabelText(l, _("View:"));
501 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
502 WMMapWidget(l);
504 tf = WMCreateTextField(f2);
505 WMResizeWidget(tf, 115, 18);
506 WMMoveWidget(tf, 50, 140);
507 WMSetTextFieldText(tf, _("App"));
508 /* WMSetTextFieldDelegate(tPtr, delegate); */
509 setTFDelegate(prefs, tf);
510 WMMapWidget(tf);
511 prefs->typesViewTF = tf;
514 b = WMCreateCommandButton(f2);
515 WMResizeWidget(b, 68, 18);
516 WMMoveWidget(b, 175, 140);
517 WMSetButtonText(b, _("Browse..."));
518 WMSetButtonAction(b, genericButtonActionHandler, prefs);
519 WMMapWidget(b);
520 /* Could use WMHangData instead!!! */
521 prefs->typesViewBrowseBtn = b;
523 l = WMCreateLabel(f2);
524 WMResizeWidget(l, 40, 18);
525 WMMoveWidget(l, 10, 166);
526 WMSetLabelText(l, _("Edit:"));
527 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
528 WMMapWidget(l);
530 tf = WMCreateTextField(f2);
531 WMResizeWidget(tf, 115, 18);
532 WMMoveWidget(tf, 50, 166);
533 WMSetTextFieldText(tf, _("App"));
534 /* WMSetTextFieldDelegate(tPtr, delegate); */
535 setTFDelegate(prefs, tf);
536 WMMapWidget(tf);
537 prefs->typesEditTF = tf;
540 b = WMCreateCommandButton(f2);
541 WMResizeWidget(b, 68, 18);
542 WMMoveWidget(b, 175, 166);
543 WMSetButtonText(b, _("Browse..."));
544 WMSetButtonAction(b, genericButtonActionHandler, prefs);
545 WMMapWidget(b);
546 prefs->typesEditBrowseBtn = b;
549 b = WMCreateCommandButton(f2);
550 WMResizeWidget(b, 73, 18);
551 WMMoveWidget(b, 10, 192);
552 WMSetButtonText(b, _("Set"));
553 WMSetButtonAction(b, genericButtonActionHandler, prefs);
554 WMMapWidget(b);
555 prefs->typesSetBtn = b;
557 b = WMCreateCommandButton(f2);
558 WMResizeWidget(b, 73, 18);
559 WMMoveWidget(b, 93, 192);
560 WMSetButtonText(b, _("Delete"));
561 WMSetButtonAction(b, genericButtonActionHandler, prefs);
562 WMMapWidget(b);
563 prefs->typesRemoveBtn = b;
564 /* End Executables */
567 tab = WMCreateTabViewItemWithIdentifier(APPS_TAB);
568 WMSetTabViewItemView(tab, WMWidgetView(f));
569 WMAddItemInTabView(prefs->tabV, tab);
570 WMSetTabViewItemLabel(tab, _("App/File Types"));
574 static void
575 createVarsTab(FSPreferencesPanel *prefs)
577 WMFrame *f;
578 WMFrame *f2;
579 WMLabel *l;
580 WMButton *b;
581 WMList *list;
582 WMTextField *tf;
583 WMTabViewItem *tab;
584 int frame_width = 155;
585 int frame_height = 220;
586 int padx = (TABVIEW_WIDTH-PADX*4-frame_width*3)/2;
588 f = WMCreateFrame(prefs->frame);
589 WMSetFrameRelief(f, WRFlat);
591 /* Start Images */
592 f2 = WMCreateFrame(f);
593 WMSetFrameRelief(f2, WRGroove);
594 WMSetFrameTitle(f2, _(" Images "));
595 WMMoveWidget(f2, PADX*2, 10);
596 WMResizeWidget(f2, frame_width, frame_height);
597 WMMapWidget(f2);
599 list = WMCreateList(f2);
600 WMMoveWidget(list, 10, 30);
601 WMResizeWidget(list, frame_width-20, 100);
602 WMSetListAction(list, genericListClick, prefs);
603 WMMapWidget(list);
604 prefs->imgList = list;
607 b = WMCreateCommandButton(f2);
608 WMMoveWidget(b, (frame_width-68)/2, 140);
609 WMResizeWidget(b, 68, 68);
610 WMSetButtonEnabled(b, True);
611 WMSetButtonAction(b, genericButtonActionHandler, prefs);
612 WMSetButtonImagePosition(b, WIPImageOnly);
613 WMMapWidget(b);
614 prefs->imgIconBtn = b;
615 /* End Images */
617 /* Start Executables */
618 f2 = WMCreateFrame(f);
619 WMSetFrameRelief(f2, WRGroove);
620 WMSetFrameTitle(f2, _(" Executables "));
621 WMMoveWidget(f2, frame_width+PADX*2+padx, 10);
622 WMResizeWidget(f2, frame_width, frame_height);
623 WMMapWidget(f2);
625 list = WMCreateList(f2);
626 WMMoveWidget(list, 10, 30);
627 WMResizeWidget(list, frame_width-20, 100);
628 WMSetListAction(list, genericListClick, prefs);
629 WMMapWidget(list);
630 prefs->execList = list;
633 l = WMCreateLabel(f2);
634 WMMoveWidget(l, 10, 140);
635 WMResizeWidget(l, frame_width-20, 18);
636 WMSetLabelText(l, _("Exec Str:"));
637 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
638 WMMapWidget(l);
640 tf = WMCreateTextField(f2);
641 WMMoveWidget(tf, 10, 160);
642 WMResizeWidget(tf, frame_width-20, 18);
643 WMSetTextFieldText(tf, _("Exes:"));
644 /* WMSetTextFieldDelegate(tPtr, delegate); */
645 setTFDelegate(prefs, tf);
646 WMMapWidget(tf);
647 prefs->execTF = tf;
650 b = WMCreateCommandButton(f2);
651 WMResizeWidget(b, 80, 18);
652 WMMoveWidget(b, (frame_width-80)/2, 188);
653 WMSetButtonText(b, _("Set"));
654 WMSetButtonAction(b, genericButtonActionHandler, prefs);
655 WMMapWidget(b);
656 prefs->execSetBtn = b;
657 /* End Executables */
659 /* Start Display */
660 f2 = WMCreateFrame(f);
661 WMSetFrameRelief(f2, WRGroove);
662 WMSetFrameTitle(f2, _(" Display "));
663 WMMoveWidget(f2, PADX*2+frame_width*2+padx*2, 10);
664 WMResizeWidget(f2, frame_width, frame_height);
665 WMMapWidget(f2);
667 list = WMCreateList(f2);
668 WMMoveWidget(list, 10, 30);
669 WMResizeWidget(list, frame_width-20, 100);
670 WMSetListAction(list, genericListClick, prefs);
671 WMMapWidget(list);
672 prefs->dpyList = list;
675 l = WMCreateLabel(f2);
676 WMMoveWidget(l, 10, 140);
677 WMResizeWidget(l, frame_width-20, 18);
678 WMSetLabelText(l, _("Display:"));
679 WMSetLabelTextColor(l, WMDarkGrayColor(prefs->scr));
680 WMMapWidget(l);
682 tf = WMCreateTextField(f2);
683 WMMoveWidget(tf, 10, 160);
684 WMResizeWidget(tf, frame_width-20, 18);
685 WMSetTextFieldText(tf, _("Display"));
686 /* WMSetTextFieldDelegate(tPtr, delegate); */
687 setTFDelegate(prefs, tf);
688 WMMapWidget(tf);
689 prefs->dpyTF = tf;
692 b = WMCreateCommandButton(f2);
693 WMResizeWidget(b, 80, 18);
694 WMMoveWidget(b, (frame_width-80)/2, 188);
695 WMSetButtonText(b, _("Set"));
696 WMSetButtonAction(b, genericButtonActionHandler, prefs);
697 WMMapWidget(b);
698 prefs->dpySetBtn = b;
699 /* End Display */
701 tab = WMCreateTabViewItemWithIdentifier(VARS_TAB);
702 WMSetTabViewItemView(tab, WMWidgetView(f));
703 WMAddItemInTabView(prefs->tabV, tab);
704 WMSetTabViewItemLabel(tab, _("Variables"));
708 static void
709 populateVarsTab(FSPreferencesPanel *prefs)
711 WMListItem *item;
713 item = WMAddListItem(prefs->imgList, "ROOT");
714 if (item)
715 item->clientData = FSGetStringForNameKey("ROOT", "icon");
717 item = WMAddListItem(prefs->imgList, "DIRECTORY");
718 if (item)
719 item->clientData = FSGetStringForName("DIRECTORY");
721 item = WMAddListItem(prefs->imgList, "DEFAULT_IMG");
722 if (item)
723 item->clientData = FSGetStringForName("DEFAULT_IMG");
725 item = WMAddListItem(prefs->imgList, "HOME");
726 if (item)
727 item->clientData = FSGetStringForName("HOME");
729 item = WMAddListItem(prefs->execList, "CONSOLE");
730 if (item)
731 item->clientData = FSGetStringForNameKey("CONSOLE", "exec");
733 item = WMAddListItem(prefs->execList, "PROCESS");
734 if (item)
735 item->clientData = FSGetStringForNameKey("PROCESS", "exec");
737 item = WMAddListItem(prefs->execList, "MAGICASCII");
738 if (item)
739 item->clientData = FSGetStringForNameKey("MAGICASCII", "exec");
741 item = WMAddListItem(prefs->execList, "MAGICIMAGE");
742 if (item)
743 item->clientData = FSGetStringForNameKey("MAGICIMAGE", "exec");
745 item = WMAddListItem(prefs->execList, "MAGICPS");
746 if (item)
747 item->clientData = FSGetStringForNameKey("MAGICPS", "exec");
749 item = WMAddListItem(prefs->dpyList, "ColumnWidth");
750 if (item)
752 char buf[10];
754 sprintf(buf, "%d", FSGetIntegerForName("ColumnWidth"));
755 item->clientData = wstrdup(buf);
758 /* item = WMAddListItem(prefs->dpyList, "IconWidth"); */
759 /* if (item) */
760 /* { */
761 /* char buf[10]; */
763 /* sprintf(buf, "%d", WMGetIntegerForKey(defaultsDB, "IconWidth")); */
764 /* item->clientData = wstrdup(buf); */
765 /* } */
767 item = WMAddListItem(prefs->dpyList, "ICONDIR");
768 if (item)
769 item->clientData = FSGetStringForName("ICONDIR");
771 item = WMAddListItem(prefs->dpyList, "SortDisplay");
772 if (item)
774 char buf[10];
776 sprintf(buf, "%d", FSGetIntegerForName("SortDisplay"));
777 item->clientData = wstrdup(buf);
780 item = WMAddListItem(prefs->dpyList, "SortOrder");
781 if (item)
783 char buf[10];
785 sprintf(buf, "%d", FSGetIntegerForName("SortOrder"));
786 item->clientData = wstrdup(buf);
789 item = WMAddListItem(prefs->dpyList, "DisplaySVBG");
790 if (item)
792 char buf[10];
794 sprintf(buf, "%d", FSGetIntegerForName("DisplaySVBG"));
795 item->clientData = wstrdup(buf);
798 item = WMAddListItem(prefs->dpyList, "DisplayMCListPixmap");
799 if (item)
801 char buf[10];
803 sprintf(buf, "%d", FSGetIntegerForName("DisplayMCListPixmap"));
804 item->clientData = wstrdup(buf);
806 WMSortListItems(prefs->imgList);
807 WMSortListItems(prefs->execList);
808 WMSortListItems(prefs->dpyList);
812 static void
813 populateTypesTab(FSPreferencesPanel *prefs)
815 int numElem, i;
816 WMListItem *item = NULL;
817 WMPropList* array = NULL;
818 WMPropList* element = NULL;
820 WMClearList(prefs->typesList);
821 WMSetTextFieldText(prefs->appsExecTF, "");
822 WMSetButtonImage(prefs->appsIconBtn, NULL);
824 WMClearList(prefs->appsList);
825 WMSetTextFieldText(prefs->typesViewTF, "");
826 WMSetTextFieldText(prefs->typesEditTF, "");
827 WMSetButtonImage(prefs->typesIconBtn, NULL);
829 array = FSGetUDObjectForKey(defaultsDB, "EXTN");
830 if (array && WMIsPLArray(array))
833 numElem = WMGetPropListItemCount(array);
834 for(i = 0; i < numElem; i++)
836 element = WMGetFromPLArray(array, i);
838 if (element)
840 char *str = WMGetPropListDescription(element, False);
842 if (str)
843 item = WMAddListItem(prefs->typesList, str);
844 else
845 continue;
847 if (item)
849 WMPropList* tmp = NULL;
851 tmp = FSGetUDObjectForKey(defaultsDB, str);
852 if (tmp)
853 item->clientData = WMDeepCopyPropList(tmp);
855 if (str)
856 free(str);
861 array = FSGetUDObjectForKey(defaultsDB, "EXE");
862 if (array && WMIsPLArray(array))
864 numElem = WMGetPropListItemCount(array);
865 for(i = 0; i < numElem; i++)
867 element = WMGetFromPLArray(array, i);
869 if (element)
871 char *str = WMGetPropListDescription(element, False);
873 if (str)
874 item = WMAddListItem(prefs->appsList, str);
875 else
876 continue;
878 if (item)
880 WMPropList* tmp = NULL;
882 tmp = FSGetUDObjectForKey(defaultsDB, str);
883 if (tmp)
884 item->clientData = WMDeepCopyPropList(tmp);
886 if (str)
887 free(str);
891 /* new in 0.2.5 */
892 WMSortListItems(prefs->appsList);
893 WMSortListItems(prefs->typesList);
896 static void
897 populateDisksTab(FSPreferencesPanel *prefs)
899 WMPropList* devArray = NULL;
900 WMPropList* array = NULL;
902 devArray = FSGetUDObjectForKey(defaultsDB, "DISCS");
904 if (devArray && WMIsPLArray(devArray))
906 int i, numElem;
907 WMPropList* tmp;
909 numElem = WMGetPropListItemCount(devArray);
910 for(i = 0; i < numElem; i++)
912 array = WMGetFromPLArray(devArray, i);
913 if (array && WMIsPLArray(array))
915 Disc *disk = NULL;
916 WMListItem *item = NULL;
918 disk = (Disc *) wmalloc(sizeof(Disc));
919 memset(disk, 0, sizeof(Disc));
921 tmp = WMGetFromPLArray(array, 0);
922 if (WMIsPLString(tmp))
924 disk->name = wstrdup(WMGetFromPLString(tmp));
925 item = WMAddListItem(prefs->disksList, disk->name);
927 else
929 continue;
932 tmp = WMGetFromPLArray(array, 1);
933 if (WMIsPLString(tmp))
934 disk->point = wstrdup(WMGetFromPLString(tmp));
936 tmp = WMGetFromPLArray(array, 2);
937 if (WMIsPLString(tmp))
938 disk->device = wstrdup(WMGetFromPLString(tmp));
940 tmp = WMGetFromPLArray(array, 3);
941 if (WMIsPLString(tmp))
942 disk->mnt = wstrdup(WMGetFromPLString(tmp));
944 tmp = WMGetFromPLArray(array, 4);
945 if (WMIsPLString(tmp))
946 disk->umnt = wstrdup(WMGetFromPLString(tmp));
948 tmp = WMGetFromPLArray(array, 5);
949 if (WMIsPLString(tmp))
950 disk->eject = wstrdup(WMGetFromPLString(tmp));
952 tmp = WMGetFromPLArray(array, 6);
953 if (WMIsPLString(tmp))
954 disk->close = wstrdup(WMGetFromPLString(tmp));
956 if (item)
957 item->clientData = disk;
961 WMSortListItems(prefs->disksList);
964 static void
965 populateDisksFields(FSPreferencesPanel *prefs)
967 WMListItem *item = WMGetListSelectedItem(prefs->disksList);
968 Disc *disk = (Disc *)item->clientData;
970 if (disk->name)
971 WMSetTextFieldText(prefs->disksNameTF, disk->name);
972 else
973 WMSetTextFieldText(prefs->disksNameTF, "");
975 if (disk->point)
976 WMSetTextFieldText(prefs->disksMntTF, disk->point);
977 else
978 WMSetTextFieldText(prefs->disksMntTF, "");
980 if (disk->device)
981 WMSetTextFieldText(prefs->disksDevTF, disk->device);
982 else
983 WMSetTextFieldText(prefs->disksDevTF, "");
985 if (disk->mnt)
986 WMSetTextFieldText(prefs->cmdMntTF, disk->mnt);
987 else
988 WMSetTextFieldText(prefs->cmdMntTF, "");
990 if (disk->umnt)
991 WMSetTextFieldText(prefs->cmdUMntTF, disk->umnt);
992 else
993 WMSetTextFieldText(prefs->cmdUMntTF, "");
995 if (disk->eject)
996 WMSetTextFieldText(prefs->cmdEjectTF, disk->eject);
997 else
998 WMSetTextFieldText(prefs->cmdEjectTF, "");
1000 if (disk->close)
1001 WMSetTextFieldText(prefs->cmdCloseTF, disk->close);
1002 else
1003 WMSetTextFieldText(prefs->cmdCloseTF, "");
1007 static void
1008 populateAppsFields(FSPreferencesPanel *prefs)
1010 char *str = NULL;
1011 WMPropList* val = NULL;
1012 WMListItem *item = WMGetListSelectedItem(prefs->appsList);
1014 if (!item)
1015 return;
1017 val = FSGetDBObjectForKey(item->clientData, "exec");
1018 if (val && WMIsPLString(val))
1019 WMSetTextFieldText(prefs->appsExecTF, WMGetFromPLString(val));
1021 val = FSGetDBObjectForKey(item->clientData, "icon");
1022 if (val && WMIsPLString(val))
1024 char *img = LocateImage(WMGetFromPLString(val));
1026 if (img)
1028 FSSetButtonImageFromFile(prefs->appsIconBtn, img);
1029 WMHangData(prefs->appsIconBtn, WMGetFromPLString(val));
1030 free(img);
1033 else
1034 WMSetButtonImage(prefs->appsIconBtn, NULL);
1037 * uflags indicates whether or not the list item should be
1038 * removed.
1040 if (item->uflags)
1041 WMSetButtonText(prefs->appsRemoveBtn, _("Undelete"));
1042 else
1043 WMSetButtonText(prefs->appsRemoveBtn, _("Delete"));
1046 static void
1047 populateTypesFields(FSPreferencesPanel *prefs)
1049 char *str = NULL;
1050 WMPropList* val = NULL;
1051 WMListItem *item = WMGetListSelectedItem(prefs->typesList);
1053 if (!item)
1054 return;
1056 val = FSGetDBObjectForKey(item->clientData, "editor");
1057 if (val && WMIsPLString(val))
1058 WMSetTextFieldText(prefs->typesEditTF, WMGetFromPLString(val));
1059 else
1060 WMSetTextFieldText(prefs->typesEditTF, "");
1062 val = FSGetDBObjectForKey(item->clientData, "viewer");
1063 if (val && WMIsPLString(val))
1064 WMSetTextFieldText(prefs->typesViewTF, WMGetFromPLString(val));
1065 else
1066 WMSetTextFieldText(prefs->typesViewTF, "");
1068 val = FSGetDBObjectForKey(item->clientData, "icon");
1069 if (val && WMIsPLString(val))
1071 char *img = LocateImage(WMGetFromPLString(val));
1073 if (img)
1075 FSSetButtonImageFromFile(prefs->typesIconBtn, img);
1076 WMHangData(prefs->typesIconBtn, WMGetFromPLString(val));
1077 free(img);
1080 else
1081 WMSetButtonImage(prefs->typesIconBtn, NULL);
1083 if (item->uflags)
1085 WMSetButtonText(prefs->typesRemoveBtn, _("Undelete"));
1087 else
1089 WMSetButtonText(prefs->typesRemoveBtn, _("Delete"));
1094 static clearDisksFields(FSPreferencesPanel *prefs)
1096 WMSetTextFieldText(prefs->disksNameTF, "");
1097 WMSetTextFieldText(prefs->disksMntTF, "");
1098 WMSetTextFieldText(prefs->disksDevTF, "");
1099 WMSetTextFieldText(prefs->cmdMntTF, "");
1100 WMSetTextFieldText(prefs->cmdUMntTF, "");
1101 WMSetTextFieldText(prefs->cmdEjectTF, "");
1102 WMSetTextFieldText(prefs->cmdCloseTF, "");
1105 static void
1106 updateDisksList(FSPreferencesPanel *prefs)
1108 WMListItem *item = WMGetListSelectedItem(prefs->disksList);
1109 Disc *disk = NULL;
1110 char *name = WMGetTextFieldText(prefs->disksNameTF);
1112 if (item)
1114 /* If an item is selected, update it's settings */
1115 disk = (Disc *) item->clientData;
1116 item->text = name;
1118 else
1120 /* If no item has been selected, its a new entry */
1121 disk = (Disc *) wmalloc(sizeof(Disc));
1122 memset(disk, 0, sizeof(Disc));
1124 item = WMAddListItem(prefs->disksList, name);
1125 item->clientData = disk;
1129 * This could be a problem if an empty entry is
1130 * created. I wonder what will happen!!
1132 if (disk)
1134 disk->name = WMGetTextFieldText(prefs->disksNameTF);
1135 disk->point = WMGetTextFieldText(prefs->disksMntTF);
1136 disk->device = WMGetTextFieldText(prefs->disksDevTF);
1137 disk->mnt = WMGetTextFieldText(prefs->cmdMntTF);
1138 disk->umnt = WMGetTextFieldText(prefs->cmdUMntTF);
1139 disk->eject = WMGetTextFieldText(prefs->cmdEjectTF);
1140 disk->close = WMGetTextFieldText(prefs->cmdCloseTF);
1144 static void
1145 genericListClick(WMWidget *self, void *data)
1147 WMList *list = (WMList *) self;
1148 WMListItem *item = WMGetListSelectedItem(list);
1149 FSPreferencesPanel *prefs = (FSPreferencesPanel *) data;
1151 if (list == prefs->imgList)
1153 char *img = NULL;
1155 img = LocateImage(item->clientData);
1157 if (img)
1159 FSSetButtonImageFromFile(prefs->imgIconBtn, img);
1160 free(img);
1163 else if (list == prefs->execList)
1165 WMSetTextFieldText(prefs->execTF, item->clientData);
1167 else if (list == prefs->dpyList)
1169 WMSetTextFieldText(prefs->dpyTF, item->clientData);
1171 else if (list == prefs->disksList)
1173 populateDisksFields(prefs);
1175 else if (list == prefs->typesList)
1177 populateTypesFields(prefs);
1179 else if (list == prefs->appsList)
1181 populateAppsFields(prefs);
1185 static void
1186 genericButtonActionHandler(WMWidget *self, void *clientData)
1188 Bool edited = False;
1189 WMOpenPanel *oPanel = NULL;
1190 WMButton *btn = (WMButton *) self;
1191 FSPreferencesPanel *prefs = (FSPreferencesPanel *) clientData;
1193 if (btn == prefs->imgIconBtn)
1195 char *img = NULL;
1196 char *tmp = NULL;
1197 WMListItem *item = WMGetListSelectedItem(prefs->imgList);
1199 if (!item || !item->clientData)
1200 return;
1202 tmp = FSRunSelectIconPanel(prefs->win, _("Icon Select"),item->clientData);
1203 if (tmp == NULL)
1204 return;
1206 img = LocateImage(tmp);
1207 if (img)
1209 FSSetButtonImageFromFile(prefs->imgIconBtn, img);
1210 free(img);
1212 free(item->clientData);
1213 item->clientData = tmp;
1214 edited = True;
1216 else if (btn == prefs->execSetBtn)
1218 WMListItem *item = WMGetListSelectedItem(prefs->execList);
1220 if (!item)
1221 return;
1223 item->clientData = WMGetTextFieldText(prefs->execTF);
1224 edited = True;
1225 /* WMSetTextFieldText(prefs->execTF, ""); */
1226 /* WMSelectListItem(prefs->execList, -1); */
1228 else if (btn == prefs->dpySetBtn)
1230 WMListItem *item = WMGetListSelectedItem(prefs->dpyList);
1232 if (!item)
1233 return;
1235 item->clientData = WMGetTextFieldText(prefs->dpyTF);
1236 /* WMSetTextFieldText(prefs->dpyTF, ""); */
1237 /* WMSelectListItem(prefs->dpyList, -1); */
1238 edited = True;
1240 else if (btn == prefs->disksNewBtn)
1242 clearDisksFields(prefs);
1243 WMSelectListItem(prefs->disksList, -1);
1245 else if (btn == prefs->disksRemoveBtn)
1247 int row = -1;
1248 WMListItem *item = NULL;
1250 clearDisksFields(prefs);
1251 item = WMGetListSelectedItem(prefs->disksList);
1252 if (item)
1254 free(item->clientData);
1255 item->clientData = NULL;
1257 row = WMGetListSelectedItemRow(prefs->disksList);
1258 WMRemoveListItem(prefs->disksList, row);
1259 edited = True;
1261 else if (btn == prefs->disksUpdateBtn)
1263 updateDisksList(prefs);
1265 /* clearDisksFields(prefs); */
1266 /* WMSelectListItem(prefs->disksList, -1); */
1267 edited = True;
1269 else if (btn == prefs->appsSetBtn)
1271 char *appStr = WMGetTextFieldText(prefs->appsExecTF);
1272 char *imgStr = WMGetHangedData(prefs->appsIconBtn);
1273 WMListItem *item = WMGetListSelectedItem(prefs->appsList);
1274 WMPropList* array = FSGetUDObjectForKey(defaultsDB, "EXE");
1277 if (!item)
1278 return;
1280 if (appStr) /* crash in 0.2.3e*/
1282 if (item->clientData) {
1283 WMPutInPLDictionary(item->clientData,
1284 WMCreatePLString("exec"), WMCreatePLString(appStr));
1286 /* new in V 0.2.3f */
1287 else {
1288 item->clientData = WMCreatePLDictionary(
1289 WMCreatePLString("exec"), WMCreatePLString(appStr), NULL);
1292 if (imgStr)
1294 if (item->clientData) {
1295 WMPutInPLDictionary(item->clientData,
1296 WMCreatePLString("icon"), WMCreatePLString(imgStr));
1298 /* new in V 0.2.3f */
1299 else {
1300 item->clientData = WMCreatePLDictionary(
1301 WMCreatePLString("icon"), WMCreatePLString(imgStr), NULL);
1305 if (array && WMIsPLArray(array))
1307 InsertArrayElement(array, WMCreatePLString(item->text));
1310 edited = True;
1312 else if (btn == prefs->appsRemoveBtn)
1314 WMListItem *item = WMGetListSelectedItem(prefs->appsList);
1316 if (!item)
1317 return;
1319 if (!item->uflags)
1321 item->uflags = 1;
1322 WMSetButtonText(btn, _("Undelete"));
1324 else
1326 item->uflags = 0;
1327 WMSetButtonText(btn, _("Delete"));
1329 /* Update of ListView? */
1330 WMSelectListItem(prefs->appsList,
1331 WMGetListSelectedItemRow(prefs->appsList));
1333 edited = True;
1335 else if (btn == prefs->typesSetBtn)
1337 char *viewStr = WMGetTextFieldText(prefs->typesViewTF);
1338 char *editStr = WMGetTextFieldText(prefs->typesEditTF);
1339 char *imgStr = WMGetHangedData(prefs->typesIconBtn);
1340 WMListItem *item = WMGetListSelectedItem(prefs->typesList);
1341 WMPropList* array = FSGetUDObjectForKey(defaultsDB, "EXTN");
1343 if (!item)
1344 return;
1346 if (viewStr)
1348 if (item->clientData) {
1349 WMPutInPLDictionary(item->clientData,
1350 WMCreatePLString("viewer"), WMCreatePLString(viewStr));
1352 /* new in V 0.2.3f */
1353 else {
1354 item->clientData = WMCreatePLDictionary(
1355 WMCreatePLString("viewer"), WMCreatePLString(viewStr), NULL);
1359 if (editStr)
1361 if (item->clientData) {
1362 WMPutInPLDictionary(item->clientData,
1363 WMCreatePLString("editor"), WMCreatePLString(editStr));
1365 /* new in V 0.2.3f */
1366 else {
1367 item->clientData = WMCreatePLDictionary(
1368 WMCreatePLString("editor"), WMCreatePLString(editStr), NULL);
1371 if (imgStr)
1373 if (item->clientData) {
1374 WMPutInPLDictionary(item->clientData,
1375 WMCreatePLString("icon"), WMCreatePLString(imgStr));
1377 /* new in V 0.2.3f */
1378 else {
1379 item->clientData = WMCreatePLDictionary(
1380 WMCreatePLString("icon"), WMCreatePLString(imgStr), NULL);
1384 if (array && WMIsPLArray(array))
1386 InsertArrayElement(array, WMCreatePLString(item->text));
1389 edited = True;
1391 else if (btn == prefs->typesRemoveBtn)
1393 WMListItem *item = WMGetListSelectedItem(prefs->typesList);
1395 if (!item)
1396 return;
1398 if (!item->uflags)
1400 item->uflags = 1;
1401 WMSetButtonText(btn, _("Undelete"));
1403 else
1405 item->uflags = 0;
1406 WMSetButtonText(btn, _("Delete"));
1408 WMSelectListItem(prefs->typesList,
1409 WMGetListSelectedItemRow(prefs->typesList));
1411 edited = True;
1413 else if (btn == prefs->appsIconBtn)
1415 char *img = NULL;
1416 char *tmp = NULL;
1417 WMPropList* val;
1418 WMListItem *item = WMGetListSelectedItem(prefs->appsList);
1420 if (!item || !item->clientData)
1421 return;
1423 val = FSGetDBObjectForKey(item->clientData, "icon");
1424 if (val && WMIsPLString(val))
1426 tmp = FSRunSelectIconPanel(prefs->win, _("Icon Select"),
1427 WMGetFromPLString(val));
1428 if (tmp == NULL)
1429 return;
1431 img = LocateImage(tmp);
1432 if (img)
1434 FSSetButtonImageFromFile(prefs->appsIconBtn, img);
1435 WMHangData(prefs->appsIconBtn, tmp);
1438 else
1439 WMSetButtonImage(prefs->appsIconBtn, NULL);
1440 /* edited = True; */
1442 else if (btn == prefs->typesIconBtn)
1444 char *img = NULL;
1445 char *tmp = NULL;
1446 WMPropList* val;
1447 WMListItem *item = WMGetListSelectedItem(prefs->typesList);
1449 if (!item || !item->clientData)
1450 return;
1452 val = FSGetDBObjectForKey(item->clientData, "icon");
1453 if (val && WMIsPLString(val))
1455 tmp = FSRunSelectIconPanel(prefs->win, _("Icon Select"),
1456 WMGetFromPLString(val));
1457 if (tmp == NULL)
1458 return;
1460 img = LocateImage(tmp);
1461 if (img)
1463 FSSetButtonImageFromFile(prefs->typesIconBtn, img);
1464 WMHangData(prefs->typesIconBtn, tmp);
1467 else
1468 WMSetButtonImage(prefs->typesIconBtn, NULL);
1469 /* edited = True; */
1471 else if (btn == prefs->appsBrowseBtn)
1473 WMOpenPanel *oPanel = NULL;
1475 oPanel = WMGetOpenPanel(prefs->scr);
1476 if (WMRunModalFilePanelForDirectory(oPanel, prefs->win,
1477 "/", _("Browse -> App"), NULL))
1479 char *str = WMGetFilePanelFileName(oPanel);
1481 WMSetTextFieldText(prefs->appsExecTF, str);
1482 WMInsertTextFieldText(prefs->appsExecTF, " %s", strlen(str));
1485 else if (btn == prefs->typesViewBrowseBtn)
1487 oPanel = WMGetOpenPanel(prefs->scr);
1488 if (WMRunModalFilePanelForDirectory(oPanel, prefs->win,
1489 "/", _("Browse -> Viewer"), NULL))
1491 char *str = WMGetFilePanelFileName(oPanel);
1493 WMSetTextFieldText(prefs->typesViewTF, str);
1494 WMInsertTextFieldText(prefs->typesViewTF, " %s", strlen(str));
1497 else if (btn == prefs->typesEditBrowseBtn)
1499 oPanel = WMGetOpenPanel(prefs->scr);
1500 if (WMRunModalFilePanelForDirectory(oPanel, prefs->win,
1501 "/", _("Browse -> Editor"), NULL))
1503 char *str = WMGetFilePanelFileName(oPanel);
1505 WMSetTextFieldText(prefs->typesEditTF, str);
1506 WMInsertTextFieldText(prefs->typesEditTF, " %s", strlen(str));
1510 if (edited)
1512 int id = -1;
1513 WMTabViewItem *item = NULL;
1515 item = WMGetSelectedTabViewItem(prefs->tabV);
1516 if (!item)
1517 return;
1519 id = WMGetTabViewItemIdentifier(item);
1521 switch(id)
1523 case VARS_TAB :
1524 prefs->flags.evars = True;
1525 break;
1526 case APPS_TAB :
1527 prefs->flags.eapps = True;
1528 break;
1529 case DISCS_TAB :
1530 prefs->flags.ediscs = True;
1531 break;
1532 default:
1533 break;
1535 WMSetButtonEnabled(prefs->applyBtn, True);
1536 WMSetButtonEnabled(prefs->okBtn, True);
1540 static void
1541 setVarsImage(WMWidget *self, void *data)
1545 static void FSClosePreferencesPanel(WMWidget *self, void *client)
1547 FSPreferencesPanel *prefs = (FSPreferencesPanel *) client;
1549 prefs->flags.done = 1;
1552 static void
1553 saveAllTabsAndClose(WMWidget *self, void *client)
1555 int i;
1556 FSPreferencesPanel *prefs = (FSPreferencesPanel *) client;
1558 for (i = 0; i < NUM_TABS; i++)
1559 saveTab(prefs, i);
1561 FSClosePreferencesPanel(self, client);
1564 static void
1565 applyBtnCB(WMWidget *self, void *client)
1567 int id = -1;
1568 WMTabViewItem *item = NULL;
1569 FSPreferencesPanel *prefs = (FSPreferencesPanel *) client;
1571 item = WMGetSelectedTabViewItem(prefs->tabV);
1572 if (!item)
1573 return;
1574 id = WMGetTabViewItemIdentifier(item);
1576 switch(id)
1578 case VARS_TAB :
1579 prefs->flags.evars = False;
1580 break;
1581 case APPS_TAB :
1582 prefs->flags.eapps = False;
1583 break;
1584 case DISCS_TAB :
1585 prefs->flags.ediscs = False;
1586 break;
1587 default:
1588 break;
1590 WMSetButtonEnabled(prefs->applyBtn, False);
1591 saveTab(prefs, id);
1594 static void
1595 saveTab(FSPreferencesPanel *prefs, int tabID)
1597 switch(tabID)
1599 case VARS_TAB : saveVarsTab(prefs);
1600 break;
1601 case APPS_TAB : saveAppsTab(prefs);
1602 break;
1603 case DISCS_TAB : saveDiscsTab(prefs);
1604 break;
1605 default:
1606 break;
1608 WMSynchronizeUserDefaults(defaultsDB);
1611 static void
1612 FSDestroyPreferencesPanel(FSPreferencesPanel *preferences)
1614 WMUnmapWidget(preferences->win);
1615 WMDestroyWidget(preferences->win);
1616 free((void *) preferences);
1617 preferences = NULL;
1620 static void
1621 tfDidChange(struct WMTextFieldDelegate *self, WMNotification *notif)
1626 static void
1627 setTFDelegate(FSPreferencesPanel *prefs, WMTextField *tf)
1629 WMTextFieldDelegate *delegate = NULL;
1631 delegate = (WMTextFieldDelegate *) wmalloc(sizeof(WMTextFieldDelegate));
1632 memset(delegate, 0, sizeof(WMTextFieldDelegate));
1634 if (delegate)
1636 delegate->data = prefs;
1637 delegate->didChange = tfDidChange;
1638 WMSetTextFieldDelegate(tf, delegate);
1642 static void
1643 setTVIDelegate(FSPreferencesPanel *prefs, WMTabView *tv)
1645 WMTabViewDelegate *delegate = NULL;
1647 delegate = (WMTabViewDelegate *) wmalloc(sizeof(WMTabViewDelegate));
1648 memset(delegate, 0, sizeof(WMTabViewDelegate));
1650 if (delegate)
1652 delegate->data = prefs;
1653 delegate->didSelectItem = tvDidSelectItem;
1654 WMSetTabViewDelegate(tv, delegate);
1658 static void
1659 tvDidSelectItem(struct WMTabViewDelegate *self, WMTabView *tabView,
1660 WMTabViewItem *item)
1662 int id = -1;
1663 Bool edited = False;
1664 WMTabViewDelegate *delegate = (WMTabViewDelegate *)self;
1665 FSPreferencesPanel *prefs = (FSPreferencesPanel *) delegate->data;
1667 id = WMGetTabViewItemIdentifier(item);
1669 switch(id)
1671 case VARS_TAB :
1672 if (prefs->flags.evars)
1673 edited = True;
1674 break;
1675 case APPS_TAB :
1676 if (prefs->flags.eapps)
1677 edited = True;
1678 break;
1679 case DISCS_TAB :
1680 if (prefs->flags.ediscs)
1681 edited = True;
1682 break;
1683 default: edited = False;
1684 break;
1687 WMSetButtonEnabled(prefs->applyBtn, edited);
1690 static void
1691 saveVarsTab(FSPreferencesPanel *prefs)
1693 int row;
1694 WMListItem *item = NULL;
1696 row = WMFindRowOfListItemWithTitle(prefs->imgList, "ROOT");
1697 if (row >= 0)
1699 item = WMGetListItem(prefs->imgList, row);
1700 if (item)
1701 FSSetStringForNameKey("ROOT", "icon", item->clientData);
1704 row = WMFindRowOfListItemWithTitle(prefs->imgList, "DIRECTORY");
1705 if (row >= 0)
1707 item = WMGetListItem(prefs->imgList, row);
1708 if (item)
1709 FSSetStringForName("DIRECTORY", item->clientData);
1712 row = WMFindRowOfListItemWithTitle(prefs->imgList, "DEFAULT_IMG");
1713 if (row >= 0)
1715 item = WMGetListItem(prefs->imgList, row);
1716 if (item)
1717 FSSetStringForName("DEFAULT_IMG", item->clientData);
1720 row = WMFindRowOfListItemWithTitle(prefs->imgList, "HOME");
1721 if (row >= 0)
1723 item = WMGetListItem(prefs->imgList, row);
1724 if (item)
1725 FSSetStringForName("HOME", item->clientData);
1728 row = WMFindRowOfListItemWithTitle(prefs->execList, "CONSOLE");
1729 if (row >= 0)
1731 item = WMGetListItem(prefs->execList, row);
1732 if (item)
1733 FSSetStringForNameKey("CONSOLE", "exec", item->clientData);
1736 row = WMFindRowOfListItemWithTitle(prefs->execList, "PROCESS");
1737 if (row >= 0)
1739 item = WMGetListItem(prefs->execList, row);
1740 if (item)
1741 FSSetStringForNameKey("PROCESS", "exec", item->clientData);
1744 row = WMFindRowOfListItemWithTitle(prefs->execList, "MAGICASCII");
1745 if (row >= 0)
1747 item = WMGetListItem(prefs->execList, row);
1748 if (item)
1749 FSSetStringForNameKey("MAGICASCII", "exec", item->clientData);
1752 row = WMFindRowOfListItemWithTitle(prefs->execList, "MAGICIMAGE");
1753 if (row >= 0)
1755 item = WMGetListItem(prefs->execList, row);
1756 if (item)
1757 FSSetStringForNameKey("MAGICIMAGE", "exec", item->clientData);
1760 row = WMFindRowOfListItemWithTitle(prefs->execList, "MAGICPS");
1761 if (row >= 0)
1763 item = WMGetListItem(prefs->execList, row);
1764 if (item)
1765 FSSetStringForNameKey("MAGICPS", "exec", item->clientData);
1768 row = WMFindRowOfListItemWithTitle(prefs->dpyList, "ColumnWidth");
1769 if (row >= 0)
1771 item = WMGetListItem(prefs->dpyList, row);
1772 if (item) {
1773 int value = atoi(item->clientData);
1774 if (FSGetIntegerForName("ColumnWidth") != value) {
1775 if (value < 169) /*MAGIC*/
1776 value = 169;
1777 FSSetIntegerForName("ColumnWidth", value);
1778 /* TODO: update viewer width */
1783 /* row = WMFindRowOfListItemWithTitle(prefs->imgList, "IconWidth"); */
1784 /* if (row >= 0) */
1785 /* { */
1786 /* item = WMGetListItem(prefs->dpyList, row); */
1787 /* if (item) */
1788 /* FSSetIntegerForName("IconWidth", atoi(item->clientData)); */
1789 /* } */
1792 row = WMFindRowOfListItemWithTitle(prefs->dpyList, "ICONDIR");
1793 if (row >= 0)
1795 item = WMGetListItem(prefs->dpyList, row);
1796 if (item)
1797 FSSetStringForName("ICONDIR", item->clientData);
1800 row = WMFindRowOfListItemWithTitle(prefs->dpyList, "SortDisplay");
1801 if (row >= 0)
1803 item = WMGetListItem(prefs->dpyList, row);
1804 if (item) {
1805 int value = atoi(item->clientData);
1806 if (FSGetIntegerForName("SortDisplay") != value) {
1807 FSSetIntegerForName("SortDisplay", value);
1808 FSUpdateFileViewPath(
1809 FSGetFSViewerCurrentView(prefs->app),
1810 FileSync, NULL, NULL);
1815 row = WMFindRowOfListItemWithTitle(prefs->dpyList, "SortOrder");
1816 if (row >= 0)
1818 item = WMGetListItem(prefs->dpyList, row);
1819 if (item) {
1820 int value = atoi(item->clientData);
1821 if (FSGetIntegerForName("SortOrder") != value) {
1822 FSSetIntegerForName("SortOrder", value);
1823 FSUpdateFileViewPath(
1824 FSGetFSViewerCurrentView(prefs->app),
1825 FileSync, NULL, NULL);
1830 row = WMFindRowOfListItemWithTitle(prefs->dpyList, "DisplaySVBG");
1831 if (row >= 0)
1833 item = WMGetListItem(prefs->dpyList, row);
1834 if (item) {
1835 int value = atoi(item->clientData);
1836 if (FSGetIntegerForName("DisplaySVBG") != value) {
1837 FSSetIntegerForName("DisplaySVBG", value);
1838 /* TODO: update view*/
1843 row = WMFindRowOfListItemWithTitle(prefs->dpyList, "DisplayMCListPixmap");
1844 if (row >= 0)
1846 item = WMGetListItem(prefs->dpyList, row);
1847 if (item) {
1848 int value = atoi(item->clientData);
1849 if (FSGetIntegerForName("DisplayMCListPixmap") != value) {
1850 FSSetIntegerForName("DisplayMCListPixmap", value);
1851 /* TODO: update view*/
1857 static void
1858 saveAppsTab(FSPreferencesPanel *prefs)
1860 int row = -1;
1861 int numRows = -1;
1862 WMListItem *item = NULL;
1863 WMPropList* exeArray = FSGetUDObjectForKey(defaultsDB, "EXE");
1864 WMPropList* extnArray = FSGetUDObjectForKey(defaultsDB, "EXTN");
1867 numRows = WMGetListNumberOfRows(prefs->appsList);
1869 for (row = 0; row < numRows; row++)
1871 item = WMGetListItem(prefs->appsList, row);
1872 if (item && !item->uflags)
1873 WMSetUDObjectForKey(defaultsDB, item->clientData, item->text);
1874 else
1876 if (exeArray && WMIsPLArray(exeArray))
1878 FSRemoveArrayElement(exeArray, WMCreatePLString(item->text));
1879 WMRemoveUDObjectForKey(defaultsDB, item->text);
1884 numRows = WMGetListNumberOfRows(prefs->typesList);
1885 for (row = 0; row < numRows; row++)
1887 item = WMGetListItem(prefs->typesList, row);
1888 if (item && !item->uflags)
1890 WMSetUDObjectForKey(defaultsDB, item->clientData, item->text);
1892 else
1894 if (extnArray && WMIsPLArray(extnArray))
1896 FSRemoveArrayElement(extnArray, WMCreatePLString(item->text));
1897 WMRemoveUDObjectForKey(defaultsDB, item->text);
1901 populateTypesTab(prefs);
1904 static void
1905 saveDiscsTab(FSPreferencesPanel *prefs)
1907 int row = -1;
1908 int numRows = -1;
1909 WMListItem *item = NULL;
1910 WMPropList* array = NULL;
1911 WMPropList* diskArray = NULL;
1912 Disc *disk = NULL;
1914 diskArray = WMCreatePLArray(NULL, NULL);
1916 numRows = WMGetListNumberOfRows(prefs->disksList);
1917 for (row = 0; row < numRows; row++)
1919 item = WMGetListItem(prefs->disksList, row);
1920 disk = (Disc *)item->clientData;
1922 if (item)
1924 array = WMCreatePLArray(WMCreatePLString(disk->name),
1925 WMCreatePLString(disk->point),
1926 WMCreatePLString(disk->device),
1927 WMCreatePLString(disk->mnt),
1928 WMCreatePLString(disk->umnt),
1929 WMCreatePLString(disk->eject),
1930 WMCreatePLString(disk->close),
1931 NULL );
1932 WMAddToPLArray(diskArray, array);
1935 WMSetUDObjectForKey(defaultsDB, diskArray, "DISCS");
1938 static void
1939 genericListDrawProc(WMList *lPtr, int index, Drawable d,
1940 char *text, int state, WMRect *rect)
1942 WMView *view = W_VIEW(lPtr);
1943 W_Screen *scr = view->screen;
1944 WMListItem *item = WMGetListItem(lPtr, index);
1946 if (item->selected)
1947 WMPaintColorSwatch(WMWhiteColor(scr), d,
1948 rect->pos.x, rect->pos.y,
1949 rect->size.width, rect->size.height);
1950 else
1951 WMPaintColorSwatch(WMGetWidgetBackgroundColor(lPtr), d,
1952 rect->pos.x, rect->pos.y,
1953 rect->size.width, rect->size.height);
1955 if (item->uflags)
1957 W_PaintText(view, d, scr->boldFont,
1958 rect->pos.x+4, rect->pos.y, rect->size.width,
1959 WALeft, WMBlackColor(scr), False,
1960 item->text, strlen(item->text));
1962 else
1964 W_PaintText(view, d, scr->normalFont,
1965 rect->pos.x+4, rect->pos.y, rect->size.width,
1966 WALeft, WMBlackColor(scr), False,
1967 item->text, strlen(item->text));