Show
Ignore:
Timestamp:
2000-05-16 11:38:41 (9 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

A modified version of Will Fiveash's compose format patch.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • compose.c

    r1716 r1792  
    415415} 
    416416 
     417/*  
     418 * cum_attachs_size: Cumulative Attachments Size 
     419 * 
     420 *  
     421 * Returns the total number of bytes used by the attachments in the 
     422 * attachment list. 
     423 */ 
     424 
     425static unsigned long cum_attachs_size (MUTTMENU *menu) 
     426{ 
     427  size_t s; 
     428  unsigned short i; 
     429  ATTACHPTR **idx = menu->data; 
     430  CONTENT *info; 
     431   
     432  for (i = 0, s = 0; i < menu->max; i++) 
     433  { 
     434    if ((info = idx[i]->content->content)) 
     435    { 
     436      switch (idx[i]->content->encoding) 
     437      { 
     438        case ENCQUOTEDPRINTABLE: 
     439          s += 3 * (info->lobin + info->hibin) + info->ascii; 
     440          break; 
     441        case ENCBASE64: 
     442          s += (4 * (info->lobin + info->hibin + info->ascii)) / 3; 
     443          break; 
     444        default: 
     445          s += info->lobin + info->hibin + info->ascii; 
     446          break; 
     447      } 
     448    } 
     449  } 
     450 
     451  return s; 
     452} 
     453 
     454/* prototype for use below */ 
     455void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu,  
     456      const char *p); 
     457 
     458/* 
     459 * compose_format_str() 
     460 * 
     461 * %a = total number of attachments  
     462 * %h = hostname  [option] 
     463 * %l = approx. length of current message (in bytes)  
     464 * %v = Mutt version  
     465 * 
     466 * This function is similar to status_format_str().  Look at that function for 
     467 * help when modifying this function. 
     468 */ 
     469 
     470static const char * 
     471compose_format_str (char *buf, size_t buflen, char op, const char *src, 
     472                   const char *prefix, const char *ifstring, 
     473                   const char *elsestring, 
     474                   unsigned long data, format_flag flags) 
     475{ 
     476  char fmt[SHORT_STRING], tmp[SHORT_STRING]; 
     477  int optional = (flags & M_FORMAT_OPTIONAL); 
     478  MUTTMENU *menu = (MUTTMENU *) data; 
     479 
     480  *buf = 0; 
     481  switch (op) 
     482  { 
     483    case 'a': /* total number of attachments */ 
     484        snprintf (fmt, sizeof (fmt), "%%%sd", prefix); 
     485        snprintf (buf, buflen, fmt, menu->max); 
     486      break; 
     487 
     488    case 'h':  /* hostname */ 
     489      snprintf (fmt, sizeof (fmt), "%%%ss", prefix); 
     490      snprintf (buf, buflen, fmt, NONULL(Hostname)); 
     491      break; 
     492 
     493    case 'l': /* approx length of current message in bytes */ 
     494        snprintf (fmt, sizeof (fmt), "%%%ss", prefix); 
     495        mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0); 
     496        snprintf (buf, buflen, fmt, tmp); 
     497      break; 
     498 
     499    case 'v': 
     500      snprintf (fmt, sizeof (fmt), "Mutt %%s"); 
     501      snprintf (buf, buflen, fmt, MUTT_VERSION); 
     502      break; 
     503 
     504    case 0: 
     505      *buf = 0; 
     506      return (src); 
     507 
     508    default: 
     509      snprintf (buf, buflen, "%%%s%c", prefix, op); 
     510      break; 
     511  } 
     512 
     513  if (optional) 
     514    compose_status_line (buf, buflen, menu, ifstring); 
     515  else if (flags & M_FORMAT_OPTIONAL) 
     516    compose_status_line (buf, buflen, menu, elsestring); 
     517 
     518  return (src); 
     519} 
     520 
     521void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu,  
     522      const char *p) 
     523{ 
     524  mutt_FormatString (buf, buflen, p, compose_format_str,  
     525        (unsigned long) menu, 0); 
     526} 
     527 
     528 
    417529/* return values: 
    418530 * 
     
    451563  menu->make_entry = snd_entry; 
    452564  menu->tag = mutt_tag_attach; 
    453   menu->title = _("Compose"); 
    454565  menu->data = idx; 
    455566  menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp); 
     
    460571    { 
    461572      case OP_REDRAW: 
    462         menu_redraw_status (menu); 
    463573        draw_envelope (msg, fcc); 
    464574        menu->offset = HDR_ATTACH; 
     
    511621          mutt_edit_file (Editor, msg->content->filename); 
    512622          mutt_update_encoding (msg->content); 
    513           menu->redraw = REDRAW_CURRENT; 
     623          menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; 
    514624          break; 
    515625        } 
     
    575685        menu->redraw |= REDRAW_STATUS; 
    576686 
    577         if(option(OPTNEEDREDRAW)) 
     687        if (option(OPTNEEDREDRAW)) 
    578688        { 
    579689          menu->redraw = REDRAW_FULL; 
     
    749859        if (menu->current == 0) 
    750860          msg->content = idx[0]->content; 
     861 
     862        menu->redraw |= REDRAW_STATUS; 
    751863        break; 
    752864 
     
    837949        { 
    838950          mutt_update_encoding(idx[menu->current]->content); 
    839           menu->redraw = REDRAW_CURRENT; 
     951          menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; 
    840952        } 
    841953        break; 
     
    869981          { 
    870982            idx[menu->current]->content->encoding = i; 
    871             menu->redraw = REDRAW_CURRENT; 
     983            menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; 
    872984            mutt_clear_error(); 
    873985          } 
     
    9091021                        idx[menu->current]->content->filename); 
    9101022        mutt_update_encoding (idx[menu->current]->content); 
    911         menu->redraw = REDRAW_CURRENT; 
     1023        menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; 
    9121024        break; 
    9131025 
     
    10771189        if (op == OP_FILTER) /* cte might have changed */ 
    10781190          menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT;  
     1191        menu->redraw |= REDRAW_STATUS; 
    10791192        break; 
    10801193 
     
    11211234          mutt_error (_("Error running \"%s\"!"), buf); 
    11221235        else 
     1236        { 
    11231237          mutt_update_encoding (msg->content); 
     1238          menu->redraw |= REDRAW_STATUS; 
     1239        } 
    11241240        break; 
    11251241 
     
    11741290 
    11751291    } 
     1292 
     1293    /* Draw formated compose status line */ 
     1294    if (menu->redraw & REDRAW_STATUS)  
     1295    { 
     1296        compose_status_line (buf, sizeof (buf), menu, NONULL(ComposeFormat)); 
     1297        CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2); 
     1298        SETCOLOR (MT_COLOR_STATUS); 
     1299        printw ("%-*.*s", COLS, COLS, buf); 
     1300        SETCOLOR (MT_COLOR_NORMAL); 
     1301        menu->redraw &= ~REDRAW_STATUS; 
     1302    } 
    11761303  } 
    11771304