25
25
#include "cd-mail-applet-accounts.h"
26
26
#include "cd-mail-applet-etpan.h"
28
typedef void (*cd_mail_fill_account)(CDMailAccount *mailaccount, GKeyFile *pKeyFile, const gchar *mailbox_name);
29
typedef void (*cd_mail_create_account)( GKeyFile *pKeyFile, const gchar *pMailAccountName );
29
31
struct storage_type_def {
33
const gchar * description;
32
34
cd_mail_fill_account pfillFunc;
33
35
cd_mail_create_account pcreateFunc;
36
38
static struct storage_type_def storage_tab[] = {
37
{"pop3", "POP3", cd_mail_retrieve_pop3_params, cd_mail_create_pop3_params },
38
{"imap", "IMAP", cd_mail_retrieve_imap_params, cd_mail_create_imap_params },
39
{"mbox", "MBox", cd_mail_retrieve_mbox_params, cd_mail_create_mbox_params },
40
{"mh", "MH", cd_mail_retrieve_mh_params, cd_mail_create_mh_params },
41
{"maildir", "MailDir", cd_mail_retrieve_maildir_params , cd_mail_create_maildir_params},
42
{"gmail", "GMail", cd_mail_retrieve_gmail_params, cd_mail_create_gmail_params },
39
{"pop3", "POP3", cd_mail_retrieve_pop3_params, cd_mail_create_pop3_params },
40
{"imap", "IMAP", cd_mail_retrieve_imap_params, cd_mail_create_imap_params },
41
{"mbox", "MBox", cd_mail_retrieve_mbox_params, cd_mail_create_mbox_params },
42
{"mh", "MH", cd_mail_retrieve_mh_params, cd_mail_create_mh_params },
43
{"maildir", "MailDir", cd_mail_retrieve_maildir_params , cd_mail_create_maildir_params},
44
{"gmail", "GMail", cd_mail_retrieve_gmail_params, cd_mail_create_gmail_params }
43
45
#if ( __WORDSIZE == 64 )
44
46
/* in 64bit libetpan crashes with RSS, so... avoid it. */
45
47
#warning "Compilation 64bits: avoiding RSS accounts"
47
{"feed", "RSS/Feed", cd_mail_retrieve_feed_params, cd_mail_create_feed_params },
49
,{"feed", "RSS/Feed", cd_mail_retrieve_feed_params, cd_mail_create_feed_params }
51
const int MAIL_NB_STORAGE_TYPES = sizeof(storage_tab) / sizeof(struct storage_type_def);
53
const guint MAIL_NB_STORAGE_TYPES = sizeof(storage_tab) / sizeof(struct storage_type_def);
53
55
static void _get_mail_accounts (GKeyFile *pKeyFile, CairoDockModuleInstance *myApplet)
73
75
//\_______________ On recupere les comptes mail dans le fichier de conf.
74
76
CDMailAccount *pMailAccount;
75
77
gchar *cMailAccountName;
77
79
gsize i, length = 0;
78
gchar **pGroupList = g_key_file_get_groups (pKeyFile, &length);
80
gboolean bFlushConfFileNeeded = FALSE;
81
gchar **pGroupList = g_key_file_get_groups (pKeyFile, &length);
79
82
myData.pMailAccounts = g_ptr_array_sized_new (length - 3);
81
g_print ("recuperons les comptes ...\n");
84
cd_debug ("recuperons les comptes ...\n");
82
85
for (i = 3; i < length; i ++) // Icon, Desklet, Configuration + mail groups
84
87
cMailAccountName = pGroupList[i];
85
g_print ("+ on recupere le compte '%s'\n", cMailAccountName);
88
cd_debug ("+ on recupere le compte '%s'\n", cMailAccountName);
87
/* Get the type of the account */
90
// Get the type of the account.
88
91
if (! g_key_file_has_key (pKeyFile, cMailAccountName, "type", NULL))
91
94
gchar *cMailAccountType = g_key_file_get_string (pKeyFile, cMailAccountName, "type", NULL);
95
if (cMailAccountType == NULL)
93
98
for( j = 0; j < MAIL_NB_STORAGE_TYPES; j++ )
95
100
if (g_strcasecmp(storage_tab[j].name, cMailAccountType) == 0)
101
/* in case the account type is unknown, just ignore... */
105
g_free (cMailAccountType);
107
// in case the account type is unknown, just ignore.
102
108
if( j >= MAIL_NB_STORAGE_TYPES )
104
g_print (" mail type : %d\n", j);
110
cd_debug (" mail type : %d\n", j);
112
// create a new mail account.
106
113
pMailAccount = g_new0 (CDMailAccount, 1);
107
114
g_ptr_array_add (myData.pMailAccounts, pMailAccount);
109
116
pMailAccount->name = g_strdup (cMailAccountName);
117
pMailAccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (cMailAccountName, "timeout mn", 10);
111
118
pMailAccount->pAppletInstance = myApplet;
112
(storage_tab[account_type].pfillFunc)( pMailAccount, pKeyFile, cMailAccountName );
114
/* get a specific mail application to launch for this account, if any */
115
pMailAccount->cMailApp = g_strdup(g_key_file_get_string (pKeyFile, cMailAccountName, "mail application", NULL));
119
pMailAccount->cMailApp = g_key_file_get_string (pKeyFile, cMailAccountName, "mail application", NULL); // a specific mail application to launch for this account, if any.
120
(storage_tab[j].pfillFunc)( pMailAccount, pKeyFile, cMailAccountName );
117
122
g_strfreev (pGroupList);
126
131
path = CD_CONFIG_GET_STRING ("Configuration", "has mail image");
127
132
myConfig.cHasMailUserImage = (path?cairo_dock_generate_file_path (path):NULL);
134
myConfig.bPlaySound = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "play sound", TRUE);
129
135
path = CD_CONFIG_GET_STRING ("Configuration", "new mail sound");
130
136
myConfig.cNewMailUserSound = (path?cairo_dock_generate_file_path (path):NULL);
133
139
myConfig.cMailApplication = CD_CONFIG_GET_STRING ("Configuration", "mail application");
134
myConfig.cMailClass = CD_CONFIG_GET_STRING ("Configuration", "mail class");
135
myConfig.bStealTaskBarIcon = myConfig.cMailApplication && CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "inhibate appli", TRUE);
140
/**myConfig.cMailClass = CD_CONFIG_GET_STRING ("Configuration", "mail class");
141
myConfig.bStealTaskBarIcon = myConfig.cMailApplication && CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "inhibate appli", TRUE);*/
136
142
myConfig.bShowMessageContent = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "show content", TRUE);
137
myConfig.iNbMaxShown = CD_CONFIG_GET_INTEGER_WITH_DEFAULT ("Configuration", "max shown mails", -1);
143
myConfig.iNbMaxShown = MIN (30, CD_CONFIG_GET_INTEGER_WITH_DEFAULT ("Configuration", "max shown mails", 10));
138
144
myConfig.bAlwaysShowMailCount = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Configuration", "show zero mail", TRUE);
139
145
//myConfig.bShowMessageContent = FALSE;
195
201
//\____________ On recupere le type et le nom du nouveau compte.
196
gint iChosenAccountType = gtk_combo_box_get_active(pMailTypesCombo);
197
if( iChosenAccountType < 0 || iChosenAccountType >= MAIL_NB_STORAGE_TYPES )
202
guint iChosenAccountType = gtk_combo_box_get_active(pMailTypesCombo);
203
if( iChosenAccountType >= MAIL_NB_STORAGE_TYPES )
199
205
cd_warning ("while trying get chosen account type (%d) : out of range.", iChosenAccountType);
200
206
cairo_dock_show_temporary_dialog_with_icon (D_("Please choose an account type."), myIcon, myContainer, 3000, "same icon");
323
329
//\____________ On recupere notre widget personnalise (un simple container vide qu'on va remplir avec nos trucs).
324
GtkWidget *pCustomWidgetBox = cairo_dock_get_widget_from_name ("Configuration", "add account");
325
g_return_if_fail (pCustomWidgetBox != NULL);
330
CairoDockGroupKeyWidget *pGroupKeyWidget = cairo_dock_get_group_key_widget_from_name ("Configuration", "add account");
331
g_return_if_fail (pGroupKeyWidget != NULL);
333
GtkWidget *pCustomWidgetBox = gtk_hbox_new (FALSE, 3);
334
gtk_box_pack_end (GTK_BOX (pGroupKeyWidget->pKeyBox),
327
340
//\____________ On cree un combo pour selectionner le type de compte mail qu'on voudrait ajouter
328
341
GtkWidget *pMailTypesCombo = gtk_combo_box_new_text();
329
342
if( pMailTypesCombo )
331
for( int j = 0; j < MAIL_NB_STORAGE_TYPES; j++ )
345
for( j = 0; j < MAIL_NB_STORAGE_TYPES; j++ )
333
347
gtk_combo_box_append_text( GTK_COMBO_BOX (pMailTypesCombo), storage_tab[j].description );
334
348
//gtk_widget_set_tooltip_text (pMenuItem, D_("description du type de compte"));
382
396
//pMailAccount = g_ptr_array_index (myData.pMailAccounts, i); // i-3
383
397
//cMailAccountName = pMailAccount->name;
384
398
cMailAccountName = pGroupList[i];
385
g_print ("- on ajoute le bouton remove au compte '%s'\n", cMailAccountName);
399
cd_debug ("- on ajoute le bouton remove au compte '%s'\n", cMailAccountName);
386
400
if (! g_key_file_has_group (pKeyFile, cMailAccountName))
388
402
cd_warning ("mail : no group for mail account '%s'", cMailAccountName);
392
406
//\____________ On recupere notre widget personnalise (un simple container vide qu'on va remplir avec nos trucs).
393
GtkWidget *pCustomWidgetBox = cairo_dock_get_widget_from_name (cMailAccountName, "remove account");
394
if( pCustomWidgetBox == NULL )
407
CairoDockGroupKeyWidget *pGroupKeyWidget = cairo_dock_get_group_key_widget_from_name (cMailAccountName, "remove account");
408
if( pGroupKeyWidget == NULL )
396
410
cd_warning ("mail : oups, there is a problem in the conf file");