NeoMutt  2023-03-22
Teaching an old dog new tricks
dlg_autocrypt.c File Reference

Autocrypt account menu. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "menu/lib.h"
#include "format_flags.h"
#include "functions.h"
#include "keymap.h"
#include "mutt_logging.h"
#include "muttlib.h"
#include "opcodes.h"
+ Include dependency graph for dlg_autocrypt.c:

Go to the source code of this file.


static const char * autocrypt_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 Autocrypt account list - Implements format_t -. More...
static void autocrypt_make_entry (struct Menu *menu, char *buf, size_t buflen, int num)
 Create a line for the Autocrypt account menu - Implements Menu::make_entry() -. More...
static void autocrypt_menu_free (struct Menu *menu, void **ptr)
 Free the Autocrypt account Menu - Implements Menu::mdata_free() -. More...
bool populate_menu (struct Menu *menu)
 Add the Autocrypt data to a Menu. More...
static int autocrypt_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -. More...
static int autocrypt_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -. More...
void dlg_select_autocrypt_account (void)
 Display the Autocrypt account Menu. More...


static const struct Mapping AutocryptAcctHelp []
 Help Bar for the Autocrypt Account selection dialog. More...

Detailed Description

Autocrypt account menu.

  • Kevin J. McCarthy

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

Definition in file dlg_autocrypt.c.

Function Documentation

◆ populate_menu()

bool populate_menu ( struct Menu menu)

Add the Autocrypt data to a Menu.

menuMenu to populate
Return values

Definition at line 214 of file dlg_autocrypt.c.

216 // Clear out any existing data
217 autocrypt_menu_free(menu, &menu->mdata);
218 menu->max = 0;
220 struct AutocryptAccount **accounts = NULL;
221 int num_accounts = 0;
223 if (mutt_autocrypt_db_account_get_all(&accounts, &num_accounts) < 0)
224 return false;
226 struct AccountEntry *entries = mutt_mem_calloc(num_accounts, sizeof(struct AccountEntry));
227 menu->mdata = entries;
229 menu->max = num_accounts;
231 for (int i = 0; i < num_accounts; i++)
232 {
233 entries[i].num = i + 1;
234 /* note: we are transferring the account pointer to the entries
235 * array, and freeing the accounts array below. the account
236 * will be freed in autocrypt_menu_free(). */
237 entries[i].account = accounts[i];
239 entries[i].addr = mutt_addr_new();
240 entries[i].addr->mailbox = mutt_str_dup(accounts[i]->email_addr);
241 mutt_addr_to_local(entries[i].addr);
242 }
243 FREE(&accounts);
246 return true;
struct Address * mutt_addr_new(void)
Create a new Address.
Definition: address.c:385
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
Definition: address.c:1316
int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
Get all accounts from an Autocrypt database.
Definition: db.c:454
static void autocrypt_menu_free(struct Menu *menu, void **ptr)
Free the Autocrypt account Menu - Implements Menu::mdata_free() -.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:43
Redraw everything.
Definition: lib.h:60
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:178
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
An entry in the Autocrypt account Menu.
Definition: private.h:44
struct Address * addr
Email address associated with the account.
Definition: private.h:47
struct AutocryptAccount * account
Account details.
Definition: private.h:46
int num
Number in the index.
Definition: private.h:45
char * mailbox
Mailbox and host address.
Definition: address.h:38
Autocrypt account.
Definition: lib.h:106
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_select_autocrypt_account()

void dlg_select_autocrypt_account ( void  )

Display the Autocrypt account Menu.

Definition at line 306 of file dlg_autocrypt.c.

308 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
309 if (!c_autocrypt)
310 return;
312 if (mutt_autocrypt_init(false))
313 return;
318 struct Menu *menu = dlg->wdata;
321 populate_menu(menu);
323 struct AutocryptData ad = { false, menu };
324 dlg->wdata = &ad;
326 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
327 // L10N: Autocrypt Account Management Menu title
328 sbar_set_title(sbar, _("Autocrypt Accounts"));
330 // NT_COLOR is handled by the SimpleDialog
334 // ---------------------------------------------------------------------------
335 // Event Loop
336 int op = OP_NULL;
337 do
338 {
339 menu_tagging_dispatcher(menu->win, op);
340 window_redraw(NULL);
343 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
344 if (op < 0)
345 continue;
346 if (op == OP_NULL)
347 {
349 continue;
350 }
353 int rc = autocrypt_function_dispatcher(dlg, op);
355 if (rc == FR_UNKNOWN)
356 rc = menu_function_dispatcher(menu->win, op);
357 if (rc == FR_UNKNOWN)
358 rc = global_function_dispatcher(NULL, op);
359 } while (!ad.done);
360 // ---------------------------------------------------------------------------
362 simple_dialog_free(&dlg);
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:97
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Unknown function.
Definition: dispatcher.h:33
static const struct Mapping AutocryptAcctHelp[]
Help Bar for the Autocrypt Account selection dialog.
Definition: dlg_autocrypt.c:87
bool populate_menu(struct Menu *menu)
Add the Autocrypt data to a Menu.
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int autocrypt_function_dispatcher(struct MuttWindow *win, int op)
Perform a Autocrypt function - Implements function_dispatcher_t -.
Definition: functions.c:169
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static void autocrypt_make_entry(struct Menu *menu, char *buf, size_t buflen, int num)
Create a line for the Autocrypt account menu - Implements Menu::make_entry() -.
static int autocrypt_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
static int autocrypt_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:796
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1062
Log at debug level 1.
Definition: logging.h:40
#define _(a)
Definition: message.h:28
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:603
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:521
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
Autocrypt Dialog, dlg_select_autocrypt_account()
Definition: mutt_window.h:79
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
Data to pass to the Autocrypt Functions.
Definition: functions.h:34
bool done
Should we close the Dialog?
Definition: functions.h:35
struct Menu * menu
Autocrypt Menu.
Definition: functions.h:36
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Autocrypt Account menu.
Definition: type.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ AutocryptAcctHelp

const struct Mapping AutocryptAcctHelp[]
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Help"), OP_HELP },
{ NULL, 0 }
#define N_(a)
Definition: message.h:32

Help Bar for the Autocrypt Account selection dialog.

Definition at line 87 of file dlg_autocrypt.c.