Make windows inherit from ModestShellWindow in gtk
[modest] / src / widgets / modest-msg-edit-window.h
1 /* Copyright (c) 2006,2007 Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef __MODEST_MSG_EDIT_WINDOW_H__
31 #define __MODEST_MSG_EDIT_WINDOW_H__
32
33 #include <tny-msg.h>
34 #include <tny-vfs-stream.h>
35 #ifdef MODEST_TOOLKIT_HILDON2
36 #include <modest-hildon2-window.h>
37 #else
38 #include <modest-shell-window.h>
39 #endif
40 #include <widgets/modest-window.h>
41
42 G_BEGIN_DECLS
43
44 /* convenience macros */
45 #define MODEST_TYPE_MSG_EDIT_WINDOW             (modest_msg_edit_window_get_type())
46 #define MODEST_MSG_EDIT_WINDOW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_MSG_EDIT_WINDOW,ModestMsgEditWindow))
47 #define MODEST_MSG_EDIT_WINDOW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_MSG_EDIT_WINDOW,ModestWindow))
48 #define MODEST_IS_MSG_EDIT_WINDOW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_MSG_EDIT_WINDOW))
49 #define MODEST_IS_MSG_EDIT_WINDOW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_MSG_EDIT_WINDOW))
50 #define MODEST_MSG_EDIT_WINDOW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_MSG_EDIT_WINDOW,ModestMsgEditWindowClass))
51
52 typedef struct _ModestMsgEditWindow      ModestMsgEditWindow;
53 typedef struct _ModestMsgEditWindowClass ModestMsgEditWindowClass;
54
55 struct _ModestMsgEditWindow {
56 #ifdef MODEST_TOOLKIT_HILDON2
57         ModestHildon2Window parent;
58 #else
59         ModestShellWindow parent;
60 #endif
61         /* insert public members, if any */
62 };
63
64 struct _ModestMsgEditWindowClass {
65 #ifdef MODEST_TOOLKIT_HILDON2
66         ModestHildon2WindowClass parent_class;
67 #else
68         ModestShellWindowClass parent_class;
69 #endif
70         /* insert signal callback declarations, eg. */
71         /* void (* my_event) (ModestMsgEditWindow* obj); */
72 };
73
74 typedef enum  {
75         MODEST_EDIT_TYPE_NEW,
76         MODEST_EDIT_TYPE_REPLY,
77         MODEST_EDIT_TYPE_FORWARD,
78         
79         MODEST_EDIT_TYPE_NUM
80 } ModestEditType;
81
82 typedef enum {
83         MODEST_MSG_EDIT_FORMAT_TEXT,
84         MODEST_MSG_EDIT_FORMAT_HTML
85 } ModestMsgEditFormat;
86
87 typedef enum {
88         MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY,
89         MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_TO,
90         MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_CC,
91         MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BCC,
92         MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_SUBJECT,
93         MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_ATTACHMENTS,
94         MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_NUM,
95 } ModestMsgEditWindowWidgetType;
96
97 /** Get these with modest_msg_edit_window_get_msg_data() 
98  * and free them with modest_msg_edit_window_free_msg_data().
99  */
100 typedef struct  {
101         gchar *from, *to, *cc, *bcc, *subject, *plain_body, *html_body;
102         gchar *references, *in_reply_to;
103         GList *attachments;
104         GList *images;
105         TnyHeaderFlags priority_flags;
106         TnyMsg *draft_msg;
107         gchar *account_name;
108 } MsgData;
109
110 typedef struct {
111         gboolean bold;
112         gboolean italics;
113         gboolean bullet;
114         GdkColor color;
115         const gchar *font_family;
116         gint font_size;
117         GtkJustification justification;
118 } ModestMsgEditFormatState;
119
120
121 /**
122  * modest_msg_edit_window_get_type:
123  * 
124  * get the GType for the #ModestMsgEditWindow class
125  *
126  * Returns: a GType for #ModestMsgEditWindow
127  */
128 GType        modest_msg_edit_window_get_type    (void) G_GNUC_CONST;
129
130
131 /**
132  * modest_msg_edit_window_new:
133  * @msg: a #TnyMsg instance
134  * @account_name: the account this message applies to
135  * @mailbox: the mailbox (if any)
136  * @preserve_is_rich: if @msg is not rich, open the message as plain text
137  * 
138  * instantiates a new #ModestMsgEditWindow widget
139  *
140  * Returns: a new #ModestMsgEditWindow, or NULL in case of error
141  */
142 ModestWindow*   modest_msg_edit_window_new         (TnyMsg *msg, 
143                                                     const gchar *account_name, 
144                                                     const gchar *mailbox,
145                                                     gboolean preserve_is_rich);
146
147
148 /**
149  * modest_msg_edit_window_get_msg_data:
150  * @self: a #ModestMsgEditWindow
151  * 
152  * gets the message data already present in the edit message
153  * window. The message data must be freed with
154  * modest_msg_edit_window_free_msg_data
155  * 
156  * Returns: the message data
157  **/
158 MsgData *               modest_msg_edit_window_get_msg_data          (ModestMsgEditWindow *self);
159
160 /**
161  * modest_msg_edit_window_free_msg_data:
162  * @self: a #ModestMsgEditWindow
163  * @data: 
164  * 
165  * frees the message data passed as argument
166  **/
167 void                    modest_msg_edit_window_free_msg_data         (ModestMsgEditWindow *self,
168                                                                       MsgData *data);
169
170 /**
171  * modest_msg_edit_window_get_format:
172  * @self: a #ModestMsgEditWindow
173  *
174  * obtains the format type of the message body.
175  *
176  * Returns: a #ModestMsgEditFormat
177  **/
178 ModestMsgEditFormat     modest_msg_edit_window_get_format            (ModestMsgEditWindow *self);
179
180 /**
181  * modest_msg_edit_window_set_format:
182  * @self: a #ModestMsgEditWindow
183  * @format: a #ModestMsgEditFormat
184  *
185  * set the @format of the edit window message body.
186  **/
187 void                    modest_msg_edit_window_set_format            (ModestMsgEditWindow *self,
188                                                                       ModestMsgEditFormat format);
189
190 /**
191  * modest_msg_edit_window_get_format_state:
192  * @self: a #ModestMsgEditWindow
193  *
194  * get the current format state (the format attributes the text user inserts
195  * will get).
196  *
197  * Returns: a #ModestMsgEditFormatState structure that should be freed with g_free().
198  **/
199 ModestMsgEditFormatState *modest_msg_edit_window_get_format_state    (ModestMsgEditWindow *self);
200
201 /**
202  * modest_msg_edit_window_set_format_state:
203  * @self: a #ModestMsgEditWindow
204  * @format_state: a #ModestMsgEditWindowFormatState
205  *
206  * sets a new format state (the format attributes the text user inserts 
207  * will get).
208  **/
209 void                    modest_msg_edit_window_set_format_state      (ModestMsgEditWindow *self,
210                                                                       const ModestMsgEditFormatState *format_state);
211
212 /**
213  * modest_msg_edit_window_select_color:
214  * @self: a #ModestMsgEditWindow
215  *
216  * show color selection dialog and update text color
217  */
218 void                    modest_msg_edit_window_select_color          (ModestMsgEditWindow *window);
219
220 /**
221  * modest_msg_edit_window_select_background_color:
222  * @self: a #ModestMsgEditWindow
223  *
224  * show color selection dialog and update background color
225  */
226 void                    modest_msg_edit_window_select_background_color          (ModestMsgEditWindow *window);
227
228 /**
229  * modest_msg_edit_window_insert_image:
230  * @self: a #ModestMsgEditWindow
231  *
232  * show a file selection dialog to insert an image
233  */
234 void                    modest_msg_edit_window_insert_image          (ModestMsgEditWindow *window);
235
236 /**
237  * modest_msg_edit_window_offer_attach_file:
238  * @self: a #ModestMsgEditWindow
239  *
240  * show a file selection dialog to attach a file
241  */
242 void                    modest_msg_edit_window_offer_attach_file           (ModestMsgEditWindow *window);
243
244 /**
245  * modest_msg_edit_window_attach_file_one:
246  * @self: a #ModestMsgEditWindow
247  * @file_uri: The URI of a file to attach to the email message.
248  * @allowed_size: max size allowed for this attachment, 0 for unlimited
249  *
250  * attach a file to a MsgEditWindow non interactively, 
251  * without file dialog. This is needed by dbus callbacks.
252  *
253  * Returns: the filesize (if available)
254  */
255 GnomeVFSFileSize modest_msg_edit_window_attach_file_one           (ModestMsgEditWindow *window, const gchar *file_uri, GnomeVFSFileSize allowed_size);
256
257 /**
258  * modest_msg_edit_window_remove_attachments:
259  * @self: a #ModestMsgEditWindow
260  * @att_list: a #GList of #TnyMimePart
261  *
262  * remove attachments in @att_list, with a confirmation dialog
263  */
264 void                    modest_msg_edit_window_remove_attachments    (ModestMsgEditWindow *window, 
265                                                                       TnyList *att_list);
266
267 /**
268  * modest_msg_edit_window_get_parts_size:
269  * @window: a #ModestMsgEditWindow
270  * @parts_count: number of attachments and images attached to the message
271  * @parts_size: sum of sizes of attachments and images
272  */
273 void                    modest_msg_edit_window_get_parts_size (ModestMsgEditWindow *window,
274                                                                gint *parts_count,
275                                                                guint64 *parts_size);
276 /**
277  * modest_msg_edit_window_add_part:
278  * @self: a #ModestMsgEditWindow
279  * @part: a #TnyMimePart
280  *
281  * Adds @part as an attachment
282  */
283 void                    modest_msg_edit_window_add_part (ModestMsgEditWindow *window,
284                                                          TnyMimePart *part);
285
286 /**
287  * modest_msg_edit_window_show_cc:
288  * @window: a #ModestMsgEditWindow
289  * @show: a #gboolean
290  *
291  * Set the CC field as visible (or not visible) depending on @show
292  */
293 void                    modest_msg_edit_window_show_cc               (ModestMsgEditWindow *window, gboolean show);
294
295 /**
296  * modest_msg_edit_window_show_bcc:
297  * @window: a #ModestMsgEditWindow
298  * @show: a #gboolean
299  *
300  * Set the BCC field as visible (or not visible) depending on @show
301  */
302 void                    modest_msg_edit_window_show_bcc               (ModestMsgEditWindow *window, gboolean show);
303
304 /**
305  * modest_msg_edit_window_set_priority_flags:
306  * @window: a #ModestMsgEditWindow
307  * @priority_flags: a #TnyHeaderFlags with priority information
308  *
309  * Updates the icon and priority flag to send.
310  */
311 void            modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window,
312                                                            TnyHeaderFlags priority_flags);
313
314 /**
315  * modest_msg_edit_window_set_file_format:
316  * @window: a #ModestMsgEditWindow
317  * @file_format: %MODEST_FILE_FORMAT_PLAIN_TEXT or %MODEST_FILE_FORMAT_FORMATTED_TEXT
318  *
319  * Changes the current file format.
320  */
321 void            modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window,
322                                                         gint file_format);
323
324 /**
325  * modest_msg_edit_window_select_font:
326  * @window: a #ModestMsgEditWindow
327  *
328  * Show the dialog to select the editor font and update the
329  * used font in the editor.
330  */
331 void            modest_msg_edit_window_select_font        (ModestMsgEditWindow *window);
332
333 /**
334  * modest_msg_edit_window_undo:
335  * @window: a #ModestMsgEditWindow
336  *
337  * Undoes the last operation.
338  */
339 void            modest_msg_edit_window_undo               (ModestMsgEditWindow *window);
340
341 /**
342  * modest_msg_edit_window_can_undo:
343  * @window: a #ModestMsgEditWindow
344  *
345  * Checks if an undo operation is available
346  *
347  * Returns: %TRUE if undo can be done, %FALSE otherwise.
348  */
349 gboolean            modest_msg_edit_window_can_undo               (ModestMsgEditWindow *window);
350
351 /**
352  * modest_msg_edit_window_redo:
353  * @window: a #ModestMsgEditWindow
354  *
355  * Revert last undo
356  */
357 void            modest_msg_edit_window_redo               (ModestMsgEditWindow *window);
358
359 /**
360  * modest_msg_edit_window_can_redo:
361  * @window: a #ModestMsgEditWindow
362  *
363  * Checks if a redp operation is available
364  *
365  * Returns: %TRUE if redo can be done, %FALSE otherwise.
366  */
367 gboolean            modest_msg_edit_window_can_redo               (ModestMsgEditWindow *window);
368
369 /**
370  * modest_msg_edit_window_select_contacts:
371  * @window: a #ModestMsgEditWindow
372  *
373  * Shows the dialog to add contacts to the currently focused recipient list,
374  * or to To: recipient if no recipient list is focused.
375  */
376 void            modest_msg_edit_window_select_contacts    (ModestMsgEditWindow *window);
377
378 /**
379  * modest_msg_edit_window_add_to_contacts:
380  * @self: a #ModestMsgEditWindow
381  *
382  * activates the add to contacts use. It shows the add to contacts
383  * dialog to select the recipient to add.
384  */
385 void            modest_msg_edit_window_add_to_contacts     (ModestMsgEditWindow *self);
386
387 /**
388  * modest_msg_edit_window_check_names:
389  * @window: a #ModestMsgEditWindow
390  * @add_to_addressbook: if TRUE, add valid addresses to the addressbook
391  *
392  * Validates all the recipients, and shows (if required) dialogs for adding contacts
393  * or fixing problems in specific fields.
394  *
395  * Returns: %TRUE if all fields were validated, %FALSE otherwise
396  */
397 gboolean        modest_msg_edit_window_check_names    (ModestMsgEditWindow *window,
398                                                        gboolean add_to_addressbook);
399
400 /**
401  * modest_msg_edit_window_has_pending_addresses:
402  * @window: a #ModestMsgEditWindow
403  * @add_to_addressbook: if TRUE, add valid addresses to the addressbook
404  *
405  * Validates all the recipients, and checks if there are addresses in
406  * any field that could be added to the addressbook
407  *
408  * Returns: %TRUE if there are valid pending addresses, %FALSE otherwise
409  */
410 gboolean        modest_msg_edit_window_has_pending_addresses    (ModestMsgEditWindow *window);
411
412 /**
413  * modest_msg_edit_window_toggle_isearch_toolbar:
414  * @window: a #ModestMsgEditWindow
415  * @show: a #gboolean
416  *
417  * Shows/Hides the isearch toolbar
418  */
419 void            modest_msg_edit_window_toggle_isearch_toolbar (ModestMsgEditWindow *window,
420                                                                gboolean show);
421
422
423 /**
424  * modest_msg_edit_window_is_modified:
425  * @window: a #ModestMsgEditWindow
426  *
427  * Examines whether or not the message has been modified
428  *
429  * Returns: %TRUE if any field has been modified, %FALSE otherwise
430  */
431 gboolean        modest_msg_edit_window_is_modified         (ModestMsgEditWindow *window);
432
433 /**
434  * modest_msg_edit_window_reset_modified:
435  * @window: a #ModestMsgEditWindow
436  * @modified: wheter or not we want to make the buffer as modified or not
437  *
438  * Sets the message as modified or not
439  */
440 void            modest_msg_edit_window_set_modified      (ModestMsgEditWindow *window,
441                                                           gboolean modified);
442
443
444 gboolean        modest_msg_edit_window_get_sent            (ModestMsgEditWindow *window);
445 void            modest_msg_edit_window_set_sent            (ModestMsgEditWindow *window, 
446                                                             gboolean sent);
447
448 /**
449  * modest_msg_edit_window_set_draft:
450  * @window: a #ModestMsgEditWindow
451  * @draft: a #TnyMsg, or %NULL
452  *
453  * Set @draft as the original draft message of the editor. This
454  * message will be removed on saving or sending the message.
455  */
456 void            modest_msg_edit_window_set_draft           (ModestMsgEditWindow *window,
457                                                             TnyMsg *draft);
458 /**
459  * modest_msg_edit_window_get_message_uid:
460  * @msg: an #ModestMsgEditWindow instance
461  * 
462  * gets the unique identifier for the message in this msg editor.
463  * This is the identifier of the draft or outbox message the editor was
464  * opened from. If it's a new message, then it returns %NULL
465  * 
466  * Returns: the id of the #TnyMsg being shown, or NULL in case of error
467  */
468 const gchar*    modest_msg_edit_window_get_message_uid (ModestMsgEditWindow *window);
469
470 /**
471  * modest_msg_edit_window_get_child_widget:
472  * @win: a #ModestMsgEditWindow
473  * @widget_type: the type of the child to obtain
474  *
475  * Obtain the child widget of @win of type @widget_type
476  *
477  * Returns: a #GtkWidget, or %NULL
478  */
479 GtkWidget *
480 modest_msg_edit_window_get_child_widget (ModestMsgEditWindow *win,
481                                          ModestMsgEditWindowWidgetType widget_type);
482
483 /**
484  * modest_msg_edit_window_get_clipboard_text:
485  * @win: a #ModestMsgEditWindow
486  *
487  * Obtains the currently selected text in selection clipboard
488  *
489  * Returns: a string
490  */
491 const gchar *
492 modest_msg_edit_window_get_clipboard_text (ModestMsgEditWindow *win);
493
494 G_END_DECLS
495
496 #endif /* __MODEST_MSG_EDIT_WINDOW_H__ */