Commit df1a9ea3 authored by Thomas Roessler's avatar Thomas Roessler

More addressbook fixes.

parent d3e9c08a
......@@ -117,7 +117,7 @@ static int alias_SortAddress (const void *a, const void *b)
void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
{
ALIAS *aliasp, *aliasl;
ALIAS *aliasp;
MUTTMENU *menu;
ALIAS **AliasTable = NULL;
int t = -1;
......@@ -125,17 +125,16 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
int op;
char helpstr[SHORT_STRING];
int omax;
if (!aliases)
{
mutt_error _("You have no aliases!");
return;
}
/* tell whoever called me to redraw the screen when I return */
set_option (OPTNEEDREDRAW);
/* tell mutt_alias and mutt_unalias that this menu is active */
set_option (OPTALIASMENU);
menu = mutt_new_menu ();
menu->make_entry = alias_entry;
......@@ -144,18 +143,26 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
menu->title = _("Aliases");
menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_ALIAS, AliasHelp);
new_aliases:
omax = menu->max;
/* count the number of aliases */
for (aliasp = aliases; aliasp; aliasp = aliasp->next)
{
aliasp->del = 0;
aliasp->tagged = 0;
aliasp->self->del = 0;
aliasp->self->tagged = 0;
menu->max++;
}
menu->data = AliasTable = (ALIAS **) safe_calloc (menu->max, sizeof (ALIAS *));
safe_realloc ((void **) &AliasTable, menu->max * sizeof (ALIAS *));
menu->data = AliasTable;
for (i = 0, aliasp = aliases; aliasp; aliasp = aliasp->next, i++)
AliasTable[i] = aliasp;
for (i = omax, aliasp = aliases; aliasp; aliasp = aliasp->next, i++)
{
AliasTable[i] = aliasp->self;
aliases = aliasp;
}
if ((SortAlias & SORT_MASK) != SORT_ORDER)
{
......@@ -167,6 +174,13 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
while (!done)
{
if (aliases->next)
{
menu->redraw |= REDRAW_FULL;
aliases = aliases->next;
goto new_aliases;
}
switch ((op = mutt_menuLoop (menu)))
{
case OP_DELETE:
......@@ -180,7 +194,7 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
}
else
{
AliasTable[menu->current]->del = (op == OP_DELETE) ? 1 : 0;
AliasTable[menu->current]->self->del = (op == OP_DELETE) ? 1 : 0;
menu->redraw |= REDRAW_CURRENT;
if (option (OPTRESOLVE) && menu->current < menu->max - 1)
{
......@@ -212,29 +226,4 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases)
mutt_menuDestroy (&menu);
safe_free ((void **) &AliasTable);
unset_option (OPTALIASMENU);
/* remove aliases marked for deletion. */
aliasl = NULL;
for (aliasp = Aliases; aliasp; aliasp = aliasp->next)
{
if (aliasp->del)
{
if (aliasl)
aliasl->next = aliasp->next;
else
Aliases = aliasp->next;
aliasp->next = NULL;
mutt_free_alias (&aliasp);
if (aliasl)
aliasp = aliasl;
else
aliasp = Aliases;
}
else
aliasl = aliasp;
}
}
......@@ -241,7 +241,8 @@ void mutt_create_alias (ENVELOPE *cur, ADDRESS *iadr)
return;
}
new = safe_calloc (1, sizeof (ALIAS));
new = safe_calloc (1, sizeof (ALIAS));
new->self = new;
new->name = safe_strdup (buf);
if (adr)
......@@ -381,6 +382,7 @@ int mutt_alias_complete (char *s, size_t buflen)
}
/* build alias list and show it */
a = Aliases;
while (a)
{
......@@ -414,6 +416,29 @@ int mutt_alias_complete (char *s, size_t buflen)
safe_free ((void **) &a_cur);
}
/* remove any aliases marked for deletion */
a_list = NULL;
for (a_cur = Aliases; a_cur; a_cur = a_cur->next)
{
if (a_cur->del)
{
if (a_list)
a_list->next = a_cur->next;
else
Aliases = a_cur->next;
a_cur->next = NULL;
mutt_free_alias (&a_cur);
if (a_list)
a_cur = a_list;
else
a_cur = Aliases;
}
else
a_list = a_cur;
}
return 0;
}
......
......@@ -432,7 +432,7 @@ static int parse_unalias (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *er
{
if (mutt_strcasecmp (buf->data, tmp->name) == 0)
{
if (option (OPTALIASMENU))
if (CurrentMenu == MENU_ALIAS)
{
tmp->del = 1;
set_option (OPTFORCEREDRAWINDEX);
......@@ -481,15 +481,19 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
{
/* create a new alias */
tmp = (ALIAS *) safe_calloc (1, sizeof (ALIAS));
tmp->self = tmp;
tmp->name = safe_malloc (len + 1);
memcpy (tmp->name, s->dptr, len);
tmp->name[len] = 0;
/* give the main addressbook code a chance */
if (CurrentMenu == MENU_ALIAS)
set_option (OPTMENUCALLER);
}
else
{
/* override the previous value */
rfc822_free_address (&tmp->addr);
if (option (OPTALIASMENU))
if (CurrentMenu == MENU_ALIAS)
set_option (OPTFORCEREDRAWINDEX);
}
s->dptr = p;
......
......@@ -794,6 +794,13 @@ int mutt_menuLoop (MUTTMENU *menu)
FOREVER
{
if (option (OPTMENUCALLER))
{
unset_option (OPTMENUCALLER);
return OP_NULL;
}
mutt_curs_set (0);
#ifdef USE_IMAP
......
......@@ -442,7 +442,7 @@ enum
* functions while we are executing an
* external program.
*/
OPTALIASMENU, /* (pseudo) alias menu active */
OPTMENUCALLER, /* (pseudo) tell menu to give caller a take */
#ifdef HAVE_PGP
OPTPGPCHECKTRUST, /* (pseudo) used by pgp_select_key () */
OPTDONTHANDLEPGPKEYS, /* (pseudo) used to extract PGP keys */
......@@ -486,6 +486,7 @@ void mutt_init (int, LIST *);
typedef struct alias
{
struct alias *self; /* XXX - ugly hack */
char *name;
ADDRESS *addr;
struct alias *next;
......
......@@ -207,9 +207,13 @@ static void query_entry (char *s, size_t slen, MUTTMENU *m, int num)
NONULL (table[num].data->other));
}
static int query_tag (MUTTMENU *menu, int n)
static int query_tag (MUTTMENU *menu, int n, int m)
{
return ((((ENTRY *) menu->data)[n].tagged = !((ENTRY *) menu->data)[n].tagged) ? 1 : -1);
ENTRY *cur = &((ENTRY *) menu->data)[n];
int ot = cur->tagged;
cur->tagged = m >= 0 ? m : !cur->tagged;
return cur->tagged - ot;
}
int mutt_query_complete (char *buf, size_t buflen)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment