comparison mcabber/mcabber/screen.c @ 1729:e6e89b1d7831

Minor style and header updates
author Mikael Berthe <mikael@lilotux.net>
date Sun, 28 Feb 2010 15:19:27 +0100
parents 68981c37ed3f
children a9b0364c0cb2
comparison
equal deleted inserted replaced
1728:15b3834cbe5f 1729:e6e89b1d7831
1 /* 1 /*
2 * screen.c -- UI stuff 2 * screen.c -- UI stuff
3 * 3 *
4 * Copyright (C) 2005-2009 Mikael Berthe <mikael@lilotux.net> 4 * Copyright (C) 2005-2010 Mikael Berthe <mikael@lilotux.net>
5 * Parts of this file come from the Cabber project <cabber@ajmacias.com> 5 * Parts of this file come from the Cabber project <cabber@ajmacias.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 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 (at 9 * the Free Software Foundation; either version 2 of the License, or (at
251 cl = FindColor(color); 251 cl = FindColor(color);
252 if (cl < 0) 252 if (cl < 0)
253 return NULL; 253 return NULL;
254 ccol = g_new0(ccolor, 1); 254 ccol = g_new0(ccolor, 1);
255 ccol->color_attrib = isbright ? A_BOLD : A_NORMAL; 255 ccol->color_attrib = isbright ? A_BOLD : A_NORMAL;
256 ccol->color_pair = cl + COLOR_max; //user colors come after the internal ones 256 ccol->color_pair = cl + COLOR_max; // User colors come after the internal ones
257 return ccol; 257 return ccol;
258 } 258 }
259 259
260 static void ensure_string_htable(GHashTable **table, 260 static void ensure_string_htable(GHashTable **table,
261 GDestroyNotify value_destroy_func) 261 GDestroyNotify value_destroy_func)
262 { 262 {
263 if (*table)//Have it already 263 if (*table) // Have it already
264 return; 264 return;
265 *table = g_hash_table_new_full(g_str_hash, g_str_equal, 265 *table = g_hash_table_new_full(g_str_hash, g_str_equal,
266 g_free, value_destroy_func); 266 g_free, value_destroy_func);
267 } 267 }
268 268
271 // muc - the JID of room 271 // muc - the JID of room
272 // type - the new type 272 // type - the new type
273 void scr_MucColor(const char *muc, muccoltype type) 273 void scr_MucColor(const char *muc, muccoltype type)
274 { 274 {
275 gchar *muclow = g_utf8_strdown(muc, -1); 275 gchar *muclow = g_utf8_strdown(muc, -1);
276 if (type == MC_REMOVE) {//Remove it 276 if (type == MC_REMOVE) { // Remove it
277 if (strcmp(muc, "*")) { 277 if (strcmp(muc, "*")) {
278 if (muccolors && g_hash_table_lookup(muccolors, muclow)) 278 if (muccolors && g_hash_table_lookup(muccolors, muclow))
279 g_hash_table_remove(muccolors, muclow); 279 g_hash_table_remove(muccolors, muclow);
280 } else { 280 } else {
281 scr_LogPrint(LPRINT_NORMAL, "Can not remove global coloring mode"); 281 scr_LogPrint(LPRINT_NORMAL, "Can not remove global coloring mode");
282 } 282 }
283 g_free(muclow); 283 g_free(muclow);
284 } else {//Add or overwrite 284 } else { // Add or overwrite
285 if (strcmp(muc, "*")) { 285 if (strcmp(muc, "*")) {
286 muccoltype *value = g_new(muccoltype, 1); 286 muccoltype *value = g_new(muccoltype, 1);
287 *value = type; 287 *value = type;
288 ensure_string_htable(&muccolors, g_free); 288 ensure_string_htable(&muccolors, g_free);
289 g_hash_table_replace(muccolors, muclow, value); 289 g_hash_table_replace(muccolors, muclow, value);
290 } else { 290 } else {
291 glob_muccol = type; 291 glob_muccol = type;
292 g_free(muclow); 292 g_free(muclow);
293 } 293 }
294 } 294 }
295 //Need to redraw? 295 // Need to redraw?
296 if (chatmode && 296 if (chatmode &&
297 ((buddy_search_jid(muc) == current_buddy) || !strcmp(muc, "*"))) 297 ((buddy_search_jid(muc) == current_buddy) || !strcmp(muc, "*")))
298 scr_UpdateBuddyWindow(); 298 scr_UpdateBuddyWindow();
299 } 299 }
300 300
305 { 305 {
306 char *snick, *mnick; 306 char *snick, *mnick;
307 bool need_update = FALSE; 307 bool need_update = FALSE;
308 snick = g_strdup_printf("<%s>", nick); 308 snick = g_strdup_printf("<%s>", nick);
309 mnick = g_strdup_printf("*%s ", nick); 309 mnick = g_strdup_printf("*%s ", nick);
310 if (!strcmp(color, "-")) {//Remove the color 310 if (!strcmp(color, "-")) { // Remove the color
311 if (nickcolors) { 311 if (nickcolors) {
312 nickcolor *nc = g_hash_table_lookup(nickcolors, snick); 312 nickcolor *nc = g_hash_table_lookup(nickcolors, snick);
313 if (nc) {//Have this nick already 313 if (nc) { // Have this nick already
314 nc->manual = FALSE; 314 nc->manual = FALSE;
315 nc = g_hash_table_lookup(nickcolors, mnick); 315 nc = g_hash_table_lookup(nickcolors, mnick);
316 assert(nc);//Must have both at the same time 316 assert(nc); // Must have both at the same time
317 nc->manual = FALSE; 317 nc->manual = FALSE;
318 }// Else -> no color saved, nothing to delete 318 }// Else -> no color saved, nothing to delete
319 } 319 }
320 g_free(snick);//They are not saved in the hash 320 g_free(snick); // They are not saved in the hash
321 g_free(mnick); 321 g_free(mnick);
322 need_update = TRUE; 322 need_update = TRUE;
323 } else { 323 } else {
324 ccolor *cl = get_user_color(color); 324 ccolor *cl = get_user_color(color);
325 if (!cl) { 325 if (!cl) {
329 } else { 329 } else {
330 nickcolor *nc = g_new(nickcolor, 1); 330 nickcolor *nc = g_new(nickcolor, 1);
331 ensure_string_htable(&nickcolors, NULL); 331 ensure_string_htable(&nickcolors, NULL);
332 nc->manual = TRUE; 332 nc->manual = TRUE;
333 nc->color = cl; 333 nc->color = cl;
334 //Free the struct, if any there already 334 // Free the struct, if any there already
335 g_free(g_hash_table_lookup(nickcolors, mnick)); 335 g_free(g_hash_table_lookup(nickcolors, mnick));
336 //Save the new ones 336 // Save the new ones
337 g_hash_table_replace(nickcolors, mnick, nc); 337 g_hash_table_replace(nickcolors, mnick, nc);
338 g_hash_table_replace(nickcolors, snick, nc); 338 g_hash_table_replace(nickcolors, snick, nc);
339 need_update = TRUE; 339 need_update = TRUE;
340 } 340 }
341 } 341 }
381 if ((!strcmp(status, rc->status)) && (!strcmp(wildcard, rc->wildcard))) { 381 if ((!strcmp(status, rc->status)) && (!strcmp(wildcard, rc->wildcard))) {
382 found = head; 382 found = head;
383 break; 383 break;
384 } 384 }
385 } 385 }
386 if (!strcmp(color,"-")) {//Delete the rule 386 if (!strcmp(color,"-")) { // Delete the rule
387 if (found) { 387 if (found) {
388 free_rostercolrule(found->data); 388 free_rostercolrule(found->data);
389 rostercolrules = g_slist_delete_link(rostercolrules, found); 389 rostercolrules = g_slist_delete_link(rostercolrules, found);
390 return TRUE; 390 return TRUE;
391 } else { 391 } else {
538 ncolors = end+1; 538 ncolors = end+1;
539 } 539 }
540 } 540 }
541 g_free(ncolor_start); 541 g_free(ncolor_start);
542 } 542 }
543 if (!nickcols) {//Fallback to have something 543 if (!nickcols) { // Fallback to have something
544 nickcolcount = 1; 544 nickcolcount = 1;
545 nickcols = g_new(ccolor*, 1); 545 nickcols = g_new(ccolor*, 1);
546 *nickcols = g_new(ccolor, 1); 546 *nickcols = g_new(ccolor, 1);
547 (*nickcols)->color_pair = COLOR_GENERAL; 547 (*nickcols)->color_pair = COLOR_GENERAL;
548 (*nickcols)->color_attrib = A_NORMAL; 548 (*nickcols)->color_attrib = A_NORMAL;
1333 num_history_blocks = 0U; 1333 num_history_blocks = 0U;
1334 else 1334 else
1335 num_history_blocks = get_max_history_blocks(); 1335 num_history_blocks = get_max_history_blocks();
1336 1336
1337 text_locale = from_utf8(text); 1337 text_locale = from_utf8(text);
1338 //Convert the nick alone and compute its length 1338 // Convert the nick alone and compute its length
1339 if (mucnicklen) { 1339 if (mucnicklen) {
1340 nicktmp = g_strndup(text, mucnicklen); 1340 nicktmp = g_strndup(text, mucnicklen);
1341 nicklocaltmp = from_utf8(nicktmp); 1341 nicklocaltmp = from_utf8(nicktmp);
1342 mucnicklen = strlen(nicklocaltmp); 1342 mucnicklen = strlen(nicklocaltmp);
1343 g_free(nicklocaltmp); 1343 g_free(nicklocaltmp);
1946 } else { 1946 } else {
1947 if (pending == '#') 1947 if (pending == '#')
1948 wattrset(rosterWnd, get_color(COLOR_ROSTERNMSG)); 1948 wattrset(rosterWnd, get_color(COLOR_ROSTERNMSG));
1949 else { 1949 else {
1950 int color = get_color(COLOR_ROSTER); 1950 int color = get_color(COLOR_ROSTER);
1951 if ((!isspe) && (!isgrp)) {//Look for color rules 1951 if ((!isspe) && (!isgrp)) { // Look for color rules
1952 GSList *head; 1952 GSList *head;
1953 const char *jid = buddy_getjid(BUDDATA(buddy)); 1953 const char *jid = buddy_getjid(BUDDATA(buddy));
1954 for (head = rostercolrules; head; head = g_slist_next(head)) { 1954 for (head = rostercolrules; head; head = g_slist_next(head)) {
1955 rostercolor *rc = head->data; 1955 rostercolor *rc = head->data;
1956 if (g_pattern_match_string(rc->compiled, jid) && 1956 if (g_pattern_match_string(rc->compiled, jid) &&
2658 2658
2659 if (lock) { 2659 if (lock) {
2660 win_entry->bd->lock = TRUE; 2660 win_entry->bd->lock = TRUE;
2661 } else { 2661 } else {
2662 win_entry->bd->lock = FALSE; 2662 win_entry->bd->lock = FALSE;
2663 //win_entry->bd->cleared = FALSE;
2664 if (isspe || (buddy_getflags(BUDDATA(current_buddy)) & ROSTER_FLAG_MSG)) 2663 if (isspe || (buddy_getflags(BUDDATA(current_buddy)) & ROSTER_FLAG_MSG))
2665 win_entry->bd->top = NULL; 2664 win_entry->bd->top = NULL;
2666 } 2665 }
2667 2666
2668 // If chatmode is disabled and we're at the bottom of the buffer, 2667 // If chatmode is disabled and we're at the bottom of the buffer,