restructure configure so pkg-config derived SSL flags get used
[rofl0r-ixchat.git] / src / fe-gtk / palette.c
blobebae92ff9f7815ff63fb37c2618744b47cef6de6
1 /* X-Chat
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
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
26 #include "fe-gtk.h"
27 #include "palette.h"
29 #include "../common/xchat.h"
30 #include "../common/util.h"
31 #include "../common/cfgfiles.h"
34 GdkColor colors[] = {
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) */
76 /* colors for GUI */
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) */
82 #define MAX_COL 40
85 void
86 palette_alloc (GtkWidget * widget)
88 int i;
89 static int done_alloc = FALSE;
90 GdkColormap *cmap;
92 if (!done_alloc) /* don't do it again */
94 done_alloc = TRUE;
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 */
107 34, /* 18: fg */
108 35, /* 19: bg */
109 37, /* 20: newdata */
110 38, /* 21: blue */
111 39, /* 22: newmsg */
112 40 /* 23: away */
115 void
116 palette_load (void)
118 int i, j, l, fh, res;
119 char prefname[256];
120 struct stat st;
121 char *cfg;
122 int red, green, blue;
123 int upgrade = FALSE;
125 fh = xchat_open_file ("colors.conf", O_RDONLY, 0, 0);
126 if (fh == -1)
128 fh = xchat_open_file ("palette.conf", O_RDONLY, 0, 0);
129 upgrade = TRUE;
132 if (fh != -1)
134 fstat (fh, &st);
135 cfg = malloc (st.st_size + 1);
136 if (cfg)
138 cfg[0] = '\0';
139 l = read (fh, cfg, st.st_size);
140 if (l >= 0)
141 cfg[l] = '\0';
143 if (!upgrade)
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);
150 colors[i].red = red;
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);
160 colors[j].red = red;
161 colors[j].green = green;
162 colors[j].blue = blue;
165 } else
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);
179 if (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;
195 free (cfg);
197 close (fh);
201 void
202 palette_save (void)
204 int i, j, fh;
205 char prefname[256];
207 fh = xchat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
208 if (fh != -1)
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);
224 close (fh);