Rework and simplify how compose_queue() return values are handled
[claws.git] / src / compose.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifndef __COMPOSE_H__
21 #define __COMPOSE_H__
22
23 typedef struct _Compose         Compose;
24 typedef struct _AttachInfo      AttachInfo;
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28
29 #include "procmsg.h"
30 #include "procmime.h"
31 #include "prefs_account.h"
32 #include "undo.h"
33 #include "toolbar.h"
34 #include "codeconv.h"
35 #include "template.h"
36 #include "viewtypes.h"
37 #include "folder.h"
38
39 #ifdef USE_ENCHANT
40 #include "gtkaspell.h"
41 #endif
42
43 #define COMPOSE_CHECK_BEFORE_SEND_HOOKLIST "compose_check_before_send"
44 #define COMPOSE_CREATED_HOOKLIST "compose_created"
45
46 typedef enum
47 {
48         COMPOSE_TO,
49         COMPOSE_CC,
50         COMPOSE_BCC,
51         COMPOSE_REPLYTO,
52         COMPOSE_NEWSGROUPS,
53         COMPOSE_FOLLOWUPTO,
54         COMPOSE_INREPLYTO
55 } ComposeEntryType;
56
57 typedef enum
58 {
59         COMPOSE_REPLY,
60         COMPOSE_REPLY_WITH_QUOTE,
61         COMPOSE_REPLY_WITHOUT_QUOTE,
62         COMPOSE_REPLY_TO_SENDER,
63         COMPOSE_REPLY_TO_ADDRESS,
64         COMPOSE_FOLLOWUP_AND_REPLY_TO,
65         COMPOSE_REPLY_TO_SENDER_WITH_QUOTE,
66         COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
67         COMPOSE_REPLY_TO_ALL,
68         COMPOSE_REPLY_TO_ALL_WITH_QUOTE,
69         COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
70         COMPOSE_REPLY_TO_LIST,
71         COMPOSE_REPLY_TO_LIST_WITH_QUOTE,
72         COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
73         COMPOSE_FORWARD,
74         COMPOSE_FORWARD_AS_ATTACH,
75         COMPOSE_FORWARD_INLINE,
76         COMPOSE_NEW,
77         COMPOSE_REDIRECT,
78         COMPOSE_REEDIT
79 } ComposeMode;
80
81 typedef enum
82 {
83         COMPOSE_QUEUE_SUCCESS = 0,
84         COMPOSE_QUEUE_ERROR_NO_MSG = -1,
85         COMPOSE_QUEUE_ERROR_WITH_ERRNO = -2,
86         COMPOSE_QUEUE_ERROR_SIGNING_FAILED = -3,
87         COMPOSE_QUEUE_ERROR_ENCRYPT_FAILED = -4,
88         COMPOSE_QUEUE_ERROR_CHAR_CONVERSION = -5,
89         COMPOSE_QUEUE_ERROR_NO_ENCRYPTION_KEY = -6
90 } ComposeQueueResult;
91
92 typedef enum {
93         PREF_ACCOUNT,
94         PREF_FOLDER,
95         PREF_TEMPLATE,
96         PREF_ML,
97         PREF_MAILTO,
98         PREF_NONE
99 } ComposePrefType;
100
101 typedef struct {
102         guint headernum;
103         Compose *compose;
104         GtkWidget *combo;
105         GtkWidget *entry;
106         GtkWidget *button;
107         GtkWidget *hbox;
108         ComposePrefType type;
109 } ComposeHeaderEntry;
110
111 struct _Compose
112 {
113         /* start with window widget don`t change order */
114         GtkWidget *window;
115         GtkWidget *vbox;
116         GtkWidget *menubar;
117
118         /* Toolbar handlebox */
119         GtkWidget *handlebox;
120         Toolbar *toolbar;
121         
122         GtkWidget *vbox2;
123
124         /* Header */
125         GtkWidget *table_vbox;
126         GtkWidget *table;
127         GtkWidget *account_combo;
128         GtkWidget *subject_entry;
129         GtkWidget *paned;
130
131         /* Attachments */
132         GtkWidget *attach_scrwin;
133         GtkWidget *attach_clist;
134         GtkWidget *attach_label;
135
136         /* Others */
137         GtkWidget *savemsg_checkbtn;
138         GtkWidget *savemsg_combo;
139
140         /* Headers notebook */
141         GtkWidget *notebook;
142
143         /* Textedit */
144         GtkWidget *edit_vbox;
145         GtkWidget *ruler_hbox;
146         GtkWidget *ruler;
147         GtkWidget *scrolledwin;
148         GtkWidget *text;
149         GtkWidget *from_name;
150
151         GtkWidget *focused_editable;
152
153         GtkWidget *popupmenu;
154
155         GtkWidget *tmpl_menu;
156
157         ComposeMode mode;
158
159         MsgInfo *targetinfo;
160         MsgInfo *replyinfo;
161         MsgInfo *autosaved_draft;
162         MsgInfo *fwdinfo;
163
164         GtkWidget *header_table;
165         GSList    *header_list;
166         guint      header_nextrow;
167         ComposeHeaderEntry *header_last;
168
169         GHashTable *email_hashtable;
170
171         gchar   *replyto;
172         gchar   *cc;
173         gchar   *bcc;
174         gchar   *newsgroups;
175         gchar   *followup_to;
176
177         gchar   *ml_post;
178
179         gchar   *inreplyto;
180         gchar   *references;
181         gchar   *msgid;
182         gchar   *boundary;
183
184         gboolean autowrap;
185         gboolean autoindent;
186
187         gboolean use_to;
188         gboolean use_cc;
189         gboolean use_bcc;
190         gboolean use_replyto;
191         gboolean use_newsgroups;
192         gboolean use_followupto;
193         gboolean use_attach;
194
195         CharSet out_encoding;
196
197         /* privacy settings */
198         gboolean use_signing;
199         gboolean use_encryption;
200         gchar *privacy_system;
201         gchar *encdata;
202
203         gboolean modified;
204
205         gboolean sending;
206         
207         gboolean return_receipt;
208
209         gboolean batch;
210         
211         GSList *to_list;
212         GSList *newsgroup_list;
213
214         PrefsAccount *account;
215         FolderItem *folder;
216
217         UndoMain *undostruct;
218
219         gchar *sig_str;
220         gboolean sig_inserted;
221
222         /* external editor */
223         gchar      *exteditor_file;
224         pid_t       exteditor_pid;
225         GIOChannel *exteditor_ch;
226         gint        exteditor_tag;
227         GtkWidget  *exteditor_socket;
228
229         /* Priority */
230         gint priority;
231
232         gchar *redirect_filename;
233         
234         gboolean remove_references;
235
236         gint64 draft_timeout_tag;
237         
238         GtkTextTag *no_wrap_tag;
239         GtkTextTag *no_join_tag;
240         GtkTextTag *signature_tag;
241         GtkTextTag *quote0_tag;
242         GtkTextTag *quote1_tag;
243         GtkTextTag *quote2_tag;
244         GtkTextTag *uri_tag;
245
246         gboolean automatic_break;
247         GMutex *mutex;
248         gint close_timeout_tag;
249         gchar *orig_charset;
250         gint set_cursor_pos;
251
252         gboolean updating;
253         gboolean deferred_destroy;
254         ComposeMode rmode;
255         GtkWidget *first_combo;
256         GtkWidget *first_entry;
257
258         GtkUIManager *ui_manager;
259
260         gint folder_update_callback_id;
261 #if USE_ENCHANT
262         /* GNU/aspell spell checker */
263         GtkAspell *gtkaspell;
264         GtkWidget *aspell_options_menu;
265 #endif
266
267 #ifdef USE_LDAP
268         /* List of addressbook ifaces which we disabled, and will
269          * enable in compose_destroy. */
270         GSList *passworded_ldap_servers;
271 #endif
272 };
273
274 struct _AttachInfo
275 {
276         gchar *file;
277         gchar *content_type;
278         EncodingType encoding;
279         gchar *name;
280         goffset size;
281         gchar *charset;
282         gboolean insert;
283 };
284
285 typedef enum
286 {
287         COMPOSE_QUIT_EDITING,
288         COMPOSE_KEEP_EDITING,
289         COMPOSE_AUTO_SAVE,
290         COMPOSE_DRAFT_FOR_EXIT
291 } ComposeDraftAction;
292
293 /*#warning FIXME_GTK2 */
294 /* attach_files will be locale encode */
295 Compose *compose_new                    (PrefsAccount   *account,
296                                          const gchar    *mailto,
297                                          GList          *attach_files);
298
299 Compose *compose_new_with_folderitem    (PrefsAccount   *account,
300                                          FolderItem     *item,
301                                          const gchar    *mailto);
302
303 Compose *compose_new_with_list          (PrefsAccount   *account,
304                                          GList          *listAddress);
305
306 Compose *compose_forward                (PrefsAccount *account,
307                                          MsgInfo        *msginfo,
308                                          gboolean        as_attach,
309                                          const gchar    *body,
310                                          gboolean        no_extedit,
311                                          gboolean        batch);
312
313 Compose *compose_redirect               (PrefsAccount   *account,
314                                          MsgInfo        *msginfo,
315                                          gboolean        batch);
316 Compose *compose_reedit                 (MsgInfo        *msginfo,
317                                          gboolean        batch);
318
319 const GList *compose_get_compose_list   (void);
320
321 void compose_entry_append               (Compose          *compose,
322                                          const gchar      *address,
323                                          ComposeEntryType  type,
324                                          ComposePrefType   pref_type);
325
326
327 gint compose_send                       (Compose          *compose);
328
329 void compose_update_actions_menu        (Compose        *compose);
330 void compose_reflect_prefs_all                  (void);
331 void compose_reflect_prefs_pixmap_theme (void);
332
333 void compose_destroy_all                (void);
334 gboolean compose_draft                  (gpointer data, guint action);
335 void compose_toolbar_cb                 (gint           action, 
336                                          gpointer       data);
337 void compose_reply_to_address           (MessageView    *msgview,
338                                          MsgInfo        *msginfo,
339                                          const gchar    *address);
340 void compose_reply_from_messageview     (MessageView    *msgview, 
341                                          GSList         *msginfo_list, 
342                                          guint           action);
343 void compose_action_cb                  (void           *data);
344
345 void compose_set_position                               (Compose        *compose,
346                                                  gint            pos);
347 gboolean compose_search_string                  (Compose        *compose,
348                                                  const gchar    *str,
349                                                  gboolean        case_sens);
350 gboolean compose_search_string_backward (Compose        *compose,
351                                                  const gchar    *str,
352                                                  gboolean        case_sens);
353 ComposeQueueResult compose_queue        (Compose *compose,
354                                          gint *msgnum, 
355                                          FolderItem **item, 
356                                          gchar **msgpath,
357                                          gboolean remove_reedit_target);
358 gboolean compose_close                  (Compose *compose);
359 void compose_close_toolbar              (Compose *compose);
360 void compose_clear_exit_drafts          (void);
361 void compose_reopen_exit_drafts         (void);
362 void compose_attach_from_list (Compose *compose, GList *file_list, gboolean free_data);
363 void compose_check_for_email_account(Compose *compose);
364
365 void compose_use_signing(Compose *compose, gboolean use_signing);
366 void compose_use_encryption(Compose *compose, gboolean use_encryption);
367
368 #endif /* __COMPOSE_H__ */