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

Compose Bar (status) More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "index/lib.h"
#include "menu/lib.h"
#include "attach_data.h"
#include "cbar_data.h"
#include "format_flags.h"
#include "mutt_globals.h"
#include "muttlib.h"
#include "shared_data.h"
+ Include dependency graph for cbar.c:

Go to the source code of this file.

Functions

int num_attachments (struct ComposeAttachData *adata)
 Count the number of attachments. More...
 
static const char * compose_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)
 Create the status bar string for compose mode - Implements format_t -
Expando Description
%a Total number of attachments
%h Local hostname
%l Approximate size (in bytes) of the current message
%v NeoMutt version string
More...
 
static int cbar_recalc (struct MuttWindow *win)
 Recalculate the Window data - Implements MuttWindow::recalc() -. More...
 
static int cbar_repaint (struct MuttWindow *win)
 Repaint the Window - Implements MuttWindow::repaint() -. More...
 
int cbar_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t. More...
 
int cbar_compose_observer (struct NotifyCallback *nc)
 Notification that the Compose data has changed - Implements observer_t. More...
 
int cbar_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
int cbar_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
struct MuttWindowcbar_new (struct MuttWindow *parent, struct ComposeSharedData *shared)
 Create the Compose Bar (status) More...
 

Detailed Description

Compose Bar (status)

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

Function Documentation

◆ num_attachments()

int num_attachments ( struct ComposeAttachData adata)

Count the number of attachments.

Parameters
adataAttachment data
Return values
numNumber of attachments

Definition at line 86 of file cbar.c.

87 {
88  if (!adata || !adata->menu)
89  return 0;
90  return adata->menu->max;
91 }
int max
Number of entries in the menu.
Definition: lib.h:71
struct Menu * menu
Definition: attach_data.h:35
+ Here is the caller graph for this function:

◆ cbar_color_observer()

int cbar_color_observer ( struct NotifyCallback nc)

Notification that a Color has changed - Implements observer_t.

Definition at line 205 of file cbar.c.

206 {
207  if ((nc->event_type != NT_COLOR) || !nc->global_data || !nc->event_data)
208  return -1;
209 
210  struct EventColor *ev_c = nc->event_data;
211 
212  // MT_COLOR_MAX is sent on `uncolor *`
213  if ((ev_c->color != MT_COLOR_STATUS) && (ev_c->color != MT_COLOR_MAX))
214  return 0;
215 
216  struct MuttWindow *win_cbar = nc->global_data;
217  win_cbar->actions |= WA_REPAINT;
218  mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
219 
220  return 0;
221 }
#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
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:

◆ cbar_compose_observer()

int cbar_compose_observer ( struct NotifyCallback nc)

Notification that the Compose data has changed - Implements observer_t.

Definition at line 226 of file cbar.c.

227 {
228  if ((nc->event_type != NT_COMPOSE) || !nc->global_data || !nc->event_data)
229  return -1;
230 
231  struct MuttWindow *win_cbar = nc->global_data;
232  win_cbar->actions |= WA_REPAINT;
233  mutt_debug(LL_DEBUG5, "compose done, request WA_REPAINT\n");
234 
235  return 0;
236 }
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
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
Compose data has changed, NotifyCompose.
Definition: notify_type.h:41
#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:

◆ cbar_config_observer()

int cbar_config_observer ( struct NotifyCallback nc)

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 241 of file cbar.c.

242 {
243  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
244  return -1;
245 
246  struct EventConfig *ev_c = nc->event_data;
247  if (!mutt_str_equal(ev_c->name, "compose_format"))
248  return 0;
249 
250  struct MuttWindow *win_cbar = nc->global_data;
251  win_cbar->actions |= WA_RECALC;
252  mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
253 
254  return 0;
255 }
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:

◆ cbar_window_observer()

int cbar_window_observer ( struct NotifyCallback nc)

Notification that a Window has changed - Implements observer_t.

Definition at line 260 of file cbar.c.

261 {
262  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
263  return -1;
264 
265  struct MuttWindow *win_cbar = nc->global_data;
266  struct EventWindow *ev_w = nc->event_data;
267  if (ev_w->win != win_cbar)
268  return 0;
269 
270  if (nc->event_subtype == NT_WINDOW_STATE)
271  {
272  win_cbar->actions |= WA_RECALC;
273  mutt_debug(LL_DEBUG5, "window state done, request WA_RECALC\n");
274  }
275  else if (nc->event_subtype == NT_WINDOW_DELETE)
276  {
277  struct MuttWindow *dlg = win_cbar->parent;
278  struct ComposeSharedData *shared = dlg->wdata;
279 
283  notify_observer_remove(win_cbar->notify, cbar_window_observer, win_cbar);
284 
285  mutt_debug(LL_DEBUG5, "window delete done\n");
286  }
287 
288  return 0;
289 }
int cbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: cbar.c:205
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
int cbar_compose_observer(struct NotifyCallback *nc)
Notification that the Compose data has changed - Implements observer_t.
Definition: cbar.c:226
Shared Compose Data.
Definition: shared_data.h:29
Window is about to be deleted.
Definition: mutt_window.h:206
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
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
int cbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: cbar.c:241
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
struct Notify * notify
Notifications: NotifyCompose.
Definition: shared_data.h:36
int cbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: cbar.c:260
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
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:

◆ cbar_new()

struct MuttWindow* cbar_new ( struct MuttWindow parent,
struct ComposeSharedData shared 
)

Create the Compose Bar (status)

Parameters
parentParent Window
sharedShared compose data

Definition at line 296 of file cbar.c.

297 {
298  struct MuttWindow *win_cbar =
301 
302  win_cbar->wdata = cbar_data_new();
303  win_cbar->wdata_free = cbar_data_free;
304  win_cbar->recalc = cbar_recalc;
305  win_cbar->repaint = cbar_repaint;
306 
311 
312  return win_cbar;
313 }
int cbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: cbar.c:205
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
Window uses all available vertical space.
Definition: mutt_window.h:38
int cbar_compose_observer(struct NotifyCallback *nc)
Notification that the Compose data has changed - Implements observer_t.
Definition: cbar.c:226
struct ComposeBarData * cbar_data_new(void)
Free the private data attached to the MuttWindow.
Definition: cbar_data.c:55
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
static int cbar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: cbar.c:158
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
static int cbar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: cbar.c:182
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
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
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
int cbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: cbar.c:241
Compose data has changed, NotifyCompose.
Definition: notify_type.h:41
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
struct Notify * notify
Notifications: NotifyCompose.
Definition: shared_data.h:36
int cbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: cbar.c:260
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
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
void cbar_data_free(struct MuttWindow *win, void **ptr)
Free the private data attached to the MuttWindow - Implements MuttWindow::wdata_free() -...
Definition: cbar_data.c:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function: