30 |
|
|
31 |
#include "../common/weechat.h" |
#include "../common/weechat.h" |
32 |
#include "irc.h" |
#include "irc.h" |
33 |
|
#include "../common/utf8.h" |
34 |
|
#include "../common/weeconfig.h" |
35 |
#include "../gui/gui.h" |
#include "../gui/gui.h" |
36 |
|
|
37 |
|
|
174 |
} |
} |
175 |
|
|
176 |
/* |
/* |
177 |
|
* channel_get_charset_decode_iso: get decode iso value for channel |
178 |
|
* if not found for channel, look for server |
179 |
|
* if not found for server, look for global |
180 |
|
*/ |
181 |
|
|
182 |
|
char * |
183 |
|
channel_get_charset_decode_iso (t_irc_server *server, t_irc_channel *channel) |
184 |
|
{ |
185 |
|
char *pos, *result; |
186 |
|
int length; |
187 |
|
|
188 |
|
if (!server) |
189 |
|
return (cfg_look_charset_decode_iso) ? |
190 |
|
strdup (cfg_look_charset_decode_iso) : strdup (""); |
191 |
|
|
192 |
|
if (!channel) |
193 |
|
return server_get_charset_decode_iso (server); |
194 |
|
|
195 |
|
config_option_list_get_value (&(server->charset_decode_iso), |
196 |
|
channel->name, &pos, &length); |
197 |
|
if (pos && (length > 0)) |
198 |
|
{ |
199 |
|
result = strdup (pos); |
200 |
|
result[length] = '\0'; |
201 |
|
return result; |
202 |
|
} |
203 |
|
|
204 |
|
return server_get_charset_decode_iso (server); |
205 |
|
} |
206 |
|
|
207 |
|
/* |
208 |
|
* channel_get_charset_decode_utf: get decode utf value for channel |
209 |
|
* if not found for channel, look for server |
210 |
|
* if not found for server, look for global |
211 |
|
*/ |
212 |
|
|
213 |
|
char * |
214 |
|
channel_get_charset_decode_utf (t_irc_server *server, t_irc_channel *channel) |
215 |
|
{ |
216 |
|
char *pos, *result; |
217 |
|
int length; |
218 |
|
|
219 |
|
if (!server) |
220 |
|
return (cfg_look_charset_decode_utf) ? |
221 |
|
strdup (cfg_look_charset_decode_utf) : strdup (""); |
222 |
|
|
223 |
|
if (!channel) |
224 |
|
return server_get_charset_decode_utf (server); |
225 |
|
|
226 |
|
config_option_list_get_value (&(server->charset_decode_utf), |
227 |
|
channel->name, &pos, &length); |
228 |
|
if (pos && (length > 0)) |
229 |
|
{ |
230 |
|
result = strdup (pos); |
231 |
|
result[length] = '\0'; |
232 |
|
return result; |
233 |
|
} |
234 |
|
|
235 |
|
return server_get_charset_decode_utf (server); |
236 |
|
} |
237 |
|
|
238 |
|
/* |
239 |
|
* channel_get_charset_encode: get encode value for channel |
240 |
|
* if not found for channel, look for server |
241 |
|
* if not found for server, look for global |
242 |
|
*/ |
243 |
|
|
244 |
|
char * |
245 |
|
channel_get_charset_encode (t_irc_server *server, t_irc_channel *channel) |
246 |
|
{ |
247 |
|
char *pos, *result; |
248 |
|
int length; |
249 |
|
|
250 |
|
if (!server) |
251 |
|
return (cfg_look_charset_encode) ? |
252 |
|
strdup (cfg_look_charset_encode) : strdup (""); |
253 |
|
|
254 |
|
if (!channel) |
255 |
|
return server_get_charset_encode (server); |
256 |
|
|
257 |
|
config_option_list_get_value (&(server->charset_encode), |
258 |
|
channel->name, &pos, &length); |
259 |
|
if (pos && (length > 0)) |
260 |
|
{ |
261 |
|
result = strdup (pos); |
262 |
|
result[length] = '\0'; |
263 |
|
return result; |
264 |
|
} |
265 |
|
|
266 |
|
return server_get_charset_encode (server); |
267 |
|
} |
268 |
|
|
269 |
|
/* |
270 |
|
* channel_iconv_decode: convert string to local charset |
271 |
|
*/ |
272 |
|
|
273 |
|
char * |
274 |
|
channel_iconv_decode (t_irc_server *server, t_irc_channel *channel, char *string) |
275 |
|
{ |
276 |
|
char *from_charset, *string2; |
277 |
|
|
278 |
|
if (!local_utf8 || !utf8_is_valid (string)) |
279 |
|
{ |
280 |
|
if (local_utf8) |
281 |
|
from_charset = channel_get_charset_decode_iso (server, channel); |
282 |
|
else |
283 |
|
from_charset = channel_get_charset_decode_utf (server, channel); |
284 |
|
string2 = weechat_iconv (from_charset, |
285 |
|
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ? |
286 |
|
cfg_look_charset_internal : local_charset, |
287 |
|
string); |
288 |
|
free (from_charset); |
289 |
|
return string2; |
290 |
|
} |
291 |
|
else |
292 |
|
return strdup (string); |
293 |
|
} |
294 |
|
|
295 |
|
/* |
296 |
|
* |
297 |
|
*/ |
298 |
|
|
299 |
|
char * |
300 |
|
channel_iconv_encode (t_irc_server *server, t_irc_channel *channel, char *string) |
301 |
|
{ |
302 |
|
char *to_charset, *string2; |
303 |
|
|
304 |
|
to_charset = channel_get_charset_encode (server, channel); |
305 |
|
string2 = weechat_iconv ((cfg_look_charset_internal && cfg_look_charset_internal[0]) ? |
306 |
|
cfg_look_charset_internal : local_charset, |
307 |
|
to_charset, |
308 |
|
string); |
309 |
|
free (to_charset); |
310 |
|
return string2; |
311 |
|
} |
312 |
|
|
313 |
|
/* |
314 |
* channel_remove_away: remove away for all nicks on a channel |
* channel_remove_away: remove away for all nicks on a channel |
315 |
*/ |
*/ |
316 |
|
|
445 |
} |
} |
446 |
|
|
447 |
/* |
/* |
|
* server_remove_notify_level: remove channel notify from list |
|
|
*/ |
|
|
|
|
|
void |
|
|
channel_remove_notify_level (t_irc_server *server, t_irc_channel *channel) |
|
|
{ |
|
|
char *name, *pos, *pos2; |
|
|
|
|
|
if ((!server) || (!channel)) |
|
|
return; |
|
|
|
|
|
name = (char *) malloc (strlen (channel->name) + 2); |
|
|
strcpy (name, channel->name); |
|
|
strcat (name, ":"); |
|
|
pos = strstr (server->notify_levels, name); |
|
|
free (name); |
|
|
if (pos) |
|
|
{ |
|
|
pos2 = pos + strlen (channel->name); |
|
|
if (pos2[0] == ':') |
|
|
{ |
|
|
pos2++; |
|
|
if (pos2[0]) |
|
|
{ |
|
|
pos2++; |
|
|
if (pos2[0] == ',') |
|
|
pos2++; |
|
|
if (!pos2[0] && (pos != server->notify_levels)) |
|
|
pos--; |
|
|
strcpy (pos, pos2); |
|
|
server->notify_levels = (char *) realloc (server->notify_levels, |
|
|
strlen (server->notify_levels) + 1); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
/* |
|
448 |
* server_set_notify_level: set channel notify level |
* server_set_notify_level: set channel notify level |
449 |
*/ |
*/ |
450 |
|
|
451 |
void |
void |
452 |
channel_set_notify_level (t_irc_server *server, t_irc_channel *channel, int notify) |
channel_set_notify_level (t_irc_server *server, t_irc_channel *channel, int notify) |
453 |
{ |
{ |
454 |
char *name, *pos, *pos2, level_string[2]; |
char level_string[2]; |
455 |
|
|
456 |
if ((!server) || (!channel)) |
if ((!server) || (!channel)) |
457 |
return; |
return; |
458 |
|
|
459 |
if (notify == NOTIFY_LEVEL_DEFAULT) |
if (notify == NOTIFY_LEVEL_DEFAULT) |
460 |
{ |
config_option_list_remove (&(server->notify_levels), channel->name); |
|
channel_remove_notify_level (server, channel); |
|
|
return; |
|
|
} |
|
|
|
|
|
if (!server->notify_levels) |
|
|
{ |
|
|
server->notify_levels = (char *) malloc (strlen (channel->name) + 3); |
|
|
server->notify_levels[0] = '\0'; |
|
|
} |
|
461 |
else |
else |
462 |
{ |
{ |
463 |
name = (char *) malloc (strlen (channel->name) + 2); |
level_string[0] = notify + '0'; |
464 |
strcpy (name, channel->name); |
level_string[1] = '\0'; |
465 |
strcat (name, ":"); |
config_option_list_set (&(server->notify_levels), channel->name, level_string); |
|
pos = strstr (server->notify_levels, name); |
|
|
free (name); |
|
|
if (pos) |
|
|
{ |
|
|
pos2 = pos + strlen (channel->name) + 1; |
|
|
if (pos2[0]) |
|
|
{ |
|
|
pos2[0] = '0' + notify; |
|
|
return; |
|
|
} |
|
|
} |
|
|
/* realloc notify list to add channel */ |
|
|
server->notify_levels = (char *) realloc (server->notify_levels, |
|
|
strlen (server->notify_levels) + 1 + |
|
|
strlen (channel->name) + 2 + 1); |
|
466 |
} |
} |
|
|
|
|
/* channel not in notify list => add it */ |
|
|
if (server->notify_levels[0]) |
|
|
strcat (server->notify_levels, ","); |
|
|
strcat (server->notify_levels, channel->name); |
|
|
strcat (server->notify_levels, ":"); |
|
|
level_string[0] = notify + '0'; |
|
|
level_string[1] = '\0'; |
|
|
strcat (server->notify_levels, level_string); |
|
467 |
} |
} |
468 |
|
|
469 |
/* |
/* |