toolbar_main_set_sensitive(mainwindow_get_mainwindow());
}
-void compose_draft (gpointer data, guint action)
-{
- compose_draft_cb(data, action, NULL);
-}
-
#define DRAFTED_AT_EXIT "drafted_at_exit"
-void compose_clear_exit_drafts(void)
-{
- gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- DRAFTED_AT_EXIT, NULL);
- if (is_file_exist(filepath))
- g_unlink(filepath);
-
- g_free(filepath);
-}
-
static void compose_register_draft(MsgInfo *info)
{
gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
g_free(filepath);
}
-void compose_reopen_exit_drafts(void)
-{
- gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- DRAFTED_AT_EXIT, NULL);
- FILE *fp = fopen(filepath, "rb");
- gchar buf[1024];
-
- if (fp) {
- while (fgets(buf, sizeof(buf), fp)) {
- gchar **parts = g_strsplit(buf, "\t", 2);
- const gchar *folder = parts[0];
- int msgnum = parts[1] ? atoi(parts[1]):-1;
-
- if (folder && *folder && msgnum > -1) {
- FolderItem *item = folder_find_item_from_identifier(folder);
- MsgInfo *info = folder_item_get_msginfo(item, msgnum);
- if (info)
- compose_reedit(info, FALSE);
- }
- g_strfreev(parts);
- }
- fclose(fp);
- }
- g_free(filepath);
- compose_clear_exit_drafts();
-}
-
-static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
+gboolean compose_draft (gpointer data, guint action)
{
Compose *compose = (Compose *)data;
FolderItem *draft;
FILE *fp;
gboolean target_locked = FALSE;
- if (lock) return;
+ if (lock) return FALSE;
+
+ if (compose->sending)
+ return TRUE;
draft = account_get_special_folder(compose->account, F_DRAFT);
- g_return_if_fail(draft != NULL);
+ g_return_val_if_fail(draft != NULL, FALSE);
if (!g_mutex_trylock(compose->mutex)) {
/* we don't want to lock the mutex once it's available,
* it is compose_close - which means once unlocked,
* the compose struct will be freed */
debug_print("couldn't lock mutex, probably sending\n");
- return;
+ return FALSE;
}
lock = TRUE;
if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
g_unlink(tmp);
g_free(tmp);
- if (action != COMPOSE_AUTO_SAVE)
- alertpanel_error(_("Could not save draft."));
+ if (action != COMPOSE_AUTO_SAVE) {
+ if (action != COMPOSE_DRAFT_FOR_EXIT)
+ alertpanel_error(_("Could not save draft."));
+ else {
+ AlertValue val;
+ gtkut_window_popup(compose->window);
+ val = alertpanel_full(_("Could not save draft"),
+ _("Could not save draft.\n"
+ "Do you want to cancel exit or discard this email?"),
+ _("_Cancel exit"), _("_Discard email"), NULL,
+ FALSE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
+ if (val == G_ALERTALTERNATE) {
+ lock = FALSE;
+ g_mutex_unlock(compose->mutex); /* must be done before closing */
+ compose_close(compose);
+ return TRUE;
+ } else {
+ lock = FALSE;
+ g_mutex_unlock(compose->mutex); /* must be done before closing */
+ return FALSE;
+ }
+ }
+ }
goto unlock;
}
g_free(tmp);
lock = FALSE;
g_mutex_unlock(compose->mutex); /* must be done before closing */
compose_close(compose);
- return;
+ return TRUE;
} else {
struct stat s;
gchar *path;
unlock:
lock = FALSE;
g_mutex_unlock(compose->mutex);
+ return TRUE;
+}
+
+void compose_clear_exit_drafts(void)
+{
+ gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+ DRAFTED_AT_EXIT, NULL);
+ if (is_file_exist(filepath))
+ g_unlink(filepath);
+
+ g_free(filepath);
+}
+
+void compose_reopen_exit_drafts(void)
+{
+ gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+ DRAFTED_AT_EXIT, NULL);
+ FILE *fp = fopen(filepath, "rb");
+ gchar buf[1024];
+
+ if (fp) {
+ while (fgets(buf, sizeof(buf), fp)) {
+ gchar **parts = g_strsplit(buf, "\t", 2);
+ const gchar *folder = parts[0];
+ int msgnum = parts[1] ? atoi(parts[1]):-1;
+
+ if (folder && *folder && msgnum > -1) {
+ FolderItem *item = folder_find_item_from_identifier(folder);
+ MsgInfo *info = folder_item_get_msginfo(item, msgnum);
+ if (info)
+ compose_reedit(info, FALSE);
+ }
+ g_strfreev(parts);
+ }
+ fclose(fp);
+ }
+ g_free(filepath);
+ compose_clear_exit_drafts();
+}
+
+static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
+{
+ compose_draft(data, action);
}
static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
} else if (cmd.receive) {
defer_check(NULL);
}
- mainwindow_jump_to(data);
+ mainwindow_jump_to(data, FALSE);
return FALSE;
}
STATUSBAR_POP(mainwin);
}
-static void draft_all_messages(void)
+static gboolean draft_all_messages(void)
{
GList *compose_list = NULL;
compose_clear_exit_drafts();
- while ((compose_list = compose_get_compose_list()) != NULL) {
+ compose_list = compose_get_compose_list();
+ while (compose_list != NULL) {
Compose *c = (Compose*)compose_list->data;
- compose_draft(c, COMPOSE_DRAFT_FOR_EXIT);
- }
+ if (!compose_draft(c, COMPOSE_DRAFT_FOR_EXIT))
+ return FALSE;
+ compose_list = compose_list->next;
+ }
+ return TRUE;
}
gboolean clean_quit(gpointer data)
{
sc_exiting = TRUE;
debug_print("exiting\n");
if (compose_get_compose_list()) {
- draft_all_messages();
+ if (!draft_all_messages()) {
+ main_window_popup(mainwin);
+ sc_exiting = FALSE;
+ return;
+ }
}
if (prefs_common.warn_queued_on_exit && procmsg_have_queued_mails_fast()) {
if (folders) g_ptr_array_free(folders, TRUE);
} else if (!strncmp(buf, "select ", 7)) {
const gchar *target = buf+7;
- mainwindow_jump_to(target);
+ mainwindow_jump_to(target, TRUE);
} else if (!strncmp(buf, "exit", 4)) {
app_will_exit(NULL, mainwin);
}
summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
}
-void mainwindow_jump_to(const gchar *target)
+void mainwindow_jump_to(const gchar *target, gboolean popup)
{
gchar *tmp = NULL;
gchar *p = NULL;
if ((item = folder_find_item_from_identifier(tmp))) {
printf("selecting folder '%s'\n", tmp);
folderview_select(mainwin->folderview, item);
- main_window_popup(mainwin);
+ if (popup)
+ main_window_popup(mainwin);
g_free(tmp);
return;
}
printf("selecting message %d\n", atoi(msg));
summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
summary_display_msg_selected(mainwin->summaryview, FALSE);
- main_window_popup(mainwin);
+ if (popup)
+ main_window_popup(mainwin);
g_free(tmp);
return;
} else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
printf("selecting message %s\n", msg);
summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
summary_display_msg_selected(mainwin->summaryview, FALSE);
- main_window_popup(mainwin);
+ if (popup)
+ main_window_popup(mainwin);
g_free(tmp);
procmsg_msginfo_free(msginfo);
return;