In compose window, prevent account selection combobox to get focus when navigating...
[claws.git] / src / compose.c
index 68f29a17546d1ea7bbf26c7bb030e5116293edc6..801697e74b078be71a8c0f3d7101db0f8e15e5b7 100644 (file)
@@ -1206,7 +1206,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                for (curr = attach_files ; curr != NULL ; curr = curr->next) {
                        ainfo = (AttachInfo *) curr->data;
-                       compose_attach_append(compose, ainfo->file, ainfo->name,
+                       compose_attach_append(compose, ainfo->file, ainfo->file,
                                        ainfo->content_type, ainfo->charset);
                }
        }
@@ -3207,7 +3207,7 @@ static gboolean is_subscription(const gchar *ml_post, const gchar *from)
                *(strstr(left_from, "@")) = '\0';
        }
        
-       if (left_ml && left_from && right_ml && right_from
+       if (right_ml && right_from
        &&  !strncmp(left_from, left_ml, strlen(left_ml))
        &&  !strcmp(right_from, right_ml)) {
                result = TRUE;
@@ -3575,7 +3575,6 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        gint len;
        FILE *fp;
        gboolean prev_autowrap;
-       gboolean badtxt = FALSE;
        struct stat file_stat;
        int ret;
        GString *file_contents = NULL;
@@ -3675,10 +3674,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
        fclose(fp);
 
-       if (badtxt)
-               return COMPOSE_INSERT_INVALID_CHARACTER;
-       else 
-               return COMPOSE_INSERT_SUCCESS;
+       return COMPOSE_INSERT_SUCCESS;
 }
 
 static gboolean compose_attach_append(Compose *compose, const gchar *file,
@@ -5757,8 +5753,11 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
                (tmp, CS_INTERNAL, conv_get_locale_charset_str());
 
        g_free(tmp);
-       if (!chars) return -1;
-
+       if (!chars) {
+               fclose(fp);
+               claws_unlink(file);
+               return -1;
+       }
        /* write body */
        len = strlen(chars);
        if (fwrite(chars, sizeof(gchar), len, fp) != len) {
@@ -6139,13 +6138,14 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
                        }
                        continue;
                }
+               if (g_stat(ainfo->file, &statbuf) < 0)
+                       return -1;
+
                mimepart = procmime_mimeinfo_new();
                mimepart->content = MIMECONTENT_FILE;
                mimepart->data.filename = g_strdup(ainfo->file);
                mimepart->tmp = FALSE; /* or we destroy our attachment */
                mimepart->offset = 0;
-
-               g_stat(ainfo->file, &statbuf);
                mimepart->length = statbuf.st_size;
 
                type = g_strdup(ainfo->content_type);
@@ -6828,9 +6828,6 @@ static void compose_create_header_entry(Compose *compose)
        gboolean standard_header = FALSE;
        GtkListStore *model;
        GtkTreeIter iter;
-#if !(GTK_CHECK_VERSION(2,12,0))
-       GtkTooltips *tips = compose->tooltips;
-#endif
        
        headerentry = g_new0(ComposeHeaderEntry, 1);
 
@@ -7375,8 +7372,9 @@ static void compose_dict_changed(void *data)
 {
        Compose *compose = (Compose *) data;
 
-       if(compose->gtkaspell && 
-                  compose->gtkaspell->recheck_when_changing_dict == FALSE)
+       if(!compose->gtkaspell)
+               return; 
+       if(compose->gtkaspell->recheck_when_changing_dict == FALSE)
                return;
 
        gtkaspell_highlight_all(compose->gtkaspell);
@@ -7456,10 +7454,6 @@ static Compose *compose_create(PrefsAccount *account,
        compose->mutex = cm_mutex_new();
        compose->set_cursor_pos = -1;
 
-#if !(GTK_CHECK_VERSION(2,12,0))
-       compose->tooltips = tips;
-#endif
-
        window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "compose");
 
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
@@ -8053,9 +8047,6 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
        GtkListStore *menu;
        GtkTreeIter iter;
        GtkWidget *from_name = NULL;
-#if !(GTK_CHECK_VERSION(2,12,0))
-       GtkTooltips *tips = compose->tooltips;
-#endif
 
        gint num = 0, def_menu = 0;
        
@@ -8110,6 +8101,11 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
 
        gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
+
+       GList *l = NULL;
+       l = g_list_prepend(l, from_name);
+       gtk_container_set_focus_chain(GTK_CONTAINER(hbox), l);
+       g_list_free(l);
        
        CLAWS_SET_TIP(optmenubox,
                _("Account to use for this email"));
@@ -8690,6 +8686,7 @@ static void compose_destroy(Compose *compose)
                compose->deferred_destroy = TRUE;
                return;
        }
+
        /* NOTE: address_completion_end() does nothing with the window
         * however this may change. */
        address_completion_end(compose->window);
@@ -8923,7 +8920,7 @@ static void compose_attach_property(GtkAction *action, gpointer data)
                gtk_widget_hide(attach_prop.window);
                gtk_window_set_modal(GTK_WINDOW(attach_prop.window), FALSE);
                
-               if (cancelled) 
+               if (cancelled)
                        break;
 
                entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
@@ -9529,7 +9526,7 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
 
        /* Get ID of active account in the combo box */
        menu = gtk_combo_box_get_model(optmenu);
-       gtk_combo_box_get_active_iter(optmenu, &iter);
+       cm_return_if_fail(gtk_combo_box_get_active_iter(optmenu, &iter));
        gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
 
        ac = account_find_from_id(account_id);
@@ -9781,7 +9778,7 @@ gboolean compose_draft (gpointer data, guint action)
                debug_print("couldn't lock mutex, probably sending\n");
                return FALSE;
        }
