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

Pager Bar. More...

#include "config.h"
#include <inttypes.h>
#include <stdio.h>
#include <sys/stat.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "pbar.h"
#include "lib.h"
#include "index/lib.h"
#include "context.h"
#include "format_flags.h"
#include "hdrline.h"
#include "private_data.h"
+ Include dependency graph for pbar.c:

Go to the source code of this file.

Data Structures

struct  PBarPrivateData
 Data to draw the Pager Bar. More...
 

Functions

static int pbar_recalc (struct MuttWindow *win)
 Recalculate the Window data - Implements MuttWindow::recalc() -. More...
 
static int pbar_repaint (struct MuttWindow *win)
 Repaint the Window - Implements MuttWindow::repaint() -. More...
 
static int pbar_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t. More...
 
static int pbar_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int pbar_index_observer (struct NotifyCallback *nc)
 Notification that the Index has changed - Implements observer_t. More...
 
static int pbar_pager_observer (struct NotifyCallback *nc)
 Notification that the Pager has changed - Implements observer_t. More...
 
static int pbar_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
static void pbar_data_free (struct MuttWindow *win, void **ptr)
 Free the private data attached to the MuttWindow - Implements MuttWindow::wdata_free() -. More...
 
static struct PBarPrivateDatapbar_data_new (struct IndexSharedData *shared, struct PagerPrivateData *priv)
 Free the private data attached to the MuttWindow. More...
 
struct MuttWindowpbar_new (struct MuttWindow *parent, struct IndexSharedData *shared, struct PagerPrivateData *priv)
 Create the Pager Bar. More...
 

Detailed Description

Pager Bar.

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 pbar.c.

Function Documentation

◆ pbar_color_observer()

static int pbar_color_observer ( struct NotifyCallback nc)
static

Notification that a Color has changed - Implements observer_t.

Definition at line 170 of file pbar.c.

171 {
172  if ((nc->event_type != NT_COLOR) || !nc->global_data || !nc->event_data)
173  return -1;
174 
175  struct EventColor *ev_c = nc->event_data;
176  enum ColorId color = ev_c->color;
177 
178  if (color != MT_COLOR_STATUS)
179  return 0;
180 
181  struct MuttWindow *win_pbar = nc->global_data;
182  win_pbar->actions |= WA_REPAINT;
183  mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
184 
185  return 0;
186 }
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
An Event that happened to a Colour.
Definition: color.h:122
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
ColorId
List of all colored objects.
Definition: color.h:39
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
Status bar (takes a pattern)
Definition: color.h:75
enum ColorId color
Definition: color.h:124
#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:

◆ pbar_config_observer()

static int pbar_config_observer ( struct NotifyCallback nc)
static

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 191 of file pbar.c.

192 {
193  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
194  return -1;
195 
196  struct EventConfig *ev_c = nc->event_data;
197  if (!mutt_str_equal(ev_c->name, "pager_format"))
198  return 0;
199 
200  struct MuttWindow *win_pbar = nc->global_data;
201  win_pbar->actions |= WA_RECALC;
202  mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
203 
204  return 0;
205 }
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
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
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
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
#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:

◆ pbar_index_observer()

static int pbar_index_observer ( struct NotifyCallback nc)
static

Notification that the Index has changed - Implements observer_t.

Definition at line 210 of file pbar.c.

211 {
212  if ((nc->event_type != NT_INDEX) || !nc->global_data)
213  return -1;
214 
215  struct MuttWindow *win_ibar = nc->global_data;
216  if (!win_ibar)
217  return 0;
218 
219  struct IndexSharedData *shared = nc->event_data;
220  if (!shared)
221  return 0;
222 
224  {
225  win_ibar->actions |= WA_RECALC;
226  mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
227  }
228 
229  if (nc->event_subtype & NT_INDEX_EMAIL)
230  {
231  win_ibar->actions |= WA_RECALC;
232  mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
233  }
234 
235  return 0;
236 }
#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
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
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
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the caller graph for this function:

◆ pbar_pager_observer()

static int pbar_pager_observer ( struct NotifyCallback nc)
static

Notification that the Pager has changed - Implements observer_t.

Definition at line 241 of file pbar.c.

