2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 #include <sys/types.h>
29 #include "../common/xchat.h"
30 #include "../common/util.h"
31 #include "../common/cfgfiles.h"
35 /* colors for xtext */
36 {0, 0xcccc, 0xcccc, 0xcccc}, /* 16 white */
37 {0, 0x0000, 0x0000, 0x0000}, /* 17 black */
38 {0, 0x35c2, 0x35c2, 0xb332}, /* 18 blue */
39 {0, 0x2a3d, 0x8ccc, 0x2a3d}, /* 19 green */
40 {0, 0xc3c3, 0x3b3b, 0x3b3b}, /* 20 red */
41 {0, 0xc7c7, 0x3232, 0x3232}, /* 21 light red */
42 {0, 0x8000, 0x2666, 0x7fff}, /* 22 purple */
43 {0, 0x6666, 0x3636, 0x1f1f}, /* 23 orange */
44 {0, 0xd999, 0xa6d3, 0x4147}, /* 24 yellow */
45 {0, 0x3d70, 0xcccc, 0x3d70}, /* 25 green */
46 {0, 0x199a, 0x5555, 0x5555}, /* 26 aqua */
47 {0, 0x2eef, 0x8ccc, 0x74df}, /* 27 light aqua */
48 {0, 0x451e, 0x451e, 0xe666}, /* 28 blue */
49 {0, 0xb0b0, 0x3737, 0xb0b0}, /* 29 light purple */
50 {0, 0x4c4c, 0x4c4c, 0x4c4c}, /* 30 grey */
51 {0, 0x9595, 0x9595, 0x9595}, /* 31 light grey */
53 {0, 0xcccc, 0xcccc, 0xcccc}, /* 16 white */
54 {0, 0x0000, 0x0000, 0x0000}, /* 17 black */
55 {0, 0x35c2, 0x35c2, 0xb332}, /* 18 blue */
56 {0, 0x2a3d, 0x8ccc, 0x2a3d}, /* 19 green */
57 {0, 0xc3c3, 0x3b3b, 0x3b3b}, /* 20 red */
58 {0, 0xc7c7, 0x3232, 0x3232}, /* 21 light red */
59 {0, 0x8000, 0x2666, 0x7fff}, /* 22 purple */
60 {0, 0x6666, 0x3636, 0x1f1f}, /* 23 orange */
61 {0, 0xd999, 0xa6d3, 0x4147}, /* 24 yellow */
62 {0, 0x3d70, 0xcccc, 0x3d70}, /* 25 green */
63 {0, 0x199a, 0x5555, 0x5555}, /* 26 aqua */
64 {0, 0x2eef, 0x8ccc, 0x74df}, /* 27 light aqua */
65 {0, 0x451e, 0x451e, 0xe666}, /* 28 blue */
66 {0, 0xb0b0, 0x3737, 0xb0b0}, /* 29 light purple */
67 {0, 0x4c4c, 0x4c4c, 0x4c4c}, /* 30 grey */
68 {0, 0x9595, 0x9595, 0x9595}, /* 31 light grey */
70 {0, 0xffff, 0xffff, 0xffff}, /* 32 marktext Fore (white) */
71 {0, 0x3535, 0x6e6e, 0xc1c1}, /* 33 marktext Back (blue) */
72 {0, 0x0000, 0x0000, 0x0000}, /* 34 foreground (black) */
73 {0, 0xf0f0, 0xf0f0, 0xf0f0}, /* 35 background (white) */
74 {0, 0xcccc, 0x1010, 0x1010}, /* 36 marker line (red) */
77 {0, 0x9999, 0x0000, 0x0000}, /* 37 tab New Data (dark red) */
78 {0, 0x0000, 0x0000, 0xffff}, /* 38 tab Nick Mentioned (blue) */
79 {0, 0xffff, 0x0000, 0x0000}, /* 39 tab New Message (red) */
80 {0, 0x9595, 0x9595, 0x9595}, /* 40 away user (grey) */
86 palette_alloc (GtkWidget
* widget
)
89 static int done_alloc
= FALSE
;
92 if (!done_alloc
) /* don't do it again */
95 cmap
= gtk_widget_get_colormap (widget
);
96 for (i
= MAX_COL
; i
>= 0; i
--)
97 gdk_colormap_alloc_color (cmap
, &colors
[i
], FALSE
, TRUE
);
101 /* maps XChat 2.0.x colors to current */
102 static const int remap
[] =
104 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
105 33, /* 16:marktextback */
106 32, /* 17:marktextfore */
109 37, /* 20: newdata */
118 int i
, j
, l
, fh
, res
;
122 int red
, green
, blue
;
125 fh
= xchat_open_file ("colors.conf", O_RDONLY
, 0, 0);
128 fh
= xchat_open_file ("palette.conf", O_RDONLY
, 0, 0);
135 cfg
= malloc (st
.st_size
+ 1);
139 l
= read (fh
, cfg
, st
.st_size
);
145 /* mIRC colors 0-31 are here */
146 for (i
= 0; i
< 32; i
++)
148 snprintf (prefname
, sizeof prefname
, "color_%d", i
);
149 cfg_get_color (cfg
, prefname
, &red
, &green
, &blue
);
151 colors
[i
].green
= green
;
152 colors
[i
].blue
= blue
;
155 /* our special colors are mapped at 256+ */
156 for (i
= 256, j
= 32; j
< MAX_COL
+1; i
++, j
++)
158 snprintf (prefname
, sizeof prefname
, "color_%d", i
);
159 cfg_get_color (cfg
, prefname
, &red
, &green
, &blue
);
161 colors
[j
].green
= green
;
162 colors
[j
].blue
= blue
;
167 /* loading 2.0.x palette.conf */
168 for (i
= 0; i
< MAX_COL
+1; i
++)
170 snprintf (prefname
, sizeof prefname
, "color_%d_red", i
);
171 red
= cfg_get_int (cfg
, prefname
);
173 snprintf (prefname
, sizeof prefname
, "color_%d_grn", i
);
174 green
= cfg_get_int (cfg
, prefname
);
176 snprintf (prefname
, sizeof prefname
, "color_%d_blu", i
);
177 blue
= cfg_get_int_with_result (cfg
, prefname
, &res
);
181 colors
[remap
[i
]].red
= red
;
182 colors
[remap
[i
]].green
= green
;
183 colors
[remap
[i
]].blue
= blue
;
187 /* copy 0-15 to 16-31 */
188 for (i
= 0; i
< 16; i
++)
190 colors
[i
+16].red
= colors
[i
].red
;
191 colors
[i
+16].green
= colors
[i
].green
;
192 colors
[i
+16].blue
= colors
[i
].blue
;
207 fh
= xchat_open_file ("colors.conf", O_TRUNC
| O_WRONLY
| O_CREAT
, 0600, XOF_DOMODE
);
210 /* mIRC colors 0-31 are here */
211 for (i
= 0; i
< 32; i
++)
213 snprintf (prefname
, sizeof prefname
, "color_%d", i
);
214 cfg_put_color (fh
, colors
[i
].red
, colors
[i
].green
, colors
[i
].blue
, prefname
);
217 /* our special colors are mapped at 256+ */
218 for (i
= 256, j
= 32; j
< MAX_COL
+1; i
++, j
++)
220 snprintf (prefname
, sizeof prefname
, "color_%d", i
);
221 cfg_put_color (fh
, colors
[j
].red
, colors
[j
].green
, colors
[j
].blue
, prefname
);