Re: Bug#294802: tin: line-wrap in German filter menu
Michael Bienia <[email protected]>
| Newsgroups | gmane.network.tin.devel |
|---|---|
| Message-ID | <[email protected]> |
On 2005-02-12 15:05:05 +0100, Urs JanÃen wrote:
> On Fri, Feb 11, 2005 at 07:02:50PM +0100, Christian Garbs wrote:
> > In the German filter menu (scoring for articles) the item
> > "Wähle Msg-Id" has four values:
> >
> > * Nur
> > * Nein
> > * Voll
> > * Letzte
> >
> > "Letzte" is too long and always wrapped around to the next line,
> > regardless of screen width. It looks to me like 5 characters are
> > reserved for the option but 6 are needed.
>
> quick and dirty fix: in filter.c:filter_menu() increase len by 3
> (estonian values are even longer), e.g.:
> len = cCOLS - 33;
> instead of
> len = cCOLS - 30;
>
> right thing would be some dynamic space calculation depening on the
> length of the longest translated value...
Attached is a patch to compute the space based on lengths of the
translated strings. I've tested it only with english and german but it
should also work with estonian.
The patch includes also a small clean up part: it uses
GLOBAL_{MENU,QUICK}_FILTER_{SELECT,KILL} in filter_menu() and
quick_filter() and gets rid of the defines FILTER_{KILL,SELECT}
Michael
patch-20050330.diff
(text/plain, 10.4 KB)
include/proto.h | 4 +-
include/tin.h | 3 --
src/filter.c | 78 ++++++++++++++++++++++++++++++++++++++++++++------------
src/group.c | 4 +-
src/page.c | 4 +-
src/thread.c | 2 -
6 files changed, 69 insertions(+), 26 deletions(-)
diff -Nurp tin-1.7.8/include/proto.h tin-1.7.8.new/include/proto.h
--- tin-1.7.8/include/proto.h 2005-03-20 18:02:41.000000000 +0100
+++ tin-1.7.8.new/include/proto.h 2005-03-30 00:30:01.906097589 +0200
@@ -178,8 +178,8 @@ extern void feed_articles(int function,
/* filter.c */
extern t_bool filter_articles(struct t_group *group);
-extern t_bool filter_menu(int type, struct t_group *group, struct t_article *art);
-extern t_bool quick_filter(int type, struct t_group *group, struct t_article *art);
+extern t_bool filter_menu(t_function type, struct t_group *group, struct t_article *art);
+extern t_bool quick_filter(t_function type, struct t_group *group, struct t_article *art);
extern t_bool quick_filter_select_posted_art(struct t_group *group, const char *subj, const char *a_message_id);
extern t_bool read_filter_file(const char *file);
extern void free_filter_array(struct t_filters *ptr);
diff -Nurp tin-1.7.8/include/tin.h tin-1.7.8.new/include/tin.h
--- tin-1.7.8/include/tin.h 2005-03-07 16:23:23.000000000 +0100
+++ tin-1.7.8.new/include/tin.h 2005-03-30 00:29:22.953869521 +0200
@@ -1356,9 +1356,6 @@ enum {
/*
* filter_type used in struct t_filter
*/
-#define FILTER_KILL 0
-#define FILTER_SELECT 1
-
#define SCORE_MAX 10000
#define FILTER_SUBJ_CASE_SENSITIVE 0
diff -Nurp tin-1.7.8/src/filter.c tin-1.7.8.new/src/filter.c
--- tin-1.7.8/src/filter.c 2005-02-12 15:00:56.000000000 +0100
+++ tin-1.7.8.new/src/filter.c 2005-03-30 00:25:42.907125140 +0200
@@ -986,7 +986,7 @@ fmt_filter_menu_prompt(
*/
t_bool
filter_menu(
- int type,
+ t_function type,
struct t_group *group,
struct t_article *art)
{
@@ -1003,11 +1003,14 @@ filter_menu(
char text_time[PATH_LEN];
char double_time[PATH_LEN];
char quat_time[PATH_LEN];
- t_function func, default_func = FILTER_SAVE;
- int i, len;
+ int i, len, clen = 0, flen = 0;
struct t_filter_rule rule;
t_bool proceed;
t_bool ret;
+ t_function func, default_func = FILTER_SAVE;
+#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
+ wchar_t *wbuf;
+#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
signal_context = cFilter;
@@ -1036,7 +1039,7 @@ filter_menu(
printascii(keyquit, func_to_key(GLOBAL_QUIT, filter_keys));
printascii(keysave, func_to_key(FILTER_SAVE, filter_keys));
- if (type == FILTER_KILL) {
+ if (type == GLOBAL_MENU_FILTER_KILL) {
ptr_filter_from = _(txt_kill_from);
ptr_filter_lines = _(txt_kill_lines);
ptr_filter_menu = _(txt_kill_menu);
@@ -1047,7 +1050,7 @@ filter_menu(
ptr_filter_time = _(txt_kill_time);
ptr_filter_help_scope = _(txt_help_kill_scope);
ptr_filter_quit_edit_save = _(txt_quit_edit_save_kill);
- } else {
+ } else { /* type == GLOBAL_MENU_FILTER_SELECT */
ptr_filter_from = _(txt_select_from);
ptr_filter_lines = _(txt_select_lines);
ptr_filter_menu = _(txt_select_menu);
@@ -1063,11 +1066,54 @@ filter_menu(
ptr_filter_comment = _(txt_filter_comment);
ptr_filter_groupname = group->name;
- len = cCOLS - 33;
+#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
+ if ((wbuf = char2wchar_t(_(txt_no))) != NULL) {
+ clen = MAX(clen, wcswidth(wbuf, wcslen(wbuf)));
+ free(wbuf);
+ }
+ if ((wbuf = char2wchar_t(_(txt_yes))) != NULL) {
+ clen = MAX(clen, wcswidth(wbuf, wcslen(wbuf)));
+ free(wbuf);
+ }
+ if ((wbuf = char2wchar_t(_(txt_full))) != NULL) {
+ clen = MAX(clen, wcswidth(wbuf, wcslen(wbuf)));
+ free(wbuf);
+ }
+ if ((wbuf = char2wchar_t(_(txt_last))) != NULL) {
+ clen = MAX(clen, wcswidth(wbuf, wcslen(wbuf)));
+ free(wbuf);
+ }
+ if ((wbuf = char2wchar_t(_(txt_only))) != NULL) {
+ clen = MAX(clen, wcswidth(wbuf, wcslen(wbuf)));
+ free(wbuf);
+ }
+ if ((wbuf = char2wchar_t(ptr_filter_subj)) != NULL) {
+ flen = MAX(flen, wcswidth(wbuf, wcslen(wbuf)) - 2);
+ free(wbuf);
+ }
+ if ((wbuf = char2wchar_t(ptr_filter_from)) != NULL) {
+ flen = MAX(flen, wcswidth(wbuf, wcslen(wbuf)) - 2);
+ free(wbuf);
+ }
+ if ((wbuf = char2wchar_t(ptr_filter_msgid)) != NULL) {
+ flen = MAX(flen, wcswidth(wbuf, wcslen(wbuf)) - 2);
+ free(wbuf);
+ }
+#else
+ clen = MAX(clen, (int) strlen(_(txt_no)));
+ clen = MAX(clen, (int) strlen(_(txt_yes)));
+ clen = MAX(clen, (int) strlen(_(txt_full)));
+ clen = MAX(clen, (int) strlen(_(txt_last)));
+ clen = MAX(clen, (int) strlen(_(txt_only)));
+ flen = MAX(flen, (int) strlen(ptr_filter_subj) - 2);
+ flen = MAX(flen, (int) strlen(ptr_filter_from) - 2);
+ flen = MAX(flen, (int) strlen(ptr_filter_msgid) - 2);
+#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
+ len = cCOLS - flen - clen - 1 + 4;
snprintf(text_time, sizeof(text_time), _(txt_time_default_days), tinrc.filter_days);
fmt_filter_menu_prompt(text_subj, sizeof(text_subj), ptr_filter_subj, len, art->subject);
- snprintf(text_score, sizeof(text_score), _(txt_filter_score), (type == FILTER_KILL ? -tinrc.score_kill : tinrc.score_select));
+ snprintf(text_score, sizeof(text_score), _(txt_filter_score), (type == GLOBAL_MENU_FILTER_KILL ? -tinrc.score_kill : tinrc.score_select));
fmt_filter_menu_prompt(text_from, sizeof(text_from), ptr_filter_from, len, art->from);
fmt_filter_menu_prompt(text_msgid, sizeof(text_msgid), ptr_filter_msgid, len - 4, MSGID(art));
@@ -1278,9 +1324,9 @@ filter_menu(
rule.score = atoi(buf);
else {
/* use default score */
- if (type == FILTER_KILL)
+ if (type == GLOBAL_MENU_FILTER_KILL)
rule.score = tinrc.score_kill;
- else /* type == FILTER_SELECT */
+ else /* type == GLOBAL_MENU_FILTER_SELECT */
rule.score = tinrc.score_select;
}
@@ -1298,7 +1344,7 @@ filter_menu(
rule.score = SCORE_MAX;
/* get the right sign for the score */
- if (type == FILTER_KILL)
+ if (type == GLOBAL_MENU_FILTER_KILL)
rule.score = -rule.score;
/*
@@ -1404,7 +1450,7 @@ filter_menu(
*/
t_bool
quick_filter(
- int type,
+ t_function type,
struct t_group *group,
struct t_article *art)
{
@@ -1414,12 +1460,12 @@ quick_filter(
struct t_filter_rule rule;
t_bool ret;
- if (type == FILTER_KILL) {
+ if (type == GLOBAL_QUICK_FILTER_KILL) {
header = group->attribute->quick_kill_header;
expire = group->attribute->quick_kill_expire;
icase = group->attribute->quick_kill_case;
scope = group->attribute->quick_kill_scope;
- } else {
+ } else { /* type == GLOBAL_QUICK_FILTER_SELECT */
header = group->attribute->quick_select_header;
expire = group->attribute->quick_select_expire;
icase = group->attribute->quick_select_case;
@@ -1429,7 +1475,7 @@ quick_filter(
#ifdef DEBUG
if (debug)
error_message("%s header=[%d] scope=[%s] expire=[%s] case=[%d]",
- (type == FILTER_KILL) ? "KILL" : "SELECT", header,
+ (type == GLOBAL_QUICK_FILTER_KILL) ? "KILL" : "SELECT", header,
BlankIfNull(scope), txt_onoff[expire != FALSE ? 1 : 0], icase);
#endif /* DEBUG */
@@ -1447,7 +1493,7 @@ quick_filter(
rule.subj_ok = (header == FILTER_SUBJ_CASE_SENSITIVE || header == FILTER_SUBJ_CASE_IGNORE);
/* create an auto-comment. */
- if (type == FILTER_KILL)
+ if (type == GLOBAL_QUICK_FILTER_KILL)
snprintf(txt, sizeof(txt), "%s%s%c%s%s%s", _(txt_filter_rule_created), "'", ']', "' (", _(txt_help_article_quick_kill), ").");
else
snprintf(txt, sizeof(txt), "%s%s%c%s%s%s", _(txt_filter_rule_created), "'", '[', "' (", _(txt_help_article_quick_select), ").");
@@ -1457,7 +1503,7 @@ quick_filter(
rule.icase = icase;
rule.expire_time = expire;
rule.check_string = TRUE;
- rule.score = (type == FILTER_KILL) ? tinrc.score_kill : tinrc.score_select;
+ rule.score = (type == GLOBAL_QUICK_FILTER_KILL) ? tinrc.score_kill : tinrc.score_select;
ret = add_filter_rule(group, art, &rule, TRUE);
rule.comment = free_filter_comment(rule.comment);
diff -Nurp tin-1.7.8/src/group.c tin-1.7.8.new/src/group.c
--- tin-1.7.8/src/group.c 2005-03-14 14:32:32.000000000 +0100
+++ tin-1.7.8.new/src/group.c 2005-03-30 00:27:47.725425199 +0200
@@ -322,7 +322,7 @@ group_page(
old_top = top_art;
n = (int) base[grpmenu.curr];
old_artnum = arts[n].artnum;
- if (filter_menu((func == GLOBAL_MENU_FILTER_KILL) ? FILTER_KILL : FILTER_SELECT, group, &arts[n])) {
+ if (filter_menu(func, group, &arts[n])) {
if (filter_articles(group)) {
make_threads(group, FALSE);
grpmenu.curr = find_new_pos(old_top, old_artnum, grpmenu.curr);
@@ -353,7 +353,7 @@ group_page(
old_top = top_art;
n = (int) base[grpmenu.curr]; /* should this depend on show_only_unread? */
old_artnum = arts[n].artnum;
- if (quick_filter((func == GLOBAL_QUICK_FILTER_KILL) ? FILTER_KILL : FILTER_SELECT, group, &arts[n])) {
+ if (quick_filter(func, group, &arts[n])) {
info_message((func == GLOBAL_QUICK_FILTER_KILL) ? _(txt_info_add_kill) : _(txt_info_add_select));
if (filter_articles(group)) {
make_threads(group, FALSE);
diff -Nurp tin-1.7.8/src/page.c tin-1.7.8.new/src/page.c
--- tin-1.7.8/src/page.c 2005-03-14 14:37:00.000000000 +0100
+++ tin-1.7.8.new/src/page.c 2005-03-30 00:28:32.728601296 +0200
@@ -686,7 +686,7 @@ page_goto_next_unread:
case GLOBAL_QUICK_FILTER_SELECT: /* quickly auto-select article */
case GLOBAL_QUICK_FILTER_KILL: /* quickly kill article */
- if ((filtered_articles = quick_filter((func == GLOBAL_QUICK_FILTER_KILL) ? FILTER_KILL : FILTER_SELECT, group, &arts[this_resp])))
+ if ((filtered_articles = quick_filter(func, group, &arts[this_resp])))
goto return_to_index;
draw_page(group->name, 0);
@@ -695,7 +695,7 @@ page_goto_next_unread:
case GLOBAL_MENU_FILTER_SELECT: /* auto-select article menu */
case GLOBAL_MENU_FILTER_KILL: /* kill article menu */
XFACE_CLEAR();
- if (filter_menu((func == GLOBAL_MENU_FILTER_KILL) ? FILTER_KILL : FILTER_SELECT, group, &arts[this_resp])) {
+ if (filter_menu(func, group, &arts[this_resp])) {
if ((filtered_articles = filter_articles(group)))
goto return_to_index;
}
diff -Nurp tin-1.7.8/src/thread.c tin-1.7.8.new/src/thread.c
--- tin-1.7.8/src/thread.c 2005-03-14 18:32:18.000000000 +0100
+++ tin-1.7.8.new/src/thread.c 2005-03-30 00:29:00.177829186 +0200
@@ -543,7 +543,7 @@ thread_page(
* is 'troublesome'
*/
n = find_response(thread_basenote, thdmenu.curr);
- filter_menu((func == GLOBAL_MENU_FILTER_KILL) ? FILTER_KILL : FILTER_SELECT, group, &arts[n]);
+ filter_menu(func, group, &arts[n]);
if (filter_articles(group)) {
make_threads(group, FALSE);
if ((n = next_unread(n)) == -1) {