NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
browse.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stdbool.h>
31 #include <stdint.h>
32 #include <stdio.h>
33 #include "mutt/lib.h"
34 #include "config/lib.h"
35 #include "core/lib.h"
36 #include "lib.h"
37 #include "browser.h"
38 #include "format_flags.h"
39 #include "mdata.h"
40 #include "muttlib.h"
41 
55 const char *group_index_format_str(char *buf, size_t buflen, size_t col, int cols,
56  char op, const char *src, const char *prec,
57  const char *if_str, const char *else_str,
58  intptr_t data, MuttFormatFlags flags)
59 {
60  char fn[128], fmt[128];
61  struct Folder *folder = (struct Folder *) data;
62 
63  switch (op)
64  {
65  case 'C':
66  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
67  snprintf(buf, buflen, fmt, folder->num + 1);
68  break;
69 
70  case 'd':
71  if (folder->ff->nd->desc)
72  {
73  char *desc = mutt_str_dup(folder->ff->nd->desc);
74  const char *const c_newsgroups_charset =
75  cs_subset_string(NeoMutt->sub, "newsgroups_charset");
76  const char *const c_charset = cs_subset_string(NeoMutt->sub, "charset");
77  if (c_newsgroups_charset)
78  mutt_ch_convert_string(&desc, c_newsgroups_charset, c_charset, MUTT_ICONV_HOOK_FROM);
80 
81  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
82  snprintf(buf, buflen, fmt, desc);
83  FREE(&desc);
84  }
85  else
86  {
87  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
88  snprintf(buf, buflen, fmt, "");
89  }
90  break;
91 
92  case 'f':
93  mutt_str_copy(fn, folder->ff->name, sizeof(fn));
94  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
95  snprintf(buf, buflen, fmt, fn);
96  break;
97 
98  case 'M':
99  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
100  if (folder->ff->nd->deleted)
101  snprintf(buf, buflen, fmt, 'D');
102  else
103  snprintf(buf, buflen, fmt, folder->ff->nd->allowed ? ' ' : '-');
104  break;
105 
106  case 'N':
107  snprintf(fmt, sizeof(fmt), "%%%sc", prec);
108  if (folder->ff->nd->subscribed)
109  snprintf(buf, buflen, fmt, ' ');
110  else
111  snprintf(buf, buflen, fmt, folder->ff->has_new_mail ? 'N' : 'u');
112  break;
113 
114  case 'n':
115  {
116  const bool c_mark_old = cs_subset_bool(NeoMutt->sub, "mark_old");
117  if (c_mark_old && (folder->ff->nd->last_cached >= folder->ff->nd->first_message) &&
118  (folder->ff->nd->last_cached <= folder->ff->nd->last_message))
119  {
120  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
121  snprintf(buf, buflen, fmt, folder->ff->nd->last_message - folder->ff->nd->last_cached);
122  }
123  else
124  {
125  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
126  snprintf(buf, buflen, fmt, folder->ff->nd->unread);
127  }
128  break;
129  }
130 
131  case 's':
132  if (flags & MUTT_FORMAT_OPTIONAL)
133  {
134  if (folder->ff->nd->unread != 0)
135  {
136  mutt_expando_format(buf, buflen, col, cols, if_str,
137  group_index_format_str, data, flags);
138  }
139  else
140  {
141  mutt_expando_format(buf, buflen, col, cols, else_str,
142  group_index_format_str, data, flags);
143  }
144  }
145  else
146  {
147  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
148  snprintf(buf, buflen, fmt, folder->ff->nd->unread);
149  }
150  break;
151  }
152  return src;
153 }
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
Definition: muttlib.c:780
uint8_t MuttFormatFlags
Flags for mutt_expando_format(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: format_flags.h:29
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:758
Flags to control mutt_expando_format()
Container for Accounts, Notifications.
Definition: neomutt.h:36
bool subscribed
Definition: mdata.h:41
Convenience wrapper for the config headers.
anum_t last_cached
Definition: mdata.h:39
struct FolderFile * ff
Definition: browser.h:46
GUI component for displaying/selecting items from a list.
Some miscellaneous functions.
Convenience wrapper for the core headers.
char * name
Definition: browser.h:62
int num
Definition: browser.h:47
A folder/dir in the browser.
Definition: browser.h:44
#define MUTT_ICONV_HOOK_FROM
apply charset-hooks to fromcode
Definition: charset.h:72
bool allowed
Definition: mdata.h:43
Nntp-specific Mailbox data.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool deleted
Definition: mdata.h:44
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:749
anum_t first_message
Definition: mdata.h:36
anum_t unread
Definition: mdata.h:40
#define FREE(x)
Definition: memory.h:40
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
int mutt_mb_filter_unprintable(char **s)
Replace unprintable characters.
Definition: mbyte.c:423
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct NntpMboxData * nd
Definition: browser.h:80
Convenience wrapper for the library headers.
const char * group_index_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the newsgroup menu - Implements format_t -Expando Description %C Current newsgro...
Definition: browse.c:55
char * desc
Definition: mdata.h:35
anum_t last_message
Definition: mdata.h:37
bool has_new_mail
true if mailbox has "new mail"
Definition: browser.h:65