added autosave
authorColin Leroy <colin@colino.net>
Tue, 3 Sep 2002 16:15:17 +0000 (16:15 +0000)
committerColin Leroy <colin@colino.net>
Tue, 3 Sep 2002 16:15:17 +0000 (16:15 +0000)
ChangeLog.claws
configure.in
src/compose.c
src/main.c
src/prefs_common.c
src/prefs_common.h

index 9fd3ea6..9c63965 100644 (file)
@@ -1,3 +1,15 @@
+2002-09-03 [colin]      0.8.2claws26
+
+       * src/prefs_common.[ch]
+               Added autosave and autosave_length prefs
+       * src/compose.c
+               Added compose_remove_draft()
+               Auto-save drafts according to the prefs
+       * src/main.c
+               Added a crash-indicator file, allowing to check
+               for new messages on startup if Sylpheed crashed
+               (makes saved drafts "reappear")
+
 2002-09-03 [colin]     0.8.2claws25
 
        * src/textview.[ch]
index 48086b9..ed1388f 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=8
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws25
+EXTRA_VERSION=claws26
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 022a1bf..7f148df 100644 (file)
@@ -221,6 +221,7 @@ static gint compose_write_to_file           (Compose        *compose,
 static gint compose_write_body_to_file         (Compose        *compose,
                                                 const gchar    *file);
 static gint compose_remove_reedit_target       (Compose        *compose);
+void compose_remove_draft                      (Compose        *compose);
 static gint compose_queue                      (Compose        *compose,
                                                 gint           *msgnum,
                                                 FolderItem     **item);
@@ -3360,6 +3361,19 @@ static gint compose_remove_reedit_target(Compose *compose)
        return 0;
 }
 
