1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

mail: use a private common struct mail_s instead of info.mail

This commit is contained in:
Phil Sutter 2009-10-25 01:43:08 +02:00
parent ac99833646
commit 35ecbb3330
4 changed files with 69 additions and 52 deletions

View File

@ -4560,14 +4560,14 @@ char load_config_file(const char *f)
TEMPLATE_CONF(9)
CONF("imap") {
if (value) {
info.mail = parse_mail_args(IMAP_TYPE, value);
parse_global_imap_mail_args(value);
} else {
CONF_ERR;
}
}
CONF("pop3") {
if (value) {
info.mail = parse_mail_args(POP3_TYPE, value);
parse_global_pop3_mail_args(value);
} else {
CONF_ERR;
}

View File

@ -243,8 +243,6 @@ struct information {
float loadavg[3];
struct mail_s *mail;
int mail_running;
#ifdef XMMS2
struct xmms2_s xmms2;
#endif

View File

@ -60,6 +60,9 @@
char *current_mail_spool;
static struct mail_s *global_mail;
static int global_mail_use = 0;
void update_mail_count(struct local_mail_s *mail)
{
struct stat st;
@ -435,30 +438,69 @@ struct mail_s *parse_mail_args(char type, const char *arg)
void parse_imap_mail_args(struct text_object *obj, const char *arg)
{
static int rep = 0;
if (!arg) {
obj->char_b = 1;
if (!global_mail && !rep) {
// something is wrong, warn once then stop
NORM_ERR("There's a problem with your mail settings. "
"Check that the global mail settings are properly defined"
" (line %li).", obj->line);
rep = 1;
return;
}
obj->data.mail = global_mail;
global_mail_use++;
return;
}
// proccss
obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
obj->char_b = 0;
}
void parse_pop3_mail_args(struct text_object *obj, const char *arg)
{
static int rep = 0;
if (!arg) {
obj->char_b = 1;
if (!global_mail && !rep) {
// something is wrong, warn once then stop
NORM_ERR("There's a problem with your mail settings. "
"Check that the global mail settings are properly defined"
" (line %li).", obj->line);
rep = 1;
return;
}
obj->data.mail = global_mail;
global_mail_use++;
return;
}
// proccss
obj->data.mail = parse_mail_args(POP3_TYPE, arg);
obj->char_b = 0;
}
void parse_global_imap_mail_args(const char *value)
{
global_mail = parse_mail_args(IMAP_TYPE, value);
}
void parse_global_pop3_mail_args(const char *value)
{
global_mail = parse_mail_args(POP3_TYPE, value);
}
void free_mail_obj(struct text_object *obj)
{
if (!obj->char_b) {
if (!obj->data.mail)
return;
if (obj->data.mail == global_mail) {
if (--global_mail_use == 0) {
free(global_mail);
global_mail = 0;
}
} else {
free(obj->data.mail);
obj->data.mail = 0;
}
}
@ -523,28 +565,15 @@ void imap_unseen_command(struct mail_s *mail, unsigned long old_unseen, unsigned
}
}
static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
static void ensure_mail_thread(struct text_object *obj,
void *thread(void *), const char *text)
{
if (obj->char_b && info.mail) {
// this means we use info
if (!info.mail->p_timed_thread) {
info.mail->p_timed_thread =
timed_thread_create(thread,
(void *) info.mail, info.mail->interval * 1000000);
if (!info.mail->p_timed_thread) {
NORM_ERR("Error creating %s timed thread", text);
}
timed_thread_register(info.mail->p_timed_thread,
&info.mail->p_timed_thread);
if (timed_thread_run(info.mail->p_timed_thread)) {
NORM_ERR("Error running %s timed thread", text);
}
}
return info.mail;
} else if (obj->data.mail) {
// this means we use obj
if (!obj->data.mail->p_timed_thread) {
if (!obj->data.mail)
return;
if (obj->data.mail->p_timed_thread)
return;
obj->data.mail->p_timed_thread =
timed_thread_create(thread,
(void *) obj->data.mail,
@ -557,16 +586,6 @@ static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
if (timed_thread_run(obj->data.mail->p_timed_thread)) {
NORM_ERR("Error running %s timed thread", text);
}
}
return obj->data.mail;
} else if (!obj->a) {
// something is wrong, warn once then stop
NORM_ERR("There's a problem with your mail settings. "
"Check that the global mail settings are properly defined"
" (line %li).", obj->line);
obj->a++;
}
return NULL;
}
static void *imap_thread(void *arg)

View File

@ -71,8 +71,8 @@ PRINT_MAILS_PROTO_GENERATOR(unreplied_)
PRINT_MAILS_PROTO_GENERATOR(draft_)
PRINT_MAILS_PROTO_GENERATOR(trashed_)
/* FIXME: this is here for the config leftovers only */
struct mail_s *parse_mail_args(char, const char *);
void parse_global_imap_mail_args(const char *);
void parse_global_pop3_mail_args(const char *);
void parse_imap_mail_args(struct text_object *, const char *);
void parse_pop3_mail_args(struct text_object *, const char *);