242 {
243  if ((nc->event_type != NT_PAGER) || !nc->global_data)
244  return -1;
245 
246  struct MuttWindow *win_pbar = nc->global_data;
247  if (!win_pbar)
248  return 0;
249 
250  struct IndexSharedData *shared = nc->event_data;
251  if (!shared)
252  return 0;
253 
255  {
256  win_pbar->actions |= WA_RECALC;
257  mutt_debug(LL_DEBUG5, "pager done, request WA_RECALC\n");
258  }
259 
260  if (nc->event_subtype & NT_PAGER_EMAIL)
261  {
262  win_pbar->actions |= WA_RECALC;
263  mutt_debug(LL_DEBUG5, "pager done, request WA_RECALC\n");
264  }
265 
266  return 0;
267 }
#define NT_PAGER_EMAIL
Email has changed.
Definition: lib.h:173
#define NT_PAGER_MAILBOX
Mailbox has changed.
Definition: lib.h:172
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
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
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
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
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the caller graph for this function:

◆ pbar_window_observer()

static int pbar_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t.

Definition at line 272 of file pbar.c.

273 {
274  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
275  return -1;
276 
277  struct MuttWindow *win_pbar = nc->global_data;
278  struct EventWindow *ev_w = nc->event_data;
279  if (ev_w->win != win_pbar)
280  return 0;
281 
282  if (nc->event_subtype == NT_WINDOW_STATE)
283  {
284  win_pbar->actions |= WA_RECALC;
285  mutt_debug(LL_NOTIFY, "window state done, request WA_RECALC\n");
286  }
287  else if (nc->event_subtype == NT_WINDOW_DELETE)
288  {
289  struct PBarPrivateData *pbar_data = win_pbar->wdata;
290  struct IndexSharedData *shared = pbar_data->shared;
291 
296  notify_observer_remove(win_pbar->notify, pbar_window_observer, win_pbar);
297 
298  mutt_debug(LL_DEBUG5, "window delete done\n");
299  }
300 
301  return 0;
302 }
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
Log of notifications.
Definition: logging.h:45
An Event that happened to a Window.
Definition: mutt_window.h:215
struct IndexSharedData * shared
Shared Index data.
Definition: pbar.c:85
Window is about to be deleted.
Definition: mutt_window.h:206
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
static int pbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: pbar.c:191
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
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
Data to draw the Pager Bar.
Definition: pbar.c:83
static int pbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: pbar.c:170
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
static int pbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: pbar.c:272
static int pbar_pager_observer(struct NotifyCallback *nc)
Notification that the Pager has changed - Implements observer_t.
Definition: pbar.c:241
static int pbar_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t.
Definition: pbar.c:210
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
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:

◆ pbar_data_new()

static struct PBarPrivateData* pbar_data_new ( struct IndexSharedData shared,
struct PagerPrivateData priv 
)
static

Free the private data attached to the MuttWindow.

Definition at line 319 of file pbar.c.

321 {
322  struct PBarPrivateData *pbar_data = mutt_mem_calloc(1, sizeof(struct PBarPrivateData));
323 
324  pbar_data->shared = shared;
325  pbar_data->priv = priv;
326 
327  return pbar_data;
328 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct IndexSharedData * shared
Shared Index data.
Definition: pbar.c:85
struct PagerPrivateData * priv
Private Pager data.
Definition: pbar.c:86
Data to draw the Pager Bar.
Definition: pbar.c:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pbar_new()

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

Create the Pager Bar.

Parameters
parentParent Window
sharedShared Pager data
privPrivate Pager data
Return values
ptrNew Pager Bar

Definition at line 337 of file pbar.c.

339 {
340  struct MuttWindow *win_pbar =
343 
344  win_pbar->wdata = pbar_data_new(shared, priv);
345  win_pbar->wdata_free = pbar_data_free;
346  win_pbar->recalc = pbar_recalc;
347  win_pbar->repaint = pbar_repaint;
348 
354 
355  return win_pbar;
356 }
static int pbar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: pbar.c:93
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
Window uses all available vertical space.
Definition: mutt_window.h:38
static int pbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: pbar.c:191
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
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
static struct PBarPrivateData * pbar_data_new(struct IndexSharedData *shared, struct PagerPrivateData *priv)
Free the private data attached to the MuttWindow.
Definition: pbar.c:319
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
Window has a fixed size.
Definition: mutt_window.h:47
static void pbar_data_free(struct MuttWindow *win, void **ptr)
Free the private data attached to the MuttWindow - Implements MuttWindow::wdata_free() -...
Definition: pbar.c:307
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
static int pbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: pbar.c:170
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
static int pbar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: pbar.c:146
static int pbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: pbar.c:272
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
static int pbar_pager_observer(struct NotifyCallback *nc)
Notification that the Pager has changed - Implements observer_t.
Definition: pbar.c:241
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
static int pbar_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t.
Definition: pbar.c:210
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
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
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: