Cleaning up the code
This commit is contained in:
parent
4514b62e73
commit
accd49260c
1296
src/callbacks.c
1296
src/callbacks.c
File diff suppressed because it is too large
Load Diff
|
@ -22,36 +22,36 @@
|
|||
|
||||
|
||||
/* mailer window */
|
||||
gboolean on_closex(GtkWidget * widget, GdkEvent * event, gpointer data);
|
||||
gboolean on_closex(gpointer data);
|
||||
|
||||
/* file menu */
|
||||
void on_file_new_mail(GtkWidget * widget, gpointer data);
|
||||
void on_file_send_receive(GtkWidget * widget, gpointer data);
|
||||
void on_file_print(GtkWidget * widget, gpointer data);
|
||||
void on_file_print_preview(GtkWidget * widget, gpointer data);
|
||||
void on_file_quit(GtkWidget * widget, gpointer data);
|
||||
void on_file_new_mail(gpointer data);
|
||||
void on_file_send_receive(gpointer data);
|
||||
void on_file_print(gpointer data);
|
||||
void on_file_print_preview(gpointer data);
|
||||
void on_file_quit(gpointer data);
|
||||
|
||||
/* edit menu */
|
||||
void on_edit_preferences(GtkWidget * widget, gpointer data);
|
||||
void on_edit_preferences(gpointer data);
|
||||
|
||||
/* message menu */
|
||||
void on_message_reply(GtkWidget * widget, gpointer data);
|
||||
void on_message_reply_to_all(GtkWidget * widget, gpointer data);
|
||||
void on_message_forward(GtkWidget * widget, gpointer data);
|
||||
void on_message_delete(GtkWidget * widget, gpointer data);
|
||||
void on_message_view_source(GtkWidget * widget, gpointer data);
|
||||
void on_message_reply(gpointer data);
|
||||
void on_message_reply_to_all(gpointer data);
|
||||
void on_message_forward(gpointer data);
|
||||
void on_message_delete(gpointer data);
|
||||
void on_message_view_source(gpointer data);
|
||||
|
||||
/* help menu */
|
||||
void on_help_about(GtkWidget * widget, gpointer data);
|
||||
void on_help_about(gpointer data);
|
||||
|
||||
/* toolbar */
|
||||
void on_new_mail(GtkWidget * widget, gpointer data);
|
||||
void on_stop(GtkWidget * widget, gpointer data);
|
||||
void on_reply(GtkWidget * widget, gpointer data);
|
||||
void on_reply_to_all(GtkWidget * widget, gpointer data);
|
||||
void on_forward(GtkWidget * widget, gpointer data);
|
||||
void on_delete(GtkWidget * widget, gpointer data);
|
||||
void on_print(GtkWidget * widget, gpointer data);
|
||||
void on_new_mail(gpointer data);
|
||||
void on_stop(gpointer data);
|
||||
void on_reply(gpointer data);
|
||||
void on_reply_to_all(gpointer data);
|
||||
void on_forward(gpointer data);
|
||||
void on_delete(gpointer data);
|
||||
void on_print(gpointer data);
|
||||
|
||||
/* folder view */
|
||||
void on_folder_change(GtkTreeSelection * selection, gpointer data);
|
||||
|
@ -59,47 +59,37 @@ void on_folder_change(GtkTreeSelection * selection, gpointer data);
|
|||
/* header view */
|
||||
void on_header_change(GtkTreeSelection * selection, gpointer data);
|
||||
|
||||
/* preferences window */
|
||||
void on_preferences_ok(GtkWidget * widget, gpointer data);
|
||||
void on_preferences_cancel(GtkWidget * widget, gpointer data);
|
||||
|
||||
|
||||
/* accounts */
|
||||
void on_account_new(GtkWidget * widget, gpointer data);
|
||||
void on_account_edit(GtkWidget * widget, gpointer data);
|
||||
void on_account_delete(GtkWidget * widget, gpointer data);
|
||||
|
||||
|
||||
/* compose window */
|
||||
gboolean on_compose_closex(GtkWidget * widget, GdkEvent * event, gpointer data);
|
||||
void on_compose_save(GtkWidget * widget, gpointer data);
|
||||
void on_compose_send(GtkWidget * widget, gpointer data);
|
||||
void on_compose_attach(GtkWidget * widget, gpointer data);
|
||||
gboolean on_compose_closex(gpointer data);
|
||||
void on_compose_save(gpointer data);
|
||||
void on_compose_send(gpointer data);
|
||||
void on_compose_attach(gpointer data);
|
||||
|
||||
/* file menu */
|
||||
void on_compose_file_new(GtkWidget * widget, gpointer data);
|
||||
void on_compose_file_save(GtkWidget * widget, gpointer data);
|
||||
void on_compose_file_save_as(GtkWidget * widget, gpointer data);
|
||||
void on_compose_file_send(GtkWidget * widget, gpointer data);
|
||||
void on_compose_file_close(GtkWidget * widget, gpointer data);
|
||||
void on_compose_file_new(gpointer data);
|
||||
void on_compose_file_save(gpointer data);
|
||||
void on_compose_file_save_as(gpointer data);
|
||||
void on_compose_file_send(gpointer data);
|
||||
void on_compose_file_close(gpointer data);
|
||||
|
||||
/* edit menu */
|
||||
void on_compose_edit_undo(GtkWidget * widget, gpointer data);
|
||||
void on_compose_edit_redo(GtkWidget * widget, gpointer data);
|
||||
void on_compose_edit_cut(GtkWidget * widget, gpointer data);
|
||||
void on_compose_edit_copy(GtkWidget * widget, gpointer data);
|
||||
void on_compose_edit_paste(GtkWidget * widget, gpointer data);
|
||||
void on_compose_edit_undo(gpointer data);
|
||||
void on_compose_edit_redo(gpointer data);
|
||||
void on_compose_edit_cut(gpointer data);
|
||||
void on_compose_edit_copy(gpointer data);
|
||||
void on_compose_edit_paste(gpointer data);
|
||||
|
||||
/* view menu */
|
||||
void on_compose_view_cc(GtkWidget * widget, gpointer data);
|
||||
void on_compose_view_bcc(GtkWidget * widget, gpointer data);
|
||||
void on_compose_view_cc(gpointer data);
|
||||
void on_compose_view_bcc(gpointer data);
|
||||
|
||||
/* help menu */
|
||||
void on_compose_help_about(GtkWidget * widget, gpointer data);
|
||||
void on_compose_help_about(gpointer data);
|
||||
|
||||
/* send mail */
|
||||
gboolean on_send_closex(GtkWidget * widget, GdkEvent * event, gpointer data);
|
||||
void on_send_cancel(GtkWidget * widget, gpointer data);
|
||||
gboolean on_send_closex(gpointer data);
|
||||
void on_send_cancel(gpointer data);
|
||||
gboolean on_send_write(GIOChannel * source, GIOCondition condition,
|
||||
gpointer data);
|
||||
|
||||
|
|
|
@ -62,8 +62,9 @@ GtkWidget * common_new_menubar(GtkWindow * window, struct _menubar * mb,
|
|||
image);
|
||||
}
|
||||
if(p->callback != NULL)
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(p->callback), data);
|
||||
g_signal_connect_swapped(G_OBJECT(menuitem),
|
||||
"activate", G_CALLBACK(
|
||||
p->callback), data);
|
||||
else
|
||||
gtk_widget_set_sensitive(menuitem, FALSE);
|
||||
if(p->accel != 0)
|
||||
|
@ -101,7 +102,8 @@ GtkWidget * common_new_toolbar(struct _toolbar * tb, gpointer data)
|
|||
widget = gtk_image_new_from_icon_name(tb[i].stock,
|
||||
GTK_ICON_SIZE_LARGE_TOOLBAR);
|
||||
toolitem = gtk_tool_button_new(widget, tb[i].name);
|
||||
g_signal_connect(toolitem, "clicked", tb[i].callback, data);
|
||||
g_signal_connect_swapped(toolitem, "clicked", tb[i].callback,
|
||||
data);
|
||||
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
|
||||
}
|
||||
return toolbar;
|
||||
|
|
118
src/compose.c
118
src/compose.c
|
@ -28,7 +28,39 @@
|
|||
#include "compose.h"
|
||||
|
||||
|
||||
/* Compose */
|
||||
/* private */
|
||||
/* types */
|
||||
struct _Compose
|
||||
{
|
||||
Mailer * mailer;
|
||||
|
||||
/* sending mail */
|
||||
pid_t pid;
|
||||
int fd;
|
||||
char * buf;
|
||||
size_t buf_len;
|
||||
size_t buf_pos;
|
||||
GIOChannel * channel;
|
||||
GtkWidget * snd_window;
|
||||
GtkWidget * snd_progress;
|
||||
|
||||
/* widgets */
|
||||
GtkWidget * window;
|
||||
GtkWidget * from;
|
||||
GtkWidget * to;
|
||||
GtkWidget * tb_cc;
|
||||
GtkWidget * cc;
|
||||
GtkWidget * tb_bcc;
|
||||
GtkWidget * bcc;
|
||||
GtkWidget * subject;
|
||||
GtkWidget * view;
|
||||
GtkWidget * statusbar;
|
||||
gint statusbar_id;
|
||||
GtkWidget * ab_window;
|
||||
};
|
||||
|
||||
|
||||
/* constants */
|
||||
#define SENDMAIL "/usr/sbin/sendmail"
|
||||
|
||||
|
@ -118,8 +150,8 @@ Compose * compose_new(Mailer * mailer)
|
|||
compose->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title(GTK_WINDOW(compose->window), "Mailer - Compose");
|
||||
gtk_window_set_default_size(GTK_WINDOW(compose->window), 512, 384);
|
||||
g_signal_connect(G_OBJECT(compose->window), "delete_event", G_CALLBACK(
|
||||
on_compose_closex), compose);
|
||||
g_signal_connect_swapped(G_OBJECT(compose->window), "delete-event",
|
||||
G_CALLBACK(on_compose_closex), compose);
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
/* menubar */
|
||||
widget = common_new_menubar(GTK_WINDOW(compose->window),
|
||||
|
@ -207,6 +239,7 @@ Compose * compose_new(Mailer * mailer)
|
|||
compose->statusbar_id = 0;
|
||||
gtk_box_pack_start(GTK_BOX(vbox), compose->statusbar, FALSE, TRUE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(compose->window), vbox);
|
||||
compose->ab_window = NULL;
|
||||
gtk_widget_show_all(vbox);
|
||||
gtk_widget_hide(compose->tb_cc);
|
||||
gtk_widget_hide(compose->tb_bcc);
|
||||
|
@ -271,9 +304,10 @@ Mailer * compose_get_mailer(Compose * compose)
|
|||
|
||||
/* useful */
|
||||
/* compose_save */
|
||||
void compose_save(Compose * compose)
|
||||
int compose_save(Compose * compose)
|
||||
{
|
||||
/* FIXME implement */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -282,6 +316,8 @@ static char * _send_headers(Compose * compose);
|
|||
static char * _send_body(GtkWidget * view);
|
||||
static int _send_mail(Compose * compose, char * msg, size_t msg_len);
|
||||
static int _mail_child(int fd[2]);
|
||||
static gboolean _on_send_write(GIOChannel * source, GIOCondition condition,
|
||||
gpointer data);
|
||||
|
||||
void compose_send(Compose * compose)
|
||||
{
|
||||
|
@ -330,7 +366,7 @@ static int _send_mail(Compose * compose, char * msg, size_t msg_len)
|
|||
gtk_window_set_resizable(GTK_WINDOW(compose->snd_window), FALSE);
|
||||
gtk_window_set_transient_for(GTK_WINDOW(compose->snd_window),
|
||||
GTK_WINDOW(compose->window));
|
||||
g_signal_connect(G_OBJECT(compose->snd_window), "delete_event",
|
||||
g_signal_connect_swapped(G_OBJECT(compose->snd_window), "delete-event",
|
||||
G_CALLBACK(on_send_closex), compose);
|
||||
hbox = gtk_hbox_new(FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new("Progression: "),
|
||||
|
@ -340,7 +376,7 @@ static int _send_mail(Compose * compose, char * msg, size_t msg_len)
|
|||
0.0);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), compose->snd_progress, TRUE, TRUE, 0);
|
||||
widget = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
|
||||
g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "clicked", G_CALLBACK(
|
||||
on_send_cancel), compose);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(compose->snd_window), 4);
|
||||
|
@ -351,7 +387,7 @@ static int _send_mail(Compose * compose, char * msg, size_t msg_len)
|
|||
compose->buf_len = msg_len;
|
||||
compose->buf_pos = 0;
|
||||
compose->channel = g_io_channel_unix_new(fd[1]);
|
||||
g_io_add_watch(compose->channel, G_IO_OUT, on_send_write, compose);
|
||||
g_io_add_watch(compose->channel, G_IO_OUT, _on_send_write, compose);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -439,3 +475,73 @@ static char * _send_body(GtkWidget * view)
|
|||
return gtk_text_buffer_get_text(GTK_TEXT_BUFFER(tbuf), &start, &end,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
static gboolean _on_send_write(GIOChannel * source, GIOCondition condition,
|
||||
gpointer data)
|
||||
{
|
||||
Compose * c = data;
|
||||
gsize i;
|
||||
|
||||
if(condition != G_IO_OUT)
|
||||
return FALSE;
|
||||
if((i = (c->buf_len - c->buf_pos) % 512) == 0)
|
||||
i = 512;
|
||||
if(g_io_channel_write_chars(source, &c->buf[c->buf_pos], i, &i, NULL)
|
||||
!= G_IO_STATUS_NORMAL)
|
||||
{
|
||||
mailer_error(c->mailer, strerror(errno), FALSE);
|
||||
on_send_cancel(c);
|
||||
return FALSE;
|
||||
}
|
||||
c->buf_pos+=i;
|
||||
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->snd_progress),
|
||||
c->buf_pos / c->buf_len);
|
||||
if(c->buf_pos >= c->buf_len)
|
||||
{
|
||||
on_send_cancel(c);
|
||||
compose_delete(c);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* compose_send_cancel */
|
||||
void compose_send_cancel(Compose * compose)
|
||||
{
|
||||
/* FIXME verify that a send operation is in progress */
|
||||
g_io_channel_shutdown(compose->channel, TRUE, NULL);
|
||||
gtk_widget_destroy(compose->snd_window);
|
||||
free(compose->buf);
|
||||
}
|
||||
|
||||
|
||||
/* compose_show_about */
|
||||
void compose_show_about(Compose * compose, gboolean show)
|
||||
{
|
||||
if(compose->ab_window != NULL)
|
||||
{
|
||||
if(show)
|
||||
gtk_widget_show(compose->ab_window);
|
||||
else
|
||||
gtk_widget_hide(compose->ab_window);
|
||||
return;
|
||||
}
|
||||
/* FIXME implement */
|
||||
}
|
||||
|
||||
|
||||
/* compose_toggle_show_bcc */
|
||||
void compose_toggle_show_bcc(Compose * compose)
|
||||
{
|
||||
/* FIXME implement correctly */
|
||||
gtk_widget_show(compose->tb_bcc);
|
||||
}
|
||||
|
||||
|
||||
/* compose_toggle_show_cc */
|
||||
void compose_toggle_show_cc(Compose * compose)
|
||||
{
|
||||
/* FIXME implement correctly */
|
||||
gtk_widget_show(compose->tb_cc);
|
||||
}
|
||||
|
|
|
@ -23,43 +23,23 @@
|
|||
|
||||
|
||||
/* types */
|
||||
typedef struct _Compose
|
||||
{
|
||||
Mailer * mailer;
|
||||
|
||||
/* sending mail */
|
||||
pid_t pid;
|
||||
int fd;
|
||||
char * buf;
|
||||
size_t buf_len;
|
||||
size_t buf_pos;
|
||||
GIOChannel * channel;
|
||||
GtkWidget * snd_window;
|
||||
GtkWidget * snd_progress;
|
||||
|
||||
/* widgets */
|
||||
GtkWidget * window;
|
||||
GtkWidget * from;
|
||||
GtkWidget * to;
|
||||
GtkWidget * tb_cc;
|
||||
GtkWidget * cc;
|
||||
GtkWidget * tb_bcc;
|
||||
GtkWidget * bcc;
|
||||
GtkWidget * subject;
|
||||
GtkWidget * view;
|
||||
GtkWidget * statusbar;
|
||||
gint statusbar_id;
|
||||
} Compose;
|
||||
typedef struct _Compose Compose;
|
||||
|
||||
/* methods */
|
||||
Compose * compose_new(Mailer * mailer);
|
||||
void compose_delete(Compose * compose);
|
||||
|
||||
/* accessors */
|
||||
Mailer * compose_get_mailer(Compose * compose); /* XXX ugly */
|
||||
Mailer * compose_get_mailer(Compose * compose);
|
||||
|
||||
/* useful */
|
||||
void compose_save(Compose * compose);
|
||||
int compose_save(Compose * compose);
|
||||
void compose_send(Compose * compose);
|
||||
void compose_send_cancel(Compose * compose);
|
||||
|
||||
void compose_show_about(Compose * compose, gboolean show);
|
||||
|
||||
void compose_toggle_show_bcc(Compose * compose);
|
||||
void compose_toggle_show_cc(Compose * compose);
|
||||
|
||||
#endif /* !MAILER_COMPOSE_H */
|
||||
|
|
1275
src/mailer.c
1275
src/mailer.c
File diff suppressed because it is too large
Load Diff
38
src/mailer.h
38
src/mailer.h
|
@ -52,37 +52,7 @@ enum
|
|||
# define MH_COL_LAST MH_COL_DATE
|
||||
# define MH_COL_COUNT (MH_COL_LAST + 1)
|
||||
|
||||
typedef struct _Mailer
|
||||
{
|
||||
Account * available; /* XXX consider using another data type */
|
||||
unsigned int available_cnt;
|
||||
|
||||
Account ** account;
|
||||
unsigned int account_cnt;
|
||||
Account * account_cur;
|
||||
AccountFolder * folder_cur;
|
||||
|
||||
/* configuration */
|
||||
Config * config;
|
||||
|
||||
/* widgets */
|
||||
GtkWidget * window;
|
||||
GtkWidget * view_folders;
|
||||
GtkWidget * view_headers;
|
||||
GtkWidget * hdr_vbox;
|
||||
GtkWidget * hdr_subject;
|
||||
GtkWidget * hdr_from;
|
||||
GtkWidget * hdr_to;
|
||||
GtkWidget * hdr_date;
|
||||
GtkTextBuffer * view_buffer;
|
||||
GtkWidget * view_body;
|
||||
GtkWidget * statusbar;
|
||||
gint statusbar_id;
|
||||
/* preferences */
|
||||
GtkWidget * pr_window;
|
||||
GtkWidget * pr_accounts;
|
||||
GtkWidget * pr_messages_font;
|
||||
} Mailer;
|
||||
typedef struct _Mailer Mailer;
|
||||
|
||||
|
||||
/* functions */
|
||||
|
@ -91,7 +61,6 @@ void mailer_delete(Mailer * mailer);
|
|||
|
||||
/* accessors */
|
||||
char const * mailer_get_config(Mailer * mailer, char const * variable);
|
||||
char * mailer_get_config_filename(Mailer * mailer);
|
||||
|
||||
/* useful */
|
||||
int mailer_error(Mailer * mailer, char const * message, int ret);
|
||||
|
@ -104,4 +73,7 @@ int mailer_account_enable(Mailer * mailer, Account * account);
|
|||
/* FIXME implement
|
||||
int mailer_account_remove(Mailer * mailer, Account * account); */
|
||||
|
||||
#endif
|
||||
void mailer_show_about(Mailer * mailer, gboolean show);
|
||||
void mailer_show_preferences(Mailer * mailer, gboolean show);
|
||||
|
||||
#endif /* !MAILER_MAILER_H */
|
||||
|
|
Loading…
Reference in New Issue
Block a user