-       
+
        lock = TRUE;
 
        tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
@@ -11073,10 +11070,6 @@ static gboolean completion_set_focus_to_subject
                                         GdkEventKey  *event,
                                         Compose      *compose)
 {
-       GtkTextBuffer *buffer;
-       GtkTextMark *mark;
-       GtkTextIter iter;
-
        cm_return_val_if_fail(compose != NULL, FALSE);
 
        /* make backtab move to subject field */
@@ -11084,25 +11077,6 @@ static gboolean completion_set_focus_to_subject
                gtk_widget_grab_focus(compose->subject_entry);
                return TRUE;
        }
-
-       // Up key should also move the focus to subject field, if the cursor
-       // is on the first line.
-       if ((event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_KP_Up)
-         && (event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK)) == 0) {
-               buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
-               g_return_val_if_fail(buffer != NULL, FALSE);
-
-               mark = gtk_text_buffer_get_mark(buffer, "insert");
-               g_return_val_if_fail(mark != NULL, FALSE);
-
-               gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
-
-               if (gtk_text_iter_get_line(&iter) == 0) {
-                       gtk_widget_grab_focus(compose->subject_entry);
-                       return TRUE;
-               }
-       }
-
        return FALSE;
 }
 
@@ -11191,10 +11165,7 @@ static void compose_insert_drag_received_cb (GtkWidget         *widget,
                g_list_free(list);
                gtk_drag_finish(drag_context, TRUE, FALSE, time);
                return;
-       } else {
-               return;
        }
-       gtk_drag_finish(drag_context, TRUE, FALSE, time);
 }
 
 static void compose_header_drag_received_cb (GtkWidget         *widget,
@@ -11562,13 +11533,12 @@ gboolean compose_close(Compose *compose)
                                g_timeout_add (500, (GSourceFunc) compose_close,
                                compose);
                }
-               return FALSE;
+               return TRUE;
        }
-       
-       if (compose->close_timeout_tag) {
-               /* let the close be done by the deferred callback */
-               g_mutex_unlock(compose->mutex);
-               return FALSE;
+
+       if (compose->draft_timeout_tag >= 0) {
+               g_source_remove(compose->draft_timeout_tag);
+               compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_FORBIDDEN;
        }
 
        gtkut_widget_get_uposition(compose->window, &x, &y);