NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
progress.c
Go to the documentation of this file.
1
31#include "config.h"
32#include <stdarg.h>
33#include <stdbool.h>
34#include <stdio.h>
35#include "mutt/lib.h"
36#include "config/lib.h"
37#include "core/lib.h"
38#include "gui/lib.h"
39#include "lib.h"
40#include "globals.h"
41#include "mutt_logging.h"
42#include "window.h"
43
44struct Progress;
45
51static size_t choose_increment(enum ProgressType type)
52{
53 switch (type)
54 {
56 return cs_subset_number(NeoMutt->sub, "net_inc");
58 return cs_subset_number(NeoMutt->sub, "read_inc");
60 return cs_subset_number(NeoMutt->sub, "write_inc");
61 default:
62 return 0;
63 }
64}
65
80bool progress_update(struct Progress *progress, size_t pos, int percent)
81{
82 if (!progress)
83 return false;
84
85 // Decloak an opaque pointer
86 struct MuttWindow *win = (struct MuttWindow *) progress;
87 const bool updated = progress_window_update(win, pos, percent);
88
89 if (SigWinch)
90 {
91 SigWinch = false;
93 window_redraw(NULL);
94 }
95 else
96 {
97 if (updated)
98 {
99 window_redraw(win);
100 }
101 }
102
103 return updated;
104}
105
110void progress_free(struct Progress **ptr)
111{
112 if (!ptr)
113 return;
114
115 if (!*ptr)
116 {
118 return;
119 }
120
121 // Decloak an opaque pointer
122 struct MuttWindow **wptr = (struct MuttWindow **) ptr;
123 struct MuttWindow *win_pop = msgcont_pop_window();
124 if (win_pop != *wptr)
125 return;
126
127 mutt_window_free(wptr);
128}
129
139struct Progress *progress_new(enum ProgressType type, size_t size)
140{
141 if (OptNoCurses)
142 return NULL;
143
144 const size_t size_inc = choose_increment(type);
145 if (size_inc == 0) // The user has disabled the progress bar
146 return NULL;
147
148 const short c_time_inc = cs_subset_number(NeoMutt->sub, "time_inc");
149 const bool is_bytes = (type == MUTT_PROGRESS_NET);
150
151 struct MuttWindow *win = progress_window_new(size, size_inc, c_time_inc, is_bytes);
152
154
155 // Return an opaque pointer
156 return (struct Progress *) win;
157}
158
165void progress_set_message(struct Progress *progress, const char *fmt, ...)
166{
167 // Decloak an opaque pointer
168 struct MuttWindow *win = (struct MuttWindow *) progress;
169
170 va_list ap;
171 va_start(ap, fmt);
172
173 if (win)
174 {
175 progress_window_set_message(win, fmt, ap);
176 }
177 else
178 {
179 char msg[1024] = { 0 };
180 vsnprintf(msg, sizeof(msg), fmt, ap);
181 mutt_message("%s", msg);
182 }
183
184 va_end(ap);
185}
186
190void progress_set_size(struct Progress *progress, size_t size)
191{
192 // Decloak an opaque pointer
193 struct MuttWindow *win = (struct MuttWindow *) progress;
194
196}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:72
#define mutt_message(...)
Definition: logging2.h:91
Convenience wrapper for the gui headers.
void msgcont_push_window(struct MuttWindow *win)
Add a window to the Container Stack.
Definition: msgcont.c:93
struct MuttWindow * msgcont_pop_window(void)
Remove the last Window from the Container Stack.
Definition: msgcont.c:57
Convenience wrapper for the library headers.
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:634
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:202
@ NT_RESIZE
Window has been resized.
Definition: notify_type.h:52
ProgressType
What kind of operation is this progress tracking?
Definition: lib.h:80
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition: lib.h:81
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: lib.h:82
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
Definition: lib.h:83
void progress_window_set_size(struct MuttWindow *win, size_t size)
Set the progress size.
Definition: window.c:363
bool progress_window_update(struct MuttWindow *win, size_t pos, int percent)
Update the Progress Bar Window.
Definition: window.c:274
void progress_window_set_message(struct MuttWindow *win, const char *fmt, va_list ap)
Set the progress message.
Definition: window.c:346
struct MuttWindow * progress_window_new(size_t size, size_t size_inc, size_t time_inc, bool is_bytes)
Create a new Progress Bar Window.
Definition: window.c:311
void progress_set_message(struct Progress *progress, const char *fmt,...)
Set the progress message.
Definition: progress.c:165
struct Progress * progress_new(enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition: progress.c:139
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:110
static size_t choose_increment(enum ProgressType type)
Choose the right increment given a ProgressType.
Definition: progress.c:51
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:80
void progress_set_size(struct Progress *progress, size_t size)
Set the progress size.
Definition: progress.c:190
volatile sig_atomic_t SigWinch
true after SIGWINCH is received
Definition: signal.c:64
Key value store.
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct Notify * notify_resize
Window resize notifications handler.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
Progress Bar Window.