NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
pager.c File Reference

Pager Window. More...

#include "config.h"
#include <inttypes.h>
#include <stdbool.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "index/lib.h"
#include "private_data.h"
+ Include dependency graph for pager.c:

Go to the source code of this file.

Functions

static int config_pager_index_lines (struct MuttWindow *win)
 React to changes to $pager_index_lines. More...
 
static int pager_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t. More...
 
static int pager_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int pager_index_observer (struct NotifyCallback *nc)
 Notification that the Index has changed - Implements observer_t. More...
 
static int pager_pager_observer (struct NotifyCallback *nc)
 Notification that the Pager has changed - Implements observer_t. More...
 
static int pager_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
struct MuttWindowpager_window_new (struct MuttWindow *parent, struct IndexSharedData *shared, struct PagerPrivateData *priv)
 Create a new Pager Window (list of Emails) More...
 

Detailed Description

Pager Window.

Authors
  • Richard Russon

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 http://www.gnu.org/licenses/.

Definition in file pager.c.

Function Documentation

◆ config_pager_index_lines()

static int config_pager_index_lines ( struct MuttWindow win)
static

React to changes to $pager_index_lines.

Parameters
winPager Window
Return values
0Successfully handled
-1Error

Definition at line 82 of file pager.c.

83 {
84  if (!mutt_window_is_visible(win))
85  return 0;
86 
87  struct MuttWindow *dlg = dialog_find(win);
88  struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
89  struct MuttWindow *win_index = window_find_child(panel_index, WT_MENU);
90  if (!win_index)
91  return -1;
92 
93  const short c_pager_index_lines =
94  cs_subset_number(NeoMutt->sub, "pager_index_lines");
95 
96  if (c_pager_index_lines > 0)
97  {
98  struct IndexSharedData *shared = dlg->wdata;
99  int vcount = shared->mailbox ? shared->mailbox->vcount : 0;
100  win_index->req_rows = MIN(c_pager_index_lines, vcount);
101  win_index->size = MUTT_WIN_SIZE_FIXED;
102 
103  panel_index->size = MUTT_WIN_SIZE_MINIMISE;
104  panel_index->state.visible = (c_pager_index_lines != 0);
105  }
106  else
107  {
108  win_index->req_rows = MUTT_WIN_SIZE_UNLIMITED;
109  win_index->size = MUTT_WIN_SIZE_MAXIMISE;
110 
111  panel_index->size = MUTT_WIN_SIZE_MAXIMISE;
112  panel_index->state.visible = true;
113  }
114 
115  mutt_window_reflow(dlg);
116  mutt_debug(LL_DEBUG5, "config, request WA_REFLOW\n");
117  return 0;
118 }
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:550
#define MIN(a, b)
Definition: memory.h:31
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
int vcount
The number of virtual messages.
Definition: mailbox.h:102
A panel containing the Index Window.
Definition: mutt_window.h:97
Window has a fixed size.
Definition: mutt_window.h:47
Window size depends on its children.
Definition: mutt_window.h:49
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:529
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:361
short req_rows
Number of rows required.
Definition: mutt_window.h:125
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
Log at debug level 5.
Definition: logging.h:44
Window wants as much space as possible.
Definition: mutt_window.h:48
void * wdata
Private data.
Definition: mutt_window.h:145
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:85
An Window containing a Menu.
Definition: mutt_window.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pager_color_observer()

static int pager_color_observer ( struct NotifyCallback nc)
static

Notification that a Color has changed - Implements observer_t.

Definition at line 123 of file pager.c.

124 {
125  if ((nc->event_type != NT_COLOR) || !nc->global_data || !nc->event_data)
126  return -1;
127 
128  mutt_debug(LL_DEBUG5, "color done\n");
129  return 0;
130 }
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
+ Here is the caller graph for this function:

◆ pager_config_observer()

static int pager_config_observer ( struct NotifyCallback nc)
static

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 135 of file pager.c.

136 {
137  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
138  return -1;
139 
140  struct EventConfig *ev_c = nc->event_data;
141  struct MuttWindow *win_pager = nc->global_data;
142 
143  if (mutt_str_equal(ev_c->name, "pager_index_lines"))
144  {
145  config_pager_index_lines(win_pager);
146  mutt_debug(LL_DEBUG5, "config done\n");
147  }
148 
149  return 0;
150 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
A config-change event.
Definition: subset.h:69
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
static int config_pager_index_lines(struct MuttWindow *win)
React to changes to $pager_index_lines.
Definition: pager.c:82
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
Log at debug level 5.
Definition: logging.h:44
const char * name
Name of config item that changed.
Definition: subset.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pager_index_observer()

static int pager_index_observer ( struct NotifyCallback nc)
static

Notification that the Index has changed - Implements observer_t.

Definition at line 155 of file pager.c.

156 {
157  if ((nc->event_type != NT_INDEX) || !nc->global_data)
158  return -1;
159 
160  struct MuttWindow *win_pager = nc->global_data;
161  if (!win_pager)
162  return 0;
163 
164  struct IndexSharedData *shared = nc->event_data;
165  if (!shared)
166  return 0;
167 
168  struct PagerPrivateData *priv = win_pager->wdata;
169  if (!priv)
170  return 0;
171 
173  {
175  win_pager->actions |= WA_RECALC;
176  mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
177  }
178 
179  if (nc->event_subtype & NT_INDEX_EMAIL)
180  {
182  win_pager->actions |= WA_RECALC;
183  mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
184  }
185 
186  return 0;
187 }
#define NT_INDEX_EMAIL
Email has changed.
Definition: lib.h:65
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
#define NT_INDEX_MAILBOX
Mailbox has changed.
Definition: lib.h:64
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
Private state data for the Pager.
Definition: private_data.h:39
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
struct Menu * menu
Definition: private_data.h:41
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pager_pager_observer()

static int pager_pager_observer ( struct NotifyCallback nc)
static

Notification that the Pager has changed - Implements observer_t.

Definition at line 192 of file pager.c.

193 {
194  if ((nc->event_type != NT_PAGER) || !nc->global_data || !nc->event_data)
195  return -1;
196 
197  mutt_debug(LL_DEBUG5, "pager done\n");
198  return 0;
199 }
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Pager data has changed, NotifyPager, IndexSharedData.
Definition: notify_type.h:50
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
+ Here is the caller graph for this function:

◆ pager_window_observer()

static int pager_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t.

Definition at line 204 of file pager.c.

205 {
206  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
207  return -1;
208 
209  if (nc->event_subtype != NT_WINDOW_DELETE)
210  return 0;
211 
212  struct MuttWindow *win_pager = nc->global_data;
213  struct EventWindow *ev_w = nc->event_data;
214  if (ev_w->win != win_pager)
215  return 0;
216 
217  struct MuttWindow *dlg = window_find_parent(win_pager, WT_DLG_INDEX);
218  if (!dlg)
219  dlg = window_find_parent(win_pager, WT_DLG_DO_PAGER);
220 
221  struct IndexSharedData *shared = dlg->wdata;
222 
227  notify_observer_remove(win_pager->notify, pager_window_observer, win_pager);
228 
229  mutt_debug(LL_DEBUG5, "window delete done\n");
230 
231  return 0;
232 }
static int pager_pager_observer(struct NotifyCallback *nc)
Notification that the Pager has changed - Implements observer_t.
Definition: pager.c:192
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
static int pager_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: pager.c:204
An Event that happened to a Window.
Definition: mutt_window.h:215
static int pager_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t.
Definition: pager.c:155
Window is about to be deleted.
Definition: mutt_window.h:206
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
static int pager_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: pager.c:135
struct MuttWindow * window_find_parent(struct MuttWindow *win, enum WindowType type)
Find a (grand-)parent of a Window by type.
Definition: mutt_window.c:575
Pager Dialog, mutt_do_pager()
Definition: mutt_window.h:84
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
static int pager_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: pager.c:123
void * event_data
Data from notify_send()
Definition: observer.h:44
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pager_window_new()

struct MuttWindow* pager_window_new ( struct MuttWindow parent,
struct IndexSharedData shared,
struct PagerPrivateData priv 
)

Create a new Pager Window (list of Emails)

Parameters
parentParent Window
sharedShared Index Data
privPrivate Pager Data
Return values
ptrNew Window

Definition at line 241 of file pager.c.

243 {
244  struct MuttWindow *win =
247  win->wdata = priv;
248 
254 
255  return win;
256 }
static int pager_pager_observer(struct NotifyCallback *nc)
Notification that the Pager has changed - Implements observer_t.
Definition: pager.c:192
static int pager_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: pager.c:204
Window uses all available vertical space.
Definition: mutt_window.h:38
static int pager_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t.
Definition: pager.c:155
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Window with a custom drawing function.
Definition: mutt_window.h:95
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
static int pager_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: pager.c:135
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
Pager data has changed, NotifyPager, IndexSharedData.
Definition: notify_type.h:50
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
static int pager_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: pager.c:123
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
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:180
Window wants as much space as possible.
Definition: mutt_window.h:48
void * wdata
Private data.
Definition: mutt_window.h:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function: