~profzoom/ubuntu/quantal/wmaker/bug-1079925

« back to all changes in this revision

Viewing changes to WPrefs.app/Paths.c

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2004-11-10 14:05:30 UTC
  • Revision ID: james.westby@ubuntu.com-20041110140530-qpd66b5lm38x7apk
Tags: upstream-0.91.0
ImportĀ upstreamĀ versionĀ 0.91.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Paths.c- pixmap/icon paths
 
2
 *
 
3
 *  WPrefs - Window Maker Preferences Program
 
4
 *
 
5
 *  Copyright (c) 1998-2003 Alfredo K. Kojima
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
21
 */
 
22
 
 
23
 
 
24
#include "WPrefs.h"
 
25
#include <unistd.h>
 
26
 
 
27
typedef struct _Panel {
 
28
    WMBox *box;
 
29
    char *sectionName;
 
30
 
 
31
    char *description;
 
32
 
 
33
    CallbackRec callbacks;
 
34
 
 
35
    WMWidget *parent;
 
36
 
 
37
    WMTabView *tabv;
 
38
 
 
39
    WMFrame *pixF;
 
40
    WMList *pixL;
 
41
    WMButton *pixaB;
 
42
    WMButton *pixrB;
 
43
 
 
44
    WMFrame *icoF;
 
45
    WMList *icoL;
 
46
    WMButton *icoaB;
 
47
    WMButton *icorB;
 
48
 
 
49
    WMColor *red;
 
50
    WMColor *black;
 
51
    WMColor *white;
 
52
    WMColor *gray;
 
53
    WMFont *font;
 
54
} _Panel;
 
55
 
 
56
 
 
57
 
 
58
#define ICON_FILE       "paths"
 
59
 
 
60
 
 
61
static void
 
62
addPathToList(WMList *list, int index, char *path)
 
63
{
 
64
    char *fpath = wexpandpath(path);
 
65
    WMListItem *item;
 
66
 
 
67
    item = WMInsertListItem(list, index, path);
 
68
 
 
69
    if (access(fpath, X_OK)!=0) {
 
70
        item->uflags = 1;
 
71
    }
 
72
    wfree(fpath);
 
73
}
 
74
 
 
75
 
 
76
static void
 
77
showData(_Panel *panel)
 
