NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
do_pager.c
Go to the documentation of this file.
1
58#include "config.h"
59#include <stdbool.h>
60#include <stddef.h>
61#include "mutt/lib.h"
62#include "config/lib.h"
63#include "core/lib.h"
64#include "gui/lib.h"
65#include "lib.h"
66#include "index/lib.h"
67#include "protos.h"
68
69struct Email;
70
75{
76 if (nc->event_type != NT_CONFIG)
77 return 0;
78 if (!nc->global_data || !nc->event_data)
79 return -1;
80
81 struct EventConfig *ev_c = nc->event_data;
82 if (!mutt_str_equal(ev_c->name, "status_on_top"))
83 return 0;
84
85 struct MuttWindow *dlg = nc->global_data;
87 mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
88 return 0;
89}
90
95{
96 if (nc->event_type != NT_WINDOW)
97 return 0;
98 if (!nc->global_data || !nc->event_data)
99 return -1;
101 return 0;
102
103 struct MuttWindow *dlg = nc->global_data;
104 struct EventWindow *ev_w = nc->event_data;
105 if (ev_w->win != dlg)
106 return 0;
107
110 mutt_debug(LL_DEBUG5, "window delete done\n");
111
112 return 0;
113}
114
122int mutt_do_pager(struct PagerView *pview, struct Email *e)
123{
124 ASSERT(pview);
125 ASSERT(pview->pdata);
126 ASSERT(pview->pdata->fname);
127 ASSERT((pview->mode == PAGER_MODE_ATTACH) ||
128 (pview->mode == PAGER_MODE_HELP) || (pview->mode == PAGER_MODE_OTHER));
129
133
134 struct IndexSharedData *shared = index_shared_data_new();
135 shared->email = e;
136
137 notify_set_parent(shared->notify, dlg->notify);
138
139 dlg->wdata = shared;
141
142 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
143 struct MuttWindow *panel_pager = ppanel_new(c_status_on_top, shared);
144 dlg->focus = panel_pager;
145 mutt_window_add_child(dlg, panel_pager);
146
149 dialog_push(dlg);
150
151 pview->win_index = NULL;
152 pview->win_pbar = window_find_child(panel_pager, WT_STATUS_BAR);
153 pview->win_pager = window_find_child(panel_pager, WT_CUSTOM);
154
155 int rc;
156
157 const char *const c_pager = pager_get_pager(NeoMutt->sub);
158 if (c_pager)
159 {
160 struct Buffer *cmd = buf_pool_get();
161
162 mutt_endwin();
163 buf_file_expand_fmt_quote(cmd, c_pager, pview->pdata->fname);
164 if (mutt_system(buf_string(cmd)) == -1)
165 {
166 mutt_error(_("Error running \"%s\""), buf_string(cmd));
167 rc = -1;
168 }
169 else
170 {
171 rc = 0;
172 }
174 buf_pool_release(&cmd);
175 }
176 else
177 {
178 rc = dlg_pager(pview);
179 }
180
181 dialog_pop();
182 mutt_window_free(&dlg);
183 return rc;
184}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:151
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:109
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:142
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition: do_pager.c:122
void buf_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1456
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:221
int dlg_pager(struct PagerView *pview)
Display an email, attachment, or help, in a window -.
Definition: dlg_pager.c:215
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int dopager_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: do_pager.c:74
static int dopager_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: do_pager.c:94
void index_shared_data_free(struct MuttWindow *win, void **ptr)
Free Shared Index Data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:278
Convenience wrapper for the gui headers.
GUI manage the main index (list of emails)
struct IndexSharedData * index_shared_data_new(void)
Create new Index Data.
Definition: shared_data.c:307
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
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:191
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:95
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
bool window_status_on_top(struct MuttWindow *panel, struct ConfigSubset *sub)
Organise windows according to config variable.
Definition: mutt_window.c:784
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:202
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:446
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:182
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:533
@ WT_CUSTOM
Window with a custom drawing function.
Definition: mutt_window.h:95
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ WT_DLG_PAGER
Pager Dialog, dlg_pager()
Definition: mutt_window.h:85
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:39
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:53
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:49
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
const char * pager_get_pager(struct ConfigSubset *sub)
Get the value of $pager.
Definition: config.c:111
struct MuttWindow * ppanel_new(bool status_on_top, struct IndexSharedData *shared)
Create the Windows for the Pager panel.
Definition: ppanel.c:133
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:142
@ PAGER_MODE_HELP
Pager is invoked via 3rd path to show help.
Definition: lib.h:141
@ PAGER_MODE_ATTACH
Pager is invoked via 2nd path. A user-selected attachment (mime part or a nested email) will be shown...
Definition: lib.h:139
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
Prototypes for many functions.
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:52
#define ASSERT(COND)
Definition: signal2.h:58
Key value store.
String manipulation buffer.
Definition: buffer.h:36
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
The envelope/body of an email.
Definition: email.h:39
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
struct Email * email
Currently selected Email.
Definition: shared_data.h:42
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
const char * fname
Name of the file to read.
Definition: lib.h:165
Paged view into some data.
Definition: lib.h:172
struct MuttWindow * win_index
Index Window.
Definition: lib.h:178
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:173
enum PagerMode mode
Pager mode.
Definition: lib.h:174
struct MuttWindow * win_pbar
Pager Bar Window.
Definition: lib.h:179
struct MuttWindow * win_pager
Pager Window.
Definition: lib.h:180