NeoMutt
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

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 159 of file shared_data.c.

160{
161 if (!shared)
162 return;
163
165
166 if (shared->mailbox_view != mv)
167 {
168 if (shared->mailbox_view)
169 {
172 }
173
174 shared->mailbox_view = mv;
175 subtype |= NT_INDEX_MVIEW;
176
177 if (mv)
179 }
180
181 struct Mailbox *m = mview_mailbox(mv);
182 if (shared->mailbox != m)
183 {
184 if (shared->mailbox)
186
187 shared->mailbox = m;
188 shared->email = NULL;
189 shared->email_seq = 0;
190 subtype |= NT_INDEX_MAILBOX | NT_INDEX_EMAIL;
191
192 if (m)
194 }
195
196 struct Account *a = m ? m->account : NULL;
197 if (shared->account != a)
198 {
199 if (shared->account)
201
202 shared->account = a;
203 subtype |= NT_INDEX_ACCOUNT;
204
205 if (a)
207 }
208
209 struct ConfigSubset *sub = NeoMutt->sub;
210#if 0
211 if (m)
212 sub = m->sub;
213 else if (a)
214 sub = a->sub;
215#endif
216 if (shared->sub != sub)
217 {
218 shared->sub = sub;
219 subtype |= NT_INDEX_SUBSET;
220 }
221
222 if (subtype != NT_INDEX_NO_FLAGS)
223 {
224 mutt_debug(LL_NOTIFY, "NT_INDEX: %p\n", (void *) shared);
225 notify_send(shared->notify, NT_INDEX, subtype, shared);
226 }
227}
#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:42
static int index_shared_account_observer(struct NotifyCallback *nc)
Notification that an Account has changed - Implements observer_t -.
Definition: shared_data.c:67
static int index_shared_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: shared_data.c:92
#define NT_INDEX_MAILBOX
Mailbox has changed.
Definition: lib.h:65
uint8_t NotifyIndex
Flags, e.g. NT_INDEX_ACCOUNT.
Definition: lib.h:58
#define NT_INDEX_SUBSET
Config Subset has changed.
Definition: lib.h:62
#define NT_INDEX_MVIEW
MailboxView has changed.
Definition: lib.h:64
#define NT_INDEX_ACCOUNT
Account has changed.
Definition: lib.h:63
#define NT_INDEX_EMAIL
Email has changed.
Definition: lib.h:66
#define NT_INDEX_NO_FLAGS
No flags are set.
Definition: lib.h:59
@ 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:439
@ 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:37
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
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:51
A mailbox.
Definition: mailbox.h:79
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:144
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:128
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:83
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ 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 234 of file shared_data.c.

235{
236 if (!shared)
237 return;
238
239 size_t seq = e ? e->sequence : 0;
240 if ((shared->email != e) || (shared->email_seq != seq))
241 {
242 if (shared->email)
244
245 shared->email = e;
246 shared->email_seq = seq;
247
248 if (e)
250
251 mutt_debug(LL_NOTIFY, "NT_INDEX_EMAIL: %p\n", (void *) shared->email);
252 notify_send(shared->notify, NT_INDEX, NT_INDEX_EMAIL, shared);
253 }
254}
static int index_shared_email_observer(struct NotifyCallback *nc)
Notification that an Email has changed - Implements observer_t -.
Definition: shared_data.c:117
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:71
size_t sequence
Sequence number assigned on creation.
Definition: email.h:65
+ 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 263 of file shared_data.c.

265{
266 if (!shared)
267 return false;
268
269 return shared->email_seq == e->sequence;
270}
+ 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 306 of file shared_data.c.

307{
308 struct IndexSharedData *shared = mutt_mem_calloc(1, sizeof(struct IndexSharedData));
309
310 shared->notify = notify_new();
311 shared->sub = NeoMutt->sub;
312 shared->search_state = search_state_new();
313
314 mutt_debug(LL_NOTIFY, "NT_INDEX_ADD: %p\n", (void *) shared);
315 notify_send(shared->notify, NT_INDEX, NT_INDEX_ADD, shared);
316
317 return shared;
318}
#define NT_INDEX_ADD
New Index Shared Data has been created.
Definition: lib.h:60
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
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:38
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: