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,
26 typedef struct _Panel {
32 CallbackRec callbacks;
55 #define ICON_FILE "paths"
57 static void addPathToList(WMList * list, int index, char *path)
59 char *fpath = wexpandpath(path);
62 item = WMInsertListItem(list, index, path);
64 if (access(fpath, X_OK) != 0) {
70 static void showData(_Panel * panel)
72 WMPropList *array, *val;
75 array = GetObjectForKey("IconPath");
76 if (!array || !WMIsPLArray(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");
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)) {
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");
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;
113 if (w == panel->icorB) {
114 i = WMGetListSelectedItemRow(panel->icoL);
117 WMRemoveListItem(panel->icoL, i);
121 if (w == panel->pixrB) {
122 i = WMGetListSelectedItemRow(panel->pixL);
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);
142 int len = strlen(str);
144 /* Remove the trailing '/' except if the path is exactly / */
145 if (len > 1 && str[len - 1] == '/') {
153 if (w == panel->icoaB)
155 else if (w == panel->pixaB)
158 i = WMGetListSelectedItemRow(lPtr);
161 addPathToList(lPtr, i, str);
162 WMSetListBottomPosition(lPtr, WMGetListNumberOfRows(lPtr));
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;
183 XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
186 WMDrawString(scr, d, panel->red, panel->font, x + 4, y, text, strlen(text));
188 WMDrawString(scr, d, panel->black, panel->font, x + 4, y, text, strlen(text));
192 static void storeData(_Panel * panel)
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);
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);
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);
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);
303 Panel *InitPaths(WMScreen * scr, WMWidget * parent)
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);