From c3bfb1288045a6b09670b2b0d06c1232860787bc Mon Sep 17 00:00:00 2001 From: Christoph Hohmann Date: Fri, 4 Jul 2003 11:59:46 +0000 Subject: [PATCH] 0.9.0claws78 * sync with 0.9.2cvs1 see ChangeLog 2003-06-10 --- ChangeLog.claws | 5 +++ configure.ac | 2 +- src/folder.c | 107 ++++++++++++++++++++++++++++++++++++++++++++ src/folder.h | 2 + src/main.c | 115 +++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 213 insertions(+), 18 deletions(-) diff --git a/ChangeLog.claws b/ChangeLog.claws index 05c2fb733..236fc9cae 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,8 @@ +2003-07-04 [christoph] 0.9.0claws78 + + * sync with 0.9.2cvs1 + see ChangeLog 2003-06-10 + 2003-07-04 [paul] 0.9.0claws77 * sync with 0.9.3 release diff --git a/configure.ac b/configure.ac index f03df2b21..35c52d813 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=9 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws77 +EXTRA_VERSION=claws78 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl set $target diff --git a/src/folder.c b/src/folder.c index 9e65240a1..88ec0de1f 100644 --- a/src/folder.c +++ b/src/folder.c @@ -515,6 +515,113 @@ static void folder_count_total_msgs_func(FolderItem *item, gpointer data) count->total_msgs += item->total_msgs; } +struct TotalMsgStatus +{ + guint new; + guint unread; + guint total; + GString *str; +}; + +static gboolean folder_get_status_full_all_func(GNode *node, gpointer data) +{ + FolderItem *item; + struct TotalMsgStatus *status = (struct TotalMsgStatus *)data; + gchar *id; + + g_return_val_if_fail(node->data != NULL, FALSE); + + item = FOLDER_ITEM(node->data); + + if (!item->path) return FALSE; + + status->new += item->new_msgs; + status->unread += item->unread_msgs; + status->total += item->total_msgs; + + if (status->str) { + id = folder_item_get_identifier(item); + g_string_sprintfa(status->str, "%5d %5d %5d %s\n", + item->new_msgs, item->unread_msgs, + item->total_msgs, id); + g_free(id); + } + + return FALSE; + } + +static void folder_get_status_full_all(GString *str, guint *new, guint *unread, + guint *total) +{ + GList *list; + Folder *folder; + struct TotalMsgStatus status; + + status.new = status.unread = status.total = 0; + status.str = str; + + debug_print("Counting total number of messages...\n"); + + for (list = folder_list; list != NULL; list = list->next) { + folder = FOLDER(list->data); + if (folder->node) + g_node_traverse(folder->node, G_PRE_ORDER, + G_TRAVERSE_ALL, -1, + folder_get_status_full_all_func, + &status); + } + + *new = status.new; + *unread = status.unread; + *total = status.total; +} + +gchar *folder_get_status(GPtrArray *folders, gboolean full) +{ + guint new, unread, total; + GString *str; + gint i; + gchar *ret; + + new = unread = total = 0; + + str = g_string_new(NULL); + + if (folders) { + for (i = 0; i < folders->len; i++) { + FolderItem *item; + + item = g_ptr_array_index(folders, i); + new += item->new_msgs; + unread += item->unread_msgs; + total += item->total_msgs; + + if (full) { + gchar *id; + + id = folder_item_get_identifier(item); + g_string_sprintfa(str, "%5d %5d %5d %s\n", + item->new_msgs, item->unread_msgs, + item->total_msgs, id); + g_free(id); + } + } + } else { + folder_get_status_full_all(full ? str : NULL, + &new, &unread, &total); + } + + if (full) + g_string_sprintfa(str, "%5d %5d %5d\n", new, unread, total); + else + g_string_sprintfa(str, "%d %d %d\n", new, unread, total); + + ret = str->str; + g_string_free(str, FALSE); + + return ret; +} + void folder_count_total_msgs(guint *new_msgs, guint *unread_msgs, guint *unreadmarked_msgs, guint *total_msgs) { struct TotalMsgCount count; diff --git a/src/folder.h b/src/folder.h index 9f9a44baf..2ca372dcd 100644 --- a/src/folder.h +++ b/src/folder.h @@ -375,6 +375,8 @@ void folder_count_total_msgs (guint *new_msgs, guint *unread_msgs, guint *unreadmarked_msgs, guint *total_msgs); +gchar *folder_get_status (GPtrArray *folders, + gboolean full); Folder *folder_find_from_path (const gchar *path); Folder *folder_find_from_name (const gchar *name, diff --git a/src/main.c b/src/main.c index 6ce4bde09..178c6a30f 100644 --- a/src/main.c +++ b/src/main.c @@ -104,6 +104,9 @@ static struct RemoteCmd { const gchar *compose_mailto; GPtrArray *attach_files; gboolean status; + gboolean status_full; + GPtrArray *status_folders; + GPtrArray *status_full_folders; gboolean send; gboolean crash; int online_mode; @@ -188,7 +191,7 @@ int main(int argc, char *argv[]) lock_socket = prohibit_duplicate_launch(); if (lock_socket < 0) return 0; - if (cmd.status) { + if (cmd.status || cmd.status_full) { puts("0 Sylpheed not running."); lock_socket_remove(); return 0; @@ -345,6 +348,14 @@ int main(int argc, char *argv[]) } if (cmd.send) send_queue(); + if (cmd.status_folders) { + g_ptr_array_free(cmd.status_folders, TRUE); + cmd.status_folders = NULL; + } + if (cmd.status_full_folders) { + g_ptr_array_free(cmd.status_full_folders, TRUE); + cmd.status_full_folders = NULL; + } if (cmd.online_mode == ONLINE_MODE_OFFLINE) main_window_toggle_work_offline(mainwin, TRUE); @@ -415,8 +426,31 @@ static void parse_cmd_opt(int argc, char *argv[]) } else if (!strncmp(argv[i], "--version", 9)) { puts("Sylpheed version " VERSION); exit(0); - } else if (!strncmp(argv[i], "--status", 8)) { - cmd.status = TRUE; + } else if (!strncmp(argv[i], "--status-full", 13)) { + const gchar *p = argv[i + 1]; + + cmd.status_full = TRUE; + while (p && *p != '\0' && *p != '-') { + if (!cmd.status_full_folders) + cmd.status_full_folders = + g_ptr_array_new(); + g_ptr_array_add(cmd.status_full_folders, + g_strdup(p)); + i++; + p = argv[i + 1]; + } + } else if (!strncmp(argv[i], "--status", 8)) { + const gchar *p = argv[i + 1]; + + cmd.status = TRUE; + while (p && *p != '\0' && *p != '-') { + if (!cmd.status_folders) + cmd.status_folders = g_ptr_array_new(); + g_ptr_array_add(cmd.status_folders, + g_strdup(p)); + i++; + p = argv[i + 1]; + } } else if (!strncmp(argv[i], "--online", 8)) { cmd.online_mode = ONLINE_MODE_ONLINE; } else if (!strncmp(argv[i], "--offline", 9)) { @@ -432,7 +466,9 @@ static void parse_cmd_opt(int argc, char *argv[]) puts(_(" --receive receive new messages")); puts(_(" --receive-all receive new messages of all accounts")); puts(_(" --send send all queued messages")); - puts(_(" --status show the total number of messages")); + puts(_(" --status [folder]... show the total number of messages")); + puts(_(" --status-full [folder]...\n" + " show the status of each folder")); puts(_(" --online switch to online mode")); puts(_(" --offline switch to offline mode")); puts(_(" --debug debug mode")); @@ -698,7 +734,8 @@ static gint prohibit_duplicate_launch(void) gchar *compose_str; if (cmd.compose_mailto) - compose_str = g_strdup_printf("compose %s\n", cmd.compose_mailto); + compose_str = g_strdup_printf + ("compose %s\n", cmd.compose_mailto); else compose_str = g_strdup("compose\n"); @@ -710,12 +747,29 @@ static gint prohibit_duplicate_launch(void) fd_write(uxsock, "online\n", 6); } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) { fd_write(uxsock, "offline\n", 7); - } else if (cmd.status) { - gchar buf[BUFFSIZE]; - - fd_write_all(uxsock, "status\n", 7); - fd_gets(uxsock, buf, sizeof(buf)); - fputs(buf, stdout); + } else if (cmd.status || cmd.status_full) { + gchar buf[BUFFSIZE]; + gint i; + const gchar *command; + GPtrArray *folders; + gchar *folder; + + command = cmd.status_full ? "status-full\n" : "status\n"; + folders = cmd.status_full ? cmd.status_full_folders : + cmd.status_folders; + + fd_write_all(uxsock, command, strlen(command)); + for (i = 0; folders && i < folders->len; ++i) { + folder = g_ptr_array_index(folders, i); + fd_write_all(uxsock, folder, strlen(folder)); + fd_write_all(uxsock, "\n", 1); + } + fd_write_all(uxsock, ".\n", 2); + for (;;) { + fd_gets(uxsock, buf, sizeof(buf)); + if (!strncmp(buf, ".\n", 2)) break; + fputs(buf, stdout); + } } else fd_write_all(uxsock, "popup\n", 6); @@ -738,6 +792,27 @@ static gint lock_socket_remove(void) return 0; } +static GPtrArray *get_folder_item_list(gint sock) +{ + gchar buf[BUFFSIZE]; + FolderItem *item; + GPtrArray *folders = NULL; + + for (;;) { + fd_gets(sock, buf, sizeof(buf)); + if (!strncmp(buf, ".\n", 2)) break; + strretchomp(buf); + if (!folders) folders = g_ptr_array_new(); + item = folder_find_item_from_identifier(buf); + if (item) + g_ptr_array_add(folders, item); + else + g_warning("no such folder: %s\n", buf); + } + + return folders; +} + static void lock_socket_input_cb(gpointer data, gint source, GdkInputCondition condition) @@ -778,12 +853,18 @@ static void lock_socket_input_cb(gpointer data, main_window_toggle_work_offline(mainwin, FALSE); } else if (!strncmp(buf, "offline", 7)) { main_window_toggle_work_offline(mainwin, TRUE); - } else if (!strncmp(buf, "status", 6)) { - guint new, unread, unreadmarked, total; - - folder_count_total_msgs(&new, &unread, &unreadmarked, &total); - g_snprintf(buf, sizeof(buf), "%d %d %d %d\n", new, unread, unreadmarked, total); - fd_write_all(sock, buf, strlen(buf)); + } else if (!strncmp(buf, "status-full", 11) || + !strncmp(buf, "status", 6)) { + gchar *status; + GPtrArray *folders; + + folders = get_folder_item_list(sock); + status = folder_get_status + (folders, !strncmp(buf, "status-full", 11)); + fd_write_all(sock, status, strlen(status)); + fd_write_all(sock, ".\n", 2); + g_free(status); + if (folders) g_ptr_array_free(folders, TRUE); } fd_close(sock); -- 2.25.1