Small fix for wmaker nightly build script 2
[wmaker-crm.git] / WPrefs.app / Paths.c
blobca1b353af3cbb8d97ca7200faed3bf0589efc4a0
1 /* Paths.c- pixmap/icon paths
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "WPrefs.h"
24 #include <unistd.h>
26 typedef struct _Panel {
27 WMBox *box;
28 char *sectionName;
30 char *description;
32 CallbackRec callbacks;
34 WMWidget *parent;
36 WMTabView *tabv;
38 WMFrame *pixF;
39 WMList *pixL;
40 WMButton *pixaB;
41 WMButton *pixrB;
43 WMFrame *icoF;
44 WMList *icoL;
45 WMButton *icoaB;
46 WMButton *icorB;
48 WMColor *red;
49 WMColor *black;
50 WMColor *white;
51 WMColor *gray;
52 WMFont *font;
53 } _Panel;
55 #define ICON_FILE "paths"
57 static void addPathToList(WMList * list, int index, char *path)
59 char *fpath = wexpandpath(path);
60 WMListItem *item;
62 item = WMInsertListItem(list, index, path);
64 if (access(fpath, X_OK) != 0) {
65 item->uflags = 1;
67 wfree(fpath);
70 static void showData(_Panel * panel)
72 WMPropList *array, *val;
73 int i;
75 array = GetObjectForKey("IconPath");
76 if (!array || !WMIsPLArray(array)) {
77 if (array)
78 wwarning(_("bad value in option IconPath. Using default path list"));
79 addPathToList(panel->icoL, -1, "~/pixmaps");
80 addPathToList(panel->icoL, -1, "~/GNUstep/Library/Icons");
81 addPathToList(panel->icoL, -1, "/usr/include/X11/pixmaps");
82 addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Icons");
83 addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Pixmaps");
84 addPathToList(panel->icoL, -1, "/usr/share/WindowMaker/Icons");
85 } else {
86 for (i = 0; i < WMGetPropListItemCount(array); i++) {
87 val = WMGetFromPLArray(array, i);
88 addPathToList(panel->icoL, -1, WMGetFromPLString(val));
92 array = GetObjectForKey("PixmapPath");
93 if (!array || !WMIsPLArray(array)) {
94 if (array)
95 wwarning(_("bad value in option PixmapPath. Using default path list"));
96 addPathToList(panel->pixL, -1, "~/pixmaps");
97 addPathToList(panel->pixL, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
98 addPathToList(panel->pixL, -1, "/usr/local/share/WindowMaker/Pixmaps");
99 } else {
100 for (i = 0; i < WMGetPropListItemCount(array); i++) {
101 val = WMGetFromPLArray(array, i);
102 addPathToList(panel->pixL, -1, WMGetFromPLString(val));
107 static void pushButton(WMWidget * w, void *data)
109 _Panel *panel = (_Panel *) data;
110 int i;
112 /* icon paths */
113 if (w == panel->icorB) {
114 i = WMGetListSelectedItemRow(panel->icoL);
116 if (i >= 0)
117 WMRemoveListItem(panel->icoL, i);
120 /* pixmap paths */
121 if (w == panel->pixrB) {
122 i = WMGetListSelectedItemRow(panel->pixL);
124 if (i >= 0)
125 WMRemoveListItem(panel->pixL, i);
129 static void browseForFile(WMWidget * w, void *data)
131 _Panel *panel = (_Panel *) data;
132 WMFilePanel *filePanel;
134 filePanel = WMGetOpenPanel(WMWidgetScreen(w));
136 WMSetFilePanelCanChooseFiles(filePanel, False);
138 if (WMRunModalFilePanelForDirectory(filePanel, panel->parent, "/", _("Select directory"), NULL) == True) {
139 char *str = WMGetFilePanelFileName(filePanel);
141 if (str) {
142 int len = strlen(str);
144 /* Remove the trailing '/' except if the path is exactly / */
145 if (len > 1 && str[len - 1] == '/') {
146 str[len - 1] = '\0';
147 len--;
149 if (len > 0) {
150 WMList *lPtr;
151 int i;
153 if (w == panel->icoaB)
154 lPtr = panel->icoL;
155 else if (w == panel->pixaB)
156 lPtr = panel->pixL;
158 i = WMGetListSelectedItemRow(lPtr);
159 if (i >= 0)
160 i++;
161 addPathToList(lPtr, i, str);
162 WMSetListBottomPosition(lPtr, WMGetListNumberOfRows(lPtr));
164 wfree(str);
170 static void paintItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
172 int width, height, x, y;
173 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
174 WMScreen *scr = WMWidgetScreen(lPtr);
175 Display *dpy = WMScreenDisplay(scr);
176 WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray;
178 width = rect->size.width;
179 height = rect->size.height;
180 x = rect->pos.x;
181 y = rect->pos.y;
183 XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
185 if (state & 1) {
186 WMDrawString(scr, d, panel->red, panel->font, x + 4, y, text, strlen(text));
187 } else {
188 WMDrawString(scr, d, panel->black, panel->font, x + 4, y, text, strlen(text));
192 static void storeData(_Panel * panel)
194 WMPropList *list;
195 WMPropList *tmp;
196 int i;
197 char *p;
199 list = WMCreatePLArray(NULL, NULL);
200 for (i = 0; i < WMGetListNumberOfRows(panel->icoL); i++) {
201 p = WMGetListItem(panel->icoL, i)->text;
202 tmp = WMCreatePLString(p);
203 WMAddToPLArray(list, tmp);
205 SetObjectForKey(list, "IconPath");
207 list = WMCreatePLArray(NULL, NULL);
208 for (i = 0; i < WMGetListNumberOfRows(panel->pixL); i++) {
209 p = WMGetListItem(panel->pixL, i)->text;
210 tmp = WMCreatePLString(p);
211 WMAddToPLArray(list, tmp);
213 SetObjectForKey(list, "PixmapPath");
216 static void createPanel(Panel * p)
218 _Panel *panel = (_Panel *) p;
219 WMScreen *scr = WMWidgetScreen(panel->parent);
220 WMTabViewItem *tab;
222 panel->white = WMWhiteColor(scr);
223 panel->black = WMBlackColor(scr);
224 panel->gray = WMGrayColor(scr);
225 panel->red = WMCreateRGBColor(scr, 0xffff, 0, 0, True);
226 panel->font = WMSystemFontOfSize(scr, 12);
228 panel->box = WMCreateBox(panel->parent);
229 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
231 panel->tabv = WMCreateTabView(panel->box);
232 WMMoveWidget(panel->tabv, 12, 10);
233 WMResizeWidget(panel->tabv, 500, 215);
235 /* icon path */
236 panel->icoF = WMCreateFrame(panel->box);
237 WMSetFrameRelief(panel->icoF, WRFlat);
238 WMResizeWidget(panel->icoF, 230, 210);
240 tab = WMCreateTabViewItemWithIdentifier(0);
241 WMSetTabViewItemView(tab, WMWidgetView(panel->icoF));
242 WMAddItemInTabView(panel->tabv, tab);
243 WMSetTabViewItemLabel(tab, _("Icon Search Paths"));
245 panel->icoL = WMCreateList(panel->icoF);
246 WMResizeWidget(panel->icoL, 480, 147);
247 WMMoveWidget(panel->icoL, 10, 10);
248 WMSetListUserDrawProc(panel->icoL, paintItem);
249 WMHangData(panel->icoL, panel);
251 panel->icoaB = WMCreateCommandButton(panel->icoF);
252 WMResizeWidget(panel->icoaB, 95, 24);
253 WMMoveWidget(panel->icoaB, 293, 165);
254 WMSetButtonText(panel->icoaB, _("Add"));
255 WMSetButtonAction(panel->icoaB, browseForFile, panel);
256 WMSetButtonImagePosition(panel->icoaB, WIPRight);
258 panel->icorB = WMCreateCommandButton(panel->icoF);
259 WMResizeWidget(panel->icorB, 95, 24);
260 WMMoveWidget(panel->icorB, 395, 165);
261 WMSetButtonText(panel->icorB, _("Remove"));
262 WMSetButtonAction(panel->icorB, pushButton, panel);
264 WMMapSubwidgets(panel->icoF);
266 /* pixmap path */
267 panel->pixF = WMCreateFrame(panel->box);
268 WMSetFrameRelief(panel->pixF, WRFlat);
269 WMResizeWidget(panel->pixF, 230, 210);
271 tab = WMCreateTabViewItemWithIdentifier(0);
272 WMSetTabViewItemView(tab, WMWidgetView(panel->pixF));
273 WMAddItemInTabView(panel->tabv, tab);
274 WMSetTabViewItemLabel(tab, _("Pixmap Search Paths"));
276 panel->pixL = WMCreateList(panel->pixF);
277 WMResizeWidget(panel->pixL, 480, 147);
278 WMMoveWidget(panel->pixL, 10, 10);
279 WMSetListUserDrawProc(panel->pixL, paintItem);
280 WMHangData(panel->pixL, panel);
282 panel->pixaB = WMCreateCommandButton(panel->pixF);
283 WMResizeWidget(panel->pixaB, 95, 24);
284 WMMoveWidget(panel->pixaB, 293, 165);
285 WMSetButtonText(panel->pixaB, _("Add"));
286 WMSetButtonAction(panel->pixaB, browseForFile, panel);
287 WMSetButtonImagePosition(panel->pixaB, WIPRight);
289 panel->pixrB = WMCreateCommandButton(panel->pixF);
290 WMResizeWidget(panel->pixrB, 95, 24);
291 WMMoveWidget(panel->pixrB, 395, 165);
292 WMSetButtonText(panel->pixrB, _("Remove"));
293 WMSetButtonAction(panel->pixrB, pushButton, panel);
295 WMMapSubwidgets(panel->pixF);
297 WMRealizeWidget(panel->box);
298 WMMapSubwidgets(panel->box);
300 showData(panel);
303 Panel *InitPaths(WMScreen * scr, WMWidget * parent)
305 _Panel *panel;
307 panel = wmalloc(sizeof(_Panel));
308 memset(panel, 0, sizeof(_Panel));
310 panel->sectionName = _("Search Path Configuration");
312 panel->description = _("Search paths to use when looking for pixmaps\n" "and icons.");
314 panel->parent = parent;
316 panel->callbacks.createWidgets = createPanel;
317 panel->callbacks.updateDomain = storeData;
319 AddSection(panel, ICON_FILE);
321 return panel;