PATCH: balsa exit code cleanup
- From: Pawel Salek <pawsa theochem kth se>
- To: balsa-list gnome org
- Subject: PATCH: balsa exit code cleanup
- Date: Wed, 05 Sep 2001 15:23:07 +0200
Hi,
I would like to commit the attached patch that cleans up balsa exit
code. Basically, so far balsa used very rough&hard combination of
destroy&quit calls. The proposed patch replaces it with a softer
approach using "delete-event" signals that give a chance to save
composed messages etc.
I would appreciate if somebody else would test the patch a little:
quit balsa, quit balsa with several compose windows open, quit using
different ways etc.
Thanks in advance,
Pawel
--
Pawel Salek, pavels@kjemi.uio.no, +47 (228) 55430
Theoretical Chemistry, Dept of Chemistry, Univ of Oslo
http://www.theochem.kth.se/~pawsa/
Index: configure.in
===================================================================
RCS file: /cvs/gnome/balsa/configure.in,v
retrieving revision 1.156
diff -u -r1.156 configure.in
--- configure.in 2001/09/01 08:45:45 1.156
+++ configure.in 2001/09/05 13:21:30
@@ -169,6 +169,7 @@
if test -d "${srcdir}/CVS" ; then
BALSA_FROM_CVS=yes
+ CFLAGS="$CFLAGS -Werror"
else
BALSA_FROM_CVS=no
fi
Index: src/main-window.c
===================================================================
RCS file: /cvs/gnome/balsa/src/main-window.c,v
retrieving revision 1.415
diff -u -r1.415 main-window.c
--- src/main-window.c 2001/08/31 13:51:25 1.415
+++ src/main-window.c 2001/09/05 13:21:32
@@ -113,8 +113,6 @@
static void balsa_window_real_close_mbnode(BalsaWindow *window,
BalsaMailboxNode *mbnode);
static void balsa_window_destroy(GtkObject * object);
-static void balsa_window_delete_cb (GtkWidget* widget, GdkEvent* event,
- gpointer user_data);
GtkWidget *balsa_window_find_current_index(BalsaWindow * window);
static gboolean balsa_close_mailbox_on_timer(GtkWidget * widget,
@@ -230,6 +228,14 @@
static void ident_manage_dialog_cb(GtkWidget*, gpointer);
+static void
+balsa_quit_nicely(void)
+{
+ GdkEventAny e = { GDK_DELETE, NULL, 0 };
+ e.window = GTK_WIDGET(balsa_app.main_window)->window;
+ gdk_event_put((GdkEvent*)&e);
+}
+
static GnomeUIInfo file_new_menu[] = {
#define MENU_FILE_NEW_MESSAGE_POS 0
{
@@ -309,7 +315,7 @@
address_book_cb, NULL, NULL, GNOME_APP_PIXMAP_STOCK,
GNOME_STOCK_MENU_BOOK_RED, 'B', 0, NULL},
GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_MENU_EXIT_ITEM(balsa_exit, NULL),
+ GNOMEUIINFO_MENU_EXIT_ITEM(balsa_quit_nicely, NULL),
GNOMEUIINFO_END
};
@@ -720,8 +726,6 @@
balsa_app.show_notebook_tabs);
gtk_notebook_set_show_border (GTK_NOTEBOOK(window->notebook), FALSE);
gtk_notebook_set_scrollable (GTK_NOTEBOOK (window->notebook), TRUE);
- gtk_signal_connect(GTK_OBJECT(window), "delete_event",
- GTK_SIGNAL_FUNC(balsa_exit), NULL);
gtk_signal_connect(GTK_OBJECT(window->notebook), "size_allocate",
GTK_SIGNAL_FUNC(notebook_size_alloc_cb), NULL);
gtk_signal_connect(GTK_OBJECT(window->notebook), "switch_page",
@@ -826,9 +830,10 @@
GTK_SIGNAL_FUNC(set_icon), NULL);
gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
GTK_SIGNAL_FUNC(mw_size_alloc_cb), NULL);
- gtk_signal_connect (GTK_OBJECT (window), "delete-event",
- GTK_SIGNAL_FUNC (balsa_window_delete_cb), NULL);
-
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
+ /* gtk_signal_connect(GTK_OBJECT(window), "delete-event",
+ GTK_SIGNAL_FUNC(delete_event_cb), NULL);*/
return GTK_WIDGET(window);
}
@@ -1276,15 +1281,7 @@
/* don't try to use notebook later in empty_trash */
balsa_app.notebook = NULL;
- balsa_exit();
-}
-
-
-static void
-balsa_window_delete_cb (GtkWidget* widget, GdkEvent* event,
- gpointer user_data)
-{
- balsa_exit();
+ // balsa_exit();
}
Index: src/main.c
===================================================================
RCS file: /cvs/gnome/balsa/src/main.c,v
retrieving revision 1.116
diff -u -r1.116 main.c
--- src/main.c 2001/08/23 07:39:42 1.116
+++ src/main.c 2001/09/05 13:21:33
@@ -89,6 +89,7 @@
static void balsa_init(int argc, char **argv);
static void config_init(void);
static void mailboxes_init(void);
+static void balsa_cleanup(void);
static gint balsa_kill_session(GnomeClient * client, gpointer client_data);
static gint balsa_save_session(GnomeClient * client, gint phase,
GnomeSaveStyle save_style, gint is_shutdown,
@@ -370,7 +371,8 @@
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
-
+
+ balsa_cleanup();
gdk_colormap_unref(balsa_app.colormap);
#ifdef BALSA_USE_THREADS
@@ -423,6 +425,14 @@
void
balsa_exit(void)
{
+ printf("Balsa exit...\n");
+ gtk_main_quit();
+}
+
+static void
+balsa_cleanup(void)
+{
+
g_node_traverse(balsa_app.mailbox_nodes,
G_LEVEL_ORDER,
G_TRAVERSE_ALL, 10, close_all_mailboxes, NULL);
@@ -440,9 +450,7 @@
gnome_sound_shutdown();
libbalsa_imap_close_all_connections();
- gtk_main_quit();
}
-
static gint
balsa_kill_session(GnomeClient * client, gpointer client_data)
Index: src/sendmsg-window.c
===================================================================
RCS file: /cvs/gnome/balsa/src/sendmsg-window.c,v
retrieving revision 1.296
diff -u -r1.296 sendmsg-window.c
--- src/sendmsg-window.c 2001/08/31 13:51:25 1.296
+++ src/sendmsg-window.c 2001/09/05 13:21:33
@@ -85,9 +85,9 @@
static gint postpone_message_cb(GtkWidget *, BalsaSendmsg *);
static gint print_message_cb(GtkWidget *, BalsaSendmsg *);
static gint attach_clicked(GtkWidget *, gpointer);
-static gint close_window(GtkWidget *, gpointer);
+static gint close_window_cb(GtkWidget *, gpointer);
static gchar* check_if_regular_file(const gchar *);
-static void balsa_sendmsg_destroy(BalsaSendmsg * bsm);
+static void balsa_sendmsg_destroy_handler(BalsaSendmsg * bsm);
static void check_readiness(GtkEditable * w, BalsaSendmsg * bsmsg);
static void init_menus(BalsaSendmsg *);
@@ -175,7 +175,7 @@
GNOMEUIINFO_SEPARATOR,
#define MENU_FILE_CLOSE_POS 8
- GNOMEUIINFO_MENU_CLOSE_ITEM(close_window, NULL),
+ GNOMEUIINFO_MENU_CLOSE_ITEM(close_window_cb, NULL),
GNOMEUIINFO_END
};
@@ -444,13 +444,6 @@
/* the callback handlers */
-static gint
-close_window(GtkWidget * widget, gpointer data)
-{
- balsa_sendmsg_destroy((BalsaSendmsg *) data);
- return TRUE;
-}
-
static void
address_book_cb(GtkWidget *widget, BalsaSendmsg *snd_msg_wind)
{
@@ -477,9 +470,51 @@
}
static gint
+delete_handler(BalsaSendmsg* bsmsg)
+{
+ gint reply;
+ printf("delete_event_cb\n");
+ if(bsmsg->modified) {
+ gchar* str =
+ g_strdup_printf(_("The message to '%s' is modified.\n"
+ "Save message to Draftbox?"),
+ gtk_entry_get_text(GTK_ENTRY(bsmsg->to[1])));
+ GtkWidget* l = gtk_label_new(str);
+ GnomeDialog* d =
+ GNOME_DIALOG(gnome_dialog_new(_("Closing the Compose Window"),
+ GNOME_STOCK_BUTTON_YES,
+ GNOME_STOCK_BUTTON_NO,
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL));
+ g_free(str);
+ gnome_dialog_set_parent(d, GTK_WINDOW(bsmsg->window));
+ gtk_widget_show(l);
+ gtk_box_pack_start_defaults(GTK_BOX(d->vbox), l);
+ reply = gnome_dialog_run_and_close(GNOME_DIALOG(d));
+ if(reply == 0)
+ postpone_message_cb(NULL, bsmsg);
+ /* cancel action when reply = "yes" or "no" */
+ return (reply != 0) && (reply != 1);
+ }
+ return FALSE;
+}
+static gint
delete_event_cb(GtkWidget * widget, GdkEvent * e, gpointer data)
+{
+ BalsaSendmsg* bsmsg = (BalsaSendmsg *) data;
+ return delete_handler(bsmsg);
+}
+
+static gint
+close_window_cb(GtkWidget * widget, gpointer data)
+{
+ return delete_handler((BalsaSendmsg *) data);
+}
+
+static gint
+destroy_event_cb(GtkWidget * widget, gpointer data)
{
- balsa_sendmsg_destroy((BalsaSendmsg *) data);
+ balsa_sendmsg_destroy_handler((BalsaSendmsg *) data);
return TRUE;
}
@@ -487,15 +522,15 @@
to the balsa_app structure.
*/
static void
-balsa_sendmsg_destroy(BalsaSendmsg * bsm)
+balsa_sendmsg_destroy_handler(BalsaSendmsg * bsm)
{
g_assert(bsm != NULL);
g_assert(ELEMENTS(headerDescs) == ELEMENTS(bsm->view_checkitems));
- if(balsa_app.debug) g_message("balsa_sendmsg_destroy(): Start.");
+ gtk_signal_disconnect(GTK_OBJECT(balsa_app.main_window),
+ bsm->delete_sig_id);
+ if(balsa_app.debug) g_message("balsa_sendmsg_destroy()_handler: Start.");
- gtk_quit_remove (bsm->quituid);
-
if (bsm->orig_message) {
if (bsm->orig_message->mailbox)
libbalsa_mailbox_close(bsm->orig_message->mailbox);
@@ -503,7 +538,7 @@
}
if (balsa_app.debug)
- printf("balsa_sendmsg_destroy: Freeing bsm\n");
+ printf("balsa_sendmsg_destroy_handler: Freeing bsm\n");
release_toolbars(bsm->window);
gtk_widget_destroy(bsm->window);
g_list_free(bsm->spell_check_disable_list);
@@ -513,6 +548,7 @@
}
g_free(bsm);
+
#ifdef BALSA_USE_THREADS
if (balsa_app.compose_email) {
while(sending_mail) {
@@ -1431,6 +1467,7 @@
msg->locale = NULL;
msg->ident = balsa_app.current_ident;
msg->update_config = FALSE;
+ msg->modified = TRUE; /* well, we should try harder guessing this one */
switch (type) {
case SEND_REPLY:
@@ -1469,10 +1506,10 @@
msg->window = window;
msg->type = type;
- gtk_signal_connect(GTK_OBJECT(msg->window), "delete_event",
- GTK_SIGNAL_FUNC(delete_event_cb), msg);
- gtk_signal_connect(GTK_OBJECT(msg->window), "destroy_event",
+ gtk_signal_connect(GTK_OBJECT(msg->window), "delete-event",
GTK_SIGNAL_FUNC(delete_event_cb), msg);
+ gtk_signal_connect(GTK_OBJECT(msg->window), "destroy",
+ GTK_SIGNAL_FUNC(destroy_event_cb), msg);
gtk_signal_connect(GTK_OBJECT(msg->window), "size_allocate",
GTK_SIGNAL_FUNC(sw_size_alloc_cb), msg);
@@ -1495,7 +1532,7 @@
set_toolbar_button_callback(1, GNOME_STOCK_PIXMAP_PRINT,
GTK_SIGNAL_FUNC(print_message_cb), msg);
set_toolbar_button_callback(1, GNOME_STOCK_PIXMAP_CLOSE,
- GTK_SIGNAL_FUNC(close_window), msg);
+ GTK_SIGNAL_FUNC(close_window_cb), msg);
gnome_app_set_toolbar(GNOME_APP(window),
get_toolbar(GTK_WIDGET(window), TOOLBAR_COMPOSE));
@@ -1675,9 +1712,11 @@
else
gtk_widget_grab_focus(msg->text);
- msg->quituid = gtk_quit_add( 1, autopostpone_message, msg );
-
msg->update_config = TRUE;
+
+ msg->delete_sig_id =
+ gtk_signal_connect(GTK_OBJECT(balsa_app.main_window), "delete-event",
+ (GtkSignalFunc)delete_event_cb, msg);
return msg;
}
@@ -2092,7 +2131,7 @@
}
gtk_object_destroy(GTK_OBJECT(message));
- balsa_sendmsg_destroy(bsmsg);
+ gtk_widget_destroy(bsmsg->window);
return TRUE;
}
@@ -2164,7 +2203,7 @@
}
gtk_object_destroy(GTK_OBJECT(message));
- balsa_sendmsg_destroy(bsmsg);
+ gtk_widget_destroy(bsmsg->window);
return TRUE;
}
Index: src/sendmsg-window.h
===================================================================
RCS file: /cvs/gnome/balsa/src/sendmsg-window.h,v
retrieving revision 1.39
diff -u -r1.39 sendmsg-window.h
--- src/sendmsg-window.h 2001/08/29 03:56:07 1.39
+++ src/sendmsg-window.h 2001/09/05 13:21:33
@@ -64,7 +64,8 @@
gboolean update_config; /* is the window being set up or in normal */
/* operation and user actions should update */
/* the config */
- guint quituid; /* id of the gtk_quit callback */
+ guint delete_sig_id;
+ gboolean modified;
};
BalsaSendmsg *sendmsg_window_new(GtkWidget *, LibBalsaMessage *,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]