# HG changeset patch # User Mikael Berthe # Date 1188076042 -7200 # Node ID 02ad6200df2604ca09860cfe3f2722ad1d91e3ba # Parent 1046bbcb6d14e545a26950eeb3168c413c03de4c Add selectable time prefixes (vorner) diff -r 1046bbcb6d14 -r 02ad6200df26 mcabber/mcabberrc.example --- a/mcabber/mcabberrc.example Sat Aug 25 22:56:47 2007 +0200 +++ b/mcabber/mcabberrc.example Sat Aug 25 23:07:22 2007 +0200 @@ -311,6 +311,12 @@ # - 3: "name" (if the name is the same as the jid, use ) #set buddy_format = 2 # +# Time format: +# - 0: (default) Date and time +# - 1: Time only +# - 2: None +#set time_prefix = 0 +# # When a contacts sends "/me ", mcabber displays "*user ", where user # is the local part of the contact's jid. # If you want mcabber to display the complete bare jid (user@server.com), diff -r 1046bbcb6d14 -r 02ad6200df26 mcabber/src/screen.c --- a/mcabber/src/screen.c Sat Aug 25 22:56:47 2007 +0200 +++ b/mcabber/src/screen.c Sat Aug 25 23:07:22 2007 +0200 @@ -628,6 +628,40 @@ beep(); } +// This and following belongs to dynamic setting of time prefix +static const char *timeprefixes[] = { + "%m-%d %H:%M ", + "%H:%M ", + " " +}; + +static const char *spectimeprefixes[] = { + "%m-%d %H:%M:%S ", + "%H:%M:%S ", + " " +}; + +static int timepreflengths[] = { + 17, + 11, + 6 +}; + +static const char *gettprefix() +{ + return timeprefixes[settings_opt_get_int("time_prefix")]; +} + +static const char *getspectprefix() +{ + return spectimeprefixes[settings_opt_get_int("time_prefix")]; +} + +static unsigned getprefixwidth() +{ + return timepreflengths[settings_opt_get_int("time_prefix")]; +} + // scr_LogPrint(...) // Display a message in the log window. // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set. @@ -757,7 +791,7 @@ } else { // Load buddy history from file (if enabled) tmp->bd = g_new0(buffdata, 1); hlog_read_history(title, &tmp->bd->hbuf, - maxX - Roster_Width - PREFIX_WIDTH); + maxX - Roster_Width - getprefixwidth()); } id = g_strdup(title); @@ -816,8 +850,6 @@ for (n = 0; n < CHAT_WIN_HEIGHT; n++) { wmove(win_entry->win, n, 0); line = *(lines+n); - // NOTE: update PREFIX_WIDTH if you change the date format!! - // You need to set it to the whole prefix length + 1 if (line) { if (line->flags & HBB_PREFIX_HLIGHT_OUT) wattrset(win_entry->win, get_color(COLOR_MSGOUT)); @@ -830,7 +862,7 @@ if (line->timestamp && !(line->flags & (HBB_PREFIX_SPECIAL|HBB_PREFIX_CONT))) { - strftime(date, 30, "%m-%d %H:%M", localtime(&line->timestamp)); + strftime(date, 30, gettprefix(), localtime(&line->timestamp)); } else strcpy(date, " "); if (!(line->flags & HBB_PREFIX_CONT)) { @@ -840,30 +872,32 @@ dir = '<'; else if (line->flags & HBB_PREFIX_OUT) dir = '>'; - wprintw(win_entry->win, "%.11s *%c* ", date, dir); + wprintw(win_entry->win, "%s*%c* ", date, dir); } else if (line->flags & HBB_PREFIX_ERR) { char dir = '#'; if (line->flags & HBB_PREFIX_IN) dir = '<'; else if (line->flags & HBB_PREFIX_OUT) dir = '>'; - wprintw(win_entry->win, "%.11s #%c# ", date, dir); + wprintw(win_entry->win, "%s#%c# ", date, dir); } else if (line->flags & HBB_PREFIX_IN) { char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '='; - wprintw(win_entry->win, "%.11s <%c= ", date, cryptflag); + wprintw(win_entry->win, "%s<%c= ", date, cryptflag); } else if (line->flags & HBB_PREFIX_OUT) { char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '-'; - wprintw(win_entry->win, "%.11s -%c> ", date, cryptflag); + wprintw(win_entry->win, "%s-%c> ", date, cryptflag); } else if (line->flags & HBB_PREFIX_SPECIAL) { - strftime(date, 30, "%m-%d %H:%M:%S", localtime(&line->timestamp)); - wprintw(win_entry->win, "%.14s ", date); + strftime(date, 30, getspectprefix(), localtime(&line->timestamp)); + wprintw(win_entry->win, "%s ", date); } else { - wprintw(win_entry->win, "%.11s ", date); + wprintw(win_entry->win, "%s ", date); } } else { wprintw(win_entry->win, " " ); } + // Make sure we are at the right position + wmove(win_entry->win, n, getprefixwidth()-1); wprintw(win_entry->win, "%s", line->text); // Display text line // Return the color back @@ -1009,7 +1043,7 @@ text_locale = from_utf8(text); hbuf_add_line(&win_entry->bd->hbuf, text_locale, timestamp, prefix_flags, - maxX - Roster_Width - PREFIX_WIDTH, num_history_blocks); + maxX - Roster_Width - getprefixwidth(), num_history_blocks); g_free(text_locale); if (win_entry->bd->cleared) { @@ -1210,7 +1244,7 @@ // Init prev_chatwidth; this variable will be used to prevent us // from rewrapping buffers when the width doesn't change. - prev_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; + prev_chatwidth = maxX - Roster_Width - getprefixwidth(); // Wrap existing status buffer lines hbuf_rebuild(&statushbuf, prev_chatwidth); @@ -1264,7 +1298,7 @@ // Redo line wrapping wbp->bd->top = hbuf_previous_persistent(wbp->bd->top); - new_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; + new_chatwidth = maxX - Roster_Width - getprefixwidth(); if (new_chatwidth != prev_chatwidth) hbuf_rebuild(&wbp->bd->hbuf, new_chatwidth); } @@ -1301,7 +1335,7 @@ resize_win_buffer(NULL, statusWindow, &dim); // Update prev_chatwidth, now that all buffers have been resized - prev_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; + prev_chatwidth = maxX - Roster_Width - getprefixwidth(); // Refresh current buddy window if (chatmode) diff -r 1046bbcb6d14 -r 02ad6200df26 mcabber/src/screen.h --- a/mcabber/src/screen.h Sat Aug 25 22:56:47 2007 +0200 +++ b/mcabber/src/screen.h Sat Aug 25 23:07:22 2007 +0200 @@ -22,9 +22,6 @@ #include "logprint.h" -// Length of the timestamp & flag prefix in the chat buffer window -#define PREFIX_WIDTH 17 - #define INPUTLINE_LENGTH 1024 // Only used in screen.c; this is the maximum line number