Files
wmaker/WPrefs.app/Paths.c
T

352 lines
9.4 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/* Paths.c- pixmap/icon paths
2004-10-12 21:28:27 +00:00
*
1998-10-21 14:43:47 +00:00
* WPrefs - Window Maker Preferences Program
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1998-2003 Alfredo K. Kojima
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2004-10-12 21:28:27 +00:00
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1998-09-29 22:36:29 +00:00
* USA.
*/
#include "WPrefs.h"
#include <unistd.h>
typedef struct _Panel {
WMBox *box;
1998-09-29 22:36:29 +00:00
char *sectionName;
1999-04-25 01:49:46 +00:00
char *description;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
CallbackRec callbacks;
WMWidget *parent;
2004-10-12 21:28:27 +00:00
1999-05-17 18:19:09 +00:00
WMTabView *tabv;
1998-09-29 22:36:29 +00:00
WMFrame *pixF;
WMList *pixL;
WMButton *pixaB;
WMButton *pixrB;
WMFrame *icoF;
WMList *icoL;
WMButton *icoaB;
WMButton *icorB;
WMColor *red;
WMColor *black;
WMColor *white;
WMColor *gray;
1998-09-29 22:36:29 +00:00
WMFont *font;
} _Panel;
#define ICON_FILE "paths"
static void
addPathToList(WMList *list, int index, char *path)
{
char *fpath = wexpandpath(path);
WMListItem *item;
item = WMInsertListItem(list, index, path);
if (access(fpath, X_OK)!=0) {
2004-10-12 21:28:27 +00:00
item->uflags = 1;
1998-09-29 22:36:29 +00:00
}
wfree(fpath);
1998-09-29 22:36:29 +00:00
}
static void
showData(_Panel *panel)
{
WMPropList *array, *val;
1998-09-29 22:36:29 +00:00
int i;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
array = GetObjectForKey("IconPath");
if (!array || !WMIsPLArray(array)) {
2004-10-12 21:28:27 +00:00
if (array)
wwarning(_("bad value in option IconPath. Using default path list"));
addPathToList(panel->icoL, -1, "~/pixmaps");
addPathToList(panel->icoL, -1, "~/GNUstep/Library/Icons");
addPathToList(panel->icoL, -1, "/usr/include/X11/pixmaps");
addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Icons");
addPathToList(panel->icoL, -1, "/usr/local/share/WindowMaker/Pixmaps");
addPathToList(panel->icoL, -1, "/usr/share/WindowMaker/Icons");
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
for (i=0; i<WMGetPropListItemCount(array); i++) {
val = WMGetFromPLArray(array, i);
addPathToList(panel->icoL, -1, WMGetFromPLString(val));
}
1998-09-29 22:36:29 +00:00
}
array = GetObjectForKey("PixmapPath");
if (!array || !WMIsPLArray(array)) {
2004-10-12 21:28:27 +00:00
if (array)
wwarning(_("bad value in option PixmapPath. Using default path list"));
addPathToList(panel->pixL, -1, "~/pixmaps");
addPathToList(panel->pixL, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
addPathToList(panel->pixL, -1, "/usr/local/share/WindowMaker/Pixmaps");
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
for (i=0; i<WMGetPropListItemCount(array); i++) {
val = WMGetFromPLArray(array, i);
addPathToList(panel->pixL, -1, WMGetFromPLString(val));
}
1998-09-29 22:36:29 +00:00
}
}
static void
pushButton(WMWidget *w, void *data)
{
_Panel *panel = (_Panel*)data;
int i;
/* icon paths */
if (w == panel->icorB) {
2004-10-12 21:28:27 +00:00
i = WMGetListSelectedItemRow(panel->icoL);
1998-09-29 22:36:29 +00:00
2004-10-12 21:28:27 +00:00
if (i>=0)
WMRemoveListItem(panel->icoL, i);
1998-09-29 22:36:29 +00:00
}
/* pixmap paths */
if (w == panel->pixrB) {
2004-10-12 21:28:27 +00:00
i = WMGetListSelectedItemRow(panel->pixL);
2004-10-12 21:28:27 +00:00
if (i>=0)
WMRemoveListItem(panel->pixL, i);
1998-09-29 22:36:29 +00:00
}
}
static void
browseForFile(WMWidget *w, void *data)
1998-09-29 22:36:29 +00:00
{
_Panel *panel = (_Panel*)data;
WMFilePanel *filePanel;
1998-09-29 22:36:29 +00:00
filePanel = WMGetOpenPanel(WMWidgetScreen(w));
1998-09-29 22:36:29 +00:00
WMSetFilePanelCanChooseFiles(filePanel, False);
1998-09-29 22:36:29 +00:00
if (WMRunModalFilePanelForDirectory(filePanel, panel->parent, "/",
_("Select directory"), NULL) == True) {
char *str = WMGetFilePanelFileName(filePanel);
1998-09-29 22:36:29 +00:00
if (str) {
int len = strlen(str);
1998-09-29 22:36:29 +00:00
/* Remove the trailing '/' except if the path is exactly / */
if (len > 1 && str[len-1] == '/') {
str[len-1] = '\0';
len--;
}
if (len > 0) {
WMList *lPtr;
int i;
if (w == panel->icoaB)
lPtr = panel->icoL;
else if (w == panel->pixaB)
lPtr = panel->pixL;
i = WMGetListSelectedItemRow(lPtr);
if (i >= 0) i++;
addPathToList(lPtr, i, str);
WMSetListBottomPosition(lPtr, WMGetListNumberOfRows(lPtr));
wfree(str);
}
}
1998-09-29 22:36:29 +00:00
}
}
static void
paintItem(WMList *lPtr, int index, Drawable d, char *text, int state, WMRect *rect)
1998-09-29 22:36:29 +00:00
{
int width, height, x, y;
_Panel *panel = (_Panel*)WMGetHangedData(lPtr);
WMScreen *scr = WMWidgetScreen(lPtr);
Display *dpy = WMScreenDisplay(scr);
WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray;
1998-09-29 22:36:29 +00:00
width = rect->size.width;
height = rect->size.height;
x = rect->pos.x;
y = rect->pos.y;
XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
1998-09-29 22:36:29 +00:00
if (state & 1) {
2004-10-12 21:28:27 +00:00
WMDrawString(scr, d, panel->red, panel->font, x+4, y, text, strlen(text));
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
WMDrawString(scr, d, panel->black, panel->font, x+4, y, text, strlen(text));
1998-09-29 22:36:29 +00:00
}
}
static void
storeData(_Panel *panel)
{
WMPropList *list;
WMPropList *tmp;
1998-09-29 22:36:29 +00:00
int i;
char *p;
2004-10-12 21:28:27 +00:00
list = WMCreatePLArray(NULL, NULL);
1998-09-29 22:36:29 +00:00
for (i=0; i<WMGetListNumberOfRows(panel->icoL); i++) {
2004-10-12 21:28:27 +00:00
p = WMGetListItem(panel->icoL, i)->text;
tmp = WMCreatePLString(p);
WMAddToPLArray(list, tmp);
1998-09-29 22:36:29 +00:00
}
SetObjectForKey(list, "IconPath");
2004-10-12 21:28:27 +00:00
list = WMCreatePLArray(NULL, NULL);
1998-09-29 22:36:29 +00:00
for (i=0; i<WMGetListNumberOfRows(panel->pixL); i++) {
2004-10-12 21:28:27 +00:00
p = WMGetListItem(panel->pixL, i)->text;
tmp = WMCreatePLString(p);
WMAddToPLArray(list, tmp);
1998-09-29 22:36:29 +00:00
}
SetObjectForKey(list, "PixmapPath");
}
static void
createPanel(Panel *p)
{
_Panel *panel = (_Panel*)p;
WMScreen *scr = WMWidgetScreen(panel->parent);
1999-05-17 18:19:09 +00:00
WMTabViewItem *tab;
1998-09-29 22:36:29 +00:00
panel->white = WMWhiteColor(scr);
panel->black = WMBlackColor(scr);
panel->gray = WMGrayColor(scr);
1998-09-29 22:36:29 +00:00
panel->red = WMCreateRGBColor(scr, 0xffff, 0, 0, True);
panel->font = WMSystemFontOfSize(scr, 12);
2004-10-12 21:28:27 +00:00
panel->box = WMCreateBox(panel->parent);
2001-04-25 02:03:08 +00:00
WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
2004-10-12 21:28:27 +00:00
panel->tabv = WMCreateTabView(panel->box);
1999-05-19 02:24:47 +00:00
WMMoveWidget(panel->tabv, 12, 10);
1999-05-17 18:19:09 +00:00
WMResizeWidget(panel->tabv, 500, 215);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/* icon path */
panel->icoF = WMCreateFrame(panel->box);
1999-05-17 18:19:09 +00:00
WMSetFrameRelief(panel->icoF, WRFlat);
1998-09-29 22:36:29 +00:00
WMResizeWidget(panel->icoF, 230, 210);
1999-05-17 18:19:09 +00:00
tab = WMCreateTabViewItemWithIdentifier(0);
WMSetTabViewItemView(tab, WMWidgetView(panel->icoF));
WMAddItemInTabView(panel->tabv, tab);
1999-08-02 18:28:13 +00:00
WMSetTabViewItemLabel(tab, _("Icon Search Paths"));
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->icoL = WMCreateList(panel->icoF);
1999-05-17 18:19:09 +00:00
WMResizeWidget(panel->icoL, 480, 147);
WMMoveWidget(panel->icoL, 10, 10);
1998-09-29 22:36:29 +00:00
WMSetListUserDrawProc(panel->icoL, paintItem);
WMHangData(panel->icoL, panel);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->icoaB = WMCreateCommandButton(panel->icoF);
1999-05-15 17:38:05 +00:00
WMResizeWidget(panel->icoaB, 95, 24);
1999-05-19 02:24:47 +00:00
WMMoveWidget(panel->icoaB, 293, 165);
1998-09-29 22:36:29 +00:00
WMSetButtonText(panel->icoaB, _("Add"));
WMSetButtonAction(panel->icoaB, browseForFile, panel);
1998-09-29 22:36:29 +00:00
WMSetButtonImagePosition(panel->icoaB, WIPRight);
panel->icorB = WMCreateCommandButton(panel->icoF);
1999-05-15 17:38:05 +00:00
WMResizeWidget(panel->icorB, 95, 24);
1999-05-19 02:24:47 +00:00
WMMoveWidget(panel->icorB, 395, 165);
1998-09-29 22:36:29 +00:00
WMSetButtonText(panel->icorB, _("Remove"));
WMSetButtonAction(panel->icorB, pushButton, panel);
WMMapSubwidgets(panel->icoF);
/* pixmap path */
panel->pixF = WMCreateFrame(panel->box);
1999-05-17 18:19:09 +00:00
WMSetFrameRelief(panel->pixF, WRFlat);
1998-09-29 22:36:29 +00:00
WMResizeWidget(panel->pixF, 230, 210);
2004-10-12 21:28:27 +00:00
1999-05-17 18:19:09 +00:00
tab = WMCreateTabViewItemWithIdentifier(0);
WMSetTabViewItemView(tab, WMWidgetView(panel->pixF));
WMAddItemInTabView(panel->tabv, tab);
1999-08-02 18:28:13 +00:00
WMSetTabViewItemLabel(tab, _("Pixmap Search Paths"));
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->pixL = WMCreateList(panel->pixF);
1999-05-17 18:19:09 +00:00
WMResizeWidget(panel->pixL, 480, 147);
WMMoveWidget(panel->pixL, 10, 10);
1998-09-29 22:36:29 +00:00
WMSetListUserDrawProc(panel->pixL, paintItem);
WMHangData(panel->pixL, panel);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->pixaB = WMCreateCommandButton(panel->pixF);
1999-05-15 17:38:05 +00:00
WMResizeWidget(panel->pixaB, 95, 24);
1999-05-19 02:24:47 +00:00
WMMoveWidget(panel->pixaB, 293, 165);
1998-09-29 22:36:29 +00:00
WMSetButtonText(panel->pixaB, _("Add"));
WMSetButtonAction(panel->pixaB, browseForFile, panel);
1998-09-29 22:36:29 +00:00
WMSetButtonImagePosition(panel->pixaB, WIPRight);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->pixrB = WMCreateCommandButton(panel->pixF);
1999-05-15 17:38:05 +00:00
WMResizeWidget(panel->pixrB, 95, 24);
1999-05-19 02:24:47 +00:00
WMMoveWidget(panel->pixrB, 395, 165);
1998-09-29 22:36:29 +00:00
WMSetButtonText(panel->pixrB, _("Remove"));
WMSetButtonAction(panel->pixrB, pushButton, panel);
1998-09-29 22:36:29 +00:00
WMMapSubwidgets(panel->pixF);
2004-10-12 21:28:27 +00:00
WMRealizeWidget(panel->box);
WMMapSubwidgets(panel->box);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
showData(panel);
}
Panel*
InitPaths(WMScreen *scr, WMWidget *parent)
1998-09-29 22:36:29 +00:00
{
_Panel *panel;
panel = wmalloc(sizeof(_Panel));
memset(panel, 0, sizeof(_Panel));
panel->sectionName = _("Search Path Configuration");
1999-04-25 01:49:46 +00:00
panel->description = _("Search paths to use when looking for pixmaps\n"
2004-10-12 21:28:27 +00:00
"and icons.");
1999-04-25 01:49:46 +00:00
panel->parent = parent;
1998-09-29 22:36:29 +00:00
panel->callbacks.createWidgets = createPanel;
panel->callbacks.updateDomain = storeData;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
AddSection(panel, ICON_FILE);
return panel;
}
2004-10-12 21:28:27 +00:00