if (prefs_common.auto_sig)
compose_insert_sig(compose);
- gtk_editable_set_position(GTK_EDITABLE(text), 0);
- gtk_stext_set_point(text, 0);
if (quote && prefs_common.linewrap_quote)
compose_wrap_line_all(compose);
+ gtk_editable_set_position(GTK_EDITABLE(text), 0);
+ gtk_stext_set_point(text, 0);
+
gtk_stext_thaw(text);
gtk_widget_grab_focus(compose->text);
compose_attach_info(compose, ainfo, cnttype);
}
+#define GET_CHAR(pos, buf, len) \
+{ \
+ if (text->use_wchar) \
+ len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
+ else { \
+ buf[0] = GTK_STEXT_INDEX(text, (pos)); \
+ len = 1; \
+ } \
+}
+
static void compose_wrap_line(Compose *compose)
{
GtkSText *text = GTK_STEXT(compose->text);
gint line_pos, cur_pos;
gint line_len, cur_len;
-#define GET_STEXT(pos) \
- if (text->use_wchar) \
- ch_len = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
- else { \
- cbuf[0] = GTK_STEXT_INDEX(text, (pos)); \
- ch_len = 1; \
- }
gtk_stext_freeze(text);
/* check to see if the point is on the paragraph mark (empty line). */
cur_pos = gtk_stext_get_point(text);
- GET_STEXT(cur_pos);
+ GET_CHAR(cur_pos, cbuf, ch_len);
if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
if (cur_pos == 0)
goto compose_end; /* on the paragraph mark */
- GET_STEXT(cur_pos - 1);
+ GET_CHAR(cur_pos - 1, cbuf, ch_len);
if (ch_len == 1 && *cbuf == '\n')
goto compose_end; /* on the paragraph mark */
}
/* find paragraph start. */
line_end = quoted = 0;
for (p_start = cur_pos; p_start >= 0; --p_start) {
- GET_STEXT(p_start);
+ GET_CHAR(p_start, cbuf, ch_len);
if (ch_len == 1 && *cbuf == '\n') {
if (quoted)
goto compose_end; /* quoted part */
/* find paragraph end. */
line_end = 0;
for (p_end = cur_pos; p_end < text_len; p_end++) {
- GET_STEXT(p_end);
+ GET_CHAR(p_end, cbuf, ch_len);
if (ch_len == 1 && *cbuf == '\n') {
if (line_end) {
p_end -= 1;
for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
guint space = 0;
- GET_STEXT(cur_pos);
+ GET_CHAR(cur_pos, cbuf, ch_len);
if (ch_len < 0) {
cbuf[0] = '\0';
guint replace = 0;
if (last_ch_len == 1 && !isspace(last_ch)) {
if (cur_pos + 1 < p_end) {
- GET_STEXT(cur_pos + 1);
+ GET_CHAR(cur_pos + 1, cbuf, ch_len);
if (ch_len == 1 && !isspace(*cbuf))
replace = 1;
}
line_len > 0) {
gint tlen = ch_len;
- GET_STEXT(line_pos - 1);
+ GET_CHAR(line_pos - 1, cbuf, ch_len);
if (ch_len == 1 && isspace(*cbuf)) {
gtk_stext_set_point(text, line_pos);
gtk_stext_backward_delete(text, 1);
compose_end:
gtk_stext_thaw(text);
-
-#undef GET_STEXT
}
/* return indent length */
gchar cbuf[MB_LEN_MAX];
for (i = start_pos; i < text_len; i++) {
- if (text->use_wchar)
- ch_len = wctomb
- (cbuf, (wchar_t)GTK_STEXT_INDEX(text, i));
- else {
- cbuf[0] = GTK_STEXT_INDEX(text, i);
- ch_len = 1;
- }
+ GET_CHAR(i, cbuf, ch_len);
if (ch_len > 1)
break;
/* allow space, tab, > or | */
gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
}
ins_len = indent_len;
- }
- else {
+ } else {
gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
ins_len = quote_len;
}
/* Darko: used when I debug wrapping */
void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
{
- int i;
- char ch;
+ gint i;
+ gchar ch;
printf("%d [", pos);
for (i = pos; i < tlen; i++) {
guint line_pos = 0, cur_pos = 0, p_pos = 0;
gint line_len = 0, cur_len = 0;
gint ch_len;
- gint is_new_line = 1, do_delete = 0;
+ gboolean is_new_line = TRUE, do_delete = FALSE;
guint qlen = 0, i_len = 0;
guint linewrap_quote = prefs_common.linewrap_quote;
guint linewrap_len = prefs_common.linewrap_len;
if (linewrap_quote && is_new_line) {
qlen = gtkut_text_str_compare
(text, cur_pos, tlen, qfmt);
- is_new_line = 0;
+ is_new_line = FALSE;
if (qlen)
i_len = get_indent_length(text, cur_pos, tlen);
else
#endif
}
- /* get character(s) at current position */
- if (text->use_wchar)
- ch_len = wctomb
- (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
- else {
- cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
- ch_len = 1;
- }
+ GET_CHAR(cur_pos, cbuf, ch_len);
/* fix line length for tabs */
if (ch_len == 1 && *cbuf == '\t') {
ilen = gtkut_text_str_compare_n
(text, cur_pos + 1, p_pos, i_len, tlen);
if (cur_pos + ilen < tlen) {
- if (text->use_wchar)
- clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + ilen + 1));
- else {
- cb[0] = GTK_STEXT_INDEX(text,
- cur_pos + ilen + 1);
- clen = 1;
- }
+ GET_CHAR(cur_pos + ilen + 1, cb, clen);
/* no need to join the lines */
- if ((clen == 1) && (cb[0] == '\n'))
- do_delete = 0;
+ if (clen == 1 && cb[0] == '\n')
+ do_delete = FALSE;
}
- }
/* if it's just newline skip it */
- else if (do_delete && (cur_pos + 1 < tlen)) {
- if (text->use_wchar)
- clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + 1));
- else {
- cb[0] = GTK_STEXT_INDEX(text,
- cur_pos + 1);
- clen = 1;
- }
+ } else if (do_delete && (cur_pos + 1 < tlen)) {
+ GET_CHAR(cur_pos + 1, cb, clen);
/* no need to join the lines */
- if ((clen == 1) && (cb[0] == '\n'))
- do_delete = 0;
+ if (clen == 1 && cb[0] == '\n')
+ do_delete = FALSE;
}
#ifdef WRAP_DEBUG
}
}
- if (text->use_wchar)
- clen = wctomb
- (cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
- else {
- cb[0] = GTK_STEXT_INDEX(text, cur_pos);
- clen = 1;
- }
+ GET_CHAR(cur_pos, cb, clen);
/* insert space if it's alphanumeric */
if ((cur_pos != line_pos) &&
line_pos = cur_pos;
line_len = cur_len = 0;
qlen = 0;
- do_delete = 0;
- is_new_line = 1;
+ do_delete = FALSE;
+ is_new_line = TRUE;
#ifdef WRAP_DEBUG
printf("after delete l_pos=");
dump_text(text, line_pos, tlen, 1);
line_pos = cur_pos + 1;
line_len = cur_len = 0;
qlen = 0;
- do_delete = 0;
- is_new_line = 1;
+ do_delete = FALSE;
+ is_new_line = TRUE;
continue;
}
printf("new line_pos=%d\n", line_pos);
#endif
+ GET_CHAR(line_pos - 1, cbuf, clen);
+
/* if next character is space delete it */
- if (text->use_wchar)
- clen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
- else {
- cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
- clen = 1;
- }
if (clen == 1 && isspace(*cbuf)) {
if (p_pos + i_len != line_pos ||
!gtkut_text_is_uri_string
/* for loop will increase it */
cur_pos = line_pos - 1;
/* start over with current line */
- is_new_line = 1;
+ is_new_line = TRUE;
line_len = 0;
cur_len = 0;
- do_delete = 1;
+ do_delete = TRUE;
#ifdef WRAP_DEBUG
printf("after CR insert ");
dump_text(text, line_pos, tlen, 1);
gtk_stext_thaw(text);
}
-#if 0
-static void compose_wrap_line_all(Compose *compose)
-{
- GtkText *text = GTK_STEXT(compose->text);
- guint text_len;
- guint line_pos = 0, cur_pos = 0;
- gint line_len = 0, cur_len = 0;
- gint ch_len;
- gchar cbuf[MB_LEN_MAX];
-
- gtk_stext_freeze(text);
-
- text_len = gtk_stext_get_length(text);
-
- for (; cur_pos < text_len; cur_pos++) {
- if (text->use_wchar)
- ch_len = wctomb
- (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
- else {
- cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
- ch_len = 1;
- }
-
- if (ch_len == 1 && *cbuf == '\n') {
- line_pos = cur_pos + 1;
- line_len = cur_len = 0;
- continue;
- }
-
- if (ch_len < 0) {
- cbuf[0] = '\0';
- ch_len = 1;
- }
-
- if (ch_len == 1 && isspace(*cbuf)) {
- line_pos = cur_pos + 1;
- line_len = cur_len + ch_len;
- }
-
- if (cur_len + ch_len > prefs_common.linewrap_len &&
- line_len > 0) {
- gint tlen;
-
- if (text->use_wchar)
- tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
- else {
- cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
- tlen = 1;
- }
- if (tlen == 1 && isspace(*cbuf)) {
- gtk_stext_set_point(text, line_pos);
- gtk_stext_backward_delete(text, 1);
- text_len--;
- cur_pos--;
- line_pos--;
- cur_len--;
- line_len--;
- }
-
- gtk_stext_set_point(text, line_pos);
- gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
- text_len++;
- cur_pos++;
- line_pos++;
- cur_len = cur_len - line_len + ch_len;
- line_len = 0;
- continue;
- }
-
- if (ch_len > 1) {
- line_pos = cur_pos + 1;
- line_len = cur_len + ch_len;
- }
- cur_len += ch_len;
- }
-
- gtk_stext_thaw(text);
-}
-#endif
+#undef GET_CHAR
static void compose_set_title(Compose *compose)
{
g_warning("failed to write folder list.\n");
}
+static void folder_count_total_msgs_func(GNode *node, guint *new,
+ guint *unread, guint *total)
+{
+ g_return_if_fail(node != NULL);
+
+ if (node->data) {
+ FolderItem *item = FOLDER_ITEM(node->data);
+ *new += item->new;
+ *unread += item->unread;
+ *total += item->total;
+ }
+
+ if (node->children)
+ folder_count_total_msgs_func(node->children,
+ new, unread, total);
+ if (node->next)
+ folder_count_total_msgs_func(node->next, new, unread, total);
+}
+
+void folder_count_total_msgs(guint *new, guint *unread, guint *total)
+{
+ GList *list;
+ Folder *folder;
+
+ *new = *unread = *total = 0;
+
+ debug_print(_("Counting total number of messages...\n"));
+
+ for (list = folder_list; list != NULL; list = list->next) {
+ folder = FOLDER(list->data);
+ folder_count_total_msgs_func(folder->node, new, unread, total);
+ }
+
+ return;
+}
+
Folder *folder_find_from_path(const gchar *path)
{
GList *list;
folder_item_find_func, d);
return d[1];
}
-
-static void folder_count_total_newmsgs_func(const GNode *node, guint *newmsgs,
- guint *unreadmsgs, guint *totalmsgs)
-{
- if (node->data) {
- FolderItem *item = node->data;
- *newmsgs += item->new;
- *unreadmsgs += item->unread;
- *totalmsgs += item->total;
- }
- if (node->children)
- folder_count_total_newmsgs_func(node->children, newmsgs, unreadmsgs, totalmsgs);
- if (node->next)
- folder_count_total_newmsgs_func(node->next, newmsgs, unreadmsgs, totalmsgs);
-}
-
-void folder_count_total_msgs(guint *newmsgs, guint *unreadmsgs, guint *totalmsgs)
-{
- GList *list;
- Folder *folder;
-
- *newmsgs = 0;
- *unreadmsgs = 0;
- *totalmsgs = 0;
-
- debug_print(_("Counting total number of messages...\n"));
- list = folder_get_list();
- for (; list != NULL; list = list->next) {
- folder = FOLDER(list->data);
- if (folder->node)
- folder_count_total_newmsgs_func(folder->node, newmsgs, unreadmsgs, totalmsgs);
- }
- debug_print(_(" New: %d\n"), *newmsgs);
- debug_print(_(" Unread: %d\n"), *unreadmsgs);
- debug_print(_(" Total: %d\n"), *totalmsgs);
-
- return;
-}
/* check and create unix domain socket */
lock_socket = prohibit_duplicate_launch();
if (lock_socket < 0) return 0;
+
if (cmd.status) {
puts("0 Sylpheed not running.\n");
return 0;
} else if (!strncmp(argv[i], "--version", 9)) {
puts("Sylpheed version " VERSION);
exit(0);
- } else if (!strncmp(argv[i], "--status", 5)) {
+ } else if (!strncmp(argv[i], "--status", 8)) {
cmd.status = TRUE;
} else if (!strncmp(argv[i], "--help", 6)) {
g_print(_("Usage: %s [OPTION]...\n"),
puts(_(" --compose [address] open composition window"));
puts(_(" --receive receive new messages"));
puts(_(" --receive-all receive new messages of all accounts"));
+ puts(_(" --status show the total number of messages"));
puts(_(" --debug debug mode"));
puts(_(" --help display this help and exit"));
puts(_(" --version output version information and exit"));
} else if (cmd.status) {
gchar buf[BUFFSIZE];
- fd_write(uxsock, "status\n", 9);
+ fd_write(uxsock, "status\n", 7);
fd_gets(uxsock, buf, sizeof(buf));
- puts(buf);
+ fputs(buf, stdout);
} else
fd_write(uxsock, "popup\n", 6);
} else if (!strncmp(buf, "compose", 7)) {
open_compose_new_with_recipient(buf + strlen("compose") + 1);
} else if (!strncmp(buf, "status", 6)) {
- gchar buf[BUFFSIZE];
- guint newmsgs, unreadmsgs, totalmsgs;
+ guint new, unread, total;
- folder_count_total_msgs(&newmsgs, &unreadmsgs, &totalmsgs);
- snprintf(buf, sizeof(buf), "%d %d %d\n", newmsgs, unreadmsgs, totalmsgs);
+ folder_count_total_msgs(&new, &unread, &total);
+ g_snprintf(buf, sizeof(buf), "%d %d %d\n", new, unread, total);
fd_write(sock, buf, strlen(buf));
}
+
fd_close(sock);
}