NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
shared_data.c File Reference

Data shared between Index, Pager and Sidebar. More...

#include "config.h"
#include <stdbool.h>
#include "mutt/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "shared_data.h"
#include "lib.h"
#include "pattern/lib.h"
#include "mview.h"
+ Include dependency graph for shared_data.c:

Go to the source code of this file.

Functions

static int index_shared_mview_observer (struct NotifyCallback *nc)
 Notification that the MailboxView has changed - Implements observer_t -.
 
static int index_shared_account_observer (struct NotifyCallback *nc)
 Notification that an Account has changed - Implements observer_t -.
 
static int index_shared_mailbox_observer (struct NotifyCallback *nc)
 Notification that a Mailbox has changed - Implements observer_t -.
 
static int index_shared_email_observer (struct NotifyCallback *nc)
 Notification that an Email has changed - Implements observer_t -.
 
void index_shared_data_set_mview (struct IndexSharedData *shared, struct MailboxView *mv)
 Set the MailboxView for the Index and friends.
 
void index_shared_data_set_email (struct IndexSharedData *shared, struct Email *e)
 Set the current Email for the Index and friends.
 
bool index_shared_data_is_cur_email (const struct IndexSharedData *shared, const struct Email *e)
 Check whether an email is the currently selected Email.
 
void index_shared_data_free (struct MuttWindow *win, void **ptr)
 Free Shared Index Data - Implements MuttWindow::wdata_free() -.
 
struct IndexSharedDataindex_shared_data_new (void)
 Create new Index Data.
 

Detailed Description

Data shared between Index, Pager and Sidebar.

Authors
  • Richard Russon
  • Dennis Schön

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

Function Documentation

◆ index_shared_data_set_mview()

void index_shared_data_set_mview ( struct IndexSharedData shared,
struct MailboxView mv 
)

Set the MailboxView for the Index and friends.

Parameters
sharedShared Index data
mvMailbox View, may be NULL

Definition at line 160 of file shared_data.c.

161{
162 if (!shared)
163 return;
164
166
167 if (shared->mailbox_view != mv)
168 {
169 if (shared->mailbox_view)
170 {
173 }
174
175 shared->mailbox_view = mv;
176 subtype |= NT_INDEX_MVIEW;
177
178 if (mv)
180 }
181
182 struct Mailbox *m = mview_mailbox(mv);
183 if (shared->mailbox != m)
184 {
185 if (shared->mailbox)
187
188 shared->mailbox = m;
189 shared->email = NULL;
190 shared->email_seq = 0;
191 subtype |= NT_INDEX_MAILBOX | NT_INDEX_EMAIL;
192
193 if (m)
195 }
196
197 struct Account *a = m ? m->account : NULL;
198 if (shared->account != a)
199 {
200 if (shared->account)
202
203 shared->account = a;
204 subtype |= NT_INDEX_ACCOUNT;
205
206 if (a)
208 }
209
210 struct ConfigSubset *sub = NeoMutt->sub;
211#if 0
212 if (m)
213 sub = m->sub;
214 else if (a)
215 sub = a->sub;
216#endif
217 if (shared->sub != sub)
218 {
219 shared->sub = sub;
220 subtype |= NT_INDEX_SUBSET;
221 }
222
223 if (subtype != NT_INDEX_NO_FLAGS)
224 {
225 mutt_debug(LL_NOTIFY, "NT_INDEX: %p\n", (void *) shared);
226 notify_send(shared->notify, NT_INDEX, subtype, shared);
227 }
228}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int index_shared_mview_observer(struct NotifyCallback *nc)
Notification that the MailboxView has changed - Implements observer_t -.
Definition: shared_data.c:43
static int index_shared_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t -.
Definition: shared_data.c:68
static int index_shared_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: shared_data.c:93
#define NT_INDEX_MAILBOX
Mailbox has changed.
Definition: lib.h:64
uint8_t NotifyIndex
Flags, e.g. NT_INDEX_ACCOUNT.
Definition: lib.h:57
#define NT_INDEX_SUBSET
Config Subset has changed.
Definition: lib.h:61
#define NT_INDEX_MVIEW
MailboxView has changed.
Definition: lib.h:63
#define NT_INDEX_ACCOUNT
Account has changed.
Definition: lib.h:62
#define NT_INDEX_EMAIL
Email has changed.
Definition: lib.h:65
#define NT_INDEX_NO_FLAGS
No flags are set.
Definition: lib.h:58
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
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
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
struct Mailbox * mview_mailbox(struct MailboxView *mv)
Wrapper to get the mailbox in a MailboxView, or NULL.
Definition: mview.c:450
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
@ NT_INDEX
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:48
@ NT_MVIEW
MailboxView has changed, NotifyMview, EventMview.
Definition: notify_type.h:50
A group of associated Mailboxes.
Definition: account.h:36
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:39
A set of inherited config items.
Definition: subset.h:47
size_t email_seq
Sequence number of the current email.
Definition: shared_data.h:43
struct Account * account
Current Account.
Definition: shared_data.h:39
struct Email * email
Currently selected Email.
Definition: shared_data.h:42
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:38
struct MailboxView * mailbox_view
Current Mailbox view.
Definition: shared_data.h:40
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
struct Notify * notify
Notifications: NotifyMview, EventMview.
Definition: mview.h:52
A mailbox.
Definition: mailbox.h:79
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:145
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:127
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:83
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_shared_data_set_email()

