1 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
2 /* Balsa E-Mail Client
3  * Copyright (C) 1997-2013 Stuart Parmenter and others,
4  *                         See the file AUTHORS for a list.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21 
22 #ifndef __BALSA_MAILBOX_NODE_H__
23 #define __BALSA_MAILBOX_NODE_H__
24 
25 #include <gtk/gtk.h>
26 #include "libbalsa.h"
27 
28 #define BALSA_TYPE_MAILBOX_NODE          (balsa_mailbox_node_get_type ())
29 #define BALSA_MAILBOX_NODE(obj) \
30     G_TYPE_CHECK_INSTANCE_CAST(obj, BALSA_TYPE_MAILBOX_NODE, \
31                                 BalsaMailboxNode)
32 #define BALSA_MAILBOX_NODE_CLASS(klass) \
33     G_TYPE_CHECK_CLASS_CAST(klass, BALSA_TYPE_MAILBOX_NODE, \
34                              BalsaMailboxNodeClass)
35 #define BALSA_IS_MAILBOX_NODE(obj) \
36     G_TYPE_CHECK_INSTANCE_TYPE(obj, BALSA_TYPE_MAILBOX_NODE)
37 #define BALSA_IS_MAILBOX_NODE_CLASS(klass) \
38     G_TYPE_CHECK_CLASS_TYPE(klass, BALSA_TYPE_MAILBOX_NODE)
39 
40 typedef struct _BalsaMailboxNode BalsaMailboxNode;
41 typedef struct _BalsaMailboxNodeClass BalsaMailboxNodeClass;
42 
43 /* BalsaMailboxNodeStyle
44  * used to store the style of mailbox entry in the mailbox tree.
45  * Currently only MBNODE_STYLE_NEW_MAIL is really used, but
46  * the others may be used later for more efficient style handling.
47  *
48  * MBNODE_STYLE_NEW_MAIL: Whether the full mailbox icon is displayed
49  *      (also when font is bolded)
50  * MBNODE_STYLE_UNREAD_MESSAGES: Whether the number of unread messages
51  *      is being displayed in the maibox list
52  * MBNODE_STYLE_TOTAL_MESSAGES: Whether the number of total messages
53  *      is being displayed in the mailbox list
54  *
55  * */
56 typedef enum {
57     MBNODE_STYLE_NEW_MAIL = 1 << 1,
58     MBNODE_STYLE_UNREAD_MESSAGES = 1 << 2,
59     MBNODE_STYLE_TOTAL_MESSAGES = 1 << 3,
60     MBNODE_STYLE_UNREAD_CHILD = 1 << 4
61 } BalsaMailboxNodeStyle;
62 
63 struct _BalsaMailboxNode {
64     GObject object;
65     BalsaMailboxNode *parent; /* NULL for root-level folders & mailboxes */
66     LibBalsaMailbox *mailbox; /* != NULL for leaves only */
67     gchar *name;       /* used for folders, i.e. when mailbox == NULL */
68     time_t last_use;   /* for closing least recently used mailboxes */
69     BalsaMailboxNodeStyle style;
70     /* folder data */
71     gchar* config_prefix;
72     gchar* dir;
73     LibBalsaServer * server; /* Used only by remote; is referenced */
74     char delim; /* IMAP delimiter so that we do not need to check it
75 		 * too often. */
76 
77     unsigned subscribed:1;     /* Used only by remote */
78     unsigned list_inbox:1;     /* Used only by remote */
79     unsigned scanned:1;        /* IMAP flag */
80 };
81 
82 struct _BalsaMailboxNodeClass {
83     GObjectClass parent_class;
84     void (*save_config) (BalsaMailboxNode * mn, const gchar * prefix);
85     void (*load_config) (BalsaMailboxNode * mn, const gchar * prefix);
86     GtkWidget* (*show_prop_dialog) (BalsaMailboxNode * mn);
87     void (*append_subtree) (BalsaMailboxNode * mn);
88 };
89 
90 GType balsa_mailbox_node_get_type(void);
91 
92 BalsaMailboxNode *balsa_mailbox_node_new(void);
93 BalsaMailboxNode *balsa_mailbox_node_new_from_mailbox(LibBalsaMailbox *m);
94 BalsaMailboxNode *balsa_mailbox_node_new_from_dir(const gchar* dir);
95 BalsaMailboxNode *balsa_mailbox_node_new_imap(LibBalsaServer* s, const char*p);
96 BalsaMailboxNode *balsa_mailbox_node_new_imap_folder(LibBalsaServer* s,
97 						     const char*p);
98 BalsaMailboxNode *balsa_mailbox_node_new_from_config(const gchar* prefix);
99 
100 GtkWidget *balsa_mailbox_node_get_context_menu(BalsaMailboxNode * mbnode);
101 void balsa_mailbox_node_show_prop_dialog(BalsaMailboxNode * mbnode);
102 void balsa_mailbox_node_append_subtree(BalsaMailboxNode * mbnode);
103 void balsa_mailbox_node_load_config(BalsaMailboxNode* mn, const gchar* prefix);
104 void balsa_mailbox_node_save_config(BalsaMailboxNode* mn, const gchar* prefix);
105 void balsa_mailbox_node_show_prop_dialog_cb(GtkWidget * widget, gpointer data);
106 
107 /* applicable only to local mailboxes (mailbox collections) */
108 void balsa_mailbox_local_append(LibBalsaMailbox* mbx);
109 /* applicable only to folders (mailbox collections) */
110 void balsa_mailbox_node_rescan(BalsaMailboxNode* mn);
111 void balsa_mailbox_node_clear_children_cache(BalsaMailboxNode * mbnode);
112 
113 /* applicable to any mailbox node */
114 void balsa_mailbox_node_scan_children(BalsaMailboxNode * mbnode);
115 
116 #endif
117