Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 1376:a0deb5124ebf
Check time_prefix value before using it
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 23 Nov 2007 21:56:58 +0100 |
parents | 7daf906fbcdc |
children | 40095d413da9 |
comparison
equal
deleted
inserted
replaced
1375:6fd893fe0908 | 1376:a0deb5124ebf |
---|---|
792 "%H:%M:%S ", | 792 "%H:%M:%S ", |
793 " " | 793 " " |
794 }; | 794 }; |
795 | 795 |
796 static int timepreflengths[] = { | 796 static int timepreflengths[] = { |
797 // (length of the corresponding timeprefix + 5) | |
797 17, | 798 17, |
798 11, | 799 11, |
799 6 | 800 6 |
800 }; | 801 }; |
801 | 802 |
802 static const char *gettprefix() | 803 static const char *gettprefix() |
803 { | 804 { |
804 return timeprefixes[settings_opt_get_int("time_prefix")]; | 805 guint n = settings_opt_get_int("time_prefix"); |
806 return timeprefixes[(n < 3 ? n : 0)]; | |
805 } | 807 } |
806 | 808 |
807 static const char *getspectprefix() | 809 static const char *getspectprefix() |
808 { | 810 { |
809 return spectimeprefixes[settings_opt_get_int("time_prefix")]; | 811 guint n = settings_opt_get_int("time_prefix"); |
812 return spectimeprefixes[(n < 3 ? n : 0)]; | |
810 } | 813 } |
811 | 814 |
812 static unsigned getprefixwidth() | 815 static unsigned getprefixwidth() |
813 { | 816 { |
814 return timepreflengths[settings_opt_get_int("time_prefix")]; | 817 guint n = settings_opt_get_int("time_prefix"); |
818 return timepreflengths[(n < 3 ? n : 0)]; | |
815 } | 819 } |
816 | 820 |
817 // scr_LogPrint(...) | 821 // scr_LogPrint(...) |
818 // Display a message in the log window. | 822 // Display a message in the log window. |
819 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set. | 823 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set. |
958 // scr_UpdateWindow() | 962 // scr_UpdateWindow() |
959 // (Re-)Display the given chat window. | 963 // (Re-)Display the given chat window. |
960 static void scr_UpdateWindow(winbuf *win_entry) | 964 static void scr_UpdateWindow(winbuf *win_entry) |
961 { | 965 { |
962 int n; | 966 int n; |
963 int width; | 967 int width, prefixwidth; |
964 hbb_line **lines, *line; | 968 hbb_line **lines, *line; |
965 GList *hbuf_head; | 969 GList *hbuf_head; |
966 char date[64]; | 970 char date[64]; |
967 int color; | 971 int color; |
968 | 972 |
969 width = getmaxx(win_entry->win); | 973 width = getmaxx(win_entry->win); |
974 prefixwidth = getprefixwidth(); | |
970 | 975 |
971 // Should the window be empty? | 976 // Should the window be empty? |
972 if (win_entry->bd->cleared) { | 977 if (win_entry->bd->cleared) { |
973 werase(win_entry->win); | 978 werase(win_entry->win); |
974 return; | 979 return; |
1053 } else { | 1058 } else { |
1054 wprintw(win_entry->win, " " ); | 1059 wprintw(win_entry->win, " " ); |
1055 } | 1060 } |
1056 | 1061 |
1057 // Make sure we are at the right position | 1062 // Make sure we are at the right position |
1058 wmove(win_entry->win, n, getprefixwidth()-1); | 1063 wmove(win_entry->win, n, prefixwidth-1); |
1059 | 1064 |
1060 //The MUC nick - overwrite with propper color | 1065 // The MUC nick - overwrite with proper color |
1061 if (line->mucnicklen) { | 1066 if (line->mucnicklen) { |
1062 //Store the char after the nick | 1067 // Store the char after the nick |
1063 char tmp = line->text[line->mucnicklen]; | 1068 char tmp = line->text[line->mucnicklen]; |
1064 muccoltype type = glob_muccol, *typetmp; | 1069 muccoltype type = glob_muccol, *typetmp; |
1065 //Terminate the string after the nick | 1070 // Terminate the string after the nick |
1066 line->text[line->mucnicklen] = '\0'; | 1071 line->text[line->mucnicklen] = '\0'; |
1067 char *mucjid = g_utf8_strdown(CURRENT_JID, -1); | 1072 char *mucjid = g_utf8_strdown(CURRENT_JID, -1); |
1068 if (muccolors) { | 1073 if (muccolors) { |
1069 typetmp = g_hash_table_lookup(muccolors, mucjid); | 1074 typetmp = g_hash_table_lookup(muccolors, mucjid); |
1070 if (typetmp) | 1075 if (typetmp) |
1082 nc->manual = false; | 1087 nc->manual = false; |
1083 *snick = '<'; | 1088 *snick = '<'; |
1084 snick[strlen(snick)-1] = '>'; | 1089 snick[strlen(snick)-1] = '>'; |
1085 *mnick = '*'; | 1090 *mnick = '*'; |
1086 mnick[strlen(mnick)-1] = ' '; | 1091 mnick[strlen(mnick)-1] = ' '; |
1087 //Insert them | 1092 // Insert them |
1088 g_hash_table_insert(nickcolors, snick, nc); | 1093 g_hash_table_insert(nickcolors, snick, nc); |
1089 g_hash_table_insert(nickcolors, mnick, nc); | 1094 g_hash_table_insert(nickcolors, mnick, nc); |
1090 } | 1095 } |
1091 if (nickcolors) | 1096 if (nickcolors) |
1092 actual = g_hash_table_lookup(nickcolors, line->text); | 1097 actual = g_hash_table_lookup(nickcolors, line->text); |
1093 if (actual && ((type == MC_ALL) || (actual->manual)) | 1098 if (actual && ((type == MC_ALL) || (actual->manual)) |
1094 && (line->flags & HBB_PREFIX_IN) && | 1099 && (line->flags & HBB_PREFIX_IN) && |
1095 (!(line->flags & HBB_PREFIX_HLIGHT_OUT))) | 1100 (!(line->flags & HBB_PREFIX_HLIGHT_OUT))) |
1096 wattrset(win_entry->win, get_color(actual->color)); | 1101 wattrset(win_entry->win, get_color(actual->color)); |
1097 wprintw(win_entry->win, "%s", line->text); | 1102 wprintw(win_entry->win, "%s", line->text); |
1098 //Return the char | 1103 // Return the char |
1099 line->text[line->mucnicklen] = tmp; | 1104 line->text[line->mucnicklen] = tmp; |
1100 //Return the color back | 1105 // Return the color back |
1101 wattrset(win_entry->win, get_color(color)); | 1106 wattrset(win_entry->win, get_color(color)); |
1102 } | 1107 } |
1103 | 1108 |
1104 // Display text line | 1109 // Display text line |
1105 wprintw(win_entry->win, "%s", line->text+line->mucnicklen); | 1110 wprintw(win_entry->win, "%s", line->text+line->mucnicklen); |