X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fgtk%2Fmodest-main-window.c;h=60ffaea990246699fed408843665acef4bc5c7f9;hb=b28cabc5878650bce571a5d548b4224878c151c7;hp=ab4b0a5c1fc2179cafa523301a973d698b42010a;hpb=1d54dd2435d706f0f82d2a81cd00c1410832a241;p=modest diff --git a/src/gtk/modest-main-window.c b/src/gtk/modest-main-window.c index ab4b0a5..60ffaea 100644 --- a/src/gtk/modest-main-window.c +++ b/src/gtk/modest-main-window.c @@ -27,6 +27,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include +#include + #include #include @@ -39,6 +43,8 @@ #include "modest-edit-msg-window.h" #include "modest-icon-names.h" #include "modest-tny-platform-factory.h" +#include "modest-tny-msg-actions.h" +#include "modest-mail-operation.h" /* 'private'/'protected' functions */ static void modest_main_window_class_init (ModestMainWindowClass *klass); @@ -202,12 +208,8 @@ on_menu_new_message (ModestMainWindow *self, guint action, GtkWidget *widget) { GtkWidget *msg_win; ModestMainWindowPrivate *priv; - ModestConf *conf; - TnyAccountStore *account_store; priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); - conf = modest_tny_platform_factory_get_modest_conf_instance (priv->factory); - account_store = tny_platform_factory_new_account_store (priv->factory); msg_win = modest_edit_msg_window_new (priv->widget_factory, MODEST_EDIT_TYPE_NEW, @@ -216,12 +218,148 @@ on_menu_new_message (ModestMainWindow *self, guint action, GtkWidget *widget) } static void +on_menu_reply_forward (ModestMainWindow *self, guint action, GtkWidget *widget) +{ + GtkWidget *msg_win; + ModestMainWindowPrivate *priv; + ModestHeaderView *header_view; + TnyList *header_list; + TnyIterator *iter; + const gchar *from; + gchar *reply_key, *forward_key; + ModestMailOperationReplyType reply_type; + ModestMailOperationForwardType forward_type; + ModestConf *conf; + GError *error; + + priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); + conf = modest_tny_platform_factory_get_modest_conf_instance (priv->factory); + + header_view = modest_widget_factory_get_header_view (priv->widget_factory); + header_list = modest_header_view_get_selected_headers (header_view); + + /* Get reply and forward types */ + error = NULL; + reply_key = g_strdup_printf ("%s/%s", MODEST_CONF_NAMESPACE, MODEST_CONF_REPLY_TYPE); + reply_type = modest_conf_get_int (conf, reply_key, &error); + if (error) { + g_warning ("key %s not defined", reply_key); + reply_type = MODEST_MAIL_OPERATION_REPLY_TYPE_CITE; + g_error_free (error); + error = NULL; + } + g_free (reply_key); + + forward_key = g_strdup_printf ("%s/%s", MODEST_CONF_NAMESPACE, MODEST_CONF_FORWARD_TYPE); + forward_type = modest_conf_get_int (conf, forward_key, NULL); + if (error) { + g_warning ("key %s not defined", forward_key); + reply_type = MODEST_MAIL_OPERATION_FORWARD_TYPE_INLINE; + g_error_free (error); + } + g_free (forward_key); + + if (header_list) { + iter = tny_list_create_iterator (header_list); + do { + TnyHeader *header, *new_header; + TnyFolder *folder; + TnyMsg *msg, *new_msg; + ModestEditType edit_type; + + /* Get msg from header */ + header = TNY_HEADER (tny_iterator_get_current (iter)); + folder = tny_header_get_folder (header); + msg = tny_folder_get_msg (folder, header); + + from = modest_folder_view_get_selected_account (priv->folder_view); + + /* FIXME: select proper action */ + switch (action) { + case 1: + new_msg = + modest_mail_operation_create_reply_mail (msg, from, reply_type, + MODEST_MAIL_OPERATION_REPLY_MODE_SENDER); + edit_type = MODEST_EDIT_TYPE_REPLY; + break; + case 2: + new_msg = + modest_mail_operation_create_reply_mail (msg, from, reply_type, + MODEST_MAIL_OPERATION_REPLY_MODE_ALL); + edit_type = MODEST_EDIT_TYPE_REPLY; + break; + case 3: + new_msg = + modest_mail_operation_create_forward_mail (msg, from, forward_type); + edit_type = MODEST_EDIT_TYPE_FORWARD; + break; + default: + g_warning ("unexpected action type: %d", action); + } + + /* Set from */ + new_header = tny_msg_get_header (new_msg); + tny_header_set_from (new_header, + modest_folder_view_get_selected_account (priv->folder_view)); + + /* Show edit window */ + msg_win = modest_edit_msg_window_new (priv->widget_factory, + edit_type, + new_msg); + gtk_widget_show (msg_win); + + /* Clean and go on */ + g_object_unref (new_msg); + tny_iterator_next (iter); + + } while (!tny_iterator_is_done (iter)); + } +} + +static void on_menu_quit (ModestMainWindow *self, guint action, GtkWidget *widget) { save_sizes (self); gtk_widget_destroy (GTK_WIDGET(self)); } +static void +on_menu_delete (ModestMainWindow *self, guint action, GtkWidget *widget) +{ + ModestMainWindowPrivate *priv; + ModestHeaderView *header_view; + TnyList *header_list; + TnyIterator *iter; + GtkTreeModel *model; + + priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); + + header_view = modest_widget_factory_get_header_view (priv->widget_factory); + header_list = modest_header_view_get_selected_headers (header_view); + + if (header_list) { + iter = tny_list_create_iterator (header_list); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)); + if (GTK_IS_TREE_MODEL_SORT (model)) + model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model)); + do { + TnyHeader *header; + + header = TNY_HEADER (tny_iterator_get_current (iter)); + + /* Remove from tree model */ + tny_list_remove (TNY_LIST (model), G_OBJECT (header)); + + /* Remove from server */ + modest_tny_msg_actions_remove (header); + + g_object_unref (header); + tny_iterator_next (iter); + + } while (!tny_iterator_is_done (iter)); + } +} + /* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */ static GtkItemFactoryEntry menu_items[] = { @@ -247,8 +385,8 @@ static GtkItemFactoryEntry menu_items[] = { { "/_Actions", NULL, NULL, 0, "" ,NULL}, { "/Actions/_New Message", NULL, on_menu_new_message, 0, "",NULL }, - { "/Actions/_Reply", NULL, NULL, 0, "" ,NULL}, - { "/Actions/_Forward", NULL, NULL, 0, "" ,NULL}, + { "/Actions/_Reply", NULL, on_menu_reply_forward, 1, "" ,NULL}, + { "/Actions/_Forward", NULL, on_menu_reply_forward, 3, "" ,NULL}, { "/Actions/_Bounce", NULL, NULL, 0, "",NULL }, { "/_Options", NULL, NULL, 0, "" ,NULL}, @@ -301,10 +439,10 @@ header_view_new (ModestMainWindow *self) ModestHeaderViewColumn cols[] = { MODEST_HEADER_VIEW_COLUMN_MSGTYPE, MODEST_HEADER_VIEW_COLUMN_ATTACH, - MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER -/* MODEST_HEADER_VIEW_COLUMN_FROM, */ -/* MODEST_HEADER_VIEW_COLUMN_SUBJECT, */ -/* MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE */ +/* MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER, */ + MODEST_HEADER_VIEW_COLUMN_FROM, + MODEST_HEADER_VIEW_COLUMN_SUBJECT, + MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE }; priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); @@ -334,10 +472,13 @@ on_toolbar_button_clicked (ModestToolbar *toolbar, ModestToolbarButton button_id on_menu_new_message (self, 0, NULL); break; case MODEST_TOOLBAR_BUTTON_REPLY: + on_menu_reply_forward (self, 1, NULL); break; case MODEST_TOOLBAR_BUTTON_REPLY_ALL: + on_menu_reply_forward (self, 2, NULL); break; case MODEST_TOOLBAR_BUTTON_FORWARD: + on_menu_reply_forward (self, 3, NULL); break; case MODEST_TOOLBAR_BUTTON_SEND_RECEIVE: @@ -359,6 +500,8 @@ on_toolbar_button_clicked (ModestToolbar *toolbar, ModestToolbarButton button_id break; case MODEST_TOOLBAR_BUTTON_DELETE: + on_menu_delete (self, 0, GTK_WIDGET (toolbar)); + break; default: g_printerr ("modest: key %d pressed\n", button_id);