0.8.6claws96
[claws.git] / src / compose.c
index 7c08e2a0185e108f52de25c03364398163c9e8b3..9a51d6c64467248c3b9817168a2bc3d346ee3f79 100644 (file)
@@ -315,11 +315,9 @@ static void toolbar_linewrap_cb            (GtkWidget      *widget,
                                         gpointer        data);
 static void toolbar_address_cb         (GtkWidget      *widget,
                                         gpointer        data);
-static void toolbar_actions_execute_cb  (GtkWidget      *widget,
-                                        gpointer        data);
 static void toolbar_compose_buttons_cb  (GtkWidget      *widget, 
 
-                                        ToolbarItem    *t_item);
+                                        ToolbarItem    *item);
 static void account_activated          (GtkMenuItem    *menuitem,
                                         gpointer        data);
 
@@ -949,8 +947,6 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
                compose_exec_ext_editor(compose);
 }
 
-static void set_toolbar_style(Compose *compose);
-
 #define INSERT_FW_HEADER(var, hdr) \
 if (msginfo->var && *msginfo->var) { \
        gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
@@ -1017,7 +1013,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
                        msgfile = procmsg_get_message_file_path(msginfo);
                        if (!is_file_exist(msgfile))
-                               g_warning(_("%s: file not exist\n"), msgfile);
+                               g_warning("%s: file not exist\n", msgfile);
                        else
                                compose_attach_append(compose, msgfile, msgfile,
                                                      "message/rfc822");
@@ -1118,7 +1114,7 @@ Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
        for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
                msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
                if (!is_file_exist(msgfile))
-                       g_warning(_("%s: file not exist\n"), msgfile);
+                       g_warning("%s: file not exist\n", msgfile);
                else
                        compose_attach_append(compose, msgfile, msgfile,
                                "message/rfc822");
@@ -1164,11 +1160,11 @@ void compose_reedit(MsgInfo *msginfo)
 
                /* Select Account from queue headers */
                if (!get_header_from_msginfo(msginfo, queueheader_buf, 
-                                            sizeof(queueheader_buf), "H_X_SYLPHEED_ACCOUNT_ID:")) {
-                       id = atoi(&queueheader_buf[5]);
+                                            sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
+                       id = atoi(&queueheader_buf[22]);
                        account = account_find_from_id(id);
                }
-               if (!get_header_from_msginfo(msginfo, queueheader_buf, 
+               if (!account && !get_header_from_msginfo(msginfo, queueheader_buf, 
                                             sizeof(queueheader_buf), "NAID:")) {
                        id = atoi(&queueheader_buf[5]);
                        account = account_find_from_id(id);
@@ -1219,7 +1215,7 @@ void compose_reedit(MsgInfo *msginfo)
        gtk_stext_freeze(text);
 
        if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
-               g_warning(_("Can't get text part\n"));
+               g_warning("Can't get text part\n");
        else {
                while (fgets(buf, sizeof(buf), fp) != NULL) {
                        strcrchomp(buf);
@@ -1911,11 +1907,11 @@ static void compose_attach_append(Compose *compose, const gchar *file,
        gint row;
 
        if (!is_file_exist(file)) {
-               g_warning(_("File %s doesn't exist\n"), file);
+               g_warning("File %s doesn't exist\n", file);
                return;
        }
        if ((size = get_file_size(file)) < 0) {
-               g_warning(_("Can't get file size of %s\n"), file);
+               g_warning("Can't get file size of %s\n", file);
                return;
        }
        if (size == 0) {
@@ -2027,7 +2023,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                }
                outfile = procmime_get_tmp_file_name(child);
                if (procmime_get_part(outfile, infile, child) < 0)
-                       g_warning(_("Can't get the part of multipart message."));
+                       g_warning("Can't get the part of multipart message.");
                else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
                        compose_attach_append
                                (compose, outfile,
@@ -2873,7 +2869,7 @@ gint compose_send(Compose *compose)
        }
 
        if (!compose->to_list && !compose->newsgroup_list) {
-               g_warning(_("can't get recipient list."));
+               g_warning("can't get recipient list.");
                unlink(tmp);
                lock = FALSE;
                return -1;
@@ -2905,7 +2901,6 @@ gint compose_send(Compose *compose)
                ac = compose->account;
 
                ok = send_message(tmp, ac, compose->to_list);
-               statusbar_pop_all();
        }
 
        if (ok == 0 && compose->newsgroup_list) {
@@ -3087,7 +3082,7 @@ static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
        /* chmod for security */
        if (change_file_mode_rw(fdest, file) < 0) {
                FILE_OP_ERROR(file, "chmod");
-               g_warning(_("can't change file mode\n"));
+               g_warning("can't change file mode\n");
        }
 
        while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
@@ -3240,7 +3235,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        /* chmod for security */
        if (change_file_mode_rw(fp, file) < 0) {
                FILE_OP_ERROR(file, "chmod");
-               g_warning(_("can't change file mode\n"));
+               g_warning("can't change file mode\n");
        }
 
        /* get all composed text */
@@ -3339,7 +3334,7 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        /* write headers */
        if (compose_write_headers
                (compose, fp, out_codeset, encoding, is_draft) < 0) {
-               g_warning(_("can't write headers\n"));
+               g_warning("can't write headers\n");
                fclose(fp);
                /* unlink(file); */
                g_free(buf);
@@ -3440,7 +3435,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
        /* chmod for security */
        if (change_file_mode_rw(fp, file) < 0) {
                FILE_OP_ERROR(file, "chmod");
-               g_warning(_("can't change file mode\n"));
+               g_warning("can't change file mode\n");
        }
 
        chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
@@ -3479,7 +3474,7 @@ static gint compose_remove_reedit_target(Compose *compose)
        if (procmsg_msg_exist(msginfo) &&
            (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
                if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
-                       g_warning(_("can't remove the old message\n"));
+                       g_warning("can't remove the old message\n");
                        return -1;
                }
        }
@@ -3526,7 +3521,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
 
        if (!compose->to_list && !compose->newsgroup_list) {
-               g_warning(_("can't get recipient list."));
+               g_warning("can't get recipient list.");
                lock = FALSE;
                 return -1;
         }
@@ -3594,7 +3589,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
        if (change_file_mode_rw(fp, tmp) < 0) {
                FILE_OP_ERROR(tmp, "chmod");
-               g_warning(_("can't change file mode\n"));
+               g_warning("can't change file mode\n");
        }
 
        /* queueing variables */
@@ -3686,14 +3681,14 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
 
        queue = account_get_special_folder(compose->account, F_QUEUE);
        if (!queue) {
-               g_warning(_("can't find queue folder\n"));
+               g_warning("can't find queue folder\n");
                unlink(tmp);
                g_free(tmp);
                return -1;
        }
        folder_item_scan(queue);
        if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
-               g_warning(_("can't queue the message\n"));
+               g_warning("can't queue the message\n");
                unlink(tmp);
                g_free(tmp);
                return -1;
@@ -3736,7 +3731,7 @@ static void compose_write_attach(Compose *compose, FILE *fp)
                gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
 
                if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
-                       g_warning(_("Can't open file %s\n"), ainfo->file);
+                       g_warning("Can't open file %s\n", ainfo->file);
                        continue;
                }
 
@@ -3902,6 +3897,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
 
        /* Save draft infos */
        if (is_draft) {
+               fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
                fprintf(fp, "S:%s\n", compose->account->address);
                if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
                        gchar *savefolderid;
@@ -4109,10 +4105,6 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                        procmime_get_encoding_str(encoding));
        }
 
-       /* X-Sylpheed header */
-       if (is_draft)
-               fprintf(fp, "X-Sylpheed-Account-Id: %d\n",
-                       compose->account->account_id);
        /* PRIORITY */
        switch (compose->priority) {
                case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
@@ -5007,7 +4999,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        activate_gnupg_mode(compose, account);
 #endif 
 
-       set_toolbar_style(compose);
+       common_toolbar_set_style(compose, TOOLBAR_COMPOSE);
 
        gtk_widget_show(window);
        
@@ -5015,32 +5007,33 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 }
 
 static void toolbar_compose_buttons_cb(GtkWidget   *widget, 
-                                      ToolbarItem *t_item)
+                                      ToolbarItem *item)
 {
        struct {
                gint   index;
                void (*func)(GtkWidget *widget, gpointer data);
        } compose_action[] = {
-               { A_SEND,        toolbar_send_cb            },
-               { A_SENDL,       toolbar_send_later_cb      },
-               { A_DRAFT,       toolbar_draft_cb           },
-               { A_INSERT,      toolbar_insert_cb          },
-               { A_ATTACH,      toolbar_attach_cb          },
-               { A_SIG,         toolbar_sig_cb             },
-               { A_EXTEDITOR,   toolbar_ext_editor_cb      },
-               { A_LINEWRAP,    toolbar_linewrap_cb        },
-               { A_ADDRBOOK,    toolbar_address_cb         },
-               { A_SYL_ACTIONS, toolbar_actions_execute_cb }};
+               { A_SEND,        toolbar_send_cb                        },
+               { A_SENDL,       toolbar_send_later_cb                  },
+               { A_DRAFT,       toolbar_draft_cb                       },
+               { A_INSERT,      toolbar_insert_cb                      },
+               { A_ATTACH,      toolbar_attach_cb                      },
+               { A_SIG,         toolbar_sig_cb                         },
+               { A_EXTEDITOR,   toolbar_ext_editor_cb                  },
+               { A_LINEWRAP,    toolbar_linewrap_cb                    },
+               { A_ADDRBOOK,    toolbar_address_cb                     },
+               { A_SYL_ACTIONS, common_toolbar_actions_execute_cb      }};
 
 
        gint num_items = sizeof(compose_action)/sizeof(compose_action[0]);
        gint i;
-       debug_print("_buttons: index: %i \n", t_item->index);
        for (i = 0; i < num_items; i++) {
                
-               if (compose_action[i].index == t_item->index) {
-                       Compose *compose = (Compose*)t_item->parent;
-                       debug_print("_buttons: compose: %p toolbar: %p\n", compose, compose->toolbar);                  compose_action[i].func(widget, compose);
+               if (compose_action[i].index == item->index) {
+                       if (item->index == A_SYL_ACTIONS)
+                               compose_action[i].func(widget, (gpointer)item->parent);
+                       else /* this won`t be necessary if everything is moved to toolbar.c */
+                               compose_action[i].func(widget, (gpointer)item->parent->data);
                        break;
                }
        }
@@ -5062,8 +5055,8 @@ static void compose_toolbar_update(Compose *compose)
        compose->toolbar->linewrap_btn  = NULL; 
        compose->toolbar->addrbook_btn  = NULL; 
 
-       TOOLBAR_DESTROY_ITEMS(compose->toolbar->t_item_list);   
-       TOOLBAR_DESTROY_ACTIONS(compose->toolbar->t_action_list);
+       TOOLBAR_DESTROY_ITEMS(compose->toolbar->item_list);     
+       TOOLBAR_DESTROY_ACTIONS(compose->toolbar->action_list);
        compose_toolbar_create(compose, compose->handlebox);    
 }
 
@@ -5076,22 +5069,15 @@ static void compose_toolbar_create(Compose   *compose,
        GtkWidget *icon_wid  = NULL;
        GtkWidget *item;
        GtkTooltips *toolbar_tips;
-       ToolbarSylpheedActions *t_action_item;
+       ToolbarSylpheedActions *action_item;
        GSList *cur;
        GSList *toolbar_list;
-       GList *elem;
        toolbar_tips = gtk_tooltips_new();
        
        toolbar_read_config_file(TOOLBAR_COMPOSE);
        toolbar_list = toolbar_get_list(TOOLBAR_COMPOSE);
 
-       compose->toolbar = g_new0(ComposeToolbar, 1); 
-       
-       for (elem = compose_list; elem != NULL; elem = elem->next) {
-               Compose *c = (Compose*)elem->data;
-               debug_print("toolbar_create: compose: %p toolbar: %p\n", 
-                           c, c->toolbar);
-       }
+       compose->toolbar = g_new0(Toolbar, 1); 
        
        toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
                                  GTK_TOOLBAR_BOTH);
@@ -5113,11 +5099,13 @@ static void compose_toolbar_create(Compose   *compose,
                toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
                toolbar_item->index = ((ToolbarItem*)cur->data)->index;
 
-               toolbar_item->parent = (gpointer)compose;
+               toolbar_item->parent = g_new0(ToolbarParent, 1);
+               toolbar_item->parent->data = (gpointer)compose;
+               toolbar_item->parent->type = TOOLBAR_COMPOSE;
 
                /* collect toolbar items in list to keep track */
-               compose->toolbar->t_item_list = g_slist_append(compose->toolbar->t_item_list, 
-                                                             toolbar_item);
+               compose->toolbar->item_list = g_slist_append(compose->toolbar->item_list, 
+                                                            toolbar_item);
 
                icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
                item  = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
@@ -5183,17 +5171,17 @@ static void compose_toolbar_create(Compose   *compose,
                                             _("Address book"), NULL);
                        break;
                case A_SYL_ACTIONS:
-                       t_action_item = g_new0(ToolbarSylpheedActions, 1);
-                       t_action_item->widget = item;
-                       t_action_item->name   = g_strdup(toolbar_item->text);
+                       action_item = g_new0(ToolbarSylpheedActions, 1);
+                       action_item->widget = item;
+                       action_item->name   = g_strdup(toolbar_item->text);
 
-                       compose->toolbar->t_action_list = 
-                               g_slist_append(compose->toolbar->t_action_list,
-                                              t_action_item);
+                       compose->toolbar->action_list = 
+                               g_slist_append(compose->toolbar->action_list,
+                                              action_item);
 
                        gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
                                             item,
-                                            t_action_item->name, NULL);
+                                            action_item->name, NULL);
 
                        gtk_widget_show(item);
                        break;
@@ -5209,7 +5197,7 @@ static void compose_toolbar_create(Compose   *compose,
 
 static void compose_toolbar_set_sensitive (Compose * compose, gboolean sensitive)
 {
-       GSList *items = compose->toolbar->t_action_list;
+       GSList *items = compose->toolbar->action_list;
        if (compose->toolbar->send_btn)
                gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
        if (compose->toolbar->sendl_btn)
@@ -5397,7 +5385,7 @@ void compose_reflect_prefs_pixmap_theme(void)
        for (cur = compose_list; cur != NULL; cur = cur->next) {
                compose = (Compose *)cur->data;
                compose_toolbar_update(compose);
-               set_toolbar_style(compose);
+               common_toolbar_set_style(compose, TOOLBAR_COMPOSE);
        }
 }
 
@@ -5508,8 +5496,8 @@ static void compose_destroy(Compose *compose)
 
        gtk_widget_destroy(compose->paned);
 
-       TOOLBAR_DESTROY_ITEMS(compose->toolbar->t_item_list);
-       TOOLBAR_DESTROY_ACTIONS(compose->toolbar->t_action_list);
+       TOOLBAR_DESTROY_ITEMS(compose->toolbar->item_list);
+       TOOLBAR_DESTROY_ACTIONS(compose->toolbar->action_list);
        g_free(compose->toolbar);
        g_free(compose);
 
@@ -5920,7 +5908,7 @@ static gint compose_exec_ext_editor_real(const gchar *file)
                g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
        } else {
                if (prefs_common.ext_editor_cmd)
-                       g_warning(_("External editor command line is invalid: `%s'\n"),
+                       g_warning("External editor command line is invalid: `%s'\n",
                                  prefs_common.ext_editor_cmd);
                g_snprintf(buf, sizeof(buf), def_cmd, file);
        }
@@ -5959,8 +5947,8 @@ static gboolean compose_ext_editor_kill(Compose *compose)
                        if (kill(pgid, SIGTERM) < 0) perror("kill");
                        waitpid(compose->exteditor_pid, NULL, 0);
 
-                       g_warning(_("Terminated process group id: %d"), -pgid);
-                       g_warning(_("Temporary file: %s"),
+                       g_warning("Terminated process group id: %d", -pgid);
+                       g_warning("Temporary file: %s",
                                  compose->exteditor_file);
 
                        compose_set_ext_editor_sensitive(compose, TRUE);
@@ -6017,13 +6005,13 @@ static void compose_input_cb(gpointer data, gint source,
                if (unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '1') {     /* failed */
-               g_warning(_("Couldn't exec external editor\n"));
+               g_warning("Couldn't exec external editor\n");
                if (unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '2') {
-               g_warning(_("Couldn't write to file\n"));
+               g_warning("Couldn't write to file\n");
        } else if (buf[0] == '3') {
-               g_warning(_("Pipe read failed\n"));
+               g_warning("Pipe read failed\n");
        }
 
        close(source);
@@ -6224,14 +6212,6 @@ static void toolbar_address_cb(GtkWidget *widget, gpointer data)
        compose_address_cb(data, 0, NULL);
 }
 
-static void toolbar_actions_execute_cb(GtkWidget *widget,
-                                      gpointer   data)
-{
-       Compose *compose = (Compose*)data;
-
-       toolbar_action_execute(widget, compose->toolbar->t_action_list, data, TOOLBAR_COMPOSE);
-}
-
 static void account_activated(GtkMenuItem *menuitem, gpointer data)
 {
        Compose *compose = (Compose *)data;
@@ -7149,28 +7129,3 @@ static void compose_check_forwards_go(Compose *compose)
 }
 #endif
 
-static void set_toolbar_style(Compose *compose)
-{
-       switch (prefs_common.toolbar_style) {
-       case TOOLBAR_NONE:
-               gtk_widget_hide(compose->handlebox);
-               break;
-       case TOOLBAR_ICON:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
-                                     GTK_TOOLBAR_ICONS);
-               break;
-       case TOOLBAR_TEXT:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
-                                     GTK_TOOLBAR_TEXT);
-               break;
-       case TOOLBAR_BOTH:
-               gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
-                                     GTK_TOOLBAR_BOTH);
-               break;
-       }
-       
-       if (prefs_common.toolbar_style != TOOLBAR_NONE) {
-               gtk_widget_show(compose->handlebox);
-               gtk_widget_queue_resize(compose->handlebox);
-       }
-}