+void compose_remove_draft(Compose *compose)
+{
+       FolderItem *drafts;
+       MsgInfo *msginfo = compose->targetinfo;
+       drafts = account_get_special_folder(compose->account, F_DRAFT);
+
+       if (procmsg_msg_exist(msginfo)) {
+               folder_item_remove_msg(drafts, msginfo->msgnum);
+               folderview_update_item(drafts, TRUE);
+       }
+
+}
+
 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
 {
        return compose_queue_sub (compose, msgnum, item, FALSE);
@@ -6265,7 +6279,8 @@ static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
 {
        Compose *compose = (Compose *)data;
        AlertValue val;
-
+       gchar *tmp = NULL;
+       
        if (compose->exteditor_tag != -1) {
                if (!compose_ext_editor_kill(compose))
                        return;
@@ -6278,6 +6293,8 @@ static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
 
                switch (val) {
                case G_ALERTDEFAULT:
+                       if (prefs_common.autosave)
+                               compose_remove_draft(compose);                  
                        break;
                case G_ALERTALTERNATE:
                        compose_draft_cb(data, 0, NULL);
@@ -6809,6 +6826,9 @@ static void text_activated(GtkWidget *widget, Compose *compose)
        compose_send_control_enter(compose);
 }
 
+#define EDITABLE_LENGTH(x) \
+       strlen(gtk_editable_get_chars(x,0,-1))
+
 static void text_inserted(GtkWidget *widget, const gchar *text,
                          gint length, gint *position, Compose *compose)
 {
@@ -6843,6 +6863,11 @@ static void text_inserted(GtkWidget *widget, const gchar *text,
                                           GTK_SIGNAL_FUNC(text_inserted),
                                           compose);
        gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
+
+       
+       if (prefs_common.autosave && 
+           EDITABLE_LENGTH(editable) % prefs_common.autosave_length == 0)
+               compose_draft_cb((gpointer)compose, 1, NULL);
 }
 
 static gboolean compose_send_control_enter(Compose *compose)
index bbabc67..d2430b7 100644 (file)
@@ -113,6 +113,7 @@ static void idle_function_for_gpgme(void);
 #endif /* USE_GPGME */
 
 static gint prohibit_duplicate_launch  (void);
+static gchar * get_crashfile_name      (void);
 static void lock_socket_input_cb       (gpointer          data,
                                         gint              source,
                                         GdkInputCondition condition);
@@ -323,6 +324,14 @@ int main(int argc, char *argv[])
        /* make one all-folder processing before using sylpheed */
        folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
 
+       /* if Sylpheed crashed, rebuild caches */
+       if (!cmd.crash && is_file_exist(get_crashfile_name())) {
+               debug_print("Sylpheed crashed, checking for new messages\n");
+               folderview_check_new_all();
+       }
+       /* make the crash-indicator file */
+       str_write_to_file("foo", get_crashfile_name());
+
        addressbook_read_file();
 
        inc_autocheck_timer_init(mainwin);
@@ -540,6 +549,10 @@ void app_will_exit(GtkWidget *widget, gpointer data)
        fd_close(lock_socket);
        filename = get_socket_name();
        unlink(filename);
+       
+       /* delete crashfile */
+       if (!cmd.crash)
+               unlink(get_crashfile_name());
 
 #if USE_SSL
        ssl_done();
@@ -576,6 +589,18 @@ gchar *get_socket_name(void)
        return filename;
 }
 
+static gchar *get_crashfile_name(void)
+{
+       static gchar *filename = NULL;
+
+       if (filename == NULL) {
+               filename = g_strdup_printf("%s%csylpheed-crashed",
+                                          get_tmp_dir(), G_DIR_SEPARATOR);
+       }
+
+       return filename;
+}
+
 static gint prohibit_duplicate_launch(void)
 {
        gint uxsock;
index d39ddc9..1063824 100644 (file)
@@ -126,6 +126,9 @@ static struct Compose {
        GtkWidget *checkbtn_smart_wrapping;
        GtkWidget *checkbtn_block_cursor;
        GtkWidget *checkbtn_reply_with_quote;
+       
+       GtkWidget *checkbtn_autosave;
+       GtkWidget *entry_autosave_length;
 } compose;
 
        /* spelling */
@@ -380,6 +383,12 @@ static PrefParam param[] = {
         {"smart_wrapping", "TRUE", &prefs_common.smart_wrapping,
         P_BOOL, &compose.checkbtn_smart_wrapping,
         prefs_set_data_from_toggle, prefs_set_toggle},
+        {"autosave", "FALSE", &prefs_common.autosave,
+        P_BOOL, &compose.checkbtn_autosave,
+        prefs_set_data_from_toggle, prefs_set_toggle},
+        {"autosave_length", "50", &prefs_common.autosave_length,
+        P_INT, &compose.entry_autosave_length,
+        prefs_set_data_from_entry, prefs_set_entry},
 #if USE_ASPELL
        {"enable_aspell", "TRUE", &prefs_common.enable_aspell,
         P_BOOL, &spelling.checkbtn_enable_aspell,
@@ -1717,6 +1726,11 @@ static void prefs_compose_create(void)
        GtkWidget *checkbtn_block_cursor;
        GtkWidget *frame_msgwrap;
 
+       GtkWidget *hbox_autosave;
+       GtkWidget *checkbtn_autosave;
+       GtkWidget *entry_autosave_length;
+       GtkWidget *label_autosave_length;
+       
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox1);
        gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
@@ -1780,6 +1794,23 @@ static void prefs_compose_create(void)
        PACK_CHECK_BUTTON (vbox2, checkbtn_redirect_keep_from,
                           _("Keep the original 'From' header when redirecting"));
 
+       
+       hbox_autosave = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (hbox_autosave);
+       gtk_box_pack_start (GTK_BOX (vbox1), hbox_autosave, FALSE, FALSE, 0);
+       
+       PACK_CHECK_BUTTON (hbox_autosave, checkbtn_autosave,
+                          _("Autosave to drafts every "));
+
+       entry_autosave_length = gtk_entry_new();
+       gtk_widget_set_usize (entry_autosave_length, 64, -1);   
+       gtk_widget_show (entry_autosave_length);
+       gtk_box_pack_start (GTK_BOX (hbox_autosave), entry_autosave_length, FALSE, FALSE, 0);
+       
+       label_autosave_length = gtk_label_new(_("characters"));
+       gtk_widget_show (label_autosave_length);
+       gtk_box_pack_start (GTK_BOX (hbox_autosave), label_autosave_length, FALSE, FALSE, 0);
+       
        hbox_undolevel = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox_undolevel);
        gtk_box_pack_start (GTK_BOX (vbox1), hbox_undolevel, FALSE, FALSE, 0);
@@ -1856,12 +1887,15 @@ static void prefs_compose_create(void)
        compose.spinbtn_undolevel     = spinbtn_undolevel;
        compose.spinbtn_undolevel_adj = spinbtn_undolevel_adj;
 
-       compose.spinbtn_linewrap     = spinbtn_linewrap;
-       compose.spinbtn_linewrap_adj = spinbtn_linewrap_adj;
-       compose.checkbtn_wrapquote   = checkbtn_wrapquote;
-       compose.checkbtn_autowrap    = checkbtn_autowrap;
-       compose.checkbtn_wrapatsend  = checkbtn_wrapatsend;
+       compose.spinbtn_linewrap      = spinbtn_linewrap;
+       compose.spinbtn_linewrap_adj  = spinbtn_linewrap_adj;
+       compose.checkbtn_wrapquote    = checkbtn_wrapquote;
+       compose.checkbtn_autowrap     = checkbtn_autowrap;
+       compose.checkbtn_wrapatsend   = checkbtn_wrapatsend;
 
+       compose.checkbtn_autosave     = checkbtn_autosave;
+       compose.entry_autosave_length = entry_autosave_length;
+       
        compose.checkbtn_forward_as_attachment =
                checkbtn_forward_as_attachment;
        compose.checkbtn_redirect_keep_from =
index fed5e03..7eef3be 100644 (file)
@@ -83,7 +83,9 @@ struct _PrefsCommon
        gboolean forward_account_autosel;
        gboolean reedit_account_autosel;
        gboolean show_ruler;
-
+       gboolean autosave;
+       gint autosave_length;
+       
        /* Quote */
        gboolean reply_with_quote;
        gchar *quotemark;