void index_shared_data_set_email ( struct IndexSharedData shared,
struct Email e 
)

Set the current Email for the Index and friends.

Parameters
sharedShared Index data
eCurrent Email, may be NULL

Definition at line 235 of file shared_data.c.

236{
237 if (!shared)
238 return;
239
240 size_t seq = e ? e->sequence : 0;
241 if ((shared->email != e) || (shared->email_seq != seq))
242 {
243 if (shared->email)
245
246 shared->email = e;
247 shared->email_seq = seq;
248
249 if (e)
251
252 mutt_debug(LL_NOTIFY, "NT_INDEX_EMAIL: %p\n", (void *) shared->email);
253 notify_send(shared->notify, NT_INDEX, NT_INDEX_EMAIL, shared);
254 }
255}
static int index_shared_email_observer(struct NotifyCallback *nc)
Notification that an Email has changed - Implements observer_t -.
Definition: shared_data.c:118
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:73
size_t sequence
Sequence number assigned on creation.
Definition: email.h:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_shared_data_is_cur_email()

bool index_shared_data_is_cur_email ( const struct IndexSharedData shared,
const struct Email e 
)

Check whether an email is the currently selected Email.

Parameters
sharedShared Index data
eEmail to check
Return values
truee is current
falsee is not current

Definition at line 264 of file shared_data.c.

266{
267 if (!shared)
268 return false;
269
270 return shared->email_seq == e->sequence;
271}
+ Here is the caller graph for this function:

◆ index_shared_data_new()

struct IndexSharedData * index_shared_data_new ( void  )

Create new Index Data.

Return values
ptrNew IndexSharedData

Definition at line 307 of file shared_data.c.

308{
309 struct IndexSharedData *shared = MUTT_MEM_CALLOC(1, struct IndexSharedData);
310
311 shared->notify = notify_new();
312 shared->sub = NeoMutt->sub;
313 shared->search_state = search_state_new();
314
315 mutt_debug(LL_NOTIFY, "NT_INDEX_ADD: %p\n", (void *) shared);
316 notify_send(shared->notify, NT_INDEX, NT_INDEX_ADD, shared);
317
318 return shared;
319}
#define NT_INDEX_ADD
New Index Shared Data has been created.
Definition: lib.h:59
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
struct SearchState * search_state_new(void)
Create a new SearchState.
Definition: search_state.c:39
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
struct SearchState * search_state
State of the current search.
Definition: shared_data.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function: