624b415656f4391c2b9bf61fdc9ec6fee7988872
[modest] / src / modest-tny-store-actions.c
1 /* modest-tny-store-actions.c */
2
3 /* insert (c)/licensing information) */
4
5 #include <tny-msg.h>
6 #include <tny-msg-iface.h>                      
7 #include <tny-msg-header.h>
8 #include <tny-msg-header-iface.h>
9 #include <tny-account-iface.h>  
10 #include <tny-account-store-iface.h>
11 #include <tny-store-account-iface.h>    
12 #include <tny-store-account.h>
13 #include <tny-stream-camel.h>
14 #include <string.h>
15 #include <camel/camel-folder.h>
16 #include <camel/camel.h>
17 #include <camel/camel-folder-summary.h>
18
19
20 #include <glib.h>
21 #include "modest-tny-store-actions.h"
22
23
24 /* 'private'/'protected' functions */
25 static void    modest_tny_store_actions_class_init   (ModestTnyStoreActionsClass *klass);
26 static void    modest_tny_store_actions_init         (ModestTnyStoreActions *obj);
27 static void    modest_tny_store_actions_finalize     (GObject *obj);
28
29 /* list my signals */
30 enum {
31         /* MY_SIGNAL_1, */
32         /* MY_SIGNAL_2, */
33         LAST_SIGNAL
34 };
35
36 typedef struct _ModestTnyStoreActionsPrivate ModestTnyStoreActionsPrivate;
37
38 struct _ModestTnyStoreActionsPrivate {
39         gboolean active;
40 };
41
42 #define MODEST_TNY_STORE_ACTIONS_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
43                                                           MODEST_TYPE_TNY_STORE_ACTIONS, \
44                                                           ModestTnyStoreActionsPrivate))
45 /* globals */
46 static GObjectClass *parent_class = NULL;
47
48 /* uncomment the following if you have defined any signals */
49 /* static guint signals[LAST_SIGNAL] = {0}; */
50
51 void
52 modest_tny_store_actions_update_folders (ModestTnyStoreActions *self,
53                                            TnyStoreAccountIface *storage_account)
54 {
55
56         const TnyListIface* folders;
57         TnyIteratorIface* ifolders;
58         gpointer *cur_folder;
59
60         folders = tny_store_account_iface_get_folders (storage_account, 
61                                                                                                   TNY_STORE_ACCOUNT_FOLDER_TYPE_SUBSCRIBED);
62         
63         ifolders = tny_list_iface_create_iterator (folders);
64         
65         for (cur_folder = tny_iterator_iface_first (ifolders); 
66                               tny_iterator_iface_has_next (ifolders); 
67                           tny_iterator_iface_next (ifolders))
68         {
69                 cur_folder = tny_iterator_iface_current (ifolders);
70                 tny_msg_folder_iface_refresh (cur_folder);
71         }
72         g_object_unref (ifolders);
73 }
74
75
76 GType
77 modest_tny_store_actions_get_type (void)
78 {
79         static GType my_type = 0;
80         if (!my_type) {
81                 static const GTypeInfo my_info = {
82                         sizeof(ModestTnyStoreActionsClass),
83                         NULL,           /* base init */
84                         NULL,           /* base finalize */
85                         (GClassInitFunc) modest_tny_store_actions_class_init,
86                         NULL,           /* class finalize */
87                         NULL,           /* class data */
88                         sizeof(ModestTnyStoreActions),
89                         1,              /* n_preallocs */
90                         (GInstanceInitFunc) modest_tny_store_actions_init,
91                 };
92                 my_type = g_type_register_static (G_TYPE_OBJECT,
93                                                   "ModestTnyStoreActions",
94                                                   &my_info, 0);
95         }
96         return my_type;
97 }
98
99 static void
100 modest_tny_store_actions_class_init (ModestTnyStoreActionsClass *klass)
101 {
102         GObjectClass *gobject_class;
103         gobject_class = (GObjectClass*) klass;
104
105         parent_class            = g_type_class_peek_parent (klass);
106         gobject_class->finalize = modest_tny_store_actions_finalize;
107
108         g_type_class_add_private (gobject_class, sizeof(ModestTnyStoreActionsPrivate));
109         
110         klass->update_folders = modest_tny_store_actions_update_folders;
111         /* signal definitions go here, e.g.: */
112 /*      signals[MY_SIGNAL_1] = */
113 /*              g_signal_new ("my_signal_1",....); */
114 /*      signals[MY_SIGNAL_2] = */
115 /*              g_signal_new ("my_signal_2",....); */
116 /*      etc. */
117 }
118
119 static void
120 modest_tny_store_actions_init (ModestTnyStoreActions *obj)
121 {
122 /* uncomment the following if you init any of the private data */
123 /*      ModestTnyStoreActionsPrivate *priv = MODEST_TNY_STORE_ACTIONS_GET_PRIVATE(obj); */
124
125 /*      initialize this object, eg.: */
126 /*      priv->frobnicate_mode = FALSE; */
127 }
128
129 static void
130 modest_tny_store_actions_finalize (GObject *obj)
131 {
132 /*      free/unref instance resources here */
133 }
134
135 GObject*
136 modest_tny_store_actions_new (void)
137 {
138         return G_OBJECT(g_object_new(MODEST_TYPE_TNY_STORE_ACTIONS, NULL));
139 }