|
From: CORE C. L. <cor...@li...> - 2000-11-23 09:32:14
|
Core CVS committal
Author : rbdpngn
Project : core
Module : src
Modified Files:
account.c account.h callbacks.c callbacks.h menus.c message.c
message.h panes.c util.c
Log Message:
Some basic framework for checking for new messages, and listing the total number of messages and total number of new messages.
===================================================================
RCS file: /cvsroot/corem/core/src/account.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- account.c 2000/11/23 02:23:03 1.10
+++ account.c 2000/11/23 09:32:12 1.11
@@ -22,9 +22,10 @@
ret->address = NULL;
ret->server = NULL;
ret->path = NULL;
- ret->fp = NULL;
- ret->messages = 0;
- ret->new_messages = 0;
+ ret->fp = NULL;
+ ret->messages = 0;
+ ret->new_messages = 0;
+ ret->last_access = 0;
return ret;
}
@@ -54,6 +55,24 @@
return TRUE;
}
+int account_set_last_access(Account * ac, time_t time)
+{
+ if (!ac)
+ return FALSE;
+
+ ac->last_access = time;
+
+ return TRUE;
+}
+
+time_t account_get_last_access(Account * ac)
+{
+ if (!ac)
+ return 0;
+
+ return (ac->last_access);
+}
+
int account_set_name(Account * ac, char *name)
{
if (!name || !ac)
@@ -103,9 +122,9 @@
if (!ac)
return FALSE;
- ac->messages = num;
+ ac->messages = num;
- return TRUE;
+ return TRUE;
}
int account_get_num_new_messages(Account * ac)
@@ -121,9 +140,9 @@
if (!ac)
return FALSE;
- ac->new_messages = num;
+ ac->new_messages = num;
- return TRUE;
+ return TRUE;
}
char *account_get_name(Account * ac)
===================================================================
RCS file: /cvsroot/corem/core/src/account.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- account.h 2000/11/23 02:23:03 1.8
+++ account.h 2000/11/23 09:32:12 1.9
@@ -10,9 +10,10 @@
/* Folder specific info */
char *name; /* Name of the mailbox. */
AccountType type; /* Mailbox type. */
- char *path; /* Path to the local mailbox. */
- int messages; /* Number of messages in mailbox */
- int new_messages; /* Number of new messages in mailbox */
+ char *path; /* Path to the local mailbox. */
+ int messages; /* Number of messages in mailbox */
+ int new_messages; /* Number of new messages in mailbox */
+ time_t last_access; /* Time the mailbox was last checked */
FILE *fp; /* Pointer to the local mailbox file */
/* User specific info */
@@ -29,6 +30,11 @@
Account *new_account(void);
/* Free an account created with new_account() */
int destroy_account(Account * ac);
+
+/* Set the time in seconds that the mailbox was last checked for updates */
+int account_set_last_access(Account * ac, time_t time);
+/* Return the last time the mailbox was last checked for updates */
+time_t account_get_last_access(Account * ac);
/* Set the address of account ac to the string address */
int account_set_address(Account * ac, char *address);
===================================================================
RCS file: /cvsroot/corem/core/src/callbacks.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- callbacks.c 2000/11/23 03:28:13 1.25
+++ callbacks.c 2000/11/23 09:32:12 1.26
@@ -2,15 +2,18 @@
#include "core.h"
#include "callbacks.h"
#include "panes.h"
+#include <signal.h>
-extern Account *current_mbox;
+#define TIMEOUT 30
+
+Account *current_mbox;
extern GtkWidget *mail_ctree;
extern GtkWidget *main_win;
extern ConfigData config;
extern gchar *title;
extern gchar *theme;
-GtkWidget *ctree;
+extern GtkWidget *folder_ctree;
GtkWidget *folder_name, *full_name, *email_address, *type, *username,
*password, *server, *path;
GtkWidget *accounts_win_new;
@@ -342,6 +345,7 @@
GTK_CTREE_NODE
(node));
+ gtk_clist_freeze(GTK_CLIST(mail_ctree));
while (1) {
GtkCTreeNode *top, *item;
char *temp;
@@ -443,18 +447,25 @@
if (config.ml_read == 1) {
found = find_header(head, "Status:");
- if (found) {
+ if (found)
text[col] = header_get_value(found);
- if (strchr(text[col], 'O')) {
- g_free(text[col]);
- colormap = gtk_widget_get_colormap(mail_ctree);
- pixmap = gdk_pixmap_colormap_create_from_xpm(NULL, colormap, &bitmap, NULL, g_strconcat(theme, "read.xpm", NULL));
- gtk_ctree_node_set_pixmap(GTK_CTREE(mail_ctree), item, col, pixmap, bitmap);
- gdk_bitmap_unref(bitmap);
- gdk_pixmap_unref(pixmap);
- }
+
+ if (!found || strchr(text[col], 'N')) {
+ g_free(text[col]);
+ colormap =
+ gtk_widget_get_colormap(mail_ctree);
+ pixmap =
+ gdk_pixmap_colormap_create_from_xpm
+ (NULL, colormap, &bitmap, NULL,
+ g_strconcat(theme, "read.xpm", NULL));
+ gtk_ctree_node_set_pixmap(GTK_CTREE
+ (mail_ctree),
+ item, col,
+ pixmap, bitmap);
+ gdk_bitmap_unref(bitmap);
+ gdk_pixmap_unref(pixmap);
}
- }
+ }
temp = header_get_value(find_header(head, "Message-Id:"));
if (temp)
@@ -464,7 +475,9 @@
(GtkDestroyNotify)
free);
destroy_message(message);
- }
+ }
+
+ gtk_clist_thaw(GTK_CLIST(mail_ctree));
current_mbox = mbox;
account_reset_file(mbox);
@@ -515,4 +528,38 @@
node = NULL;
col = 0;
data = NULL;
+}
+
+/* Function for checking folders for new mail */
+void check_for_new_mail(int signum)
+{
+ int i;
+ char *temp;
+ Account *mbox;
+ GtkCTreeNode *node;
+
+ for (i = 1, node = gtk_ctree_node_nth(GTK_CTREE(folder_ctree), i); node;
+ i++, node = gtk_ctree_node_nth(GTK_CTREE(folder_ctree), i)) {
+ mbox = gtk_ctree_node_get_row_data(GTK_CTREE(folder_ctree), node);
+ if (account_get_last_access(mbox) <
+ last_modify(account_get_path(mbox))) {
+ account_set_num_messages(mbox, num_messages(mbox));
+ account_set_num_new_messages(mbox,
+ num_new_messages
+ (mbox));
+ }
+ asprintf(&temp, "%d", account_get_num_messages(mbox));
+ gtk_ctree_node_set_text(GTK_CTREE(folder_ctree), node, 1, temp);
+ free(temp);
+
+ asprintf(&temp, "%d", account_get_num_new_messages(mbox));
+ gtk_ctree_node_set_text(GTK_CTREE(folder_ctree), node, 2, temp);
+ free(temp);
+ }
+
+ signal(SIGALRM, check_for_new_mail);
+ alarm(TIMEOUT);
+
+ return;
+ signum = 0;
}
===================================================================
RCS file: /cvsroot/corem/core/src/callbacks.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- callbacks.h 2000/11/23 02:23:03 1.11
+++ callbacks.h 2000/11/23 09:32:12 1.12
@@ -64,3 +64,6 @@
/* Function for switching the where *theme is the directory name of the theme */
void switch_theme(gchar * theme);
+
+/* Function for checking for new messages. */
+void check_for_new_mail(int signum);
===================================================================
RCS file: /cvsroot/corem/core/src/menus.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- menus.c 2000/11/23 02:23:03 1.9
+++ menus.c 2000/11/23 09:32:12 1.10
@@ -449,8 +449,8 @@
GTK_SIGNAL_FUNC
(switch_theme),
(gpointer)
- g_strdup(dent->
- d_name));
+ g_strdup
+ (dent->d_name));
gtk_menu_append(GTK_MENU(menu), menu_item);
g_free(temp);
}
===================================================================
RCS file: /cvsroot/corem/core/src/message.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -3 -r1.1.1.1 -r1.2
--- message.c 2000/11/14 19:23:24 1.1.1.1
+++ message.c 2000/11/23 09:32:12 1.2
@@ -264,4 +264,50 @@
destroy_message(m);
}
+ return NULL;
+}
+
+int num_messages(Account * mbox)
+{
+ int ret = 0;
+ Message *m;
+
+ if (!mbox)
+ return 0;
+
+ if (mbox->fp)
+ rewind(mbox->fp);
+
+ while ((m = message_get_next(mbox)) != NULL) {
+ destroy_message(m);
+ ret++;
+ }
+
+ return ret;
+}
+
+int num_new_messages(Account * mbox)
+{
+ int ret = 0;
+ char *temp;
+ Message *m;
+
+ if (!mbox)
+ return 0;
+
+ if (mbox->fp)
+ rewind(mbox->fp);
+
+ while ((m = message_get_next(mbox)) != NULL) {
+ temp =
+ header_get_value(find_header
+ (message_get_headers(m), "Status:"));
+ if (temp) {
+ free(temp);
+ ret++;
+ }
+ destroy_message(m);
+ }
+
+ return ret;
}
===================================================================
RCS file: /cvsroot/corem/core/src/message.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- message.h 2000/11/23 02:23:03 1.2
+++ message.h 2000/11/23 09:32:12 1.3
@@ -32,3 +32,8 @@
Message *message_get_n(Account * mbox, int num);
Message *message_find_id(Account * mbox, char *id);
+
+/* Return the number of new messages in the mailbox mbox */
+int num_new_messages(Account * mbox);
+/* Return the number of messages in the mailbox mbox */
+int num_messages(Account * mbox);
===================================================================
RCS file: /cvsroot/corem/core/src/panes.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- panes.c 2000/11/23 02:23:03 1.11
+++ panes.c 2000/11/23 09:32:12 1.12
@@ -4,12 +4,11 @@
#include "callbacks.h"
ConfigData config;
-Account *current_mbox = NULL;
GtkWidget *mail_ctree;
GtkWidget *folder_ctree;
+GtkWidget *ctree;
extern GtkWidget *main_win;
extern GtkWidget *hpane;
-extern GtkWidget *ctree;
extern gchar *theme;
extern gchar *title;
@@ -113,6 +112,7 @@
gtk_ctree_set_line_style(GTK_CTREE(mail_ctree),
GTK_CTREE_LINES_TABBED);
+ check_for_new_mail(0);
return (scroll);
}
@@ -208,7 +208,7 @@
if (config.ml_date == 1) {
gtk_clist_set_column_width(GTK_CLIST(mail_ctree), idate,
- 120);
+ 150);
}
if (config.ml_server == 1) {
@@ -233,13 +233,14 @@
gtk_clist_set_column_widget(GTK_CLIST(mail_ctree), iread,
read);
gtk_clist_set_column_width(GTK_CLIST(mail_ctree), iread,
- 38);
+ 8);
gtk_clist_set_column_auto_resize(GTK_CLIST(mail_ctree),
iread, FALSE);
gdk_bitmap_unref(bitmap);
gdk_pixmap_unref(pixmap);
}
+
if (config.ml_attachment == 1) {
colormap = gtk_widget_get_colormap(mail_ctree);
pixmap =
@@ -393,7 +394,7 @@
gtk_container_add(GTK_CONTAINER(hbutton_box), button_close);
/* Show all widgets in the accounts window */
- gtk_widget_show_all(accounts_win);
+ gtk_widget_show_all(accounts_win);
}
===================================================================
RCS file: /cvsroot/corem/core/src/util.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- util.c 2000/11/14 22:07:28 1.2
+++ util.c 2000/11/23 09:32:12 1.3
@@ -1,4 +1,8 @@
#include "util.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <time.h>
#define BUFSIZE 400
@@ -115,4 +119,17 @@
line++;
return token;
+}
+
+time_t last_modify(char *path)
+{
+ struct stat dstat;
+
+ if (!path)
+ return 0;
+
+ if (stat(path, &dstat) < 0)
+ return 0;
+
+ return dstat.st_mtime;
}
|