78
{
 
79
    WMPropList *array, *val;
 
80
    int i;
 
81
 
 
82
    array = GetObjectForKey("IconPath");
 
83
    if (!array || !WMIsPLArray(array)) {
 
84
        if (array)
 
85
            wwarning(_("bad value in option IconPath. Using default path list"));
 
86
        addPathToList(panel->icoL, -1, "~/pixmaps");
 
87
        addPathToList(panel->icoL, -1, "~/GNUstep/Library/Icons");
 
88
        addPathToList(panel->icoL, -1, "/usr/include/X11/pixmaps");
 
89
        addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Icons");
 
90
        addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Pixmaps");
 
91
        addPathToList(panel->icoL, -1, "/usr/share/WindowMaker/Icons");
 
92
    } else {
 
93
        for (i=0; i<WMGetPropListItemCount(array); i++) {
 
94
            val = WMGetFromPLArray(array, i);
 
95
            addPathToList(panel->icoL, -1, WMGetFromPLString(val));
 
96
        }
 
97
    }
 
98
 
 
99
    array = GetObjectForKey("PixmapPath");
 
100
    if (!array || !WMIsPLArray(array)) {
 
101
        if (array)
 
102
            wwarning(_("bad value in option PixmapPath. Using default path list"));
 
103
        addPathToList(panel->pixL, -1, "~/pixmaps");
 
104
        addPathToList(panel->pixL, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
 
105
        addPathToList(panel->pixL, -1, "/usr/local/share/WindowMaker/Pixmaps");
 
106
    } else {
 
107
        for (i=0; i<WMGetPropListItemCount(array); i++) {
 
108
            val = WMGetFromPLArray(array, i);
 
109
            addPathToList(panel->pixL, -1, WMGetFromPLString(val));
 
110
        }
 
111
    }
 
112
}
 
113
 
 
114
 
 
115
static void
 
116
pushButton(WMWidget *w, void *data)
 
117
{
 
118
    _Panel *panel = (_Panel*)data;
 
119
    int i;
 
120
 
 
121
    /* icon paths */
 
122
    if (w == panel->icorB) {
 
123
        i = WMGetListSelectedItemRow(panel->icoL);
 
124
 
 
125
        if (i>=0)
 
126
            WMRemoveListItem(panel->icoL, i);
 
127
    }
 
128
 
 
129
    /* pixmap paths */
 
130
    if (w == panel->pixrB) {
 
131
        i = WMGetListSelectedItemRow(panel->pixL);
 
132
 
 
133
        if (i>=0)
 
134
            WMRemoveListItem(panel->pixL, i);
 
135
    }
 
136
}
 
137
 
 
138
 
 
139
static void
 
140
browseForFile(WMWidget *w, void *data)
 
141
{
 
142
    _Panel *panel = (_Panel*)data;
 
143
    WMFilePanel *filePanel;
 
144
 
 
145
    filePanel = WMGetOpenPanel(WMWidgetScreen(w));
 
146
 
 
147
    WMSetFilePanelCanChooseFiles(filePanel, False);
 
148
 
 
149
    if (WMRunModalFilePanelForDirectory(filePanel, panel->parent, "/",
 
150
                                        _("Select directory"), NULL) == True) {
 
151
        char *str = WMGetFilePanelFileName(filePanel);
 
152
 
 
153
        if (str) {
 
154
            int len = strlen(str);
 
155
 
 
156
            /* Remove the trailing '/' except if the path is exactly / */
 
157
            if (len > 1 && str[len-1] == '/') {
 
158
                str[len-1] = '\0';
 
159
                len--;
 
160
            }
 
161
            if (len > 0) {
 
162
                WMList *lPtr;
 
163
                int i;
 
164
 
 
165
                if (w == panel->icoaB)
 
166
                    lPtr = panel->icoL;
 
167
                else if (w == panel->pixaB)
 
168
                    lPtr = panel->pixL;
 
169
 
 
170
                i = WMGetListSelectedItemRow(lPtr);
 
171
                if (i >= 0) i++;
 
172
                addPathToList(lPtr, i, str);
 
173
                WMSetListBottomPosition(lPtr, WMGetListNumberOfRows(lPtr));
 
174
 
 
175
                wfree(str);
 
176
            }
 
177
        }
 
178
    }
 
179
}
 
180
 
 
181
 
 
182
 
 
183
static void
 
184
paintItem(WMList *lPtr, int index, Drawable d, char *text, int state, WMRect *rect)
 
185
{
 
186
    int width, height, x, y;
 
187
    _Panel *panel = (_Panel*)WMGetHangedData(lPtr);
 
188
    WMScreen *scr = WMWidgetScreen(lPtr);
 
189
    Display *dpy = WMScreenDisplay(scr);
 
190
    WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray;
 
191
 
 
192
    width = rect->size.width;
 
193
    height = rect->size.height;
 
194
    x = rect->pos.x;
 
195
    y = rect->pos.y;
 
196
 
 
197
    XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
 
198
 
 
199
    if (state & 1) {
 
200
        WMDrawString(scr, d, panel->red, panel->font, x+4, y, text, strlen(text));
 
201
    } else {
 
202
        WMDrawString(scr, d, panel->black, panel->font, x+4, y, text, strlen(text));
 
203
    }
 
204
}
 
205
 
 
206
 
 
207
 
 
208
static void
 
209
storeData(_Panel *panel)
 
210
{
 
211
    WMPropList *list;
 
212
    WMPropList *tmp;
 
213
    int i;
 
214
    char *p;
 
215
 
 
216
    list = WMCreatePLArray(NULL, NULL);
 
217
    for (i=0; i<WMGetListNumberOfRows(panel->icoL); i++) {
 
218
        p = WMGetListItem(panel->icoL, i)->text;
 
219
        tmp = WMCreatePLString(p);
 
220
        WMAddToPLArray(list, tmp);
 
221
    }
 
222
    SetObjectForKey(list, "IconPath");
 
223
 
 
224
    list = WMCreatePLArray(NULL, NULL);
 
225
    for (i=0; i<WMGetListNumberOfRows(panel->pixL); i++) {
 
226
        p = WMGetListItem(panel->pixL, i)->text;
 
227
        tmp = WMCreatePLString(p);
 
228
        WMAddToPLArray(list, tmp);
 
229
    }
 
230
    SetObjectForKey(list, "PixmapPath");
 
231
}
 
232
 
 
233
 
 
234
 
 
235
static void
 
236
createPanel(Panel *p)
 
237
{
 
238
    _Panel *panel = (_Panel*)p;
 
239
    WMScreen *scr = WMWidgetScreen(panel->parent);
 
240
    WMTabViewItem *tab;
 
241
 
 
242
    panel->white = WMWhiteColor(scr);
 
243
    panel->black = WMBlackColor(scr);
 
244
    panel->gray = WMGrayColor(scr);
 
245
    panel->red = WMCreateRGBColor(scr, 0xffff, 0, 0, True);
 
246
    panel->font = WMSystemFontOfSize(scr, 12);
 
247
 
 
248
    panel->box = WMCreateBox(panel->parent);
 
249
    WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
 
250
 
 
251
 
 
252
    panel->tabv = WMCreateTabView(panel->box);
 
253
    WMMoveWidget(panel->tabv, 12, 10);
 
254
    WMResizeWidget(panel->tabv, 500, 215);
 
255
 
 
256
 
 
257
 
 
258
    /* icon path */
 
259
    panel->icoF = WMCreateFrame(panel->box);
 
260
    WMSetFrameRelief(panel->icoF, WRFlat);
 
261
    WMResizeWidget(panel->icoF, 230, 210);
 
262
 
 
263
    tab = WMCreateTabViewItemWithIdentifier(0);
 
264
    WMSetTabViewItemView(tab, WMWidgetView(panel->icoF));
 
265
    WMAddItemInTabView(panel->tabv, tab);
 
266
    WMSetTabViewItemLabel(tab, _("Icon Search Paths"));
 
267
 
 
268
    panel->icoL = WMCreateList(panel->icoF);
 
269
    WMResizeWidget(panel->icoL, 480, 147);
 
270
    WMMoveWidget(panel->icoL, 10, 10);
 
271
    WMSetListUserDrawProc(panel->icoL, paintItem);
 
272
    WMHangData(panel->icoL, panel);
 
273
 
 
274
    panel->icoaB = WMCreateCommandButton(panel->icoF);
 
275
    WMResizeWidget(panel->icoaB, 95, 24);
 
276
    WMMoveWidget(panel->icoaB, 293, 165);
 
277
    WMSetButtonText(panel->icoaB, _("Add"));
 
278
    WMSetButtonAction(panel->icoaB, browseForFile, panel);
 
279
    WMSetButtonImagePosition(panel->icoaB, WIPRight);
 
280
 
 
281
    panel->icorB = WMCreateCommandButton(panel->icoF);
 
282
    WMResizeWidget(panel->icorB, 95, 24);
 
283
    WMMoveWidget(panel->icorB, 395, 165);
 
284
    WMSetButtonText(panel->icorB, _("Remove"));
 
285
    WMSetButtonAction(panel->icorB, pushButton, panel);
 
286
 
 
287
    WMMapSubwidgets(panel->icoF);
 
288
 
 
289
    /* pixmap path */
 
290
    panel->pixF = WMCreateFrame(panel->box);
 
291
    WMSetFrameRelief(panel->pixF, WRFlat);
 
292
    WMResizeWidget(panel->pixF, 230, 210);
 
293
 
 
294
    tab = WMCreateTabViewItemWithIdentifier(0);
 
295
    WMSetTabViewItemView(tab, WMWidgetView(panel->pixF));
 
296
    WMAddItemInTabView(panel->tabv, tab);
 
297
    WMSetTabViewItemLabel(tab, _("Pixmap Search Paths"));
 
298
 
 
299
    panel->pixL = WMCreateList(panel->pixF);
 
300
    WMResizeWidget(panel->pixL, 480, 147);
 
301
    WMMoveWidget(panel->pixL, 10, 10);
 
302
    WMSetListUserDrawProc(panel->pixL, paintItem);
 
303
    WMHangData(panel->pixL, panel);
 
304
 
 
305
    panel->pixaB = WMCreateCommandButton(panel->pixF);
 
306
    WMResizeWidget(panel->pixaB, 95, 24);
 
307
    WMMoveWidget(panel->pixaB, 293, 165);
 
308
    WMSetButtonText(panel->pixaB, _("Add"));
 
309
    WMSetButtonAction(panel->pixaB, browseForFile, panel);
 
310
    WMSetButtonImagePosition(panel->pixaB, WIPRight);
 
311
 
 
312
    panel->pixrB = WMCreateCommandButton(panel->pixF);
 
313
    WMResizeWidget(panel->pixrB, 95, 24);
 
314
    WMMoveWidget(panel->pixrB, 395, 165);
 
315
    WMSetButtonText(panel->pixrB, _("Remove"));
 
316
    WMSetButtonAction(panel->pixrB, pushButton, panel);
 
317
 
 
318
 
 
319
    WMMapSubwidgets(panel->pixF);
 
320
 
 
321
    WMRealizeWidget(panel->box);
 
322
    WMMapSubwidgets(panel->box);
 
323
 
 
324
    showData(panel);
 
325
}
 
326
 
 
327
 
 
328
 
 
329
Panel*
 
330
InitPaths(WMScreen *scr, WMWidget *parent)
 
331
{
 
332
    _Panel *panel;
 
333
 
 
334
    panel = wmalloc(sizeof(_Panel));
 
335
    memset(panel, 0, sizeof(_Panel));
 
336
 
 
337
    panel->sectionName = _("Search Path Configuration");
 
338
 
 
339
    panel->description = _("Search paths to use when looking for pixmaps\n"
 
340
                           "and icons.");
 
341
 
 
342
    panel->parent = parent;
 
343
 
 
344
    panel->callbacks.createWidgets = createPanel;
 
345
    panel->callbacks.updateDomain = storeData;
 
346
 
 
347
    AddSection(panel, ICON_FILE);
 
348
 
 
349
    return panel;
 
350
}
 
351